@layerzerolabs/lz-initia-cli 3.0.19 → 3.0.20

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
@@ -1,11 +1,13 @@
1
- import fs3 from 'fs';
2
- import path2 from 'path';
3
- import { MsgPublish, Wallet, AccAddress, LCDClient, MnemonicKey } from '@initia/initia.js';
1
+ import fs4 from 'fs';
2
+ import path3 from 'path';
3
+ import { AccAddress, LCDClient, MsgPublish, Wallet, bcs, MsgExecute, MnemonicKey } from '@initia/initia.js';
4
+ import { sha3_256 } from '@noble/hashes/sha3';
5
+ import { EndpointVersion, networkToEnv } from '@layerzerolabs/lz-definitions';
6
+ import { ensure0x } from '@layerzerolabs/lz-utilities';
4
7
  import { parse } from 'smol-toml';
5
8
  import { glob } from 'glob';
6
9
  import { $ } from 'zx';
7
10
  import * as crypto from 'node:crypto';
8
- import { EndpointVersion, networkToEnv, networkToStage, Stage } from '@layerzerolabs/lz-definitions';
9
11
 
10
12
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
13
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
@@ -13,6 +15,44 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
13
15
  if (typeof require !== "undefined") return require.apply(this, arguments);
14
16
  throw Error('Dynamic require of "' + x + '" is not supported');
15
17
  });
18
+ function getInitiaClient(env, config) {
19
+ const url = config.network?.[env];
20
+ if (url === void 0) {
21
+ throw new Error(`No network url for ${env} found in lz-initia.config.ts`);
22
+ }
23
+ const lcd = new LCDClient(url);
24
+ return lcd;
25
+ }
26
+
27
+ // src/constant.ts
28
+ var InitiaObjectDeployerAddress = "0x1";
29
+
30
+ // src/config-parser.ts
31
+ function getConfigByNetwork(config, network) {
32
+ if (config === null) {
33
+ throw new Error("Config is null");
34
+ }
35
+ if (typeof config === "object") {
36
+ return config[network];
37
+ }
38
+ return config;
39
+ }
40
+ function getObjectDeployer(configValue, network) {
41
+ return getConfigByNetwork(configValue, network);
42
+ }
43
+ function getObjectDeployerFromConfig(config, network, moduleName) {
44
+ const module = config.modules[moduleName];
45
+ if (!module) {
46
+ throw new Error(`module ${moduleName} not found when getting object deployer`);
47
+ }
48
+ const moduleObjectDeployer = getObjectDeployer(module.objectDeployer, network);
49
+ const defaultObjectDeployer = getObjectDeployer(config.defaultObjectDeployer, network);
50
+ return moduleObjectDeployer ?? defaultObjectDeployer ?? InitiaObjectDeployerAddress;
51
+ }
52
+ function getFullName(config, moduleName) {
53
+ const variant = config.modules[moduleName]?.variant;
54
+ return variant !== void 0 && variant.length > 0 ? `${moduleName}-${variant}` : moduleName;
55
+ }
16
56
 
17
57
  // src/loader.ts
