@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/dist/index.mjs ADDED
@@ -0,0 +1,371 @@
1
+ import fs3 from 'fs';
2
+ import path2 from 'path';
3
+ import { MsgPublish, Wallet, AccAddress, LCDClient, MnemonicKey } from '@initia/initia.js';
4
+ import { parse } from 'smol-toml';
5
+ import { glob } from 'glob';
6
+ import { $ } from 'zx';
7
+ import * as crypto from 'crypto';
8
+ import { EndpointVersion, networkToEnv, networkToStage, Stage } from '@layerzerolabs/lz-definitions';
9
+
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined")
14
+ return require.apply(this, arguments);
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+
18
+ // src/loader.ts
19
+ function loadConfig(configPath) {
20
+ const moduleName = "ts-node";
21
+ const tsnode = __require(moduleName);
22
+ tsnode.register({
23
+ transpileOnly: true,
24
+ typeCheck: false
25
+ });
26
+ try {
27
+ const imported = __require(configPath);
28
+ return "default" in imported ? imported.default : imported;
29
+ } catch (e) {
30
+ if (e !== null && typeof e === "object" && "code" in e && e.code === "ERR_REQUIRE_ESM") {
31
+ throw new Error(
32
+ `Your project is an ESM project (you have "type": "module" set in your package.json) but your LayerZero config file uses the .js extension.`
33
+ );
34
+ }
35
+ throw e;
36
+ }
37
+ }
38
+ function isInitiaAccount(account) {
39
+ return account !== void 0 && account instanceof MnemonicKey;
40
+ }
41
+ function getDeployer(moduleName, lzInitiaConfig, network) {
42
+ const module = lzInitiaConfig.modules[moduleName];
43
+ if (!module) {
44
+ if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {
45
+ for (const baseModule of lzInitiaConfig.baseModules) {
46
+ const baseConfig = loadConfig(baseModule);
47
+ try {
48
+ return getDeployer(moduleName, baseConfig, network);
49
+ } catch (e) {
50
+ }
51
+ }
52
+ }
53
+ throw new Error(
54
+ `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.`
55
+ );
56
+ }
57
+ const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
58
+ const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
59
+ const deployer = moduleDeployer ?? defaultDeployer;
60
+ if (!deployer) {
61
+ throw new Error(`deployer for module ${moduleName} not found`);
62
+ }
63
+ return deployer;
64
+ }
65
+ function getRawMoveContextByPath(modulePath) {
66
+ const tomlPath = path2.join(modulePath, "Move.toml");
67
+ if (!fs3.existsSync(tomlPath)) {
68
+ throw new Error(`Move.toml not found in ${tomlPath}`);
69
+ }
70
+ const toml = parse(fs3.readFileSync(tomlPath, "utf-8"));
71
+ const { dependencies } = toml;
72
+ let result = { [toml.package.name]: toml };
73
+ if (dependencies !== void 0) {
74
+ Object.keys(dependencies).filter((key) => {
75
+ return dependencies[key]?.local !== void 0;
76
+ }).forEach((key) => {
77
+ const dependency = dependencies[key];
78
+ const dependencyPath = path2.join(modulePath, dependency.local);
79
+ result = { ...getRawMoveContextByPath(dependencyPath), ...result };
80
+ });
81
+ }
82
+ return result;
83
+ }
84
+ function parseAddresses(addresses, network) {
85
+ if (addresses === void 0) {
86
+ return {};
87
+ }
88
+ const result = {};
89
+ for (const key of Object.keys(addresses)) {
90
+ const value = addresses[key];
91
+ if (typeof value === "string") {
92
+ result[key] = value;
93
+ } else {
94
+ const networkAddress = value[network];
95
+ if (networkAddress === void 0) {
96
+ throw new Error(`${key} address not found for network ${network}`);
97
+ }
98
+ result[key] = networkAddress;
99
+ }
100
+ }
101
+ return result;
102
+ }
103
+ function getMoveContext(moduleName, lzInitiaConfig, network) {
104
+ const module = lzInitiaConfig.modules[moduleName];
105
+ if (!module) {
106
+ throw new Error(`module ${moduleName} not found when getting Move context`);
107
+ }
108
+ const context = getRawMoveContextByPath(module.modulePath);
109
+ for (const key of Object.keys(context)) {
110
+ const toml = context[key];
111
+ for (const addressKey of Object.keys(toml.addresses)) {
112
+ const address = toml.addresses[addressKey];
113
+ const presetAddresses = parseAddresses(lzInitiaConfig.modules[key]?.addresses, network);
114
+ if (address === "_") {
115
+ if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
116
+ toml.addresses[addressKey] = presetAddresses[addressKey];
117
+ } else {
118
+ try {
119
+ toml.addresses[addressKey] = AccAddress.toHex(
120
+ getDeployer(addressKey, lzInitiaConfig, network).accAddress
121
+ );
122
+ } catch (e) {
123
+ if (key === moduleName) {
124
+ throw new Error(`Fail to generate context for ${key}. ${e.toString()}`);
125
+ } else {
126
+ throw new Error(
127
+ `Fail to generate context for dependent module ${key}. ${e.toString()}`
128
+ );
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ return context;
136
+ }
137
+
138
+ // src/options.ts
139
+ function parseOptions(defaultOptions, customOptions) {
140
+ const options = { ...defaultOptions, ...customOptions };
141
+ const res = [];
142
+ for (const key of Object.keys(options)) {
143
+ if (typeof options[key] === "boolean") {
144
+ if (options[key] === true) {
145
+ res.push(key);
146
+ }
147
+ } else {
148
+ res.push(key);
149
+ res.push(options[key]);
150
+ }
151
+ }
152
+ return res;
153
+ }
154
+ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
155
+ const addressesParam = Object.keys(addresses).map((key) => `${key}=${addresses[key]}`).join(",");
156
+ const defaultOptions = {
157
+ "--skip-fetch-latest-git-deps": true,
158
+ "--named-addresses": addressesParam
159
+ };
160
+ const args = parseOptions(defaultOptions, customOptions);
161
+ return $({
162
+ cwd: modulePath,
163
+ stdio: ["inherit", "pipe", process.stderr],
164
+ verbose: true
165
+ })`initiad move build ${args}`;
166
+ }
167
+ async function copyArtifacts(src, dest) {
168
+ if (fs3.existsSync(dest)) {
169
+ console.log(`Removing existing artifacts at ${dest}`);
170
+ fs3.rmSync(dest, { recursive: true });
171
+ }
172
+ fs3.mkdirSync(dest, { recursive: true });
173
+ const moduleDir = path2.join(src, "bytecode_modules");
174
+ const modules = glob.sync("*.mv", { cwd: moduleDir });
175
+ for (const module of modules) {
176
+ const destByteCodePath = path2.join(dest, "bytecode_modules");
177
+ if (!fs3.existsSync(destByteCodePath)) {
178
+ fs3.mkdirSync(destByteCodePath, { recursive: true });
179
+ }
180
+ await $({
181
+ verbose: true
182
+ })`cp ${path2.join(moduleDir, module)} ${path2.join(destByteCodePath, module)}`;
183
+ }
184
+ }
185
+ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
186
+ const module = lzInitiaConfig.modules[moduleName];
187
+ if (!module) {
188
+ throw new Error(`module ${moduleName} not found`);
189
+ }
190
+ const { modulePath } = module;
191
+ const context = getMoveContext(moduleName, lzInitiaConfig, network);
192
+ const pkgName = context[moduleName].package.name;
193
+ const srcPath = path2.join(modulePath, "build", pkgName);
194
+ const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
195
+ const outputPath = path2.join(
196
+ lzInitiaConfig.artifactsPath,
197
+ variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
198
+ );
199
+ let addresses = {};
200
+ for (const key of Object.keys(context)) {
201
+ const toml = context[key];
202
+ if (!(key in toml.addresses)) {
203
+ throw new Error(`address not found for ${key}`);
204
+ }
205
+ addresses = { ...addresses, ...toml.addresses };
206
+ }
207
+ addresses = { ...addresses, ...context[moduleName].addresses };
208
+ if (!skipBuild) {
209
+ await buildProcess(modulePath, addresses, context[moduleName], {
210
+ ...lzInitiaConfig.compileOptions,
211
+ ...module.compileOptions
212
+ });
213
+ }
214
+ await copyArtifacts(srcPath, outputPath);
215
+ }
216
+ function getInitiaClient(env, config) {
217
+ const url = config.network?.[env];
218
+ if (url === void 0) {
219
+ throw new Error(`No network url for ${env} found in lz-initia.config.ts`);
220
+ }
221
+ const lcd = new LCDClient(url);
222
+ return lcd;
223
+ }
224
+ function isAxiosError(error) {
225
+ return error?.response?.data?.message !== void 0;
226
+ }
227
+ function handleDepMissingError(error, moduleName, context) {
228
+ if (error.response.data.message.includes("EPACKAGE_DEP_MISSING")) {
229
+ throw new Error(
230
+ `Deploy ${moduleName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
231
+ context
232
+ ).filter((module) => module !== moduleName).join(",")}]`
233
+ );
234
+ }
235
+ }
236
+ function handleAccountNotFoundError(error, moduleName, context, network) {
237
+ const address = context[moduleName]?.addresses[moduleName];
238
+ if (address === void 0) {
239
+ return;
240
+ }
241
+ if (error.response.data.message.includes(`account ${AccAddress.fromHex(address)} not found`)) {
242
+ throw new Error(
243
+ `${error.response.data.message}, make sure you have funded the account ${AccAddress.fromHex(address)}(${address}) on ${network}`
244
+ );
245
+ }
246
+ }
247
+ function handleSenderNotMatchError(error, moduleName) {
248
+ if (error.response.data.message.includes("MODULE_ADDRESS_DOES_NOT_MATCH_SENDER")) {
249
+ throw new Error(
250
+ `Deploy ${moduleName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${moduleName} with the deployer account address`
251
+ );
252
+ }
253
+ }
254
+ function handleOtherAxiosError(error) {
255
+ throw new Error(error.response.data.message);
256
+ }
257
+ function handleError(error, moduleName, context, network) {
258
+ if (isAxiosError(error)) {
259
+ handleDepMissingError(error, moduleName, context);
260
+ handleAccountNotFoundError(error, moduleName, context, network);
261
+ handleSenderNotMatchError(error, moduleName);
262
+ handleOtherAxiosError(error);
263
+ }
264
+ throw error;
265
+ }
266
+ function deploymentPath(pkgName, dest, network, variant) {
267
+ const deploymentPath2 = path2.join(dest, network);
268
+ return path2.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
269
+ }
270
+ function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
271
+ const destPath = deploymentPath(pkgName, dest, network, variant);
272
+ const deploymentDir = path2.dirname(destPath);
273
+ if (!fs3.existsSync(deploymentDir)) {
274
+ fs3.mkdirSync(deploymentDir, { recursive: true });
275
+ }
276
+ fs3.writeFileSync(
277
+ destPath,
278
+ JSON.stringify(
279
+ {
280
+ address,
281
+ name: pkgWithVariant(pkgName, variant),
282
+ moduleName,
283
+ network,
284
+ compatibleVersions,
285
+ bytecodeHash,
286
+ transactionHash: hash
287
+ },
288
+ null,
289
+ 2
290
+ )
291
+ );
292
+ console.log(`Deployment saved to ${destPath}`);
293
+ }
294
+ function needDeploy(pkgName, dest, network, bytecodeHash, variant) {
295
+ if (networkToStage(network) === Stage.SANDBOX) {
296
+ return true;
297
+ }
298
+ const destPath = deploymentPath(pkgName, dest, network, variant);
299
+ if (fs3.existsSync(destPath)) {
300
+ const deployment = JSON.parse(fs3.readFileSync(destPath, "utf-8"));
301
+ return deployment.bytecodeHash !== bytecodeHash;
302
+ }
303
+ return true;
304
+ }
305
+ function pkgWithVariant(pkgName, variant) {
306
+ return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
307
+ }
308
+ function getBytecodesHash(bytecodes) {
309
+ const hash = crypto.createHash("sha256");
310
+ bytecodes.forEach((bytecode) => {
311
+ hash.update(bytecode);
312
+ });
313
+ return hash.digest("hex");
314
+ }
315
+ async function deploy(moduleName, lzInitiaConfig, network, variant) {
316
+ const module = lzInitiaConfig.modules[moduleName];
317
+ if (!module) {
318
+ throw new Error(`module ${moduleName} not found`);
319
+ }
320
+ const env = networkToEnv(network, EndpointVersion.V2);
321
+ const client = getInitiaClient(env, lzInitiaConfig);
322
+ const deployer = getDeployer(moduleName, lzInitiaConfig, network);
323
+ const context = getMoveContext(moduleName, lzInitiaConfig, network);
324
+ const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
325
+ const moduleDir = path2.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
326
+ const moduleNames = glob.sync("*.mv", { cwd: moduleDir });
327
+ const moduleBuffers = moduleNames.map((moduleName2) => fs3.readFileSync(path2.join(moduleDir, moduleName2)));
328
+ const bytecodeHash = getBytecodesHash(moduleBuffers);
329
+ if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {
330
+ console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
331
+ return;
332
+ }
333
+ try {
334
+ const msgs = [
335
+ new MsgPublish(
336
+ deployer.accAddress,
337
+ moduleBuffers.map((codeBytes) => codeBytes.toString("base64")),
338
+ MsgPublish.Policy.COMPATIBLE
339
+ )
340
+ ];
341
+ const wallet = new Wallet(client, deployer);
342
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}unit`;
343
+ const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
344
+ const tx = await client.tx.broadcast(signedTx);
345
+ if (tx.code !== 0) {
346
+ throw new Error(tx.raw_log);
347
+ }
348
+ console.log(`Deploy transaction ${tx.txhash} successfully`);
349
+ saveDeployment(
350
+ moduleName,
351
+ pkgName,
352
+ AccAddress.toHex(deployer.accAddress),
353
+ lzInitiaConfig.deploymentPath,
354
+ network,
355
+ bytecodeHash,
356
+ tx.txhash,
357
+ variant,
358
+ lzInitiaConfig.compatibleVersions
359
+ );
360
+ } catch (e) {
361
+ if (e instanceof Error) {
362
+ handleError(e, moduleName, context, network);
363
+ } else {
364
+ throw e;
365
+ }
366
+ }
367
+ }
368
+
369
+ export { build, buildProcess, copyArtifacts, deploy, saveDeployment };
370
+ //# sourceMappingURL=out.js.map
371
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/build.ts","../src/move.ts","../src/loader.ts","../src/deployer.ts","../src/options.ts","../src/deploy.ts","../src/client.ts","../src/errors.ts"],"names":["fs","path","AccAddress","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AS,QAAQ,CAAC;AAAA,QAC7D,WAAW,OAAO;AAAA,MACtB;AAAA,IACJ;AACA,UAAM,SAAS,IAAI,OAAO,QAAQ,QAAQ;AAC1C,UAAM,YACF,eAAe,WAAW,OAAO,MAAM,SAAY,SAAY,GAAG,eAAe,SAAS,OAAO,CAAC;AACtG,UAAM,WAAW,MAAM,OAAO,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjE,UAAM,KAAK,MAAM,OAAO,GAAG,UAAU,QAAQ;AAC7C,QAAM,GAAe,SAAoB,GAAG;AACxC,YAAM,IAAI,MAAM,GAAG,OAAO;AAAA,IAC9B;AACA,YAAQ,IAAI,sBAAsB,GAAG,MAAM,eAAe;AAC1D;AAAA,MACI;AAAA,MACA;AAAA,MACAH,YAAW,MAAM,SAAS,UAAU;AAAA,MACpC,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA,GAAG;AAAA,MACH;AAAA,MACA,eAAe;AAAA,IACnB;AAAA,EACJ,SAAS,GAAY;AACjB,QAAI,aAAa,OAAO;AACpB,kBAAY,GAAG,YAAY,SAAS,OAAO;AAAA,IAC/C,OAAO;AACH,YAAM;AAAA,IACV;AAAA,EACJ;AACJ","sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport { getMoveContext } from '@/move'\nimport { parseOptions } from '@/options'\nimport { CmdOptions, LzInitiaConfig, MoveToml } from '@/types'\nimport { glob } from 'glob'\nimport { $, ProcessOutput } from 'zx'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nexport function buildProcess(\n modulePath: string,\n addresses: { [key: string]: string },\n toml: MoveToml,\n customOptions: CmdOptions = {}\n): Promise<ProcessOutput> {\n const addressesParam = Object.keys(addresses)\n .map((key) => `${key}=${addresses[key]}`)\n .join(',')\n const defaultOptions = {\n '--skip-fetch-latest-git-deps': true,\n '--named-addresses': addressesParam,\n }\n const args = parseOptions(defaultOptions, customOptions)\n return $({\n cwd: modulePath,\n stdio: ['inherit', 'pipe', process.stderr],\n verbose: true,\n })`initiad move build ${args}`\n}\n\nexport async function copyArtifacts(src: string, dest: string): Promise<void> {\n // remove existing artifacts, this is necessary to avoid leaving old artifacts\n if (fs.existsSync(dest)) {\n console.log(`Removing existing artifacts at ${dest}`)\n fs.rmSync(dest, { recursive: true })\n }\n fs.mkdirSync(dest, { recursive: true })\n const moduleDir = path.join(src, 'bytecode_modules')\n const modules = glob.sync('*.mv', { cwd: moduleDir })\n for (const module of modules) {\n const destByteCodePath = path.join(dest, 'bytecode_modules')\n if (!fs.existsSync(destByteCodePath)) {\n fs.mkdirSync(destByteCodePath, { recursive: true })\n }\n await $({\n verbose: true,\n })`cp ${path.join(moduleDir, module)} ${path.join(destByteCodePath, module)}`\n }\n}\n\nexport async function build(\n moduleName: string,\n lzInitiaConfig: LzInitiaConfig,\n network: Network,\n skipBuild = false,\n variant?: string\n): Promise<void> {\n const module = lzInitiaConfig.modules[moduleName]\n if (!module) {\n throw new Error(`module ${moduleName} not found`)\n }\n const { modulePath } = module\n const context = getMoveContext(moduleName, lzInitiaConfig, network)\n const pkgName = context[moduleName]!.package.name\n const srcPath = path.join(modulePath, 'build', pkgName)\n const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName\n const outputPath = path.join(\n lzInitiaConfig.artifactsPath,\n variant !== undefined && variant.length > 0 ? `${outputDir}-${variant}` : outputDir\n )\n let addresses: { [key: string]: string } = {}\n for (const key of Object.keys(context)) {\n const toml = context[key]!\n if (!(key in toml.addresses)) {\n throw new Error(`address not found for ${key}`)\n }\n addresses = { ...addresses, ...toml.addresses }\n }\n addresses = { ...addresses, ...context[moduleName]!.addresses }\n if (!skipBuild) {\n await buildProcess(modulePath, addresses, context[moduleName]!, {\n ...lzInitiaConfig.compileOptions,\n ...module.compileOptions,\n })\n }\n await copyArtifacts(srcPath, outputPath)\n}\n","import fs from 'fs'\nimport path from 'path'\n\nimport { getDeployer } from '@/deployer'\nimport { LzInitiaConfig, ModuleAddresses, MoveContext, MoveToml } from '@/types'\nimport { AccAddress } from '@initia/initia.js'\nimport { parse } from 'smol-toml'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nexport function getRawMoveContextByPath(modulePath: string): MoveContext {\n const tomlPath = path.join(modulePath, 'Move.toml')\n if (!fs.existsSync(tomlPath)) {\n throw new Error(`Move.toml not found in ${tomlPath}`)\n }\n const toml = parse(fs.readFileSync(tomlPath, 'utf-8')) as unknown as MoveToml\n const { dependencies } = toml\n let result: MoveContext = { [toml.package.name]: toml } satisfies MoveContext\n if (dependencies !== undefined) {\n Object.keys(dependencies)\n .filter((key) => {\n return dependencies[key]?.local !== undefined\n })\n .forEach((key) => {\n const dependency = dependencies[key] as { local: string }\n const dependencyPath = path.join(modulePath, dependency.local)\n result = { ...getRawMoveContextByPath(dependencyPath), ...result } satisfies MoveContext\n })\n }\n return result\n}\n\nexport function parseAddresses(addresses: ModuleAddresses, network: Network): { [key in string]?: string } {\n if (addresses === undefined) {\n return {}\n }\n const result: { [key in string]?: string } = {}\n for (const key of Object.keys(addresses)) {\n const value = addresses[key]\n if (typeof value === 'string') {\n result[key] = value\n } else {\n const networkAddress = value[network]\n if (networkAddress === undefined) {\n throw new Error(`${key} address not found for network ${network}`)\n }\n result[key] = networkAddress\n }\n }\n return result\n}\n\nexport function getMoveContext(moduleName: string, lzInitiaConfig: LzInitiaConfig, network: Network): MoveContext {\n const module = lzInitiaConfig.modules[moduleName]\n if (!module) {\n throw new Error(`module ${moduleName} not found when getting Move context`)\n }\n const context = getRawMoveContextByPath(module.modulePath)\n for (const key of Object.keys(context)) {\n const toml = context[key]!\n for (const addressKey of Object.keys(toml.addresses)) {\n const address = toml.addresses[addressKey]\n const presetAddresses = parseAddresses(lzInitiaConfig.modules[key]?.addresses, network)\n if (address === '_') {\n if (presetAddresses[addressKey] !== undefined && presetAddresses[addressKey] !== '') {\n toml.addresses[addressKey] = presetAddresses[addressKey]!\n } else {\n try {\n toml.addresses[addressKey] = AccAddress.toHex(\n getDeployer(addressKey, lzInitiaConfig, network).accAddress\n )\n } catch (e) {\n if (key === moduleName) {\n throw new Error(`Fail to generate context for ${key}. ${(e as Error).toString()}`)\n } else {\n throw new Error(\n `Fail to generate context for dependent module ${key}. ${(e as Error).toString()}`\n )\n }\n }\n }\n }\n }\n }\n return context\n}\n","import { LzInitiaConfig } from '@/types'\n\nexport function loadConfig(configPath: string): LzInitiaConfig {\n // WARNING: require('ts-node') will cause '[ERROR] Unterminated template (867:31) [plugin commonjs]' in some cases\n // this error can be eliminated by assigning the name to a variable and require that variable\n const moduleName = 'ts-node'\n const tsnode = require(moduleName) as typeof import('ts-node')\n tsnode.register({\n transpileOnly: true,\n typeCheck: false,\n })\n\n try {\n type ImportType = LzInitiaConfig | { default: LzInitiaConfig }\n const imported = require(configPath) as ImportType\n return 'default' in imported ? imported.default : imported\n } catch (e) {\n if (e !== null && typeof e === 'object' && 'code' in e && e.code === 'ERR_REQUIRE_ESM') {\n throw new Error(\n `Your project is an ESM project (you have \"type\": \"module\" set in your package.json) but your LayerZero config file uses the .js extension.`\n )\n }\n\n throw e\n }\n}\n","import { loadConfig } from '@/loader'\nimport { LzInitiaConfig } from '@/types'\nimport { MnemonicKey } from '@initia/initia.js'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nexport function isInitiaAccount(account: object | undefined): account is MnemonicKey {\n return account !== undefined && account instanceof MnemonicKey\n}\n\nexport function getDeployer(moduleName: string, lzInitiaConfig: LzInitiaConfig, network: Network): MnemonicKey {\n const module = lzInitiaConfig.modules[moduleName]\n if (!module) {\n if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {\n for (const baseModule of lzInitiaConfig.baseModules) {\n const baseConfig = loadConfig(baseModule)\n try {\n return getDeployer(moduleName, baseConfig, network)\n } catch (e) {\n /* ignore */\n }\n }\n }\n throw new Error(\n `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.`\n )\n }\n const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network]\n const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer)\n ? lzInitiaConfig.defaultDeployer\n : lzInitiaConfig.defaultDeployer?.[network]\n const deployer = moduleDeployer ?? defaultDeployer\n if (!deployer) {\n throw new Error(`deployer for module ${moduleName} not found`)\n }\n return deployer\n}\n","import { CmdOptions } from '@/types'\n\nexport function parseOptions(defaultOptions: CmdOptions, customOptions: CmdOptions): string[] {\n const options: CmdOptions = { ...defaultOptions, ...customOptions }\n const res: string[] = []\n for (const key of Object.keys(options)) {\n if (typeof options[key] === 'boolean') {\n if (options[key] === true) {\n res.push(key)\n }\n } else {\n res.push(key)\n res.push(options[key] as string)\n }\n }\n return res\n}\n","import fs from 'fs'\nimport * as crypto from 'node:crypto'\nimport path from 'path'\n\nimport { getInitiaClient } from '@/client'\nimport { getDeployer } from '@/deployer'\nimport { handleError } from '@/errors'\nimport { getMoveContext } from '@/move'\nimport { LzInitiaConfig } from '@/types'\nimport { AccAddress, MsgPublish, TxError, Wallet } from '@initia/initia.js'\nimport { glob } from 'glob'\n\nimport { EndpointVersion, Network, Stage, networkToEnv, networkToStage } from '@layerzerolabs/lz-definitions'\n\nfunction deploymentPath(pkgName: string, dest: string, network: Network, variant?: string): string {\n const deploymentPath = path.join(dest, network)\n return path.join(deploymentPath, `${pkgWithVariant(pkgName, variant)}.json`)\n}\n\nexport function saveDeployment(\n moduleName: string,\n pkgName: string,\n address: string,\n dest: string,\n network: Network,\n bytecodeHash: string,\n hash: string,\n variant?: string,\n compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]\n): void {\n const destPath = deploymentPath(pkgName, dest, network, variant)\n const deploymentDir = path.dirname(destPath)\n if (!fs.existsSync(deploymentDir)) {\n fs.mkdirSync(deploymentDir, { recursive: true })\n }\n fs.writeFileSync(\n destPath,\n JSON.stringify(\n {\n address,\n name: pkgWithVariant(pkgName, variant),\n moduleName,\n network,\n compatibleVersions,\n bytecodeHash,\n transactionHash: hash,\n },\n null,\n 2\n )\n )\n console.log(`Deployment saved to ${destPath}`)\n}\n\nfunction needDeploy(pkgName: string, dest: string, network: Network, bytecodeHash: string, variant?: string): boolean {\n if (networkToStage(network) === Stage.SANDBOX) {\n return true\n }\n const destPath = deploymentPath(pkgName, dest, network, variant)\n if (fs.existsSync(destPath)) {\n const deployment = JSON.parse(fs.readFileSync(destPath, 'utf-8')) as { bytecodeHash: string }\n return deployment.bytecodeHash !== bytecodeHash\n }\n return true\n}\n\nfunction pkgWithVariant(pkgName: string, variant?: string): string {\n return variant !== undefined && variant.length > 0 ? `${pkgName}-${variant}` : pkgName\n}\n\nfunction getBytecodesHash(bytecodes: Uint8Array[]): string {\n // sha256 hash of all bytecodes\n const hash = crypto.createHash('sha256')\n bytecodes.forEach((bytecode) => {\n hash.update(bytecode)\n })\n return hash.digest('hex')\n}\n\nexport async function deploy(\n moduleName: string,\n lzInitiaConfig: LzInitiaConfig,\n network: Network,\n variant?: string\n): Promise<void> {\n const module = lzInitiaConfig.modules[moduleName]\n if (!module) {\n throw new Error(`module ${moduleName} not found`)\n }\n const env = networkToEnv(network, EndpointVersion.V2)\n const client = getInitiaClient(env, lzInitiaConfig)\n const deployer = getDeployer(moduleName, lzInitiaConfig, network)\n const context = getMoveContext(moduleName, lzInitiaConfig, network)\n const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName]!.package.name\n const moduleDir = path.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`)\n\n const moduleNames: string[] = glob.sync('*.mv', { cwd: moduleDir })\n const moduleBuffers = moduleNames.map((moduleName) => fs.readFileSync(path.join(moduleDir, moduleName)))\n const bytecodeHash = getBytecodesHash(moduleBuffers)\n if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {\n console.warn(`Code of ${moduleName} has not changed, skipping deploy`)\n return\n }\n try {\n // TODO policy from config\n const msgs = [\n new MsgPublish(\n deployer.accAddress,\n moduleBuffers.map((codeBytes) => codeBytes.toString('base64')),\n MsgPublish.Policy.COMPATIBLE\n ),\n ]\n const wallet = new Wallet(client, deployer)\n const gasPrices =\n lzInitiaConfig.gasPrice?.[network] === undefined ? undefined : `${lzInitiaConfig.gasPrice[network]}unit`\n const signedTx = await wallet.createAndSignTx({ msgs, gasPrices })\n const tx = await client.tx.broadcast(signedTx)\n if (((tx as TxError).code as number) !== 0) {\n throw new Error(tx.raw_log)\n }\n console.log(`Deploy transaction ${tx.txhash} successfully`)\n saveDeployment(\n moduleName,\n pkgName,\n AccAddress.toHex(deployer.accAddress),\n lzInitiaConfig.deploymentPath,\n network,\n bytecodeHash,\n tx.txhash,\n variant,\n lzInitiaConfig.compatibleVersions\n )\n } catch (e: unknown) {\n if (e instanceof Error) {\n handleError(e, moduleName, context, network)\n } else {\n throw e\n }\n }\n}\n","import { LzInitiaConfig } from '@/types'\nimport { LCDClient } from '@initia/initia.js'\n\nimport { Environment } from '@layerzerolabs/lz-definitions'\n\nexport function getInitiaClient(env: Environment, config: LzInitiaConfig): LCDClient {\n const url = config.network?.[env] as string | undefined\n if (url === undefined) {\n throw new Error(`No network url for ${env} found in lz-initia.config.ts`)\n }\n const lcd = new LCDClient(url)\n return lcd\n}\n","import { AxiosError, MoveContext } from '@/types'\nimport { AccAddress } from '@initia/initia.js'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nfunction isAxiosError(error: any): error is AxiosError {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return error?.response?.data?.message !== undefined\n}\n\nfunction handleDepMissingError(error: AxiosError, moduleName: string, context: MoveContext): void {\n if (error.response.data.message.includes('EPACKAGE_DEP_MISSING')) {\n throw new Error(\n `Deploy ${moduleName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(\n context\n )\n .filter((module) => module !== moduleName)\n .join(',')}]`\n )\n }\n}\n\nfunction handleAccountNotFoundError(\n error: AxiosError,\n moduleName: string,\n context: MoveContext,\n network: Network\n): void {\n const address = context[moduleName]?.addresses[moduleName]\n if (address === undefined) {\n return\n }\n if (error.response.data.message.includes(`account ${AccAddress.fromHex(address)} not found`)) {\n throw new Error(\n `${error.response.data.message}, make sure you have funded the account ${AccAddress.fromHex(address)}(${address}) on ${network}`\n )\n }\n}\n\nfunction handleSenderNotMatchError(error: AxiosError, moduleName: string): void {\n if (error.response.data.message.includes('MODULE_ADDRESS_DOES_NOT_MATCH_SENDER')) {\n throw new Error(\n `Deploy ${moduleName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${moduleName} with the deployer account address`\n )\n }\n}\n\nfunction handleOtherAxiosError(error: AxiosError): void {\n throw new Error(error.response.data.message)\n}\n\nexport function handleError(error: Error, moduleName: string, context: MoveContext, network: Network): void {\n if (isAxiosError(error)) {\n handleDepMissingError(error, moduleName, context)\n handleAccountNotFoundError(error, moduleName, context, network)\n handleSenderNotMatchError(error, moduleName)\n handleOtherAxiosError(error)\n }\n throw error\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@layerzerolabs/lz-initia-cli",
3
+ "version": "2.3.45-initia-oft.5",
4
+ "license": "BUSL-1.1",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.mjs",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "main": "./dist/index.cjs",
14
+ "types": "./dist/index.d.ts",
15
+ "bin": "./dist/cli.cjs",
16
+ "files": [
17
+ "./dist/**/*"
18
+ ],
19
+ "scripts": {
20
+ "build": "$npm_execpath tsc --noEmit && $npm_execpath build-ts",
21
+ "build-ts": "$npm_execpath tsup",
22
+ "clean": "rimraf dist",
23
+ "test": "jest"
24
+ },
25
+ "dependencies": {
26
+ "@commander-js/extra-typings": "^12.1.0",
27
+ "@initia/initia.js": "^0.2.11",
28
+ "@layerzerolabs/lz-config-types": "^2.3.45-initia-oft.5",
29
+ "@layerzerolabs/lz-definitions": "^2.3.45-initia-oft.5",
30
+ "@layerzerolabs/lz-utilities": "^2.3.45-initia-oft.5",
31
+ "commander": "^12.1.0",
32
+ "find-up": "^5.0.0",
33
+ "glob": "^10.3.10",
34
+ "smol-toml": "^1.2.0",
35
+ "zx": "^8.1.3"
36
+ },
37
+ "devDependencies": {
38
+ "@jest/globals": "^29.7.0",
39
+ "@layerzerolabs/ops-utilities": "^2.3.45-initia-oft.5",
40
+ "@layerzerolabs/tsup-config-next": "^2.3.45-initia-oft.5",
41
+ "@layerzerolabs/typescript-config-next": "^2.3.45-initia-oft.5",
42
+ "@types/jest": "^29.5.10",
43
+ "jest": "^29.7.0",
44
+ "rimraf": "^5.0.5",
45
+ "ts-jest": "^29.1.1",
46
+ "tsup": "^8.0.1",
47
+ "typescript": "~5.2.2"
48
+ },
49
+ "publishConfig": {
50
+ "access": "restricted"
51
+ }
52
+ }