From 30d92c31972cda14d57e9430cf2dc525d15d7373 Mon Sep 17 00:00:00 2001 From: Lee <6251863+ltyu@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:23:25 -0500 Subject: [PATCH] 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 --- .changeset/quick-bags-check.md | 5 +++ typescript/sdk/src/index.ts | 1 + .../sdk/src/token/EvmERC20WarpRouteReader.ts | 41 +++++++++++++++---- typescript/sdk/src/token/config.ts | 6 --- typescript/sdk/src/token/schemas.ts | 1 + 5 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 .changeset/quick-bags-check.md diff --git a/.changeset/quick-bags-check.md b/.changeset/quick-bags-check.md new file mode 100644 index 0000000000..2026982750 --- /dev/null +++ b/.changeset/quick-bags-check.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/sdk': minor +--- + +Add `collateralChainName` to Warp Reader. Partial refactor of fetchTokenConfig(). diff --git a/typescript/sdk/src/index.ts b/typescript/sdk/src/index.ts index 4688acd28c..e57d4895ba 100644 --- a/typescript/sdk/src/index.ts +++ b/typescript/sdk/src/index.ts @@ -514,6 +514,7 @@ export { MailboxClientConfigSchema as mailboxClientConfigSchema } from './router export { CollateralConfig, NativeConfig, + TokenConfig, TokenRouterConfigSchema, WarpRouteDeployConfigSchema, WarpRouteDeployConfigSchemaErrors, diff --git a/typescript/sdk/src/token/EvmERC20WarpRouteReader.ts b/typescript/sdk/src/token/EvmERC20WarpRouteReader.ts index 1ec2e99809..df2ab1affe 100644 --- a/typescript/sdk/src/token/EvmERC20WarpRouteReader.ts +++ b/typescript/sdk/src/token/EvmERC20WarpRouteReader.ts @@ -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 { - if (CollateralExtensions.includes(type)) { + ): Promise { + 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`, diff --git a/typescript/sdk/src/token/config.ts b/typescript/sdk/src/token/config.ts index 08fb750f2b..ae3c596545 100644 --- a/typescript/sdk/src/token/config.ts +++ b/typescript/sdk/src/token/config.ts @@ -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: diff --git a/typescript/sdk/src/token/schemas.ts b/typescript/sdk/src/token/schemas.ts index c92f98ea94..ae9ee15a41 100644 --- a/typescript/sdk/src/token/schemas.ts +++ b/typescript/sdk/src/token/schemas.ts @@ -74,6 +74,7 @@ export const TokenConfigSchema = z.discriminatedUnion('type', [ SyntheticConfigSchema, SyntheticRebaseConfigSchema, ]); +export type TokenConfig = z.infer; export const TokenRouterConfigSchema = TokenConfigSchema.and( GasRouterConfigSchema,