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