Skip to content

Commit

Permalink
Update according to PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Jun 6, 2024
1 parent e05cd60 commit d28ab7d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
3 changes: 1 addition & 2 deletions typescript/cli/src/config/ism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function readIsmConfig(filePath: string) {
return parsedConfig;
}

const ISM_TYPE_DESCRIPTIONS: Record<IsmType, string> = {
const ISM_TYPE_DESCRIPTIONS: Record<string, string> = {
[IsmType.MESSAGE_ID_MULTISIG]: 'Validators need to sign just this messageId',
[IsmType.MERKLE_ROOT_MULTISIG]:
'Validators need to sign the root of the merkle tree of all messages from origin chain',
Expand All @@ -73,7 +73,6 @@ const ISM_TYPE_DESCRIPTIONS: Record<IsmType, string> = {
'ISM where you can deliver messages without any validation (WARNING: only for testing, do not use in production)',
[IsmType.OP_STACK]: '',
[IsmType.PAUSABLE]: '',
[IsmType.CUSTOM]: '',
};

export async function createIsmConfig(
Expand Down
2 changes: 1 addition & 1 deletion typescript/sdk/src/hook/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export enum OnchainHookType {
}

export enum HookType {
ADDRESS = 'address',
CUSTOM = 'custom',
MERKLE_TREE = 'merkleTreeHook',
INTERCHAIN_GAS_PAYMASTER = 'interchainGasPaymaster',
AGGREGATION = 'aggregationHook',
Expand Down
23 changes: 11 additions & 12 deletions typescript/sdk/src/token/EvmERC20WarpModule.hardhat-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
});

// Let's derive it's onchain token type
const { collateral } = evmERC20WarpModule.serialize();
const { deployedTokenRoute } = evmERC20WarpModule.serialize();
const tokenType: TokenType =
await evmERC20WarpModule.reader.deriveTokenType(collateral);
await evmERC20WarpModule.reader.deriveTokenType(deployedTokenRoute);
expect(tokenType).to.equal(TokenType.collateral);
});

Expand All @@ -126,15 +126,14 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
});

// Let's derive it's onchain token type
const { collateralVault: collateralVaultAddr } =
evmERC20WarpModule.serialize();
const { deployedTokenRoute } = evmERC20WarpModule.serialize();
const tokenType: TokenType =
await evmERC20WarpModule.reader.deriveTokenType(collateralVaultAddr);
await evmERC20WarpModule.reader.deriveTokenType(deployedTokenRoute);
expect(tokenType).to.equal(TokenType.collateralVault);

// Validate onchain token values
const collateralVault = HypERC20CollateralVaultDeposit__factory.connect(
collateralVaultAddr,
deployedTokenRoute,
signer,
);
await validateCoreValues(collateralVault);
Expand Down Expand Up @@ -162,13 +161,13 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
});

// Let's derive it's onchain token type
const { synthetic: syntheticAddr } = evmERC20WarpModule.serialize();
const { deployedTokenRoute } = evmERC20WarpModule.serialize();
const tokenType: TokenType =
await evmERC20WarpModule.reader.deriveTokenType(syntheticAddr);
await evmERC20WarpModule.reader.deriveTokenType(deployedTokenRoute);
expect(tokenType).to.equal(TokenType.synthetic);

// Validate onchain token values
const synthetic = HypERC20__factory.connect(syntheticAddr, signer);
const synthetic = HypERC20__factory.connect(deployedTokenRoute, signer);
await validateCoreValues(synthetic);
expect(await synthetic.name()).to.equal(TOKEN_NAME);
expect(await synthetic.symbol()).to.equal(TOKEN_NAME);
Expand All @@ -191,13 +190,13 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
});

// Let's derive it's onchain token type
const { native: nativeAddr } = evmERC20WarpModule.serialize();
const { deployedTokenRoute } = evmERC20WarpModule.serialize();
const tokenType: TokenType =
await evmERC20WarpModule.reader.deriveTokenType(nativeAddr);
await evmERC20WarpModule.reader.deriveTokenType(deployedTokenRoute);
expect(tokenType).to.equal(TokenType.native);

// Validate onchain token values
const native = HypNative__factory.connect(nativeAddr, signer);
const native = HypNative__factory.connect(deployedTokenRoute, signer);
await validateCoreValues(native);
});
});
8 changes: 2 additions & 6 deletions typescript/sdk/src/token/EvmERC20WarpModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Address, ProtocolType, rootLogger } from '@hyperlane-xyz/utils';

