Skip to content

Commit

Permalink
fix: add collateralChainName to warp read (#4822)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
ltyu authored Nov 6, 2024
1 parent e89030d commit 30d92c3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-bags-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Add `collateralChainName` to Warp Reader. Partial refactor of fetchTokenConfig().
1 change: 1 addition & 0 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export { MailboxClientConfigSchema as mailboxClientConfigSchema } from './router
export {
CollateralConfig,
NativeConfig,
TokenConfig,
TokenRouterConfigSchema,
WarpRouteDeployConfigSchema,
WarpRouteDeployConfigSchemaErrors,
Expand Down
41 changes: 32 additions & 9 deletions typescript/sdk/src/token/EvmERC20WarpRouteReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@hyperlane-xyz/core';
import {
MailboxClientConfig,
TokenConfig,
TokenRouterConfig,
TokenType,
} from '@hyperlane-xyz/sdk';
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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`,
Expand Down
6 changes: 0 additions & 6 deletions typescript/sdk/src/token/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions typescript/sdk/src/token/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 30d92c3

Please sign in to comment.