Skip to content

Commit

Permalink
Fill warp route defaults after reading from file
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed May 23, 2024
1 parent fb94b85 commit 0bd82f1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion typescript/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const validateWarpCommand: CommandModuleWithContext<{ path: string }> = {
path: inputFileCommandOption,
},
handler: async ({ path }) => {
readWarpRouteDeployConfig(path);
await readWarpRouteDeployConfig(path);
logGreen('Config is valid');
process.exit(0);
},
Expand Down
41 changes: 37 additions & 4 deletions typescript/cli/src/config/warp.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { input, select } from '@inquirer/prompts';

import {
ChainMap,
MailboxClientConfig,
TokenType,
WarpCoreConfig,
WarpCoreConfigSchema,
WarpRouteDeployConfig,
WarpRouteDeployConfigSchema,
} from '@hyperlane-xyz/sdk';
import { assert, objMap, promiseObjAll } from '@hyperlane-xyz/utils';

import { CommandContext } from '../context/types.js';
import { errorRed, logBlue, logGreen } from '../logger.js';
Expand Down Expand Up @@ -42,12 +45,43 @@ const TYPE_CHOICES = Object.values(TokenType).map((type) => ({
description: TYPE_DESCRIPTIONS[type],
}));

export function readWarpRouteDeployConfig(
async function fillDefaults(
context: CommandContext,
config: ChainMap<Partial<MailboxClientConfig>>,
): Promise<ChainMap<MailboxClientConfig>> {
return promiseObjAll(
objMap(config, async (chain, config): Promise<MailboxClientConfig> => {
let mailbox = config.mailbox;
if (!mailbox) {
const addresses = await context.registry.getChainAddresses(chain);
assert(addresses, `No addresses found for chain ${chain}`);
mailbox = addresses.mailbox;
}
let owner = config.owner;
if (!owner) {
owner =
(await context.signer?.getAddress()) ??
(await context.multiProvider.getSignerAddress(chain));
}
return {
owner,
mailbox,
...config,
};
}),
);
}

export async function readWarpRouteDeployConfig(
filePath: string,
): WarpRouteDeployConfig {
const config = readYamlOrJson(filePath);
context?: CommandContext,
): Promise<WarpRouteDeployConfig> {
let config = readYamlOrJson(filePath);
if (!config)
throw new Error(`No warp route deploy config found at ${filePath}`);
if (context) {
config = await fillDefaults(context, config as any);
}
return WarpRouteDeployConfigSchema.parse(config);
}

Expand Down Expand Up @@ -76,7 +110,6 @@ export async function createWarpRouteDeployConfig({
);

const result: WarpRouteDeployConfig = {};
WarpRouteDeployConfigSchema;
for (const chain of warpChains) {
logBlue(`Configuring warp route for chain ${chain}`);
const type = await select({
Expand Down
3 changes: 2 additions & 1 deletion typescript/cli/src/deploy/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export async function runWarpRouteDeploy({
`Using warp route deployment config at ${warpRouteDeploymentConfigPath}`,
);
}
const warpRouteConfig = readWarpRouteDeployConfig(
const warpRouteConfig = await readWarpRouteDeployConfig(
warpRouteDeploymentConfigPath,
context,
);

const deploymentParams = {
Expand Down

0 comments on commit 0bd82f1

Please sign in to comment.