@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/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/dist/cli.cjs +269 -68
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +269 -68
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +258 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +257 -67
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/cli.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import fs3 from 'fs';
|
|
2
|
+
import path4 from 'path';
|
|
3
3
|
import process2 from 'process';
|
|
4
4
|
import { Command, createOption } from '@commander-js/extra-typings';
|
|
5
5
|
import { sync } from 'find-up';
|
|
6
6
|
import { $ as $$1 } from 'zx/core';
|
|
7
|
-
import { getLogger } from '@layerzerolabs/lz-utilities';
|
|
7
|
+
import { getLogger, ensure0x } from '@layerzerolabs/lz-utilities';
|
|
8
8
|
import * as crypto from 'node:crypto';
|
|
9
|
-
import { MsgPublish, Wallet,
|
|
9
|
+
import { LCDClient, AccAddress, MsgPublish, Wallet, bcs, MsgExecute, MnemonicKey } from '@initia/initia.js';
|
|
10
|
+
import { sha3_256 } from '@noble/hashes/sha3';
|
|
11
|
+
import { networkToEnv, EndpointVersion } from '@layerzerolabs/lz-definitions';
|
|
10
12
|
import { parse } from 'smol-toml';
|
|
11
13
|
import { glob } from 'glob';
|
|
12
|
-
import { networkToEnv, EndpointVersion, networkToStage, Stage } from '@layerzerolabs/lz-definitions';
|
|
13
14
|
import { $ } from 'zx';
|
|
14
15
|
|
|
15
16
|
var __defProp = Object.defineProperty;
|
|
@@ -59,14 +60,44 @@ function getInitiaClient(env, config) {
|
|
|
59
60
|
const lcd = new LCDClient(url);
|
|
60
61
|
return lcd;
|
|
61
62
|
}
|
|
63
|
+
|
|
64
|
+
// src/constant.ts
|
|
65
|
+
var InitiaObjectDeployerAddress = "0x1";
|
|
66
|
+
|
|
67
|
+
// src/config-parser.ts
|
|
68
|
+
function getConfigByNetwork(config, network) {
|
|
69
|
+
if (config === null) {
|
|
70
|
+
throw new Error("Config is null");
|
|
71
|
+
}
|
|
72
|
+
if (typeof config === "object") {
|
|
73
|
+
return config[network];
|
|
74
|
+
}
|
|
75
|
+
return config;
|
|
76
|
+
}
|
|
77
|
+
function getObjectDeployer(configValue, network) {
|
|
78
|
+
return getConfigByNetwork(configValue, network);
|
|
79
|
+
}
|
|
80
|
+
function getObjectDeployerFromConfig(config, network, moduleName) {
|
|
81
|
+
const module = config.modules[moduleName];
|
|
82
|
+
if (!module) {
|
|
83
|
+
throw new Error(`module ${moduleName} not found when getting object deployer`);
|
|
84
|
+
}
|
|
85
|
+
const moduleObjectDeployer = getObjectDeployer(module.objectDeployer, network);
|
|
86
|
+
const defaultObjectDeployer = getObjectDeployer(config.defaultObjectDeployer, network);
|
|
87
|
+
return moduleObjectDeployer ?? defaultObjectDeployer ?? InitiaObjectDeployerAddress;
|
|
88
|
+
}
|
|
89
|
+
function getFullName(config, moduleName) {
|
|
90
|
+
const variant = config.modules[moduleName]?.variant;
|
|
91
|
+
return variant !== void 0 && variant.length > 0 ? `${moduleName}-${variant}` : moduleName;
|
|
92
|
+
}
|
|
62
93
|
function isInitiaAccount(account) {
|
|
63
94
|
return account !== void 0 && account instanceof MnemonicKey;
|
|
64
95
|
}
|
|
65
|
-
function getDeployer(moduleName,
|
|
66
|
-
const module =
|
|
96
|
+
function getDeployer(moduleName, lzAptosConfig, network) {
|
|
97
|
+
const module = lzAptosConfig.modules[moduleName];
|
|
67
98
|
if (!module) {
|
|
68
|
-
if (
|
|
69
|
-
for (const baseModule of
|
|
99
|
+
if (lzAptosConfig.baseModules && lzAptosConfig.baseModules.length > 0) {
|
|
100
|
+
for (const baseModule of lzAptosConfig.baseModules) {
|
|
70
101
|
const baseConfig = loadConfig(baseModule);
|
|
71
102
|
try {
|
|
72
103
|
return getDeployer(moduleName, baseConfig, network);
|
|
@@ -75,17 +106,96 @@ function getDeployer(moduleName, lzInitiaConfig, network) {
|
|
|
75
106
|
}
|
|
76
107
|
}
|
|
77
108
|
throw new Error(
|
|
78
|
-
`Module ${moduleName} not found. Make sure it is defined in lz-
|
|
109
|
+
`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.`
|
|
79
110
|
);
|
|
80
111
|
}
|
|
81
112
|
const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
|
|
82
|
-
const defaultDeployer = isInitiaAccount(
|
|
113
|
+
const defaultDeployer = isInitiaAccount(lzAptosConfig.defaultDeployer) ? lzAptosConfig.defaultDeployer : lzAptosConfig.defaultDeployer?.[network];
|
|
83
114
|
const deployer = moduleDeployer ?? defaultDeployer;
|
|
84
115
|
if (!deployer) {
|
|
85
116
|
throw new Error(`deployer for module ${moduleName} not found`);
|
|
86
117
|
}
|
|
87
118
|
return deployer;
|
|
88
119
|
}
|
|
120
|
+
function getDeploymentPath(lzAptosConfig, network, moduleName) {
|
|
121
|
+
return path4.join(lzAptosConfig.deploymentPath, network, `${moduleName}.json`);
|
|
122
|
+
}
|
|
123
|
+
async function checkIfObjectAddressExists(lzAptosConfig, network, address) {
|
|
124
|
+
try {
|
|
125
|
+
const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzAptosConfig);
|
|
126
|
+
const object = await client.auth.accountInfo(address);
|
|
127
|
+
return object !== void 0;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function getObjectAddressFromDeployment(lzAptosConfig, network, moduleName) {
|
|
133
|
+
const deploymentPath2 = getDeploymentPath(lzAptosConfig, network, moduleName);
|
|
134
|
+
if (!fs3.existsSync(deploymentPath2)) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
const deployment = JSON.parse(fs3.readFileSync(deploymentPath2, "utf-8"));
|
|
138
|
+
return deployment.address;
|
|
139
|
+
}
|
|
140
|
+
async function resolveAddress(moduleName, lzAptosConfig, network, isOngoingModule) {
|
|
141
|
+
const deployToObject = lzAptosConfig.modules[moduleName]?.deployToObject ?? lzAptosConfig.defaultDeployToObject ?? false;
|
|
142
|
+
if (!deployToObject) {
|
|
143
|
+
const deployer = getDeployer(moduleName, lzAptosConfig, network);
|
|
144
|
+
return AccAddress.toHex(deployer.accAddress);
|
|
145
|
+
}
|
|
146
|
+
const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
|
|
147
|
+
if (objectDeployer !== InitiaObjectDeployerAddress) {
|
|
148
|
+
return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
|
|
149
|
+
}
|
|
150
|
+
const objectAddress = getObjectAddressFromDeployment(lzAptosConfig, network, moduleName);
|
|
151
|
+
if (objectAddress !== void 0) {
|
|
152
|
+
if (await checkIfObjectAddressExists(lzAptosConfig, network, objectAddress)) {
|
|
153
|
+
return objectAddress;
|
|
154
|
+
}
|
|
155
|
+
if (!isOngoingModule) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`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.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
} else if (!isOngoingModule) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Deployment file not found at: ${getDeploymentPath(lzAptosConfig, network, moduleName)}. Make sure ${moduleName} is deployed.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return genObjectAddress(moduleName, lzAptosConfig, network);
|
|
166
|
+
}
|
|
167
|
+
var createObjectAddress = (creatorAddress, seed) => {
|
|
168
|
+
const hexAddress = AccAddress.validate(creatorAddress) ? AccAddress.toHex(creatorAddress) : creatorAddress;
|
|
169
|
+
const creatorBytes = bcs.address().serialize(hexAddress).toBytes();
|
|
170
|
+
const seedBytes = typeof seed === "string" ? Buffer.from(seed, "utf8") : seed;
|
|
171
|
+
const bytes = new Uint8Array([...creatorBytes, ...seedBytes, 254]);
|
|
172
|
+
return ensure0x(Buffer.from(sha3_256(bytes)).toString("hex"));
|
|
173
|
+
};
|
|
174
|
+
async function genObjectAddressForOfficial(network, lzAptosConfig, moduleName) {
|
|
175
|
+
const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzAptosConfig);
|
|
176
|
+
const deployer = getDeployer(moduleName, lzAptosConfig, network);
|
|
177
|
+
const OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR = "aptos_framework::object_code_deployment";
|
|
178
|
+
const account = await client.auth.accountInfo(deployer.accAddress);
|
|
179
|
+
const sequenceNumber = account.getSequenceNumber();
|
|
180
|
+
const firstPart = bcs.string().serialize(OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR);
|
|
181
|
+
const secondPart = bcs.u64().serialize(BigInt(sequenceNumber) + BigInt(1));
|
|
182
|
+
const seed = new Uint8Array([...firstPart.toBytes(), ...secondPart.toBytes()]);
|
|
183
|
+
const objectAddress = createObjectAddress(deployer.accAddress, seed);
|
|
184
|
+
return objectAddress;
|
|
185
|
+
}
|
|
186
|
+
function genObjectAddressForLayerzero(network, lzAptosConfig, moduleName) {
|
|
187
|
+
const deployer = getDeployer(moduleName, lzAptosConfig, network);
|
|
188
|
+
const seed = getFullName(lzAptosConfig, moduleName);
|
|
189
|
+
const objectAddress = createObjectAddress(deployer.accAddress, new Uint8Array(Buffer.from(seed, "utf8")));
|
|
190
|
+
return objectAddress.toString();
|
|
191
|
+
}
|
|
192
|
+
async function genObjectAddress(moduleName, lzAptosConfig, network) {
|
|
193
|
+
const objectDeployer = getObjectDeployerFromConfig(lzAptosConfig, network, moduleName);
|
|
194
|
+
if (objectDeployer === InitiaObjectDeployerAddress) {
|
|
195
|
+
return genObjectAddressForOfficial(network, lzAptosConfig, moduleName);
|
|
196
|
+
}
|
|
197
|
+
return genObjectAddressForLayerzero(network, lzAptosConfig, moduleName);
|
|
198
|
+
}
|
|
89
199
|
function isAxiosError(error) {
|
|
90
200
|
return error?.response?.data?.message !== void 0;
|
|
91
201
|
}
|
|
@@ -129,11 +239,11 @@ function handleError(error, moduleName, context, network) {
|
|
|
129
239
|
throw error;
|
|
130
240
|
}
|
|
131
241
|
function getRawMoveContextByPath(modulePath) {
|
|
132
|
-
const tomlPath =
|
|
133
|
-
if (!
|
|
242
|
+
const tomlPath = path4.join(modulePath, "Move.toml");
|
|
243
|
+
if (!fs3.existsSync(tomlPath)) {
|
|
134
244
|
throw new Error(`Move.toml not found in ${tomlPath}`);
|
|
135
245
|
}
|
|
136
|
-
const toml = parse(
|
|
246
|
+
const toml = parse(fs3.readFileSync(tomlPath, "utf-8"));
|
|
137
247
|
const { dependencies } = toml;
|
|
138
248
|
let result = { [toml.package.name]: toml };
|
|
139
249
|
if (dependencies !== void 0) {
|
|
@@ -141,7 +251,7 @@ function getRawMoveContextByPath(modulePath) {
|
|
|
141
251
|
return dependencies[key]?.local !== void 0;
|
|
142
252
|
}).forEach((key) => {
|
|
143
253
|
const dependency = dependencies[key];
|
|
144
|
-
const dependencyPath =
|
|
254
|
+
const dependencyPath = path4.join(modulePath, dependency.local);
|
|
145
255
|
result = { ...getRawMoveContextByPath(dependencyPath), ...result };
|
|
146
256
|
});
|
|
147
257
|
}
|
|
@@ -166,7 +276,7 @@ function parseAddresses(addresses, network) {
|
|
|
166
276
|
}
|
|
167
277
|
return result;
|
|
168
278
|
}
|
|
169
|
-
function getMoveContext(moduleName, lzInitiaConfig, network) {
|
|
279
|
+
async function getMoveContext(moduleName, lzInitiaConfig, network) {
|
|
170
280
|
const module = lzInitiaConfig.modules[moduleName];
|
|
171
281
|
if (!module) {
|
|
172
282
|
throw new Error(`module ${moduleName} not found when getting Move context`);
|
|
@@ -178,15 +288,21 @@ function getMoveContext(moduleName, lzInitiaConfig, network) {
|
|
|
178
288
|
const address = toml.addresses[addressKey];
|
|
179
289
|
const presetAddresses = {
|
|
180
290
|
...parseAddresses(lzInitiaConfig.modules[key]?.addresses, network),
|
|
291
|
+
// dependency or current module config address
|
|
181
292
|
...parseAddresses(lzInitiaConfig.modules[moduleName]?.addresses, network)
|
|
293
|
+
// current module config address
|
|
182
294
|
};
|
|
183
295
|
if (address === "_") {
|
|
184
296
|
if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
|
|
185
297
|
toml.addresses[addressKey] = presetAddresses[addressKey];
|
|
186
298
|
} else {
|
|
187
299
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
300
|
+
const isOnGoingModule = moduleName === addressKey;
|
|
301
|
+
toml.addresses[addressKey] = await resolveAddress(
|
|
302
|
+
addressKey,
|
|
303
|
+
lzInitiaConfig,
|
|
304
|
+
network,
|
|
305
|
+
isOnGoingModule
|
|
190
306
|
);
|
|
191
307
|
} catch (e) {
|
|
192
308
|
if (key === moduleName) {
|
|
@@ -204,20 +320,21 @@ function getMoveContext(moduleName, lzInitiaConfig, network) {
|
|
|
204
320
|
return context;
|
|
205
321
|
}
|
|
206
322
|
function deploymentPath(pkgName, dest, network, variant) {
|
|
207
|
-
const deploymentPath2 =
|
|
208
|
-
return
|
|
323
|
+
const deploymentPath2 = path4.join(dest, network);
|
|
324
|
+
return path4.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
|
|
209
325
|
}
|
|
210
|
-
function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
|
|
326
|
+
function saveDeployment(deployer, moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
|
|
211
327
|
const destPath = deploymentPath(pkgName, dest, network, variant);
|
|
212
|
-
const deploymentDir =
|
|
213
|
-
if (!
|
|
214
|
-
|
|
328
|
+
const deploymentDir = path4.dirname(destPath);
|
|
329
|
+
if (!fs3.existsSync(deploymentDir)) {
|
|
330
|
+
fs3.mkdirSync(deploymentDir, { recursive: true });
|
|
215
331
|
}
|
|
216
|
-
|
|
332
|
+
fs3.writeFileSync(
|
|
217
333
|
destPath,
|
|
218
334
|
JSON.stringify(
|
|
219
335
|
{
|
|
220
336
|
address,
|
|
337
|
+
deployer: AccAddress.toHex(deployer.accAddress),
|
|
221
338
|
name: pkgWithVariant(pkgName, variant),
|
|
222
339
|
moduleName,
|
|
223
340
|
network,
|
|
@@ -231,16 +348,35 @@ function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHas
|
|
|
231
348
|
);
|
|
232
349
|
console.log(`Deployment saved to ${destPath}`);
|
|
233
350
|
}
|
|
234
|
-
function
|
|
235
|
-
|
|
236
|
-
|
|
351
|
+
async function checkIfModuleExistedOnChain(client, moduleNames, address) {
|
|
352
|
+
try {
|
|
353
|
+
const modules = (await client.move.modules(address))[0];
|
|
354
|
+
return moduleNames.some(
|
|
355
|
+
(moduleName) => modules.map((module) => module.module_name).includes(moduleName.replace(".mv", ""))
|
|
356
|
+
);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
try {
|
|
359
|
+
const object = await client.auth.accountInfo(address);
|
|
360
|
+
return object !== void 0;
|
|
361
|
+
} catch (e2) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
237
364
|
}
|
|
365
|
+
}
|
|
366
|
+
async function getDeployActionType(client, pkgName, moduleNames, dest, network, bytecodeHash, variant) {
|
|
238
367
|
const destPath = deploymentPath(pkgName, dest, network, variant);
|
|
239
|
-
if (
|
|
240
|
-
const deployment = JSON.parse(
|
|
241
|
-
|
|
368
|
+
if (fs3.existsSync(destPath)) {
|
|
369
|
+
const deployment = JSON.parse(fs3.readFileSync(destPath, "utf-8"));
|
|
370
|
+
const moduleExisted = await checkIfModuleExistedOnChain(client, moduleNames, deployment.address);
|
|
371
|
+
if (moduleExisted) {
|
|
372
|
+
if (deployment.bytecodeHash !== bytecodeHash || network.includes("local")) {
|
|
373
|
+
return { actionType: "Upgrade" /* Upgrade */, address: deployment.address };
|
|
374
|
+
} else {
|
|
375
|
+
return { actionType: "Skip" /* Skip */, address: deployment.address };
|
|
376
|
+
}
|
|
377
|
+
}
|
|
242
378
|
}
|
|
243
|
-
return
|
|
379
|
+
return { actionType: "Deploy" /* Deploy */, address: void 0 };
|
|
244
380
|
}
|
|
245
381
|
function pkgWithVariant(pkgName, variant) {
|
|
246
382
|
return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
|
|
@@ -252,7 +388,44 @@ function getBytecodesHash(bytecodes) {
|
|
|
252
388
|
});
|
|
253
389
|
return hash.digest("hex");
|
|
254
390
|
}
|
|
255
|
-
async function
|
|
391
|
+
async function createAccountDeploymentTx(client, deployer, modules, lzInitiaConfig, network) {
|
|
392
|
+
const msgs = [
|
|
393
|
+
new MsgPublish(
|
|
394
|
+
deployer.accAddress,
|
|
395
|
+
modules.map((codeBytes) => codeBytes.toString("base64")),
|
|
396
|
+
MsgPublish.Policy.COMPATIBLE
|
|
397
|
+
)
|
|
398
|
+
];
|
|
399
|
+
const wallet = new Wallet(client, deployer);
|
|
400
|
+
const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
|
|
401
|
+
const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
|
|
402
|
+
return signedTx;
|
|
403
|
+
}
|
|
404
|
+
async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network, moduleName, objectAddress) {
|
|
405
|
+
const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleName);
|
|
406
|
+
const metadataArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from([])).toBase64();
|
|
407
|
+
const modulesArg = bcs.vector(bcs.vector(bcs.u8())).serialize(modules).toBase64();
|
|
408
|
+
const objectAddressArg = objectAddress === void 0 ? void 0 : bcs.address().serialize(objectAddress).toBase64();
|
|
409
|
+
let functionArguments = objectAddressArg === void 0 ? [metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
|
|
410
|
+
if (objectDeployer !== InitiaObjectDeployerAddress) {
|
|
411
|
+
const seed = getFullName(lzInitiaConfig, moduleName);
|
|
412
|
+
const seedArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from(Buffer.from(seed))).toBase64();
|
|
413
|
+
functionArguments = objectAddressArg === void 0 ? [seedArg, metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
|
|
414
|
+
}
|
|
415
|
+
const msg = new MsgExecute(
|
|
416
|
+
deployer.accAddress,
|
|
417
|
+
AccAddress.fromHex(objectDeployer),
|
|
418
|
+
"object_code_deployment",
|
|
419
|
+
objectAddress === void 0 ? `publish` : `upgrade`,
|
|
420
|
+
[],
|
|
421
|
+
functionArguments
|
|
422
|
+
);
|
|
423
|
+
const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}uinit`;
|
|
424
|
+
const wallet = new Wallet(client, deployer);
|
|
425
|
+
const signedTx = await wallet.createAndSignTx({ msgs: [msg], gasPrices });
|
|
426
|
+
return signedTx;
|
|
427
|
+
}
|
|
428
|
+
async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObject = false) {
|
|
256
429
|
const module = lzInitiaConfig.modules[moduleName];
|
|
257
430
|
if (!module) {
|
|
258
431
|
throw new Error(`module ${moduleName} not found`);
|
|
@@ -260,36 +433,52 @@ async function deploy(moduleName, lzInitiaConfig, network, variant) {
|
|
|
260
433
|
const env = networkToEnv(network, EndpointVersion.V2);
|
|
261
434
|
const client = getInitiaClient(env, lzInitiaConfig);
|
|
262
435
|
const deployer = getDeployer(moduleName, lzInitiaConfig, network);
|
|
263
|
-
const context = getMoveContext(moduleName, lzInitiaConfig, network);
|
|
436
|
+
const context = await getMoveContext(moduleName, lzInitiaConfig, network);
|
|
264
437
|
const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
|
|
265
|
-
const moduleDir =
|
|
266
|
-
const
|
|
267
|
-
const moduleBuffers =
|
|
438
|
+
const moduleDir = path4.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
|
|
439
|
+
const mvNames = glob.sync("*.mv", { cwd: moduleDir });
|
|
440
|
+
const moduleBuffers = mvNames.map((moduleName2) => fs3.readFileSync(path4.join(moduleDir, moduleName2)));
|
|
268
441
|
const bytecodeHash = getBytecodesHash(moduleBuffers);
|
|
269
|
-
|
|
442
|
+
const { actionType, address: deployedAddress } = await getDeployActionType(
|
|
443
|
+
client,
|
|
444
|
+
moduleName,
|
|
445
|
+
mvNames,
|
|
446
|
+
lzInitiaConfig.deploymentPath,
|
|
447
|
+
network,
|
|
448
|
+
bytecodeHash,
|
|
449
|
+
variant
|
|
450
|
+
);
|
|
451
|
+
if (actionType === "Skip" /* Skip */) {
|
|
270
452
|
console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
|
|
271
453
|
return;
|
|
272
454
|
}
|
|
273
455
|
try {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
|
|
456
|
+
const signedTx = deployToObject ? await createObjectDeploymentTx(
|
|
457
|
+
client,
|
|
458
|
+
deployer,
|
|
459
|
+
moduleBuffers,
|
|
460
|
+
lzInitiaConfig,
|
|
461
|
+
network,
|
|
462
|
+
moduleName,
|
|
463
|
+
deployedAddress
|
|
464
|
+
) : await createAccountDeploymentTx(client, deployer, moduleBuffers, lzInitiaConfig, network);
|
|
284
465
|
const tx = await client.tx.broadcast(signedTx);
|
|
466
|
+
const info = await client.tx.txInfo(tx.txhash);
|
|
467
|
+
const publishedEvent = info.events.find(
|
|
468
|
+
(event) => event.type === "move" && event.attributes.find((attr) => attr.key === "type_tag")?.value === "0x1::code::ModulePublishedEvent"
|
|
469
|
+
);
|
|
470
|
+
const publishModuleAttr = publishedEvent?.attributes.find((attr) => attr.key === "data");
|
|
471
|
+
const { module_id } = JSON.parse(publishModuleAttr.value);
|
|
472
|
+
const codeAddress = module_id.split("::")[0];
|
|
285
473
|
if (tx.code !== 0) {
|
|
286
474
|
throw new Error(tx.raw_log);
|
|
287
475
|
}
|
|
288
476
|
console.log(`Deploy transaction ${tx.txhash} successfully`);
|
|
289
477
|
saveDeployment(
|
|
478
|
+
deployer,
|
|
290
479
|
moduleName,
|
|
291
480
|
pkgName,
|
|
292
|
-
|
|
481
|
+
codeAddress,
|
|
293
482
|
lzInitiaConfig.deploymentPath,
|
|
294
483
|
network,
|
|
295
484
|
bytecodeHash,
|
|
@@ -306,13 +495,24 @@ async function deploy(moduleName, lzInitiaConfig, network, variant) {
|
|
|
306
495
|
}
|
|
307
496
|
}
|
|
308
497
|
var command = new Command();
|
|
309
|
-
command.name("deploy").description("deploy Initia modules").addOption(createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
498
|
+
command.name("deploy").description("deploy Initia modules").addOption(createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).addOption(
|
|
499
|
+
createOption("-dto, --deploy-to-object", "Deploy to Move Object. Default to false").makeOptionMandatory(false)
|
|
500
|
+
).action(
|
|
501
|
+
async (options, cmd) => {
|
|
502
|
+
const context = cmd.getOptionValue("__CONTEXT__");
|
|
503
|
+
const { modules, variant, network, deployToObject: deployToObjectOpt } = options;
|
|
504
|
+
for (const module of modules) {
|
|
505
|
+
const deployToObject = deployToObjectOpt ?? context.modules[module]?.deployToObject ?? context.defaultDeployToObject ?? false;
|
|
506
|
+
await deploy(
|
|
507
|
+
module,
|
|
508
|
+
context,
|
|
509
|
+
network,
|
|
510
|
+
variant ?? context.modules[module]?.variant,
|
|
511
|
+
deployToObject
|
|
512
|
+
);
|
|
513
|
+
}
|
|
314
514
|
}
|
|
315
|
-
|
|
515
|
+
);
|
|
316
516
|
|
|
317
517
|
// src/options.ts
|
|
318
518
|
function parseOptions(defaultOptions, customOptions) {
|
|
@@ -344,21 +544,21 @@ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
|
|
|
344
544
|
})`initiad move build ${args}`;
|
|
345
545
|
}
|
|
346
546
|
async function copyArtifacts(src, dest) {
|
|
347
|
-
if (
|
|
547
|
+
if (fs3.existsSync(dest)) {
|
|
348
548
|
console.log(`Removing existing artifacts at ${dest}`);
|
|
349
|
-
|
|
549
|
+
fs3.rmSync(dest, { recursive: true });
|
|
350
550
|
}
|
|
351
|
-
|
|
352
|
-
const moduleDir =
|
|
551
|
+
fs3.mkdirSync(dest, { recursive: true });
|
|
552
|
+
const moduleDir = path4.join(src, "bytecode_modules");
|
|
353
553
|
const modules = glob.sync("*.mv", { cwd: moduleDir });
|
|
354
554
|
for (const module of modules) {
|
|
355
|
-
const destByteCodePath =
|
|
356
|
-
if (!
|
|
357
|
-
|
|
555
|
+
const destByteCodePath = path4.join(dest, "bytecode_modules");
|
|
556
|
+
if (!fs3.existsSync(destByteCodePath)) {
|
|
557
|
+
fs3.mkdirSync(destByteCodePath, { recursive: true });
|
|
358
558
|
}
|
|
359
559
|
await $({
|
|
360
560
|
verbose: true
|
|
361
|
-
})`cp ${
|
|
561
|
+
})`cp ${path4.join(moduleDir, module)} ${path4.join(destByteCodePath, module)}`;
|
|
362
562
|
}
|
|
363
563
|
}
|
|
364
564
|
async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
|
|
@@ -367,11 +567,11 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
|
|
|
367
567
|
throw new Error(`module ${moduleName} not found`);
|
|
368
568
|
}
|
|
369
569
|
const { modulePath } = module;
|
|
370
|
-
const context = getMoveContext(moduleName, lzInitiaConfig, network);
|
|
570
|
+
const context = await getMoveContext(moduleName, lzInitiaConfig, network);
|
|
371
571
|
const pkgName = context[moduleName].package.name;
|
|
372
|
-
const srcPath =
|
|
572
|
+
const srcPath = path4.join(modulePath, "build", pkgName);
|
|
373
573
|
const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
|
|
374
|
-
const outputPath =
|
|
574
|
+
const outputPath = path4.join(
|
|
375
575
|
lzInitiaConfig.artifactsPath,
|
|
376
576
|
variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
|
|
377
577
|
);
|
|
@@ -436,8 +636,8 @@ function checkIfInitiaConfigExists() {
|
|
|
436
636
|
if (packagePath === void 0) {
|
|
437
637
|
throw new Error("package.json not found");
|
|
438
638
|
}
|
|
439
|
-
const configPath =
|
|
440
|
-
if (!
|
|
639
|
+
const configPath = path4.join(path4.dirname(packagePath), "lz-initia.config.ts");
|
|
640
|
+
if (!fs3.existsSync(configPath)) {
|
|
441
641
|
throw new Error("lz-initia.config.ts not found, please create one in the same directory as package.json");
|
|
442
642
|
}
|
|
443
643
|
return configPath;
|
|
@@ -454,6 +654,7 @@ async function main() {
|
|
|
454
654
|
}
|
|
455
655
|
main().then(() => process2.exit(process2.exitCode)).catch((error) => {
|
|
456
656
|
logger.error(error);
|
|
657
|
+
console.trace(error);
|
|
457
658
|
process2.exit(1);
|
|
458
659
|
});
|
|
459
660
|
//# sourceMappingURL=cli.mjs.map
|