Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dan/sealevel-merkle-i…
Browse files Browse the repository at this point in the history
…ndexer
  • Loading branch information
daniel-savu committed Dec 15, 2023
2 parents 0f28010 + dcf8b80 commit 40cda52
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 38 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
5 changes: 5 additions & 0 deletions .changeset/purple-bulldogs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---

Remove domainId and protocolType setting when creating chain config
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
23 changes: 3 additions & 20 deletions typescript/cli/src/config/chain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { confirm, input, select } from '@inquirer/prompts';
import { input } from '@inquirer/prompts';

import {
ChainMap,
Expand Down Expand Up @@ -81,30 +81,13 @@ export async function createChainConfig({
message: 'Enter chain name (one word, lower case)',
});
const chainId = await input({ message: 'Enter chain id (number)' });
const skipDomain = await confirm({
message: 'Will the domainId match the chainId (recommended)?',
});
let domainId: string;
if (skipDomain) {
domainId = chainId;
} else {
domainId = await input({
message: 'Enter domain id (number, often matches chainId)',
});
}
const protocol = await select({
message: 'Select protocol type',
choices: Object.values(ProtocolType).map((protocol) => ({
name: protocol,
value: protocol,
})),
});
const domainId = chainId;
const rpcUrl = await input({ message: 'Enter http or https rpc url' });
const metadata: ChainMetadata = {
name,
chainId: parseInt(chainId, 10),
domainId: parseInt(domainId, 10),
protocol,
protocol: ProtocolType.Ethereum,
rpcUrls: [{ http: rpcUrl }],
};
const parseResult = ChainMetadataSchema.safeParse(metadata);
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 40cda52

Please sign in to comment.