@latticexyz/cli 2.0.0-main-76055f45 → 2.0.0-main-e0377761

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/chunk-KX5JLFDL.js +11 -0
  2. package/dist/chunk-KX5JLFDL.js.map +1 -0
  3. package/dist/index.js +1 -1
  4. package/dist/mud.js +6 -6
  5. package/dist/mud.js.map +1 -1
  6. package/package.json +11 -11
  7. package/src/commands/deploy.ts +1 -1
  8. package/src/commands/dev-contracts.ts +1 -3
  9. package/src/commands/test.ts +1 -1
  10. package/src/commands/trace.ts +1 -2
  11. package/src/commands/worldgen.ts +1 -1
  12. package/src/utils/deploy.ts +555 -183
  13. package/src/utils/deployHandler.ts +1 -1
  14. package/src/utils/index.ts +6 -0
  15. package/dist/chunk-3LOTLAJX.js +0 -11
  16. package/dist/chunk-3LOTLAJX.js.map +0 -1
  17. package/src/utils/modules/constants.ts +0 -23
  18. package/src/utils/modules/getInstallModuleCallData.ts +0 -27
  19. package/src/utils/modules/getUserModules.ts +0 -5
  20. package/src/utils/modules/types.ts +0 -14
  21. package/src/utils/systems/getGrantAccessCallData.ts +0 -29
  22. package/src/utils/systems/getRegisterFunctionSelectorsCallData.ts +0 -68
  23. package/src/utils/systems/getRegisterSystemCallData.ts +0 -17
  24. package/src/utils/systems/types.ts +0 -14
  25. package/src/utils/systems/utils.ts +0 -50
  26. package/src/utils/tables/getRegisterTableCallData.ts +0 -40
  27. package/src/utils/tables/getTableIds.ts +0 -21
  28. package/src/utils/tables/types.ts +0 -12
  29. package/src/utils/utils/confirmNonce.ts +0 -24
  30. package/src/utils/utils/deployContract.ts +0 -33
  31. package/src/utils/utils/fastTxExecute.ts +0 -56
  32. package/src/utils/utils/getContractData.ts +0 -29
  33. package/src/utils/utils/postDeploy.ts +0 -25
  34. package/src/utils/utils/setInternalFeePerGas.ts +0 -49
  35. package/src/utils/utils/toBytes16.ts +0 -16
  36. package/src/utils/utils/types.ts +0 -21
  37. package/src/utils/world.ts +0 -28
  38. /package/src/utils/{utils/getChainId.ts → getChainId.ts} +0 -0
