Skip to content

Commit

Permalink
Eas - ethers compat issues between dependencies (#1748)
Browse files Browse the repository at this point in the history
* eh

* dashboard layout

* t

* t

* ethers issues identified

* `/me` is loading & linting without error 🍞

* fixing an `import`s order error 🛼

* Update useEAS.ts

* eas

* attestations working

* get attestations

* attest

* chore: improve design

* chore: size

* change design

* fix: update schema

* chore

* eas

* eas

---------

Co-authored-by: dysbulic <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent 8c8934c commit 1345015
Show file tree
Hide file tree
Showing 44 changed files with 1,847 additions and 1,588 deletions.
File renamed without changes.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "@metafam/the-game",
"version": "0.2.0",
"license": "GPL-3.0",
"type": "module",
"engines": {
"node": ">=16"
"node": ">=20"
},
"private": true,
"scripts": {
Expand Down Expand Up @@ -99,11 +100,11 @@
"@ceramicnetwork/common": "2.31.1",
"did-resolver": "4.1.0",
"dids": "4.0.4",
"ethers": "5.7.0",
"graphql": "16.8.0",
"graphql": "16.5.0",
"multihashes": "4.0.3",
"node-gyp": "10.0.1",
"better-sqlite3": "9.0.0"
"better-sqlite3": "9.4.5",
"nan": "2.18.0"
},
"browserslist": [
"defaults",
Expand Down
7 changes: 4 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"cors": "2.8.5",
"discord.js": "13.6.0",
"dotenv": "16.0.0",
"ethers": "5.6.9",
"ethers": "^6.11.1",
"express": "^4.18.2",
"express-graphql": "0.12.0",
"graphql": "16.7.1",
"graphql": "16.5.0",
"graphql-request": "4.0.0",
"graphql-tag": "2.12.6",
"showdown": "^2.1.0",
Expand All @@ -49,7 +49,8 @@
"ts-node": "^10.9.1"
},
"resolutions": {
"typescript": "4.8.4"
"better-sqlite3": "9.4.5",
"node-gyp": "10.0.1"
},
"nodemonConfig": {
"exec": "node --inspect=0.0.0.0:4322 --loader ts-node/esm src/index.ts",
Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/handlers/actions/player/syncBalances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentSeasonStart, Maybe } from '@metafam/utils';
import ethers from 'ethers';
import { ethers } from 'ethers';
import { Request, Response } from 'express';

import { client } from '../../../lib/hasuraClient.js';
Expand Down Expand Up @@ -65,9 +65,7 @@ const setBalances = async ({
uniqueDrops[executionDate] ??= {};
uniqueDrops[executionDate][to] ??= 0;
if (tokenAddress === guildTokenAddress) {
uniqueDrops[executionDate][to] += Number(
ethers.utils.formatEther(value),
);
uniqueDrops[executionDate][to] += Number(ethers.formatEther(value));
}
});
});
Expand Down
9 changes: 3 additions & 6 deletions packages/backend/src/lib/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import ERC20_ABI from './abis/ERC20.json' assert { type: 'json' };

const { infuraId } = CONFIG;

export const mainnetProvider = new ethers.providers.InfuraProvider(1, infuraId);
export const polygonProvider = new ethers.providers.InfuraProvider(
137,
infuraId,
);
export const mainnetProvider = new ethers.InfuraProvider(1, infuraId);
export const polygonProvider = new ethers.InfuraProvider(137, infuraId);

export const getERC20Contract = (
contractAddress: string,
provider: ethers.providers.BaseProvider = mainnetProvider,
provider: ethers.Provider = mainnetProvider,
): ethers.Contract => new ethers.Contract(contractAddress, ERC20_ABI, provider);
2 changes: 1 addition & 1 deletion packages/discord-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dotenv": "16.0.0",
"ethers": "5.6.9",
"express": "4.17.3",
"graphql": "^16.8.0",
"graphql": "16.5.0",
"graphql-request": "^6.1.0",
"graphql-tag": "2.12.6",
"node-fetch": "3.2.1",
Expand Down
7 changes: 5 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
"@ceramicnetwork/http-client": "^2.15.0",
"@datamodels/identity-accounts-crypto": "^0.2.0",
"@datamodels/identity-profile-basic": "^0.2.0",
"@ethersproject/address": "5.6.0",
"bignumber.js": "^9.1.0",
"cids": "^1.1.9",
"ethers": "5.7.0",
"ethers": "^6.11.1",
"imgix-core-js": "2.3.2",
"js-base64": "3.7.2",
"node-fetch": "3.2.1",
Expand All @@ -31,5 +30,9 @@
"devDependencies": {
"key-did-provider-ed25519": "^2.0.1",
"key-did-resolver": "^2.1.3"
},
"resolutions": {
"better-sqlite3": "9.4.5",
"node-gyp": "10.0.1"
}
}
6 changes: 3 additions & 3 deletions packages/utils/src/did/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { providers } from 'ethers';
import { BrowserProvider, Provider } from 'ethers';
import { Base64 } from 'js-base64';
import { v4 as uuidv4 } from 'uuid';

