From 378a5b79f7230125f7c3e983ebe3ad4bfba19fcb Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Fri, 28 Jun 2024 17:40:39 +0100 Subject: [PATCH] fix: Remove extra fields in warp core config (#4072) ### Description Remove extra fields in warp core configs. Context: https://github.com/hyperlane-xyz/hyperlane-registry/pull/73 Discussion: https://discord.com/channels/935678348330434570/1255901895503908934 ### Drive-by changes Improve type assertion of `assert` util ### Backward compatibility Yes ### Testing Took configs from CLI e2e test artifact and tested it in registry CI. --- .changeset/quiet-ways-pay.md | 5 +++++ typescript/cli/src/deploy/warp.ts | 30 ++++++++++++++---------------- typescript/utils/src/validation.ts | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 .changeset/quiet-ways-pay.md diff --git a/.changeset/quiet-ways-pay.md b/.changeset/quiet-ways-pay.md new file mode 100644 index 000000000..89eed483b --- /dev/null +++ b/.changeset/quiet-ways-pay.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/cli': patch +--- + +Remove extra fields from warp core config diff --git a/typescript/cli/src/deploy/warp.ts b/typescript/cli/src/deploy/warp.ts index 58758eac8..a00974618 100644 --- a/typescript/cli/src/deploy/warp.ts +++ b/typescript/cli/src/deploy/warp.ts @@ -19,7 +19,12 @@ import { isTokenMetadata, serializeContracts, } from '@hyperlane-xyz/sdk'; -import { ProtocolType, objMap, promiseObjAll } from '@hyperlane-xyz/utils'; +import { + ProtocolType, + assert, + objMap, + promiseObjAll, +} from '@hyperlane-xyz/utils'; import { readWarpRouteDeployConfig } from '../config/warp.js'; import { MINIMUM_WARP_DEPLOY_GAS } from '../consts.js'; @@ -261,31 +266,24 @@ async function getWarpCoreConfig( context.multiProvider, configMap, ); + assert( + tokenMetadata && isTokenMetadata(tokenMetadata), + 'Missing required token metadata', + ); + const { decimals, symbol, name } = tokenMetadata; + assert(decimals, 'Missing decimals on token metadata'); // First pass, create token configs for (const [chainName, contract] of Object.entries(contracts)) { const config = configMap[chainName]; - const metadata = { - ...tokenMetadata, - ...config, - }; - - if (!isTokenMetadata(metadata)) { - throw new Error('Missing required token metadata'); - } - - const { decimals } = metadata; - if (!decimals) { - throw new Error('Missing decimals on token metadata'); - } - const collateralAddressOrDenom = config.type === TokenType.collateral ? config.token : undefined; warpCoreConfig.tokens.push({ chainName, standard: TOKEN_TYPE_TO_STANDARD[config.type], - ...metadata, decimals, + symbol, + name, addressOrDenom: contract[configMap[chainName].type as keyof TokenFactories].address, collateralAddressOrDenom, diff --git a/typescript/utils/src/validation.ts b/typescript/utils/src/validation.ts index 1b3dd2289..29ac931c6 100644 --- a/typescript/utils/src/validation.ts +++ b/typescript/utils/src/validation.ts @@ -1,7 +1,7 @@ export function assert( predicate: T, errorMessage?: string, -): asserts predicate is NonNullable { +): asserts predicate { if (!predicate) { throw new Error(errorMessage ?? 'Error'); }