@@ -1,56 +0,0 @@
1
- import chalk from "chalk";
2
- import { TransactionReceipt, TransactionResponse } from "@ethersproject/providers";
3
- import { MUDError } from "@latticexyz/common/errors";
4
- import { TxConfig } from "./types";
5
-
6
- /**
7
- * Only await gas estimation (for speed), only execute if gas estimation succeeds (for safety)
8
- */
9
- export async function fastTxExecute<
10
- C extends { connect: any; estimateGas: any; [key: string]: any },
11
- F extends keyof C
12
- >(
13
- input: TxConfig & {
14
- nonce: number;
15
- contract: C;
16
- func: F;
17
- args: Parameters<C[F]>;
18
- confirmations: number;
19
- }
20
- ): Promise<TransactionResponse | TransactionReceipt> {
21
- const {
22
- func,
23
- args,
24
- contract,
25
- signer,
26
- nonce,
27
- maxPriorityFeePerGas,
28
- maxFeePerGas,
29
- gasPrice,
30
- confirmations = 1,
31
- debug,
32
- } = input;
33
- const functionName = `${func as string}(${args.map((arg) => `'${arg}'`).join(",")})`;
34
- try {
35
- const contractWithSigner = contract.connect(signer);
36
- const gasLimit = await contractWithSigner.estimateGas[func].apply(null, args);
37
- console.log(chalk.gray(`executing transaction: ${functionName} with nonce ${nonce}`));
38
- return contractWithSigner[func]
39
- .apply(null, [
40
- ...args,
41
- {
42
- gasLimit,
43
- nonce: nonce,
44
- maxPriorityFeePerGas: maxPriorityFeePerGas,
45
- maxFeePerGas: maxFeePerGas,
46
- gasPrice: gasPrice,
47
- },
48
- ])
49
- .then((tx: TransactionResponse) => {
50
- return confirmations === 0 ? tx : tx.wait(confirmations);
51
- });
52
- } catch (error: any) {
53
- if (debug) console.error(error);
54
- throw new MUDError(`Gas estimation error for ${functionName}: ${error?.reason}`);
55
- }
56
- }
@@ -1,29 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import path from "path";
3
- import { Fragment } from "ethers/lib/utils.js";
4
- import { MUDError } from "@latticexyz/common/errors";
5
-
6
- /**
7
- * Load the contract's abi and bytecode from the file system
8
- * @param contractName: Name of the contract to load
9
- */
10
- export function getContractData(
11
- contractName: string,
12
- forgeOutDirectory: string
13
- ): { bytecode: string; abi: Fragment[] } {
14
- let data: any;
15
- const contractDataPath = path.join(forgeOutDirectory, contractName + ".sol", contractName + ".json");
16
- try {
17
- data = JSON.parse(readFileSync(contractDataPath, "utf8"));
18
- } catch (error: any) {
19
- throw new MUDError(`Error reading file at ${contractDataPath}`);
20
- }
21
-
22
- const bytecode = data?.bytecode?.object;
23
- if (!bytecode) throw new MUDError(`No bytecode found in ${contractDataPath}`);
24
-
25
- const abi = data?.abi;
26
- if (!abi) throw new MUDError(`No ABI found in ${contractDataPath}`);
27
-
28
- return { abi, bytecode };
29
- }
@@ -1,25 +0,0 @@
1
- import { existsSync } from "fs";
2
- import path from "path";
3
- import chalk from "chalk";
4
- import { getScriptDirectory, forge } from "@latticexyz/common/foundry";
5
-
6
- export async function postDeploy(
7
- postDeployScript: string,
8
- worldAddress: string,
9
- rpc: string,
10
- profile: string | undefined
11
- ): Promise<void> {
12
- // Execute postDeploy forge script
13
- const postDeployPath = path.join(await getScriptDirectory(), postDeployScript + ".s.sol");
14
- if (existsSync(postDeployPath)) {
15
- console.log(chalk.blue(`Executing post deploy script at ${postDeployPath}`));
16
- await forge(
17
- ["script", postDeployScript, "--sig", "run(address)", worldAddress, "--broadcast", "--rpc-url", rpc, "-vvv"],
18
- {
19
- profile: profile,
20
- }
21
- );
22
- } else {
23
- console.log(`No script at ${postDeployPath}, skipping post deploy hook`);
24
- }
25
- }
@@ -1,49 +0,0 @@
1
- import { BigNumber, Wallet } from "ethers";
2
- import { MUDError } from "@latticexyz/common/errors";
3
-
4
- /**
5
- * Set the maxFeePerGas and maxPriorityFeePerGas based on the current base fee and the given multiplier.
6
- * The multiplier is used to allow replacing pending transactions.
7
- * @param multiplier Multiplier to apply to the base fee
8
- */
9
- export async function setInternalFeePerGas(
10
- signer: Wallet,
11
- multiplier: number
12
- ): Promise<{
13
- maxPriorityFeePerGas: number | undefined;
14
- maxFeePerGas: BigNumber | undefined;
15
- gasPrice: BigNumber | undefined;
16
- }> {
17
- // Compute maxFeePerGas and maxPriorityFeePerGas like ethers, but allow for a multiplier to allow replacing pending transactions
18
- const feeData = await signer.provider.getFeeData();
19
- let maxPriorityFeePerGas: number | undefined;
20
- let maxFeePerGas: BigNumber | undefined;
21
- let gasPrice: BigNumber | undefined;
22
-
23
- if (feeData.lastBaseFeePerGas) {
24
- if (!feeData.lastBaseFeePerGas.eq(0) && (await signer.getBalance()).eq(0)) {
25
- throw new MUDError(`Attempting to deploy to a chain with non-zero base fee with an account that has no balance.
26
- If you're deploying to the Lattice testnet, you can fund your account by running 'pnpm mud faucet --address ${await signer.getAddress()}'`);
27
- }
28
-
29
- // Set the priority fee to 0 for development chains with no base fee, to allow transactions from unfunded wallets
30
- maxPriorityFeePerGas = feeData.lastBaseFeePerGas.eq(0) ? 0 : Math.floor(1_500_000_000 * multiplier);
31
- maxFeePerGas = feeData.lastBaseFeePerGas.mul(2).add(maxPriorityFeePerGas);
32
- } else if (feeData.gasPrice) {
33
- // Legacy chains with gasPrice instead of maxFeePerGas
34
- if (!feeData.gasPrice.eq(0) && (await signer.getBalance()).eq(0)) {
35
- throw new MUDError(
36
- `Attempting to deploy to a chain with non-zero gas price with an account that has no balance.`
37
- );
38
- }
39
-
40
- gasPrice = feeData.gasPrice;
41
- } else {
42
- throw new MUDError("Can not fetch fee data from RPC");
43
- }
44
- return {
45
- maxPriorityFeePerGas,
46
- maxFeePerGas,
47
- gasPrice,
48
- };
49
- }
@@ -1,16 +0,0 @@
1
- // TODO: use stringToBytes16 from utils as soon as utils are usable inside cli
2
- // (see https://github.com/latticexyz/mud/issues/499)
3
- export function toBytes16(input: string) {
4
- if (input.length > 16) throw new Error("String does not fit into 16 bytes");
5
-
6
- const result = new Uint8Array(16);
7
- // Set ascii bytes
8
- for (let i = 0; i < input.length; i++) {
9
- result[i] = input.charCodeAt(i);
10
- }
11
- // Set the remaining bytes to 0
12
- for (let i = input.length; i < 16; i++) {
13
- result[i] = 0;
14
- }
15
- return result;
16
- }
@@ -1,21 +0,0 @@
1
- import { BigNumber, ContractInterface, ethers } from "ethers";
2
-
3
- export type CallData = {
4
- func: string;
5
- args: unknown[];
6
- };
7
-
8
- export type ContractCode = {
9
- name: string;
10
- abi: ContractInterface;
11
- bytecode: string | { object: string };
12
- };
13
-
14
- export type TxConfig = {
15
- signer: ethers.Wallet;
16
- maxPriorityFeePerGas: number | undefined;
17
- maxFeePerGas: BigNumber | undefined;
18
- gasPrice: BigNumber | undefined;
19
- debug: boolean;
20
- confirmations: number;
21
- };
@@ -1,28 +0,0 @@
1
- import chalk from "chalk";
2
-
3
- import WorldData from "@latticexyz/world/out/World.sol/World.json" assert { type: "json" };
4
- import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" };
5
- import { deployContract } from "./utils/deployContract";
6
- import { getContractData } from "./utils/getContractData";
7
- import { TxConfig } from "./utils/types";
8
-
9
- export async function deployWorldContract(
10
- ip: TxConfig & {
11
- nonce: number;
12
- worldContractName: string | undefined;
13
- forgeOutDirectory: string;
14
- }
15
- ): Promise<string> {
16
- console.log(chalk.blue(`Deploying World`));
17
- const contractData = ip.worldContractName
18
- ? {
19
- name: "World",
20
- ...getContractData(ip.worldContractName, ip.forgeOutDirectory),
21
- }
22
- : { abi: IBaseWorldAbi, bytecode: WorldData.bytecode, name: "World" };
23
- return deployContract({
24
- ...ip,
25
- nonce: ip.nonce,
26
- contract: contractData,
27
- });
28
- }