Skip to content

Commit

Permalink
Fixes for commands with --yes flag (#3063)
Browse files Browse the repository at this point in the history
### Description

Consistently respect --yes flag for all user prompts in the core and warp deploy commands

### Related issues

Fixes #3056 

### Backward compatibility

Yes

### Testing

Locally with CI test alterations
  • Loading branch information
jmrossy authored Dec 15, 2023
1 parent 9c7dbcb commit dcf8b80
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-laws-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---

Fixes for commands with --yes flag
20 changes: 15 additions & 5 deletions typescript/cli/src/config/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,24 @@ export function readDeploymentArtifacts(filePath: string) {
return artifacts;
}

export async function runDeploymentArtifactStep(
artifactsPath?: string,
message?: string,
selectedChains?: ChainName[],
export async function runDeploymentArtifactStep({
artifactsPath,
message,
selectedChains,
defaultArtifactsPath = './artifacts',
defaultArtifactsNamePattern = 'core-deployment',
): Promise<HyperlaneContractsMap<any> | undefined> {
skipConfirmation = false,
}: {
artifactsPath?: string;
message?: string;
selectedChains?: ChainName[];
defaultArtifactsPath?: string;
defaultArtifactsNamePattern?: string;
skipConfirmation?: boolean;
}): Promise<HyperlaneContractsMap<any> | undefined> {
if (!artifactsPath) {
if (skipConfirmation) return undefined;

const useArtifacts = await confirm({
message: message || 'Do you want use some existing contract addresses?',
});
Expand Down
22 changes: 14 additions & 8 deletions typescript/cli/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface ContextSettings {
key?: string;
promptMessage?: string;
};
skipConfirmation?: boolean;
}

interface CommandContextBase {
Expand All @@ -75,29 +76,34 @@ export async function getContext<P extends ContextSettings>({
chainConfigPath,
coreConfig,
keyConfig,
skipConfirmation,
}: P): Promise<CommandContext<P>> {
const customChains = readChainConfigsIfExists(chainConfigPath);

let signer = undefined;
if (keyConfig) {
const key =
keyConfig.key ||
(await input({
let key: string;
if (keyConfig.key) key = keyConfig.key;
else if (skipConfirmation) throw new Error('No key provided');
else
key = await input({
message:
keyConfig.promptMessage ||
'Please enter a private key or use the HYP_KEY environment variable',
}));
});
signer = keyToSigner(key);
}

let coreArtifacts = undefined;
if (coreConfig) {
coreArtifacts =
(await runDeploymentArtifactStep(
coreConfig.coreArtifactsPath,
coreConfig.promptMessage ||
(await runDeploymentArtifactStep({
artifactsPath: coreConfig.coreArtifactsPath,
message:
coreConfig.promptMessage ||
'Do you want to use some core deployment address artifacts? This is required for PI chains (non-core chains).',
)) || {};
skipConfirmation,
})) || {};
}

const multiProvider = getMultiProvider(customChains, signer);
Expand Down
29 changes: 24 additions & 5 deletions typescript/cli/src/deploy/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,23 @@ export async function runCoreDeploy({
const { customChains, multiProvider, signer } = await getContext({
chainConfigPath,
keyConfig: { key },
skipConfirmation,
});

if (!chains?.length) {
if (skipConfirmation) throw new Error('No chains provided');
chains = await runMultiChainSelectionStep(
customChains,
'Select chains to connect',
true,
);
}
const artifacts = await runArtifactStep(chains, artifactsPath);
const result = await runIsmStep(chains, ismConfigPath);
const artifacts = await runArtifactStep(
chains,
skipConfirmation,
artifactsPath,
);
const result = await runIsmStep(chains, skipConfirmation, ismConfigPath);
// we can either specify the full ISM config or just the multisig config
const isIsmConfig = isISMConfig(result);
const ismConfigs = isIsmConfig ? (result as ChainMap<IsmConfig>) : undefined;
Expand Down Expand Up @@ -118,14 +124,26 @@ export async function runCoreDeploy({
await executeDeploy(deploymentParams);
}

function runArtifactStep(selectedChains: ChainName[], artifactsPath?: string) {
function runArtifactStep(
selectedChains: ChainName[],
skipConfirmation: boolean,
artifactsPath?: string,
) {
logBlue(
'\nDeployments can be totally new or can use some existing contract addresses.',
);
return runDeploymentArtifactStep(artifactsPath, undefined, selectedChains);
return runDeploymentArtifactStep({
artifactsPath,
selectedChains,
skipConfirmation,
});
}

async function runIsmStep(selectedChains: ChainName[], ismConfigPath?: string) {
async function runIsmStep(
selectedChains: ChainName[],
skipConfirmation: boolean,
ismConfigPath?: string,
) {
if (!ismConfigPath) {
logBlue(
'\n',
Expand All @@ -134,6 +152,7 @@ async function runIsmStep(selectedChains: ChainName[], ismConfigPath?: string) {
logGray(
'Example config: https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/cli/typescript/cli/examples/ism.yaml',
);
if (skipConfirmation) throw new Error('ISM config required');
ismConfigPath = await runFileSelectionStep(
'./configs',
'ISM config',
Expand Down
7 changes: 7 additions & 0 deletions typescript/cli/src/deploy/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export async function runWarpDeploy({
chainConfigPath,
coreConfig: { coreArtifactsPath },
keyConfig: { key },
skipConfirmation,
});

if (!warpConfigPath || !isFile(warpConfigPath)) {
if (skipConfirmation) throw new Error('Warp config required');
warpConfigPath = await runFileSelectionStep(
'./configs',
'Warp config',
Expand All @@ -70,6 +72,7 @@ export async function runWarpDeploy({
coreArtifacts,
multiProvider,
signer,
skipConfirmation,
});

const deploymentParams = {
Expand All @@ -95,11 +98,13 @@ async function runBuildConfigStep({
multiProvider,
signer,
coreArtifacts,
skipConfirmation,
}: {
warpRouteConfig: WarpRouteConfig;
multiProvider: MultiProvider;
signer: ethers.Signer;
coreArtifacts?: HyperlaneContractsMap<any>;
skipConfirmation: boolean;
}) {
log('Assembling token configs');
const { base, synthetics } = warpRouteConfig;
Expand Down Expand Up @@ -164,6 +169,8 @@ async function runBuildConfigStep({
for (const [chain, token] of Object.entries(configMap)) {
for (const field of requiredRouterFields) {
if (token[field]) continue;
if (skipConfirmation)
throw new Error(`Field ${field} for token on ${chain} required`);
if (!hasShownInfo) {
logBlue(
'Some router fields are missing. Please enter them now, add them to your warp config, or use the --core flag to use deployment artifacts.',
Expand Down

0 comments on commit dcf8b80

Please sign in to comment.