@layerzerolabs/lz-initia-cli 3.0.23 → 3.0.24

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/dist/index.mjs CHANGED
@@ -10,12 +10,7 @@ import { glob } from 'glob';
10
10
  import { $ } from 'zx';
11
11
  import * as crypto from 'node:crypto';
12
12
 
13
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
14
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
15
- }) : x)(function(x) {
16
- if (typeof require !== "undefined") return require.apply(this, arguments);
17
- throw Error('Dynamic require of "' + x + '" is not supported');
18
- });
13
+ // src/build.ts
19
14
  function getInitiaClient(env, config) {
20
15
  const url = config.network?.[env];
21
16
  if (url === void 0) {
@@ -27,127 +22,56 @@ function getInitiaClient(env, config) {
27
22
 
28
23
  // src/constant.ts
29
24
  var InitiaObjectDeployerAddress = "0x1";
30
-
31
- // src/config-parser.ts
32
- function getConfigByNetwork(config, network) {
33
- if (config === null) {
34
- throw new Error("Config is null");
35
- }
36
- if (typeof config === "object") {
37
- return config[network];
38
- }
39
- return config;
40
- }
41
- function getObjectDeployer(configValue, network) {
42
- return getConfigByNetwork(configValue, network);
43
- }
44
- function getObjectDeployerFromConfig(config, network, moduleName) {
45
- const module = config.modules[moduleName];
46
- if (!module) {
47
- throw new Error(`module ${moduleName} not found when getting object deployer`);
48
- }
49
- const moduleObjectDeployer = getObjectDeployer(module.objectDeployer, network);
50
- const defaultObjectDeployer = getObjectDeployer(config.defaultObjectDeployer, network);
51
- return moduleObjectDeployer ?? defaultObjectDeployer ?? InitiaObjectDeployerAddress;
52
- }
53
- function getFullName(config, moduleName) {
54
- const variant = config.modules[moduleName]?.variant;
55
- return variant !== void 0 && variant.length > 0 ? `${moduleName}-${variant}` : moduleName;
56
- }
57
-
58
- // src/loader.ts
59
- function loadConfig(configPath) {
60
- const moduleName = "ts-node";
61
- const tsnode = __require(moduleName);
62
- tsnode.register({
63
- transpileOnly: true,
64
- typeCheck: false
65
- });
66
- try {
67
- const imported = __require(configPath);
68
- return "default" in imported ? imported.default : imported;
69
- } catch (e) {
70
- if (e !== null && typeof e === "object" && "code" in e && e.code === "ERR_REQUIRE_ESM") {
71
- throw new Error(
72
- `Your project is an ESM project (you have "type": "module" set in your package.json) but your LayerZero config file uses the .js extension.`
73
- );
74
- }
75
- throw e;
76
- }
77
- }
78
25
  function isInitiaAccount(account) {
79
26
  return account !== void 0 && account instanceof MnemonicKey;
80
27
  }
81
- function getDeployer(moduleName, lzAptosConfig, network) {
82
- const module = lzAptosConfig.modules[moduleName];
83
- if (!module) {
84
- if (lzAptosConfig.baseModules && lzAptosConfig.baseModules.length > 0) {
85
- for (const baseModule of lzAptosConfig.baseModules) {
86
- const baseConfig = loadConfig(baseModule);
87
- try {
88
- return getDeployer(moduleName, baseConfig, network);
89
- } catch (e) {
90
- }
91
- }
92
- }
93
- throw new Error(
94
- `Module ${moduleName} not found. Make sure it is defined in lz-aptos.config.ts and double check the key is the package name in Move.toml.`
95
- );
96
- }
97
- const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
98
- const defaultDeployer = isInitiaAccount(lzAptosConfig.defaultDeployer) ? lzAptosConfig.defaultDeployer : lzAptosConfig.defaultDeployer?.[network];
99
- const deployer = moduleDeployer ?? defaultDeployer;
100
- if (!deployer) {
101
- throw new Error(`deployer for module ${moduleName} not found`);
102
- }
103
- return deployer;
104
- }
105
- function getDeploymentPath(lzAptosConfig, network, moduleName) {
106
- return path3.join(lzAptosConfig.deploymentPath, network, `${moduleName}.json`);
28
+ function getDeploymentPath(lzInitiaConfig, network, moduleName) {
29
+ const fullName = getFullName(lzInitiaConfig, moduleName);
30
+ return path3.join(lzInitiaConfig.deploymentPath, network, `${fullName}.json`);
107
31
  }
108
- async function checkIfObjectAddressExists(lzAptosConfig, network, address) {
32
+ async function checkIfObjectAddressExists(lzInitiaConfig, network, address) {
109
33
  try {
110
- const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzAptosConfig);
34
+ const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzInitiaConfig);
111
35
  const module = (await client.move.modules(address))[0];
112
36
  return module !== void 0;
113
37
  } catch (e) {
114
38
  return false;
115
39
  }
116
40
  }
117
- function getObjectAddressFromDeployment(lzAptosConfig, network, moduleName) {
118
- const deploymentPath2 = getDeploymentPath(lzAptosConfig, network, moduleName);
41
+ function getObjectAddressFromDeployment(lzInitiaConfig, network, moduleName) {
42
+ const deploymentPath2 = getDeploymentPath(lzInitiaConfig, network, moduleName);
119
43
  if (!fs4.existsSync(deploymentPath2)) {
120
44
  return void 0;
121
45
  }
122
46
  const deployment = JSON.parse(fs4.readFileSync(deploymentPath2, "utf-8"));
123
47
  return deployment.address;
124
48
  }
125
- async function resolveAddress(moduleName, lzAptosConfig, network, isOngoingModule) {
126
- const deployToObject = lzAptosConfig.modules[moduleName]?.deployToObject ?? lzAptosConfig.defaultDeployToObject ?? false;
49
+ async function resolveAddress(moduleKey, lzInitiaConfig, network, isOngoingModule) {
50
+ const deployToObject = lzInitiaConfig.modules[moduleKey]?.deployToObject ?? lzInitiaConfig.defaultDeployToObject ?? false;
127
51
  if (!deployToObject) {
128
- const deployer = getDeployer(moduleName, lzAptosConfig, network);
52
+ const deployer = getDeployerAccount(moduleKey, lzInitiaConfig, network);
129
53
  return AccAddress.toHex(deployer.accAddress);
130
54
  }
131
- const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
55
+ const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleKey);
132
56
  if (objectDeployer !== InitiaObjectDeployerAddress) {
133
- return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
57
+ return genObjectAddressForLayerzero(network, lzInitiaConfig, moduleKey);
134
58
  }
135
- const objectAddress = getObjectAddressFromDeployment(lzAptosConfig, network, moduleName);
59
+ const objectAddress = getObjectAddressFromDeployment(lzInitiaConfig, network, moduleKey);
136
60
  if (objectAddress !== void 0) {
137
- if (await checkIfObjectAddressExists(lzAptosConfig, network, objectAddress)) {
61
+ if (await checkIfObjectAddressExists(lzInitiaConfig, network, objectAddress)) {
138
62
  return objectAddress;
139
63
  }
140
64
  if (!isOngoingModule) {
141
65
  throw new Error(
142
- `Deployment file found at: ${getDeploymentPath(lzAptosConfig, network, moduleName)} but object address ${objectAddress} does not exist. Dependent module ${moduleName} should be deployed if using ${InitiaObjectDeployerAddress}::object_code_deployment.`
66
+ `Deployment file found at: ${getDeploymentPath(lzInitiaConfig, network, moduleKey)} but object address ${objectAddress} does not exist. Dependent module ${moduleKey} should be deployed if using ${InitiaObjectDeployerAddress}::object_code_deployment.`
143
67
  );
144
68
  }
145
69
  } else if (!isOngoingModule) {
146
70
  throw new Error(
147
- `Deployment file not found at: ${getDeploymentPath(lzAptosConfig, network, moduleName)}. Make sure ${moduleName} is deployed.`
71
+ `Deployment file not found at: ${getDeploymentPath(lzInitiaConfig, network, moduleKey)}. Make sure ${moduleKey} is deployed.`
148
72
  );
149
73
  }
150
- return genObjectAddress(moduleName, lzAptosConfig, network);
74
+ return genObjectAddress(moduleKey, lzInitiaConfig, network);
151
75
  }
152
76
  var createObjectAddress = (creatorAddress, seed) => {
153
77
  const hexAddress = AccAddress.validate(creatorAddress) ? AccAddress.toHex(creatorAddress) : creatorAddress;
@@ -156,9 +80,9 @@ var createObjectAddress = (creatorAddress, seed) => {
156
80
  const bytes = new Uint8Array([...creatorBytes, ...seedBytes, 254]);
157
81
  return ensure0x(Buffer.from(sha3_256(bytes)).toString("hex"));
158
82
  };
159
- async function genObjectAddressForOfficial(network, lzAptosConfig, moduleName) {
160
- const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzAptosConfig);
161
- const deployer = getDeployer(moduleName, lzAptosConfig, network);
83
+ async function genObjectAddressForOfficial(network, lzInitiaConfig, moduleKey) {
84
+ const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzInitiaConfig);
85
+ const deployer = getDeployerAccount(moduleKey, lzInitiaConfig, network);
162
86
  const OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR = "initia_std::object_code_deployment";
163
87
  const account = await client.auth.accountInfo(deployer.accAddress);
164
88
  const sequenceNumber = account.getSequenceNumber();
@@ -168,18 +92,60 @@ async function genObjectAddressForOfficial(network, lzAptosConfig, moduleName) {
168
92
  const objectAddress = createObjectAddress(deployer.accAddress, seed);
169
93
  return objectAddress;
170
94
  }
171
- function genObjectAddressForLayerzero(network, lzAptosConfig, moduleName) {
172
- const deployer = getDeployer(moduleName, lzAptosConfig, network);
173
- const seed = getFullName(lzAptosConfig, moduleName);
95
+ function genObjectAddressForLayerzero(network, lzInitiaConfig, moduleName) {
96
+ const deployer = getDeployerAccount(moduleName, lzInitiaConfig, network);
97
+ const seed = getFullName(lzInitiaConfig, moduleName);
174
98
  const objectAddress = createObjectAddress(deployer.accAddress, new Uint8Array(Buffer.from(seed, "utf8")));
175
99
  return objectAddress;
176
100
  }
177
- async function genObjectAddress(moduleName, lzAptosConfig, network) {
178
- const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
101
+ async function genObjectAddress(moduleKey, lzInitiaConfig, network) {
102
+ const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleKey);
179
103
  if (objectDeployer === InitiaObjectDeployerAddress) {
180
- return genObjectAddressForOfficial(network, lzAptosConfig, moduleName);
104
+ return genObjectAddressForOfficial(network, lzInitiaConfig, moduleKey);
181
105
  }
182
- return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
106
+ return genObjectAddressForLayerzero(network, lzInitiaConfig, moduleKey);
107
+ }
108
+
109
+ // src/config-parser.ts
110
+ function getConfigByNetwork(config, network) {
111
+ if (config === null) {
112
+ throw new Error("Config is null");
113
+ }
114
+ if (typeof config === "object") {
115
+ return config[network];
116
+ }
117
+ return config;
118
+ }
119
+ function getObjectDeployer(configValue, network) {
120
+ return getConfigByNetwork(configValue, network);
121
+ }
122
+ function getObjectDeployerFromConfig(config, network, moduleName) {
123
+ const module = config.modules[moduleName];
124
+ if (!module) {
125
+ throw new Error(`module ${moduleName} not found when getting object deployer`);
126
+ }
127
+ const moduleObjectDeployer = getObjectDeployer(module.objectDeployer, network);
128
+ const defaultObjectDeployer = getObjectDeployer(config.defaultObjectDeployer, network);
129
+ return moduleObjectDeployer ?? defaultObjectDeployer ?? InitiaObjectDeployerAddress;
130
+ }
131
+ function getDeployerAccount(moduleName, lzInitiaConfig, network) {
132
+ const module = lzInitiaConfig.modules[moduleName];
133
+ if (!module) {
134
+ throw new Error(
135
+ `Module ${moduleName} not found. Make sure it is defined in lz-initia.config.ts and double check the key is the package name in Move.toml.`
136
+ );
137
+ }
138
+ const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
139
+ const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
140
+ const deployer = moduleDeployer ?? defaultDeployer;
141
+ if (!deployer) {
142
+ throw new Error(`deployer for module ${moduleName} not found`);
143
+ }
144
+ return deployer;
145
+ }
146
+ function getFullName(config, moduleName) {
147
+ const variant = config.modules[moduleName]?.variant;
148
+ return variant !== void 0 && variant.length > 0 ? `${moduleName}-${variant}` : moduleName;
183
149
  }
184
150
  function getRawMoveContextByPath(modulePath) {
185
151
  const tomlPath = path3.join(modulePath, "Move.toml");
@@ -219,40 +185,65 @@ function parseAddresses(addresses, network) {
219
185
  }
220
186
  return result;
221
187
  }
222
- async function getMoveContext(moduleName, lzInitiaConfig, network) {
223
- const module = lzInitiaConfig.modules[moduleName];
188
+ function getPkgName(moduleKey, lzInitiaConfig) {
189
+ const module = lzInitiaConfig.modules[moduleKey];
190
+ if (!module) {
191
+ throw new Error(`module ${moduleKey} not found in lz-initia.config.ts`);
192
+ }
193
+ const tomlPath = path3.join(module.modulePath, "Move.toml");
194
+ if (!fs4.existsSync(tomlPath)) {
195
+ throw new Error(`Move.toml not found in ${tomlPath}`);
196
+ }
197
+ const toml = parse(fs4.readFileSync(tomlPath, "utf-8"));
198
+ return toml.package.name;
199
+ }
200
+ function genModuleKeyToPkgNameMap(lzInitiaConfig) {
201
+ const result = {};
202
+ for (const moduleKey of Object.keys(lzInitiaConfig.modules)) {
203
+ result[getPkgName(moduleKey, lzInitiaConfig)] = moduleKey;
204
+ }
205
+ return result;
206
+ }
207
+ async function getMoveContext(moduleKey, lzInitiaConfig, network) {
208
+ const module = lzInitiaConfig.modules[moduleKey];
224
209
  if (!module) {
225
- throw new Error(`module ${moduleName} not found when getting Move context`);
210
+ throw new Error(`module ${moduleKey} not found when getting Move context`);
226
211
  }
227
212
  const context = getRawMoveContextByPath(module.modulePath);
228
- for (const key of Object.keys(context)) {
229
- const toml = context[key];
213
+ const pkgNameToModuleKey = genModuleKeyToPkgNameMap(lzInitiaConfig);
214
+ for (const pkgName of Object.keys(context)) {
215
+ const toml = context[pkgName];
230
216
  for (const addressKey of Object.keys(toml.addresses)) {
231
217
  const address = toml.addresses[addressKey];
232
218
  const presetAddresses = {
233
- ...parseAddresses(lzInitiaConfig.modules[key]?.addresses, network),
219
+ ...parseAddresses(lzInitiaConfig.modules[pkgNameToModuleKey[pkgName]]?.addresses, network),
234
220
  // dependency or current module config address
235
- ...parseAddresses(lzInitiaConfig.modules[moduleName]?.addresses, network)
221
+ ...parseAddresses(lzInitiaConfig.modules[moduleKey]?.addresses, network)
236
222
  // current module config address
237
223
  };
238
224
  if (address === "_") {
239
225
  if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
240
226
  toml.addresses[addressKey] = presetAddresses[addressKey];
241
227
  } else {
228
+ const isOnGoingModule = moduleKey === pkgNameToModuleKey[addressKey];
242
229
  try {
243
- const isOnGoingModule = moduleName === addressKey;
230
+ if (pkgNameToModuleKey[addressKey] === void 0) {
231
+ throw new Error(
232
+ `Module ${addressKey} not found. Make sure it is defined in lz-initia.config.ts and double check the key is the package name in Move.toml.`
233
+ );
234
+ }
244
235
  toml.addresses[addressKey] = await resolveAddress(
245
- addressKey,
236
+ pkgNameToModuleKey[addressKey],
246
237
  lzInitiaConfig,
247
238
  network,
248
239
  isOnGoingModule
249
240
  );
250
241
  } catch (e) {
251
- if (key === moduleName) {
252
- throw new Error(`Fail to generate context for ${key}. ${e.toString()}`);
242
+ if (isOnGoingModule) {
243
+ throw new Error(`Fail to generate context for ${pkgName}. ${e.toString()}`);
253
244
  } else {
254
245
  throw new Error(
255
- `Fail to generate context for dependent module ${key}. ${e.toString()}`
246
+ `Fail to generate context for dependent module ${pkgName}. ${e.toString()}`
256
247
  );
257
248
  }
258
249
  }
@@ -290,18 +281,20 @@ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
290
281
  const addressesParam = Object.keys(addresses).map((key) => `${key}=${addresses[key]}`).join(",");
291
282
  const defaultOptions = {
292
283
  "--skip-fetch-latest-git-deps": true,
293
- "--named-addresses": addressesParam
284
+ "--named-addresses": addressesParam,
285
+ "--verbose": true
294
286
  };
295
287
  const args = parseOptions(defaultOptions, customOptions);
288
+ console.log(`initiad move build ${args.join(" ")}`);
296
289
  return $({
297
290
  cwd: modulePath,
298
- stdio: ["inherit", "pipe", process.stderr],
299
- verbose: true
291
+ // pipe std error to avoid printing the compiling message which is not useful
292
+ stdio: ["inherit", "inherit", "pipe"],
293
+ quiet: true
300
294
  })`initiad move build ${args}`;
301
295
  }
302
296
  async function copyArtifacts(src, dest) {
303
297
  if (fs4.existsSync(dest)) {
304
- console.log(`Removing existing artifacts at ${dest}`);
305
298
  fs4.rmSync(dest, { recursive: true });
306
299
  }
307
300
  fs4.mkdirSync(dest, { recursive: true });
@@ -313,24 +306,22 @@ async function copyArtifacts(src, dest) {
313
306
  fs4.mkdirSync(destByteCodePath, { recursive: true });
314
307
  }
315
308
  await $({
316
- verbose: true
309
+ verbose: false,
310
+ quiet: true
317
311
  })`cp ${path3.join(moduleDir, module)} ${path3.join(destByteCodePath, module)}`;
318
312
  }
319
313
  }
320
- async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
321
- const module = lzInitiaConfig.modules[moduleName];
314
+ async function build(moduleKey, lzInitiaConfig, network, skipBuild = false, variant) {
315
+ const module = lzInitiaConfig.modules[moduleKey];
322
316
  if (!module) {
323
- throw new Error(`module ${moduleName} not found in lz-initia.config.ts`);
317
+ throw new Error(`module ${moduleKey} not found in lz-initia.config.ts`);
324
318
  }
325
319
  const { modulePath } = module;
326
- const context = await getMoveContext(moduleName, lzInitiaConfig, network);
327
- const pkgName = context[moduleName].package.name;
320
+ const context = await getMoveContext(moduleKey, lzInitiaConfig, network);
321
+ const pkgName = context[moduleKey].package.name;
328
322
  const srcPath = path3.join(modulePath, "build", pkgName);
329
- const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
330
- const outputPath = path3.join(
331
- lzInitiaConfig.artifactsPath,
332
- variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
333
- );
323
+ const outputDir = getFullName(lzInitiaConfig, moduleKey);
324
+ const outputPath = path3.join(lzInitiaConfig.artifactsPath, outputDir);
334
325
  let addresses = {};
335
326
  for (const key of Object.keys(context)) {
336
327
  const toml = context[key];
@@ -339,9 +330,9 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
339
330
  }
340
331
  addresses = { ...addresses, ...toml.addresses };
341
332
  }
342
- addresses = { ...addresses, ...context[moduleName].addresses };
333
+ addresses = { ...addresses, ...context[pkgName].addresses };
343
334
  if (!skipBuild) {
344
- await buildProcess(modulePath, addresses, context[moduleName], {
335
+ await buildProcess(modulePath, addresses, context[pkgName], {
345
336
  ...lzInitiaConfig.compileOptions,
346
337
  ...module.compileOptions
347
338
  });
@@ -351,17 +342,17 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
351
342
  function isAxiosError(error) {
352
343
  return error?.response?.data?.message !== void 0;
353
344
  }
354
- function handleDepMissingError(error, moduleName, context) {
345
+ function handleDepMissingError(error, pkgName, context) {
355
346
  if (error.response.data.message.includes("EPACKAGE_DEP_MISSING")) {
356
347
  throw new Error(
357
- `Deploy ${moduleName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
348
+ `Deploy ${pkgName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
358
349
  context
359
- ).filter((module) => module !== moduleName).join(",")}]`
350
+ ).filter((module) => module !== pkgName).join(",")}]`
360
351
  );
361
352
  }
362
353
  }
363
- function handleAccountNotFoundError(error, moduleName, context, network) {
364
- const address = context[moduleName]?.addresses[moduleName];
354
+ function handleAccountNotFoundError(error, pkgName, context, network) {
355
+ const address = context[pkgName]?.addresses[pkgName];
365
356
  if (address === void 0) {
366
357
  return;
367
358
  }
@@ -371,31 +362,31 @@ function handleAccountNotFoundError(error, moduleName, context, network) {
371
362
  );
372
363
  }
373
364
  }
374
- function handleSenderNotMatchError(error, moduleName) {
365
+ function handleSenderNotMatchError(error, pkgName) {
375
366
  if (error.response.data.message.includes("MODULE_ADDRESS_DOES_NOT_MATCH_SENDER")) {
376
367
  throw new Error(
377
- `Deploy ${moduleName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${moduleName} with the deployer account address`
368
+ `Deploy ${pkgName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${pkgName} with the deployer account address`
378
369
  );
379
370
  }
380
371
  }
381
372
  function handleOtherAxiosError(error) {
382
373
  throw new Error(error.response.data.message);
383
374
  }
384
- function handleError(error, moduleName, context, network) {
375
+ function handleError(error, pkgName, context, network) {
385
376
  if (isAxiosError(error)) {
386
- handleDepMissingError(error, moduleName, context);
387
- handleAccountNotFoundError(error, moduleName, context, network);
388
- handleSenderNotMatchError(error, moduleName);
377
+ handleDepMissingError(error, pkgName, context);
378
+ handleAccountNotFoundError(error, pkgName, context, network);
379
+ handleSenderNotMatchError(error, pkgName);
389
380
  handleOtherAxiosError(error);
390
381
  }
391
382
  throw error;
392
383
  }
393
- function deploymentPath(pkgName, dest, network, variant) {
384
+ function deploymentPath(moduleKey, dest, network, variant) {
394
385
  const deploymentPath2 = path3.join(dest, network);
395
- return path3.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
386
+ return path3.join(deploymentPath2, `${moduleKeyWithVariant(moduleKey, variant)}.json`);
396
387
  }
397
- function saveDeployment(deployer, moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
398
- const destPath = deploymentPath(pkgName, dest, network, variant);
388
+ function saveDeployment(deployer, moduleKey, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
389
+ const destPath = deploymentPath(moduleKey, dest, network, variant);
399
390
  const deploymentDir = path3.dirname(destPath);
400
391
  if (!fs4.existsSync(deploymentDir)) {
401
392
  fs4.mkdirSync(deploymentDir, { recursive: true });
@@ -406,8 +397,8 @@ function saveDeployment(deployer, moduleName, pkgName, address, dest, network, b
406
397
  {
407
398
  address,
408
399
  deployer: AccAddress.toHex(deployer.accAddress),
409
- name: pkgWithVariant(pkgName, variant),
410
- moduleName,
400
+ name: moduleKeyWithVariant(moduleKey, variant),
401
+ moduleName: pkgName,
411
402
  network,
412
403
  compatibleVersions,
413
404
  bytecodeHash,
@@ -419,10 +410,10 @@ function saveDeployment(deployer, moduleName, pkgName, address, dest, network, b
419
410
  );
420
411
  console.log(`Deployment saved to ${destPath}`);
421
412
  }
422
- async function checkIfModuleExistedOnAddress(client, moduleNames, address) {
413
+ async function checkIfModuleExistedOnAddress(client, mvNames, address) {
423
414
  try {
424
415
  const modules = (await client.move.modules(address))[0];
425
- const isExisted = moduleNames.some(
416
+ const isExisted = mvNames.some(
426
417
  (moduleName) => modules.map((module) => module.module_name).includes(moduleName.replace(".mv", ""))
427
418
  );
428
419
  return isExisted;
@@ -430,10 +421,10 @@ async function checkIfModuleExistedOnAddress(client, moduleNames, address) {
430
421
  return false;
431
422
  }
432
423
  }
433
- async function getDeployActionType(client, pkgName, moduleNames, dest, network, bytecodeHash, deployAddress, variant) {
434
- const moduleExisted = await checkIfModuleExistedOnAddress(client, moduleNames, deployAddress);
424
+ async function getDeployActionType(client, moduleKey, mvNames, dest, network, bytecodeHash, deployAddress, variant) {
425
+ const moduleExisted = await checkIfModuleExistedOnAddress(client, mvNames, deployAddress);
435
426
  if (moduleExisted) {
436
- const destPath = deploymentPath(pkgName, dest, network, variant);
427
+ const destPath = deploymentPath(moduleKey, dest, network, variant);
437
428
  if (fs4.existsSync(destPath)) {
438
429
  const deployment = JSON.parse(fs4.readFileSync(destPath, "utf-8"));
439
430
  if (deployment.bytecodeHash === bytecodeHash) {
@@ -444,8 +435,8 @@ async function getDeployActionType(client, pkgName, moduleNames, dest, network,
444
435
  }
445
436
  return "Deploy" /* Deploy */;
446
437
  }
447
- function pkgWithVariant(pkgName, variant) {
448
- return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
438
+ function moduleKeyWithVariant(moduleKey, variant) {
439
+ return variant !== void 0 && variant.length > 0 ? `${moduleKey}-${variant}` : moduleKey;
449
440
  }
450
441
  function getBytecodesHash(bytecodes) {
451
442
  const hash = crypto.createHash("sha256");
@@ -467,14 +458,14 @@ async function createAccountDeploymentTx(client, deployer, modules, lzInitiaConf
467
458
  const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
468
459
  return signedTx;
469
460
  }
470
- async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network, moduleName, deployedAddress, actionType) {
471
- const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleName);
461
+ async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network, moduleKey, deployedAddress, actionType) {
462
+ const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleKey);
472
463
  const metadataArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from([])).toBase64();
473
464
  const modulesArg = bcs.vector(bcs.vector(bcs.u8())).serialize(modules).toBase64();
474
465
  const objectAddressArg = bcs.address().serialize(deployedAddress).toBase64();
475
466
  let functionArguments = actionType === "Deploy" /* Deploy */ ? [metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
476
467
  if (objectDeployer !== InitiaObjectDeployerAddress) {
477
- const seed = getFullName(lzInitiaConfig, moduleName);
468
+ const seed = getFullName(lzInitiaConfig, moduleKey);
478
469
  const seedArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from(Buffer.from(seed))).toBase64();
479
470
  functionArguments = actionType === "Deploy" /* Deploy */ ? [seedArg, metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
480
471
  }
@@ -491,24 +482,27 @@ async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfi
491
482
  const signedTx = await wallet.createAndSignTx({ msgs: [msg], gasPrices });
492
483
  return signedTx;
493
484
  }
494
- async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObject = false) {
495
- const module = lzInitiaConfig.modules[moduleName];
485
+ async function deploy(moduleKey, lzInitiaConfig, network, variant, deployToObject = false) {
486
+ const module = lzInitiaConfig.modules[moduleKey];
496
487
  if (!module) {
497
- throw new Error(`module ${moduleName} not found in lz-initia.config.ts`);
488
+ throw new Error(`module ${moduleKey} not found in lz-initia.config.ts`);
498
489
  }
499
490
  const env = networkToEnv(network, EndpointVersion.V2);
500
491
  const client = getInitiaClient(env, lzInitiaConfig);
501
- const deployer = getDeployer(moduleName, lzInitiaConfig, network);
502
- const context = await getMoveContext(moduleName, lzInitiaConfig, network);
503
- const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
504
- const moduleDir = path3.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
492
+ const deployer = getDeployerAccount(moduleKey, lzInitiaConfig, network);
493
+ const context = await getMoveContext(moduleKey, lzInitiaConfig, network);
494
+ const pkgName = getPkgName(moduleKey, lzInitiaConfig);
495
+ const moduleDir = path3.join(
496
+ lzInitiaConfig.artifactsPath,
497
+ `${moduleKeyWithVariant(pkgName, variant)}/bytecode_modules`
498
+ );
505
499
  const mvNames = glob.sync("*.mv", { cwd: moduleDir });
506
- const moduleBuffers = mvNames.map((moduleName2) => fs4.readFileSync(path3.join(moduleDir, moduleName2)));
500
+ const moduleBuffers = mvNames.map((moduleName) => fs4.readFileSync(path3.join(moduleDir, moduleName)));
507
501
  const bytecodeHash = getBytecodesHash(moduleBuffers);
508
- const deployAddress = await resolveAddress(moduleName, lzInitiaConfig, network, true);
502
+ const deployAddress = await resolveAddress(moduleKey, lzInitiaConfig, network, true);
509
503
  const actionType = await getDeployActionType(
510
504
  client,
511
- moduleName,
505
+ moduleKey,
512
506
  mvNames,
513
507
  lzInitiaConfig.deploymentPath,
514
508
  network,
@@ -517,7 +511,7 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
517
511
  variant
518
512
  );
519
513
  if (actionType === "Skip" /* Skip */) {
520
- console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
514
+ console.warn(`Code of ${moduleKey} has not changed, skipping deploy`);
521
515
  return;
522
516
  }
523
517
  try {
@@ -527,7 +521,7 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
527
521
  moduleBuffers,
528
522
  lzInitiaConfig,
529
523
  network,
530
- moduleName,
524
+ moduleKey,
531
525
  deployAddress,
532
526
  actionType
533
527
  ) : await createAccountDeploymentTx(client, deployer, moduleBuffers, lzInitiaConfig, network);
@@ -543,11 +537,11 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
543
537
  throw new Error(tx.raw_log);
544
538
  }
545
539
  console.log(
546
- `${actionType} ${moduleName} to ${deployToObject ? "Object" : "Account"}(${codeAddress}) succeeded on ${network}`
540
+ `${actionType} ${moduleKey} to ${deployToObject ? "Object" : "Account"}(${codeAddress}) succeeded on ${network}`
547
541
  );
548
542
  saveDeployment(
549
543
  deployer,
550
- moduleName,
544
+ moduleKey,
551
545
  pkgName,
552
546
  codeAddress,
553
547
  lzInitiaConfig.deploymentPath,
@@ -559,7 +553,7 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
559
553
  );
560
554
  } catch (e) {
561
555
  if (e instanceof Error) {
562
- handleError(e, moduleName, context, network);
556
+ handleError(e, moduleKey, context, network);
563
557
  } else {
564
558
  throw e;
565
559
  }