Expand All @@ -18,7 +18,7 @@ type Claim = {
};

export async function createToken(
provider: providers.Web3Provider,
provider: BrowserProvider,
userAddress: string,
): Promise<string> {
const iat = +new Date();
Expand All @@ -40,7 +40,7 @@ export async function createToken(

export async function verifyToken(
token: string,
provider: providers.JsonRpcProvider,
provider: Provider,
connectedAddress?: string,
): Promise<Maybe<Claim>> {
const rawToken = Base64.decode(token);
Expand Down
38 changes: 12 additions & 26 deletions packages/utils/src/ethereumHelper.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { Contract, providers, utils } from 'ethers';
import { BrowserProvider, Contract, ethers, Provider } from 'ethers';

export async function getSignature(
provider: providers.Web3Provider,
provider: BrowserProvider,
msg: string,
extraParams?: string[] | undefined,
): Promise<string> {
const ethereum = provider.provider;
const signer = provider.getSigner();
const address = await signer.getAddress();
if (!ethereum.request) throw new Error('No `request` On Ethereum Provider');
let params = [msg, address];

if (extraParams) {
params = [...params, ...extraParams];
}

const signature = await ethereum.request({
method: 'personal_sign',
params,
});
return signature;
const signer = await provider.getSigner();
return signer.signMessage(msg);
}

const smartWalletABI = [
Expand All @@ -33,7 +19,7 @@ enum WalletType {

async function getWalletType(
address: string,
provider: providers.BaseProvider,
provider: Provider,
): Promise<WalletType> {
const code = await new Promise((resolve, reject) => {
const seconds = 45;
Expand All @@ -58,24 +44,24 @@ export async function verifySignature(
address: string,
message: string,
signature: string,
provider: providers.BaseProvider,
provider: Provider,
): Promise<boolean> {
const walletType = await getWalletType(address, provider);

if (walletType === WalletType.EOA) {
const recoveredAddress = utils.verifyMessage(message, signature);
const recoveredAddress = ethers.verifyMessage(message, signature);
return address === recoveredAddress;
}

// Smart wallet
const msgBytes = utils.toUtf8Bytes(message);
const hexMsg = utils.hexlify(msgBytes);
const hexArray = utils.arrayify(hexMsg);
const hashMsg = utils.hashMessage(hexArray);
const msgBytes = ethers.toUtf8Bytes(message);
const hexMsg = ethers.hexlify(msgBytes);
const hexArray = ethers.getBytes(hexMsg);
const hashMsg = ethers.hashMessage(hexArray);

const contract = new Contract(address, smartWalletABI, provider);
try {
return contract.isValidSignature(hashMsg, signature);
return await contract.isValidSignature(hashMsg, signature);
} catch (error) {
throw new Error(`Unsupported Smart Wallet: ${(error as Error).message}`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Guild/GuildForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isAddress } from '@ethersproject/address';
import {
Box,
CloseButton,
Expand All @@ -19,6 +18,7 @@ import { SelectOption } from '@metafam/ds/src/MultiSelect';
import FileOpenIcon from 'assets/file-open-icon.svg';
import { Field, FieldDescription } from 'components/Forms/Field';
import { MetaLink } from 'components/Link';
import { isAddress } from 'ethers';
import {
DiscordRole,
GuildDaoInput,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Guild/UnverifiedGuildForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isAddress } from '@ethersproject/address';
import {
Box,
chakra,
Expand All @@ -16,6 +15,7 @@ import {
} from '@metafam/ds';
import FileOpenIcon from 'assets/file-open-icon.svg';
import { Field, FieldDescription } from 'components/Forms/Field';
import { isAddress } from 'ethers';
import {
AddUnverifiedGuildMutation,
AddUnverifiedGuildMutationVariables,
Expand Down
162 changes: 0 additions & 162 deletions packages/web/components/Landing/UserGrid.tsx

This file was deleted.

Loading

0 comments on commit 1345015

Please sign in to comment.