@latticexyz/cli 2.0.0-main-e667ee80 → 2.0.0-main-e1dc88eb

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/cli",
3
- "version": "2.0.0-main-e667ee80",
3
+ "version": "2.0.0-main-e1dc88eb",
4
4
  "description": "Command line interface for mud",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,6 +31,7 @@
31
31
  "glob": "^8.0.3",
32
32
  "nice-grpc-web": "^2.0.1",
33
33
  "openurl": "^1.1.1",
34
+ "p-retry": "^5.1.2",
34
35
  "path": "^0.12.7",
35
36
  "rxjs": "7.5.5",
36
37
  "throttle-debounce": "^5.0.0",
@@ -39,17 +40,17 @@
39
40
  "yargs": "^17.7.1",
40
41
  "zod": "^3.21.4",
41
42
  "zod-validation-error": "^1.3.0",
42
- "@latticexyz/abi-ts": "2.0.0-main-e667ee80",
43
- "@latticexyz/common": "2.0.0-main-e667ee80",
44
- "@latticexyz/config": "2.0.0-main-e667ee80",
45
- "@latticexyz/gas-report": "2.0.0-main-e667ee80",
46
- "@latticexyz/protocol-parser": "2.0.0-main-e667ee80",
47
- "@latticexyz/schema-type": "2.0.0-main-e667ee80",
48
- "@latticexyz/services": "2.0.0-main-e667ee80",
49
- "@latticexyz/store": "2.0.0-main-e667ee80",
50
- "@latticexyz/utils": "2.0.0-main-e667ee80",
51
- "@latticexyz/world": "2.0.0-main-e667ee80",
52
- "@latticexyz/world-modules": "2.0.0-main-e667ee80"
43
+ "@latticexyz/abi-ts": "2.0.0-main-e1dc88eb",
44
+ "@latticexyz/common": "2.0.0-main-e1dc88eb",
45
+ "@latticexyz/config": "2.0.0-main-e1dc88eb",
46
+ "@latticexyz/gas-report": "2.0.0-main-e1dc88eb",
47
+ "@latticexyz/protocol-parser": "2.0.0-main-e1dc88eb",
48
+ "@latticexyz/schema-type": "2.0.0-main-e1dc88eb",
49
+ "@latticexyz/services": "2.0.0-main-e1dc88eb",
50
+ "@latticexyz/store": "2.0.0-main-e1dc88eb",
51
+ "@latticexyz/utils": "2.0.0-main-e1dc88eb",
52
+ "@latticexyz/world": "2.0.0-main-e1dc88eb",
53
+ "@latticexyz/world-modules": "2.0.0-main-e1dc88eb"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@types/debug": "^4.1.7",
@@ -4,7 +4,7 @@ import { deployWorld } from "./deployWorld";
4
4
  import { ensureTables } from "./ensureTables";
5
5
  import { Config, ConfigInput, WorldDeploy, supportedStoreVersions, supportedWorldVersions } from "./common";
6
6
  import { ensureSystems } from "./ensureSystems";
7
- import { getTransactionReceipt, waitForTransactionReceipt } from "viem/actions";
7
+ import { waitForTransactionReceipt } from "viem/actions";
8
8
  import { getWorldDeploy } from "./getWorldDeploy";
9
9
  import { ensureFunctions } from "./ensureFunctions";
10
10
  import { ensureModules } from "./ensureModules";
@@ -4,6 +4,8 @@ import { deployer } from "./ensureDeployer";
4
4
  import { salt } from "./common";
5
5
  import { sendTransaction } from "@latticexyz/common";
6
6
  import { debug } from "./debug";
7
+ import pRetry from "p-retry";
8
+ import { wait } from "@latticexyz/common/utils";
7
9
 
