@layerzerolabs/lz-initia-cli 3.0.19 → 3.0.20-move.0

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/README.md CHANGED
@@ -121,4 +121,6 @@ yarn lz-initia-cli build -m layerzero_common -n initia-sandbox-local -p path/to/
121
121
  yarn lz-initia-cli deploy -m layerzero_common -n initia-sandbox-local
122
122
  # deploy the contracts with a variant
123
123
  yarn lz-initia-cli deploy -m layerzero_common -n initia-sandbox-local --variant nethermind
124
+ # deploy the contracts to Object
125
+ yarn lz-initia-cli deploy -m layerzero_common -n initia-sandbox-local -dto
124
126
  ```
package/dist/cli.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var fs2 = require('fs');
4
- var path3 = require('path');
3
+ var fs3 = require('fs');
4
+ var path4 = require('path');
5
5
  var process2 = require('process');
6
6
  var extraTypings = require('@commander-js/extra-typings');
7
7
  var findUp = require('find-up');
@@ -9,9 +9,10 @@ var core = require('zx/core');
9
9
  var lzUtilities = require('@layerzerolabs/lz-utilities');
10
10
  var crypto = require('crypto');
11
11
  var initia_js = require('@initia/initia.js');
12
+ var sha3 = require('@noble/hashes/sha3');
13
+ var lzDefinitions = require('@layerzerolabs/lz-definitions');
12
14
  var smolToml = require('smol-toml');
13
15
  var glob = require('glob');
14
- var lzDefinitions = require('@layerzerolabs/lz-definitions');
15
16
  var zx = require('zx');
16
17
 
17
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -34,8 +35,8 @@ function _interopNamespace(e) {
34
35
  return Object.freeze(n);
35
36
  }
36
37
 
37
- var fs2__default = /*#__PURE__*/_interopDefault(fs2);
38
- var path3__default = /*#__PURE__*/_interopDefault(path3);
38
+ var fs3__default = /*#__PURE__*/_interopDefault(fs3);
39
+ var path4__default = /*#__PURE__*/_interopDefault(path4);
39
40
  var process2__default = /*#__PURE__*/_interopDefault(process2);
40
41
  var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
41
42
 
@@ -86,14 +87,44 @@ function getInitiaClient(env, config) {
86
87
  const lcd = new initia_js.LCDClient(url);
87
88
  return lcd;
88
89
  }
90
+
91
+ // src/constant.ts
92
+ var InitiaObjectDeployerAddress = "0x1";
93
+
94
+ // src/config-parser.ts
95
+ function getConfigByNetwork(config, network) {
96
+ if (config === null) {
97
+ throw new Error("Config is null");
98
+ }
99
+ if (typeof config === "object") {
100
+ return config[network];
101
+ }
102
+ return config;
103
+ }
104
+ function getObjectDeployer(configValue, network) {
105
+ return getConfigByNetwork(configValue, network);
106
+ }
107
+ function getObjectDeployerFromConfig(config, network, moduleName) {
108
+ const module = config.modules[moduleName];
109
+ if (!module) {
110
+ throw new Error(`module ${moduleName} not found when getting object deployer`);
111
+ }
112
+ const moduleObjectDeployer = getObjectDeployer(module.objectDeployer, network);
113
+ const defaultObjectDeployer = getObjectDeployer(config.defaultObjectDeployer, network);
114
+ return moduleObjectDeployer ?? defaultObjectDeployer ?? InitiaObjectDeployerAddress;
115
+ }
116
+ function getFullName(config, moduleName) {
117
+ const variant = config.modules[moduleName]?.variant;
118
+ return variant !== void 0 && variant.length > 0 ? `${moduleName}-${variant}` : moduleName;
119
+ }
89
120
  function isInitiaAccount(account) {
90
121
  return account !== void 0 && account instanceof initia_js.MnemonicKey;
91
122
  }
92
- function getDeployer(moduleName, lzInitiaConfig, network) {
93
- const module = lzInitiaConfig.modules[moduleName];
123
+ function getDeployer(moduleName, lzAptosConfig, network) {
124
+ const module = lzAptosConfig.modules[moduleName];
94
125
  if (!module) {
95
- if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {
96
- for (const baseModule of lzInitiaConfig.baseModules) {
126
+ if (lzAptosConfig.baseModules && lzAptosConfig.baseModules.length > 0) {
127
+ for (const baseModule of lzAptosConfig.baseModules) {
97
128
  const baseConfig = loadConfig(baseModule);
98
129
  try {
99
130
  return getDeployer(moduleName, baseConfig, network);
@@ -102,17 +133,96 @@ function getDeployer(moduleName, lzInitiaConfig, network) {
102
133
  }
103
134
  }
104
135
  throw new Error(
105
- `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
+ `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.`
106
137
  );
