Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Quest Chains from ethers to Viem for Contract Access #1761

Merged
merged 41 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
aa2109f
converting PNGs to WebP 🚁
dysbulic Jul 9, 2024
c353420
replacing `ethers` with Viem for Quest Chains contract access 🪡
dysbulic Jul 9, 2024
6230eb3
displaying ENS name for Quest Chain author 🈴
dysbulic Jul 9, 2024
b07ada6
fixing submission 🏈
dysbulic Jul 9, 2024
e4fec00
adding `onComplete` handler for uploading 🥕
dysbulic Jul 9, 2024
fbeef7f
in the process of upgrading `ethers` to `v6`
dysbulic Jul 9, 2024
d7369f0
trying to upgrade `yarn` b/c `yarn` classic was crapping out 🪇
dysbulic Jul 9, 2024
0dfe315
updating dependencies 🫛
dysbulic Jul 9, 2024
0207ed4
almost running; need to check another branch 🎤
dysbulic Jul 10, 2024
d725c5c
disabled `yarn` PnP 🥏
dysbulic Jul 10, 2024
fa37b69
pushing so I can reinstall my OS 🧙‍♂️
dysbulic Jul 12, 2024
11d9c91
switching to `package.json` import munging from TypeScript `paths` 🥔
dysbulic Jul 15, 2024
4163b66
fixing ERC-20 contract read using WAGMI 👛
dysbulic Jul 15, 2024
235ad17
criminey, much finessing to hopefully cause the test instance to buil…
dysbulic Jul 15, 2024
e7b8c04
moving Markdown component to `design-system` 🧱
dysbulic Jul 15, 2024
7193bbf
upgrading `eslint` 🪢
dysbulic Jul 16, 2024
6b511b1
switching to `yarn workspaces focus` for production dependencies 🔱
dysbulic Jul 16, 2024
09e495e
removing unneeded `node_modules/`? ✊🏻
dysbulic Jul 16, 2024
cb07eff
enable `corepack` for `yarn` `berry` 🪮
dysbulic Jul 16, 2024
a3c3058
fighting with `docker` ⛑️
dysbulic Jul 16, 2024
298c4ef
finagling `package.json` `imports` to work in dev & prod 🥫
dysbulic Jul 18, 2024
9773e46
allowing Discord bot to start w/o credentials 🏺
dysbulic Jul 18, 2024
83e942c
frontend container building & should deploy 🦥
dysbulic Jul 19, 2024
1204ce2
working on auth & fixing all-category playbooks 🍂
dysbulic Jul 19, 2024
ace7ab6
improving login experience 🪴
dysbulic Jul 19, 2024
18addfd
working on relative paths & saving to Ceramic 🧇
dysbulic Jul 25, 2024
b5f28bd
matching [a recent example](https://github.com/ceramicstudio/walletco…
dysbulic Jul 25, 2024
56707ef
debugging Ceramic & winnowing down `ethers` presence 🏎️
dysbulic Jul 25, 2024
a9e45c4
cleaning up save error messages 🌀
dysbulic Jul 25, 2024
34f2279
Merge branch 'develop' into fix/quest-chains-ethers
dysbulic Jul 30, 2024
12d63d6
testing `yarn` install error on GitHub 🐦‍🔥
dysbulic Jul 30, 2024
6701d92
🪆 Merge branch 'fix/quest-chains-ethers' of github.com:MetaFam/TheGam…
dysbulic Jul 30, 2024
f3aa8a4
trying to get `yarn` to not die when installing from GitHub 🥕
dysbulic Jul 30, 2024
3283e13
missed updating `yarn.lock` 🦞
dysbulic Jul 30, 2024
d944743
reenabling EAS & switching `node-ts` to `tsx` 🏚️
dysbulic Aug 13, 2024
f0aec1f
tweaking Discord bot GraphQL codegen 🏔️
dysbulic Aug 13, 2024
36d41d9
tweaking backend GraphQL codegen 🚒
dysbulic Aug 13, 2024
82e4b09
trying DAOHaus v3 Graph endpoint 🚜
dysbulic Aug 13, 2024
207a713
trying DAOHaus Graph endpoint from [the docs]('https://docs.daohaus.c…
dysbulic Aug 13, 2024
7cde476
maybe this Graph will work 🛰️
dysbulic Aug 13, 2024
c509513
making attestations non-conditional 🚤
dysbulic Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ tsconfig.tsbuildinfo
# Ceramic daemon
ipfs
packages/backend/uploads/
*.key
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/gallium
lts/iron
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"develop"
]
}
{
"githubPullRequests.ignoredPullRequestBranches": [
"develop"
],
"typescript.tsdk": "node_modules/typescript/lib"
}
7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.3.1.cjs

