@layerzerolabs/lz-initia-cli 2.3.45-initia-oft.5

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 ADDED
@@ -0,0 +1,88 @@
1
+ # @layerzerolabs/lz-initia-cli
2
+
3
+ ## 2.3.45-initia-oft.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Build Initia,aptos,movement,bsc snapshot images with newest images
8
+ - Updated dependencies
9
+ - @layerzerolabs/lz-definitions@2.3.45-initia-oft.5
10
+ - @layerzerolabs/lz-config-types@2.3.45-initia-oft.5
11
+ - @layerzerolabs/lz-utilities@2.3.45-initia-oft.5
12
+
13
+ ## 2.3.45-initia-oft.4
14
+
15
+ ### Patch Changes
16
+
17
+ - Build initia images with newest contracts
18
+ - Updated dependencies
19
+ - @layerzerolabs/lz-definitions@2.3.45-initia-oft.4
20
+ - @layerzerolabs/lz-config-types@2.3.45-initia-oft.4
21
+ - @layerzerolabs/lz-utilities@2.3.45-initia-oft.4
22
+
23
+ ## 2.3.45-initia-oft.3
24
+
25
+ ### Patch Changes
26
+
27
+ - Fix Aptos OFT SDK to fit newest contracts
28
+ - Updated dependencies
29
+ - @layerzerolabs/lz-definitions@2.3.45-initia-oft.3
30
+ - @layerzerolabs/lz-config-types@2.3.45-initia-oft.3
31
+ - @layerzerolabs/lz-utilities@2.3.45-initia-oft.3
32
+
33
+ ## 2.3.45-initia-oft.2
34
+
35
+ ### Patch Changes
36
+
37
+ - Fix bug in Initia OFT sdk
38
+ - Updated dependencies
39
+ - @layerzerolabs/lz-definitions@2.3.45-initia-oft.2
40
+ - @layerzerolabs/lz-config-types@2.3.45-initia-oft.2
41
+ - @layerzerolabs/lz-utilities@2.3.45-initia-oft.2
42
+
43
+ ## 2.3.45-initia-oft.1
44
+
45
+ ### Patch Changes
46
+
47
+ - Build new initia images with newest contracts
48
+ - Updated dependencies
49
+ - @layerzerolabs/lz-definitions@2.3.45-initia-oft.1
50
+ - @layerzerolabs/lz-config-types@2.3.45-initia-oft.1
51
+ - @layerzerolabs/lz-utilities@2.3.45-initia-oft.1
52
+
53
+ ## 2.3.45-initia-oft.0
54
+
55
+ ### Patch Changes
56
+
57
+ - Build new initia images with testnet deployments
58
+ - Updated dependencies
59
+ - @layerzerolabs/lz-definitions@2.3.45-initia-oft.0
60
+ - @layerzerolabs/lz-config-types@2.3.45-initia-oft.0
61
+ - @layerzerolabs/lz-utilities@2.3.45-initia-oft.0
62
+
63
+ ## 2.3.43-initia-oft.2
64
+
65
+ ### Patch Changes
66
+
67
+ - Build new Initia snapshot images with multi tokens
68
+ - Updated dependencies
69
+ - @layerzerolabs/lz-definitions@2.3.43-initia-oft.2
70
+ - @layerzerolabs/lz-utilities@2.3.43-initia-oft.2
71
+
72
+ ## 2.3.43-initia-oft.1
73
+
74
+ ### Patch Changes
75
+
76
+ - Update Initia Snapshot image with newest contracts
77
+ - Updated dependencies
78
+ - @layerzerolabs/lz-definitions@2.3.43-initia-oft.1
79
+ - @layerzerolabs/lz-utilities@2.3.43-initia-oft.1
80
+
81
+ ## 2.3.43-initia-oft.0
82
+
83
+ ### Patch Changes
84
+
85
+ - Building new Initia snapshot image, including OFT TokenOne
86
+ - Updated dependencies
87
+ - @layerzerolabs/lz-definitions@2.3.43-initia-oft.0
88
+ - @layerzerolabs/lz-utilities@2.3.43-initia-oft.0
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ Wrap Initia cli to support custom configuration just like Hardhat
2
+
3
+ #### Install
4
+
5
+ ```bash
6
+ yarn add @layerzerolabs/lz-initia-cli
7
+ ```
8
+
9
+ #### Config
10
+
11
+ Create a `initia.config.ts` file in the root of your project. A full example is below:
12
+
13
+ ```ts
14
+ import { LzInitiaConfig } from "@layerzerolabs/lz-initia-cli";
15
+ import {
16
+ Chain,
17
+ chainAndStageToNetwork,
18
+ Environment,
19
+ Stage,
20
+ } from "@layerzerolabs/lz-definitions";
21
+ import path from "path";
22
+ import { Account } from "@initia-labs/ts-sdk";
23
+
24
+ const INITIA_SANDBOX_LOCAL = chainAndStageToNetwork(
25
+ Chain.INITIA,
26
+ Stage.SANDBOX,
27
+ Environment.LOCAL,
28
+ );
29
+ const INITIA_TESTNET = chainAndStageToNetwork(
30
+ Chain.INITIA,
31
+ Stage.TESTNET,
32
+ Environment.TESTNET,
33
+ );
34
+ const INITIA_MAINNET = chainAndStageToNetwork(
35
+ Chain.INITIA,
36
+ Stage.MAINNET,
37
+ Environment.MAINNET,
38
+ );
39
+ const contractWorkspace = "./contracts";
40
+
41
+ const config: LzInitiaConfig = {
42
+ artifactsPath: "./artifacts",
43
+ deploymentPath: "./deployments",
44
+ compatibleVersions: ["v1"],
45
+ network: {
46
+ [Environment.LOCAL]: "http://127.0.0.1:8080",
47
+ },
48
+ defaultDeployer: {
49
+ [INITIA_SANDBOX_LOCAL]: Account.fromPrivateKey({
50
+ privateKey: process.env.LOCAL_DEPLOYER,
51
+ }),
52
+ [INITIA_TESTNET]: Account.fromPrivateKey({
53
+ privateKey: process.env.TESTNET_DEPLOYER,
54
+ }),
55
+ [INITIA_MAINNET]: Account.fromPrivateKey({
56
+ privateKey: process.env.MAINNET_DEPLOYER,
57
+ }),
58
+ },
59
+ // alternative way to set defaultDeployer
60
+ // defaultDeployer: Account.fromPrivateKey({ privateKey: process.env.DEFAULT_DEPLOYER })
61
+ gasPrice: {
62
+ [INITIA_SANDBOX_LOCAL]: 1000,
63
+ [INITIA_TESTNET]: 1000,
64
+ [INITIA_MAINNET]: 1000,
65
+ },
66
+ baseModules: ["PATH_TO_ANOTHER_LZ_INITIA_CONFIG_FILE"],
67
+ modules: {
68
+ layerzero_common: {
69
+ modulePath: path.join(contractWorkspace, "layerzero-common"),
70
+ deployer: {
71
+ "initia-sandbox-local": Account.fromPrivateKey({
72
+ privateKey: process.env.LAYERZERO_DEPLOYER,
73
+ }),
74
+ },
75
+ },
76
+ executor_v2: {
77
+ alias: "ExecutorV2",
78
+ modulePath: path.join(contractWorkspace, "executor/executor-v2"),
79
+ deployer: Account.fromPrivateKey({
80
+ privateKey: process.env.EXECUTOR_DEPLOYER,
81
+ }),
82
+ },
83
+ executor_auth: {
84
+ modulePath: path.join(contractWorkspace, "executor/executor-auth"),
85
+ variant: process.env.SUFFIX_EXECUTOR,
86
+ },
87
+ },
88
+ };
89
+
90
+ export default config;
91
+ ```
92
+
93
+ Details of the configuration:
94
+
95
+ - `artifactsPath`: Path to store the artifacts(\*.mv and package-metadata.bcs) generated by the compiler.
96
+ - `deploymentPath`: Path to store the deployment files(\*.json) recording the deployment information.
97
+ - `compatibleVersions`: The compatible endpoint version. If not set, the default value is ['v1', 'v2']
98
+ - `network`: The RPC for each environment.
99
+ - `compileOptions`: The `OPTIONS` for the `initiad move build`. If not set, the default value is `--skip-fetch-latest-git-deps=true`.
100
+ - `defaultDeployer`: The default deployer. Deployer account address is also the address of the contract.
101
+ - `gasPrice`: The gas price for each environment. If not set, the default value is 2 times the current gas price.
102
+ - `baseModules`: The path to another lz-initia config file. The command tool will search the base modules recursively if module name not found in `modules`. If not set, the default value is [].
103
+ - `modules`: The module configuration. The key is the module name used in lz-initia-cli command. The key should be the same with package name in Move.toml.
104
+ - `alias`: Artifact/Deployment name for the module. If not set, the module name will be used.
105
+ - `modulePath`: The path to the module's contract directory which contains Move.toml.
106
+ - `deployer`: The deployer for the module. If not set, the default deployer will be used.
107
+ - `variant`: The variant for the module. If not set, it means the module has no variant. It will be overridden by the variant in the command line.
108
+
109
+ #### Usage
110
+
111
+ ```bash
112
+ cd path/to/your/project
113
+ # compile the contracts
114
+ yarn lz-initia-cli build -m layerzero_common -n initia-sandbox-local
115
+ # compile the contracts with a variant
116
+ # for use cases like deploying same contract to different addresses
117
+ yarn lz-initia-cli build -m dvn -n initia-sandbox-local --variant nethermind
118
+ # deploy the contracts
119
+ yarn lz-initia-cli deploy -m layerzero_common -n initia-sandbox-local
120
+ # deploy the contracts with a variant
121
+ yarn lz-initia-cli deploy -m layerzero_common -n initia-sandbox-local --variant nethermind
122
+ ```
package/dist/cli.cjs ADDED
@@ -0,0 +1,469 @@
1
+ 'use strict';
2
+
3
+ var fs2 = require('fs');
4
+ var path3 = require('path');
5
+ var process2 = require('process');
6
+ var extraTypings = require('@commander-js/extra-typings');
7
+ var findUp = require('find-up');
8
+ var core = require('zx/core');
9
+ var lzUtilities = require('@layerzerolabs/lz-utilities');
10
+ var crypto = require('crypto');
11
+ var initia_js = require('@initia/initia.js');
12
+ var smolToml = require('smol-toml');
13
+ var glob = require('glob');
14
+ var lzDefinitions = require('@layerzerolabs/lz-definitions');
15
+ var zx = require('zx');
16
+
17
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
+
19
+ function _interopNamespace(e) {
20
+ if (e && e.__esModule) return e;
21
+ var n = Object.create(null);
22
+ if (e) {
23
+ Object.keys(e).forEach(function (k) {
24
+ if (k !== 'default') {
25
+ var d = Object.getOwnPropertyDescriptor(e, k);
26
+ Object.defineProperty(n, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () { return e[k]; }
29
+ });
30
+ }
31
+ });
32
+ }
33
+ n.default = e;
34
+ return Object.freeze(n);
35
+ }
36
+
37
+ var fs2__default = /*#__PURE__*/_interopDefault(fs2);
38
+ var path3__default = /*#__PURE__*/_interopDefault(path3);
39
+ var process2__default = /*#__PURE__*/_interopDefault(process2);
40
+ var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
41
+
42
+ var __defProp = Object.defineProperty;
43
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
44
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
45
+ }) : x)(function(x) {
46
+ if (typeof require !== "undefined")
47
+ return require.apply(this, arguments);
48
+ throw Error('Dynamic require of "' + x + '" is not supported');
49
+ });
50
+ var __export = (target, all) => {
51
+ for (var name in all)
52
+ __defProp(target, name, { get: all[name], enumerable: true });
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
+ function getInitiaClient(env, config) {
83
+ const url = config.network?.[env];
84
+ if (url === void 0) {
85
+ throw new Error(`No network url for ${env} found in lz-initia.config.ts`);
86
+ }
87
+ const lcd = new initia_js.LCDClient(url);
88
+ return lcd;
89
+ }
90
+ function isInitiaAccount(account) {
91
+ return account !== void 0 && account instanceof initia_js.MnemonicKey;
92
+ }
93
+ function getDeployer(moduleName, lzInitiaConfig, network) {
94
+ const module = lzInitiaConfig.modules[moduleName];
95
+ if (!module) {
96
+ if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {
97
+ for (const baseModule of lzInitiaConfig.baseModules) {
98
+ const baseConfig = loadConfig(baseModule);
99
+ try {
100
+ return getDeployer(moduleName, baseConfig, network);
101
+ } catch (e) {
102
+ }
103
+ }
104
+ }
105
+ throw new Error(
106
+ `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.`
107
+ );
108
+ }
109
+ const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
110
+ const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
111
+ const deployer = moduleDeployer ?? defaultDeployer;
112
+ if (!deployer) {
113
+ throw new Error(`deployer for module ${moduleName} not found`);
114
+ }
115
+ return deployer;
116
+ }
117
+ function isAxiosError(error) {
118
+ return error?.response?.data?.message !== void 0;
119
+ }
120
+ function handleDepMissingError(error, moduleName, context) {
121
+ if (error.response.data.message.includes("EPACKAGE_DEP_MISSING")) {
122
+ throw new Error(
123
+ `Deploy ${moduleName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
124
+ context
125
+ ).filter((module) => module !== moduleName).join(",")}]`
126
+ );
127
+ }
128
+ }
129
+ function handleAccountNotFoundError(error, moduleName, context, network) {
130
+ const address = context[moduleName]?.addresses[moduleName];
131
+ if (address === void 0) {
132
+ return;
133
+ }
134
+ if (error.response.data.message.includes(`account ${initia_js.AccAddress.fromHex(address)} not found`)) {
135
+ throw new Error(
136
+ `${error.response.data.message}, make sure you have funded the account ${initia_js.AccAddress.fromHex(address)}(${address}) on ${network}`
137
+ );
138
+ }
139
+ }
140
+ function handleSenderNotMatchError(error, moduleName) {
141
+ if (error.response.data.message.includes("MODULE_ADDRESS_DOES_NOT_MATCH_SENDER")) {
142
+ throw new Error(
143
+ `Deploy ${moduleName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${moduleName} with the deployer account address`
144
+ );
145
+ }
146
+ }
147
+ function handleOtherAxiosError(error) {
148
+ throw new Error(error.response.data.message);
149
+ }
150
+ function handleError(error, moduleName, context, network) {
151
+ if (isAxiosError(error)) {
152
+ handleDepMissingError(error, moduleName, context);
153
+ handleAccountNotFoundError(error, moduleName, context, network);
154
+ handleSenderNotMatchError(error, moduleName);
155
+ handleOtherAxiosError(error);
156
+ }
157
+ throw error;
158
+ }
159
+ function getRawMoveContextByPath(modulePath) {
160
+ const tomlPath = path3__default.default.join(modulePath, "Move.toml");
161
+ if (!fs2__default.default.existsSync(tomlPath)) {
162
+ throw new Error(`Move.toml not found in ${tomlPath}`);
163
+ }
164
+ const toml = smolToml.parse(fs2__default.default.readFileSync(tomlPath, "utf-8"));
165
+ const { dependencies } = toml;
166
+ let result = { [toml.package.name]: toml };
167
+ if (dependencies !== void 0) {
168
+ Object.keys(dependencies).filter((key) => {
169
+ return dependencies[key]?.local !== void 0;
170
+ }).forEach((key) => {
171
+ const dependency = dependencies[key];
172
+ const dependencyPath = path3__default.default.join(modulePath, dependency.local);
173
+ result = { ...getRawMoveContextByPath(dependencyPath), ...result };
174
+ });
175
+ }
176
+ return result;
177
+ }
178
+ function parseAddresses(addresses, network) {
179
+ if (addresses === void 0) {
180
+ return {};
181
+ }
182
+ const result = {};
183
+ for (const key of Object.keys(addresses)) {
184
+ const value = addresses[key];
185
+ if (typeof value === "string") {
186
+ result[key] = value;
187
+ } else {
188
+ const networkAddress = value[network];
189
+ if (networkAddress === void 0) {
190
+ throw new Error(`${key} address not found for network ${network}`);
191
+ }
192
+ result[key] = networkAddress;
193
+ }
194
+ }
195
+ return result;
196
+ }
197
+ function getMoveContext(moduleName, lzInitiaConfig, network) {
198
+ const module = lzInitiaConfig.modules[moduleName];
199
+ if (!module) {
200
+ throw new Error(`module ${moduleName} not found when getting Move context`);
201
+ }
202
+ const context = getRawMoveContextByPath(module.modulePath);
203
+ for (const key of Object.keys(context)) {
204
+ const toml = context[key];
205
+ for (const addressKey of Object.keys(toml.addresses)) {
206
+ const address = toml.addresses[addressKey];
207
+ const presetAddresses = parseAddresses(lzInitiaConfig.modules[key]?.addresses, network);
208
+ if (address === "_") {
209
+ if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
210
+ toml.addresses[addressKey] = presetAddresses[addressKey];
211
+ } else {
212
+ try {
213
+ toml.addresses[addressKey] = initia_js.AccAddress.toHex(
214
+ getDeployer(addressKey, lzInitiaConfig, network).accAddress
215
+ );
216
+ } catch (e) {
217
+ if (key === moduleName) {
218
+ throw new Error(`Fail to generate context for ${key}. ${e.toString()}`);
219
+ } else {
220
+ throw new Error(
221
+ `Fail to generate context for dependent module ${key}. ${e.toString()}`
222
+ );
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ return context;
230
+ }
231
+ function deploymentPath(pkgName, dest, network, variant) {
232
+ const deploymentPath2 = path3__default.default.join(dest, network);
233
+ return path3__default.default.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
234
+ }
235
+ function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [lzDefinitions.EndpointVersion.V1, lzDefinitions.EndpointVersion.V2]) {
236
+ const destPath = deploymentPath(pkgName, dest, network, variant);
237
+ const deploymentDir = path3__default.default.dirname(destPath);
238
+ if (!fs2__default.default.existsSync(deploymentDir)) {
239
+ fs2__default.default.mkdirSync(deploymentDir, { recursive: true });
240
+ }
241
+ fs2__default.default.writeFileSync(
242
+ destPath,
243
+ JSON.stringify(
244
+ {
245
+ address,
246
+ name: pkgWithVariant(pkgName, variant),
247
+ moduleName,
248
+ network,
249
+ compatibleVersions,
250
+ bytecodeHash,
251
+ transactionHash: hash
252
+ },
253
+ null,
254
+ 2
255
+ )
256
+ );
257
+ console.log(`Deployment saved to ${destPath}`);
258
+ }
259
+ function needDeploy(pkgName, dest, network, bytecodeHash, variant) {
260
+ if (lzDefinitions.networkToStage(network) === lzDefinitions.Stage.SANDBOX) {
261
+ return true;
262
+ }
263
+ const destPath = deploymentPath(pkgName, dest, network, variant);
264
+ if (fs2__default.default.existsSync(destPath)) {
265
+ const deployment = JSON.parse(fs2__default.default.readFileSync(destPath, "utf-8"));
266
+ return deployment.bytecodeHash !== bytecodeHash;
267
+ }
268
+ return true;
269
+ }
270
+ function pkgWithVariant(pkgName, variant) {
271
+ return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
272
+ }
273
+ function getBytecodesHash(bytecodes) {
274
+ const hash = crypto__namespace.createHash("sha256");
275
+ bytecodes.forEach((bytecode) => {
276
+ hash.update(bytecode);
277
+ });
278
+ return hash.digest("hex");
279
+ }
280
+ async function deploy(moduleName, lzInitiaConfig, network, variant) {
281
+ const module = lzInitiaConfig.modules[moduleName];
282
+ if (!module) {
283
+ throw new Error(`module ${moduleName} not found`);
284
+ }
285
+ const env = lzDefinitions.networkToEnv(network, lzDefinitions.EndpointVersion.V2);
286
+ const client = getInitiaClient(env, lzInitiaConfig);
287
+ const deployer = getDeployer(moduleName, lzInitiaConfig, network);
288
+ const context = getMoveContext(moduleName, lzInitiaConfig, network);
289
+ const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
290
+ const moduleDir = path3__default.default.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
291
+ const moduleNames = glob.glob.sync("*.mv", { cwd: moduleDir });
292
+ const moduleBuffers = moduleNames.map((moduleName2) => fs2__default.default.readFileSync(path3__default.default.join(moduleDir, moduleName2)));
293
+ const bytecodeHash = getBytecodesHash(moduleBuffers);
294
+ if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {
295
+ console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
296
+ return;
297
+ }
298
+ try {
299
+ const msgs = [
300
+ new initia_js.MsgPublish(
301
+ deployer.accAddress,
302
+ moduleBuffers.map((codeBytes) => codeBytes.toString("base64")),
303
+ initia_js.MsgPublish.Policy.COMPATIBLE
304
+ )
305
+ ];
306
+ const wallet = new initia_js.Wallet(client, deployer);
307
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}unit`;
308
+ const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
309
+ const tx = await client.tx.broadcast(signedTx);
310
+ if (tx.code !== 0) {
311
+ throw new Error(tx.raw_log);
312
+ }
313
+ console.log(`Deploy transaction ${tx.txhash} successfully`);
314
+ saveDeployment(
315
+ moduleName,
316
+ pkgName,
317
+ initia_js.AccAddress.toHex(deployer.accAddress),
318
+ lzInitiaConfig.deploymentPath,
319
+ network,
320
+ bytecodeHash,
321
+ tx.txhash,
322
+ variant,
323
+ lzInitiaConfig.compatibleVersions
324
+ );
325
+ } catch (e) {
326
+ if (e instanceof Error) {
327
+ handleError(e, moduleName, context, network);
328
+ } else {
329
+ throw e;
330
+ }
331
+ }
332
+ }
333
+ var command = new extraTypings.Command();
334
+ command.name("deploy").description("deploy Initia modules").addOption(extraTypings.createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(extraTypings.createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(extraTypings.createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).action(async (options, cmd) => {
335
+ const context = cmd.getOptionValue("__CONTEXT__");
336
+ const { modules, variant, network } = options;
337
+ for (const module of modules) {
338
+ await deploy(module, context, network, variant ?? context.modules[module]?.variant);
339
+ }
340
+ });
341
+
342
+ // src/options.ts
343
+ function parseOptions(defaultOptions, customOptions) {
344
+ const options = { ...defaultOptions, ...customOptions };
345
+ const res = [];
346
+ for (const key of Object.keys(options)) {
347
+ if (typeof options[key] === "boolean") {
348
+ if (options[key] === true) {
349
+ res.push(key);
350
+ }
351
+ } else {
352
+ res.push(key);
353
+ res.push(options[key]);
354
+ }
355
+ }
356
+ return res;
357
+ }
358
+ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
359
+ const addressesParam = Object.keys(addresses).map((key) => `${key}=${addresses[key]}`).join(",");
360
+ const defaultOptions = {
361
+ "--skip-fetch-latest-git-deps": true,
362
+ "--named-addresses": addressesParam
363
+ };
364
+ const args = parseOptions(defaultOptions, customOptions);
365
+ return zx.$({
366
+ cwd: modulePath,
367
+ stdio: ["inherit", "pipe", process.stderr],
368
+ verbose: true
369
+ })`initiad move build ${args}`;
370
+ }
371
+ async function copyArtifacts(src, dest) {
372
+ if (fs2__default.default.existsSync(dest)) {
373
+ console.log(`Removing existing artifacts at ${dest}`);
374
+ fs2__default.default.rmSync(dest, { recursive: true });
375
+ }
376
+ fs2__default.default.mkdirSync(dest, { recursive: true });
377
+ const moduleDir = path3__default.default.join(src, "bytecode_modules");
378
+ const modules = glob.glob.sync("*.mv", { cwd: moduleDir });
379
+ for (const module of modules) {
380
+ const destByteCodePath = path3__default.default.join(dest, "bytecode_modules");
381
+ if (!fs2__default.default.existsSync(destByteCodePath)) {
382
+ fs2__default.default.mkdirSync(destByteCodePath, { recursive: true });
383
+ }
384
+ await zx.$({
385
+ verbose: true
386
+ })`cp ${path3__default.default.join(moduleDir, module)} ${path3__default.default.join(destByteCodePath, module)}`;
387
+ }
388
+ }
389
+ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
390
+ const module = lzInitiaConfig.modules[moduleName];
391
+ if (!module) {
392
+ throw new Error(`module ${moduleName} not found`);
393
+ }
394
+ const { modulePath } = module;
395
+ const context = getMoveContext(moduleName, lzInitiaConfig, network);
396
+ const pkgName = context[moduleName].package.name;
397
+ const srcPath = path3__default.default.join(modulePath, "build", pkgName);
398
+ const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
399
+ const outputPath = path3__default.default.join(
400
+ lzInitiaConfig.artifactsPath,
401
+ variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
402
+ );
403
+ let addresses = {};
404
+ for (const key of Object.keys(context)) {
405
+ const toml = context[key];
406
+ if (!(key in toml.addresses)) {
407
+ throw new Error(`address not found for ${key}`);
408
+ }
409
+ addresses = { ...addresses, ...toml.addresses };
410
+ }
411
+ addresses = { ...addresses, ...context[moduleName].addresses };
412
+ if (!skipBuild) {
413
+ await buildProcess(modulePath, addresses, context[moduleName], {
414
+ ...lzInitiaConfig.compileOptions,
415
+ ...module.compileOptions
416
+ });
417
+ }
418
+ await copyArtifacts(srcPath, outputPath);
419
+ }
420
+ var command2 = new extraTypings.Command();
421
+ command2.name("build").description("build Initia program").addOption(extraTypings.createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(extraTypings.createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(extraTypings.createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).addOption(extraTypings.createOption("-sb, --skip-build", "skip build").default(false)).action(async (options, cmd) => {
422
+ const context = cmd.getOptionValue("__CONTEXT__");
423
+ const { skipBuild, modules, network, variant } = options;
424
+ for (const module of modules) {
425
+ await build(module, context, network, skipBuild, variant ?? context.modules[module]?.variant);
426
+ }
427
+ });
428
+
429
+ // src/cli.ts
430
+ var program = new extraTypings.Command();
431
+ var logger = lzUtilities.getLogger();
432
+ program.name("lz-initia-cli").description("Wrapper of Initia cli").version("0.1.0").action((_, command3) => {
433
+ logger.info("Please specify a subcommand");
434
+ command3.help();
435
+ });
436
+ async function checkIfInitiaInstalled() {
437
+ try {
438
+ await core.$`initiad version`;
439
+ } catch (e) {
440
+ throw new Error("Initia cli is not installed");
441
+ }
442
+ }
443
+ function checkIfInitiaConfigExists() {
444
+ const packagePath = findUp.sync("package.json", { cwd: process2__default.default.cwd() });
445
+ if (packagePath === void 0) {
446
+ throw new Error("package.json not found");
447
+ }
448
+ const configPath = path3__default.default.join(path3__default.default.dirname(packagePath), "lz-initia.config.ts");
449
+ if (!fs2__default.default.existsSync(configPath)) {
450
+ throw new Error("lz-initia.config.ts not found, please create one in the same directory as package.json");
451
+ }
452
+ return configPath;
453
+ }
454
+ async function main() {
455
+ await checkIfInitiaInstalled();
456
+ const configPath = checkIfInitiaConfigExists();
457
+ const config = loadConfig(configPath);
458
+ Object.values(subCommands_exports).forEach((subCommand) => {
459
+ subCommand.setOptionValue("__CONTEXT__", config);
460
+ program.addCommand(subCommand);
461
+ });
462
+ await program.parseAsync();
463
+ }
464
+ main().then(() => process2__default.default.exit(process2__default.default.exitCode)).catch((error) => {
465
+ logger.error(error);
466
+ process2__default.default.exit(1);
467
+ });
468
+ //# sourceMappingURL=out.js.map
469
+ //# sourceMappingURL=cli.cjs.map