@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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts","../src/loader.ts","../src/subCommands/index.ts","../src/deploy.ts","../src/client.ts","../src/deployer.ts","../src/errors.ts","../src/move.ts","../src/subCommands/deploy.ts","../src/build.ts","../src/options.ts","../src/subCommands/build.ts"],"names":["fs","path","process","Command","$","command","AccAddress","deploymentPath","moduleName","glob","createOption"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,OAAOC,cAAa;;;ACAb,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;;;ADpBA,SAAS,WAAAC,gBAAe;AACxB,SAAS,QAAQ,kBAAkB;AACnC,SAAS,KAAAC,UAAS;AAElB,SAAS,iBAAiB;;;AET1B;AAAA;AAAA,eAAAC;AAAA,EAAA;AAAA;;;ACAA,OAAOL,SAAQ;AACf,YAAY,YAAY;AACxB,OAAOC,WAAU;;;ACDjB,SAAS,iBAAiB;AAInB,SAAS,gBAAgB,KAAkB,QAAmC;AACjF,QAAM,MAAM,OAAO,UAAU,GAAG;AAChC,MAAI,QAAQ,QAAW;AACnB,UAAM,IAAI,MAAM,sBAAsB,GAAG,+BAA+B;AAAA,EAC5E;A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AE5B,IAAM,SAAS,UAAU;AAEzB,QACK,KAAK,eAAe,EACpB,YAAY,uBAAuB,EACnC,QAAQ,OAAO,EACf,OAAO,CAAC,GAAGE,aAAqB;AAC7B,SAAO,KAAK,6BAA6B;AACzC,EAAAA,SAAQ,KAAK;AACjB,CAAC;AAEL,eAAe,yBAAwC;AACnD,MAAI;AACA,UAAMD;AAAA,EACV,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,6BAA6B;AAAA,EACjD;AACJ;AAEA,SAAS,4BAAoC;AACzC,QAAM,cAAc,WAAW,gBAAgB,EAAE,KAAKF,SAAQ,IAAI,EAAE,CAAC;AACrE,MAAI,gBAAgB,QAAW;AAC3B,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC5C;AACA,QAAM,aAAaD,MAAK,KAAKA,MAAK,QAAQ,WAAW,GAAG,qBAAqB;AAC7E,MAAI,CAACD,IAAG,WAAW,UAAU,GAAG;AAC5B,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC5G;AACA,SAAO;AACX;AAEA,eAAe,OAAsB;AACjC,QAAM,uBAAuB;AAC7B,QAAM,aAAa,0BAA0B;AAC7C,QAAM,SAAS,WAAW,UAAU;AACpC,SAAO,OAAO,mBAAW,EAAE,QAAQ,CAAC,eAAwB;AACxD,eAAW,eAAe,eAAe,MAAM;AAC/C,YAAQ,WAAW,UAAU;AAAA,EACjC,CAAC;AACD,QAAM,QAAQ,WAAW;AAC7B;AAEA,KAAK,EACA,KAAK,MAAME,SAAQ,KAAKA,SAAQ,QAAQ,CAAC,EACzC,MAAM,CAAC,UAAmB;AACvB,SAAO,MAAM,KAAK;AAClB,EAAAA,SAAQ,KAAK,CAAC;AAClB,CAAC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport process from 'process'\n\nimport { loadConfig } from '@/loader'\nimport { Command } from '@commander-js/extra-typings'\nimport { sync as findUpSync } from 'find-up'\nimport { $ } from 'zx/core'\n\nimport { getLogger } from '@layerzerolabs/lz-utilities'\n\nimport * as subCommands from './subCommands'\n\nconst program = new Command()\n// iterate over subCommands and add them to the program\nconst logger = getLogger()\n\nprogram\n .name('lz-initia-cli')\n .description('Wrapper of Initia cli')\n .version('0.1.0')\n .action((_, command: Command) => {\n logger.info('Please specify a subcommand')\n command.help()\n })\n\nasync function checkIfInitiaInstalled(): Promise<void> {\n try {\n await $`initiad version`\n } catch (e) {\n throw new Error('Initia cli is not installed')\n }\n}\n\nfunction checkIfInitiaConfigExists(): string {\n const packagePath = findUpSync('package.json', { cwd: process.cwd() })\n if (packagePath === undefined) {\n throw new Error('package.json not found')\n }\n const configPath = path.join(path.dirname(packagePath), 'lz-initia.config.ts')\n if (!fs.existsSync(configPath)) {\n throw new Error('lz-initia.config.ts not found, please create one in the same directory as package.json')\n }\n return configPath\n}\n\nasync function main(): Promise<void> {\n await checkIfInitiaInstalled()\n const configPath = checkIfInitiaConfigExists()\n const config = loadConfig(configPath)\n Object.values(subCommands).forEach((subCommand: Command) => {\n subCommand.setOptionValue('__CONTEXT__', config)\n program.addCommand(subCommand)\n })\n await program.parseAsync()\n}\n\nmain()\n .then(() => process.exit(process.exitCode))\n .catch((error: unknown) => {\n logger.error(error)\n process.exit(1)\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","export { command as deploy } from './deploy'\nexport { command as build } from './build'\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 { 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 { 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","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 { deploy } from '@/deploy'\nimport { Command, createOption } from '@commander-js/extra-typings'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nimport { LzInitiaConfig } from '../types'\n\nconst command = new Command()\n\nexport { command }\n\ncommand\n .name('deploy')\n .description('deploy Initia modules')\n .addOption(createOption('-m, --modules <modules...>', 'modules').makeOptionMandatory(true))\n .addOption(createOption('-n, --network <network>', 'network').makeOptionMandatory(true))\n .addOption(createOption('-v, --variant <variant>', 'variant').makeOptionMandatory(false))\n .action(async (options: { network: string; modules: string[]; variant?: string }, cmd: Command) => {\n const context = cmd.getOptionValue('__CONTEXT__') as LzInitiaConfig\n\n const { modules, variant, network } = options\n for (const module of modules) {\n await deploy(module, context, network as Network, variant ?? context.modules[module]?.variant)\n }\n })\n","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 { 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 { build } from '@/build'\nimport { Command, createOption } from '@commander-js/extra-typings'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nimport { LzInitiaConfig } from '../types'\n\nconst command = new Command()\n\nexport { command }\n\ncommand\n .name('build')\n .description('build Initia program')\n .addOption(createOption('-m, --modules <modules...>', 'modules').makeOptionMandatory(true))\n .addOption(createOption('-n, --network <network>', 'network').makeOptionMandatory(true))\n .addOption(createOption('-v, --variant <variant>', 'variant').makeOptionMandatory(false))\n .addOption(createOption('-sb, --skip-build', 'skip build').default(false))\n .action(async (options: { network: string; modules: string[]; variant?: string; skipBuild: boolean }, cmd) => {\n const context = cmd.getOptionValue('__CONTEXT__') as LzInitiaConfig\n const { skipBuild, modules, network, variant } = options\n for (const module of modules) {\n await build(module, context, network as Network, skipBuild, variant ?? context.modules[module]?.variant)\n }\n })\n"]}
package/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.mjs ADDED
@@ -0,0 +1,442 @@
1
+ import fs2 from 'fs';
2
+ import path3 from 'path';
3
+ import process2 from 'process';
4
+ import { Command, createOption } from '@commander-js/extra-typings';
5
+ import { sync } from 'find-up';
6
+ import { $ as $$1 } from 'zx/core';
7
+ import { getLogger } from '@layerzerolabs/lz-utilities';
8
+ import * as crypto from 'crypto';
9
+ import { MsgPublish, Wallet, AccAddress, LCDClient, MnemonicKey } from '@initia/initia.js';
10
+ import { parse } from 'smol-toml';
11
+ import { glob } from 'glob';
12
+ import { networkToEnv, EndpointVersion, networkToStage, Stage } from '@layerzerolabs/lz-definitions';
13
+ import { $ } from 'zx';
14
+
15
+ var __defProp = Object.defineProperty;
16
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
17
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
18
+ }) : x)(function(x) {
19
+ if (typeof require !== "undefined")
20
+ return require.apply(this, arguments);
21
+ throw Error('Dynamic require of "' + x + '" is not supported');
22
+ });
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+
28
+ // src/loader.ts
29
+ function loadConfig(configPath) {
30
+ const moduleName = "ts-node";
31
+ const tsnode = __require(moduleName);
32
+ tsnode.register({
33
+ transpileOnly: true,
34
+ typeCheck: false
35
+ });
36
+ try {
37
+ const imported = __require(configPath);
38
+ return "default" in imported ? imported.default : imported;
39
+ } catch (e) {
40
+ if (e !== null && typeof e === "object" && "code" in e && e.code === "ERR_REQUIRE_ESM") {
41
+ throw new Error(
42
+ `Your project is an ESM project (you have "type": "module" set in your package.json) but your LayerZero config file uses the .js extension.`
43
+ );
44
+ }
45
+ throw e;
46
+ }
47
+ }
48
+
49
+ // src/subCommands/index.ts
50
+ var subCommands_exports = {};
51
+ __export(subCommands_exports, {
52
+ build: () => command2,
53
+ deploy: () => command
54
+ });
55
+ function getInitiaClient(env, config) {
56
+ const url = config.network?.[env];
57
+ if (url === void 0) {
58
+ throw new Error(`No network url for ${env} found in lz-initia.config.ts`);
59
+ }
60
+ const lcd = new LCDClient(url);
61
+ return lcd;
62
+ }
63
+ function isInitiaAccount(account) {
64
+ return account !== void 0 && account instanceof MnemonicKey;
65
+ }
66
+ function getDeployer(moduleName, lzInitiaConfig, network) {
67
+ const module = lzInitiaConfig.modules[moduleName];
68
+ if (!module) {
69
+ if (lzInitiaConfig.baseModules && lzInitiaConfig.baseModules.length > 0) {
70
+ for (const baseModule of lzInitiaConfig.baseModules) {
71
+ const baseConfig = loadConfig(baseModule);
72
+ try {
73
+ return getDeployer(moduleName, baseConfig, network);
74
+ } catch (e) {
75
+ }
76
+ }
77
+ }
78
+ throw new Error(
79
+ `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.`
80
+ );
81
+ }
82
+ const moduleDeployer = isInitiaAccount(module.deployer) ? module.deployer : module.deployer?.[network];
83
+ const defaultDeployer = isInitiaAccount(lzInitiaConfig.defaultDeployer) ? lzInitiaConfig.defaultDeployer : lzInitiaConfig.defaultDeployer?.[network];
84
+ const deployer = moduleDeployer ?? defaultDeployer;
85
+ if (!deployer) {
86
+ throw new Error(`deployer for module ${moduleName} not found`);
87
+ }
88
+ return deployer;
89
+ }
90
+ function isAxiosError(error) {
91
+ return error?.response?.data?.message !== void 0;
92
+ }
93
+ function handleDepMissingError(error, moduleName, context) {
94
+ if (error.response.data.message.includes("EPACKAGE_DEP_MISSING")) {
95
+ throw new Error(
96
+ `Deploy ${moduleName} failed with EPACKAGE_DEP_MISSING, make sure you have deployed the dependent module [${Object.keys(
97
+ context
98
+ ).filter((module) => module !== moduleName).join(",")}]`
99
+ );
100
+ }
101
+ }
102
+ function handleAccountNotFoundError(error, moduleName, context, network) {
103
+ const address = context[moduleName]?.addresses[moduleName];
104
+ if (address === void 0) {
105
+ return;
106
+ }
107
+ if (error.response.data.message.includes(`account ${AccAddress.fromHex(address)} not found`)) {
108
+ throw new Error(
109
+ `${error.response.data.message}, make sure you have funded the account ${AccAddress.fromHex(address)}(${address}) on ${network}`
110
+ );
111
+ }
112
+ }
113
+ function handleSenderNotMatchError(error, moduleName) {
114
+ if (error.response.data.message.includes("MODULE_ADDRESS_DOES_NOT_MATCH_SENDER")) {
115
+ throw new Error(
116
+ `Deploy ${moduleName} failed with MODULE_ADDRESS_DOES_NOT_MATCH_SENDER, make sure you compile ${moduleName} with the deployer account address`
117
+ );
118
+ }
119
+ }
120
+ function handleOtherAxiosError(error) {
121
+ throw new Error(error.response.data.message);
122
+ }
123
+ function handleError(error, moduleName, context, network) {
124
+ if (isAxiosError(error)) {
125
+ handleDepMissingError(error, moduleName, context);
126
+ handleAccountNotFoundError(error, moduleName, context, network);
127
+ handleSenderNotMatchError(error, moduleName);
128
+ handleOtherAxiosError(error);
129
+ }
130
+ throw error;
131
+ }
132
+ function getRawMoveContextByPath(modulePath) {
133
+ const tomlPath = path3.join(modulePath, "Move.toml");
134
+ if (!fs2.existsSync(tomlPath)) {
135
+ throw new Error(`Move.toml not found in ${tomlPath}`);
136
+ }
137
+ const toml = parse(fs2.readFileSync(tomlPath, "utf-8"));
138
+ const { dependencies } = toml;
139
+ let result = { [toml.package.name]: toml };
140
+ if (dependencies !== void 0) {
141
+ Object.keys(dependencies).filter((key) => {
142
+ return dependencies[key]?.local !== void 0;
143
+ }).forEach((key) => {
144
+ const dependency = dependencies[key];
145
+ const dependencyPath = path3.join(modulePath, dependency.local);
146
+ result = { ...getRawMoveContextByPath(dependencyPath), ...result };
147
+ });
148
+ }
149
+ return result;
150
+ }
151
+ function parseAddresses(addresses, network) {
152
+ if (addresses === void 0) {
153
+ return {};
154
+ }
155
+ const result = {};
156
+ for (const key of Object.keys(addresses)) {
157
+ const value = addresses[key];
158
+ if (typeof value === "string") {
159
+ result[key] = value;
160
+ } else {
161
+ const networkAddress = value[network];
162
+ if (networkAddress === void 0) {
163
+ throw new Error(`${key} address not found for network ${network}`);
164
+ }
165
+ result[key] = networkAddress;
166
+ }
167
+ }
168
+ return result;
169
+ }
170
+ function getMoveContext(moduleName, lzInitiaConfig, network) {
171
+ const module = lzInitiaConfig.modules[moduleName];
172
+ if (!module) {
173
+ throw new Error(`module ${moduleName} not found when getting Move context`);
174
+ }
175
+ const context = getRawMoveContextByPath(module.modulePath);
176
+ for (const key of Object.keys(context)) {
177
+ const toml = context[key];
178
+ for (const addressKey of Object.keys(toml.addresses)) {
179
+ const address = toml.addresses[addressKey];
180
+ const presetAddresses = parseAddresses(lzInitiaConfig.modules[key]?.addresses, network);
181
+ if (address === "_") {
182
+ if (presetAddresses[addressKey] !== void 0 && presetAddresses[addressKey] !== "") {
183
+ toml.addresses[addressKey] = presetAddresses[addressKey];
184
+ } else {
185
+ try {
186
+ toml.addresses[addressKey] = AccAddress.toHex(
187
+ getDeployer(addressKey, lzInitiaConfig, network).accAddress
188
+ );
189
+ } catch (e) {
190
+ if (key === moduleName) {
191
+ throw new Error(`Fail to generate context for ${key}. ${e.toString()}`);
192
+ } else {
193
+ throw new Error(
194
+ `Fail to generate context for dependent module ${key}. ${e.toString()}`
195
+ );
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ return context;
203
+ }
204
+ function deploymentPath(pkgName, dest, network, variant) {
205
+ const deploymentPath2 = path3.join(dest, network);
206
+ return path3.join(deploymentPath2, `${pkgWithVariant(pkgName, variant)}.json`);
207
+ }
208
+ function saveDeployment(moduleName, pkgName, address, dest, network, bytecodeHash, hash, variant, compatibleVersions = [EndpointVersion.V1, EndpointVersion.V2]) {
209
+ const destPath = deploymentPath(pkgName, dest, network, variant);
210
+ const deploymentDir = path3.dirname(destPath);
211
+ if (!fs2.existsSync(deploymentDir)) {
212
+ fs2.mkdirSync(deploymentDir, { recursive: true });
213
+ }
214
+ fs2.writeFileSync(
215
+ destPath,
216
+ JSON.stringify(
217
+ {
218
+ address,
219
+ name: pkgWithVariant(pkgName, variant),
220
+ moduleName,
221
+ network,
222
+ compatibleVersions,
223
+ bytecodeHash,
224
+ transactionHash: hash
225
+ },
226
+ null,
227
+ 2
228
+ )
229
+ );
230
+ console.log(`Deployment saved to ${destPath}`);
231
+ }
232
+ function needDeploy(pkgName, dest, network, bytecodeHash, variant) {
233
+ if (networkToStage(network) === Stage.SANDBOX) {
234
+ return true;
235
+ }
236
+ const destPath = deploymentPath(pkgName, dest, network, variant);
237
+ if (fs2.existsSync(destPath)) {
238
+ const deployment = JSON.parse(fs2.readFileSync(destPath, "utf-8"));
239
+ return deployment.bytecodeHash !== bytecodeHash;
240
+ }
241
+ return true;
242
+ }
243
+ function pkgWithVariant(pkgName, variant) {
244
+ return variant !== void 0 && variant.length > 0 ? `${pkgName}-${variant}` : pkgName;
245
+ }
246
+ function getBytecodesHash(bytecodes) {
247
+ const hash = crypto.createHash("sha256");
248
+ bytecodes.forEach((bytecode) => {
249
+ hash.update(bytecode);
250
+ });
251
+ return hash.digest("hex");
252
+ }
253
+ async function deploy(moduleName, lzInitiaConfig, network, variant) {
254
+ const module = lzInitiaConfig.modules[moduleName];
255
+ if (!module) {
256
+ throw new Error(`module ${moduleName} not found`);
257
+ }
258
+ const env = networkToEnv(network, EndpointVersion.V2);
259
+ const client = getInitiaClient(env, lzInitiaConfig);
260
+ const deployer = getDeployer(moduleName, lzInitiaConfig, network);
261
+ const context = getMoveContext(moduleName, lzInitiaConfig, network);
262
+ const pkgName = lzInitiaConfig.modules[moduleName]?.alias ?? context[moduleName].package.name;
263
+ const moduleDir = path3.join(lzInitiaConfig.artifactsPath, `${pkgWithVariant(pkgName, variant)}/bytecode_modules`);
264
+ const moduleNames = glob.sync("*.mv", { cwd: moduleDir });
265
+ const moduleBuffers = moduleNames.map((moduleName2) => fs2.readFileSync(path3.join(moduleDir, moduleName2)));
266
+ const bytecodeHash = getBytecodesHash(moduleBuffers);
267
+ if (!needDeploy(pkgName, lzInitiaConfig.deploymentPath, network, bytecodeHash, variant)) {
268
+ console.warn(`Code of ${moduleName} has not changed, skipping deploy`);
269
+ return;
270
+ }
271
+ try {
272
+ const msgs = [
273
+ new MsgPublish(
274
+ deployer.accAddress,
275
+ moduleBuffers.map((codeBytes) => codeBytes.toString("base64")),
276
+ MsgPublish.Policy.COMPATIBLE
277
+ )
278
+ ];
279
+ const wallet = new Wallet(client, deployer);
280
+ const gasPrices = lzInitiaConfig.gasPrice?.[network] === void 0 ? void 0 : `${lzInitiaConfig.gasPrice[network]}unit`;
281
+ const signedTx = await wallet.createAndSignTx({ msgs, gasPrices });
282
+ const tx = await client.tx.broadcast(signedTx);
283
+ if (tx.code !== 0) {
284
+ throw new Error(tx.raw_log);
285
+ }
286
+ console.log(`Deploy transaction ${tx.txhash} successfully`);
287
+ saveDeployment(
288
+ moduleName,
289
+ pkgName,
290
+ AccAddress.toHex(deployer.accAddress),
291
+ lzInitiaConfig.deploymentPath,
292
+ network,
293
+ bytecodeHash,
294
+ tx.txhash,
295
+ variant,
296
+ lzInitiaConfig.compatibleVersions
297
+ );
298
+ } catch (e) {
299
+ if (e instanceof Error) {
300
+ handleError(e, moduleName, context, network);
301
+ } else {
302
+ throw e;
303
+ }
304
+ }
305
+ }
306
+ var command = new Command();
307
+ command.name("deploy").description("deploy Initia modules").addOption(createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).action(async (options, cmd) => {
308
+ const context = cmd.getOptionValue("__CONTEXT__");
309
+ const { modules, variant, network } = options;
310
+ for (const module of modules) {
311
+ await deploy(module, context, network, variant ?? context.modules[module]?.variant);
312
+ }
313
+ });
314
+
315
+ // src/options.ts
316
+ function parseOptions(defaultOptions, customOptions) {
317
+ const options = { ...defaultOptions, ...customOptions };
318
+ const res = [];
319
+ for (const key of Object.keys(options)) {
320
+ if (typeof options[key] === "boolean") {
321
+ if (options[key] === true) {
322
+ res.push(key);
323
+ }
324
+ } else {
325
+ res.push(key);
326
+ res.push(options[key]);
327
+ }
328
+ }
329
+ return res;
330
+ }
331
+ function buildProcess(modulePath, addresses, toml, customOptions = {}) {
332
+ const addressesParam = Object.keys(addresses).map((key) => `${key}=${addresses[key]}`).join(",");
333
+ const defaultOptions = {
334
+ "--skip-fetch-latest-git-deps": true,
335
+ "--named-addresses": addressesParam
336
+ };
337
+ const args = parseOptions(defaultOptions, customOptions);
338
+ return $({
339
+ cwd: modulePath,
340
+ stdio: ["inherit", "pipe", process.stderr],
341
+ verbose: true
342
+ })`initiad move build ${args}`;
343
+ }
344
+ async function copyArtifacts(src, dest) {
345
+ if (fs2.existsSync(dest)) {
346
+ console.log(`Removing existing artifacts at ${dest}`);
347
+ fs2.rmSync(dest, { recursive: true });
348
+ }
349
+ fs2.mkdirSync(dest, { recursive: true });
350
+ const moduleDir = path3.join(src, "bytecode_modules");
351
+ const modules = glob.sync("*.mv", { cwd: moduleDir });
352
+ for (const module of modules) {
353
+ const destByteCodePath = path3.join(dest, "bytecode_modules");
354
+ if (!fs2.existsSync(destByteCodePath)) {
355
+ fs2.mkdirSync(destByteCodePath, { recursive: true });
356
+ }
357
+ await $({
358
+ verbose: true
359
+ })`cp ${path3.join(moduleDir, module)} ${path3.join(destByteCodePath, module)}`;
360
+ }
361
+ }
362
+ async function build(moduleName, lzInitiaConfig, network, skipBuild = false, variant) {
363
+ const module = lzInitiaConfig.modules[moduleName];
364
+ if (!module) {
365
+ throw new Error(`module ${moduleName} not found`);
366
+ }
367
+ const { modulePath } = module;
368
+ const context = getMoveContext(moduleName, lzInitiaConfig, network);
369
+ const pkgName = context[moduleName].package.name;
370
+ const srcPath = path3.join(modulePath, "build", pkgName);
371
+ const outputDir = lzInitiaConfig.modules[moduleName]?.alias ?? pkgName;
372
+ const outputPath = path3.join(
373
+ lzInitiaConfig.artifactsPath,
374
+ variant !== void 0 && variant.length > 0 ? `${outputDir}-${variant}` : outputDir
375
+ );
376
+ let addresses = {};
377
+ for (const key of Object.keys(context)) {
378
+ const toml = context[key];
379
+ if (!(key in toml.addresses)) {
380
+ throw new Error(`address not found for ${key}`);
381
+ }
382
+ addresses = { ...addresses, ...toml.addresses };
383
+ }
384
+ addresses = { ...addresses, ...context[moduleName].addresses };
385
+ if (!skipBuild) {
386
+ await buildProcess(modulePath, addresses, context[moduleName], {
387
+ ...lzInitiaConfig.compileOptions,
388
+ ...module.compileOptions
389
+ });
390
+ }
391
+ await copyArtifacts(srcPath, outputPath);
392
+ }
393
+ var command2 = new Command();
394
+ command2.name("build").description("build Initia program").addOption(createOption("-m, --modules <modules...>", "modules").makeOptionMandatory(true)).addOption(createOption("-n, --network <network>", "network").makeOptionMandatory(true)).addOption(createOption("-v, --variant <variant>", "variant").makeOptionMandatory(false)).addOption(createOption("-sb, --skip-build", "skip build").default(false)).action(async (options, cmd) => {
395
+ const context = cmd.getOptionValue("__CONTEXT__");
396
+ const { skipBuild, modules, network, variant } = options;
397
+ for (const module of modules) {
398
+ await build(module, context, network, skipBuild, variant ?? context.modules[module]?.variant);
399
+ }
400
+ });
401
+
402
+ // src/cli.ts
403
+ var program = new Command();
404
+ var logger = getLogger();
405
+ program.name("lz-initia-cli").description("Wrapper of Initia cli").version("0.1.0").action((_, command3) => {
406
+ logger.info("Please specify a subcommand");
407
+ command3.help();
408
+ });
409
+ async function checkIfInitiaInstalled() {
410
+ try {
411
+ await $$1`initiad version`;
412
+ } catch (e) {
413
+ throw new Error("Initia cli is not installed");
414
+ }
415
+ }
416
+ function checkIfInitiaConfigExists() {
417
+ const packagePath = sync("package.json", { cwd: process2.cwd() });
418
+ if (packagePath === void 0) {
419
+ throw new Error("package.json not found");
420
+ }
421
+ const configPath = path3.join(path3.dirname(packagePath), "lz-initia.config.ts");
422
+ if (!fs2.existsSync(configPath)) {
423
+ throw new Error("lz-initia.config.ts not found, please create one in the same directory as package.json");
424
+ }
425
+ return configPath;
426
+ }
427
+ async function main() {
428
+ await checkIfInitiaInstalled();
429
+ const configPath = checkIfInitiaConfigExists();
430
+ const config = loadConfig(configPath);
431
+ Object.values(subCommands_exports).forEach((subCommand) => {
432
+ subCommand.setOptionValue("__CONTEXT__", config);
433
+ program.addCommand(subCommand);
434
+ });
435
+ await program.parseAsync();
436
+ }
437
+ main().then(() => process2.exit(process2.exitCode)).catch((error) => {
438
+ logger.error(error);
439
+ process2.exit(1);
440
+ });
441
+ //# sourceMappingURL=out.js.map
442
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts","../src/loader.ts","../src/subCommands/index.ts","../src/deploy.ts","../src/client.ts","../src/deployer.ts","../src/errors.ts","../src/move.ts","../src/subCommands/deploy.ts","../src/build.ts","../src/options.ts","../src/subCommands/build.ts"],"names":["fs","path","process","Command","$","command","AccAddress","deploymentPath","moduleName","glob","createOption"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,OAAOC,cAAa;;;ACAb,SAAS,WAAW,YAAoC;AAG3D,QAAM,aAAa;AACnB,QAAM,SAAS,UAAQ,UAAU;AACjC,SAAO,SAAS;AAAA,IACZ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I,CAACD,IAAG,WAAW,UAAU,GAAG;AAC5B,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC5G;AACA,SAAO;AACX;AAEA,eAAe,OAAsB;AACjC,QAAM,uBAAuB;AAC7B,QAAM,aAAa,0BAA0B;AAC7C,QAAM,SAAS,WAAW,UAAU;AACpC,SAAO,OAAO,mBAAW,EAAE,QAAQ,CAAC,eAAwB;AACxD,eAAW,eAAe,eAAe,MAAM;AAC/C,YAAQ,WAAW,UAAU;AAAA,EACjC,CAAC;AACD,QAAM,QAAQ,WAAW;AAC7B;AAEA,KAAK,EACA,KAAK,MAAME,SAAQ,KAAKA,SAAQ,QAAQ,CAAC,EACzC,MAAM,CAAC,UAAmB;AACvB,SAAO,MAAM,KAAK;AAClB,EAAAA,SAAQ,KAAK,CAAC;AAClB,CAAC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport process from 'process'\n\nimport { loadConfig } from '@/loader'\nimport { Command } from '@commander-js/extra-typings'\nimport { sync as findUpSync } from 'find-up'\nimport { $ } from 'zx/core'\n\nimport { getLogger } from '@layerzerolabs/lz-utilities'\n\nimport * as subCommands from './subCommands'\n\nconst program = new Command()\n// iterate over subCommands and add them to the program\nconst logger = getLogger()\n\nprogram\n .name('lz-initia-cli')\n .description('Wrapper of Initia cli')\n .version('0.1.0')\n .action((_, command: Command) => {\n logger.info('Please specify a subcommand')\n command.help()\n })\n\nasync function checkIfInitiaInstalled(): Promise<void> {\n try {\n await $`initiad version`\n } catch (e) {\n throw new Error('Initia cli is not installed')\n }\n}\n\nfunction checkIfInitiaConfigExists(): string {\n const packagePath = findUpSync('package.json', { cwd: process.cwd() })\n if (packagePath === undefined) {\n throw new Error('package.json not found')\n }\n const configPath = path.join(path.dirname(packagePath), 'lz-initia.config.ts')\n if (!fs.existsSync(configPath)) {\n throw new Error('lz-initia.config.ts not found, please create one in the same directory as package.json')\n }\n return configPath\n}\n\nasync function main(): Promise<void> {\n await checkIfInitiaInstalled()\n const configPath = checkIfInitiaConfigExists()\n const config = loadConfig(configPath)\n Object.values(subCommands).forEach((subCommand: Command) => {\n subCommand.setOptionValue('__CONTEXT__', config)\n program.addCommand(subCommand)\n })\n await program.parseAsync()\n}\n\nmain()\n .then(() => process.exit(process.exitCode))\n .catch((error: unknown) => {\n logger.error(error)\n process.exit(1)\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","export { command as deploy } from './deploy'\nexport { command as build } from './build'\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 { 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 { 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","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 { deploy } from '@/deploy'\nimport { Command, createOption } from '@commander-js/extra-typings'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nimport { LzInitiaConfig } from '../types'\n\nconst command = new Command()\n\nexport { command }\n\ncommand\n .name('deploy')\n .description('deploy Initia modules')\n .addOption(createOption('-m, --modules <modules...>', 'modules').makeOptionMandatory(true))\n .addOption(createOption('-n, --network <network>', 'network').makeOptionMandatory(true))\n .addOption(createOption('-v, --variant <variant>', 'variant').makeOptionMandatory(false))\n .action(async (options: { network: string; modules: string[]; variant?: string }, cmd: Command) => {\n const context = cmd.getOptionValue('__CONTEXT__') as LzInitiaConfig\n\n const { modules, variant, network } = options\n for (const module of modules) {\n await deploy(module, context, network as Network, variant ?? context.modules[module]?.variant)\n }\n })\n","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 { 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 { build } from '@/build'\nimport { Command, createOption } from '@commander-js/extra-typings'\n\nimport { Network } from '@layerzerolabs/lz-definitions'\n\nimport { LzInitiaConfig } from '../types'\n\nconst command = new Command()\n\nexport { command }\n\ncommand\n .name('build')\n .description('build Initia program')\n .addOption(createOption('-m, --modules <modules...>', 'modules').makeOptionMandatory(true))\n .addOption(createOption('-n, --network <network>', 'network').makeOptionMandatory(true))\n .addOption(createOption('-v, --variant <variant>', 'variant').makeOptionMandatory(false))\n .addOption(createOption('-sb, --skip-build', 'skip build').default(false))\n .action(async (options: { network: string; modules: string[]; variant?: string; skipBuild: boolean }, cmd) => {\n const context = cmd.getOptionValue('__CONTEXT__') as LzInitiaConfig\n const { skipBuild, modules, network, variant } = options\n for (const module of modules) {\n await build(module, context, network as Network, skipBuild, variant ?? context.modules[module]?.variant)\n }\n })\n"]}