107
138
  }
108
139
  const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
109
- const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
140
+ const defaultDeployer = isInitiaAccount(lzAptosConfig.defaultDeployer) ? lzAptosConfig.defaultDeployer : lzAptosConfig.defaultDeployer?.[network];
110
141
  const deployer = moduleDeployer ?? defaultDeployer;
111
142
  if (!deployer) {
112
143
  throw new Error(`deployer for module ${moduleName} not found`);
113
144
  }
114
145
  return deployer;
115
146
  }
147
+ function getDeploymentPath(lzAptosConfig, network, moduleName) {
148
+ return path4__default.default.join(lzAptosConfig.deploymentPath, network, `${moduleName}.json`);
149
+ }
150
+ async function checkIfObjectAddressExists(lzAptosConfig, network, address) {
151
+ try {
152
+ const client = getInitiaClient(lzDefinitions.networkToEnv(network, lzDefinitions.EndpointVersion.V2), lzAptosConfig);
153
+ const object = await client.auth.accountInfo(address);
154
+ return object !== void 0;
155
+ } catch (e) {
156
+ return false;
157
+ }
158
+ }
159
+ function getObjectAddressFromDeployment(lzAptosConfig, network, moduleName) {
160
+ const deploymentPath2 = getDeploymentPath(lzAptosConfig, network, moduleName);
161
+ if (!fs3__default.default.existsSync(deploymentPath2)) {
162
+ return void 0;
163
+ }
164
+ const deployment = JSON.parse(fs3__default.default.readFileSync(deploymentPath2, "utf-8"));
165
+ return deployment.address;
166
+ }
167
+ async function resolveAddress(moduleName, lzAptosConfig, network, isOngoingModule) {
168
+ const deployToObject = lzAptosConfig.modules[moduleName]?.deployToObject ?? lzAptosConfig.defaultDeployToObject ?? false;
169
+ if (!deployToObject) {
170
+ const deployer = getDeployer(moduleName, lzAptosConfig, network);
171
+ return initia_js.AccAddress.toHex(deployer.accAddress);
172
+ }
173
+ const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
174
+ if (objectDeployer !== InitiaObjectDeployerAddress) {
175
+ return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
176
+ }
177
+ const objectAddress = getObjectAddressFromDeployment(lzAptosConfig, network, moduleName);
178
+ if (objectAddress !== void 0) {
179
+ if (await checkIfObjectAddressExists(lzAptosConfig, network, objectAddress)) {
180
+ return objectAddress;
181
+ }
182
+ if (!isOngoingModule) {
183
+ throw new Error(
184
+ `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.`
185
+ );
186
+ }
187
+ } else if (!isOngoingModule) {
188
+ throw new Error(
189
+ `Deployment file not found at: ${getDeploymentPath(lzAptosConfig, network, moduleName)}. Make sure ${moduleName} is deployed.`
190
+ );
191
+ }
192
+ return genObjectAddress(moduleName, lzAptosConfig, network);
193
+ }
194
+ var createObjectAddress = (creatorAddress, seed) => {
195
+ const hexAddress = initia_js.AccAddress.validate(creatorAddress) ? initia_js.AccAddress.toHex(creatorAddress) : creatorAddress;
196
+ const creatorBytes = initia_js.bcs.address().serialize(hexAddress).toBytes();
197
+ const seedBytes = typeof seed === "string" ? Buffer.from(seed, "utf8") : seed;
198
+ const bytes = new Uint8Array([...creatorBytes, ...seedBytes, 254]);
199
+ return lzUtilities.ensure0x(Buffer.from(sha3.sha3_256(bytes)).toString("hex"));
200
+ };
201
+ async function genObjectAddressForOfficial(network, lzAptosConfig, moduleName) {
202
+ const client = getInitiaClient(lzDefinitions.networkToEnv(network, lzDefinitions.EndpointVersion.V2), lzAptosConfig);
203
+ const deployer = getDeployer(moduleName, lzAptosConfig, network);
204
+ const OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR = "aptos_framework::object_code_deployment";
205
+ const account = await client.auth.accountInfo(deployer.accAddress);
206
+ const sequenceNumber = account.getSequenceNumber();
207
+ const firstPart = initia_js.bcs.string().serialize(OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR);
208
+ const secondPart = initia_js.bcs.u64().serialize(BigInt(sequenceNumber) + BigInt(1));
209
+ const seed = new Uint8Array([...firstPart.toBytes(), ...secondPart.toBytes()]);
210
+ const objectAddress = createObjectAddress(deployer.accAddress, seed);
211
+ return objectAddress;
212
+ }
213
+ function genObjectAddressForLayerzero(network, lzAptosConfig, moduleName) {
214
+ const deployer = getDeployer(moduleName, lzAptosConfig, network);
215
+ const seed = getFullName(lzAptosConfig, moduleName);
216
+ const objectAddress = createObjectAddress(deployer.accAddress, new Uint8Array(Buffer.from(seed, "utf8")));
217
+ return objectAddress.toString();
218
+ }
219
+ async function genObjectAddress(moduleName, lzAptosConfig, network) {
220
+ const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
221
+ if (objectDeployer === InitiaObjectDeployerAddress) {
222
+ return genObjectAddressForOfficial(network, lzAptosConfig, moduleName);
223
+ }
224
+ return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
225
+ }
116
226
  function isAxiosError(error) {
117
227
  return error?.response?.data?.message !== void 0;
118
228
  }
