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.
pull/3925/merge
J M Rossy 5 months ago committed by GitHub
parent 56f5d88e96
commit 378a5b79f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/quiet-ways-pay.md
  2. 30
      typescript/cli/src/deploy/warp.ts
  3. 2
      typescript/utils/src/validation.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---
Remove extra fields from warp core config

@ -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,

@ -1,7 +1,7 @@
export function assert<T>(
predicate: T,
errorMessage?: string,
): asserts predicate is NonNullable<T> {
): asserts predicate {
if (!predicate) {
throw new Error(errorMessage ?? 'Error');
}

Loading…
Cancel
Save