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