fix: add collateralChainName to warp read (#4822)

### Description
Fixes "warp read does not return collateralChainName for rebase vault
type" and "warp check fails when checking the config because
collateralChainName is missing" of CLI 5.6 Bug Bash

### Backward compatibility
Yes

### Testing
Manual/Unit Tests
pull/4828/head
Lee 2 weeks ago committed by GitHub
parent e89030de30
commit 30d92c3197
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/quick-bags-check.md
  2. 1
      typescript/sdk/src/index.ts
  3. 41
      typescript/sdk/src/token/EvmERC20WarpRouteReader.ts
  4. 6
      typescript/sdk/src/token/config.ts
  5. 1
      typescript/sdk/src/token/schemas.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---
Add `collateralChainName` to Warp Reader. Partial refactor of fetchTokenConfig().

@ -514,6 +514,7 @@ export { MailboxClientConfigSchema as mailboxClientConfigSchema } from './router
export {
CollateralConfig,
NativeConfig,
TokenConfig,
TokenRouterConfigSchema,
WarpRouteDeployConfigSchema,
WarpRouteDeployConfigSchemaErrors,

@ -11,6 +11,7 @@ import {
} from '@hyperlane-xyz/core';
import {
MailboxClientConfig,
TokenConfig,
TokenRouterConfig,
TokenType,
} from '@hyperlane-xyz/sdk';
@ -32,7 +33,6 @@ import { ChainNameOrId } from '../types.js';
import { HyperlaneReader } from '../utils/HyperlaneReader.js';
import { proxyAdmin } from './../deploy/proxy.js';
import { CollateralExtensions } from './config.js';
import { TokenMetadata } from './types.js';
export class EvmERC20WarpRouteReader extends HyperlaneReader {
@ -65,14 +65,14 @@ export class EvmERC20WarpRouteReader extends HyperlaneReader {
// Derive the config type
const type = await this.deriveTokenType(warpRouteAddress);
const baseMetadata = await this.fetchMailboxClientConfig(warpRouteAddress);
const tokenMetadata = await this.fetchTokenMetadata(type, warpRouteAddress);
const tokenConfig = await this.fetchTokenConfig(type, warpRouteAddress);
const remoteRouters = await this.fetchRemoteRouters(warpRouteAddress);
const proxyAdmin = await this.fetchProxyAdminConfig(warpRouteAddress);
const destinationGas = await this.fetchDestinationGas(warpRouteAddress);
return {
...baseMetadata,
...tokenMetadata,
...tokenConfig,
remoteRouters,
proxyAdmin,
destinationGas,
@ -189,11 +189,15 @@ export class EvmERC20WarpRouteReader extends HyperlaneReader {
* @returns A partial ERC20 metadata object containing the token name, symbol, total supply, and decimals.
* Throws if unsupported token type
*/
async fetchTokenMetadata(
async fetchTokenConfig(
type: TokenType,
tokenAddress: Address,
): Promise<TokenMetadata & { token?: string }> {
if (CollateralExtensions.includes(type)) {
): Promise<TokenConfig> {
if (
type === TokenType.collateral ||
type === TokenType.collateralVault ||
type === TokenType.collateralVaultRebase
) {
const erc20 = HypERC20Collateral__factory.connect(
tokenAddress,
this.provider,
@ -202,17 +206,36 @@ export class EvmERC20WarpRouteReader extends HyperlaneReader {
const { name, symbol, decimals, totalSupply } =
await this.fetchERC20Metadata(token);
return { name, symbol, decimals, totalSupply, token };
return { type, name, symbol, decimals, totalSupply, token };
} else if (
type === TokenType.synthetic ||
type === TokenType.syntheticRebase
) {
return this.fetchERC20Metadata(tokenAddress);
const baseMetadata = await this.fetchERC20Metadata(tokenAddress);
if (type === TokenType.syntheticRebase) {
const hypERC4626 = HypERC4626__factory.connect(
tokenAddress,
this.provider,
);
const collateralChainName = this.multiProvider.getChainName(
await hypERC4626.collateralDomain(),
);
return { type, ...baseMetadata, collateralChainName };
}
return { type, ...baseMetadata };
} else if (type === TokenType.native) {
const chainMetadata = this.multiProvider.getChainMetadata(this.chain);
if (chainMetadata.nativeToken) {
const { name, symbol, decimals } = chainMetadata.nativeToken;
return { name, symbol, decimals, totalSupply: 0 };
return {
type,
name,
symbol,
decimals,
totalSupply: 0,
};
} else {
throw new Error(
`Warp route config specifies native token but chain metadata for ${this.chain} does not provide native token details`,

@ -15,12 +15,6 @@ export enum TokenType {
nativeScaled = 'nativeScaled',
}
export const CollateralExtensions = [
TokenType.collateral,
TokenType.collateralVault,
TokenType.collateralVaultRebase,
];
export const gasOverhead = (tokenType: TokenType): number => {
switch (tokenType) {
case TokenType.fastSynthetic:

@ -74,6 +74,7 @@ export const TokenConfigSchema = z.discriminatedUnion('type', [
SyntheticConfigSchema,
SyntheticRebaseConfigSchema,
]);
export type TokenConfig = z.infer<typeof TokenConfigSchema>;
export const TokenRouterConfigSchema = TokenConfigSchema.and(
GasRouterConfigSchema,

Loading…
Cancel
Save