18
58
  function loadConfig(configPath) {
@@ -37,11 +77,11 @@ function loadConfig(configPath) {
37
77
  function isInitiaAccount(account) {
38
78
  return account !== void 0 && account instanceof MnemonicKey;
39
79
  }
40
- function getDeployer(moduleName, lzInitiaConfig, network) {
41
- const module = lzInitiaConfig.modules[moduleName];
80
+ function getDeployer(moduleName, lzAptosConfig, network) {
81
+ const module = lzAptosConfig.modules[moduleName];
42
82
  if (!module) {
43
- if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {
44
- for (const baseModule of lzInitiaConfig.baseModules) {
83
+ if (lzAptosConfig.baseModules && lzAptosConfig.baseModules.length > 0) {
84
+ for (const baseModule of lzAptosConfig.baseModules) {
45
85
  const baseConfig = loadConfig(baseModule);
46
86
  try {
47
87
  return getDeployer(moduleName, baseConfig, network);
@@ -50,23 +90,102 @@ function getDeployer(moduleName, lzInitiaConfig, network) {
50
90
  }
51
91
  }
52
92
  throw new Error(
53
- `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.`
93
+ `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.`
54
94
  );
55
95
  }
56
96
  const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
57
- const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
97
+ const defaultDeployer = isInitiaAccount(lzAptosConfig.defaultDeployer) ? lzAptosConfig.defaultDeployer : lzAptosConfig.defaultDeployer?.[network];
58
98
  const deployer = moduleDeployer ?? defaultDeployer;
59
99
  if (!deployer) {
60
100
  throw new Error(`deployer for module ${moduleName} not found`);
61
101
  }
62
102
  return deployer;
63
103
  }
104
+ function getDeploymentPath(lzAptosConfig, network, moduleName) {
105
+ return path3.join(lzAptosConfig.deploymentPath, network, `${moduleName}.json`);
106
+ }
107
+ async function checkIfObjectAddressExists(lzAptosConfig, network, address) {
108
+ try {
109
+ const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzAptosConfig);
110
+ const object = await client.auth.accountInfo(address);
111
+ return object !== void 0;
112
+ } catch (e) {
113
+ return false;
114
+ }
115
+ }
116
+ function getObjectAddressFromDeployment(lzAptosConfig, network, moduleName) {
117
+ const deploymentPath2 = getDeploymentPath(lzAptosConfig, network, moduleName);
118
+ if (!fs4.existsSync(deploymentPath2)) {
119
+ return void 0;
120
+ }
121
+ const deployment = JSON.parse(fs4.readFileSync(deploymentPath2, "utf-8"));
122
+ return deployment.address;
123
+ }
124
+ async function resolveAddress(moduleName, lzAptosConfig, network, isOngoingModule) {
125
+ const deployToObject = lzAptosConfig.modules[moduleName]?.deployToObject ?? lzAptosConfig.defaultDeployToObject ?? false;
126
+ if (!deployToObject) {
127
+ const deployer = getDeployer(moduleName, lzAptosConfig, network);
128
+ return AccAddress.toHex(deployer.accAddress);
129
+ }
130
+ const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
131
+ if (objectDeployer !== InitiaObjectDeployerAddress) {
132
+ return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
133
+ }
134
+ const objectAddress = getObjectAddressFromDeployment(lzAptosConfig, network, moduleName);
135
+ if (objectAddress !== void 0) {
136
+ if (await checkIfObjectAddressExists(lzAptosConfig, network, objectAddress)) {
137
+ return objectAddress;
138
+ }
139
+ if (!isOngoingModule) {
140
+ throw new Error(
141
+ `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.`
142
+ );
143
+ }
144
+ } else if (!isOngoingModule) {
145
+ throw new Error(
146
+ `Deployment file not found at: ${getDeploymentPath(lzAptosConfig, network, moduleName)}. Make sure ${moduleName} is deployed.`
147
+ );
148
+ }
149
+ return genObjectAddress(moduleName, lzAptosConfig, network);
150
+ }
151
+ var createObjectAddress = (creatorAddress, seed) => {
152
+ const hexAddress = AccAddress.validate(creatorAddress) ? AccAddress.toHex(creatorAddress) : creatorAddress;
153
+ const creatorBytes = bcs.address().serialize(hexAddress).toBytes();
154
+ const seedBytes = typeof seed === "string" ? Buffer.from(seed, "utf8") : seed;
155
+ const bytes = new Uint8Array([...creatorBytes, ...seedBytes, 254]);
156
+ return ensure0x(Buffer.from(sha3_256(bytes)).toString("hex"));
157
+ };
158
+ async function genObjectAddressForOfficial(network, lzAptosConfig, moduleName) {
159
+ const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzAptosConfig);
160
+ const deployer = getDeployer(moduleName, lzAptosConfig, network);
161
+ const OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR = "aptos_framework::object_code_deployment";
162
+ const account = await client.auth.accountInfo(deployer.accAddress);
163
+ const sequenceNumber = account.getSequenceNumber();
164
+ const firstPart = bcs.string().serialize(OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR);
165
+ const secondPart = bcs.u64().serialize(BigInt(sequenceNumber) + BigInt(1));
166
+ const seed = new Uint8Array([...firstPart.toBytes(), ...secondPart.toBytes()]);
167
+ const objectAddress = createObjectAddress(deployer.accAddress, seed);
168
+ return objectAddress;
169
+ }
170
+ function genObjectAddressForLayerzero(network, lzAptosConfig, moduleName) {
171
+ const deployer = getDeployer(moduleName, lzAptosConfig, network);
172
+ const seed = getFullName(lzAptosConfig, moduleName);
173
+ const objectAddress = createObjectAddress(deployer.accAddress, new Uint8Array(Buffer.from(seed, "utf8")));
174
+ return objectAddress.toString();
175
+ }
176
+ async function genObjectAddress(moduleName, lzAptosConfig, network) {
177
+ const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
178
+ if (objectDeployer === InitiaObjectDeployerAddress) {
179
+ return genObjectAddressForOfficial(network, lzAptosConfig, moduleName);
180
+ }
181
+ return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
182
+ }
64
183
  function getRawMoveContextByPath(modulePath) {
65
- const tomlPath = path2.join(modulePath, "Move.toml");
66
- if (!fs3.existsSync(tomlPath)) {
184
+ const tomlPath = path3.join(modulePath, "Move.toml");
185
+ if (!fs4.existsSync(tomlPath)) {
67
186
  throw new Error(`Move.toml not found in ${tomlPath}`);
68
187
  }
69
- const toml = parse(fs3.readFileSync(tomlPath, "utf-8"));
188
+ const toml = parse(fs4.readFileSync(tomlPath, "utf-8"));
70
189
  const { dependencies } = toml;
71
190
  let result = { [toml.package.name]: toml };
72
191
  if (dependencies !== void 0) {
@@ -74,7 +193,7 @@ function getRawMoveContextByPath(modulePath) {
74
193
  return dependencies[key]?.local !== void 0;
75
194
  }).forEach((key) => {
76
195
  const dependency = dependencies[key];
77
- const dependencyPath = path2.join(modulePath, dependency.local);
196
+ const dependencyPath = path3.join(modulePath, dependency.local);
78
197
  result = { ...getRawMoveContextByPath(dependencyPath), ...result };
79
198
  });
80
199
  }
@@ -99,7 +218,7 @@ function parseAddresses(addresses, network) {
99
218
  }
100
219
  return result;
101
220
  }
102
- function getMoveContext(moduleName, lzInitiaConfig, network) {
221
+ async function getMoveContext(moduleName, lzInitiaConfig, network) {
103
222
  const module = lzInitiaConfig.modules[moduleName];
104
223
  if (!module) {
105
224
  throw new Error(`module ${moduleName} not found when getting Move context`);
@@ -111,15 +230,21 @@ function getMoveContext(moduleName, lzInitiaConfig, network) {
111
230
  const address = toml.addresses[addressKey];
112
231
  const presetAddresses = {
113
232
  ...parseAddresses(lzInitiaConfig.modules[key]?.addresses, network),
233
+ // dependency or current module config address
114
234
  ...parseAddresses(lzInitiaConfig.modules[moduleName]?.addresses, network)
235
+ // current module config address
115
236
  };
116
237
  if (address === "_") {
117
238
  if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
118
239
  toml.addresses[addressKey] = presetAddresses[addressKey];
119
240
  } else {
120
241
  try {
121
- toml.addresses[addressKey] = AccAddress.toHex(
122
- getDeployer(addressKey, lzInitiaConfig, network).accAddress
242
+ const isOnGoingModule = moduleName === addressKey;
243
+ toml.addresses[addressKey] = await resolveAddress(
244
+ addressKey,
245
+ lzInitiaConfig,
246
+ network,
247
+ isOnGoingModule
123
248
  );
124
249
  } catch (e) {
125
250
  if (key === moduleName) {
@@ -167,21 +292,21 @@ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
167
292
  })`initiad move build ${args}`;
168
293
  }
169
294
  async function copyArtifacts(src, dest) {
170
- if (fs3.existsSync(dest)) {
295
+ if (fs4.existsSync(dest)) {
171
296
  console.log(`Removing existing artifacts at ${dest}`);
172
- fs3.rmSync(dest, { recursive: true });
297
+ fs4.rmSync(dest, { recursive: true });
173
298
  }
174
- fs3.mkdirSync(dest, { recursive: true });
175
- const moduleDir = path2.join(src, "bytecode_modules");
299
+ fs4.mkdirSync(dest, { recursive: true });
300
+ const moduleDir = path3.join(src, "bytecode_modules");
176
301
  const modules = glob.sync("*.mv", { cwd: moduleDir });
177
302
  for (const module of modules) {
178
- const destByteCodePath = path2.join(dest, "bytecode_modules");
179
- if (!fs3.existsSync(destByteCodePath)) {
180
- fs3.mkdirSync(destByteCodePath, { recursive: true });
303
+ const destByteCodePath = path3.join(dest, "bytecode_modules");
304
+ if (!fs4.existsSync(destByteCodePath)) {
305
+ fs4.mkdirSync(destByteCodePath, { recursive: true });
181
306
  }
182
307
  await $({
183
308
  verbose: true
184
- })`cp ${path2.join(moduleDir, module)} ${path2.join(destByteCodePath, module)}`;
309
+ })`cp ${path3.join(moduleDir, module)} ${path3.join(destByteCodePath, module)}`;
185
310
  }
186
311
  }
187
312
  async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
@@ -190,11 +315,11 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
190
315
  throw new Error(`module ${moduleName} not found`);
191
316
  }
192
317
  const { modulePath } = module;
193
- const context = getMoveContext(moduleName, lzInitiaConfig, network);
318
+ const context = await getMoveContext(moduleName, lzInitiaConfig, network);
194
319
  const pkgName = context[moduleName].package.name;
195
- const srcPath = path2.join(modulePath, "build", pkgName);
320
+ const srcPath = path3.join(modulePath, "build", pkgName);
196
321
  const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
197
- const outputPath = path2.join(
322
+ const outputPath = path3.join(
198
323
  lzInitiaConfig.artifactsPath,
199
324
  variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
200
325
  );
@@ -215,14 +340,6 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
215
340
  }
216
341
  await copyArtifacts(srcPath, outputPath);
217
342
  }
218
- function getInitiaClient(env, config) {
219
- const url = config.network?.[env];
220
- if (url === void 0) {
221
- throw new Error(`No network url for ${env} found in lz-initia.config.ts`);
222
- }
223
- const lcd = new LCDClient(url);
224
- return lcd;
225
- }
226
343
  function isAxiosError(error) {
227
344
  return error?.response?.data?.message !== void 0;
228
345
  }
@@ -266,20 +383,21 @@ function handleError(error, moduleName, context, network) {
266
383
  throw error;
267
384
  }
268
385
  function deploymentPath(pkgName, dest, network, variant) {
269
- const deploymentPath2 = path2.join(dest, network);
270
- return path2.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
386
+ const deploymentPath2 = path3.join(dest, network);
387
+ return path3.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
271
388
  }
272
- function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
389
+ function saveDeployment(deployer, moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
273
390
  const destPath = deploymentPath(pkgName, dest, network, variant);
274
- const deploymentDir = path2.dirname(destPath);
275
- if (!fs3.existsSync(deploymentDir)) {
276
- fs3.mkdirSync(deploymentDir, { recursive: true });
391
+ const deploymentDir = path3.dirname(destPath);
392
+ if (!fs4.existsSync(deploymentDir)) {
393
+ fs4.mkdirSync(deploymentDir, { recursive: true });
277
394
  }
278
- fs3.writeFileSync(
395
+ fs4.writeFileSync(
279
396
  destPath,
280
397
  JSON.stringify(
281
398
  {
282
399
  address,
400
+ deployer: AccAddress.toHex(deployer.accAddress),
283
401
  name: pkgWithVariant(pkgName, variant),
284
402
  moduleName,
285
403
  network,
@@ -293,16 +411,35 @@ function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHas
293
411
  );
294
412
  console.log(`Deployment saved to ${destPath}`);
295
413
  }
296
- function needDeploy(pkgName, dest, network, bytecodeHash, variant) {
297
- if (networkToStage(network) === Stage.SANDBOX) {
298
- return true;
414
+ async function checkIfModuleExistedOnChain(client, moduleNames, address) {
415
+ try {
416
+ const modules = (await client.move.modules(address))[0];
417
+ return moduleNames.some(
418
+ (moduleName) => modules.map((module) => module.module_name).includes(moduleName.replace(".mv", ""))
419
+ );
420
+ } catch (e) {
421
+ try {
422
+ const object = await client.auth.accountInfo(address);
423
+ return object !== void 0;
424
+ } catch (e2) {
425
+ return false;
426
+ }
299
427
  }
428
+ }
429
+ async function getDeployActionType(client, pkgName, moduleNames, dest, network, bytecodeHash, variant) {
300
430
  const destPath = deploymentPath(pkgName, dest, network, variant);
301
- if (fs3.existsSync(destPath)) {
302
- const deployment = JSON.parse(fs3.readFileSync(destPath, "utf-8"));
303
- return deployment.bytecodeHash !== bytecodeHash;
431
+ if (fs4.existsSync(destPath)) {
432
+ const deployment = JSON.parse(fs4.readFileSync(destPath, "utf-8"));
433
+ const moduleExisted = await checkIfModuleExistedOnChain(client, moduleNames, deployment.address);
434
+ if (moduleExisted) {
435
+ if (deployment.bytecodeHash !== bytecodeHash || network.includes("local")) {
436
+ return { actionType: "Upgrade" /* Upgrade */, address: deployment.address };
437
+ } else {
438
+ return { actionType: "Skip" /* Skip */, address: deployment.address };
439
+ }
440
+ }
304
441
  }
305
- return true;
442
+ return { actionType: "Deploy" /* Deploy */, address: void 0 };
306
443
  }
307
444
  function pkgWithVariant(pkgName, variant) {
308
445
  return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
@@ -314,7 +451,44 @@ function getBytecodesHash(bytecodes) {
314
451
  });
315
452
  return hash.digest("hex");
316
453
  }
317
- async function deploy(moduleName, lzInitiaConfig, network, variant) {
454
+ async function createAccountDeploymentTx(client, deployer, modules, lzInitiaConfig, network) {
455
+ const msgs = [
456
+ new MsgPublish(
457
+ deployer.accAddress,
458
+ modules.map((codeBytes) => codeBytes.toString("base64")),
459
+ MsgPublish.Policy.COMPATIBLE
460
+ )
461
+ ];
462
+ const wallet = new Wallet(client, deployer);
463
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
464
+ const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
465
+ return signedTx;
466
+ }
467
+ async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network, moduleName, objectAddress) {
468
+ const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleName);
469
+ const metadataArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from([])).toBase64();
470
+ const modulesArg = bcs.vector(bcs.vector(bcs.u8())).serialize(modules).toBase64();
471
+ const objectAddressArg = objectAddress === void 0 ? void 0 : bcs.address().serialize(objectAddress).toBase64();
472
+ let functionArguments = objectAddressArg === void 0 ? [metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
473
+ if (objectDeployer !== InitiaObjectDeployerAddress) {
474
+ const seed = getFullName(lzInitiaConfig, moduleName);
475
+ const seedArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from(Buffer.from(seed))).toBase64();
476
+ functionArguments = objectAddressArg === void 0 ? [seedArg, metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
477
+ }
478
+ const msg = new MsgExecute(
479
+ deployer.accAddress,
480
+ AccAddress.fromHex(objectDeployer),
481
+ "object_code_deployment",
482
+ objectAddress === void 0 ? `publish` : `upgrade`,
483
+ [],
484
+ functionArguments
485
+ );
486
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
487
+ const wallet = new Wallet(client, deployer);
488
+ const signedTx = await wallet.createAndSignTx({ msgs: [msg], gasPrices });
489
+ return signedTx;
490
+ }
491
+ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObject = false) {
318
492
  const module = lzInitiaConfig.modules[moduleName];
319
493
  if (!module) {
320
494
  throw new Error(`module ${moduleName} not found`);
@@ -322,36 +496,52 @@ async function deploy(moduleName, lzInitiaConfig, network, variant) {
322
496
  const env = networkToEnv(network, EndpointVersion.V2);
323
497
  const client = getInitiaClient(env, lzInitiaConfig);
324
498
  const deployer = getDeployer(moduleName, lzInitiaConfig, network);
325
- const context = getMoveContext(moduleName, lzInitiaConfig, network);
499
+ const context = await getMoveContext(moduleName, lzInitiaConfig, network);
326
500
  const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
327
- const moduleDir = path2.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
328
- const moduleNames = glob.sync("*.mv", { cwd: moduleDir });
329
- const moduleBuffers = moduleNames.map((moduleName2) => fs3.readFileSync(path2.join(moduleDir, moduleName2)));
501
+ const moduleDir = path3.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
502
+ const mvNames = glob.sync("*.mv", { cwd: moduleDir });
503
+ const moduleBuffers = mvNames.map((moduleName2) => fs4.readFileSync(path3.join(moduleDir, moduleName2)));
330
504
  const bytecodeHash = getBytecodesHash(moduleBuffers);
331
- if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {
505
+ const { actionType, address: deployedAddress } = await getDeployActionType(
506
+ client,
507
+ moduleName,
508
+ mvNames,
509
+ lzInitiaConfig.deploymentPath,
510
+ network,
511
+ bytecodeHash,
512
+ variant
513
+ );
514
+ if (actionType === "Skip" /* Skip */) {
332
515
  console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
333
516
  return;
334
517
  }
335
518
  try {
336
- const msgs = [
337
- new MsgPublish(
338
- deployer.accAddress,
339
- moduleBuffers.map((codeBytes) => codeBytes.toString("base64")),
340
- MsgPublish.Policy.COMPATIBLE
341
- )
342
- ];
343
- const wallet = new Wallet(client, deployer);
344
- const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
345
- const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
519
+ const signedTx = deployToObject ? await createObjectDeploymentTx(
520
+ client,
521
+ deployer,
522
+ moduleBuffers,
523
+ lzInitiaConfig,
524
+ network,
525
+ moduleName,
526
+ deployedAddress
527
+ ) : await createAccountDeploymentTx(client, deployer, moduleBuffers, lzInitiaConfig, network);
346
528
  const tx = await client.tx.broadcast(signedTx);
529
+ const info = await client.tx.txInfo(tx.txhash);
530
+ const publishedEvent = info.events.find(
531
+ (event) => event.type === "move" && event.attributes.find((attr) => attr.key === "type_tag")?.value === "0x1::code::ModulePublishedEvent"
532
+ );
533
+ const publishModuleAttr = publishedEvent?.attributes.find((attr) => attr.key === "data");
534
+ const { module_id } = JSON.parse(publishModuleAttr.value);
535
+ const codeAddress = module_id.split("::")[0];
347
536
  if (tx.code !== 0) {
348
537
  throw new Error(tx.raw_log);
349
538
  }
350
539
  console.log(`Deploy transaction ${tx.txhash} successfully`);
351
540
  saveDeployment(
541
+ deployer,
352
542
  moduleName,
353
543
  pkgName,
354
- AccAddress.toHex(deployer.accAddress),
544
+ codeAddress,
355
545
  lzInitiaConfig.deploymentPath,
356
546
  network,
357
547
  bytecodeHash,