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: move forge build + abi + abi-ts to out #1483

Merged
merged 12 commits into from
Sep 14, 2023
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions .changeset/many-pumpkins-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@latticexyz/store": major
"@latticexyz/world": major
---

Store and World contract ABIs are now exported from the `out` directory. You'll need to update your imports like:

```diff
- import IBaseWorldAbi from "@latticexyz/world/abi/IBaseWorld.sol/IBaseWorldAbi.json";
+ import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorldAbi.json";
```

`MudTest.sol` was also moved to the World package. You can update your import like:

```diff
- import { MudTest } from "@latticexyz/store/src/MudTest.sol";
+ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
```
19 changes: 19 additions & 0 deletions .changeset/modern-trains-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"create-mud": minor
---

Templates now use `out` for their `forge build` artifacts, including ABIs. If you have a project created from a previous template, you can update your `packages/contracts/package.json` with:

```diff
- "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:abi": "forge clean && forge build --skip test script",
+ "build:abi-ts": "mud abi-ts && prettier --write '**/*.abi.json.d.ts'",
```

And your `packages/client/src/mud/setupNetwork` with:

```diff
- import IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
+ import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
```
5 changes: 5 additions & 0 deletions .changeset/sweet-kiwis-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

`deploy` and `dev-contracts` CLI commands now use `forge build --skip test script` before deploying and run `mud abi-ts` to generate strong types for ABIs.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ dist
**/cache/
**/bindings/
**/artifacts/
**/abi/
**/broadcast/
**/deploys/
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# suppress diffs for codegen in PRs
**/abi/**/*.json linguist-generated=true
**/abi/**/*.json.d.ts linguist-generated=true
Comment on lines -2 to -3
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 suppress out diffs now then?

Copy link
Member

Choose a reason for hiding this comment

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

ahh i see abis are no longer checked in to git

**/codegen/**/*.sol linguist-generated=true
2 changes: 1 addition & 1 deletion 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 IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
import mudConfig from "contracts/mud.config";

Expand Down
1 change: 0 additions & 1 deletion e2e/packages/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cache/
node_modules/
bindings/
artifacts/
abi/
broadcast/

# Ignore all deploy artifacts
Expand Down
6 changes: 3 additions & 3 deletions e2e/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"license": "MIT",
"scripts": {
"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:abi": "forge build --skip test script",
Copy link
Member

Choose a reason for hiding this comment

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

do we not need the --extra-output-files abi anymore?

Copy link
Member

Choose a reason for hiding this comment

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

ahh i see it's in the forge config now

"build:abi-ts": "mud abi-ts && prettier --write '**/*.abi.json.d.ts'",
"build:mud": "mud tablegen && mud worldgen",
"clean": "pnpm run clean:abi && pnpm run clean:mud",
"clean:abi": "rimraf abi",
"clean:abi": "forge clean",
"clean:mud": "rimraf src/codegen",
"deploy:local": "mud deploy",
"test": "mud test",
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/contracts/test/Worldgen.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { MudTest } from "@latticexyz/store/src/MudTest.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";

import { ICustomErrorsSystem } from "../src/codegen/world/ICustomErrorsSystem.sol";
import { Position } from "../src/CustomTypes.sol";
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/sync-test/data/callWorld.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Page } from "@playwright/test";
import IWorldAbi from "../../contracts/abi/IWorld.sol/IWorld.abi.json";
import IWorldAbi from "../../contracts/out/IWorld.sol/IWorld.abi.json";
import { GetContractReturnType, PublicClient, WalletClient } from "viem";
import { AbiParametersToPrimitiveTypes, ExtractAbiFunction, ExtractAbiFunctionNames } from "abitype";

Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/test-data/generate-test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { mudFoundry } from "@latticexyz/common/chains";
import { createContract } from "@latticexyz/common";
import { storeEventsAbi } from "@latticexyz/store";
import { privateKeyToAccount } from "viem/accounts";
import IWorldAbi from "../contracts/abi/IWorld.sol/IWorld.abi.json";
import IWorldAbi from "../contracts/out/IWorld.sol/IWorld.abi.json";

