Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 52 additions & 23 deletions cli/src/cli-helpers/ensureBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,45 +36,72 @@ 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'
: ' - Native balance is insufficient';
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 <name>')})`)
);
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 <name>')})`)
);
throw Error(`Balance is insufficient`);
);
throw Error(`RLC balance is insufficient`);
}
}

return {
wei,
nRLC,
stake,
};
}
3 changes: 2 additions & 1 deletion cli/src/cmd/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export async function deploy({ chain }: { chain?: string }) {
iexec = getIExec({ ...chainConfig, signer });
}

await ensureBalances({ spinner, iexec });
// 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 });
Expand Down
Loading