@twin.org/move-to-json 0.0.3-next.7 → 0.0.3-next.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/cli.js CHANGED
@@ -21,7 +21,7 @@ export class CLI extends CLIBase {
21
21
  return this.execute({
22
22
  title: "TWIN Move to JSON",
23
23
  appName: "move-to-json",
24
- version: "0.0.3-next.7", // x-release-please-version
24
+ version: "0.0.3-next.8", // x-release-please-version
25
25
  icon: "⚙️ ",
26
26
  supportsEnvFiles: true,
27
27
  overrideOutputWidth: options?.overrideOutputWidth
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAEC;QAED,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,mBAAmB;YAC1B,OAAO,EAAE,cAAc;YACvB,OAAO,EAAE,cAAc,EAAE,2BAA2B;YACpD,IAAI,EAAE,KAAK;YACX,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,OAAO,EAAE,mBAAmB;SACjD,EACD,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,EACzF,IAAI,CACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACO,aAAa,CAAC,OAAgB;QACvC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3B,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { CLIBase } from \"@twin.org/cli-core\";\nimport type { Command } from \"commander\";\nimport { buildCommandBuild } from \"./commands/build.js\";\nimport { buildCommandDeploy } from \"./commands/deploy.js\";\n\n/**\n * The main entry point for the Move to JSON CLI.\n */\nexport class CLI extends CLIBase {\n\t/**\n\t * Run the app.\n\t * @param argv The process arguments.\n\t * @param localesDirectory The directory for the locales, default to relative to the script.\n\t * @param options Additional options.\n\t * @param options.overrideOutputWidth Override the output width.\n\t * @returns The exit code.\n\t */\n\tpublic async run(\n\t\targv: string[],\n\t\tlocalesDirectory?: string,\n\t\toptions?: {\n\t\t\toverrideOutputWidth?: number;\n\t\t}\n\t): Promise<number> {\n\t\treturn this.execute(\n\t\t\t{\n\t\t\t\ttitle: \"TWIN Move to JSON\",\n\t\t\t\tappName: \"move-to-json\",\n\t\t\t\tversion: \"0.0.3-next.7\", // x-release-please-version\n\t\t\t\ticon: \"⚙️ \",\n\t\t\t\tsupportsEnvFiles: true,\n\t\t\t\toverrideOutputWidth: options?.overrideOutputWidth\n\t\t\t},\n\t\t\tlocalesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), \"../locales\"),\n\t\t\targv\n\t\t);\n\t}\n\n\t/**\n\t * Configure any options or actions at the root program level.\n\t * @param program The root program command.\n\t */\n\tprotected configureRoot(program: Command): void {\n\t\tbuildCommandBuild(program);\n\t\tbuildCommandDeploy(program);\n\t}\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAEC;QAED,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,mBAAmB;YAC1B,OAAO,EAAE,cAAc;YACvB,OAAO,EAAE,cAAc,EAAE,2BAA2B;YACpD,IAAI,EAAE,KAAK;YACX,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,OAAO,EAAE,mBAAmB;SACjD,EACD,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,EACzF,IAAI,CACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACO,aAAa,CAAC,OAAgB;QACvC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3B,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { CLIBase } from \"@twin.org/cli-core\";\nimport type { Command } from \"commander\";\nimport { buildCommandBuild } from \"./commands/build.js\";\nimport { buildCommandDeploy } from \"./commands/deploy.js\";\n\n/**\n * The main entry point for the Move to JSON CLI.\n */\nexport class CLI extends CLIBase {\n\t/**\n\t * Run the app.\n\t * @param argv The process arguments.\n\t * @param localesDirectory The directory for the locales, default to relative to the script.\n\t * @param options Additional options.\n\t * @param options.overrideOutputWidth Override the output width.\n\t * @returns The exit code.\n\t */\n\tpublic async run(\n\t\targv: string[],\n\t\tlocalesDirectory?: string,\n\t\toptions?: {\n\t\t\toverrideOutputWidth?: number;\n\t\t}\n\t): Promise<number> {\n\t\treturn this.execute(\n\t\t\t{\n\t\t\t\ttitle: \"TWIN Move to JSON\",\n\t\t\t\tappName: \"move-to-json\",\n\t\t\t\tversion: \"0.0.3-next.8\", // x-release-please-version\n\t\t\t\ticon: \"⚙️ \",\n\t\t\t\tsupportsEnvFiles: true,\n\t\t\t\toverrideOutputWidth: options?.overrideOutputWidth\n\t\t\t},\n\t\t\tlocalesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), \"../locales\"),\n\t\t\targv\n\t\t);\n\t}\n\n\t/**\n\t * Configure any options or actions at the root program level.\n\t * @param program The root program command.\n\t */\n\tprotected configureRoot(program: Command): void {\n\t\tbuildCommandBuild(program);\n\t\tbuildCommandDeploy(program);\n\t}\n}\n"]}
@@ -5,7 +5,7 @@ import path from "node:path";
5
5
  import { IotaClient } from "@iota/iota-sdk/client";
6
6
  import { requestIotaFromFaucetV0 } from "@iota/iota-sdk/faucet";
7
7
  import { CLIDisplay, CLIParam, CLIUtils } from "@twin.org/cli-core";
8
- import { Converter, GeneralError, Guards, I18n, Is, RandomHelper } from "@twin.org/core";
8
+ import { Coerce, Converter, GeneralError, Guards, I18n, Is, RandomHelper } from "@twin.org/core";
9
9
  import { Bip39, Bip44 } from "@twin.org/crypto";
10
10
  import { Iota, NetworkTypes } from "@twin.org/dlt-iota";
11
11
  import { cleanBuildArtifactsInPath } from "../utils/buildArtifactUtils.js";
@@ -398,6 +398,39 @@ async function determineDeploymentStrategy(contractData) {
398
398
  }
399
399
  return "initial-deploy";
400
400
  }
401
+ /**
402
+ * Query the on-chain UpgradeCap object to get the actual latest package ID.
403
+ * This is used to validate/correct the `published-at` value before upgrades,
404
+ * preventing failures when the deployment JSON is stale.
405
+ * @param rpcUrl RPC endpoint URL for the network.
406
+ * @param upgradeCapabilityId The UpgradeCap object ID on-chain.
407
+ * @returns The on-chain package ID and version, or undefined if query fails.
408
+ */
409
+ async function queryUpgradeCapPackage(rpcUrl, upgradeCapabilityId) {
410
+ try {
411
+ const client = new IotaClient({ url: rpcUrl });
412
+ const response = await client.getObject({
413
+ id: upgradeCapabilityId,
414
+ options: { showContent: true }
415
+ });
416
+ if (response.data?.content?.dataType === "moveObject") {
417
+ const fields = response.data.content.fields;
418
+ const fieldPackage = Coerce.string(fields.package);
419
+ const fieldVersion = Coerce.number(fields.version);
420
+ if (Is.stringValue(fieldPackage) && Is.number(fieldVersion)) {
421
+ return {
422
+ package: fieldPackage,
423
+ version: fieldVersion
424
+ };
425
+ }
426
+ }
427
+ return undefined;
428
+ }
429
+ catch {
430
+ // If query fails (e.g. network issue), return undefined to fall back to JSON value
431
+ return undefined;
432
+ }
433
+ }
401
434
  /**
402
435
  * Execute contract upgrade using iota client upgrade command.
403
436
  * @param contractData Contract data containing upgrade capability.
@@ -405,10 +438,27 @@ async function determineDeploymentStrategy(contractData) {
405
438
  * @returns Upgrade result with package ID and upgrade capability.
406
439
  */
