@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 +88 -0
- package/README.md +122 -0
- package/dist/cli.cjs +469 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +442 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.cjs +401 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.mjs +371 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +52 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs3 = require('fs');
|
|
4
|
+
var path2 = require('path');
|
|
5
|
+
var initia_js = require('@initia/initia.js');
|
|
6
|
+
var smolToml = require('smol-toml');
|
|
7
|
+
var glob = require('glob');
|
|
8
|
+
var zx = require('zx');
|
|
9
|
+
var crypto = require('crypto');
|
|
10
|
+
var lzDefinitions = require('@layerzerolabs/lz-definitions');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
33
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
34
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
35
|
+
|
|
36
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
37
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
38
|
+
}) : x)(function(x) {
|
|
39
|
+
if (typeof require !== "undefined")
|
|
40
|
+
return require.apply(this, arguments);
|
|
41
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// src/loader.ts
|
|
45
|
+
function loadConfig(configPath) {
|
|
46
|
+
const moduleName = "ts-node";
|
|
47
|
+
const tsnode = __require(moduleName);
|
|
48
|
+
tsnode.register({
|
|
49
|
+
transpileOnly: true,
|
|
50
|
+
typeCheck: false
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
const imported = __require(configPath);
|
|
54
|
+
return "default" in imported ? imported.default : imported;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
if (e !== null && typeof e === "object" && "code" in e && e.code === "ERR_REQUIRE_ESM") {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Your project is an ESM project (you have "type": "module" set in your package.json) but your LayerZero config file uses the .js extension.`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function isInitiaAccount(account) {
|
|
65
|
+
return account !== void 0 && account instanceof initia_js.MnemonicKey;
|
|
66
|
+
}
|
|
67
|
+
function getDeployer(moduleName, lzInitiaConfig, network) {
|
|
68
|
+
const module = lzInitiaConfig.modules[moduleName];
|
|
69
|
+
if (!module) {
|
|
70
|
+
if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {
|
|
71
|
+
for (const baseModule of lzInitiaConfig.baseModules) {
|
|
72
|
+
const baseConfig = loadConfig(baseModule);
|
|
73
|
+
try {
|
|
74
|
+
return getDeployer(moduleName, baseConfig, network);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new Error(
|
|
80
|
+
`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.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
|
|
84
|
+
const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
|
|
85
|
+
const deployer = moduleDeployer ?? defaultDeployer;
|
|
86
|
+
if (!deployer) {
|
|
87
|
+
throw new Error(`deployer for module ${moduleName} not found`);
|
|
88
|
+
}
|
|
89
|
+
return deployer;
|
|
90
|
+
}
|
|
91
|
+
function getRawMoveContextByPath(modulePath) {
|
|
92
|
+
const tomlPath = path2__default.default.join(modulePath, "Move.toml");
|
|
93
|
+
if (!fs3__default.default.existsSync(tomlPath)) {
|
|
94
|
+
throw new Error(`Move.toml not found in ${tomlPath}`);
|
|
95
|
+
}
|
|
96
|
+
const toml = smolToml.parse(fs3__default.default.readFileSync(tomlPath, "utf-8"));
|
|
97
|
+
const { dependencies } = toml;
|
|
98
|
+
let result = { [toml.package.name]: toml };
|
|
99
|
+
if (dependencies !== void 0) {
|
|
100
|
+
Object.keys(dependencies).filter((key) => {
|
|
101
|
+
return dependencies[key]?.local !== void 0;
|
|
102
|
+
}).forEach((key) => {
|
|
103
|
+
const dependency = dependencies[key];
|
|
104
|
+
const dependencyPath = path2__default.default.join(modulePath, dependency.local);
|
|
105
|
+
result = { ...getRawMoveContextByPath(dependencyPath), ...result };
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
function parseAddresses(addresses, network) {
|
|
111
|
+
if (addresses === void 0) {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
const result = {};
|
|
115
|
+
for (const key of Object.keys(addresses)) {
|
|
116
|
+
const value = addresses[key];
|
|
117
|
+
if (typeof value === "string") {
|
|
118
|
+
result[key] = value;
|
|
119
|
+
} else {
|
|
120
|
+
const networkAddress = value[network];
|
|
121
|
+
if (networkAddress === void 0) {
|
|
122
|
+
throw new Error(`${key} address not found for network ${network}`);
|
|
123
|
+
}
|
|
124
|
+
result[key] = networkAddress;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
function getMoveContext(moduleName, lzInitiaConfig, network) {
|
|
130
|
+
const module = lzInitiaConfig.modules[moduleName];
|
|
131
|
+
if (!module) {
|
|
132
|
+
throw new Error(`module ${moduleName} not found when getting Move context`);
|
|
133
|
+
}
|
|
134
|
+
const context = getRawMoveContextByPath(module.modulePath);
|
|
135
|
+
for (const key of Object.keys(context)) {
|
|
136
|
+
const toml = context[key];
|
|
137
|
+
for (const addressKey of Object.keys(toml.addresses)) {
|
|
138
|
+
const address = toml.addresses[addressKey];
|
|
139
|
+
const presetAddresses = parseAddresses(lzInitiaConfig.modules[key]?.addresses, network);
|
|
140
|
+
if (address === "_") {
|
|
141
|
+
if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
|
|
142
|
+
toml.addresses[addressKey] = presetAddresses[addressKey];
|
|
143
|
+
} else {
|
|
144
|
+
try {
|
|
145
|
+
toml.addresses[addressKey] = initia_js.AccAddress.toHex(
|
|
146
|
+
getDeployer(addressKey, lzInitiaConfig, network).accAddress
|
|
147
|
+
);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
if (key === moduleName) {
|
|
150
|
+
throw new Error(`Fail to generate context for ${key}. ${e.toString()}`);
|
|
151
|
+
} else {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Fail to generate context for dependent module ${key}. ${e.toString()}`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return context;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/options.ts
|
|
165
|
+
function parseOptions(defaultOptions, customOptions) {
|
|
166
|
+
const options = { ...defaultOptions, ...customOptions };
|
|
167
|
+
const res = [];
|
|
168
|
+
for (const key of Object.keys(options)) {
|
|
169
|
+
if (typeof options[key] === "boolean") {
|
|
170
|
+
if (options[key] === true) {
|
|
171
|
+
res.push(key);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
res.push(key);
|
|
175
|
+
res.push(options[key]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return res;
|
|
179
|
+
}
|
|
180
|
+
function buildProcess(modulePath, addresses, toml, customOptions = {}) {
|
|
181
|
+
const addressesParam = Object.keys(addresses).map((key) => `${key}=${addresses[key]}`).join(",");
|
|
182
|
+
const defaultOptions = {
|
|
183
|
+
"--skip-fetch-latest-git-deps": true,
|
|
184
|
+
"--named-addresses": addressesParam
|
|
185
|
+
};
|
|
186
|
+
const args = parseOptions(defaultOptions, customOptions);
|
|
187
|
+
return zx.$({
|
|
188
|
+
cwd: modulePath,
|
|
189
|
+
stdio: ["inherit", "pipe", process.stderr],
|
|
190
|
+
verbose: true
|
|
191
|
+
})`initiad move build ${args}`;
|
|
192
|
+
}
|
|
193
|
+
async function copyArtifacts(src, dest) {
|
|
194
|
+
if (fs3__default.default.existsSync(dest)) {
|
|
195
|
+
console.log(`Removing existing artifacts at ${dest}`);
|
|
196
|
+
fs3__default.default.rmSync(dest, { recursive: true });
|
|
197
|
+
}
|
|
198
|
+
fs3__default.default.mkdirSync(dest, { recursive: true });
|
|
199
|
+
const moduleDir = path2__default.default.join(src, "bytecode_modules");
|
|
200
|
+
const modules = glob.glob.sync("*.mv", { cwd: moduleDir });
|
|
201
|
+
for (const module of modules) {
|
|
202
|
+
const destByteCodePath = path2__default.default.join(dest, "bytecode_modules");
|
|
203
|
+
if (!fs3__default.default.existsSync(destByteCodePath)) {
|
|
204
|
+
fs3__default.default.mkdirSync(destByteCodePath, { recursive: true });
|
|
205
|
+
}
|
|
206
|
+
await zx.$({
|
|
207
|
+
verbose: true
|
|
208
|
+
})`cp ${path2__default.default.join(moduleDir, module)} ${path2__default.default.join(destByteCodePath, module)}`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
|
|
212
|
+
const module = lzInitiaConfig.modules[moduleName];
|
|
213
|
+
if (!module) {
|
|
214
|
+
throw new Error(`module ${moduleName} not found`);
|
|
215
|
+
}
|
|
216
|
+
const { modulePath } = module;
|
|
217
|
+
const context = getMoveContext(moduleName, lzInitiaConfig, network);
|
|
218
|
+
const pkgName = context[moduleName].package.name;
|
|
219
|
+
const srcPath = path2__default.default.join(modulePath, "build", pkgName);
|
|
220
|
+
const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
|
|
221
|
+
const outputPath = path2__default.default.join(
|
|
222
|
+
lzInitiaConfig.artifactsPath,
|
|
223
|
+
variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
|
|
224
|
+
);
|
|
225
|
+
let addresses = {};
|
|
226
|
+
for (const key of Object.keys(context)) {
|
|
227
|
+
const toml = context[key];
|
|
228
|
+
if (!(key in toml.addresses)) {
|
|
229
|
+
throw new Error(`address not found for ${key}`);
|
|
230
|
+
}
|
|
231
|
+
addresses = { ...addresses, ...toml.addresses };
|
|
232
|
+
}
|
|
233
|
+
addresses = { ...addresses, ...context[moduleName].addresses };
|
|
234
|
+
if (!skipBuild) {
|
|
235
|
+
await buildProcess(modulePath, addresses, context[moduleName], {
|
|
236
|
+
...lzInitiaConfig.compileOptions,
|
|
237
|
+
...module.compileOptions
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
await copyArtifacts(srcPath, outputPath);
|
|
241
|
+
}
|
|
242
|
+
function getInitiaClient(env, config) {
|
|
243
|
+
const url = config.network?.[env];
|
|
244
|
+
if (url === void 0) {
|
|
245
|
+
throw new Error(`No network url for ${env} found in lz-initia.config.ts`);
|
|
246
|
+
}
|
|
247
|
+
const lcd = new initia_js.LCDClient(url);
|
|
248
|
+
return lcd;
|
|
249
|
+
}
|
|
250
|
+
function isAxiosError(error) {
|
|
251
|
+
return error?.response?.data?.message !== void 0;
|
|
252
|
+
}
|
|
253
|
+
function handleDepMissingError(error, moduleName, context) {
|
|
254
|
+
if (error.response.data.message.includes("EPACKAGE_DEP_MISSING")) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`Deploy ${moduleName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
|
|
257
|
+
context
|
|
258
|
+
).filter((module) => module !== moduleName).join(",")}]`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function handleAccountNotFoundError(error, moduleName, context, network) {
|
|
263
|
+
const address = context[moduleName]?.addresses[moduleName];
|
|
264
|
+
if (address === void 0) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (error.response.data.message.includes(`account ${initia_js.AccAddress.fromHex(address)} not found`)) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
`${error.response.data.message}, make sure you have funded the account ${initia_js.AccAddress.fromHex(address)}(${address}) on ${network}`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function handleSenderNotMatchError(error, moduleName) {
|
|
274
|
+
if (error.response.data.message.includes("MODULE_ADDRESS_DOES_NOT_MATCH_SENDER")) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Deploy ${moduleName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${moduleName} with the deployer account address`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function handleOtherAxiosError(error) {
|
|
281
|
+
throw new Error(error.response.data.message);
|
|
282
|
+
}
|
|
283
|
+
function handleError(error, moduleName, context, network) {
|
|
284
|
+
if (isAxiosError(error)) {
|
|
285
|
+
handleDepMissingError(error, moduleName, context);
|
|
286
|
+
handleAccountNotFoundError(error, moduleName, context, network);
|
|
287
|
+
handleSenderNotMatchError(error, moduleName);
|
|
288
|
+
handleOtherAxiosError(error);
|
|
289
|
+
}
|
|
290
|
+
throw error;
|
|
291
|
+
}
|
|
292
|
+
function deploymentPath(pkgName, dest, network, variant) {
|
|
293
|
+
const deploymentPath2 = path2__default.default.join(dest, network);
|
|
294
|
+
return path2__default.default.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
|
|
295
|
+
}
|
|
296
|
+
function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [lzDefinitions.EndpointVersion.V1, lzDefinitions.EndpointVersion.V2]) {
|
|
297
|
+
const destPath = deploymentPath(pkgName, dest, network, variant);
|
|
298
|
+
const deploymentDir = path2__default.default.dirname(destPath);
|
|
299
|
+
if (!fs3__default.default.existsSync(deploymentDir)) {
|
|
300
|
+
fs3__default.default.mkdirSync(deploymentDir, { recursive: true });
|
|
301
|
+
}
|
|
302
|
+
fs3__default.default.writeFileSync(
|
|
303
|
+
destPath,
|
|
304
|
+
JSON.stringify(
|
|
305
|
+
{
|
|
306
|
+
address,
|
|
307
|
+
name: pkgWithVariant(pkgName, variant),
|
|
308
|
+
moduleName,
|
|
309
|
+
network,
|
|
310
|
+
compatibleVersions,
|
|
311
|
+
bytecodeHash,
|
|
312
|
+
transactionHash: hash
|
|
313
|
+
},
|
|
314
|
+
null,
|
|
315
|
+
2
|
|
316
|
+
)
|
|
317
|
+
);
|
|
318
|
+
console.log(`Deployment saved to ${destPath}`);
|
|
319
|
+
}
|
|
320
|
+
function needDeploy(pkgName, dest, network, bytecodeHash, variant) {
|
|
321
|
+
if (lzDefinitions.networkToStage(network) === lzDefinitions.Stage.SANDBOX) {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
const destPath = deploymentPath(pkgName, dest, network, variant);
|
|
325
|
+
if (fs3__default.default.existsSync(destPath)) {
|
|
326
|
+
const deployment = JSON.parse(fs3__default.default.readFileSync(destPath, "utf-8"));
|
|
327
|
+
return deployment.bytecodeHash !== bytecodeHash;
|
|
328
|
+
}
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
function pkgWithVariant(pkgName, variant) {
|
|
332
|
+
return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
|
|
333
|
+
}
|
|
334
|
+
function getBytecodesHash(bytecodes) {
|
|
335
|
+
const hash = crypto__namespace.createHash("sha256");
|
|
336
|
+
bytecodes.forEach((bytecode) => {
|
|
337
|
+
hash.update(bytecode);
|
|
338
|
+
});
|
|
339
|
+
return hash.digest("hex");
|
|
340
|
+
}
|
|
341
|
+
async function deploy(moduleName, lzInitiaConfig, network, variant) {
|
|
342
|
+
const module = lzInitiaConfig.modules[moduleName];
|
|
343
|
+
if (!module) {
|
|
344
|
+
throw new Error(`module ${moduleName} not found`);
|
|
345
|
+
}
|
|
346
|
+
const env = lzDefinitions.networkToEnv(network, lzDefinitions.EndpointVersion.V2);
|
|
347
|
+
const client = getInitiaClient(env, lzInitiaConfig);
|
|
348
|
+
const deployer = getDeployer(moduleName, lzInitiaConfig, network);
|
|
349
|
+
const context = getMoveContext(moduleName, lzInitiaConfig, network);
|
|
350
|
+
const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
|
|
351
|
+
const moduleDir = path2__default.default.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
|
|
352
|
+
const moduleNames = glob.glob.sync("*.mv", { cwd: moduleDir });
|
|
353
|
+
const moduleBuffers = moduleNames.map((moduleName2) => fs3__default.default.readFileSync(path2__default.default.join(moduleDir, moduleName2)));
|
|
354
|
+
const bytecodeHash = getBytecodesHash(moduleBuffers);
|
|
355
|
+
if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {
|
|
356
|
+
console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const msgs = [
|
|
361
|
+
new initia_js.MsgPublish(
|
|
362
|
+
deployer.accAddress,
|
|
363
|
+
moduleBuffers.map((codeBytes) => codeBytes.toString("base64")),
|
|
364
|
+
initia_js.MsgPublish.Policy.COMPATIBLE
|
|
365
|
+
)
|
|
366
|
+
];
|
|
367
|
+
const wallet = new initia_js.Wallet(client, deployer);
|
|
368
|
+
const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}unit`;
|
|
369
|
+
const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
|
|
370
|
+
const tx = await client.tx.broadcast(signedTx);
|
|
371
|
+
if (tx.code !== 0) {
|
|
372
|
+
throw new Error(tx.raw_log);
|
|
373
|
+
}
|
|
374
|
+
console.log(`Deploy transaction ${tx.txhash} successfully`);
|
|
375
|
+
saveDeployment(
|
|
376
|
+
moduleName,
|
|
377
|
+
pkgName,
|
|
378
|
+
initia_js.AccAddress.toHex(deployer.accAddress),
|
|
379
|
+
lzInitiaConfig.deploymentPath,
|
|
380
|
+
network,
|
|
381
|
+
bytecodeHash,
|
|
382
|
+
tx.txhash,
|
|
383
|
+
variant,
|
|
384
|
+
lzInitiaConfig.compatibleVersions
|
|
385
|
+
);
|
|
386
|
+
} catch (e) {
|
|
387
|
+
if (e instanceof Error) {
|
|
388
|
+
handleError(e, moduleName, context, network);
|
|
389
|
+
} else {
|
|
390
|
+
throw e;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
exports.build = build;
|
|
396
|
+
exports.buildProcess = buildProcess;
|
|
397
|
+
exports.copyArtifacts = copyArtifacts;
|
|
398
|
+
exports.deploy = deploy;
|
|
399
|
+
exports.saveDeployment = saveDeployment;
|
|
400
|
+
//# sourceMappingURL=out.js.map
|
|
401
|
+
//# sourceMappingURL=index.cjs.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","glob","deploymentPath","moduleName"],"mappings":";;;;;;;;;AAAA,OAAOA,SAAQ;AACf,OAAOC,WAAU;;;ACDjB,OAAO,QAAQ;AACf,OAAO,UAAU;;;ACCV,SAAS,WAAW,YAAoC;AAG3D,QAAM,aAAa;AACnB,QAAM,SAAS,UAAQ,UAAU;AACjC,SAAO,SAAS;AAAA,IACZ,eAAe;AAAA,IACf,WAAW;AAAA,EACf,CAAC;AAED,MAAI;AAEA,UAAM,WAAW,UAAQ,UAAU;AACnC,WAAO,aAAa,WAAW,SAAS,UAAU;AAAA,EACtD,SAAS,GAAG;AACR,QAAI,MAAM,QAAQ,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,SAAS,mBAAmB;AACpF,YAAM,IAAI;AAAA,QACN;AAAA,MACJ;AAAA,IACJ;AAEA,UAAM;AAAA,EACV;AACJ;;;ACvBA,SAAS,mBAAmB;AAIrB,SAAS,gBAAgB,SAAqD;AACjF,SAAO,YAAY,UAAa,mBAAmB;AACvD;AAEO,SAAS,YAAY,YAAoB,gBAAgC,SAA+B;AAC3G,QAAM,SAAS,eAAe,QAAQ,UAAU;AAChD,MAAI,CAAC,QAAQ;AACT,QAAI,eAAe,eAAe,eAAe,YAAY,SAAS,GAAG;AACrE,iBAAW,cAAc,eAAe,aAAa;AACjD,cAAM,aAAa,WAAW,UAAU;AACxC,YAAI;AACA,iBAAO,YAAY,YAAY,YAAY,OAAO;AAAA,QACtD,SAAS,GAAG;AAAA,QAEZ;AAAA,MACJ;AAAA,IACJ;AACA,UAAM,IA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,WAAU,CAAC,CAAC;AACvG,QAAM,eAAe,iBAAiB,aAAa;AACnD,MAAI,CAAC,WAAW,SAAS,eAAe,gBAAgB,SAAS,cAAc,OAAO,GAAG;AACrF,YAAQ,KAAK,WAAW,UAAU,mCAAmC;AACrE;AAAA,EACJ;AACA,MAAI;AAEA,UAAM,OAAO;AAAA,MACT,IAAI;AAAA,QACA,SAAS;AAAA,QACT,cAAc,IAAI,CAAC,cAAc,UAAU,SAAS,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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MnemonicKey } from '@initia/initia.js';
|
|
2
|
+
import { EndpointVersion, Environment, Network } from '@layerzerolabs/lz-definitions';
|
|
3
|
+
import { ProviderSetting } from '@layerzerolabs/lz-config-types';
|
|
4
|
+
import { ProcessOutput } from 'zx';
|
|
5
|
+
|
|
6
|
+
type CmdOptions = {
|
|
7
|
+
[key in string]: string | boolean;
|
|
8
|
+
};
|
|
9
|
+
interface LzInitiaConfig {
|
|
10
|
+
artifactsPath: string;
|
|
11
|
+
deploymentPath: string;
|
|
12
|
+
compatibleVersions?: EndpointVersion[];
|
|
13
|
+
network?: {
|
|
14
|
+
[key in Environment]?: ProviderSetting;
|
|
15
|
+
};
|
|
16
|
+
defaultDeployer?: {
|
|
17
|
+
[network in Network]?: MnemonicKey;
|
|
18
|
+
} | MnemonicKey;
|
|
19
|
+
gasPrice?: {
|
|
20
|
+
[network in Network]?: number;
|
|
21
|
+
};
|
|
22
|
+
compileOptions?: CmdOptions;
|
|
23
|
+
baseModules?: string[];
|
|
24
|
+
modules: {
|
|
25
|
+
[key in string]?: {
|
|
26
|
+
alias?: string;
|
|
27
|
+
variant?: string;
|
|
28
|
+
modulePath: string;
|
|
29
|
+
deployer?: {
|
|
30
|
+
[network in Network]?: MnemonicKey;
|
|
31
|
+
} | MnemonicKey;
|
|
32
|
+
addresses?: {
|
|
33
|
+
[key in string]: {
|
|
34
|
+
[network in Network]?: string;
|
|
35
|
+
} | string;
|
|
36
|
+
};
|
|
37
|
+
compileOptions?: CmdOptions;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
type ModuleAddresses = NonNullable<LzInitiaConfig['modules'][string]>['addresses'];
|
|
42
|
+
interface MoveToml {
|
|
43
|
+
package: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
};
|
|
47
|
+
addresses: {
|
|
48
|
+
[key in string]: string;
|
|
49
|
+
};
|
|
50
|
+
dependencies?: {
|
|
51
|
+
[key in string]?: {
|
|
52
|
+
local?: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
upgrade_policy?: string;
|
|
56
|
+
}
|
|
57
|
+
type MoveContext = {
|
|
58
|
+
[key in string]?: MoveToml;
|
|
59
|
+
};
|
|
60
|
+
interface AxiosError {
|
|
61
|
+
response: {
|
|
62
|
+
data: {
|
|
63
|
+
code: number;
|
|
64
|
+
message: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare function buildProcess(modulePath: string, addresses: {
|
|
70
|
+
[key: string]: string;
|
|
71
|
+
}, toml: MoveToml, customOptions?: CmdOptions): Promise<ProcessOutput>;
|
|
72
|
+
declare function copyArtifacts(src: string, dest: string): Promise<void>;
|
|
73
|
+
declare function build(moduleName: string, lzInitiaConfig: LzInitiaConfig, network: Network, skipBuild?: boolean, variant?: string): Promise<void>;
|
|
74
|
+
|
|
75
|
+
declare function saveDeployment(moduleName: string, pkgName: string, address: string, dest: string, network: Network, bytecodeHash: string, hash: string, variant?: string, compatibleVersions?: EndpointVersion[]): void;
|
|
76
|
+
declare function deploy(moduleName: string, lzInitiaConfig: LzInitiaConfig, network: Network, variant?: string): Promise<void>;
|
|
77
|
+
|
|
78
|
+
export { type AxiosError, type CmdOptions, type LzInitiaConfig, type ModuleAddresses, type MoveContext, type MoveToml, build, buildProcess, copyArtifacts, deploy, saveDeployment };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MnemonicKey } from '@initia/initia.js';
|
|
2
|
+
import { EndpointVersion, Environment, Network } from '@layerzerolabs/lz-definitions';
|
|
3
|
+
import { ProviderSetting } from '@layerzerolabs/lz-config-types';
|
|
4
|
+
import { ProcessOutput } from 'zx';
|
|
5
|
+
|
|
6
|
+
type CmdOptions = {
|
|
7
|
+
[key in string]: string | boolean;
|
|
8
|
+
};
|
|
9
|
+
interface LzInitiaConfig {
|
|
10
|
+
artifactsPath: string;
|
|
11
|
+
deploymentPath: string;
|
|
12
|
+
compatibleVersions?: EndpointVersion[];
|
|
13
|
+
network?: {
|
|
14
|
+
[key in Environment]?: ProviderSetting;
|
|
15
|
+
};
|
|
16
|
+
defaultDeployer?: {
|
|
17
|
+
[network in Network]?: MnemonicKey;
|
|
18
|
+
} | MnemonicKey;
|
|
19
|
+
gasPrice?: {
|
|
20
|
+
[network in Network]?: number;
|
|
21
|
+
};
|
|
22
|
+
compileOptions?: CmdOptions;
|
|
23
|
+
baseModules?: string[];
|
|
24
|
+
modules: {
|
|
25
|
+
[key in string]?: {
|
|
26
|
+
alias?: string;
|
|
27
|
+
variant?: string;
|
|
28
|
+
modulePath: string;
|
|
29
|
+
deployer?: {
|
|
30
|
+
[network in Network]?: MnemonicKey;
|
|
31
|
+
} | MnemonicKey;
|
|
32
|
+
addresses?: {
|
|
33
|
+
[key in string]: {
|
|
34
|
+
[network in Network]?: string;
|
|
35
|
+
} | string;
|
|
36
|
+
};
|
|
37
|
+
compileOptions?: CmdOptions;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
type ModuleAddresses = NonNullable<LzInitiaConfig['modules'][string]>['addresses'];
|
|
42
|
+
interface MoveToml {
|
|
43
|
+
package: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
};
|
|
47
|
+
addresses: {
|
|
48
|
+
[key in string]: string;
|
|
49
|
+
};
|
|
50
|
+
dependencies?: {
|
|
51
|
+
[key in string]?: {
|
|
52
|
+
local?: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
upgrade_policy?: string;
|
|
56
|
+
}
|
|
57
|
+
type MoveContext = {
|
|
58
|
+
[key in string]?: MoveToml;
|
|
59
|
+
};
|
|
60
|
+
interface AxiosError {
|
|
61
|
+
response: {
|
|
62
|
+
data: {
|
|
63
|
+
code: number;
|
|
64
|
+
message: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare function buildProcess(modulePath: string, addresses: {
|
|
70
|
+
[key: string]: string;
|
|
71
|
+
}, toml: MoveToml, customOptions?: CmdOptions): Promise<ProcessOutput>;
|
|
72
|
+
declare function copyArtifacts(src: string, dest: string): Promise<void>;
|
|
73
|
+
declare function build(moduleName: string, lzInitiaConfig: LzInitiaConfig, network: Network, skipBuild?: boolean, variant?: string): Promise<void>;
|
|
74
|
+
|
|
75
|
+
declare function saveDeployment(moduleName: string, pkgName: string, address: string, dest: string, network: Network, bytecodeHash: string, hash: string, variant?: string, compatibleVersions?: EndpointVersion[]): void;
|
|
76
|
+
declare function deploy(moduleName: string, lzInitiaConfig: LzInitiaConfig, network: Network, variant?: string): Promise<void>;
|
|
77
|
+
|
|
78
|
+
export { type AxiosError, type CmdOptions, type LzInitiaConfig, type ModuleAddresses, type MoveContext, type MoveToml, build, buildProcess, copyArtifacts, deploy, saveDeployment };
|