8
10
  export async function ensureContract({
9
11
  client,
@@ -24,10 +26,21 @@ export async function ensureContract({
24
26
 
25
27
  debug("deploying", label, "at", address);
26
28
  return [
27
- await sendTransaction(client, {
28
- chain: client.chain ?? null,
29
- to: deployer,
30
- data: concatHex([salt, bytecode]),
31
- }),
29
+ await pRetry(
30
+ () =>
31
+ sendTransaction(client, {
32
+ chain: client.chain ?? null,
33
+ to: deployer,
34
+ data: concatHex([salt, bytecode]),
35
+ }),
36
+ {
37
+ retries: 3,
38
+ onFailedAttempt: async (error) => {
39
+ const delay = error.attemptNumber * 500;
40
+ debug(`failed to deploy ${label}, retrying in ${delay}ms...`);
41
+ await wait(delay);
42
+ },
43
+ }
44
+ ),
32
45
  ];
33
46
  }
@@ -3,6 +3,8 @@ import { hexToResource, writeContract } from "@latticexyz/common";
3
3
  import { WorldDeploy, WorldFunction, worldAbi } from "./common";
4
4
  import { debug } from "./debug";
5
5
  import { getFunctions } from "./getFunctions";
6
+ import pRetry from "p-retry";
7
+ import { wait } from "@latticexyz/common/utils";
6
8
 
7
9
  export async function ensureFunctions({
8
10
  client,
@@ -40,23 +42,45 @@ export async function ensureFunctions({
40
42
  toAdd.map((func) => {
41
43
  const { namespace } = hexToResource(func.systemId);
42
44
  if (namespace === "") {
43
- return writeContract(client, {
44
- chain: client.chain ?? null,
45
- address: worldDeploy.address,
46
- abi: worldAbi,
47
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
48
- functionName: "registerRootFunctionSelector",
49
- args: [func.systemId, func.systemFunctionSignature, func.systemFunctionSelector],
50
- });
45
+ return pRetry(
46
+ () =>
47
+ writeContract(client, {
48
+ chain: client.chain ?? null,
49
+ address: worldDeploy.address,
50
+ abi: worldAbi,
51
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
52
+ functionName: "registerRootFunctionSelector",
53
+ args: [func.systemId, func.systemFunctionSignature, func.systemFunctionSelector],
54
+ }),
55
+ {
56
+ retries: 3,
57
+ onFailedAttempt: async (error) => {
58
+ const delay = error.attemptNumber * 500;
59
+ debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`);
60
+ await wait(delay);
61
+ },
62
+ }
63
+ );
51
64
  }
52
- return writeContract(client, {
53
- chain: client.chain ?? null,
54
- address: worldDeploy.address,
55
- abi: worldAbi,
56
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
57
- functionName: "registerFunctionSelector",
58
- args: [func.systemId, func.systemFunctionSignature],
59
- });
65
+ return pRetry(
66
+ () =>
67
+ writeContract(client, {
68
+ chain: client.chain ?? null,
69
+ address: worldDeploy.address,
70
+ abi: worldAbi,
71
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
72
+ functionName: "registerFunctionSelector",
73
+ args: [func.systemId, func.systemFunctionSignature],
74
+ }),
75
+ {
76
+ retries: 3,
77
+ onFailedAttempt: async (error) => {
78
+ const delay = error.attemptNumber * 500;
79
+ debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`);
80
+ await wait(delay);
81
+ },
82
+ }
83
+ );
60
84
  })
61
85
  );
62
86
  }
@@ -3,7 +3,8 @@ import { writeContract } from "@latticexyz/common";
3
3
  import { Module, WorldDeploy, worldAbi } from "./common";
4
4
  import { ensureContract } from "./ensureContract";
5
5
  import { debug } from "./debug";
6
- import { uniqueBy } from "@latticexyz/common/utils";
6
+ import { uniqueBy, wait } from "@latticexyz/common/utils";
7
+ import pRetry from "p-retry";
7
8
 
8
9
  export async function ensureModules({
9
10
  client,
@@ -28,22 +29,44 @@ export async function ensureModules({
28
29
  const installTxs = await Promise.all(
29
30
  modules.map((mod) =>
30
31
  mod.installAsRoot
31
- ? writeContract(client, {
32
- chain: client.chain ?? null,
33
- address: worldDeploy.address,
34
- abi: worldAbi,
35
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
36
- functionName: "installRootModule",
37
- args: [mod.address, mod.installData],
38
- })
39
- : writeContract(client, {
40
- chain: client.chain ?? null,
41
- address: worldDeploy.address,
42
- abi: worldAbi,
43
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
44
- functionName: "installModule",
45
- args: [mod.address, mod.installData],
46
- })
32
+ ? pRetry(
33
+ () =>
34
+ writeContract(client, {
35
+ chain: client.chain ?? null,
36
+ address: worldDeploy.address,
37
+ abi: worldAbi,
38
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
39
+ functionName: "installRootModule",
40
+ args: [mod.address, mod.installData],
41
+ }),
42
+ {
43
+ retries: 3,
44
+ onFailedAttempt: async (error) => {
45
+ const delay = error.attemptNumber * 500;
46
+ debug(`failed to install root module ${mod.name}, retrying in ${delay}ms...`);
47
+ await wait(delay);
48
+ },
49
+ }
50
+ )
51
+ : pRetry(
52
+ () =>
53
+ writeContract(client, {
54
+ chain: client.chain ?? null,
55
+ address: worldDeploy.address,
56
+ abi: worldAbi,
57
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
58
+ functionName: "installModule",
59
+ args: [mod.address, mod.installData],
60
+ }),
61
+ {
62
+ retries: 3,
63
+ onFailedAttempt: async (error) => {
64
+ const delay = error.attemptNumber * 500;
65
+ debug(`failed to install module ${mod.name}, retrying in ${delay}ms...`);
66
+ await wait(delay);
67
+ },
68
+ }
69
+ )
47
70
  )
48
71
  );
49
72
 
@@ -6,7 +6,8 @@ import { debug } from "./debug";
6
6
  import { resourceLabel } from "./resourceLabel";
7
7
  import { getSystems } from "./getSystems";
8
8
  import { getResourceAccess } from "./getResourceAccess";
9
- import { uniqueBy } from "@latticexyz/common/utils";
9
+ import { uniqueBy, wait } from "@latticexyz/common/utils";
10
+ import pRetry from "p-retry";
10
11
 
11
12
  export async function ensureSystems({
12
13
  client,
@@ -54,22 +55,44 @@ export async function ensureSystems({
54
55
 
55
56
  const accessTxs = await Promise.all([
56
57
  ...accessToRemove.map((access) =>
57
- writeContract(client, {
58
- chain: client.chain ?? null,
59
- address: worldDeploy.address,
60
- abi: worldAbi,
61
- functionName: "revokeAccess",
62
- args: [access.resourceId, access.address],
63
- })
58
+ pRetry(
59
+ () =>
60
+ writeContract(client, {
61
+ chain: client.chain ?? null,
62
+ address: worldDeploy.address,
63
+ abi: worldAbi,
64
+ functionName: "revokeAccess",
65
+ args: [access.resourceId, access.address],
66
+ }),
67
+ {
68
+ retries: 3,
69
+ onFailedAttempt: async (error) => {
70
+ const delay = error.attemptNumber * 500;
71
+ debug(`failed to revoke access, retrying in ${delay}ms...`);
72
+ await wait(delay);
73
+ },
74
+ }
75
+ )
64
76
  ),
65
77
  ...accessToAdd.map((access) =>
66
- writeContract(client, {
67
- chain: client.chain ?? null,
68
- address: worldDeploy.address,
69
- abi: worldAbi,
70
- functionName: "grantAccess",
71
- args: [access.resourceId, access.address],
72
- })
78
+ pRetry(
79
+ () =>
80
+ writeContract(client, {
81
+ chain: client.chain ?? null,
82
+ address: worldDeploy.address,
83
+ abi: worldAbi,
84
+ functionName: "grantAccess",
85
+ args: [access.resourceId, access.address],
86
+ }),
87
+ {
88
+ retries: 3,
89
+ onFailedAttempt: async (error) => {
90
+ const delay = error.attemptNumber * 500;
91
+ debug(`failed to grant access, retrying in ${delay}ms...`);
92
+ await wait(delay);
93
+ },
94
+ }
95
+ )
73
96
  ),
74
97
  ]);
75
98
 
@@ -114,14 +137,25 @@ export async function ensureSystems({
114
137
  // then start registering systems
115
138
  const registerTxs = await Promise.all(
116
139
  missingSystems.map((system) =>
117
- writeContract(client, {
118
- chain: client.chain ?? null,
119
- address: worldDeploy.address,
120
- abi: worldAbi,
121
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
122
- functionName: "registerSystem",
123
- args: [system.systemId, system.address, system.allowAll],
124
- })
140
+ pRetry(
141
+ () =>
142
+ writeContract(client, {
143
+ chain: client.chain ?? null,
144
+ address: worldDeploy.address,
145
+ abi: worldAbi,
146
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
147
+ functionName: "registerSystem",
148
+ args: [system.systemId, system.address, system.allowAll],
149
+ }),
150
+ {
151
+ retries: 3,
152
+ onFailedAttempt: async (error) => {
153
+ const delay = error.attemptNumber * 500;
154
+ debug(`failed to register system ${resourceLabel(system)}, retrying in ${delay}ms...`);
155
+ await wait(delay);
156
+ },
157
+ }
158
+ )
125
159
  )
126
160
  );
127
161
 
@@ -6,6 +6,8 @@ import { valueSchemaToFieldLayoutHex, keySchemaToHex, valueSchemaToHex } from "@
6
6
  import { debug } from "./debug";
7
7
  import { resourceLabel } from "./resourceLabel";
8
8
  import { getTables } from "./getTables";
9
+ import pRetry from "p-retry";
10
+ import { wait } from "@latticexyz/common/utils";
9
11
 
10
12
  export async function ensureTables({
11
13
  client,
@@ -29,21 +31,32 @@ export async function ensureTables({
29
31
  debug("registering tables", missingTables.map(resourceLabel).join(", "));
30
32
  return await Promise.all(
31
33
  missingTables.map((table) =>
32
- writeContract(client, {
33
- chain: client.chain ?? null,
34
- address: worldDeploy.address,
35
- abi: worldAbi,
36
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
37
- functionName: "registerTable",
38
- args: [
39
- table.tableId,
40
- valueSchemaToFieldLayoutHex(table.valueSchema),
41
- keySchemaToHex(table.keySchema),
42
- valueSchemaToHex(table.valueSchema),
43
- Object.keys(table.keySchema),
44
- Object.keys(table.valueSchema),
45
- ],
46
- })
34
+ pRetry(
35
+ () =>
36
+ writeContract(client, {
37
+ chain: client.chain ?? null,
38
+ address: worldDeploy.address,
39
+ abi: worldAbi,
40
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
41
+ functionName: "registerTable",
42
+ args: [
43
+ table.tableId,
44
+ valueSchemaToFieldLayoutHex(table.valueSchema),
45
+ keySchemaToHex(table.keySchema),
46
+ valueSchemaToHex(table.valueSchema),
47
+ Object.keys(table.keySchema),
48
+ Object.keys(table.valueSchema),
49
+ ],
50
+ }),
51
+ {
52
+ retries: 3,
53
+ onFailedAttempt: async (error) => {
54
+ const delay = error.attemptNumber * 500;
55
+ debug(`failed to register table ${resourceLabel(table)}, retrying in ${delay}ms...`);
56
+ await wait(delay);
57
+ },
58
+ }
59
+ )
47
60
  )
48
61
  );
49
62
  }
package/src/runDeploy.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { InferredOptionTypes, Options } from "yargs";
4
4
  import { deploy } from "./deploy/deploy";
5
5
  import { createWalletClient, http, Hex } from "viem";