@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/cli.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import fs3 from 'fs';
|
|
2
2
|
import path4 from 'path';
|
|
3
|
-
import
|
|
3
|
+
import process from 'process';
|
|
4
|
+
import { LCDClient, AccAddress, MsgPublish, Wallet, bcs, MsgExecute, MnemonicKey } from '@initia/initia.js';
|
|
5
|
+
import { sha3_256 } from '@noble/hashes/sha3';
|
|
6
|
+
import { networkToChainType, ChainType, InitiaChain, networkToChain, networkToEnv, EndpointVersion } from '@layerzerolabs/lz-definitions';
|
|
7
|
+
import { getLogger, ensure0x } from '@layerzerolabs/lz-utilities';
|
|
4
8
|
import { createOption, Command } from '@commander-js/extra-typings';
|
|
5
9
|
import { sync } from 'find-up';
|
|
6
10
|
import { $ as $$1 } from 'zx/core';
|
|
7
|
-
import { getLogger, ensure0x } from '@layerzerolabs/lz-utilities';
|
|
8
11
|
import * as crypto from 'node:crypto';
|
|
9
|
-
import { LCDClient, AccAddress, MsgPublish, Wallet, bcs, MsgExecute, MnemonicKey } from '@initia/initia.js';
|
|
10
|
-
import { sha3_256 } from '@noble/hashes/sha3';
|
|
11
|
-
import { networkToChainType, ChainType, InitiaChain, networkToChain, networkToEnv, EndpointVersion } from '@layerzerolabs/lz-definitions';
|
|
12
12
|
import { parse } from 'smol-toml';
|
|
13
13
|
import { glob } from 'glob';
|
|
14
14
|
import { $ } from 'zx';
|
|
@@ -24,34 +24,6 @@ var __export = (target, all) => {
|
|
|
24
24
|
for (var name in all)
|
|
25
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
// src/loader.ts
|
|
29
|
-
function loadConfig(configPath) {
|
|
30
|
-
const moduleName = "ts-node";
|
|
31
|
-
const tsnode = __require(moduleName);
|
|
32
|
-
tsnode.register({
|
|
33
|
-
transpileOnly: true,
|
|
34
|
-
typeCheck: false
|
|
35
|
-
});
|
|
36
|
-
try {
|
|
37
|
-
const imported = __require(configPath);
|
|
38
|
-
return "default" in imported ? imported.default : imported;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
if (e !== null && typeof e === "object" && "code" in e && e.code === "ERR_REQUIRE_ESM") {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Your project is an ESM project (you have "type": "module" set in your package.json) but your LayerZero config file uses the .js extension.`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
throw e;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/subCommands/index.ts
|
|
50
|
-
var subCommands_exports = {};
|
|
51
|
-
__export(subCommands_exports, {
|
|
52
|
-
build: () => command2,
|
|
53
|
-
deploy: () => command
|
|
54
|
-
});
|
|
55
27
|
function getInitiaClient(env, config) {
|
|
56
28
|
const url = config.network?.[env];
|
|
57
29
|
if (url === void 0) {
|
|
@@ -63,106 +35,56 @@ function getInitiaClient(env, config) {
|
|
|
63
35
|
|
|
64
36
|
// src/constant.ts
|
|
65
37
|
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
|
-
}
|
|
93
38
|
function isInitiaAccount(account) {
|
|
94
39
|
return account !== void 0 && account instanceof MnemonicKey;
|
|
95
40
|
}
|
|
96
|
-
function
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
if (lzAptosConfig.baseModules && lzAptosConfig.baseModules.length > 0) {
|
|
100
|
-
for (const baseModule of lzAptosConfig.baseModules) {
|
|
101
|
-
const baseConfig = loadConfig(baseModule);
|
|
102
|
-
try {
|
|
103
|
-
return getDeployer(moduleName, baseConfig, network);
|
|
104
|
-
} catch (e) {
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
throw new Error(
|
|
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.`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
|
|
113
|
-
const defaultDeployer = isInitiaAccount(lzAptosConfig.defaultDeployer) ? lzAptosConfig.defaultDeployer : lzAptosConfig.defaultDeployer?.[network];
|
|
114
|
-
const deployer = moduleDeployer ?? defaultDeployer;
|
|
115
|
-
if (!deployer) {
|
|
116
|
-
throw new Error(`deployer for module ${moduleName} not found`);
|
|
117
|
-
}
|
|
118
|
-
return deployer;
|
|
119
|
-
}
|
|
120
|
-
function getDeploymentPath(lzAptosConfig, network, moduleName) {
|
|
121
|
-
return path4.join(lzAptosConfig.deploymentPath, network, `${moduleName}.json`);
|
|
41
|
+
function getDeploymentPath(lzInitiaConfig, network, moduleName) {
|
|
42
|
+
const fullName = getFullName(lzInitiaConfig, moduleName);
|
|
43
|
+
return path4.join(lzInitiaConfig.deploymentPath, network, `${fullName}.json`);
|
|
122
44
|
}
|
|
123
|
-
async function checkIfObjectAddressExists(
|
|
45
|
+
async function checkIfObjectAddressExists(lzInitiaConfig, network, address) {
|
|
124
46
|
try {
|
|
125
|
-
const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2),
|
|
47
|
+
const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzInitiaConfig);
|
|
126
48
|
const module = (await client.move.modules(address))[0];
|
|
127
49
|
return module !== void 0;
|
|
128
50
|
} catch (e) {
|
|
129
51
|
return false;
|
|
130
52
|
}
|
|
131
53
|
}
|
|
132
|
-
function getObjectAddressFromDeployment(
|
|
133
|
-
const deploymentPath2 = getDeploymentPath(
|
|
54
|
+
function getObjectAddressFromDeployment(lzInitiaConfig, network, moduleName) {
|
|
55
|
+
const deploymentPath2 = getDeploymentPath(lzInitiaConfig, network, moduleName);
|
|
134
56
|
if (!fs3.existsSync(deploymentPath2)) {
|
|
135
57
|
return void 0;
|
|
136
58
|
}
|
|
137
59
|
const deployment = JSON.parse(fs3.readFileSync(deploymentPath2, "utf-8"));
|
|
138
60
|
return deployment.address;
|
|
139
61
|
}
|
|
140
|
-
async function resolveAddress(
|
|
141
|
-
const deployToObject =
|
|
62
|
+
async function resolveAddress(moduleKey, lzInitiaConfig, network, isOngoingModule) {
|
|
63
|
+
const deployToObject = lzInitiaConfig.modules[moduleKey]?.deployToObject ?? lzInitiaConfig.defaultDeployToObject ?? false;
|
|
142
64
|
if (!deployToObject) {
|
|
143
|
-
const deployer =
|
|
65
|
+
const deployer = getDeployerAccount(moduleKey, lzInitiaConfig, network);
|
|
144
66
|
return AccAddress.toHex(deployer.accAddress);
|
|
145
67
|
}
|
|
146
|
-
const objectDeployer = getObjectDeployerFromConfig(
|
|
68
|
+
const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleKey);
|
|
147
69
|
if (objectDeployer !== InitiaObjectDeployerAddress) {
|
|
148
|
-
return genObjectAddressForLayerzero(network,
|
|
70
|
+
return genObjectAddressForLayerzero(network, lzInitiaConfig, moduleKey);
|
|
149
71
|
}
|
|
150
|
-
const objectAddress = getObjectAddressFromDeployment(
|
|
72
|
+
const objectAddress = getObjectAddressFromDeployment(lzInitiaConfig, network, moduleKey);
|
|
151
73
|
if (objectAddress !== void 0) {
|
|
152
|
-
if (await checkIfObjectAddressExists(
|
|
74
|
+
if (await checkIfObjectAddressExists(lzInitiaConfig, network, objectAddress)) {
|
|
153
75
|
return objectAddress;
|
|
154
76
|
}
|
|
155
77
|
if (!isOngoingModule) {
|
|
156
78
|
throw new Error(
|
|
157
|
-
`Deployment file found at: ${getDeploymentPath(
|
|
79
|
+
`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.`
|
|
158
80
|
);
|
|
159
81
|
}
|
|
160
82
|
} else if (!isOngoingModule) {
|
|
161
83
|
throw new Error(
|
|
162
|
-
`Deployment file not found at: ${getDeploymentPath(
|
|
84
|
+
`Deployment file not found at: ${getDeploymentPath(lzInitiaConfig, network, moduleKey)}. Make sure ${moduleKey} is deployed.`
|
|
163
85
|
);
|
|
164
86
|
}
|
|
165
|
-
return genObjectAddress(
|
|
87
|
+
return genObjectAddress(moduleKey, lzInitiaConfig, network);
|
|
166
88
|
}
|
|
167
89
|
var createObjectAddress = (creatorAddress, seed) => {
|
|
168
90
|
const hexAddress = AccAddress.validate(creatorAddress) ? AccAddress.toHex(creatorAddress) : creatorAddress;
|
|
@@ -171,9 +93,9 @@ var createObjectAddress = (creatorAddress, seed) => {
|
|
|
171
93
|
const bytes = new Uint8Array([...creatorBytes, ...seedBytes, 254]);
|
|
172
94
|
return ensure0x(Buffer.from(sha3_256(bytes)).toString("hex"));
|
|
173
95
|
};
|
|
174
|
-
async function genObjectAddressForOfficial(network,
|
|
175
|
-
const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2),
|
|
176
|
-
const deployer =
|
|
96
|
+
async function genObjectAddressForOfficial(network, lzInitiaConfig, moduleKey) {
|
|
97
|
+
const client = getInitiaClient(networkToEnv(network, EndpointVersion.V2), lzInitiaConfig);
|
|
98
|
+
const deployer = getDeployerAccount(moduleKey, lzInitiaConfig, network);
|
|
177
99
|
const OBJECT_CODE_DEPLOYMENT_DOMAIN_SEPARATOR = "initia_std::object_code_deployment";
|
|
178
100
|
const account = await client.auth.accountInfo(deployer.accAddress);
|
|
179
101
|
const sequenceNumber = account.getSequenceNumber();
|
|
@@ -183,33 +105,132 @@ async function genObjectAddressForOfficial(network, lzAptosConfig, moduleName) {
|
|
|
183
105
|
const objectAddress = createObjectAddress(deployer.accAddress, seed);
|
|
184
106
|
return objectAddress;
|
|
185
107
|
}
|
|
186
|
-
function genObjectAddressForLayerzero(network,
|
|
187
|
-
const deployer =
|
|
188
|
-
const seed = getFullName(
|
|
108
|
+
function genObjectAddressForLayerzero(network, lzInitiaConfig, moduleName) {
|
|
109
|
+
const deployer = getDeployerAccount(moduleName, lzInitiaConfig, network);
|
|
110
|
+
const seed = getFullName(lzInitiaConfig, moduleName);
|
|
189
111
|
const objectAddress = createObjectAddress(deployer.accAddress, new Uint8Array(Buffer.from(seed, "utf8")));
|
|
190
112
|
return objectAddress;
|
|
191
113
|
}
|
|
192
|
-
async function genObjectAddress(
|
|
193
|
-
const objectDeployer = getObjectDeployerFromConfig(
|
|
114
|
+
async function genObjectAddress(moduleKey, lzInitiaConfig, network) {
|
|
115
|
+
const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleKey);
|
|
194
116
|
if (objectDeployer === InitiaObjectDeployerAddress) {
|
|
195
|
-
return genObjectAddressForOfficial(network,
|
|
117
|
+
return genObjectAddressForOfficial(network, lzInitiaConfig, moduleKey);
|
|
196
118
|
}
|
|
197
|
-
return genObjectAddressForLayerzero(network,
|
|
119
|
+
return genObjectAddressForLayerzero(network, lzInitiaConfig, moduleKey);
|
|
198
120
|
}
|
|
121
|
+
|
|
122
|
+
// src/loader.ts
|
|
123
|
+
function loadConfig(configPath) {
|
|
124
|
+
const moduleName = "ts-node";
|
|
125
|
+
const tsnode = __require(moduleName);
|
|
126
|
+
tsnode.register({
|
|
127
|
+
transpileOnly: true,
|
|
128
|
+
typeCheck: false
|
|
129
|
+
});
|
|
130
|
+
try {
|
|
131
|
+
const imported = __require(configPath);
|
|
132
|
+
return "default" in imported ? imported.default : imported;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
if (e !== null && typeof e === "object" && "code" in e && e.code === "ERR_REQUIRE_ESM") {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Your project is an ESM project (you have "type": "module" set in your package.json) but your LayerZero config file uses the .js extension.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/config-parser.ts
|
|
144
|
+
function getConfigByNetwork(config, network) {
|
|
145
|
+
if (config === null) {
|
|
146
|
+
throw new Error("Config is null");
|
|
147
|
+
}
|
|
148
|
+
if (typeof config === "object") {
|
|
149
|
+
return config[network];
|
|
150
|
+
}
|
|
151
|
+
return config;
|
|
152
|
+
}
|
|
153
|
+
function getObjectDeployer(configValue, network) {
|
|
154
|
+
return getConfigByNetwork(configValue, network);
|
|
155
|
+
}
|
|
156
|
+
function getObjectDeployerFromConfig(config, network, moduleName) {
|
|
157
|
+
const module = config.modules[moduleName];
|
|
158
|
+
if (!module) {
|
|
159
|
+
throw new Error(`module ${moduleName} not found when getting object deployer`);
|
|
160
|
+
}
|
|
161
|
+
const moduleObjectDeployer = getObjectDeployer(module.objectDeployer, network);
|
|
162
|
+
const defaultObjectDeployer = getObjectDeployer(config.defaultObjectDeployer, network);
|
|
163
|
+
return moduleObjectDeployer ?? defaultObjectDeployer ?? InitiaObjectDeployerAddress;
|
|
164
|
+
}
|
|
165
|
+
function getDeployerAccount(moduleName, lzInitiaConfig, network) {
|
|
166
|
+
const module = lzInitiaConfig.modules[moduleName];
|
|
167
|
+
if (!module) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`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.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
|
|
173
|
+
const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
|
|
174
|
+
const deployer = moduleDeployer ?? defaultDeployer;
|
|
175
|
+
if (!deployer) {
|
|
176
|
+
throw new Error(`deployer for module ${moduleName} not found`);
|
|
177
|
+
}
|
|
178
|
+
return deployer;
|
|
179
|
+
}
|
|
180
|
+
function getFullName(config, moduleName) {
|
|
181
|
+
const variant = config.modules[moduleName]?.variant;
|
|
182
|
+
return variant !== void 0 && variant.length > 0 ? `${moduleName}-${variant}` : moduleName;
|
|
183
|
+
}
|
|
184
|
+
function combineBaseConfigRecursive(config) {
|
|
185
|
+
if (!config.baseModules || config.baseModules.length === 0) {
|
|
186
|
+
return config;
|
|
187
|
+
}
|
|
188
|
+
const baseConfigs = config.baseModules.map((baseModule) => combineBaseConfigRecursive(loadConfig(baseModule)));
|
|
189
|
+
const result = baseConfigs.reduce((acc, baseConfig) => {
|
|
190
|
+
for (const moduleKey in baseConfig.modules) {
|
|
191
|
+
baseConfig.modules[moduleKey].deployer = baseConfig.modules[moduleKey]?.deployer ?? baseConfig.defaultDeployer;
|
|
192
|
+
baseConfig.modules[moduleKey].objectDeployer = baseConfig.modules[moduleKey]?.objectDeployer ?? baseConfig.defaultObjectDeployer;
|
|
193
|
+
baseConfig.modules[moduleKey].deployToObject = baseConfig.modules[moduleKey]?.deployToObject ?? baseConfig.defaultDeployToObject;
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
...acc,
|
|
197
|
+
...baseConfig,
|
|
198
|
+
modules: {
|
|
199
|
+
...acc.modules,
|
|
200
|
+
...baseConfig.modules
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, config);
|
|
204
|
+
return {
|
|
205
|
+
...config,
|
|
206
|
+
modules: {
|
|
207
|
+
...result.modules,
|
|
208
|
+
...config.modules
|
|
209
|
+
// current modules has higher priority
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/subCommands/index.ts
|
|
215
|
+
var subCommands_exports = {};
|
|
216
|
+
__export(subCommands_exports, {
|
|
217
|
+
build: () => command2,
|
|
218
|
+
deploy: () => command
|
|
219
|
+
});
|
|
199
220
|
function isAxiosError(error) {
|
|
200
221
|
return error?.response?.data?.message !== void 0;
|
|
201
222
|
}
|
|
202
|
-
function handleDepMissingError(error,
|
|
223
|
+
function handleDepMissingError(error, pkgName, context) {
|
|
203
224
|
if (error.response.data.message.includes("EPACKAGE_DEP_MISSING")) {
|
|
204
225
|
throw new Error(
|
|
205
|
-
`Deploy ${
|
|
226
|
+
`Deploy ${pkgName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
|
|
206
227
|
context
|
|
207
|
-
).filter((module) => module !==
|
|
228
|
+
).filter((module) => module !== pkgName).join(",")}]`
|
|
208
229
|
);
|
|
209
230
|
}
|
|
210
231
|
}
|
|
211
|
-
function handleAccountNotFoundError(error,
|
|
212
|
-
const address = context[
|
|
232
|
+
function handleAccountNotFoundError(error, pkgName, context, network) {
|
|
233
|
+
const address = context[pkgName]?.addresses[pkgName];
|
|
213
234
|
if (address === void 0) {
|
|
214
235
|
return;
|
|
215
236
|
}
|
|
@@ -219,21 +240,21 @@ function handleAccountNotFoundError(error, moduleName, context, network) {
|
|
|
219
240
|
);
|
|
220
241
|
}
|
|
221
242
|
}
|
|
222
|
-
function handleSenderNotMatchError(error,
|
|
243
|
+
function handleSenderNotMatchError(error, pkgName) {
|
|
223
244
|
if (error.response.data.message.includes("MODULE_ADDRESS_DOES_NOT_MATCH_SENDER")) {
|
|
224
245
|
throw new Error(
|
|
225
|
-
`Deploy ${
|
|
246
|
+
`Deploy ${pkgName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${pkgName} with the deployer account address`
|
|
226
247
|
);
|
|
227
248
|
}
|
|
228
249
|
}
|
|
229
250
|
function handleOtherAxiosError(error) {
|
|
230
251
|
throw new Error(error.response.data.message);
|
|
231
252
|
}
|
|
232
|
-
function handleError(error,
|
|
253
|
+
function handleError(error, pkgName, context, network) {
|
|
233
254
|
if (isAxiosError(error)) {
|
|
234
|
-
handleDepMissingError(error,
|
|
235
|
-
handleAccountNotFoundError(error,
|
|
236
|
-
handleSenderNotMatchError(error,
|
|
255
|
+
handleDepMissingError(error, pkgName, context);
|
|
256
|
+
handleAccountNotFoundError(error, pkgName, context, network);
|
|
257
|
+
handleSenderNotMatchError(error, pkgName);
|
|
237
258
|
handleOtherAxiosError(error);
|
|
238
259
|
}
|
|
239
260
|
throw error;
|
|
@@ -276,40 +297,65 @@ function parseAddresses(addresses, network) {
|
|
|
276
297
|
}
|
|
277
298
|
return result;
|
|
278
299
|
}
|
|
279
|
-
|
|
280
|
-
const module = lzInitiaConfig.modules[
|
|
300
|
+
function getPkgName(moduleKey, lzInitiaConfig) {
|
|
301
|
+
const module = lzInitiaConfig.modules[moduleKey];
|
|
281
302
|
if (!module) {
|
|
282
|
-
throw new Error(`module ${
|
|
303
|
+
throw new Error(`module ${moduleKey} not found in lz-initia.config.ts`);
|
|
304
|
+
}
|
|
305
|
+
const tomlPath = path4.join(module.modulePath, "Move.toml");
|
|
306
|
+
if (!fs3.existsSync(tomlPath)) {
|
|
307
|
+
throw new Error(`Move.toml not found in ${tomlPath}`);
|
|
308
|
+
}
|
|
309
|
+
const toml = parse(fs3.readFileSync(tomlPath, "utf-8"));
|
|
310
|
+
return toml.package.name;
|
|
311
|
+
}
|
|
312
|
+
function genModuleKeyToPkgNameMap(lzInitiaConfig) {
|
|
313
|
+
const result = {};
|
|
314
|
+
for (const moduleKey of Object.keys(lzInitiaConfig.modules)) {
|
|
315
|
+
result[getPkgName(moduleKey, lzInitiaConfig)] = moduleKey;
|
|
316
|
+
}
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
async function getMoveContext(moduleKey, lzInitiaConfig, network) {
|
|
320
|
+
const module = lzInitiaConfig.modules[moduleKey];
|
|
321
|
+
if (!module) {
|
|
322
|
+
throw new Error(`module ${moduleKey} not found when getting Move context`);
|
|
283
323
|
}
|
|
284
324
|
const context = getRawMoveContextByPath(module.modulePath);
|
|
285
|
-
|
|
286
|
-
|
|
325
|
+
const pkgNameToModuleKey = genModuleKeyToPkgNameMap(lzInitiaConfig);
|
|
326
|
+
for (const pkgName of Object.keys(context)) {
|
|
327
|
+
const toml = context[pkgName];
|
|
287
328
|
for (const addressKey of Object.keys(toml.addresses)) {
|
|
288
329
|
const address = toml.addresses[addressKey];
|
|
289
330
|
const presetAddresses = {
|
|
290
|
-
...parseAddresses(lzInitiaConfig.modules[
|
|
331
|
+
...parseAddresses(lzInitiaConfig.modules[pkgNameToModuleKey[pkgName]]?.addresses, network),
|
|
291
332
|
// dependency or current module config address
|
|
292
|
-
...parseAddresses(lzInitiaConfig.modules[
|
|
333
|
+
...parseAddresses(lzInitiaConfig.modules[moduleKey]?.addresses, network)
|
|
293
334
|
// current module config address
|
|
294
335
|
};
|
|
295
336
|
if (address === "_") {
|
|
296
337
|
if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
|
|
297
338
|
toml.addresses[addressKey] = presetAddresses[addressKey];
|
|
298
339
|
} else {
|
|
340
|
+
const isOnGoingModule = moduleKey === pkgNameToModuleKey[addressKey];
|
|
299
341
|
try {
|
|
300
|
-
|
|
342
|
+
if (pkgNameToModuleKey[addressKey] === void 0) {
|
|
343
|
+
throw new Error(
|
|
344
|
+
`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.`
|
|
345
|
+
);
|
|
346
|
+
}
|
|
301
347
|
toml.addresses[addressKey] = await resolveAddress(
|
|
302
|
-
addressKey,
|
|
348
|
+
pkgNameToModuleKey[addressKey],
|
|
303
349
|
lzInitiaConfig,
|
|
304
350
|
network,
|
|
305
351
|
isOnGoingModule
|
|
306
352
|
);
|
|
307
353
|
} catch (e) {
|
|
308
|
-
if (
|
|
309
|
-
throw new Error(`Fail to generate context for ${
|
|
354
|
+
if (isOnGoingModule) {
|
|
355
|
+
throw new Error(`Fail to generate context for ${pkgName}. ${e.toString()}`);
|
|
310
356
|
} else {
|
|
311
357
|
throw new Error(
|
|
312
|
-
`Fail to generate context for dependent module ${
|
|
358
|
+
`Fail to generate context for dependent module ${pkgName}. ${e.toString()}`
|
|
313
359
|
);
|
|
314
360
|
}
|
|
315
361
|
}
|
|
@@ -319,12 +365,12 @@ async function getMoveContext(moduleName, lzInitiaConfig, network) {
|
|
|
319
365
|
}
|
|
320
366
|
return context;
|
|
321
367
|
}
|
|
322
|
-
function deploymentPath(
|
|
368
|
+
function deploymentPath(moduleKey, dest, network, variant) {
|
|
323
369
|
const deploymentPath2 = path4.join(dest, network);
|
|
324
|
-
return path4.join(deploymentPath2, `${
|
|
370
|
+
return path4.join(deploymentPath2, `${moduleKeyWithVariant(moduleKey, variant)}.json`);
|
|
325
371
|
}
|
|
326
|
-
function saveDeployment(deployer,
|
|
327
|
-
const destPath = deploymentPath(
|
|
372
|
+
function saveDeployment(deployer, moduleKey, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
|
|
373
|
+
const destPath = deploymentPath(moduleKey, dest, network, variant);
|
|
328
374
|
const deploymentDir = path4.dirname(destPath);
|
|
329
375
|
if (!fs3.existsSync(deploymentDir)) {
|
|
330
376
|
fs3.mkdirSync(deploymentDir, { recursive: true });
|
|
@@ -335,8 +381,8 @@ function saveDeployment(deployer, moduleName, pkgName, address, dest, network, b
|
|
|
335
381
|
{
|
|
336
382
|
address,
|
|
337
383
|
deployer: AccAddress.toHex(deployer.accAddress),
|
|
338
|
-
name:
|
|
339
|
-
moduleName,
|
|
384
|
+
name: moduleKeyWithVariant(moduleKey, variant),
|
|
385
|
+
moduleName: pkgName,
|
|
340
386
|
network,
|
|
341
387
|
compatibleVersions,
|
|
342
388
|
bytecodeHash,
|
|
@@ -348,10 +394,10 @@ function saveDeployment(deployer, moduleName, pkgName, address, dest, network, b
|
|
|
348
394
|
);
|
|
349
395
|
console.log(`Deployment saved to ${destPath}`);
|
|
350
396
|
}
|
|
351
|
-
async function checkIfModuleExistedOnAddress(client,
|
|
397
|
+
async function checkIfModuleExistedOnAddress(client, mvNames, address) {
|
|
352
398
|
try {
|
|
353
399
|
const modules = (await client.move.modules(address))[0];
|
|
354
|
-
const isExisted =
|
|
400
|
+
const isExisted = mvNames.some(
|
|
355
401
|
(moduleName) => modules.map((module) => module.module_name).includes(moduleName.replace(".mv", ""))
|
|
356
402
|
);
|
|
357
403
|
return isExisted;
|
|
@@ -359,10 +405,10 @@ async function checkIfModuleExistedOnAddress(client, moduleNames, address) {
|
|
|
359
405
|
return false;
|
|
360
406
|
}
|
|
361
407
|
}
|
|
362
|
-
async function getDeployActionType(client,
|
|
363
|
-
const moduleExisted = await checkIfModuleExistedOnAddress(client,
|
|
408
|
+
async function getDeployActionType(client, moduleKey, mvNames, dest, network, bytecodeHash, deployAddress, variant) {
|
|
409
|
+
const moduleExisted = await checkIfModuleExistedOnAddress(client, mvNames, deployAddress);
|
|
364
410
|
if (moduleExisted) {
|
|
365
|
-
const destPath = deploymentPath(
|
|
411
|
+
const destPath = deploymentPath(moduleKey, dest, network, variant);
|
|
366
412
|
if (fs3.existsSync(destPath)) {
|
|
367
413
|
const deployment = JSON.parse(fs3.readFileSync(destPath, "utf-8"));
|
|
368
414
|
if (deployment.bytecodeHash === bytecodeHash) {
|
|
@@ -373,8 +419,8 @@ async function getDeployActionType(client, pkgName, moduleNames, dest, network,
|
|
|
373
419
|
}
|
|
374
420
|
return "Deploy" /* Deploy */;
|
|
375
421
|
}
|
|
376
|
-
function
|
|
377
|
-
return variant !== void 0 && variant.length > 0 ? `${
|
|
422
|
+
function moduleKeyWithVariant(moduleKey, variant) {
|
|
423
|
+
return variant !== void 0 && variant.length > 0 ? `${moduleKey}-${variant}` : moduleKey;
|
|
378
424
|
}
|
|
379
425
|
function getBytecodesHash(bytecodes) {
|
|
380
426
|
const hash = crypto.createHash("sha256");
|
|
@@ -396,14 +442,14 @@ async function createAccountDeploymentTx(client, deployer, modules, lzInitiaConf
|
|
|
396
442
|
const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
|
|
397
443
|
return signedTx;
|
|
398
444
|
}
|
|
399
|
-
async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network,
|
|
400
|
-
const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network,
|
|
445
|
+
async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfig, network, moduleKey, deployedAddress, actionType) {
|
|
446
|
+
const objectDeployer = getObjectDeployerFromConfig(lzInitiaConfig, network, moduleKey);
|
|
401
447
|
const metadataArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from([])).toBase64();
|
|
402
448
|
const modulesArg = bcs.vector(bcs.vector(bcs.u8())).serialize(modules).toBase64();
|
|
403
449
|
const objectAddressArg = bcs.address().serialize(deployedAddress).toBase64();
|
|
404
450
|
let functionArguments = actionType === "Deploy" /* Deploy */ ? [metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
|
|
405
451
|
if (objectDeployer !== InitiaObjectDeployerAddress) {
|
|
406
|
-
const seed = getFullName(lzInitiaConfig,
|
|
452
|
+
const seed = getFullName(lzInitiaConfig, moduleKey);
|
|
407
453
|
const seedArg = bcs.vector(bcs.u8()).serialize(Uint8Array.from(Buffer.from(seed))).toBase64();
|
|
408
454
|
functionArguments = actionType === "Deploy" /* Deploy */ ? [seedArg, metadataArg, modulesArg] : [metadataArg, modulesArg, objectAddressArg];
|
|
409
455
|
}
|
|
@@ -420,24 +466,27 @@ async function createObjectDeploymentTx(client, deployer, modules, lzInitiaConfi
|
|
|
420
466
|
const signedTx = await wallet.createAndSignTx({ msgs: [msg], gasPrices });
|
|
421
467
|
return signedTx;
|
|
422
468
|
}
|
|
423
|
-
async function deploy(
|
|
424
|
-
const module = lzInitiaConfig.modules[
|
|
469
|
+
async function deploy(moduleKey, lzInitiaConfig, network, variant, deployToObject = false) {
|
|
470
|
+
const module = lzInitiaConfig.modules[moduleKey];
|
|
425
471
|
if (!module) {
|
|
426
|
-
throw new Error(`module ${
|
|
472
|
+
throw new Error(`module ${moduleKey} not found in lz-initia.config.ts`);
|
|
427
473
|
}
|
|
428
474
|
const env = networkToEnv(network, EndpointVersion.V2);
|
|
429
475
|
const client = getInitiaClient(env, lzInitiaConfig);
|
|
430
|
-
const deployer =
|
|
431
|
-
const context = await getMoveContext(
|
|
432
|
-
const pkgName = lzInitiaConfig
|
|
433
|
-
const moduleDir = path4.join(
|
|
476
|
+
const deployer = getDeployerAccount(moduleKey, lzInitiaConfig, network);
|
|
477
|
+
const context = await getMoveContext(moduleKey, lzInitiaConfig, network);
|
|
478
|
+
const pkgName = getPkgName(moduleKey, lzInitiaConfig);
|
|
479
|
+
const moduleDir = path4.join(
|
|
480
|
+
lzInitiaConfig.artifactsPath,
|
|
481
|
+
`${moduleKeyWithVariant(pkgName, variant)}/bytecode_modules`
|
|
482
|
+
);
|
|
434
483
|
const mvNames = glob.sync("*.mv", { cwd: moduleDir });
|
|
435
|
-
const moduleBuffers = mvNames.map((
|
|
484
|
+
const moduleBuffers = mvNames.map((moduleName) => fs3.readFileSync(path4.join(moduleDir, moduleName)));
|
|
436
485
|
const bytecodeHash = getBytecodesHash(moduleBuffers);
|
|
437
|
-
const deployAddress = await resolveAddress(
|
|
486
|
+
const deployAddress = await resolveAddress(moduleKey, lzInitiaConfig, network, true);
|
|
438
487
|
const actionType = await getDeployActionType(
|
|
439
488
|
client,
|
|
440
|
-
|
|
489
|
+
moduleKey,
|
|
441
490
|
mvNames,
|
|
442
491
|
lzInitiaConfig.deploymentPath,
|
|
443
492
|
network,
|
|
@@ -446,7 +495,7 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
|
|
|
446
495
|
variant
|
|
447
496
|
);
|
|
448
497
|
if (actionType === "Skip" /* Skip */) {
|
|
449
|
-
console.warn(`Code of ${
|
|
498
|
+
console.warn(`Code of ${moduleKey} has not changed, skipping deploy`);
|
|
450
499
|
return;
|
|
451
500
|
}
|
|
452
501
|
try {
|
|
@@ -456,7 +505,7 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
|
|
|
456
505
|
moduleBuffers,
|
|
457
506
|
lzInitiaConfig,
|
|
458
507
|
network,
|
|
459
|
-
|
|
508
|
+
moduleKey,
|
|
460
509
|
deployAddress,
|
|
461
510
|
actionType
|
|
462
511
|
) : await createAccountDeploymentTx(client, deployer, moduleBuffers, lzInitiaConfig, network);
|
|
@@ -472,11 +521,11 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
|
|
|
472
521
|
throw new Error(tx.raw_log);
|
|
473
522
|
}
|
|
474
523
|
console.log(
|
|
475
|
-
`${actionType} ${
|
|
524
|
+
`${actionType} ${moduleKey} to ${deployToObject ? "Object" : "Account"}(${codeAddress}) succeeded on ${network}`
|
|
476
525
|
);
|
|
477
526
|
saveDeployment(
|
|
478
527
|
deployer,
|
|
479
|
-
|
|
528
|
+
moduleKey,
|
|
480
529
|
pkgName,
|
|
481
530
|
codeAddress,
|
|
482
531
|
lzInitiaConfig.deploymentPath,
|
|
@@ -488,7 +537,7 @@ async function deploy(moduleName, lzInitiaConfig, network, variant, deployToObje
|
|
|
488
537
|
);
|
|
489
538
|
} catch (e) {
|
|
490
539
|
if (e instanceof Error) {
|
|
491
|
-
handleError(e,
|
|
540
|
+
handleError(e, moduleKey, context, network);
|
|
492
541
|
} else {
|
|
493
542
|
throw e;
|
|
494
543
|
}
|
|
@@ -541,18 +590,20 @@ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
|
|
|
541
590
|
const addressesParam = Object.keys(addresses).map((key) => `${key}=${addresses[key]}`).join(",");
|
|
542
591
|
const defaultOptions = {
|
|
543
592
|
"--skip-fetch-latest-git-deps": true,
|
|
544
|
-
"--named-addresses": addressesParam
|
|
593
|
+
"--named-addresses": addressesParam,
|
|
594
|
+
"--verbose": true
|
|
545
595
|
};
|
|
546
596
|
const args = parseOptions(defaultOptions, customOptions);
|
|
597
|
+
console.log(`initiad move build ${args.join(" ")}`);
|
|
547
598
|
return $({
|
|
548
599
|
cwd: modulePath,
|
|
549
|
-
|
|
550
|
-
|
|
600
|
+
// pipe std error to avoid printing the compiling message which is not useful
|
|
601
|
+
stdio: ["inherit", "inherit", "pipe"],
|
|
602
|
+
quiet: true
|
|
551
603
|
})`initiad move build ${args}`;
|
|
552
604
|
}
|
|
553
605
|
async function copyArtifacts(src, dest) {
|
|
554
606
|
if (fs3.existsSync(dest)) {
|
|
555
|
-
console.log(`Removing existing artifacts at ${dest}`);
|
|
556
607
|
fs3.rmSync(dest, { recursive: true });
|
|
557
608
|
}
|
|
558
609
|
fs3.mkdirSync(dest, { recursive: true });
|
|
@@ -564,24 +615,22 @@ async function copyArtifacts(src, dest) {
|
|
|
564
615
|
fs3.mkdirSync(destByteCodePath, { recursive: true });
|
|
565
616
|
}
|
|
566
617
|
await $({
|
|
567
|
-
verbose:
|
|
618
|
+
verbose: false,
|
|
619
|
+
quiet: true
|
|
568
620
|
})`cp ${path4.join(moduleDir, module)} ${path4.join(destByteCodePath, module)}`;
|
|
569
621
|
}
|
|
570
622
|
}
|
|
571
|
-
async function build(
|
|
572
|
-
const module = lzInitiaConfig.modules[
|
|
623
|
+
async function build(moduleKey, lzInitiaConfig, network, skipBuild = false, variant) {
|
|
624
|
+
const module = lzInitiaConfig.modules[moduleKey];
|
|
573
625
|
if (!module) {
|
|
574
|
-
throw new Error(`module ${
|
|
626
|
+
throw new Error(`module ${moduleKey} not found in lz-initia.config.ts`);
|
|
575
627
|
}
|
|
576
628
|
const { modulePath } = module;
|
|
577
|
-
const context = await getMoveContext(
|
|
578
|
-
const pkgName = context[
|
|
629
|
+
const context = await getMoveContext(moduleKey, lzInitiaConfig, network);
|
|
630
|
+
const pkgName = context[moduleKey].package.name;
|
|
579
631
|
const srcPath = path4.join(modulePath, "build", pkgName);
|
|
580
|
-
const outputDir = lzInitiaConfig
|
|
581
|
-
const outputPath = path4.join(
|
|
582
|
-
lzInitiaConfig.artifactsPath,
|
|
583
|
-
variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
|
|
584
|
-
);
|
|
632
|
+
const outputDir = getFullName(lzInitiaConfig, moduleKey);
|
|
633
|
+
const outputPath = path4.join(lzInitiaConfig.artifactsPath, outputDir);
|
|
585
634
|
let addresses = {};
|
|
586
635
|
for (const key of Object.keys(context)) {
|
|
587
636
|
const toml = context[key];
|
|
@@ -590,9 +639,9 @@ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, var
|
|
|
590
639
|
}
|
|
591
640
|
addresses = { ...addresses, ...toml.addresses };
|
|
592
641
|
}
|
|
593
|
-
addresses = { ...addresses, ...context[
|
|
642
|
+
addresses = { ...addresses, ...context[pkgName].addresses };
|
|
594
643
|
if (!skipBuild) {
|
|
595
|
-
await buildProcess(modulePath, addresses, context[
|
|
644
|
+
await buildProcess(modulePath, addresses, context[pkgName], {
|
|
596
645
|
...lzInitiaConfig.compileOptions,
|
|
597
646
|
...module.compileOptions
|
|
598
647
|
});
|
|
@@ -639,7 +688,7 @@ async function checkIfInitiaInstalled() {
|
|
|
639
688
|
}
|
|
640
689
|
}
|
|
641
690
|
function checkIfInitiaConfigExists() {
|
|
642
|
-
const packagePath = sync("package.json", { cwd:
|
|
691
|
+
const packagePath = sync("package.json", { cwd: process.cwd() });
|
|
643
692
|
if (packagePath === void 0) {
|
|
644
693
|
throw new Error("package.json not found");
|
|
645
694
|
}
|
|
@@ -654,15 +703,15 @@ async function main() {
|
|
|
654
703
|
const configPath = checkIfInitiaConfigExists();
|
|
655
704
|
const config = loadConfig(configPath);
|
|
656
705
|
Object.values(subCommands_exports).forEach((subCommand) => {
|
|
657
|
-
subCommand.setOptionValue("__CONTEXT__", config);
|
|
706
|
+
subCommand.setOptionValue("__CONTEXT__", combineBaseConfigRecursive(config));
|
|
658
707
|
program.addCommand(subCommand);
|
|
659
708
|
});
|
|
660
709
|
await program.parseAsync();
|
|
661
710
|
}
|
|
662
|
-
main().then(() =>
|
|
711
|
+
main().then(() => process.exit(process.exitCode)).catch((error) => {
|
|
663
712
|
logger.error(error);
|
|
664
713
|
console.trace(error);
|
|
665
|
-
|
|
714
|
+
process.exit(1);
|
|
666
715
|
});
|
|
667
716
|
//# sourceMappingURL=cli.mjs.map
|
|
668
717
|
//# sourceMappingURL=cli.mjs.map
|