From 9d31318a24128ea532a8004073fc862a7d6ccc70 Mon Sep 17 00:00:00 2001 From: Pierre Jeanjacquot <26487010+PierreJeanjacquot@users.noreply.github.com> Date: Thu, 21 Aug 2025 16:11:43 +0200 Subject: [PATCH 1/2] fix: stop blocking iapp deploy when RLC balance is empty --- cli/src/cli-helpers/ensureBalances.ts | 71 +++++++++++++++------------ cli/src/cmd/deploy.ts | 2 +- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/cli/src/cli-helpers/ensureBalances.ts b/cli/src/cli-helpers/ensureBalances.ts index 24d38adb..22375479 100644 --- a/cli/src/cli-helpers/ensureBalances.ts +++ b/cli/src/cli-helpers/ensureBalances.ts @@ -1,16 +1,18 @@ import { warnBox } from './box.js'; -import { emphasis, command } from './color.js'; +import { emphasis, command, promptHelper } from './color.js'; import type { Spinner } from './spinner.js'; import { BN, IExec, utils } from 'iexec'; export async function ensureBalances({ spinner, iexec, + warnOnlyRlc = false, nRlcMin, weiMin, }: { spinner: Spinner; iexec: IExec; + warnOnlyRlc?: boolean; nRlcMin?: BN; weiMin?: BN; }): Promise<{ @@ -34,36 +36,33 @@ export async function ensureBalances({ (chainId !== 134 && totalRlc.isZero()) || (!!nRlcMin && totalRlc.lt(nRlcMin)); - if (!missingNative && !missingRlc) { - return { - wei, - nRLC, - stake, - }; - } + const shouldThrow = missingNative || (missingRlc && !warnOnlyRlc); - const helpers = []; - if (missingNative) { - const msg = wei.isZero() - ? ' - Native balance is empty' - : ' - Native balance is insufficient'; - const requirement = weiMin - ? ` (requires ${utils.formatEth(weiMin as BN)} ether)` - : ''; - helpers.push(`${msg}${requirement}`); - } - if (missingRlc) { - const msg = totalRlc.isZero() - ? ' - RLC balance is empty' - : ' - RLC balance is insufficient'; - const requirement = nRlcMin - ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` - : ''; - helpers.push(`${msg}${requirement}`); - } + // always show missing balance warnings + if (missingNative || missingRlc) { + const helpers = []; + if (missingNative) { + const msg = + ' - Native asset balance required for blockchain transactions is ' + + (wei.isZero() ? 'empty' : 'insufficient'); + const requirement = weiMin + ? ` (requires ${utils.formatEth(weiMin as BN)} ether)` + : ''; + helpers.push(`${msg}${requirement}`); + } + if (missingRlc) { + const msg = + ' - RLC token balance required for iapp runs is ' + + (totalRlc.isZero() ? 'empty' : 'insufficient') + + (warnOnlyRlc ? promptHelper(' (warning only)') : ''); + const requirement = nRlcMin + ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` + : ''; + helpers.push(`${msg}${requirement}`); + } - spinner.log( - warnBox(`Current chain requires ${chainId !== 134 ? 'native asset to pay transaction fees and ' : ''}RLC to pay iApp runs! + spinner.log( + warnBox(`Current chain requires ${chainId !== 134 ? 'native asset to pay transaction fees and ' : ''}RLC to pay iApp runs! Your wallet balance is insufficient: ${helpers.join('\n')} @@ -73,6 +72,16 @@ You can either: - Import another wallet (run ${command('iapp wallet import')}) - Select an imported wallet (run ${command('iapp wallet select')}) - Use another chain (use option ${command('--chain ')})`) - ); - throw Error(`Balance is insufficient`); + ); + } + + if (shouldThrow) { + throw Error(`Balance is insufficient`); + } + + return { + wei, + nRLC, + stake, + }; } diff --git a/cli/src/cmd/deploy.ts b/cli/src/cmd/deploy.ts index 97b92df9..f0bfaba1 100644 --- a/cli/src/cmd/deploy.ts +++ b/cli/src/cmd/deploy.ts @@ -46,7 +46,7 @@ export async function deploy({ chain }: { chain?: string }) { iexec = getIExec({ ...chainConfig, signer }); } - await ensureBalances({ spinner, iexec }); + await ensureBalances({ spinner, iexec, warnOnlyRlc: true }); const dockerhubUsername = await askForDockerhubUsername({ spinner }); const dockerhubAccessToken = await askForDockerhubAccessToken({ spinner }); From c36084f41ccfeb79fe6f48cb38b478df5d54529c Mon Sep 17 00:00:00 2001 From: Pierre Jeanjacquot <26487010+PierreJeanjacquot@users.noreply.github.com> Date: Thu, 21 Aug 2025 16:45:52 +0200 Subject: [PATCH 2/2] style: reword balance warning --- cli/src/cli-helpers/ensureBalances.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/cli-helpers/ensureBalances.ts b/cli/src/cli-helpers/ensureBalances.ts index 22375479..7e8b8596 100644 --- a/cli/src/cli-helpers/ensureBalances.ts +++ b/cli/src/cli-helpers/ensureBalances.ts @@ -43,7 +43,7 @@ export async function ensureBalances({ const helpers = []; if (missingNative) { const msg = - ' - Native asset balance required for blockchain transactions is ' + + ' - Native asset balance needed for transaction fees is ' + (wei.isZero() ? 'empty' : 'insufficient'); const requirement = weiMin ? ` (requires ${utils.formatEth(weiMin as BN)} ether)` @@ -52,7 +52,7 @@ export async function ensureBalances({ } if (missingRlc) { const msg = - ' - RLC token balance required for iapp runs is ' + + ' - RLC token balance needed for iapp runs is ' + (totalRlc.isZero() ? 'empty' : 'insufficient') + (warnOnlyRlc ? promptHelper(' (warning only)') : ''); const requirement = nRlcMin @@ -62,7 +62,7 @@ export async function ensureBalances({ } spinner.log( - warnBox(`Current chain requires ${chainId !== 134 ? 'native asset to pay transaction fees and ' : ''}RLC to pay iApp runs! + warnBox(`Operations on this chain require ${chainId !== 134 ? 'native assets for transaction fees and ' : ''}RLC for iApp runs! Your wallet balance is insufficient: ${helpers.join('\n')}