Skip to content

Commit

Permalink
feat(cli,create-mud,store,world): add abi-ts to replace typechain (#1403
Browse files Browse the repository at this point in the history
)

Co-authored-by: alvarius <[email protected]>
  • Loading branch information
holic and alvrs authored Sep 7, 2023
1 parent 8658e7b commit 55377ff
Show file tree
Hide file tree
Showing 137 changed files with 13,854 additions and 7,703 deletions.
47 changes: 47 additions & 0 deletions .changeset/six-cats-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
"@latticexyz/abi-ts": minor
"@latticexyz/cli": minor
"@latticexyz/store": minor
"@latticexyz/world": minor
"create-mud": minor
---

Added a new `@latticexyz/abi-ts` package to generate TS type declaration files (`.d.ts`) for each ABI JSON file. This replaces our usage TypeChain everywhere. It's also bundled into `@latticexyz/cli` under the `mud abi-ts` command.

If you have a MUD project created from an older template, you can replace TypeChain with `abi-ts` by first updating your contracts' `package.json`:

```diff
-"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:typechain",
+"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
-"build:abi": "forge clean && forge build",
+"build:abi": "rimraf abi && forge build --extra-output-files abi --out abi --skip test script MudTest.sol",
+"build:abi-ts": "mud abi-ts --input 'abi/IWorld.sol/IWorld.abi.json' && prettier --write '**/*.abi.json.d.ts'",
"build:mud": "mud tablegen && mud worldgen",
-"build:typechain": "rimraf types && typechain --target=ethers-v5 out/IWorld.sol/IWorld.json",
```

And update your client's `setupNetwork.ts` with:

```diff
-import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
+import IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";

const worldContract = createContract({
address: networkConfig.worldAddress as Hex,
- abi: IWorld__factory.abi,
+ abi: IWorldAbi,
```

If you previously relied on TypeChain types from `@latticexyz/store` or `@latticexyz/world`, you will either need to migrate to viem or abitype using ABI JSON imports or generate TypeChain types from our exported ABI JSON files.

```ts
import { getContract } from "viem";
import IStoreAbi from "@latticexyz/store/abi/IStore.sol/IStore.abi.json";

const storeContract = getContract({
abi: IStoreAbi,
...
});

await storeContract.write.setRecord(...);
```
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ dist
**/artifacts/
**/abi/
**/broadcast/
**/deploys/
**/deploys/
4 changes: 0 additions & 4 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ runs:
shell: bash
run: pnpm turbo run build --cache-dir=.turbo --concurrency 10

- name: Install node dependencies again to update workspace binaries
shell: bash
run: pnpm install --frozen-lockfile

- name: Outdated files, run `pnpm build` and commit them
uses: ./.github/actions/require-empty-diff
7 changes: 7 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ runs:
with:
repo-token: ${{ github.token }}

# pnpm no longer runs this before the actual install (https://github.com/pnpm/pnpm/issues/3760)
# but we need to create some placeholder files like bins so that the install step can find them and put references to them in the right spot
# this resolves some chicken-and-egg problems with using workspace bins before they're created (install -> build -> install)
- name: Run prepare scripts
shell: bash
run: pnpm recursive run prepare

- name: Install node dependencies
shell: bash
run: pnpm install --frozen-lockfile
Expand Down
30 changes: 0 additions & 30 deletions .pnpmfile.cjs

This file was deleted.

2 changes: 0 additions & 2 deletions e2e/packages/client-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"dev": "vite"
},
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@improbable-eng/grpc-web": "^0.15.0",
"@latticexyz/common": "link:../../../packages/common",
"@latticexyz/dev-tools": "link:../../../packages/dev-tools",
Expand All @@ -22,7 +21,6 @@
"@latticexyz/world": "link:../../../packages/world",
"async-mutex": "^0.4.0",
"contracts": "workspace:*",
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"mobx": "^6.7.0",
"nice-grpc": "^2.0.1",
Expand Down
4 changes: 2 additions & 2 deletions e2e/packages/client-vanilla/src/mud/setupNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createFaucetService } from "@latticexyz/services/faucet";
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { getNetworkConfig } from "./getNetworkConfig";
import { world } from "./world";
import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
import IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
import mudConfig from "contracts/mud.config";

Expand All @@ -28,7 +28,7 @@ export async function setupNetwork() {

const worldContract = createContract({
address: networkConfig.worldAddress as Hex,
abi: IWorld__factory.abi,
abi: IWorldAbi,
publicClient,
walletClient: burnerWalletClient,
});
Expand Down
13 changes: 5 additions & 8 deletions e2e/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
"private": true,
"license": "MIT",
"scripts": {
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:typechain",
"build:abi": "forge build --extra-output-files abi --out abi --skip test script",
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
"build:abi": "forge build --extra-output-files abi --out abi --skip test script MudTest.sol",
"build:abi-ts": "mud abi-ts --input 'abi/IWorld.sol/IWorld.abi.json' && prettier --write '**/*.abi.json.d.ts'",
"build:mud": "mud tablegen && mud worldgen",
"build:typechain": "typechain --target=ethers-v5 abi/IWorld.sol/IWorld.json",
"clean": "pnpm run clean:abi && pnpm run clean:mud && pnpm run clean:typechain",
"clean": "pnpm run clean:abi && pnpm run clean:mud",
"clean:abi": "rimraf abi",
"clean:mud": "rimraf src/codegen",
"clean:typechain": "rimraf types",
"deploy:local": "mud deploy",
"test": "mud test",
"test:ci": "pnpm run test"
Expand All @@ -22,13 +21,11 @@
"@latticexyz/schema-type": "link:../../../packages/schema-type",
"@latticexyz/store": "link:../../../packages/store",
"@latticexyz/world": "link:../../../packages/world",
"@typechain/ethers-v5": "^10.2.0",
"dotenv": "^16.0.3",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"ethers": "^5.7.2",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typechain": "^8.1.1",
"typescript": "5.1.6",
"vite": "^4.2.1",
"vitest": "0.31.4"
Expand Down
Loading

0 comments on commit 55377ff

Please sign in to comment.