407
440
  async function executeContractUpgrade(contractData, config) {
408
- // Store the previous deployedPackageId for "published-at" field in Move.toml
409
- // Use lastDeployedPackageId which tracks the previous deployment for upgrade chain
410
- const previousDeployedPackageId = contractData.lastDeployedPackageId;
411
- if (!previousDeployedPackageId) {
441
+ // Start with lastDeployedPackageId from JSON as the candidate for "published-at"
442
+ let publishedAtPackageId = contractData.lastDeployedPackageId;
443
+ // Query the on-chain UpgradeCap to get the actual latest package ID.
444
+ // This prevents failures when the JSON is stale
445
+ if (Is.stringValue(contractData.upgradeCapabilityId)) {
446
+ CLIDisplay.task(I18n.formatMessage("commands.deploy.progress.queryingUpgradeCap"));
447
+ const onChainCap = await queryUpgradeCapPackage(config.rpc.url, contractData.upgradeCapabilityId);
448
+ if (onChainCap) {
449
+ CLIDisplay.value(I18n.formatMessage("commands.deploy.labels.onChainPackageId"), onChainCap.package, 1);
450
+ CLIDisplay.value(I18n.formatMessage("commands.deploy.labels.onChainVersion"), String(onChainCap.version), 1);
451
+ if (publishedAtPackageId !== onChainCap.package) {
452
+ CLIDisplay.value(I18n.formatMessage("commands.deploy.labels.warning"), I18n.formatMessage("commands.deploy.messages.staleJsonDetected", {
453
+ jsonPackageId: publishedAtPackageId ?? "none",
454
+ onChainPackageId: onChainCap.package
455
+ }), 2);
456
+ publishedAtPackageId = onChainCap.package;
457
+ contractData.lastDeployedPackageId = onChainCap.package;
458
+ }
459
+ }
460
+ }
461
+ if (!publishedAtPackageId) {
412
462
  throw new GeneralError("commands", "commands.deploy.noPreviousDeploymentForUpgrade");
413
463
  }
414
464
  const moveTomlPaths = [];
@@ -424,8 +474,8 @@ async function executeContractUpgrade(contractData, config) {
424
474
  const projectRoot = path.dirname(moveTomlPath);
425
475
  const backupPath = await backupMoveToml(moveTomlPath);
426
476
  try {
427
- // Update Move.toml with "published-at" = previous deployedPackageId
428
- await updateMoveTomlPublishedAt(moveTomlPath, previousDeployedPackageId);
477
+ // Update Move.toml with "published-at" = validated package ID (from chain or JSON)
478
+ await updateMoveTomlPublishedAt(moveTomlPath, publishedAtPackageId);
429
479
  await validateContractIsBuilt(contractData, projectRoot);
430
480
  // Execute upgrade command
431
481
  const upgradeCapabilityId = contractData.upgradeCapabilityId;
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ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AmB,EAAE,EAAE,CAAC,IAAI,KAAK,eAAe,CACzD,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;YACpB,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,oCAAoC,EAAE;gBACxE,eAAe;gBACf,SAAS;aACT,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,YAAY,CACrB,UAAU,EACV,wCAAwC,EACxC,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,EACvC,KAAK,CACL,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,wBAAwB,CACtC,OAAqB,EACrB,SAAiB,EACjB,YAAoB,EACpB,aAAqB,EACrB,gBAAwB;IAExB,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,+CAA+C,EAAE,EAAE,SAAS,EAAE,CAAC,CAClF,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IACxE,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;IAE7F,MAAM,kBAAkB,CACvB,wBAAwB,QAAQ,cAAc,cAAc,cAAc,SAAS,GAAG,CACtF,CAAC;IAEF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC,EAChE,GAAG,SAAS,KAAK,aAAa,GAAG,EACjC,CAAC,CACD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { promises as fsPromises } from \"node:fs\";\nimport path from \"node:path\";\nimport { IotaClient } from \"@iota/iota-sdk/client\";\nimport { requestIotaFromFaucetV0 } from \"@iota/iota-sdk/faucet\";\nimport { CLIDisplay, CLIParam, CLIUtils } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, I18n, Is, RandomHelper } from \"@twin.org/core\";\nimport { Bip39, Bip44 } from \"@twin.org/crypto\";\nimport {\n\tIota,\n\tNetworkTypes,\n\ttype IContractData,\n\ttype ISmartContractDeployments\n} from \"@twin.org/dlt-iota\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { Command } from \"commander\";\nimport type { INetworkConfig } from \"../models/INetworkConfig.js\";\nimport { cleanBuildArtifactsInPath } from \"../utils/buildArtifactUtils.js\";\nimport { ensureEnvironment, execAsyncWithError } from \"../utils/environmentUtils.js\";\nimport {\n\tgetDeploymentMnemonic,\n\tgetDeploymentSeed,\n\tvalidateDeploymentEnvironment\n} from \"../utils/envSetup.js\";\nimport { verifyIotaSDK } from \"../utils/iotaUtils.js\";\nimport { searchDirectoryForMoveToml } from \"../utils/moveToJsonUtils.js\";\n\n/**\n * Build the deploy command.\n * @param program The command program.\n */\nexport function buildCommandDeploy(program: Command): void {\n\tprogram\n\t\t.command(\"deploy\")\n\t\t.description(I18n.formatMessage(\"commands.deploy.description\"))\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.contracts.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.contracts.description\"),\n\t\t\t\"smart-contract-deployments.json\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.dryRun.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.dryRun.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.force.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.force.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcUrl.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcUrl.description\"),\n\t\t\t\"!RPC_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.addressIndex.description\"),\n\t\t\t\"!ADDRESS_INDEX\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcTimeout.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcTimeout.description\"),\n\t\t\t\"!RPC_TIMEOUT\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.gasBudget.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.gasBudget.description\"),\n\t\t\t\"!GAS_BUDGET\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.confirmationTimeout.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.confirmationTimeout.description\"),\n\t\t\t\"!CONFIRMATION_TIMEOUT\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.faucetUrl.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.faucetUrl.description\"),\n\t\t\t\"!FAUCET_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerMnemonic.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerMnemonic.description\"),\n\t\t\t\"!DEPLOYER_MNEMONIC\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerSeed.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerSeed.description\"),\n\t\t\t\"!DEPLOYER_SEED\"\n\t\t)\n\t\t.action(actionCommandDeploy);\n}\n\n/**\n * Action for the deploy command.\n * @param opts Command options.\n * @param opts.contracts Path to compiled modules JSON.\n * @param opts.network Network identifier - optional if NETWORK env var is set.\n * @param opts.dryRun Simulate deployment without executing.\n * @param opts.force Force redeployment of existing packages.\n * @param opts.rpcUrl RPC endpoint URL for the network.\n * @param opts.addressIndex Address index for key derivation.\n * @param opts.rpcTimeout RPC request timeout in milliseconds.\n * @param opts.gasBudget Gas budget for transactions.\n * @param opts.confirmationTimeout Transaction confirmation timeout in milliseconds.\n * @param opts.faucetUrl Faucet URL for requesting test tokens.\n * @param opts.deployerMnemonic Deployer wallet mnemonic phrase.\n * @param opts.deployerSeed Deployer wallet seed (alternative to mnemonic).\n */\nexport async function actionCommandDeploy(opts: {\n\tcontracts?: string;\n\tnetwork?: NetworkTypes;\n\tdryRun?: boolean;\n\tforce?: boolean;\n\trpcUrl?: string;\n\taddressIndex?: string;\n\trpcTimeout?: string;\n\tgasBudget?: string;\n\tconfirmationTimeout?: string;\n\tfaucetUrl?: string;\n\tdeployerMnemonic?: string;\n\tdeployerSeed?: string;\n}): Promise<void> {\n\tconst network = CLIParam.arrayOneOf<NetworkTypes>(\n\t\t\"network\",\n\t\topts.network,\n\t\tObject.values(NetworkTypes),\n\t\ttrue\n\t);\n\n\tconst contractsPath = opts.contracts ?? \"smart-contract-deployments.json\";\n\tconst dryRun = opts.dryRun ?? false;\n\tconst force = opts.force ?? false;\n\n\tCLIDisplay.section(I18n.formatMessage(\"commands.deploy.section.deployContracts\"));\n\tCLIDisplay.section(contractsPath);\n\n\t// Verify the IOTA SDK before we do anything else\n\tawait verifyIotaSDK();\n\n\t// Get configuration values needed for environment setup\n\tconst rpcUrl: string = CLIParam.stringValue(\"rpcUrl\", opts.rpcUrl);\n\tconst addressIndex = CLIParam.number(\"addressIndex\", opts.addressIndex) ?? 0;\n\tconst rpcTimeout = CLIParam.number(\"rpcTimeout\", opts.rpcTimeout);\n\tconst gasBudget = CLIParam.number(\"gasBudget\", opts.gasBudget);\n\tconst confirmationTimeout = CLIParam.number(\"confirmationTimeout\", opts.confirmationTimeout);\n\tconst faucetUrl: string | undefined =\n\t\tnetwork === NetworkTypes.Mainnet\n\t\t\t? undefined\n\t\t\t: CLIParam.stringValue(\"faucetUrl\", opts.faucetUrl);\n\n\tlet deployerMnemonic: string | undefined;\n\ttry {\n\t\tdeployerMnemonic = CLIParam.stringValue(\"deployerMnemonic\", opts.deployerMnemonic);\n\t} catch {\n\t\t// Optional parameter, can be undefined\n\t\tdeployerMnemonic = undefined;\n\t}\n\n\tlet deployerSeed: string | undefined;\n\ttry {\n\t\tdeployerSeed = CLIParam.stringValue(\"deployerSeed\", opts.deployerSeed);\n\t} catch {\n\t\t// Optional parameter, can be undefined\n\t\tdeployerSeed = undefined;\n\t}\n\n\t// Validate that at least one deployer credential is provided\n\tconst hasValidMnemonic = Is.stringValue(deployerMnemonic);\n\tconst hasValidSeed = Is.stringValue(deployerSeed);\n\n\tif (!hasValidMnemonic && !hasValidSeed) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.deployerCredentialRequired\", {\n\t\t\tnetwork\n\t\t});\n\t}\n\n\t// Check/switch to target network environment BEFORE loading config\n\tawait setIotaEnvironment(network, rpcUrl, addressIndex, dryRun, deployerMnemonic, deployerSeed);\n\n\tconst config = await createNetworkConfig(\n\t\tnetwork,\n\t\trpcUrl,\n\t\taddressIndex,\n\t\trpcTimeout,\n\t\tgasBudget,\n\t\tconfirmationTimeout\n\t);\n\tvalidateNetworkConfig(config, network);\n\n\tconst contractsData = await loadCompiledContracts(contractsPath);\n\n\tif (network === NetworkTypes.Mainnet) {\n\t\tconst validatedMnemonic = await getDeploymentMnemonic(\n\t\t\tnetwork,\n\t\t\thasValidMnemonic ? deployerMnemonic : undefined\n\t\t);\n\t\tawait validateDeploymentEnvironment(network, validatedMnemonic);\n\t}\n\n\tconst networkContracts = contractsData[network];\n\tif (!Is.object<IContractData>(networkContracts)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noContractsFound\", {\n\t\t\tnetwork,\n\t\t\tcontractsPath\n\t\t});\n\t}\n\n\tawait deployContract(\n\t\t\"contract\",\n\t\tnetworkContracts,\n\t\tconfig,\n\t\tnetwork,\n\t\tdryRun,\n\t\tforce,\n\t\tfaucetUrl,\n\t\tdeployerMnemonic,\n\t\tdeployerSeed\n\t);\n\n\tif (!dryRun) {\n\t\tawait updateContractsFile(contractsPath, contractsData);\n\t}\n\n\tCLIDisplay.done();\n}\n\n/**\n * Switch IOTA CLI to the target network environment and set the active address.\n * @param network Target network to switch to\n * @param rpcUrl The RPC URL for the network\n * @param addressIndex The address index to derive the target address\n * @param dryRun Whether this is a dry run (checks environment but doesn't switch)\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function setIotaEnvironment(\n\tnetwork: NetworkTypes,\n\trpcUrl: string,\n\taddressIndex: number,\n\tdryRun: boolean = false,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\ttry {\n\t\tCLIDisplay.task(\n\t\t\tdryRun\n\t\t\t\t? I18n.formatMessage(\"commands.deploy.progress.checkingEnvironment\")\n\t\t\t\t: I18n.formatMessage(\"commands.deploy.progress.settingEnvironment\")\n\t\t);\n\n\t\t// Ensure environment exists, create if necessary\n\t\tGuards.stringValue(\"setIotaEnvironment\", nameof(rpcUrl), rpcUrl);\n\n\t\tawait ensureEnvironment(network, rpcUrl);\n\n\t\tif (dryRun) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.iotaEnvironmentCheck\"),\n\t\t\t\t`✅ ${network} environment exists`,\n\t\t\t\t1\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// Derive the target address from existing mnemonic/seed\n\t\tconst targetAddress = await getDeploymentWalletAddress(\n\t\t\tnetwork,\n\t\t\taddressIndex,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\n\t\t// Ensure the correct deployer key exists in the keystore\n\t\tconst aliasName = `deployer-${network}`;\n\t\tconst validatedMnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\t\tawait ensureCorrectDeployerKey(\n\t\t\tnetwork,\n\t\t\taliasName,\n\t\t\ttargetAddress,\n\t\t\taddressIndex,\n\t\t\tvalidatedMnemonic\n\t\t);\n\n\t\t// Switch both environment and address in one command\n\t\tawait execAsyncWithError(`iota client switch --env ${network} --address ${targetAddress}`);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.switchedIotaEnvironment\"),\n\t\t\tnetwork,\n\t\t\t1\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.switchedActiveAddress\"),\n\t\t\ttargetAddress,\n\t\t\t1\n\t\t);\n\n\t\t// Verify the switch was successful\n\t\tconst { stdout: activeEnv } = await execAsyncWithError(\"iota client active-env\");\n\t\tif (!activeEnv.includes(network)) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.environmentSwitchFailed\", {\n\t\t\t\tnetwork,\n\t\t\t\tactiveEnv\n\t\t\t});\n\t\t}\n\n\t\t// Verify address switch was successful\n\t\tconst { stdout: activeAddressOutput } = await execAsyncWithError(\"iota client active-address\");\n\t\tconst activeAddress = activeAddressOutput.trim();\n\t\tif (activeAddress !== targetAddress) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.addressSwitchFailed\", {\n\t\t\t\tnetwork,\n\t\t\t\ttargetAddress,\n\t\t\t\tactiveAddress\n\t\t\t});\n\t\t}\n\t} catch (error) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.environmentOperationFailed\",\n\t\t\t{ network, operation: dryRun ? \"check\" : \"switch to\" },\n\t\t\terror\n\t\t);\n\t}\n}\n\n/**\n * Creates the network configuration.\n * @param network Target network to determine which env file to load.\n * @param rpcUrl The RPC URL for the network.\n * @param addressIndex The address index for the wallet.\n * @param rpcTimeout The RPC timeout in milliseconds.\n * @param gasBudget The gas budget for deployment.\n * @param confirmationTimeout The confirmation timeout in seconds.\n * @returns Network configuration.\n */\nasync function createNetworkConfig(\n\tnetwork: NetworkTypes,\n\trpcUrl: string,\n\taddressIndex: number,\n\trpcTimeout?: number,\n\tgasBudget?: number,\n\tconfirmationTimeout?: number\n): Promise<INetworkConfig> {\n\ttry {\n\t\tGuards.stringValue(\"createNetworkConfig\", nameof(rpcUrl), rpcUrl);\n\n\t\tconst config: INetworkConfig = {\n\t\t\tnetwork,\n\t\t\tplatform: \"iota\",\n\t\t\trpc: {\n\t\t\t\turl: rpcUrl,\n\t\t\t\ttimeout: rpcTimeout ?? 60000\n\t\t\t},\n\t\t\tdeployment: {\n\t\t\t\tgasBudget: gasBudget ?? 50000000,\n\t\t\t\tconfirmationTimeout: confirmationTimeout ?? 60,\n\t\t\t\twallet: {\n\t\t\t\t\taddressIndex\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\treturn config;\n\t} catch (err) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.networkConfigInvalid\", { network }, err);\n\t}\n}\n\n/**\n * Validate network configuration matches expected network.\n * @param config Network configuration.\n * @param expectedNetwork Expected network type.\n * @throws GeneralError if the network configuration is invalid.\n */\nfunction validateNetworkConfig(config: INetworkConfig, expectedNetwork: NetworkTypes): void {\n\tif (config.network !== expectedNetwork) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.networkMismatch\", {\n\t\t\texpected: expectedNetwork,\n\t\t\tactual: config.network,\n\t\t\thelp: `Configuration file specifies '${config.network}' but command targets '${expectedNetwork}'`\n\t\t});\n\t}\n\n\tif (!Is.stringValue(config.rpc?.url)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.rpcUrlRequired\", {\n\t\t\tnetwork: expectedNetwork\n\t\t});\n\t}\n\n\tif (!Is.number(config.deployment?.gasBudget)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.gasBudgetRequired\", {\n\t\t\tnetwork: expectedNetwork\n\t\t});\n\t}\n}\n\n/**\n * Load compiled contracts from file.\n * @param contractsPath Path to contracts file.\n * @returns Compiled contracts data.\n */\nasync function loadCompiledContracts(contractsPath: string): Promise<ISmartContractDeployments> {\n\ttry {\n\t\tif (!(await CLIUtils.fileExists(contractsPath))) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.contractsFileNotFound\", {\n\t\t\t\tcontractsPath\n\t\t\t});\n\t\t}\n\n\t\tconst contracts = await CLIUtils.readJsonFile<ISmartContractDeployments>(contractsPath);\n\n\t\tif (!Is.object(contracts)) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.invalidContractsFile\");\n\t\t}\n\n\t\treturn contracts;\n\t} catch (err) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.contractsLoadFailed\",\n\t\t\t{ contractsPath },\n\t\t\terr\n\t\t);\n\t}\n}\n\n/**\n * Validate environment and setup for deployment based on network type.\n * @param network Target network.\n * @param config Network configuration.\n * @param isDryRun Whether this is a dry run.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic for validation.\n * @param deployerSeed The deployer seed (optional).\n * @returns Wallet address for the deployment.\n */\nasync function validateEnvironmentForNetwork(\n\tnetwork: NetworkTypes,\n\tconfig: INetworkConfig,\n\tisDryRun: boolean = false,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<string> {\n\tconst walletAddress = await getDeploymentWalletAddress(\n\t\tnetwork,\n\t\tconfig.deployment.wallet.addressIndex,\n\t\tdeployerMnemonic,\n\t\tdeployerSeed\n\t);\n\n\tif (isDryRun) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.dryRunWalletAddress\"),\n\t\t\twalletAddress,\n\t\t\t1\n\t\t);\n\t} else {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.walletAddress\"), walletAddress, 1);\n\t}\n\n\tif (network === NetworkTypes.Mainnet) {\n\t\tconst validatedMnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\t\tawait validateDeploymentEnvironment(network, validatedMnemonic);\n\t} else if ((network === NetworkTypes.Testnet || network === NetworkTypes.Devnet) && !isDryRun) {\n\t\t// For testnet/devnet, check balance first and only request funds if needed\n\t\tawait checkBalanceAndRequestFaucetIfNeeded(network, config, walletAddress, faucetUrl);\n\t}\n\n\treturn walletAddress;\n}\n\n/**\n * Check wallet balance and display relevant information.\n * @param network Target network.\n * @param config Network configuration.\n * @param walletAddress Wallet address.\n * @param isDryRun Whether this is a dry run.\n * @returns Balance in nanos.\n */\nasync function checkWalletBalance(\n\tnetwork: NetworkTypes,\n\tconfig: INetworkConfig,\n\twalletAddress: string,\n\tisDryRun: boolean = false\n): Promise<number> {\n\tconst client = new IotaClient({ url: config.rpc.url });\n\tconst balanceResponse = await client.getBalance({ owner: walletAddress });\n\tconst balanceInNanos = Number(balanceResponse.totalBalance);\n\tconst requiredInNanos = config.deployment.gasBudget;\n\n\tconst balanceInIota = nanosToIota(balanceInNanos);\n\tconst requiredInIota = nanosToIota(requiredInNanos);\n\n\tconst balanceLabel = isDryRun\n\t\t? \"commands.deploy.labels.dryRunWalletBalance\"\n\t\t: \"commands.deploy.labels.walletBalance\";\n\tconst gasBudgetLabel = isDryRun\n\t\t? \"commands.deploy.labels.dryRunGasBudget\"\n\t\t: \"commands.deploy.labels.gasBudget\";\n\n\tCLIDisplay.value(I18n.formatMessage(balanceLabel), `${balanceInIota.toFixed(2)} IOTA`, 1);\n\tCLIDisplay.value(I18n.formatMessage(gasBudgetLabel), `${requiredInIota.toFixed(2)} IOTA`, 1);\n\n\t// Handle insufficient balance based on network and run type (compare in same units - nanos)\n\tif (balanceInNanos < requiredInNanos) {\n\t\tif (isDryRun) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.insufficientBalanceWarning\", {\n\t\t\t\t\tcurrentBalance: balanceInIota.toFixed(2),\n\t\t\t\t\trequiredBalance: requiredInIota.toFixed(2)\n\t\t\t\t}),\n\t\t\t\t2\n\t\t\t);\n\t\t} else if (network === NetworkTypes.Mainnet) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.insufficientBalance\", {\n\t\t\t\tbalance: balanceInIota,\n\t\t\t\trequired: requiredInIota,\n\t\t\t\twalletAddress\n\t\t\t});\n\t\t} else {\n\t\t\t// For testnet/devnet, show warning but continue\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.insufficientBalanceAfterFaucet\", {\n\t\t\t\t\tnetwork,\n\t\t\t\t\tbalance: balanceInIota.toFixed(2),\n\t\t\t\t\trequired: requiredInIota.toFixed(2),\n\t\t\t\t\twalletAddress\n\t\t\t\t}),\n\t\t\t\t2\n\t\t\t);\n\t\t}\n\t}\n\n\treturn balanceInNanos;\n}\n\n/**\n * Handle dry run validation and display.\n * @param contractName Name of the contract.\n * @param contractData Contract data.\n * @param config Network configuration.\n * @param network Target network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function handleDryRunValidation(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.dryRunWouldDeploy\"),\n\t\t`${contractName} (${network})`,\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.dryRunPackageId\"),\n\t\tcontractData.packageId,\n\t\t1\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.dryRunRpcUrl\"), config.rpc.url, 1);\n\n\ttry {\n\t\tconst walletAddress = await validateEnvironmentForNetwork(\n\t\t\tnetwork,\n\t\t\tconfig,\n\t\t\ttrue,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t\tawait checkWalletBalance(network, config, walletAddress, true);\n\t} catch (err) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.environmentValidationWarning\", {\n\t\t\t\tmessage: (err as Error).message\n\t\t\t}),\n\t\t\t2\n\t\t);\n\t}\n}\n\n/**\n * Handle actual deployment execution.\n * @param contractName Name of the contract.\n * @param contractData Contract data.\n * @param config Network configuration.\n * @param network Target network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function handleActualDeployment(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\ttry {\n\t\tconst walletAddress = await validateEnvironmentForNetwork(\n\t\t\tnetwork,\n\t\t\tconfig,\n\t\t\tfalse,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t\tawait checkWalletBalance(network, config, walletAddress, false);\n\n\t\tconst deploymentResult = await deployWithIotaCli(config.deployment.gasBudget);\n\n\t\tcontractData.deployedPackageId = deploymentResult.packageId;\n\t\tcontractData.upgradeCapabilityId = deploymentResult.upgradeCap;\n\n\t\tif (deploymentResult.migrationStateId) {\n\t\t\tcontractData.migrationStateId = deploymentResult.migrationStateId;\n\t\t}\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.deployedPackageIdResult\"),\n\t\t\tdeploymentResult.packageId,\n\t\t\t1\n\t\t);\n\t\tif (deploymentResult.upgradeCap) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeCapabilityIdResult\"),\n\t\t\t\tdeploymentResult.upgradeCap,\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t\tif (contractData.migrationStateId) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.migrationStateIdResult\"),\n\t\t\t\tcontractData.migrationStateId,\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t} catch (err) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.deploymentFailed\",\n\t\t\t{ contract: contractName },\n\t\t\terr\n\t\t);\n\t}\n}\n\n/**\n * Determine the deployment strategy based on contract state.\n * @param contractData Contract data to analyze.\n * @returns Deployment strategy: initial-deploy, upgrade or already-deployed.\n */\nasync function determineDeploymentStrategy(\n\tcontractData: IContractData\n): Promise<\"initial-deploy\" | \"upgrade\" | \"already-deployed\"> {\n\tif (Is.stringValue(contractData.deployedPackageId)) {\n\t\treturn \"already-deployed\";\n\t}\n\n\tif (Is.stringValue(contractData.lastDeployedPackageId)) {\n\t\treturn \"upgrade\";\n\t}\n\n\treturn \"initial-deploy\";\n}\n\n/**\n * Execute contract upgrade using iota client upgrade command.\n * @param contractData Contract data containing upgrade capability.\n * @param config Network configuration.\n * @returns Upgrade result with package ID and upgrade capability.\n */\nasync function executeContractUpgrade(\n\tcontractData: IContractData,\n\tconfig: INetworkConfig\n): Promise<{ packageId: string; upgradeCap: string; migrationStateId?: string }> {\n\t// Store the previous deployedPackageId for \"published-at\" field in Move.toml\n\t// Use lastDeployedPackageId which tracks the previous deployment for upgrade chain\n\tconst previousDeployedPackageId = contractData.lastDeployedPackageId;\n\tif (!previousDeployedPackageId) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noPreviousDeploymentForUpgrade\");\n\t}\n\n\tconst moveTomlPaths: string[] = [];\n\tawait searchDirectoryForMoveToml(process.cwd(), moveTomlPaths);\n\n\tif (moveTomlPaths.length === 0) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noMoveTomlFilesFound\", {\n\t\t\tcurrentDir: process.cwd()\n\t\t});\n\t}\n\n\tconst currentDirMoveToml = path.join(process.cwd(), \"Move.toml\");\n\tconst selectedMoveToml = moveTomlPaths.find(p => p === currentDirMoveToml) ?? moveTomlPaths[0];\n\tconst moveTomlPath = selectedMoveToml;\n\tconst projectRoot = path.dirname(moveTomlPath);\n\n\tconst backupPath = await backupMoveToml(moveTomlPath);\n\n\ttry {\n\t\t// Update Move.toml with \"published-at\" = previous deployedPackageId\n\t\tawait updateMoveTomlPublishedAt(moveTomlPath, previousDeployedPackageId);\n\n\t\tawait validateContractIsBuilt(contractData, projectRoot);\n\n\t\t// Execute upgrade command\n\t\tconst upgradeCapabilityId = contractData.upgradeCapabilityId;\n\t\tif (!upgradeCapabilityId) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.upgradeCapabilityNotFound\");\n\t\t}\n\t\tconst upgradeResult = await executeUpgradeWithIotaCli(\n\t\t\tupgradeCapabilityId,\n\t\t\tconfig.deployment.gasBudget,\n\t\t\tprojectRoot\n\t\t);\n\n\t\t// Update contract data with new package ID\n\t\tcontractData.deployedPackageId = upgradeResult.packageId;\n\n\t\treturn upgradeResult;\n\t} finally {\n\t\t// Always restore original Move.toml\n\t\tawait restoreMoveToml(moveTomlPath, backupPath);\n\t}\n}\n\n/**\n * Execute upgrade using iota client upgrade command.\n * @param upgradeCapabilityId Upgrade capability ID.\n * @param gasBudget Gas budget for upgrade.\n * @param moveProjectRoot Move project root directory.\n * @returns Upgrade result.\n */\nasync function executeUpgradeWithIotaCli(\n\tupgradeCapabilityId: string,\n\tgasBudget: number,\n\tmoveProjectRoot: string\n): Promise<{ packageId: string; upgradeCap: string; migrationStateId?: string }> {\n\t// Clean build artifacts and lock files before upgrade to prevent permission issues\n\tawait cleanBuildArtifactsInPath(moveProjectRoot);\n\n\tconst upgradeCmd = `iota client upgrade --upgrade-capability ${upgradeCapabilityId} . --gas-budget ${gasBudget} --json`;\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.publishCommand\"), upgradeCmd, 1);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.workingDirectory\"),\n\t\tmoveProjectRoot,\n\t\t1\n\t);\n\n\ttry {\n\t\tconst { stdout: output } = await execAsyncWithError(upgradeCmd, {\n\t\t\tcwd: moveProjectRoot\n\t\t});\n\t\tconst result = JSON.parse(output);\n\n\t\t// Parse upgrade response (different from publish response)\n\t\tconst packageId = result.objectChanges?.find(\n\t\t\t(change: { type: string; packageId?: string }) => change.type === \"published\"\n\t\t)?.packageId;\n\n\t\tif (!packageId) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.upgradePackageIdNotFound\", { result });\n\t\t}\n\n\t\t// UpgradeCap persists with same ID\n\t\tconst upgradeCap = upgradeCapabilityId;\n\n\t\treturn { packageId, upgradeCap };\n\t} catch (err) {\n\t\t// Clean up on error too\n\t\tawait cleanBuildArtifactsInPath(moveProjectRoot);\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.upgradeFailed\", undefined, err);\n\t}\n}\n\n/**\n * Backup Move.toml file.\n * @param moveTomlPath Path to Move.toml file.\n * @returns Path to backup file.\n */\nasync function backupMoveToml(moveTomlPath: string): Promise<string> {\n\tconst backupPath = `${moveTomlPath}.backup.${Date.now()}`;\n\tawait fsPromises.copyFile(moveTomlPath, backupPath);\n\treturn backupPath;\n}\n\n/**\n * Restore Move.toml file from backup.\n * @param moveTomlPath Path to Move.toml file.\n * @param backupPath Path to backup file.\n */\nasync function restoreMoveToml(moveTomlPath: string, backupPath: string): Promise<void> {\n\tawait fsPromises.copyFile(backupPath, moveTomlPath);\n\tawait fsPromises.unlink(backupPath);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.moveTomlRestored\"),\n\t\tI18n.formatMessage(\"commands.deploy.messages.originalConfigurationRestored\"),\n\t\t1\n\t);\n}\n\n/**\n * Update Move.toml published-at field.\n * @param moveTomlPath Path to Move.toml file.\n * @param publishedAt Published-at value to set.\n */\nasync function updateMoveTomlPublishedAt(moveTomlPath: string, publishedAt: string): Promise<void> {\n\tconst content = await fsPromises.readFile(moveTomlPath, \"utf-8\");\n\n\t// Parse TOML and update \"published-at\" field\n\tconst lines = content.split(\"\\n\");\n\tlet updated = false;\n\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tif (lines[i].trim().startsWith(\"published-at\")) {\n\t\t\tlines[i] = `published-at = \"${publishedAt}\"`;\n\t\t\tupdated = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (!updated) {\n\t\t// Add \"published-at\" to \"[package]\" section\n\t\tconst packageSectionIndex = lines.findIndex(line => line.trim() === \"[package]\");\n\t\tif (packageSectionIndex >= 0) {\n\t\t\tlines.splice(packageSectionIndex + 1, 0, `published-at = \"${publishedAt}\"`);\n\t\t}\n\t}\n\n\tawait fsPromises.writeFile(moveTomlPath, lines.join(\"\\n\"));\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.moveTomlUpdated\"),\n\t\t`published-at = \"${publishedAt}\"`,\n\t\t1\n\t);\n}\n\n/**\n * Validate that contract has been built.\n * @param contractData Contract data to validate.\n * @param projectRoot Project root directory.\n */\nasync function validateContractIsBuilt(\n\tcontractData: IContractData,\n\tprojectRoot: string\n): Promise<void> {\n\t// Check if build directory exists and has been built\n\tconst buildDir = path.join(projectRoot, \"build\");\n\ttry {\n\t\tconst stats = await fsPromises.stat(buildDir);\n\t\tif (!stats.isDirectory()) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.buildPathNotDirectory\", {\n\t\t\t\tbuildDir\n\t\t\t});\n\t\t}\n\t} catch {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.contractNotBuilt\", {\n\t\t\tprojectRoot\n\t\t});\n\t}\n\n\t// Verify that the contract data has current packageId (build should have been run)\n\tif (!contractData.packageId || !contractData.packageBytecode) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.contractDataOutdated\");\n\t}\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.buildValidation\"),\n\t\tI18n.formatMessage(\"commands.deploy.messages.contractBuiltAndReadyForUpgrade\"),\n\t\t1\n\t);\n}\n\n/**\n * Handle contract upgrade execution.\n * @param contractName Name of the contract.\n * @param contractData Contract data.\n * @param config Network configuration.\n * @param network Target network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function handleContractUpgrade(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\tCLIDisplay.task(`Upgrading contract: ${contractName}`);\n\n\tconst walletAddress = await validateEnvironmentForNetwork(\n\t\tnetwork,\n\t\tconfig,\n\t\tfalse,\n\t\tfaucetUrl,\n\t\tdeployerMnemonic,\n\t\tdeployerSeed\n\t);\n\tawait checkWalletBalance(network, config, walletAddress, false);\n\n\tconst upgradeResult = await executeContractUpgrade(contractData, config);\n\n\t// Update contract data with upgrade chain tracking\n\tcontractData.deployedPackageId = upgradeResult.packageId;\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeSuccessful\"),\n\t\tupgradeResult.packageId,\n\t\t1\n\t);\n\tif (contractData.lastDeployedPackageId) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.previousDeployment\"),\n\t\t\tcontractData.lastDeployedPackageId,\n\t\t\t1\n\t\t);\n\t}\n\tif (contractData.upgradeCapabilityId) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeCapabilityPreserved\"),\n\t\t\tcontractData.upgradeCapabilityId,\n\t\t\t1\n\t\t);\n\t}\n}\n\n/**\n * Deploy a single contract.\n * @param contractName Name of the contract\n * @param contractData Contract compilation data\n * @param contractData.packageId Package ID\n * @param contractData.packageBytecode Package bytecode\n * @param contractData.deployedPackageId Deployed package ID\n * @param config Network configuration\n * @param network Target network\n * @param dryRun Whether this is a dry run\n * @param force Whether to force redeployment\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function deployContract(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tdryRun: boolean,\n\tforce: boolean,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.deploy.progress.deployingContract\", { contractName, network })\n\t);\n\n\tconst strategy = await determineDeploymentStrategy(contractData);\n\n\tif (strategy === \"already-deployed\" && !force) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.contractStatus\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.contractAlreadyDeployed\"),\n\t\t\t1\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeGuidance\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.upgradeGuidanceMessage\"),\n\t\t\t1\n\t\t);\n\t\treturn;\n\t}\n\n\t// Show deployment strategy\n\tCLIDisplay.section(I18n.formatMessage(\"commands.deploy.labels.smartDeployAnalysis\"));\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeCapability\"),\n\t\tcontractData.upgradeCapabilityId ??\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.noneInitialDeployment\")\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.currentDeployment\"),\n\t\tcontractData.deployedPackageId ??\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.noneNeedsDeploymentUpgrade\")\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.detectedStrategy\"), strategy);\n\n\tif (dryRun) {\n\t\tawait handleDryRunValidation(\n\t\t\tcontractName,\n\t\t\tcontractData,\n\t\t\tconfig,\n\t\t\tnetwork,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t\treturn;\n\t}\n\n\tif (strategy === \"upgrade\") {\n\t\tawait handleContractUpgrade(\n\t\t\tcontractName,\n\t\t\tcontractData,\n\t\t\tconfig,\n\t\t\tnetwork,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t} else {\n\t\tawait handleActualDeployment(\n\t\t\tcontractName,\n\t\t\tcontractData,\n\t\t\tconfig,\n\t\t\tnetwork,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t}\n}\n\n/**\n * Get wallet address for deployment, preferring seed over mnemonic if available.\n * @param network The target network.\n * @param addressIndex The address index to derive.\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n * @returns The wallet address.\n */\nasync function getDeploymentWalletAddress(\n\tnetwork: NetworkTypes,\n\taddressIndex: number,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<string> {\n\t// Try to use seed first if available\n\tconst hexSeed = await getDeploymentSeed(network, deployerSeed);\n\tlet seed: Uint8Array | undefined;\n\tif (Is.stringValue(hexSeed)) {\n\t\tseed = Converter.hexToBytes(hexSeed);\n\t} else {\n\t\tconst mnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\t\tseed = Bip39.mnemonicToSeed(mnemonic);\n\t}\n\n\tconst addresses = Iota.getAddresses(seed, Iota.DEFAULT_COIN_TYPE, 0, addressIndex, 1, false);\n\n\treturn addresses[0];\n}\n\n/**\n * Convert nanos to IOTA (1 IOTA = 1,000,000,000 nanos).\n * @param nanos Balance in nanos.\n * @returns Balance in IOTA.\n */\nfunction nanosToIota(nanos: number): number {\n\treturn nanos / 1_000_000_000;\n}\n\n/**\n * Request funds from the faucet for testnet or devnet deployment.\n * @param network The target network (testnet or devnet).\n * @param walletAddress The wallet address to fund.\n * @param rpcUrl The RPC URL for the network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @returns Promise that resolves when funding is complete.\n */\nasync function requestFaucetFunds(\n\tnetwork: NetworkTypes,\n\twalletAddress: string,\n\trpcUrl: string,\n\tfaucetUrl: string\n): Promise<void> {\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.deploy.progress.requestingFaucetFunds\", { network })\n\t);\n\n\tconst response = await requestIotaFromFaucetV0({\n\t\thost: faucetUrl,\n\t\trecipient: walletAddress\n\t});\n\n\tif (response?.error) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.fundingFailed\", undefined, response.error);\n\t}\n\n\tconst client = new IotaClient({ url: rpcUrl });\n\tconst balanceResponse = await client.getBalance({ owner: walletAddress });\n\tconst balanceInNanos = Number(balanceResponse.totalBalance);\n\n\tif (balanceInNanos > 0) {\n\t\tconst amountInIota = nanosToIota(balanceInNanos);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.faucetFundsRequested\"),\n\t\t\t`${amountInIota.toFixed(2)} IOTA`,\n\t\t\t1\n\t\t);\n\t} else {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.faucetNoFundsAdded\", { network }),\n\t\t\t2\n\t\t);\n\t}\n}\n\n/**\n * Check wallet balance and request faucet funds only if needed.\n * @param network The target network (testnet or devnet).\n * @param config Network configuration.\n * @param walletAddress The wallet address to check and potentially fund.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @returns Promise that resolves when balance check and optional funding is complete.\n */\nasync function checkBalanceAndRequestFaucetIfNeeded(\n\tnetwork: NetworkTypes,\n\tconfig: INetworkConfig,\n\twalletAddress: string,\n\tfaucetUrl?: string\n): Promise<void> {\n\t// Check current balance\n\tconst client = new IotaClient({ url: config.rpc.url });\n\tconst balanceResponse = await client.getBalance({ owner: walletAddress });\n\tconst balanceInNanos = Number(balanceResponse.totalBalance);\n\tconst requiredInNanos = config.deployment.gasBudget;\n\t// Convert to IOTA for display purposes\n\tconst balanceInIota = nanosToIota(balanceInNanos);\n\tconst requiredInIota = nanosToIota(requiredInNanos);\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.walletBalance\"),\n\t\t`${balanceInIota.toFixed(2)} IOTA`,\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.gasBudget\"),\n\t\t`${requiredInIota.toFixed(2)} IOTA`,\n\t\t1\n\t);\n\n\t// Only request faucet funds if balance is insufficient (compare in same units - nanos)\n\tif (balanceInNanos < requiredInNanos) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.insufficientBalance\", {\n\t\t\t\tcurrentBalance: balanceInIota.toFixed(2),\n\t\t\t\trequiredBalance: requiredInIota.toFixed(2)\n\t\t\t}),\n\t\t\t1\n\t\t);\n\n\t\tif (!Is.stringValue(faucetUrl)) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noFaucetConfigured\");\n\t\t}\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"commands.deploy.progress.requestingAdditionalFaucetFunds\"));\n\t\tawait requestFaucetFunds(network, walletAddress, config.rpc.url, faucetUrl);\n\n\t\t// Check balance again after faucet request\n\t\tconst updatedBalanceResponse = await client.getBalance({ owner: walletAddress });\n\t\tconst updatedBalanceInNanos = Number(updatedBalanceResponse.totalBalance);\n\t\tconst updatedBalanceInIota = nanosToIota(updatedBalanceInNanos);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.updatedWalletBalance\"),\n\t\t\t`${updatedBalanceInIota.toFixed(2)} IOTA`,\n\t\t\t1\n\t\t);\n\t} else {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.balanceCheck\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.sufficientFundsAvailable\"),\n\t\t\t1\n\t\t);\n\t}\n}\n\n/**\n * Deploy contract using IOTA CLI.\n * @param gasBudget Gas budget for deployment.\n * @returns Deployment result with package ID, upgrade cap, and migration state ID.\n */\nasync function deployWithIotaCli(\n\tgasBudget: number\n): Promise<{ packageId: string; upgradeCap?: string; migrationStateId?: string }> {\n\t// Find the Move project directory\n\tconst moveTomlPaths: string[] = [];\n\tconst cwd = process.cwd();\n\tawait searchDirectoryForMoveToml(cwd, moveTomlPaths);\n\n\tif (moveTomlPaths.length === 0) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noMoveTomlFilesFound\", {\n\t\t\tcurrentDir: cwd\n\t\t});\n\t}\n\n\t// Prioritize Move.toml in current directory, then use first found\n\tconst currentDirMoveToml = path.join(cwd, \"Move.toml\");\n\tconst selectedMoveToml = moveTomlPaths.find(p => p === currentDirMoveToml) ?? moveTomlPaths[0];\n\n\t// Use the actual Move project directory\n\tconst moveProjectRoot = path.dirname(selectedMoveToml);\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.moveProjectRoot\"),\n\t\tmoveProjectRoot,\n\t\t1\n\t);\n\n\tconst publishCmd = `iota client publish --gas-budget ${gasBudget} --json`;\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.publishCommand\"), publishCmd, 1);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.workingDirectory\"),\n\t\tmoveProjectRoot,\n\t\t1\n\t);\n\n\ttry {\n\t\tconst { stdout: output } = await execAsyncWithError(publishCmd, { cwd: moveProjectRoot });\n\t\tconst result = JSON.parse(output);\n\n\t\t// Extract package ID from published object\n\t\tconst packageId = result.objectChanges?.find(\n\t\t\t(change: { type: string; packageId?: string }) => change.type === \"published\"\n\t\t)?.packageId;\n\n\t\tif (!packageId) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.packageIdNotFound\", {\n\t\t\t\tresult\n\t\t\t});\n\t\t}\n\n\t\t// Extract UpgradeCap ID from created objects\n\t\tconst upgradeCap = result.objectChanges?.find(\n\t\t\t(change: { objectType?: string; objectId?: string }) =>\n\t\t\t\tchange.objectType === \"0x2::package::UpgradeCap\"\n\t\t)?.objectId;\n\n\t\t// Extract MigrationState ID from created objects\n\t\tconst migrationStateId = result.objectChanges?.find(\n\t\t\t(change: { objectType?: string; objectId?: string }) =>\n\t\t\t\tchange.objectType?.endsWith(\"::MigrationState\")\n\t\t)?.objectId;\n\n\t\treturn {\n\t\t\tpackageId,\n\t\t\tupgradeCap,\n\t\t\tmigrationStateId\n\t\t};\n\t} catch (err) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.deploymentFailed\", undefined, err);\n\t}\n}\n\n/**\n * Update contracts file with deployed package IDs.\n * @param contractsPath Path to contracts file.\n * @param contractsData Updated contracts data.\n */\nasync function updateContractsFile(\n\tcontractsPath: string,\n\tcontractsData: ISmartContractDeployments\n): Promise<void> {\n\ttry {\n\t\tawait CLIUtils.writeJsonFile(contractsPath, contractsData, false);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.updatedContractsFile\"),\n\t\t\tcontractsPath,\n\t\t\t1\n\t\t);\n\t} catch (err) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.contractsFileUpdateFailed\",\n\t\t\t{ contractsPath },\n\t\t\terr\n\t\t);\n\t}\n}\n\n/**\n * Generate a unique backup alias that doesn't conflict with existing keys.\n * Uses cryptographically secure random bytes to avoid conflicts.\n * @param baseAlias The original alias name.\n * @param existingKeys Array of existing keys from keystore.\n * @returns A unique backup alias name.\n */\nexport function generateUniqueBackupAlias(\n\tbaseAlias: string,\n\texistingKeys: { alias: string; iotaAddress: string }[]\n): string {\n\tconst existingAliases = new Set(existingKeys.map(key => key.alias));\n\n\t// Generate cryptographically secure random identifier\n\tconst randomSuffix = Converter.bytesToHex(RandomHelper.generate(4));\n\tconst backupAlias = `${baseAlias}-backup-${randomSuffix}`;\n\n\t// In the extremely unlikely event of collision, add timestamp\n\tif (existingAliases.has(backupAlias)) {\n\t\treturn `${baseAlias}-backup-${Date.now()}-${randomSuffix}`;\n\t}\n\n\treturn backupAlias;\n}\n\n/**\n * Ensure the correct deployer key exists in the keystore with the expected address.\n * If a conflicting alias exists, rename it and import the correct key.\n * @param network The target network.\n * @param aliasName The desired alias name (e.g., \"deployer-testnet\").\n * @param expectedAddress The expected address from the current mnemonic.\n * @param addressIndex The address index to use.\n * @param deployerMnemonic The deployer mnemonic.\n */\nexport async function ensureCorrectDeployerKey(\n\tnetwork: NetworkTypes,\n\taliasName: string,\n\texpectedAddress: string,\n\taddressIndex: number,\n\tdeployerMnemonic: string\n): Promise<void> {\n\ttry {\n\t\t// Check if the alias already exists in keystore\n\t\tconst { stdout: keysListOutput } = await execAsyncWithError(\"iota keytool list --json\");\n\t\tconst keysList = JSON.parse(keysListOutput);\n\n\t\t// Find existing key with the target alias\n\t\tconst existingKey = keysList.find(\n\t\t\t(key: { alias: string; iotaAddress: string }) => key.alias === aliasName\n\t\t);\n\n\t\tif (existingKey) {\n\t\t\t// Check if existing key has the correct address\n\t\t\tconst existingAddress = existingKey.iotaAddress;\n\n\t\t\tif (existingAddress !== expectedAddress) {\n\t\t\t\t// Conflicting alias exists with wrong mnemonic - rename it\n\t\t\t\tCLIDisplay.task(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.progress.renamingConflictingKey\", { aliasName })\n\t\t\t\t);\n\n\t\t\t\tconst backupAlias = generateUniqueBackupAlias(aliasName, keysList);\n\t\t\t\tawait execAsyncWithError(`iota keytool update-alias \"${aliasName}\" \"${backupAlias}\"`);\n\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.renamedExistingKey\"),\n\t\t\t\t\t`${aliasName} → ${backupAlias} (${existingAddress})`,\n\t\t\t\t\t1\n\t\t\t\t);\n\n\t\t\t\t// Now import the correct key with the desired alias\n\t\t\t\tawait importCorrectDeployerKey(\n\t\t\t\t\tnetwork,\n\t\t\t\t\taliasName,\n\t\t\t\t\taddressIndex,\n\t\t\t\t\texpectedAddress,\n\t\t\t\t\tdeployerMnemonic\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Existing key is correct - no action needed\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.usingExistingCorrectKey\"),\n\t\t\t\t\t`${aliasName} (${expectedAddress})`,\n\t\t\t\t\t1\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\t// No existing alias - import the key\n\t\t\tawait importCorrectDeployerKey(\n\t\t\t\tnetwork,\n\t\t\t\taliasName,\n\t\t\t\taddressIndex,\n\t\t\t\texpectedAddress,\n\t\t\t\tdeployerMnemonic\n\t\t\t);\n\t\t}\n\n\t\t// Verify the address exists in client addresses\n\t\tconst { stdout: addressListOutput } = await execAsyncWithError(\"iota client addresses --json\");\n\t\tconst addressInfo = JSON.parse(addressListOutput);\n\t\tconst addressExists: boolean = addressInfo.addresses.some(\n\t\t\t([_, addr]: [string, string]) => addr === expectedAddress\n\t\t);\n\n\t\tif (!addressExists) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.addressNotInClient\", {\n\t\t\t\texpectedAddress,\n\t\t\t\taliasName\n\t\t\t});\n\t\t}\n\t} catch (error) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.deployerKeySetupFailed\",\n\t\t\t{ network, aliasName, expectedAddress },\n\t\t\terror\n\t\t);\n\t}\n}\n\n/**\n * Import the deployer key with the correct mnemonic.\n * @param network The target network.\n * @param aliasName The alias name to use.\n * @param addressIndex The address index.\n * @param targetAddress The expected target address (avoids redundant calculation).\n * @param deployerMnemonic The deployer mnemonic.\n */\nasync function importCorrectDeployerKey(\n\tnetwork: NetworkTypes,\n\taliasName: string,\n\taddressIndex: number,\n\ttargetAddress: string,\n\tdeployerMnemonic: string\n): Promise<void> {\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.deploy.progress.importingDeployerKey\", { aliasName })\n\t);\n\n\tconst mnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\tconst derivationPath = Bip44.path(Iota.DEFAULT_COIN_TYPE, 0, false, addressIndex).toString();\n\n\tawait execAsyncWithError(\n\t\t`iota keytool import \"${mnemonic}\" ed25519 \"${derivationPath}\" --alias \"${aliasName}\"`\n\t);\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.importedDeployerKey\"),\n\t\t`${aliasName} (${targetAddress})`,\n\t\t1\n\t);\n}\n"]}
1
+ {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,KAAK,EAAE,K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AK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;IAE7F,MAAM,kBAAkB,CACvB,wBAAwB,QAAQ,cAAc,cAAc,cAAc,SAAS,GAAG,CACtF,CAAC;IAEF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC,EAChE,GAAG,SAAS,KAAK,aAAa,GAAG,EACjC,CAAC,CACD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { promises as fsPromises } from \"node:fs\";\nimport path from \"node:path\";\nimport { IotaClient } from \"@iota/iota-sdk/client\";\nimport { requestIotaFromFaucetV0 } from \"@iota/iota-sdk/faucet\";\nimport { CLIDisplay, CLIParam, CLIUtils } from \"@twin.org/cli-core\";\nimport { Coerce, Converter, GeneralError, Guards, I18n, Is, RandomHelper } from \"@twin.org/core\";\nimport { Bip39, Bip44 } from \"@twin.org/crypto\";\nimport {\n\tIota,\n\tNetworkTypes,\n\ttype IContractData,\n\ttype ISmartContractDeployments\n} from \"@twin.org/dlt-iota\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { Command } from \"commander\";\nimport type { INetworkConfig } from \"../models/INetworkConfig.js\";\nimport { cleanBuildArtifactsInPath } from \"../utils/buildArtifactUtils.js\";\nimport { ensureEnvironment, execAsyncWithError } from \"../utils/environmentUtils.js\";\nimport {\n\tgetDeploymentMnemonic,\n\tgetDeploymentSeed,\n\tvalidateDeploymentEnvironment\n} from \"../utils/envSetup.js\";\nimport { verifyIotaSDK } from \"../utils/iotaUtils.js\";\nimport { searchDirectoryForMoveToml } from \"../utils/moveToJsonUtils.js\";\n\n/**\n * Build the deploy command.\n * @param program The command program.\n */\nexport function buildCommandDeploy(program: Command): void {\n\tprogram\n\t\t.command(\"deploy\")\n\t\t.description(I18n.formatMessage(\"commands.deploy.description\"))\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.contracts.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.contracts.description\"),\n\t\t\t\"smart-contract-deployments.json\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.dryRun.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.dryRun.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.force.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.force.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcUrl.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcUrl.description\"),\n\t\t\t\"!RPC_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.addressIndex.description\"),\n\t\t\t\"!ADDRESS_INDEX\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcTimeout.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.rpcTimeout.description\"),\n\t\t\t\"!RPC_TIMEOUT\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.gasBudget.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.gasBudget.description\"),\n\t\t\t\"!GAS_BUDGET\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.confirmationTimeout.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.confirmationTimeout.description\"),\n\t\t\t\"!CONFIRMATION_TIMEOUT\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.faucetUrl.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.faucetUrl.description\"),\n\t\t\t\"!FAUCET_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerMnemonic.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerMnemonic.description\"),\n\t\t\t\"!DEPLOYER_MNEMONIC\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerSeed.param\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.options.deployerSeed.description\"),\n\t\t\t\"!DEPLOYER_SEED\"\n\t\t)\n\t\t.action(actionCommandDeploy);\n}\n\n/**\n * Action for the deploy command.\n * @param opts Command options.\n * @param opts.contracts Path to compiled modules JSON.\n * @param opts.network Network identifier - optional if NETWORK env var is set.\n * @param opts.dryRun Simulate deployment without executing.\n * @param opts.force Force redeployment of existing packages.\n * @param opts.rpcUrl RPC endpoint URL for the network.\n * @param opts.addressIndex Address index for key derivation.\n * @param opts.rpcTimeout RPC request timeout in milliseconds.\n * @param opts.gasBudget Gas budget for transactions.\n * @param opts.confirmationTimeout Transaction confirmation timeout in milliseconds.\n * @param opts.faucetUrl Faucet URL for requesting test tokens.\n * @param opts.deployerMnemonic Deployer wallet mnemonic phrase.\n * @param opts.deployerSeed Deployer wallet seed (alternative to mnemonic).\n */\nexport async function actionCommandDeploy(opts: {\n\tcontracts?: string;\n\tnetwork?: NetworkTypes;\n\tdryRun?: boolean;\n\tforce?: boolean;\n\trpcUrl?: string;\n\taddressIndex?: string;\n\trpcTimeout?: string;\n\tgasBudget?: string;\n\tconfirmationTimeout?: string;\n\tfaucetUrl?: string;\n\tdeployerMnemonic?: string;\n\tdeployerSeed?: string;\n}): Promise<void> {\n\tconst network = CLIParam.arrayOneOf<NetworkTypes>(\n\t\t\"network\",\n\t\topts.network,\n\t\tObject.values(NetworkTypes),\n\t\ttrue\n\t);\n\n\tconst contractsPath = opts.contracts ?? \"smart-contract-deployments.json\";\n\tconst dryRun = opts.dryRun ?? false;\n\tconst force = opts.force ?? false;\n\n\tCLIDisplay.section(I18n.formatMessage(\"commands.deploy.section.deployContracts\"));\n\tCLIDisplay.section(contractsPath);\n\n\t// Verify the IOTA SDK before we do anything else\n\tawait verifyIotaSDK();\n\n\t// Get configuration values needed for environment setup\n\tconst rpcUrl: string = CLIParam.stringValue(\"rpcUrl\", opts.rpcUrl);\n\tconst addressIndex = CLIParam.number(\"addressIndex\", opts.addressIndex) ?? 0;\n\tconst rpcTimeout = CLIParam.number(\"rpcTimeout\", opts.rpcTimeout);\n\tconst gasBudget = CLIParam.number(\"gasBudget\", opts.gasBudget);\n\tconst confirmationTimeout = CLIParam.number(\"confirmationTimeout\", opts.confirmationTimeout);\n\tconst faucetUrl: string | undefined =\n\t\tnetwork === NetworkTypes.Mainnet\n\t\t\t? undefined\n\t\t\t: CLIParam.stringValue(\"faucetUrl\", opts.faucetUrl);\n\n\tlet deployerMnemonic: string | undefined;\n\ttry {\n\t\tdeployerMnemonic = CLIParam.stringValue(\"deployerMnemonic\", opts.deployerMnemonic);\n\t} catch {\n\t\t// Optional parameter, can be undefined\n\t\tdeployerMnemonic = undefined;\n\t}\n\n\tlet deployerSeed: string | undefined;\n\ttry {\n\t\tdeployerSeed = CLIParam.stringValue(\"deployerSeed\", opts.deployerSeed);\n\t} catch {\n\t\t// Optional parameter, can be undefined\n\t\tdeployerSeed = undefined;\n\t}\n\n\t// Validate that at least one deployer credential is provided\n\tconst hasValidMnemonic = Is.stringValue(deployerMnemonic);\n\tconst hasValidSeed = Is.stringValue(deployerSeed);\n\n\tif (!hasValidMnemonic && !hasValidSeed) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.deployerCredentialRequired\", {\n\t\t\tnetwork\n\t\t});\n\t}\n\n\t// Check/switch to target network environment BEFORE loading config\n\tawait setIotaEnvironment(network, rpcUrl, addressIndex, dryRun, deployerMnemonic, deployerSeed);\n\n\tconst config = await createNetworkConfig(\n\t\tnetwork,\n\t\trpcUrl,\n\t\taddressIndex,\n\t\trpcTimeout,\n\t\tgasBudget,\n\t\tconfirmationTimeout\n\t);\n\tvalidateNetworkConfig(config, network);\n\n\tconst contractsData = await loadCompiledContracts(contractsPath);\n\n\tif (network === NetworkTypes.Mainnet) {\n\t\tconst validatedMnemonic = await getDeploymentMnemonic(\n\t\t\tnetwork,\n\t\t\thasValidMnemonic ? deployerMnemonic : undefined\n\t\t);\n\t\tawait validateDeploymentEnvironment(network, validatedMnemonic);\n\t}\n\n\tconst networkContracts = contractsData[network];\n\tif (!Is.object<IContractData>(networkContracts)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noContractsFound\", {\n\t\t\tnetwork,\n\t\t\tcontractsPath\n\t\t});\n\t}\n\n\tawait deployContract(\n\t\t\"contract\",\n\t\tnetworkContracts,\n\t\tconfig,\n\t\tnetwork,\n\t\tdryRun,\n\t\tforce,\n\t\tfaucetUrl,\n\t\tdeployerMnemonic,\n\t\tdeployerSeed\n\t);\n\n\tif (!dryRun) {\n\t\tawait updateContractsFile(contractsPath, contractsData);\n\t}\n\n\tCLIDisplay.done();\n}\n\n/**\n * Switch IOTA CLI to the target network environment and set the active address.\n * @param network Target network to switch to\n * @param rpcUrl The RPC URL for the network\n * @param addressIndex The address index to derive the target address\n * @param dryRun Whether this is a dry run (checks environment but doesn't switch)\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function setIotaEnvironment(\n\tnetwork: NetworkTypes,\n\trpcUrl: string,\n\taddressIndex: number,\n\tdryRun: boolean = false,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\ttry {\n\t\tCLIDisplay.task(\n\t\t\tdryRun\n\t\t\t\t? I18n.formatMessage(\"commands.deploy.progress.checkingEnvironment\")\n\t\t\t\t: I18n.formatMessage(\"commands.deploy.progress.settingEnvironment\")\n\t\t);\n\n\t\t// Ensure environment exists, create if necessary\n\t\tGuards.stringValue(\"setIotaEnvironment\", nameof(rpcUrl), rpcUrl);\n\n\t\tawait ensureEnvironment(network, rpcUrl);\n\n\t\tif (dryRun) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.iotaEnvironmentCheck\"),\n\t\t\t\t`✅ ${network} environment exists`,\n\t\t\t\t1\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// Derive the target address from existing mnemonic/seed\n\t\tconst targetAddress = await getDeploymentWalletAddress(\n\t\t\tnetwork,\n\t\t\taddressIndex,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\n\t\t// Ensure the correct deployer key exists in the keystore\n\t\tconst aliasName = `deployer-${network}`;\n\t\tconst validatedMnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\t\tawait ensureCorrectDeployerKey(\n\t\t\tnetwork,\n\t\t\taliasName,\n\t\t\ttargetAddress,\n\t\t\taddressIndex,\n\t\t\tvalidatedMnemonic\n\t\t);\n\n\t\t// Switch both environment and address in one command\n\t\tawait execAsyncWithError(`iota client switch --env ${network} --address ${targetAddress}`);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.switchedIotaEnvironment\"),\n\t\t\tnetwork,\n\t\t\t1\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.switchedActiveAddress\"),\n\t\t\ttargetAddress,\n\t\t\t1\n\t\t);\n\n\t\t// Verify the switch was successful\n\t\tconst { stdout: activeEnv } = await execAsyncWithError(\"iota client active-env\");\n\t\tif (!activeEnv.includes(network)) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.environmentSwitchFailed\", {\n\t\t\t\tnetwork,\n\t\t\t\tactiveEnv\n\t\t\t});\n\t\t}\n\n\t\t// Verify address switch was successful\n\t\tconst { stdout: activeAddressOutput } = await execAsyncWithError(\"iota client active-address\");\n\t\tconst activeAddress = activeAddressOutput.trim();\n\t\tif (activeAddress !== targetAddress) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.addressSwitchFailed\", {\n\t\t\t\tnetwork,\n\t\t\t\ttargetAddress,\n\t\t\t\tactiveAddress\n\t\t\t});\n\t\t}\n\t} catch (error) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.environmentOperationFailed\",\n\t\t\t{ network, operation: dryRun ? \"check\" : \"switch to\" },\n\t\t\terror\n\t\t);\n\t}\n}\n\n/**\n * Creates the network configuration.\n * @param network Target network to determine which env file to load.\n * @param rpcUrl The RPC URL for the network.\n * @param addressIndex The address index for the wallet.\n * @param rpcTimeout The RPC timeout in milliseconds.\n * @param gasBudget The gas budget for deployment.\n * @param confirmationTimeout The confirmation timeout in seconds.\n * @returns Network configuration.\n */\nasync function createNetworkConfig(\n\tnetwork: NetworkTypes,\n\trpcUrl: string,\n\taddressIndex: number,\n\trpcTimeout?: number,\n\tgasBudget?: number,\n\tconfirmationTimeout?: number\n): Promise<INetworkConfig> {\n\ttry {\n\t\tGuards.stringValue(\"createNetworkConfig\", nameof(rpcUrl), rpcUrl);\n\n\t\tconst config: INetworkConfig = {\n\t\t\tnetwork,\n\t\t\tplatform: \"iota\",\n\t\t\trpc: {\n\t\t\t\turl: rpcUrl,\n\t\t\t\ttimeout: rpcTimeout ?? 60000\n\t\t\t},\n\t\t\tdeployment: {\n\t\t\t\tgasBudget: gasBudget ?? 50000000,\n\t\t\t\tconfirmationTimeout: confirmationTimeout ?? 60,\n\t\t\t\twallet: {\n\t\t\t\t\taddressIndex\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\treturn config;\n\t} catch (err) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.networkConfigInvalid\", { network }, err);\n\t}\n}\n\n/**\n * Validate network configuration matches expected network.\n * @param config Network configuration.\n * @param expectedNetwork Expected network type.\n * @throws GeneralError if the network configuration is invalid.\n */\nfunction validateNetworkConfig(config: INetworkConfig, expectedNetwork: NetworkTypes): void {\n\tif (config.network !== expectedNetwork) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.networkMismatch\", {\n\t\t\texpected: expectedNetwork,\n\t\t\tactual: config.network,\n\t\t\thelp: `Configuration file specifies '${config.network}' but command targets '${expectedNetwork}'`\n\t\t});\n\t}\n\n\tif (!Is.stringValue(config.rpc?.url)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.rpcUrlRequired\", {\n\t\t\tnetwork: expectedNetwork\n\t\t});\n\t}\n\n\tif (!Is.number(config.deployment?.gasBudget)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.gasBudgetRequired\", {\n\t\t\tnetwork: expectedNetwork\n\t\t});\n\t}\n}\n\n/**\n * Load compiled contracts from file.\n * @param contractsPath Path to contracts file.\n * @returns Compiled contracts data.\n */\nasync function loadCompiledContracts(contractsPath: string): Promise<ISmartContractDeployments> {\n\ttry {\n\t\tif (!(await CLIUtils.fileExists(contractsPath))) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.contractsFileNotFound\", {\n\t\t\t\tcontractsPath\n\t\t\t});\n\t\t}\n\n\t\tconst contracts = await CLIUtils.readJsonFile<ISmartContractDeployments>(contractsPath);\n\n\t\tif (!Is.object(contracts)) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.invalidContractsFile\");\n\t\t}\n\n\t\treturn contracts;\n\t} catch (err) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.contractsLoadFailed\",\n\t\t\t{ contractsPath },\n\t\t\terr\n\t\t);\n\t}\n}\n\n/**\n * Validate environment and setup for deployment based on network type.\n * @param network Target network.\n * @param config Network configuration.\n * @param isDryRun Whether this is a dry run.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic for validation.\n * @param deployerSeed The deployer seed (optional).\n * @returns Wallet address for the deployment.\n */\nasync function validateEnvironmentForNetwork(\n\tnetwork: NetworkTypes,\n\tconfig: INetworkConfig,\n\tisDryRun: boolean = false,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<string> {\n\tconst walletAddress = await getDeploymentWalletAddress(\n\t\tnetwork,\n\t\tconfig.deployment.wallet.addressIndex,\n\t\tdeployerMnemonic,\n\t\tdeployerSeed\n\t);\n\n\tif (isDryRun) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.dryRunWalletAddress\"),\n\t\t\twalletAddress,\n\t\t\t1\n\t\t);\n\t} else {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.walletAddress\"), walletAddress, 1);\n\t}\n\n\tif (network === NetworkTypes.Mainnet) {\n\t\tconst validatedMnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\t\tawait validateDeploymentEnvironment(network, validatedMnemonic);\n\t} else if ((network === NetworkTypes.Testnet || network === NetworkTypes.Devnet) && !isDryRun) {\n\t\t// For testnet/devnet, check balance first and only request funds if needed\n\t\tawait checkBalanceAndRequestFaucetIfNeeded(network, config, walletAddress, faucetUrl);\n\t}\n\n\treturn walletAddress;\n}\n\n/**\n * Check wallet balance and display relevant information.\n * @param network Target network.\n * @param config Network configuration.\n * @param walletAddress Wallet address.\n * @param isDryRun Whether this is a dry run.\n * @returns Balance in nanos.\n */\nasync function checkWalletBalance(\n\tnetwork: NetworkTypes,\n\tconfig: INetworkConfig,\n\twalletAddress: string,\n\tisDryRun: boolean = false\n): Promise<number> {\n\tconst client = new IotaClient({ url: config.rpc.url });\n\tconst balanceResponse = await client.getBalance({ owner: walletAddress });\n\tconst balanceInNanos = Number(balanceResponse.totalBalance);\n\tconst requiredInNanos = config.deployment.gasBudget;\n\n\tconst balanceInIota = nanosToIota(balanceInNanos);\n\tconst requiredInIota = nanosToIota(requiredInNanos);\n\n\tconst balanceLabel = isDryRun\n\t\t? \"commands.deploy.labels.dryRunWalletBalance\"\n\t\t: \"commands.deploy.labels.walletBalance\";\n\tconst gasBudgetLabel = isDryRun\n\t\t? \"commands.deploy.labels.dryRunGasBudget\"\n\t\t: \"commands.deploy.labels.gasBudget\";\n\n\tCLIDisplay.value(I18n.formatMessage(balanceLabel), `${balanceInIota.toFixed(2)} IOTA`, 1);\n\tCLIDisplay.value(I18n.formatMessage(gasBudgetLabel), `${requiredInIota.toFixed(2)} IOTA`, 1);\n\n\t// Handle insufficient balance based on network and run type (compare in same units - nanos)\n\tif (balanceInNanos < requiredInNanos) {\n\t\tif (isDryRun) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.insufficientBalanceWarning\", {\n\t\t\t\t\tcurrentBalance: balanceInIota.toFixed(2),\n\t\t\t\t\trequiredBalance: requiredInIota.toFixed(2)\n\t\t\t\t}),\n\t\t\t\t2\n\t\t\t);\n\t\t} else if (network === NetworkTypes.Mainnet) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.insufficientBalance\", {\n\t\t\t\tbalance: balanceInIota,\n\t\t\t\trequired: requiredInIota,\n\t\t\t\twalletAddress\n\t\t\t});\n\t\t} else {\n\t\t\t// For testnet/devnet, show warning but continue\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.insufficientBalanceAfterFaucet\", {\n\t\t\t\t\tnetwork,\n\t\t\t\t\tbalance: balanceInIota.toFixed(2),\n\t\t\t\t\trequired: requiredInIota.toFixed(2),\n\t\t\t\t\twalletAddress\n\t\t\t\t}),\n\t\t\t\t2\n\t\t\t);\n\t\t}\n\t}\n\n\treturn balanceInNanos;\n}\n\n/**\n * Handle dry run validation and display.\n * @param contractName Name of the contract.\n * @param contractData Contract data.\n * @param config Network configuration.\n * @param network Target network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function handleDryRunValidation(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.dryRunWouldDeploy\"),\n\t\t`${contractName} (${network})`,\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.dryRunPackageId\"),\n\t\tcontractData.packageId,\n\t\t1\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.dryRunRpcUrl\"), config.rpc.url, 1);\n\n\ttry {\n\t\tconst walletAddress = await validateEnvironmentForNetwork(\n\t\t\tnetwork,\n\t\t\tconfig,\n\t\t\ttrue,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t\tawait checkWalletBalance(network, config, walletAddress, true);\n\t} catch (err) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.environmentValidationWarning\", {\n\t\t\t\tmessage: (err as Error).message\n\t\t\t}),\n\t\t\t2\n\t\t);\n\t}\n}\n\n/**\n * Handle actual deployment execution.\n * @param contractName Name of the contract.\n * @param contractData Contract data.\n * @param config Network configuration.\n * @param network Target network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function handleActualDeployment(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\ttry {\n\t\tconst walletAddress = await validateEnvironmentForNetwork(\n\t\t\tnetwork,\n\t\t\tconfig,\n\t\t\tfalse,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t\tawait checkWalletBalance(network, config, walletAddress, false);\n\n\t\tconst deploymentResult = await deployWithIotaCli(config.deployment.gasBudget);\n\n\t\tcontractData.deployedPackageId = deploymentResult.packageId;\n\t\tcontractData.upgradeCapabilityId = deploymentResult.upgradeCap;\n\n\t\tif (deploymentResult.migrationStateId) {\n\t\t\tcontractData.migrationStateId = deploymentResult.migrationStateId;\n\t\t}\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.deployedPackageIdResult\"),\n\t\t\tdeploymentResult.packageId,\n\t\t\t1\n\t\t);\n\t\tif (deploymentResult.upgradeCap) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeCapabilityIdResult\"),\n\t\t\t\tdeploymentResult.upgradeCap,\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t\tif (contractData.migrationStateId) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.migrationStateIdResult\"),\n\t\t\t\tcontractData.migrationStateId,\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t} catch (err) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.deploymentFailed\",\n\t\t\t{ contract: contractName },\n\t\t\terr\n\t\t);\n\t}\n}\n\n/**\n * Determine the deployment strategy based on contract state.\n * @param contractData Contract data to analyze.\n * @returns Deployment strategy: initial-deploy, upgrade or already-deployed.\n */\nasync function determineDeploymentStrategy(\n\tcontractData: IContractData\n): Promise<\"initial-deploy\" | \"upgrade\" | \"already-deployed\"> {\n\tif (Is.stringValue(contractData.deployedPackageId)) {\n\t\treturn \"already-deployed\";\n\t}\n\n\tif (Is.stringValue(contractData.lastDeployedPackageId)) {\n\t\treturn \"upgrade\";\n\t}\n\n\treturn \"initial-deploy\";\n}\n\n/**\n * Query the on-chain UpgradeCap object to get the actual latest package ID.\n * This is used to validate/correct the `published-at` value before upgrades,\n * preventing failures when the deployment JSON is stale.\n * @param rpcUrl RPC endpoint URL for the network.\n * @param upgradeCapabilityId The UpgradeCap object ID on-chain.\n * @returns The on-chain package ID and version, or undefined if query fails.\n */\nasync function queryUpgradeCapPackage(\n\trpcUrl: string,\n\tupgradeCapabilityId: string\n): Promise<{ package: string; version: number } | undefined> {\n\ttry {\n\t\tconst client = new IotaClient({ url: rpcUrl });\n\t\tconst response = await client.getObject({\n\t\t\tid: upgradeCapabilityId,\n\t\t\toptions: { showContent: true }\n\t\t});\n\n\t\tif (response.data?.content?.dataType === \"moveObject\") {\n\t\t\tconst fields = response.data.content.fields as { [key: string]: unknown };\n\t\t\tconst fieldPackage = Coerce.string(fields.package);\n\t\t\tconst fieldVersion = Coerce.number(fields.version);\n\t\t\tif (Is.stringValue(fieldPackage) && Is.number(fieldVersion)) {\n\t\t\t\treturn {\n\t\t\t\t\tpackage: fieldPackage,\n\t\t\t\t\tversion: fieldVersion\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\t// If query fails (e.g. network issue), return undefined to fall back to JSON value\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Execute contract upgrade using iota client upgrade command.\n * @param contractData Contract data containing upgrade capability.\n * @param config Network configuration.\n * @returns Upgrade result with package ID and upgrade capability.\n */\nasync function executeContractUpgrade(\n\tcontractData: IContractData,\n\tconfig: INetworkConfig\n): Promise<{ packageId: string; upgradeCap: string; migrationStateId?: string }> {\n\t// Start with lastDeployedPackageId from JSON as the candidate for \"published-at\"\n\tlet publishedAtPackageId = contractData.lastDeployedPackageId;\n\n\t// Query the on-chain UpgradeCap to get the actual latest package ID.\n\t// This prevents failures when the JSON is stale\n\tif (Is.stringValue(contractData.upgradeCapabilityId)) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"commands.deploy.progress.queryingUpgradeCap\"));\n\t\tconst onChainCap = await queryUpgradeCapPackage(\n\t\t\tconfig.rpc.url,\n\t\t\tcontractData.upgradeCapabilityId\n\t\t);\n\t\tif (onChainCap) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.onChainPackageId\"),\n\t\t\t\tonChainCap.package,\n\t\t\t\t1\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.onChainVersion\"),\n\t\t\t\tString(onChainCap.version),\n\t\t\t\t1\n\t\t\t);\n\n\t\t\tif (publishedAtPackageId !== onChainCap.package) {\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.messages.staleJsonDetected\", {\n\t\t\t\t\t\tjsonPackageId: publishedAtPackageId ?? \"none\",\n\t\t\t\t\t\tonChainPackageId: onChainCap.package\n\t\t\t\t\t}),\n\t\t\t\t\t2\n\t\t\t\t);\n\t\t\t\tpublishedAtPackageId = onChainCap.package;\n\t\t\t\tcontractData.lastDeployedPackageId = onChainCap.package;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!publishedAtPackageId) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noPreviousDeploymentForUpgrade\");\n\t}\n\n\tconst moveTomlPaths: string[] = [];\n\tawait searchDirectoryForMoveToml(process.cwd(), moveTomlPaths);\n\n\tif (moveTomlPaths.length === 0) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noMoveTomlFilesFound\", {\n\t\t\tcurrentDir: process.cwd()\n\t\t});\n\t}\n\n\tconst currentDirMoveToml = path.join(process.cwd(), \"Move.toml\");\n\tconst selectedMoveToml = moveTomlPaths.find(p => p === currentDirMoveToml) ?? moveTomlPaths[0];\n\tconst moveTomlPath = selectedMoveToml;\n\tconst projectRoot = path.dirname(moveTomlPath);\n\n\tconst backupPath = await backupMoveToml(moveTomlPath);\n\n\ttry {\n\t\t// Update Move.toml with \"published-at\" = validated package ID (from chain or JSON)\n\t\tawait updateMoveTomlPublishedAt(moveTomlPath, publishedAtPackageId);\n\n\t\tawait validateContractIsBuilt(contractData, projectRoot);\n\n\t\t// Execute upgrade command\n\t\tconst upgradeCapabilityId = contractData.upgradeCapabilityId;\n\t\tif (!upgradeCapabilityId) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.upgradeCapabilityNotFound\");\n\t\t}\n\t\tconst upgradeResult = await executeUpgradeWithIotaCli(\n\t\t\tupgradeCapabilityId,\n\t\t\tconfig.deployment.gasBudget,\n\t\t\tprojectRoot\n\t\t);\n\n\t\t// Update contract data with new package ID\n\t\tcontractData.deployedPackageId = upgradeResult.packageId;\n\n\t\treturn upgradeResult;\n\t} finally {\n\t\t// Always restore original Move.toml\n\t\tawait restoreMoveToml(moveTomlPath, backupPath);\n\t}\n}\n\n/**\n * Execute upgrade using iota client upgrade command.\n * @param upgradeCapabilityId Upgrade capability ID.\n * @param gasBudget Gas budget for upgrade.\n * @param moveProjectRoot Move project root directory.\n * @returns Upgrade result.\n */\nasync function executeUpgradeWithIotaCli(\n\tupgradeCapabilityId: string,\n\tgasBudget: number,\n\tmoveProjectRoot: string\n): Promise<{ packageId: string; upgradeCap: string; migrationStateId?: string }> {\n\t// Clean build artifacts and lock files before upgrade to prevent permission issues\n\tawait cleanBuildArtifactsInPath(moveProjectRoot);\n\n\tconst upgradeCmd = `iota client upgrade --upgrade-capability ${upgradeCapabilityId} . --gas-budget ${gasBudget} --json`;\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.publishCommand\"), upgradeCmd, 1);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.workingDirectory\"),\n\t\tmoveProjectRoot,\n\t\t1\n\t);\n\n\ttry {\n\t\tconst { stdout: output } = await execAsyncWithError(upgradeCmd, {\n\t\t\tcwd: moveProjectRoot\n\t\t});\n\t\tconst result = JSON.parse(output);\n\n\t\t// Parse upgrade response (different from publish response)\n\t\tconst packageId = result.objectChanges?.find(\n\t\t\t(change: { type: string; packageId?: string }) => change.type === \"published\"\n\t\t)?.packageId;\n\n\t\tif (!packageId) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.upgradePackageIdNotFound\", { result });\n\t\t}\n\n\t\t// UpgradeCap persists with same ID\n\t\tconst upgradeCap = upgradeCapabilityId;\n\n\t\treturn { packageId, upgradeCap };\n\t} catch (err) {\n\t\t// Clean up on error too\n\t\tawait cleanBuildArtifactsInPath(moveProjectRoot);\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.upgradeFailed\", undefined, err);\n\t}\n}\n\n/**\n * Backup Move.toml file.\n * @param moveTomlPath Path to Move.toml file.\n * @returns Path to backup file.\n */\nasync function backupMoveToml(moveTomlPath: string): Promise<string> {\n\tconst backupPath = `${moveTomlPath}.backup.${Date.now()}`;\n\tawait fsPromises.copyFile(moveTomlPath, backupPath);\n\treturn backupPath;\n}\n\n/**\n * Restore Move.toml file from backup.\n * @param moveTomlPath Path to Move.toml file.\n * @param backupPath Path to backup file.\n */\nasync function restoreMoveToml(moveTomlPath: string, backupPath: string): Promise<void> {\n\tawait fsPromises.copyFile(backupPath, moveTomlPath);\n\tawait fsPromises.unlink(backupPath);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.moveTomlRestored\"),\n\t\tI18n.formatMessage(\"commands.deploy.messages.originalConfigurationRestored\"),\n\t\t1\n\t);\n}\n\n/**\n * Update Move.toml published-at field.\n * @param moveTomlPath Path to Move.toml file.\n * @param publishedAt Published-at value to set.\n */\nasync function updateMoveTomlPublishedAt(moveTomlPath: string, publishedAt: string): Promise<void> {\n\tconst content = await fsPromises.readFile(moveTomlPath, \"utf-8\");\n\n\t// Parse TOML and update \"published-at\" field\n\tconst lines = content.split(\"\\n\");\n\tlet updated = false;\n\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tif (lines[i].trim().startsWith(\"published-at\")) {\n\t\t\tlines[i] = `published-at = \"${publishedAt}\"`;\n\t\t\tupdated = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (!updated) {\n\t\t// Add \"published-at\" to \"[package]\" section\n\t\tconst packageSectionIndex = lines.findIndex(line => line.trim() === \"[package]\");\n\t\tif (packageSectionIndex >= 0) {\n\t\t\tlines.splice(packageSectionIndex + 1, 0, `published-at = \"${publishedAt}\"`);\n\t\t}\n\t}\n\n\tawait fsPromises.writeFile(moveTomlPath, lines.join(\"\\n\"));\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.moveTomlUpdated\"),\n\t\t`published-at = \"${publishedAt}\"`,\n\t\t1\n\t);\n}\n\n/**\n * Validate that contract has been built.\n * @param contractData Contract data to validate.\n * @param projectRoot Project root directory.\n */\nasync function validateContractIsBuilt(\n\tcontractData: IContractData,\n\tprojectRoot: string\n): Promise<void> {\n\t// Check if build directory exists and has been built\n\tconst buildDir = path.join(projectRoot, \"build\");\n\ttry {\n\t\tconst stats = await fsPromises.stat(buildDir);\n\t\tif (!stats.isDirectory()) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.buildPathNotDirectory\", {\n\t\t\t\tbuildDir\n\t\t\t});\n\t\t}\n\t} catch {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.contractNotBuilt\", {\n\t\t\tprojectRoot\n\t\t});\n\t}\n\n\t// Verify that the contract data has current packageId (build should have been run)\n\tif (!contractData.packageId || !contractData.packageBytecode) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.contractDataOutdated\");\n\t}\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.buildValidation\"),\n\t\tI18n.formatMessage(\"commands.deploy.messages.contractBuiltAndReadyForUpgrade\"),\n\t\t1\n\t);\n}\n\n/**\n * Handle contract upgrade execution.\n * @param contractName Name of the contract.\n * @param contractData Contract data.\n * @param config Network configuration.\n * @param network Target network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function handleContractUpgrade(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\tCLIDisplay.task(`Upgrading contract: ${contractName}`);\n\n\tconst walletAddress = await validateEnvironmentForNetwork(\n\t\tnetwork,\n\t\tconfig,\n\t\tfalse,\n\t\tfaucetUrl,\n\t\tdeployerMnemonic,\n\t\tdeployerSeed\n\t);\n\tawait checkWalletBalance(network, config, walletAddress, false);\n\n\tconst upgradeResult = await executeContractUpgrade(contractData, config);\n\n\t// Update contract data with upgrade chain tracking\n\tcontractData.deployedPackageId = upgradeResult.packageId;\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeSuccessful\"),\n\t\tupgradeResult.packageId,\n\t\t1\n\t);\n\tif (contractData.lastDeployedPackageId) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.previousDeployment\"),\n\t\t\tcontractData.lastDeployedPackageId,\n\t\t\t1\n\t\t);\n\t}\n\tif (contractData.upgradeCapabilityId) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeCapabilityPreserved\"),\n\t\t\tcontractData.upgradeCapabilityId,\n\t\t\t1\n\t\t);\n\t}\n}\n\n/**\n * Deploy a single contract.\n * @param contractName Name of the contract\n * @param contractData Contract compilation data\n * @param contractData.packageId Package ID\n * @param contractData.packageBytecode Package bytecode\n * @param contractData.deployedPackageId Deployed package ID\n * @param config Network configuration\n * @param network Target network\n * @param dryRun Whether this is a dry run\n * @param force Whether to force redeployment\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n */\nasync function deployContract(\n\tcontractName: string,\n\tcontractData: IContractData,\n\tconfig: INetworkConfig,\n\tnetwork: NetworkTypes,\n\tdryRun: boolean,\n\tforce: boolean,\n\tfaucetUrl?: string,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<void> {\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.deploy.progress.deployingContract\", { contractName, network })\n\t);\n\n\tconst strategy = await determineDeploymentStrategy(contractData);\n\n\tif (strategy === \"already-deployed\" && !force) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.contractStatus\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.contractAlreadyDeployed\"),\n\t\t\t1\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeGuidance\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.upgradeGuidanceMessage\"),\n\t\t\t1\n\t\t);\n\t\treturn;\n\t}\n\n\t// Show deployment strategy\n\tCLIDisplay.section(I18n.formatMessage(\"commands.deploy.labels.smartDeployAnalysis\"));\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.upgradeCapability\"),\n\t\tcontractData.upgradeCapabilityId ??\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.noneInitialDeployment\")\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.currentDeployment\"),\n\t\tcontractData.deployedPackageId ??\n\t\t\tI18n.formatMessage(\"commands.deploy.messages.noneNeedsDeploymentUpgrade\")\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.detectedStrategy\"), strategy);\n\n\tif (dryRun) {\n\t\tawait handleDryRunValidation(\n\t\t\tcontractName,\n\t\t\tcontractData,\n\t\t\tconfig,\n\t\t\tnetwork,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t\treturn;\n\t}\n\n\tif (strategy === \"upgrade\") {\n\t\tawait handleContractUpgrade(\n\t\t\tcontractName,\n\t\t\tcontractData,\n\t\t\tconfig,\n\t\t\tnetwork,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t} else {\n\t\tawait handleActualDeployment(\n\t\t\tcontractName,\n\t\t\tcontractData,\n\t\t\tconfig,\n\t\t\tnetwork,\n\t\t\tfaucetUrl,\n\t\t\tdeployerMnemonic,\n\t\t\tdeployerSeed\n\t\t);\n\t}\n}\n\n/**\n * Get wallet address for deployment, preferring seed over mnemonic if available.\n * @param network The target network.\n * @param addressIndex The address index to derive.\n * @param deployerMnemonic The deployer mnemonic from environment variables.\n * @param deployerSeed The deployer seed from environment variables (optional).\n * @returns The wallet address.\n */\nasync function getDeploymentWalletAddress(\n\tnetwork: NetworkTypes,\n\taddressIndex: number,\n\tdeployerMnemonic?: string,\n\tdeployerSeed?: string\n): Promise<string> {\n\t// Try to use seed first if available\n\tconst hexSeed = await getDeploymentSeed(network, deployerSeed);\n\tlet seed: Uint8Array | undefined;\n\tif (Is.stringValue(hexSeed)) {\n\t\tseed = Converter.hexToBytes(hexSeed);\n\t} else {\n\t\tconst mnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\t\tseed = Bip39.mnemonicToSeed(mnemonic);\n\t}\n\n\tconst addresses = Iota.getAddresses(seed, Iota.DEFAULT_COIN_TYPE, 0, addressIndex, 1, false);\n\n\treturn addresses[0];\n}\n\n/**\n * Convert nanos to IOTA (1 IOTA = 1,000,000,000 nanos).\n * @param nanos Balance in nanos.\n * @returns Balance in IOTA.\n */\nfunction nanosToIota(nanos: number): number {\n\treturn nanos / 1_000_000_000;\n}\n\n/**\n * Request funds from the faucet for testnet or devnet deployment.\n * @param network The target network (testnet or devnet).\n * @param walletAddress The wallet address to fund.\n * @param rpcUrl The RPC URL for the network.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @returns Promise that resolves when funding is complete.\n */\nasync function requestFaucetFunds(\n\tnetwork: NetworkTypes,\n\twalletAddress: string,\n\trpcUrl: string,\n\tfaucetUrl: string\n): Promise<void> {\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.deploy.progress.requestingFaucetFunds\", { network })\n\t);\n\n\tconst response = await requestIotaFromFaucetV0({\n\t\thost: faucetUrl,\n\t\trecipient: walletAddress\n\t});\n\n\tif (response?.error) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.fundingFailed\", undefined, response.error);\n\t}\n\n\tconst client = new IotaClient({ url: rpcUrl });\n\tconst balanceResponse = await client.getBalance({ owner: walletAddress });\n\tconst balanceInNanos = Number(balanceResponse.totalBalance);\n\n\tif (balanceInNanos > 0) {\n\t\tconst amountInIota = nanosToIota(balanceInNanos);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.faucetFundsRequested\"),\n\t\t\t`${amountInIota.toFixed(2)} IOTA`,\n\t\t\t1\n\t\t);\n\t} else {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.faucetNoFundsAdded\", { network }),\n\t\t\t2\n\t\t);\n\t}\n}\n\n/**\n * Check wallet balance and request faucet funds only if needed.\n * @param network The target network (testnet or devnet).\n * @param config Network configuration.\n * @param walletAddress The wallet address to check and potentially fund.\n * @param faucetUrl The faucet URL (optional, defaults to network-specific URL).\n * @returns Promise that resolves when balance check and optional funding is complete.\n */\nasync function checkBalanceAndRequestFaucetIfNeeded(\n\tnetwork: NetworkTypes,\n\tconfig: INetworkConfig,\n\twalletAddress: string,\n\tfaucetUrl?: string\n): Promise<void> {\n\t// Check current balance\n\tconst client = new IotaClient({ url: config.rpc.url });\n\tconst balanceResponse = await client.getBalance({ owner: walletAddress });\n\tconst balanceInNanos = Number(balanceResponse.totalBalance);\n\tconst requiredInNanos = config.deployment.gasBudget;\n\t// Convert to IOTA for display purposes\n\tconst balanceInIota = nanosToIota(balanceInNanos);\n\tconst requiredInIota = nanosToIota(requiredInNanos);\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.walletBalance\"),\n\t\t`${balanceInIota.toFixed(2)} IOTA`,\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.gasBudget\"),\n\t\t`${requiredInIota.toFixed(2)} IOTA`,\n\t\t1\n\t);\n\n\t// Only request faucet funds if balance is insufficient (compare in same units - nanos)\n\tif (balanceInNanos < requiredInNanos) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.warning\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.insufficientBalance\", {\n\t\t\t\tcurrentBalance: balanceInIota.toFixed(2),\n\t\t\t\trequiredBalance: requiredInIota.toFixed(2)\n\t\t\t}),\n\t\t\t1\n\t\t);\n\n\t\tif (!Is.stringValue(faucetUrl)) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noFaucetConfigured\");\n\t\t}\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"commands.deploy.progress.requestingAdditionalFaucetFunds\"));\n\t\tawait requestFaucetFunds(network, walletAddress, config.rpc.url, faucetUrl);\n\n\t\t// Check balance again after faucet request\n\t\tconst updatedBalanceResponse = await client.getBalance({ owner: walletAddress });\n\t\tconst updatedBalanceInNanos = Number(updatedBalanceResponse.totalBalance);\n\t\tconst updatedBalanceInIota = nanosToIota(updatedBalanceInNanos);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.updatedWalletBalance\"),\n\t\t\t`${updatedBalanceInIota.toFixed(2)} IOTA`,\n\t\t\t1\n\t\t);\n\t} else {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.balanceCheck\"),\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.sufficientFundsAvailable\"),\n\t\t\t1\n\t\t);\n\t}\n}\n\n/**\n * Deploy contract using IOTA CLI.\n * @param gasBudget Gas budget for deployment.\n * @returns Deployment result with package ID, upgrade cap, and migration state ID.\n */\nasync function deployWithIotaCli(\n\tgasBudget: number\n): Promise<{ packageId: string; upgradeCap?: string; migrationStateId?: string }> {\n\t// Find the Move project directory\n\tconst moveTomlPaths: string[] = [];\n\tconst cwd = process.cwd();\n\tawait searchDirectoryForMoveToml(cwd, moveTomlPaths);\n\n\tif (moveTomlPaths.length === 0) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.noMoveTomlFilesFound\", {\n\t\t\tcurrentDir: cwd\n\t\t});\n\t}\n\n\t// Prioritize Move.toml in current directory, then use first found\n\tconst currentDirMoveToml = path.join(cwd, \"Move.toml\");\n\tconst selectedMoveToml = moveTomlPaths.find(p => p === currentDirMoveToml) ?? moveTomlPaths[0];\n\n\t// Use the actual Move project directory\n\tconst moveProjectRoot = path.dirname(selectedMoveToml);\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.moveProjectRoot\"),\n\t\tmoveProjectRoot,\n\t\t1\n\t);\n\n\tconst publishCmd = `iota client publish --gas-budget ${gasBudget} --json`;\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.deploy.labels.publishCommand\"), publishCmd, 1);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.workingDirectory\"),\n\t\tmoveProjectRoot,\n\t\t1\n\t);\n\n\ttry {\n\t\tconst { stdout: output } = await execAsyncWithError(publishCmd, { cwd: moveProjectRoot });\n\t\tconst result = JSON.parse(output);\n\n\t\t// Extract package ID from published object\n\t\tconst packageId = result.objectChanges?.find(\n\t\t\t(change: { type: string; packageId?: string }) => change.type === \"published\"\n\t\t)?.packageId;\n\n\t\tif (!packageId) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.packageIdNotFound\", {\n\t\t\t\tresult\n\t\t\t});\n\t\t}\n\n\t\t// Extract UpgradeCap ID from created objects\n\t\tconst upgradeCap = result.objectChanges?.find(\n\t\t\t(change: { objectType?: string; objectId?: string }) =>\n\t\t\t\tchange.objectType === \"0x2::package::UpgradeCap\"\n\t\t)?.objectId;\n\n\t\t// Extract MigrationState ID from created objects\n\t\tconst migrationStateId = result.objectChanges?.find(\n\t\t\t(change: { objectType?: string; objectId?: string }) =>\n\t\t\t\tchange.objectType?.endsWith(\"::MigrationState\")\n\t\t)?.objectId;\n\n\t\treturn {\n\t\t\tpackageId,\n\t\t\tupgradeCap,\n\t\t\tmigrationStateId\n\t\t};\n\t} catch (err) {\n\t\tthrow new GeneralError(\"commands\", \"commands.deploy.deploymentFailed\", undefined, err);\n\t}\n}\n\n/**\n * Update contracts file with deployed package IDs.\n * @param contractsPath Path to contracts file.\n * @param contractsData Updated contracts data.\n */\nasync function updateContractsFile(\n\tcontractsPath: string,\n\tcontractsData: ISmartContractDeployments\n): Promise<void> {\n\ttry {\n\t\tawait CLIUtils.writeJsonFile(contractsPath, contractsData, false);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.deploy.labels.updatedContractsFile\"),\n\t\t\tcontractsPath,\n\t\t\t1\n\t\t);\n\t} catch (err) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.contractsFileUpdateFailed\",\n\t\t\t{ contractsPath },\n\t\t\terr\n\t\t);\n\t}\n}\n\n/**\n * Generate a unique backup alias that doesn't conflict with existing keys.\n * Uses cryptographically secure random bytes to avoid conflicts.\n * @param baseAlias The original alias name.\n * @param existingKeys Array of existing keys from keystore.\n * @returns A unique backup alias name.\n */\nexport function generateUniqueBackupAlias(\n\tbaseAlias: string,\n\texistingKeys: { alias: string; iotaAddress: string }[]\n): string {\n\tconst existingAliases = new Set(existingKeys.map(key => key.alias));\n\n\t// Generate cryptographically secure random identifier\n\tconst randomSuffix = Converter.bytesToHex(RandomHelper.generate(4));\n\tconst backupAlias = `${baseAlias}-backup-${randomSuffix}`;\n\n\t// In the extremely unlikely event of collision, add timestamp\n\tif (existingAliases.has(backupAlias)) {\n\t\treturn `${baseAlias}-backup-${Date.now()}-${randomSuffix}`;\n\t}\n\n\treturn backupAlias;\n}\n\n/**\n * Ensure the correct deployer key exists in the keystore with the expected address.\n * If a conflicting alias exists, rename it and import the correct key.\n * @param network The target network.\n * @param aliasName The desired alias name (e.g., \"deployer-testnet\").\n * @param expectedAddress The expected address from the current mnemonic.\n * @param addressIndex The address index to use.\n * @param deployerMnemonic The deployer mnemonic.\n */\nexport async function ensureCorrectDeployerKey(\n\tnetwork: NetworkTypes,\n\taliasName: string,\n\texpectedAddress: string,\n\taddressIndex: number,\n\tdeployerMnemonic: string\n): Promise<void> {\n\ttry {\n\t\t// Check if the alias already exists in keystore\n\t\tconst { stdout: keysListOutput } = await execAsyncWithError(\"iota keytool list --json\");\n\t\tconst keysList = JSON.parse(keysListOutput);\n\n\t\t// Find existing key with the target alias\n\t\tconst existingKey = keysList.find(\n\t\t\t(key: { alias: string; iotaAddress: string }) => key.alias === aliasName\n\t\t);\n\n\t\tif (existingKey) {\n\t\t\t// Check if existing key has the correct address\n\t\t\tconst existingAddress = existingKey.iotaAddress;\n\n\t\t\tif (existingAddress !== expectedAddress) {\n\t\t\t\t// Conflicting alias exists with wrong mnemonic - rename it\n\t\t\t\tCLIDisplay.task(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.progress.renamingConflictingKey\", { aliasName })\n\t\t\t\t);\n\n\t\t\t\tconst backupAlias = generateUniqueBackupAlias(aliasName, keysList);\n\t\t\t\tawait execAsyncWithError(`iota keytool update-alias \"${aliasName}\" \"${backupAlias}\"`);\n\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.renamedExistingKey\"),\n\t\t\t\t\t`${aliasName} → ${backupAlias} (${existingAddress})`,\n\t\t\t\t\t1\n\t\t\t\t);\n\n\t\t\t\t// Now import the correct key with the desired alias\n\t\t\t\tawait importCorrectDeployerKey(\n\t\t\t\t\tnetwork,\n\t\t\t\t\taliasName,\n\t\t\t\t\taddressIndex,\n\t\t\t\t\texpectedAddress,\n\t\t\t\t\tdeployerMnemonic\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Existing key is correct - no action needed\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"commands.deploy.labels.usingExistingCorrectKey\"),\n\t\t\t\t\t`${aliasName} (${expectedAddress})`,\n\t\t\t\t\t1\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\t// No existing alias - import the key\n\t\t\tawait importCorrectDeployerKey(\n\t\t\t\tnetwork,\n\t\t\t\taliasName,\n\t\t\t\taddressIndex,\n\t\t\t\texpectedAddress,\n\t\t\t\tdeployerMnemonic\n\t\t\t);\n\t\t}\n\n\t\t// Verify the address exists in client addresses\n\t\tconst { stdout: addressListOutput } = await execAsyncWithError(\"iota client addresses --json\");\n\t\tconst addressInfo = JSON.parse(addressListOutput);\n\t\tconst addressExists: boolean = addressInfo.addresses.some(\n\t\t\t([_, addr]: [string, string]) => addr === expectedAddress\n\t\t);\n\n\t\tif (!addressExists) {\n\t\t\tthrow new GeneralError(\"commands\", \"commands.deploy.addressNotInClient\", {\n\t\t\t\texpectedAddress,\n\t\t\t\taliasName\n\t\t\t});\n\t\t}\n\t} catch (error) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.deploy.deployerKeySetupFailed\",\n\t\t\t{ network, aliasName, expectedAddress },\n\t\t\terror\n\t\t);\n\t}\n}\n\n/**\n * Import the deployer key with the correct mnemonic.\n * @param network The target network.\n * @param aliasName The alias name to use.\n * @param addressIndex The address index.\n * @param targetAddress The expected target address (avoids redundant calculation).\n * @param deployerMnemonic The deployer mnemonic.\n */\nasync function importCorrectDeployerKey(\n\tnetwork: NetworkTypes,\n\taliasName: string,\n\taddressIndex: number,\n\ttargetAddress: string,\n\tdeployerMnemonic: string\n): Promise<void> {\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.deploy.progress.importingDeployerKey\", { aliasName })\n\t);\n\n\tconst mnemonic = await getDeploymentMnemonic(network, deployerMnemonic);\n\tconst derivationPath = Bip44.path(Iota.DEFAULT_COIN_TYPE, 0, false, addressIndex).toString();\n\n\tawait execAsyncWithError(\n\t\t`iota keytool import \"${mnemonic}\" ed25519 \"${derivationPath}\" --alias \"${aliasName}\"`\n\t);\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.deploy.labels.importedDeployerKey\"),\n\t\t`${aliasName} (${targetAddress})`,\n\t\t1\n\t);\n}\n"]}
@@ -505,7 +505,9 @@
505
505
  "upgradeGuidance": "Upgrade Guidance",
506
506
  "previousDeployment": "Previous Deployment",
507
507
  "currentDeployment": "Current Deployment",
508
- "buildValidation": "Build Validation"
508
+ "buildValidation": "Build Validation",
509
+ "onChainPackageId": "On-chain UpgradeCap Package",
510
+ "onChainVersion": "On-chain UpgradeCap Version"
509
511
  },
