From 428c9a2aa1257b1c55b8af83410b3ce4964b870d Mon Sep 17 00:00:00 2001 From: paypes <43441600+abbesBenayache@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:39:26 +0200 Subject: [PATCH 1/2] feat: remove RLC balance check blocking deployment and add warning instead --- cli/src/cmd/deploy.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cli/src/cmd/deploy.ts b/cli/src/cmd/deploy.ts index 97b92df9..940f5fc8 100644 --- a/cli/src/cmd/deploy.ts +++ b/cli/src/cmd/deploy.ts @@ -22,7 +22,6 @@ import { hintBox } from '../cli-helpers/box.js'; import { addDeploymentData } from '../utils/cacheExecutions.js'; import { deployTdxApp, getIExecTdx } from '../utils/tdx-poc.js'; import { useTdx } from '../utils/featureFlags.js'; -import { ensureBalances } from '../cli-helpers/ensureBalances.js'; import { warnBeforeTxFees } from '../cli-helpers/warnBeforeTxFees.js'; export async function deploy({ chain }: { chain?: string }) { @@ -46,7 +45,21 @@ export async function deploy({ chain }: { chain?: string }) { iexec = getIExec({ ...chainConfig, signer }); } - await ensureBalances({ spinner, iexec }); + // Check balance and show warning if no RLC + const chainId = await iexec.config.resolveChainId(); + const address = await iexec.wallet.getAddress(); + const [{ nRLC }, { stake }] = await Promise.all([ + iexec.wallet.checkBalances(address), + iexec.account.checkBalance(address), + ]); + + const totalRlc = stake.add(nRLC); + + if (totalRlc.isZero() && chainId !== 134) { + spinner.warn( + `⚠️ Warning: Your wallet has no RLC balance. You'll need RLC to run your iApp later. Consider funding your wallet ${address} or importing another wallet.` + ); + } const dockerhubUsername = await askForDockerhubUsername({ spinner }); const dockerhubAccessToken = await askForDockerhubAccessToken({ spinner }); From 72bdfd62d8b5803e0097694420f57e2288a8ad9b Mon Sep 17 00:00:00 2001 From: paypes <43441600+abbesBenayache@users.noreply.github.com> Date: Wed, 20 Aug 2025 17:10:44 +0200 Subject: [PATCH 2/2] refactore: improve ensureBalances with warnOnlyRlc option for RLC balance - Add warnOnlyRlc parameter to ensureBalances function - Always check native assets (required for transaction fees) - Allow RLC balance warnings instead of blocking deployment - Maintain strict RLC checking for app execution - Improve error messages with better separation of concerns - Use warnOnlyRlc: true in deploy.ts for flexible deployment --- cli/src/cli-helpers/ensureBalances.ts | 75 +++++++++++++++++++-------- cli/src/cmd/deploy.ts | 18 ++----- 2 files changed, 55 insertions(+), 38 deletions(-) diff --git a/cli/src/cli-helpers/ensureBalances.ts b/cli/src/cli-helpers/ensureBalances.ts index 24d38adb..722edb0c 100644 --- a/cli/src/cli-helpers/ensureBalances.ts +++ b/cli/src/cli-helpers/ensureBalances.ts @@ -8,11 +8,13 @@ export async function ensureBalances({ iexec, nRlcMin, weiMin, + warnOnlyRlc = false, }: { spinner: Spinner; iexec: IExec; nRlcMin?: BN; weiMin?: BN; + warnOnlyRlc?: boolean; }): Promise<{ wei: BN; nRLC: BN; @@ -34,15 +36,7 @@ export async function ensureBalances({ (chainId !== 134 && totalRlc.isZero()) || (!!nRlcMin && totalRlc.lt(nRlcMin)); - if (!missingNative && !missingRlc) { - return { - wei, - nRLC, - stake, - }; - } - - const helpers = []; + // Always check native assets - they're required for transaction fees if (missingNative) { const msg = wei.isZero() ? ' - Native balance is empty' @@ -50,29 +44,64 @@ export async function ensureBalances({ const requirement = weiMin ? ` (requires ${utils.formatEth(weiMin as BN)} ether)` : ''; - helpers.push(`${msg}${requirement}`); + + spinner.log( + warnBox(`Current chain requires native asset to pay transaction fees! + +Your wallet balance is insufficient: +${msg}${requirement} + +You can either: + - Fund your wallet ${emphasis(address)} + - 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(`Native balance is insufficient`); } + + // For RLC, either warn only or block based on warnOnlyRlc option 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}`); - } + if (warnOnlyRlc) { + // Just warn for RLC, don't block + const msg = totalRlc.isZero() + ? ' - RLC balance is empty' + : ' - RLC balance is insufficient'; + const requirement = nRlcMin + ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` + : ''; + + spinner.warn( + `⚠️ Warning: Your wallet has insufficient RLC balance:${msg}${requirement}. You'll need RLC to run your iApp later. Consider funding your wallet ${emphasis(address)} or importing another wallet.` + ); + } else { + // Block for RLC (original behavior) + const msg = totalRlc.isZero() + ? ' - RLC balance is empty' + : ' - RLC balance is insufficient'; + const requirement = nRlcMin + ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` + : ''; - 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 RLC to pay iApp runs! Your wallet balance is insufficient: -${helpers.join('\n')} +${msg}${requirement} You can either: - Fund your wallet ${emphasis(address)} - 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`); + ); + throw Error(`RLC balance is insufficient`); + } + } + + return { + wei, + nRLC, + stake, + }; } diff --git a/cli/src/cmd/deploy.ts b/cli/src/cmd/deploy.ts index 940f5fc8..4792b280 100644 --- a/cli/src/cmd/deploy.ts +++ b/cli/src/cmd/deploy.ts @@ -22,6 +22,7 @@ import { hintBox } from '../cli-helpers/box.js'; import { addDeploymentData } from '../utils/cacheExecutions.js'; import { deployTdxApp, getIExecTdx } from '../utils/tdx-poc.js'; import { useTdx } from '../utils/featureFlags.js'; +import { ensureBalances } from '../cli-helpers/ensureBalances.js'; import { warnBeforeTxFees } from '../cli-helpers/warnBeforeTxFees.js'; export async function deploy({ chain }: { chain?: string }) { @@ -45,21 +46,8 @@ export async function deploy({ chain }: { chain?: string }) { iexec = getIExec({ ...chainConfig, signer }); } - // Check balance and show warning if no RLC - const chainId = await iexec.config.resolveChainId(); - const address = await iexec.wallet.getAddress(); - const [{ nRLC }, { stake }] = await Promise.all([ - iexec.wallet.checkBalances(address), - iexec.account.checkBalance(address), - ]); - - const totalRlc = stake.add(nRLC); - - if (totalRlc.isZero() && chainId !== 134) { - spinner.warn( - `⚠️ Warning: Your wallet has no RLC balance. You'll need RLC to run your iApp later. Consider funding your wallet ${address} or importing another wallet.` - ); - } + // Check balances: always verify native assets for transaction fees, but only warn for RLC + await ensureBalances({ spinner, iexec, warnOnlyRlc: true }); const dockerhubUsername = await askForDockerhubUsername({ spinner }); const dockerhubAccessToken = await askForDockerhubAccessToken({ spinner });