Skip to content

Commit

Permalink
hotfix(cli): show total gas used
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Feb 26, 2025
1 parent e624055 commit e47337c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export async function build({
const chainName = chainInfo?.name || 'unknown chain';
const nativeCurrencySymbol = chainInfo?.nativeCurrency.symbol || 'ETH';
let totalCost = BigInt(0);
let totalGasUsed = BigInt(0);

const runtimeOptions = {
provider,
Expand Down Expand Up @@ -283,6 +284,7 @@ export async function build({
log(gray(`${' '.repeat(d)} Transaction Hash: ${txn.hash}`));
const cost = BigInt(txn.gasCost) * BigInt(txn.gasUsed);
totalCost = totalCost + cost;
totalGasUsed = totalGasUsed + BigInt(txn.gasUsed);
log(
gray(
`${' '.repeat(d)} Transaction Cost: ${viem.formatEther(
Expand All @@ -303,6 +305,7 @@ export async function build({
log(gray(`${' '.repeat(d)} Transaction Hash: ${contract.deployTxnHash}`));
const cost = BigInt(contract.gasCost) * BigInt(contract.gasUsed);
totalCost = totalCost + cost;
totalGasUsed = totalGasUsed + BigInt(contract.gasUsed);
log(
gray(
`${' '.repeat(d)} Transaction Cost: ${viem.formatEther(
Expand Down Expand Up @@ -461,7 +464,7 @@ export async function build({
)
)
);
log(gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
log(gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol} (${totalGasUsed.toLocaleString()} gas)`));
log('');
log(
'- Rerunning the build command will attempt to execute skipped operations. It will not rerun executed operations. (To rerun executed operations, delete the partial build package generated by this run by adding the --wipe flag to the build command on the next run.)'
Expand All @@ -477,15 +480,23 @@ export async function build({
);
} else {
if (dryRun) {
log(gray(`Estimated Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
log(
gray(
`Estimated Total Cost: ${viem.formatEther(
totalCost
)} ${nativeCurrencySymbol} (${totalGasUsed.toLocaleString()} gas)`
)
);
log(bold(`💥 ${fullPackageRef} would have been successfully built on ${chainName} (Chain ID: ${chainId})`));
} else {
if (chainId == 13370) {
log(bold(`💥 ${fullPackageRef} built for Cannon (Chain ID: ${chainId})`));
log(gray('This package can be run locally and cloned in cannonfiles.'));
} else {
log(bold(`💥 ${fullPackageRef} built on ${chainName} (Chain ID: ${chainId})`));
log(gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
log(
gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol} (${totalGasUsed.toLocaleString()} gas)`)
);
}
}
log();
Expand Down

0 comments on commit e47337c

Please sign in to comment.