510
512
  "progress": {
511
513
  "checkingEnvironment": "Checking IOTA CLI environment...",
@@ -514,7 +516,8 @@
514
516
  "requestingFaucetFunds": "Requesting funds from {network} faucet...",
515
517
  "requestingAdditionalFaucetFunds": "Requesting additional funds from faucet...",
516
518
  "renamingConflictingKey": "Renaming conflicting key alias \"{aliasName}\" to preserve existing key",
517
- "importingDeployerKey": "Importing deployer key as \"{aliasName}\""
519
+ "importingDeployerKey": "Importing deployer key as \"{aliasName}\"",
520
+ "queryingUpgradeCap": "Querying on-chain UpgradeCap to validate published-at..."
518
521
  },
519
522
  "messages": {
520
523
  "contractAlreadyDeployed": "Contract already deployed, no changes detected",
@@ -522,7 +525,8 @@
522
525
  "noneInitialDeployment": "None - Initial deployment",
523
526
  "noneNeedsDeploymentUpgrade": "None - Needs deployment/upgrade",
524
527
  "originalConfigurationRestored": "Original configuration restored",
525
- "contractBuiltAndReadyForUpgrade": "Contract has been built and is ready for upgrade"
528
+ "contractBuiltAndReadyForUpgrade": "Contract has been built and is ready for upgrade",
529
+ "staleJsonDetected": "Stale deployment JSON detected. JSON has \"{jsonPackageId}\" but on-chain UpgradeCap has \"{onChainPackageId}\". Using on-chain value."
526
530
  },