progressBarStyle: simba

preferInteractive: true
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
HASURA_GRAPHQL_DEV_MODE: ${HASURA_GRAPHQL_DEV_MODE:-false}

database:
image: postgres:12
image: postgres:16
volumes:
- database:/var/lib/postgresql/data
ports:
Expand All @@ -39,6 +39,8 @@ services:
context: .
dockerfile: ./docker/backend/Dockerfile
target: base
args:
CACHEBUST: ${CACHEBUST:-$(date +%s)}
command: yarn backend:dev
ports:
- 4000:4000
Expand Down
29 changes: 20 additions & 9 deletions docker/backend/Dockerfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dysbulic Does line 41 change need an actual url link also?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it's fine because line 44 refers to the env? I'm still getting backend build fails on the test build for dAcademy PR. @dysbulic

Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
FROM node:20-slim as base
WORKDIR /usr/src/app

# varying arg to prevent caching
ARG CACHEBUST
ARG DEBUG

# Install dependencies not included in the slim image
RUN apt-get update && \
apt-get install -y --no-install-recommends g++ make python3 git openssl && \
apt-get install -y --no-install-recommends --reinstall ca-certificates

# Install dependencies for dev and prod
COPY package.json .
COPY lerna.json .
COPY yarn.lock .
COPY schema.graphql .
COPY tsconfig.base.json .
COPY package.json ./
COPY lerna.json ./
COPY yarn.lock ./
COPY schema.graphql ./
COPY tsconfig.base.json ./
COPY packages/backend/*.json ./packages/backend/
COPY packages/utils/*.json ./packages/utils/
COPY packages/discord-bot/*.json ./packages/discord-bot/

RUN yarn install --pure-lockfile
RUN corepack enable
RUN yarn set version berry
RUN yarn config set nodeLinker node-modules
RUN yarn install # --immutable

# RUN set -x && echo $CACHEBUST && ls -la

# Dev environment doesn't run this stage or beyond
# Dev environment doesn't run beyond here
FROM base as build

# Copy source files
Expand All @@ -41,7 +49,10 @@ ENV THE_GRAPH_API_TOKEN $THE_GRAPH_API_TOKEN
RUN yarn backend:build

# Delete devDependencies
RUN yarn install --pure-lockfile --production --ignore-scripts --prefer-offline
RUN corepack enable
RUN yarn set version berry
RUN yarn install # --immutable
# RUN yarn install --pure-lockfile --production --ignore-scripts --prefer-offline

# Create completely new stage including only necessary files
FROM node:20-slim as app
Expand Down
4 changes: 3 additions & 1 deletion docker/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ COPY packages/web/graphql ./packages/web/graphql/
COPY packages/utils/*.json ./packages/utils/
COPY packages/design-system/*.json ./packages/design-system/

RUN yarn install --pure-lockfile
RUN corepack enable
RUN yarn set version berry
RUN yarn install # --immutable

FROM base AS build

Expand Down
2 changes: 0 additions & 2 deletions hasura/clear-xp.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

import fetch from 'node-fetch'

/* eslint-disable no-console */

