Skip to content

Commit

Permalink
fix(cli): Add better outputs for dry run and allow dry run on local n…
Browse files Browse the repository at this point in the history
…etwork (#1250)

Co-authored-by: saeta.eth <saetaeth@proton.me>
  • Loading branch information
FuzzB0t and saeta-eth authored Aug 14, 2024
1 parent f8aa78b commit c733fc8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 36 deletions.
92 changes: 57 additions & 35 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export async function build({
}

const chainId = await provider.getChainId();

const chainInfo = getChainById(chainId);
const chainName = chainInfo?.name || 'unknown chain';
const nativeCurrencySymbol = chainInfo?.nativeCurrency.symbol || 'ETH';
Expand Down Expand Up @@ -475,22 +476,39 @@ export async function build({
' to pin the partial deployment package on IPFS. Then use https://usecannon.com/deploy to collect signatures from a Safe for the skipped operations in the partial deployment package.'
);
} 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.'));
if (!persist) {
log(bold(`💥 ${fullPackageRef} would be successfully built on ${chainName} (Chain ID: ${chainId})`));
log(gray(`Estimated Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
log();

log(
bold(
`Package data would be stored locally${
filteredSettings.writeIpfsUrl && ' and pinned to ' + filteredSettings.writeIpfsUrl
}`
)
);
log();

log('(Note: These files will not be saved)');
} else {
log(bold(`💥 ${fullPackageRef} built on ${chainName} (Chain ID: ${chainId})`));
log(gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
}
log();
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();

log(
bold(
`Package data has been stored locally${
filteredSettings.writeIpfsUrl && ' and pinned to ' + filteredSettings.writeIpfsUrl
}`
)
);
log(
bold(
`Package data has been stored locally${
filteredSettings.writeIpfsUrl && ' and pinned to ' + filteredSettings.writeIpfsUrl
}`
)
);
}
log(
table([
['Deployment Data', deployUrl],
Expand All @@ -501,29 +519,33 @@ export async function build({

const isMainPreset = preset === PackageReference.DEFAULT_PRESET;

if (isMainPreset) {
log(
bold(
`Publish ${bold(`${packageRef}`)} to the registry and pin the IPFS data to ${filteredSettings.publishIpfsUrl}`
)
);
log(`> cannon publish ${packageRef} --chain-id ${chainId}`);
} else {
log(
bold(`Publish ${bold(fullPackageRef)} to the registry and pin the IPFS data to ${filteredSettings.publishIpfsUrl}`)
);
log(`> cannon publish ${fullPackageRef} --chain-id ${chainId}`);
}
if (persist) {
if (isMainPreset) {
log(
bold(
`Publish ${bold(`${packageRef}`)} to the registry and pin the IPFS data to ${filteredSettings.publishIpfsUrl}`
)
);
log(`> cannon publish ${packageRef} --chain-id ${chainId}`);
} else {
log(
bold(
`Publish ${bold(fullPackageRef)} to the registry and pin the IPFS data to ${filteredSettings.publishIpfsUrl}`
)
);
log(`> cannon publish ${fullPackageRef} --chain-id ${chainId}`);
}

log('');
if (chainId == 13370) {
log(bold('Run this package'));
log('');
if (chainId == 13370) {
log(bold('Run this package'));

if (isMainPreset) log(`> cannon ${packageRef}`);
else log(`> cannon ${fullPackageRef}`);
} else {
log(bold('Verify contracts on Etherscan'));
log(`> cannon verify ${fullPackageRef} --chain-id ${chainId}`);
if (isMainPreset) log(`> cannon ${packageRef}`);
else log(`> cannon ${fullPackageRef}`);
} else {
log(bold('Verify contracts on Etherscan'));
log(`> cannon verify ${fullPackageRef} --chain-id ${chainId}`);
}
}
}
} else {
Expand Down
15 changes: 14 additions & 1 deletion packages/cli/src/util/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import { CannonSigner, ChainArtifacts, ChainBuilderRuntime } from '@usecannon/builder';
import { CANNON_CHAIN_ID, CannonSigner, ChainArtifacts, ChainBuilderRuntime } from '@usecannon/builder';
import Debug from 'debug';
import * as viem from 'viem';
import { getFoundryArtifact } from '../foundry';
Expand All @@ -12,6 +12,7 @@ import { pickAnvilOptions } from './anvil';
import { parseSettings } from './params';
import { ProviderAction, resolveProvider, isURL, getChainIdFromProviderUrl } from './provider';
import { ANVIL_FIRST_ADDRESS } from '../constants';
import { warn } from './console';

const debug = Debug('cannon:cli');

Expand Down Expand Up @@ -140,6 +141,10 @@ async function configureProvider(options: any, cliSettings: CliSettings) {
signers = _provider.signers;
}

if (options.dryRun && options.chainId === CANNON_CHAIN_ID) {
throw new Error('Cannot perform a dry-run build on local network');
}

if (options.dryRun) {
node = await runRpc(
{
Expand Down Expand Up @@ -206,6 +211,14 @@ async function configureSigners(
getDefaultSigner = async () => signers![0];
}

if (await getDefaultSigner()) {
const defaultSignerAddress = (await getDefaultSigner())!.address;

if (opts.chainId != '13370' && defaultSignerAddress === ANVIL_FIRST_ADDRESS) {
warn(`WARNING: This build is using default anvil address ${ANVIL_FIRST_ADDRESS}`);
}
}

return { getSigner, getDefaultSigner };
}

Expand Down

0 comments on commit c733fc8

Please sign in to comment.