Skip to content

Commit

Permalink
fix: balance check skip confirmation (#5012)
Browse files Browse the repository at this point in the history
### Description

Balance checking will skip confirmation when CLI flag is defined. When
balances are insufficient, CLI asks for confirmation to continue with
deployment, if `skip-confirmations` is provided through CLI args this
should be bypassed.

### Backward compatibility

No, compatible with backwards

### Testing

Manual
  • Loading branch information
mkykadir authored Dec 16, 2024
1 parent ae5b58e commit 0c83724
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-bats-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---

fix: balance check skip confirmation
3 changes: 2 additions & 1 deletion typescript/cli/src/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function runPreflightChecksForChains({
chainsToGasCheck?: ChainName[];
}) {
log('Running pre-flight checks for chains...');
const { multiProvider } = context;
const { multiProvider, skipConfirmation } = context;

if (!chains?.length) throw new Error('Empty chain selection');
for (const chain of chains) {
Expand All @@ -59,6 +59,7 @@ export async function runPreflightChecksForChains({
multiProvider,
chainsToGasCheck ?? chains,
minGas,
skipConfirmation,
);
}

Expand Down
12 changes: 7 additions & 5 deletions typescript/cli/src/utils/balances.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { confirm } from '@inquirer/prompts';
import { ethers } from 'ethers';

import { ChainName, MultiProvider } from '@hyperlane-xyz/sdk';
import { ProtocolType } from '@hyperlane-xyz/utils';

import { logGray, logGreen, logRed } from '../logger.js';
import { autoConfirm } from '../config/prompts.js';
import { logBlue, logGray, logGreen, logRed, warnYellow } from '../logger.js';

export async function nativeBalancesAreSufficient(
multiProvider: MultiProvider,
chains: ChainName[],
minGas: string,
skipConfirmation: boolean,
) {
const sufficientBalances: boolean[] = [];
for (const chain of chains) {
Expand Down Expand Up @@ -42,9 +43,10 @@ export async function nativeBalancesAreSufficient(
if (allSufficient) {
logGreen('✅ Balances are sufficient');
} else {
const isResume = await confirm({
message: 'Deployment may fail due to insufficient balance(s). Continue?',
});
warnYellow(`Deployment may fail due to insufficient balance(s)`);
const isResume = await autoConfirm('Continue?', skipConfirmation, () =>
logBlue('Continuing deployment with insufficient balances'),
);
if (!isResume) throw new Error('Canceled deployment due to low balance');
}
}

0 comments on commit 0c83724

Please sign in to comment.