527
531
  "section": {
528
532
  "deployContracts": "Deploy Contracts"
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.8](https://github.com/twinfoundation/dlt/compare/move-to-json-v0.0.3-next.7...move-to-json-v0.0.3-next.8) (2026-03-16)
4
+
5
+
6
+ ### Features
7
+
8
+ * validate published-at against on-chain UpgradeCap before upgrade ([#62](https://github.com/twinfoundation/dlt/issues/62)) ([23b49e2](https://github.com/twinfoundation/dlt/commit/23b49e247b89d2e363f9420b01fa35941f73be12))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/dlt-iota bumped from 0.0.3-next.7 to 0.0.3-next.8
16
+
3
17
  ## [0.0.3-next.7](https://github.com/twinfoundation/dlt/compare/move-to-json-v0.0.3-next.6...move-to-json-v0.0.3-next.7) (2026-03-13)
4
18
 
5
19
 
package/locales/en.json CHANGED
@@ -202,7 +202,9 @@
202
202
  "upgradeGuidance": "Upgrade Guidance",
203
203
  "previousDeployment": "Previous Deployment",
204
204
  "currentDeployment": "Current Deployment",
205
- "buildValidation": "Build Validation"
205
+ "buildValidation": "Build Validation",
206
+ "onChainPackageId": "On-chain UpgradeCap Package",
207
+ "onChainVersion": "On-chain UpgradeCap Version"
206
208
  },
207
209
  "progress": {
208
210
  "checkingEnvironment": "Checking IOTA CLI environment...",
@@ -211,7 +213,8 @@
211
213
  "requestingFaucetFunds": "Requesting funds from {network} faucet...",
212
214
  "requestingAdditionalFaucetFunds": "Requesting additional funds from faucet...",
213
215
  "renamingConflictingKey": "Renaming conflicting key alias \"{aliasName}\" to preserve existing key",
214
- "importingDeployerKey": "Importing deployer key as \"{aliasName}\""
216
+ "importingDeployerKey": "Importing deployer key as \"{aliasName}\"",
217
+ "queryingUpgradeCap": "Querying on-chain UpgradeCap to validate published-at..."
215
218
  },
216
219
  "messages": {
217
220
  "contractAlreadyDeployed": "Contract already deployed, no changes detected",
@@ -219,7 +222,8 @@
219
222
  "noneInitialDeployment": "None - Initial deployment",
220
223
  "noneNeedsDeploymentUpgrade": "None - Needs deployment/upgrade",
221
224
  "originalConfigurationRestored": "Original configuration restored",
222
- "contractBuiltAndReadyForUpgrade": "Contract has been built and is ready for upgrade"
225
+ "contractBuiltAndReadyForUpgrade": "Contract has been built and is ready for upgrade",
226
+ "staleJsonDetected": "Stale deployment JSON detected. JSON has \"{jsonPackageId}\" but on-chain UpgradeCap has \"{onChainPackageId}\". Using on-chain value."
223
227
  },
224
228
  "section": {
225
229
  "deployContracts": "Deploy Contracts"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/move-to-json",
3
- "version": "0.0.3-next.7",
3
+ "version": "0.0.3-next.8",
4
4
  "description": "CLI for compiling Move contracts and preparing deployment JSON for IOTA networks.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "@twin.org/cli-core": "next",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/crypto": "next",
21
- "@twin.org/dlt-iota": "0.0.3-next.7",
21
+ "@twin.org/dlt-iota": "0.0.3-next.8",
22
22
  "@twin.org/nameof": "next",
23
23
  "@twin.org/wallet-connector-iota": "next",
24
24
  "commander": "14.0.3",