import { serializeContracts } from '../contracts/contracts.js';
import { HyperlaneAddresses } from '../contracts/types.js';
import {
HyperlaneModule,
HyperlaneModuleParams,
Expand All @@ -11,14 +9,13 @@ import { AnnotatedEV5Transaction } from '../providers/ProviderType.js';
import { ChainNameOrId } from '../types.js';

import { EvmERC20WarpRouteReader } from './EvmERC20WarpRouteReader.js';
import { HypERC20Factories } from './contracts.js';
import { HypERC20Deployer } from './deploy.js';
import { TokenRouterConfig } from './schemas.js';

export class EvmERC20WarpModule extends HyperlaneModule<
ProtocolType.Ethereum,
TokenRouterConfig,
HyperlaneAddresses<HypERC20Factories> & {
{
deployedTokenRoute: Address;
}
> {
Expand All @@ -31,7 +28,7 @@ export class EvmERC20WarpModule extends HyperlaneModule<
protected readonly multiProvider: MultiProvider,
args: HyperlaneModuleParams<
TokenRouterConfig,
HyperlaneAddresses<HypERC20Factories> & {
{
deployedTokenRoute: Address;
}
>,
Expand Down Expand Up @@ -87,7 +84,6 @@ export class EvmERC20WarpModule extends HyperlaneModule<

return new EvmERC20WarpModule(multiProvider, {
addresses: {
...serializeContracts(deployedContracts),
deployedTokenRoute: deployedContracts[config.type].address,
},
chain,
Expand Down
11 changes: 7 additions & 4 deletions typescript/sdk/src/token/EvmERC20WarpRouteReader.hardhat-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,14 @@ describe('ERC20WarpRouterReader', async () => {
expect(deployedValue).to.equal(value);
}

// Check hook & ism (because they're potentially objects)
expect(derivedConfig.hook?.address).to.equal(config[chain].hook);
expect(derivedConfig.interchainSecurityModule?.address).to.equal(
config[chain].interchainSecurityModule,
// Check hook because they're potentially objects
expect(derivedConfig.hook).to.deep.equal(
await evmERC20WarpRouteReader.evmHookReader.deriveHookConfig(
config[chain].hook as string,
),
);
// Check ism. should return undefined
expect(derivedConfig.interchainSecurityModule).to.be.undefined;

// Check if token values matches
if (derivedConfig.type === TokenType.collateral) {
Expand Down
35 changes: 16 additions & 19 deletions typescript/sdk/src/token/EvmERC20WarpRouteReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@ import {
HypERC20Collateral__factory,
HypERC20__factory,
} from '@hyperlane-xyz/core';
import { HookConfig, TokenRouterConfig, TokenType } from '@hyperlane-xyz/sdk';
import {
MailboxClientConfig,
TokenRouterConfig,
TokenType,
} from '@hyperlane-xyz/sdk';
import { Address, eqAddress, rootLogger } from '@hyperlane-xyz/utils';

import { DEFAULT_CONTRACT_READ_CONCURRENCY } from '../consts/concurrency.js';
import { DerivedHookConfig, EvmHookReader } from '../hook/EvmHookReader.js';
import { DerivedIsmConfig, EvmIsmReader } from '../ism/EvmIsmReader.js';
import { EvmHookReader } from '../hook/EvmHookReader.js';
import { EvmIsmReader } from '../ism/EvmIsmReader.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { ChainNameOrId } from '../types.js';

import { CollateralExtensions } from './config.js';
import { TokenMetadata } from './types.js';

type WarpRouteBaseMetadata = Record<'mailbox' | 'owner', string> & {
hook?: HookConfig;
interchainSecurityModule?: DerivedIsmConfig;
};

export type DerivedTokenRouterConfig = TokenRouterConfig & {
hook?: DerivedHookConfig;
interchainSecurityModule?: DerivedIsmConfig;
};

export class EvmERC20WarpRouteReader {
protected readonly logger = rootLogger.child({
module: 'EvmERC20WarpRouteReader',
Expand Down Expand Up @@ -53,10 +48,12 @@ export class EvmERC20WarpRouteReader {
*/
async deriveWarpRouteConfig(
warpRouteAddress: Address,
): Promise<DerivedTokenRouterConfig> {
): Promise<TokenRouterConfig> {
// Derive the config type
const type = await this.deriveTokenType(warpRouteAddress);
const fetchedBaseMetadata = await this.fetchBaseMetadata(warpRouteAddress);
const fetchedBaseMetadata = await this.fetchMailboxClientConfig(
warpRouteAddress,
);
const fetchedTokenMetadata = await this.fetchTokenMetadata(
type,
warpRouteAddress,
Expand All @@ -66,7 +63,7 @@ export class EvmERC20WarpRouteReader {
...fetchedBaseMetadata,
...fetchedTokenMetadata,
type,
} as DerivedTokenRouterConfig;
} as TokenRouterConfig;
}

/**
Expand Down Expand Up @@ -126,9 +123,9 @@ export class EvmERC20WarpRouteReader {
* @param routerAddress - The address of the Warp Route contract.
* @returns The base metadata for the Warp Route contract, including the mailbox, owner, hook, and ism.
*/
async fetchBaseMetadata(
async fetchMailboxClientConfig(
routerAddress: Address,
): Promise<WarpRouteBaseMetadata> {
): Promise<MailboxClientConfig> {
const warpRoute = HypERC20Collateral__factory.connect(
routerAddress,
this.provider,
Expand Down Expand Up @@ -166,7 +163,7 @@ export class EvmERC20WarpRouteReader {
type: TokenType,
tokenAddress: Address,
): Promise<TokenMetadata & { token?: string }> {
if (type === TokenType.collateral || type === TokenType.collateralVault) {
if (CollateralExtensions.includes(type)) {
const erc20 = HypERC20Collateral__factory.connect(
tokenAddress,
this.provider,
Expand Down
5 changes: 5 additions & 0 deletions typescript/sdk/src/token/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export enum TokenType {
nativeScaled = 'nativeScaled',
}

export const CollateralExtensions = [
TokenType.collateral,
TokenType.collateralVault,
];

export const gasOverhead = (tokenType: TokenType) => {
switch (tokenType) {
case TokenType.fastSynthetic:
Expand Down

0 comments on commit d28ab7d

Please sign in to comment.