const TARGET_GRAPHQL_URL = (
Expand Down
1 change: 0 additions & 1 deletion hasura/seed-db.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

import Bottleneck from 'bottleneck';
import fetch from 'node-fetch';

/* eslint-disable no-console */

Expand Down
45 changes: 16 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@metafam/the-game",
"version": "0.2.0",
"license": "GPL-3.0",
"license": "GPL-2.0",
"type": "module",
"engines": {
"node": ">=20"
Expand All @@ -15,6 +15,7 @@
"docker:stop": "docker-compose down",
"docker:clean": "docker-compose down -v",
"docker:dev": "DOCKER_BUILDKIT=1 docker compose up --build",
"docker:debug": "docker compose --progress=plain up --build",
"build": "lerna run --concurrency 1 --stream build",
"web:dev": "lerna run dev --parallel --scope @metafam/web --include-dependencies",
"web:build": "lerna run build --scope @metafam/web --include-dependencies --stream",
Expand All @@ -29,7 +30,7 @@
"test": "lerna run test --parallel --",
"test:full": "yarn lint && yarn typecheck && yarn test",
"clean": "lerna clean",
"clean:libndist": "CMD='rm -rf node_modules/ packages/*/node_modules/ packages/*/dist/ packages/web/.next/' && echo \"$CMD\" && eval $CMD",
"clean:libndist": "CMD='rm -rf node_modules/ packages/*/node_modules/ packages/*/dist/ packages/web/.next/' && echo \"$CMD\" && sh -c \"eval $CMD\"",
"clean:autogen": "find -type d -name autogen -exec rm -rfv '{}' \\; || true",
"clean:full": "yarn clean:libndist && yarn clean:autogen",
"format": "prettier --write \"{*,**/*}.{ts,tsx,js,jsx,json,yml,yaml,md}\"",
Expand All @@ -43,35 +44,29 @@
"web": "yarn --cwd packages/web/",
"ds": "yarn --cwd packages/design-system/",
"release": "standard-version",
"composedb:create-composite": "composedb composite:create packages/utils/schema/user-profile.graphql -o packages/utils/schema/user-profile-composite.json",
"composedb:create-definition": "composedb composite:compile packages/utils/schema/user-profile-composite.json packages/utils/schema/user-profile-definition.json",
"composedb:graphql-generate": "composedb composite:compile packages/utils/schema/user-profile-composite.json packages/utils/src/graphql/composeDBDefinition.ts",
"composedb:graphql-server": "composedb graphql:server --graphiql packages/utils/schema/user-profile-definition.json"
"composedb:create-composite": "composedb composite:create packages/utils/schema/user-profile.graphql --output packages/utils/schema/user-profile-composite.json",
"composedb:create-definition": "composedb composite:compile packages/utils/schema/user-profile-composite.json packages/utils/schema/user-profile-definition.json --ceramic-url=https://ceramic.metagame.wtf",
"composedb:graphql-generate": "composedb composite:compile packages/utils/schema/user-profile-composite.json packages/utils/src/graphql/composeDBDefinition.ts --ceramic-url=https://ceramic.metagame.wtf",
"composedb:graphql-server": "composedb graphql:server --graphiql packages/utils/schema/user-profile-definition.json --ceramic-url=https://ceramic.metagame.wtf"
},
"workspaces": [
"packages/*"
],
"dependencies": {
"dag-jose": "^4.0.0",
"tslib": "^2.4.0",
"uuid": "8.3.2"
},
"devDependencies": {
"@apollo/rover": "^0.18.0",
"@composedb/cli": "^0.4.4",
"@graphql-codegen/add": "^5.0.0",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/introspection": "^4.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-graphql-request": "^5.0.0",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@graphql-codegen/typescript-react-apollo": "^3.3.7",
"@graphql-codegen/typescript-resolvers": "^4.0.1",
"@graphql-codegen/typescript-urql": "^4.0.0",
"@apollo/rover": "^0.23.0",
"@composedb/cli": "^0.7.1",
"@types/jest": "^29.2.1",
"@types/node": "^20.8.6",
"@types/node-fetch": "^2.6.2",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.45.0",
"@typescript-eslint/parser": "^6.6.0",
"caniuse-lite": "^1.0.30001383",
"concurrently": "7.0.0",
"env-cmd": "10.1.0",
"eslint": "^8.39.0",
Expand All @@ -97,10 +92,7 @@
"wait-on": "6.0.1"
},
"resolutions": {
"@ceramicnetwork/common": "2.31.1",
"did-resolver": "4.1.0",
"dids": "4.0.4",
"graphql": "16.5.0",
"graphql": "16.9.0",
"multihashes": "4.0.3",
"node-gyp": "10.0.1",
"better-sqlite3": "9.4.5",
Expand All @@ -110,10 +102,5 @@
"defaults",
"not IE 11"
],
"dependencies": {
"dag-jose": "^4.0.0",
"tslib": "^2.4.0",
"uuid": "8.3.2"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]"
}
23 changes: 12 additions & 11 deletions packages/backend/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ const config = {
generates: {
'src/handlers/remote-schemas/autogen/types.ts': {
schema: 'src/handlers/remote-schemas/typeDefs.ts',
plugins: [
'typescript',
'typescript-resolvers',
{ add: { content: '/* eslint-disable */' } },
],
config: {
noSchemaStitching: true,
avoidOptionals: true,
maybeValue:
'T extends PromiseLike<infer U> ? Promise<U | null> : T | null | undefined',
},

// plugins: [
// 'typescript',
// 'typescript-resolvers',
// { add: { content: '/* eslint-disable */' } },
// ],
// config: {
// noSchemaStitching: true,
// avoidOptionals: true,
// maybeValue:
// 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null | undefined',
// },
},
'src/lib/autogen/hasura-sdk.ts': {
schema: '../../schema.graphql',
Expand Down
49 changes: 28 additions & 21 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,60 @@
"version": "0.2.0",
"description": "",
"author": "MetaFam",
"license": "ISC",
"contributors": [
"δυς <[email protected]> (https://trwb.live)"
],
"license": "GPL-2.0",
"type": "module",
"main": "dist/index.js",
"scripts": {
"start": "node --trace-warnings dist/index.js",
"build": "yarn generate && tsc -b",
"dev": "tsc --build && concurrently 'tsc --watch --preserveWatchOutput' nodemon",
"dev": "nodemon",
"typecheck": "tsc --noEmit --pretty",
"precommit": "yarn typecheck",
"generate": "graphql-code-generator --debug && yarn fix:daohaus-types",
"fix:daohaus-types": "export OUT=src/lib/autogen/daohaus-sdk.ts && awk '!/MolochVersion = .molochVersion/' $OUT > $OUT.filtered && mv $OUT.filtered $OUT",
"fix:daohaus-types": "bash -c 'export OUT=src/lib/autogen/daohaus-sdk.ts && awk \"!/MolochVersion = .molochVersion/\" $OUT > $OUT.filtered && mv $OUT.filtered $OUT'",
"fix:lint": "eslint --fix",
"test": "jest --passWithNoTests"
},
"dependencies": {
"@ceramicnetwork/stream-caip10-link": "^2.26.1",
"@composedb/client": "^0.4.4",
"@graphql-tools/schema": "8.3.2",
"@metafam/discord-bot": "0.1.0",
"@metafam/utils": "1.0.1",
"@ceramicnetwork/http-client": "^5.16.0",
"@ceramicnetwork/stream-caip10-link": "^5.15.0",
"@composedb/client": "^0.7.1",
"@datamodels/identity-accounts-crypto": "^0.2.0",
"@datamodels/identity-profile-basic": "^0.2.0",
"@graphql-tools/schema": "^10.0.4",
"@metafam/discord-bot": "workspace:*",
"@metafam/utils": "workspace:*",
"bluebird": "3.7.2",
"bottleneck": "^2.19.5",
"cors": "2.8.5",
"discord.js": "13.6.0",
"discord.js": "^14.15.3",
"dotenv": "16.0.0",
"ethers": "5.7.2",
"express": "^4.18.2",
"ethers": "^6.13.1",
"express": "^4.19.2",
"express-graphql": "0.12.0",
"graphql": "16.5.0",
"graphql-request": "4.0.0",
"graphql-tag": "2.12.6",
"graphql": "16.9.0",
"graphql-request": "^7.1.0",
"graphql-tag": "^2.12.6",
"showdown": "^2.1.0",
"uuid": "8.3.2"
},
"devDependencies": {
"@composedb/types": "^0.7.1",
"@types/bluebird": "3.5.36",
"@types/body-parser": "1.19.2",
"@types/cors": "2.8.12",
"@types/create-hash": "^1.2.6",
"@types/express": "^4.17.21",
"@types/node": "^20.14.10",
"@types/showdown": "^2.0.0",
"@types/uuid": "8.3.0",
"@types/uuid": "^10.0.0",
"nock": "13.2.4",
"nodemon": "^2.0.20",
"ts-node": "^10.9.1"
},
"resolutions": {
"better-sqlite3": "9.4.5",
"node-gyp": "10.0.1"
"nodemon": "^3.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
},
"nodemonConfig": {
"exec": "node --inspect=0.0.0.0:4322 --loader ts-node/esm src/index.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export default async (req: Request, res: Response): Promise<void> => {
});
const modelInstanceDoc = await composeDBClient.context.loadDoc(nodeId);

if (!modelInstanceDoc) throw new Error(`Model instance not found: "${nodeId}".`);

const { controller } = modelInstanceDoc.metadata;

// There is probably a better way to do this...
const controllerEthAddress = controller.substring(
controller.lastIndexOf(':') + 1,
);
const controllerEthAddress = controller.replace(/.*:/g, '');

// controller is something like did:pkh:eip155:1:0x4c81e51aa103490838fd9db1d859a5fcd8276324
// make sure this is a mainnet address!
if (
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/handlers/actions/player/syncBalances.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Constants, numbers } from '@metafam/utils';

import { getERC20Contract, polygonProvider } from '../../../../lib/ethereum.js';

const { BN, amountToDecimal } = numbers;
const { amountToDecimal } = numbers;

/**
* As a first iteration, we only allow people to create quests if they hold more that 100 pSEED tokens
Expand All @@ -17,13 +17,13 @@ export async function isAllowedToCreateQuest(
);
const pSEEDBalance = await pSEEDContract.balanceOf(playerAddress);
const pSEEDDecimals = await pSEEDContract.decimals();
const minimumPooledSeedBalance = new BN(Constants.PSEED_FOR_QUEST);
const minimumPooledSeedBalance = BigInt(Constants.PSEED_FOR_QUEST);
const pSEEDBalanceInDecimal = amountToDecimal(
pSEEDBalance.toString(),
pSEEDDecimals,
);

const allowed = new BN(pSEEDBalanceInDecimal).gte(minimumPooledSeedBalance);
const allowed = BigInt(pSEEDBalanceInDecimal) >= minimumPooledSeedBalance;

return allowed;
}
2 changes: 1 addition & 1 deletion packages/backend/src/handlers/auth-webhook/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const authHandler = async (
}
const claim = await did.verifyToken(
token,
mainnetProvider as unknown as ethers.providers.Web3Provider,
mainnetProvider as unknown as ethers.BrowserProvider,
);
if (!claim) {
throw new Error('Invalid token');
Expand Down
Loading
Loading