Skip to content

Commit

Permalink
refactor balance check naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli committed May 10, 2024
1 parent b686224 commit 78403ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions typescript/cli/src/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Address, ProtocolType } from '@hyperlane-xyz/utils';
import { parseIsmConfig } from '../config/ism.js';
import { WriteCommandContext } from '../context/types.js';
import { log, logGreen, logPink } from '../logger.js';
import { assertGasBalances } from '../utils/balances.js';
import { gasBalancesAreSufficient } from '../utils/balances.js';
import { ENV } from '../utils/env.js';
import { assertSigner } from '../utils/keys.js';

Expand Down Expand Up @@ -76,16 +76,16 @@ export async function runPreflightChecksForChains({
assertSigner(signer);
logGreen('✅ Signer is valid');

const lowBalanceExists = await assertGasBalances(
const sufficient = await gasBalancesAreSufficient(
multiProvider,
signer,
chainsToGasCheck ?? chains,
minGas,
);
logGreen(
lowBalanceExists
? '⚠️ Balances may not be sufficient'
: ' Balances are sufficient',
sufficient
? ' Balances are sufficient'
: '⚠️ Balances may not be sufficient',
);
}

Expand Down
16 changes: 8 additions & 8 deletions typescript/cli/src/utils/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ethers } from 'ethers';

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

export async function assertNativeBalances(
export async function nativeBalancesAreSufficient(
multiProvider: MultiProvider,
signer: ethers.Signer,
chains: ChainName[],
minBalanceWei: string,
): Promise<boolean> {
const address = await signer.getAddress();
const minBalance = ethers.utils.formatEther(minBalanceWei.toString());
let lowBalanceExists = false;
let sufficient = true;
await Promise.all(
chains.map(async (chain) => {
const balanceWei = await multiProvider
Expand All @@ -26,32 +26,32 @@ export async function assertNativeBalances(
message: `WARNING: ${error} Continue?`,
});
if (!isResume) throw new Error(error);
lowBalanceExists = true;
sufficient = false;
}
}),
);
return lowBalanceExists;
return sufficient;
}

export async function assertGasBalances(
export async function gasBalancesAreSufficient(
multiProvider: MultiProvider,
signer: ethers.Signer,
chains: ChainName[],
minGas: string,
): Promise<boolean> {
let lowBalanceExists = false;
let sufficient = true;
await Promise.all(
chains.map(async (chain) => {
const provider = multiProvider.getProvider(chain);
const gasPrice = await provider.getGasPrice();
const minBalanceWei = gasPrice.mul(minGas).toString();
lowBalanceExists = await assertNativeBalances(
sufficient = await nativeBalancesAreSufficient(
multiProvider,
signer,
[chain],
minBalanceWei,
);
}),
);
return lowBalanceExists;
return sufficient;
}

0 comments on commit 78403ea

Please sign in to comment.