@@ -156,11 +266,11 @@ function handleError(error, moduleName, context, network) {
156
266
  throw error;
157
267
  }
158
268
  function getRawMoveContextByPath(modulePath) {
159
- const tomlPath = path3__default.default.join(modulePath, "Move.toml");
160
- if (!fs2__default.default.existsSync(tomlPath)) {
269
+ const tomlPath = path4__default.default.join(modulePath, "Move.toml");
270
+ if (!fs3__default.default.existsSync(tomlPath)) {
161
271
  throw new Error(`Move.toml not found in ${tomlPath}`);
162
272
  }
163
- const toml = smolToml.parse(fs2__default.default.readFileSync(tomlPath, "utf-8"));
273
+ const toml = smolToml.parse(fs3__default.default.readFileSync(tomlPath, "utf-8"));
164
274
  const { dependencies } = toml;
165
275
  let result = { [toml.package.name]: toml };
166
276
  if (dependencies !== void 0) {
@@ -168,7 +278,7 @@ function getRawMoveContextByPath(modulePath) {
168
278
  return dependencies[key]?.local !== void 0;
169
279
  }).forEach((key) => {
170
280
  const dependency = dependencies[key];
171
- const dependencyPath = path3__default.default.join(modulePath, dependency.local);
281
+ const dependencyPath = path4__default.default.join(modulePath, dependency.local);
172
282
  result = { ...getRawMoveContextByPath(dependencyPath), ...result };
173
283
  });
174
284
  }
@@ -193,7 +303,7 @@ function parseAddresses(addresses, network) {
193
303
  }
194
304
  return result;
195
305
  }