const logsFilename = path.join(path.dirname(fileURLToPath(import.meta.url)), `../../../test-data/world-logs.json`);

Expand Down
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 IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { createBurnerAccount, createContract, transportObserver, ContractWrite } from "@latticexyz/common";
import { Subject, share } from "rxjs";
import mudConfig from "contracts/mud.config";
Expand Down
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 IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { ContractWrite, createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
import { Subject, share } from "rxjs";
import mudConfig from "contracts/mud.config";
Expand Down
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 IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { createBurnerAccount, createContract, transportObserver, ContractWrite } from "@latticexyz/common";
import { Subject, share } from "rxjs";
import mudConfig from "contracts/mud.config";
Expand Down
1 change: 0 additions & 1 deletion examples/minimal/packages/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cache/
node_modules/
bindings/
artifacts/
abi/
broadcast/

# Ignore MUD deploy artifacts
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "MIT",
"scripts": {
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
"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:abi": "forge clean && forge build --skip test script",
"build:abi-ts": "mud abi-ts && prettier --write '**/*.abi.json.d.ts'",
"build:mud": "mud tablegen && mud worldgen",
"deploy:local": "pnpm run build && mud deploy",
"deploy:testnet": "pnpm run build && mud deploy --profile=lattice-testnet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.0;

import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/store/src/MudTest.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol";
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.0;

import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/store/src/MudTest.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.0;

import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/store/src/MudTest.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
Expand Down
1 change: 0 additions & 1 deletion examples/minimal/packages/plugin-example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ out/
cache/
node_modules/
artifacts/
abi/
4 changes: 4 additions & 0 deletions packages/cli/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ allow_paths = ["../../node_modules", "../"]
src = "contracts/src"
out = "contracts/out"
test = "contracts/test"
extra_output_files = [
"abi",
"evm.bytecode"
]
8 changes: 3 additions & 5 deletions packages/cli/src/commands/dev-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ const commandModule: CommandModule<Options, Options> = {
await worldgenHandler({ config, clean: true, srcDir: srcDirectory });

// Build the contracts
await forge(["build"]);
await forge(["build", "--skip", "test", "script"]);

// Generate TS-friendly ABI files
// We rebuild into a separate dir to have a clean set of ABIs without test/script contracts
await forge(["build", "--extra-output-files", "abi", "--out", "abi", "--skip", "test", "script", "MudTest.sol"]);
await execa("mud", ["abi-ts"]);
// Generate TS type definitions for ABIs
await execa("mud", ["abi-ts"], { stdio: "inherit" });
}

/** Run after codegen if either mud config or contracts changed */
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MUDError } from "@latticexyz/common/errors";
import { cast, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
import { StoreConfig } from "@latticexyz/store";
import { resolveWorldConfig, WorldConfig } from "@latticexyz/world";
import IBaseWorldData from "@latticexyz/world/abi/IBaseWorld.sol/IBaseWorld.json" assert { type: "json" };
import IBaseWorldData from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.json" assert { type: "json" };
import worldConfig from "@latticexyz/world/mud.config.js";
import { tableIdToHex } from "@latticexyz/common";
import { getChainId, getExistingContracts } from "../utils";
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { encodeSchema, getStaticByteLength } from "@latticexyz/schema-type/depre
import { StoreConfig } from "@latticexyz/store";
import { resolveAbiOrUserType } from "@latticexyz/store/codegen";
import { WorldConfig, resolveWorldConfig } from "@latticexyz/world";
import IBaseWorldData from "@latticexyz/world/abi/IBaseWorld.sol/IBaseWorld.json" assert { type: "json" };
import WorldData from "@latticexyz/world/abi/World.sol/World.json" assert { type: "json" };
import CoreModuleData from "@latticexyz/world/abi/CoreModule.sol/CoreModule.json" assert { type: "json" };
import KeysWithValueModuleData from "@latticexyz/world/abi/KeysWithValueModule.sol/KeysWithValueModule.json" assert { type: "json" };
import KeysInTableModuleData from "@latticexyz/world/abi/KeysInTableModule.sol/KeysInTableModule.json" assert { type: "json" };
import UniqueEntityModuleData from "@latticexyz/world/abi/UniqueEntityModule.sol/UniqueEntityModule.json" assert { type: "json" };
import IBaseWorldData from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.json" assert { type: "json" };
import WorldData from "@latticexyz/world/out/World.sol/World.json" assert { type: "json" };
import CoreModuleData from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" };
import KeysWithValueModuleData from "@latticexyz/world/out/KeysWithValueModule.sol/KeysWithValueModule.json" assert { type: "json" };
import KeysInTableModuleData from "@latticexyz/world/out/KeysInTableModule.sol/KeysInTableModule.json" assert { type: "json" };
import UniqueEntityModuleData from "@latticexyz/world/out/UniqueEntityModule.sol/UniqueEntityModule.json" assert { type: "json" };
import { tableIdToHex } from "@latticexyz/common";
import { fieldLayoutToHex } from "@latticexyz/protocol-parser";

Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/utils/deployHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { forge, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { getChainId } from "../utils/getChainId";
import { getExistingContracts } from "./getExistingContracts";
import { execa } from "execa";

export type DeployOptions = {
configPath?: string;
Expand Down Expand Up @@ -37,10 +38,15 @@ export async function deployHandler(args: DeployOptions) {
)
);

if (clean) await forge(["clean"], { profile });
if (clean) {
await forge(["clean"], { profile });
}

// Run forge build
if (!skipBuild) await forge(["build"], { profile });
if (!skipBuild) {
await forge(["build", "--skip", "test", "script"], { profile });
await execa("mud", ["abi-ts"], { stdio: "inherit" });
}

// Get a list of all contract names
const srcDir = args?.srcDir ?? (await getSrcDirectory());
Expand Down
1 change: 0 additions & 1 deletion packages/gas-report/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cache
abi
out
docs
_docs
Expand Down
3 changes: 2 additions & 1 deletion packages/gas-report/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*

!abi/**
!out/**/*.abi.json
!out/**/*.abi.json.d.ts
!src/**
!ts/**
!package.json
Expand Down
4 changes: 4 additions & 0 deletions packages/gas-report/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ allow_paths= ["../../node_modules"]
src = "src"
out = "out"
bytecode_hash = "none"
extra_output_files = [
"abi",
"evm.bytecode"
]
4 changes: 4 additions & 0 deletions packages/noise/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ verbosity = 2
allow_paths = ["../../node_modules"]
src = "contracts"
out = "out"
extra_output_files = [
"abi",
"evm.bytecode"
]
1 change: 0 additions & 1 deletion packages/schema-type/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cache
abi
out
dist
docs
Expand Down
4 changes: 4 additions & 0 deletions packages/schema-type/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ allow_paths = ["../../node_modules"]
src = "src/solidity"
out = "out/solidity"
test = "test/solidity"
extra_output_files = [
"abi",
"evm.bytecode"
]
4 changes: 0 additions & 4 deletions packages/store/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ artifacts
yarn-error.log
API
dist

# only check in ABIs
abi/**/*.json
!abi/**/*.abi.json
3 changes: 2 additions & 1 deletion packages/store/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*

!abi/**
!out/**/*.abi.json
!out/**/*.abi.json.d.ts
!src/**
!ts/**
!package.json
Expand Down
1 change: 0 additions & 1 deletion packages/store/abi/Bytes.sol/Bytes.abi.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/store/abi/Callbacks.sol/Callbacks.abi.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/store/abi/DecodeSlice.sol/DecodeSlice.abi.json

This file was deleted.

Loading