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 { export {
CollateralConfig, CollateralConfig,
NativeConfig, NativeConfig,
TokenConfig,
TokenRouterConfigSchema, TokenRouterConfigSchema,
WarpRouteDeployConfigSchema, WarpRouteDeployConfigSchema,
WarpRouteDeployConfigSchemaErrors, WarpRouteDeployConfigSchemaErrors,

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

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

Loading…
Cancel
Save