196
- function getMoveContext(moduleName, lzInitiaConfig, network) {
306
+ async function getMoveContext(moduleName, lzInitiaConfig, network) {
197
307
  const module = lzInitiaConfig.modules[moduleName];
198
308
  if (!module) {
199
309
  throw new Error(`module ${moduleName} not found when getting Move context`);
@@ -205,15 +315,21 @@ function getMoveContext(moduleName, lzInitiaConfig, network) {
205
315
  const address = toml.addresses[addressKey];
206
316
  const presetAddresses = {
207
317
  ...parseAddresses(lzInitiaConfig.modules[key]?.addresses, network),
318
+ // dependency or current module config address
208
319
  ...parseAddresses(lzInitiaConfig.modules[moduleName]?.addresses, network)
320
+ // current module config address
209
321
  };
210
322
  if (address === "_") {
211
323
  if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
212
324
  toml.addresses[addressKey] = presetAddresses[addressKey];
213
325
  } else {
214
326
  try {
215
- toml.addresses[addressKey] = initia_js.AccAddress.toHex(
216
- getDeployer(addressKey, lzInitiaConfig, network).accAddress
327
+ const isOnGoingModule = moduleName === addressKey;
328
+ toml.addresses[addressKey] = await resolveAddress(
329
+ addressKey,
330
+ lzInitiaConfig,
331
+ network,
332
+ isOnGoingModule
217
333
  );
218
334
  } catch (e) {
219
335
  if (key === moduleName) {
@@ -231,20 +347,21 @@ function getMoveContext(moduleName, lzInitiaConfig, network) {
231
347
  return context;
232
348
  }
233
349
  function deploymentPath(pkgName, dest, network, variant) {
234
- const deploymentPath2 = path3__default.default.join(dest, network);
235
- return path3__default.default.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
350
+ const deploymentPath2 = path4__default.default.join(dest, network);
351
+ return path4__default.default.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
236
352
  }
237
- function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [lzDefinitions.EndpointVersion.V1, lzDefinitions.EndpointVersion.V2]) {
353
+ function saveDeployment(deployer, moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [lzDefinitions.EndpointVersion.V1, lzDefinitions.EndpointVersion.V2]) {
238
354
  const destPath = deploymentPath(pkgName, dest, network, variant);
239
- const deploymentDir = path3__default.default.dirname(destPath);
240
- if (!fs2__default.default.existsSync(deploymentDir)) {
241
- fs2__default.default.mkdirSync(deploymentDir, { recursive: true });
355
+ const deploymentDir = path4__default.default.dirname(destPath);
356
+ if (!fs3__default.default.existsSync(deploymentDir)) {
357
+ fs3__default.default.mkdirSync(deploymentDir, { recursive: true });
242
358
  }
243
- fs2__default.default.writeFileSync(
359
+ fs3__default.default.writeFileSync(
244
360
  destPath,
245
361
  JSON.stringify(
246
362
  {
247
363
  address,
364
+ deployer: initia_js.AccAddress.toHex(deployer.accAddress),
248
365
  name: pkgWithVariant(pkgName, variant),
249
366
  moduleName,
250
367
  network,
@@ -258,16 +375,35 @@ function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHas
258
375
  );
259
376
  console.log(`Deployment saved to ${destPath}`);
260
377
  }
261
- function needDeploy(pkgName, dest, network, bytecodeHash, variant) {
262
- if (lzDefinitions.networkToStage(network) === lzDefinitions.Stage.SANDBOX) {
263
- return true;
378
+ async function checkIfModuleExistedOnChain(client, moduleNames, address) {
379
+ try {
380
+ const modules = (await client.move.modules(address))[0];
381
+ return moduleNames.some(
382
+ (moduleName) => modules.map((module) => module.module_name).includes(moduleName.replace(".mv", ""))
383
+ );
384
+ } catch (e) {
385
+ try {
386
+ const object = await client.auth.accountInfo(address);
387
+ return object !== void 0;
388
+ } catch (e2) {
389
+ return false;
390
+ }
264
391
  }
392
+ }
393
+ async function getDeployActionType(client, pkgName, moduleNames, dest, network, bytecodeHash, variant) {
265
394
  const destPath = deploymentPath(pkgName, dest, network, variant);
266
- if (fs2__default.default.existsSync(destPath)) {
267
- const deployment = JSON.parse(fs2__default.default.readFileSync(destPath, "utf-8"));
268
- return deployment.bytecodeHash !== bytecodeHash;
395
+ if (fs3__default.default.existsSync(destPath)) {
396
+ const deployment = JSON.parse(fs3__default.default.readFileSync(destPath, "utf-8"));
397
+ const moduleExisted = await checkIfModuleExistedOnChain(client, moduleNames, deployment.address);
398
+ if (moduleExisted) {
399
+ if (deployment.bytecodeHash !== bytecodeHash || network.includes("local")) {
400
+ return { actionType: "Upgrade" /* Upgrade */, address: deployment.address };
401
+ } else {
402
+ return { actionType: "Skip" /* Skip */, address: deployment.address };
403
+ }
404
+ }
269
405
  }
270
- return true;
406
+ return { actionType: "Deploy" /* Deploy */, address: void 0 };
271
407
  }
272
408
  function pkgWithVariant(pkgName, variant) {
273
409
  return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
@@ -279,7 +415,44 @@ function getBytecodesHash(bytecodes) {
279
415
  });
280
416
  return hash.digest("hex");
281
417
  }
282
- async function deploy(moduleName, lzInitiaConfig, network, variant) {
418
+ async function createAccountDeploymentTx(client, deployer, modules, lzInitiaConfig, network) {
419
+ const msgs = [
420
+ new initia_js.MsgPublish(
421
+ deployer.accAddress,
422
+ modules.map((codeBytes) => codeBytes.toString("base64")),
423
+ initia_js.MsgPublish.Policy.COMPATIBLE
424
+ )
425
+ ];
426
+ const wallet = new initia_js.Wallet(client, deployer);
427
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
428
+ const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
429
+ return signedTx;
430
+ }
431
+ async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network, moduleName, objectAddress) {
432
+ const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleName);
433
+ const metadataArg = initia_js.bcs.vector(initia_js.bcs.u8()).serialize(Uint8Array.from([])).toBase64();
434
+ const modulesArg = initia_js.bcs.vector(initia_js.bcs.vector(initia_js.bcs.u8())).serialize(modules).toBase64();
435
+ const objectAddressArg = objectAddress === void 0 ? void 0 : initia_js.bcs.address().serialize(objectAddress).toBase64();
436
+ let functionArguments = objectAddressArg === void 0 ? [metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
437
+ if (objectDeployer !== InitiaObjectDeployerAddress) {
438
+ const seed = getFullName(lzInitiaConfig, moduleName);
439
+ const seedArg = initia_js.bcs.vector(initia_js.bcs.u8()).serialize(Uint8Array.from(Buffer.from(seed))).toBase64();
440
+ functionArguments = objectAddressArg === void 0 ? [seedArg, metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
441
+ }
442
+ const msg = new initia_js.MsgExecute(
443
+ deployer.accAddress,
444
+ initia_js.AccAddress.fromHex(objectDeployer),
445
+ "object_code_deployment",
446
+ objectAddress === void 0 ? `publish` : `upgrade`,
447
+ [],
448
+ functionArguments
449
+ );
450
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
451
+ const wallet = new initia_js.Wallet(client, deployer);
452
+ const signedTx = await wallet.createAndSignTx({ msgs: [msg], gasPrices });
453
+ return signedTx;
454
+ }
455
+ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObject = false) {
283
456
  const module = lzInitiaConfig.modules[moduleName];
284
457
  if (!module) {
285
458
  throw new Error(`module ${moduleName} not found`);
@@ -287,36 +460,52 @@ async function deploy(moduleName, lzInitiaConfig, network, variant) {
287
460
  const env = lzDefinitions.networkToEnv(network, lzDefinitions.EndpointVersion.V2);
288
461
  const client = getInitiaClient(env, lzInitiaConfig);
289
462
  const deployer = getDeployer(moduleName, lzInitiaConfig, network);
290
- const context = getMoveContext(moduleName, lzInitiaConfig, network);
463
+ const context = await getMoveContext(moduleName, lzInitiaConfig, network);
291
464
  const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
292
- const moduleDir = path3__default.default.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
293
- const moduleNames = glob.glob.sync("*.mv", { cwd: moduleDir });
294
- const moduleBuffers = moduleNames.map((moduleName2) => fs2__default.default.readFileSync(path3__default.default.join(moduleDir, moduleName2)));
465
+ const moduleDir = path4__default.default.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
466
+ const mvNames = glob.glob.sync("*.mv", { cwd: moduleDir });
467
+ const moduleBuffers = mvNames.map((moduleName2) => fs3__default.default.readFileSync(path4__default.default.join(moduleDir, moduleName2)));
295
468
  const bytecodeHash = getBytecodesHash(moduleBuffers);
296
- if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {
469
+ const { actionType, address: deployedAddress } = await getDeployActionType(
470
+ client,
471
+ moduleName,
472
+ mvNames,
473
+ lzInitiaConfig.deploymentPath,
474
+ network,
475
+ bytecodeHash,
476
+ variant
477
+ );
478
+ if (actionType === "Skip" /* Skip */) {
297
479
  console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
298
480
  return;
299
481
  }
300
482
  try {
301
- const msgs = [
302
- new initia_js.MsgPublish(
303
- deployer.accAddress,
304
- moduleBuffers.map((codeBytes) => codeBytes.toString("base64")),
305
- initia_js.MsgPublish.Policy.COMPATIBLE
306
- )
307
- ];
308
- const wallet = new initia_js.Wallet(client, deployer);
309
- const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
310
- const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
483
+ const signedTx = deployToObject ? await createObjectDeploymentTx(
484
+ client,
485
+ deployer,
486
+ moduleBuffers,
487
+ lzInitiaConfig,
488
+ network,
489
+ moduleName,
490
+ deployedAddress
491
+ ) : await createAccountDeploymentTx(client, deployer, moduleBuffers, lzInitiaConfig, network);
311
492
  const tx = await client.tx.broadcast(signedTx);
493
+ const info = await client.tx.txInfo(tx.txhash);
494
+ const publishedEvent = info.events.find(
495
+ (event) => event.type === "move" && event.attributes.find((attr) => attr.key === "type_tag")?.value === "0x1::code::ModulePublishedEvent"
496
+ );
497
+ const publishModuleAttr = publishedEvent?.attributes.find((attr) => attr.key === "data");
498
+ const { module_id } = JSON.parse(publishModuleAttr.value);
499
+ const codeAddress = module_id.split("::")[0];
312
500
  if (tx.code !== 0) {
313
501
  throw new Error(tx.raw_log);
314
502
  }
315
503
  console.log(`Deploy transaction ${tx.txhash} successfully`);
316
504
  saveDeployment(
505
+ deployer,
317
506
  moduleName,
318
507
  pkgName,
319
- initia_js.AccAddress.toHex(deployer.accAddress),
508
+ codeAddress,
320
509
  lzInitiaConfig.deploymentPath,
321
510
  network,
322
511
  bytecodeHash,
@@ -333,13 +522,24 @@ async function deploy(moduleName, lzInitiaConfig, network, variant) {
333
522
  }
334
523
  }
335
524
  var command = new extraTypings.Command();
336
- command.name("deploy").description("deploy Initia modules").addOption(extraTypings.createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(extraTypings.createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(extraTypings.createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).action(async (options, cmd) => {
337
- const context = cmd.getOptionValue("__CONTEXT__");
338
- const { modules, variant, network } = options;
339
- for (const module of modules) {
340
- await deploy(module, context, network, variant ?? context.modules[module]?.variant);
525
+ command.name("deploy").description("deploy Initia modules").addOption(extraTypings.createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(extraTypings.createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(extraTypings.createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).addOption(
526
+ extraTypings.createOption("-dto, --deploy-to-object", "Deploy to Move Object. Default to false").makeOptionMandatory(false)
527
+ ).action(
528
+ async (options, cmd) => {
529
+ const context = cmd.getOptionValue("__CONTEXT__");
530
+ const { modules, variant, network, deployToObject: deployToObjectOpt } = options;
531
+ for (const module of modules) {
532
+ const deployToObject = deployToObjectOpt ?? context.modules[module]?.deployToObject ?? context.defaultDeployToObject ?? false;
533
+ await deploy(
534
+ module,
535
+ context,
536
+ network,
537
+ variant ?? context.modules[module]?.variant,
538
+ deployToObject
539
+ );
540
+ }
341
541
  }
342
- });
542
+ );
343
543
 
344
544
  // src/options.ts
345
545
  function parseOptions(defaultOptions, customOptions) {
@@ -371,21 +571,21 @@ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
371
571
  })`initiad move build ${args}`;
372
572
  }
373
573
  async function copyArtifacts(src, dest) {
374
- if (fs2__default.default.existsSync(dest)) {
574
+ if (fs3__default.default.existsSync(dest)) {
375
575
  console.log(`Removing existing artifacts at ${dest}`);
376
- fs2__default.default.rmSync(dest, { recursive: true });
576
+ fs3__default.default.rmSync(dest, { recursive: true });
377
577
  }
378
- fs2__default.default.mkdirSync(dest, { recursive: true });
379
- const moduleDir = path3__default.default.join(src, "bytecode_modules");
578
+ fs3__default.default.mkdirSync(dest, { recursive: true });
579
+ const moduleDir = path4__default.default.join(src, "bytecode_modules");
380
580
  const modules = glob.glob.sync("*.mv", { cwd: moduleDir });
381
581
  for (const module of modules) {
382
- const destByteCodePath = path3__default.default.join(dest, "bytecode_modules");
383
- if (!fs2__default.default.existsSync(destByteCodePath)) {
384
- fs2__default.default.mkdirSync(destByteCodePath, { recursive: true });
582
+ const destByteCodePath = path4__default.default.join(dest, "bytecode_modules");
583
+ if (!fs3__default.default.existsSync(destByteCodePath)) {
584
+ fs3__default.default.mkdirSync(destByteCodePath, { recursive: true });
385
585
  }
386
586
  await zx.$({
387
587
  verbose: true
388
- })`cp ${path3__default.default.join(moduleDir, module)} ${path3__default.default.join(destByteCodePath, module)}`;
588
+ })`cp ${path4__default.default.join(moduleDir, module)} ${path4__default.default.join(destByteCodePath, module)}`;
389
589
  }
390
590
  }
391
591
  async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
@@ -394,11 +594,11 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
394
594
  throw new Error(`module ${moduleName} not found`);
395
595
  }
396
596
  const { modulePath } = module;
397
- const context = getMoveContext(moduleName, lzInitiaConfig, network);
597
+ const context = await getMoveContext(moduleName, lzInitiaConfig, network);
398
598
  const pkgName = context[moduleName].package.name;
399
- const srcPath = path3__default.default.join(modulePath, "build", pkgName);
599
+ const srcPath = path4__default.default.join(modulePath, "build", pkgName);
400
600
  const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
401
- const outputPath = path3__default.default.join(
601
+ const outputPath = path4__default.default.join(
402
602
  lzInitiaConfig.artifactsPath,
403
603
  variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
404
604
  );
@@ -463,8 +663,8 @@ function checkIfInitiaConfigExists() {
463
663
  if (packagePath === void 0) {
464
664
  throw new Error("package.json not found");
465
665
  }
466
- const configPath = path3__default.default.join(path3__default.default.dirname(packagePath), "lz-initia.config.ts");
467
- if (!fs2__default.default.existsSync(configPath)) {
666
+ const configPath = path4__default.default.join(path4__default.default.dirname(packagePath), "lz-initia.config.ts");
667
+ if (!fs3__default.default.existsSync(configPath)) {
468
668
  throw new Error("lz-initia.config.ts not found, please create one in the same directory as package.json");
469
669
  }
470
670
  return configPath;
@@ -481,6 +681,7 @@ async function main() {
481
681
  }
482
682
  main().then(() => process2__default.default.exit(process2__default.default.exitCode)).catch((error) => {
483
683
  logger.error(error);
684
+ console.trace(error);
484
685
  process2__default.default.exit(1);
485
686
  });
486
687
  //# sourceMappingURL=cli.cjs.map