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

feat(cli,create-mud,store,world): add abi-ts to replace typechain #1403

Merged
merged 33 commits into from
Sep 7, 2023

Conversation

holic
Copy link
Member

@holic holic commented Sep 6, 2023

big diff because I removed checked-in types from example and e2e dirs (don't think we need em in here for now and they were a pain to update if core stuff changed)

TODO:

  • migrate typechain usage in dev-contracts (need to build ABIs and pass into abi-ts)
  • migrate store/world

related to microsoft/TypeScript#32063

@changeset-bot
Copy link

changeset-bot bot commented Sep 6, 2023

🦋 Changeset detected

Latest commit: 1efce8d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@latticexyz/abi-ts Major
@latticexyz/cli Major
@latticexyz/store Major
@latticexyz/world Major
create-mud Major
@latticexyz/dev-tools Major
@latticexyz/react Major
@latticexyz/store-indexer Major
@latticexyz/store-sync Major
@latticexyz/block-logs-stream Major
@latticexyz/common Major
@latticexyz/config Major
@latticexyz/ecs-browser Major
@latticexyz/gas-report Major
@latticexyz/network Major
@latticexyz/noise Major
@latticexyz/phaserx Major
@latticexyz/protocol-parser Major
@latticexyz/recs Major
@latticexyz/schema-type Major
@latticexyz/services Major
@latticexyz/solecs Major
solhint-config-mud Major
solhint-plugin-mud Major
@latticexyz/std-client Major
@latticexyz/std-contracts Major
@latticexyz/store-cache Major
@latticexyz/utils Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@holic holic changed the title feat(cli,create-mud): add abi-ts to replace typechain feat(cli,create-mud,store,world): add abi-ts to replace typechain Sep 6, 2023
@holic holic marked this pull request as ready for review September 6, 2023 14:13
@holic holic requested a review from alvrs as a code owner September 6, 2023 14:13
Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

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

this is very exciting! just minor nits

.changeset/six-cats-agree.md Outdated Show resolved Hide resolved
@@ -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-ts/IWorld.sol/IWorld";
Copy link
Member

Choose a reason for hiding this comment

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

cc @qbzzt, this change might be relevant for the client setup file walkthrough (#1401)

packages/abi-ts/src/abi-ts.ts Outdated Show resolved Hide resolved
@@ -66,7 +65,7 @@ const commandModule: CommandModule<Options, Options> = {

// Create World contract instance from deployed address
const provider = new ethers.providers.StaticJsonRpcProvider(rpc);
const WorldContract = new ethers.Contract(worldAddress, IBaseWorldData.abi, provider) as IBaseWorld;
Copy link
Member

Choose a reason for hiding this comment

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

This previously created some ts guardrails for calling the world methods (registerTable etc) below - I guess that currently isn't the case anymore but will be the case again after we refactored the script to viem correct?

(cc #1006 #1384)

Copy link
Member Author

Choose a reason for hiding this comment

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

correct! this would have been the last remaining spot to use typechain, so I opted to ditch it all for the short time that we're between ethers and viem for deploys

@@ -14,7 +14,6 @@
"./register": "./dist/ts/register/index.js",
"./node": "./dist/ts/node/index.js",
"./abi/*": "./abi/*",
"./types/*": "./types/*",
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention this change in the changeset? (if consumers relied on these types they need to either generate them via typechain in their project or use abitype)

Same for the corresponding store package change

Co-authored-by: alvarius <alvarius@lattice.xyz>
Co-authored-by: alvarius <alvarius@lattice.xyz>
// Run typechain to rebuild typescript types for the contracts
await worldtypes();
// Generate TS-friendly ABI files
// We rebuild into a separate dir to have a clean set of ABIs without test/script contracts
Copy link
Member

Choose a reason for hiding this comment

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

is this comment still up to date?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, still relevant

Copy link
Member Author

Choose a reason for hiding this comment

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

more context:

We need forge to build everything to run things like tests, scripts, etc. But for a clean ABI dir, we want to ignore these. It's tricky to use the same target dir (e.g. out) because then tests won't find the build files they need to run. So we use a separate dir just for ABIs.

Since abi-ts can now target/build a specific ABI file or glob, we could simplify this to just a single output dir and only build IWorld ABI, but has trade-offs in that it's a bit harder for users to expand that if they want to include more ABIs in their TS code.

@holic holic merged commit 55377ff into main Sep 7, 2023
11 checks passed
@holic holic deleted the holic/abi-ts-codegen branch September 7, 2023 09:21
@github-actions github-actions bot mentioned this pull request Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants