Skip to content

Commit

Permalink
Add deriveNative. Update to simplify deriveTokenType, to use TokenRou…
Browse files Browse the repository at this point in the history
…terConfig where applicable
  • Loading branch information
ltyu committed Jun 5, 2024
1 parent e726f08 commit 7b40cca
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 130 deletions.
8 changes: 0 additions & 8 deletions typescript/sdk/src/deploy/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ export const OwnerSchema = z.string();
export const OwnableConfigSchema = z.object({
owner: OwnerSchema,
});

export const ProxyFactoryFactoriesSchema = z.object({
staticMerkleRootMultisigIsmFactory: z.string(),
staticMessageIdMultisigIsmFactory: z.string(),
staticAggregationIsmFactory: z.string(),
staticAggregationHookFactory: z.string(),
domainRoutingIsmFactory: z.string(),
});
2 changes: 1 addition & 1 deletion typescript/sdk/src/providers/ProviderType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
TransactionReceipt as VTransactionReceipt,
} from 'viem';

import { Annotated, ProtocolType } from '@hyperlane-xyz/utils';
import { ProtocolType } from '@hyperlane-xyz/utils';

export enum ProviderType {
EthersV5 = 'ethers-v5',
Expand Down
10 changes: 5 additions & 5 deletions typescript/sdk/src/token/EvmERC20WarpModule.hardhat-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import { MultiProvider } from '../providers/MultiProvider.js';
import { ChainMap } from '../types.js';

import { EvmERC20WarpModule } from './EvmERC20WarpModule.js';
import { DerivedTokenRouterConfig } from './EvmERC20WarpRouteReader.js';
import { TokenType } from './config.js';
import { TokenRouterConfig } from './schemas.js';

describe('EvmERC20WarpHyperlaneModule', async () => {
const TOKEN_NAME = 'fake';
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
type: TokenType.collateral,
token: token.address,
hook: hookAddress,
} as DerivedTokenRouterConfig; // cast because baseConfig doesn't fully confirm to DerivedTokenRouterConfig
};

// Deploy using WarpModule
const evmERC20WarpModule = await EvmERC20WarpModule.create({
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
token: vault.address,
hook: hookAddress,
...baseConfig,
} as DerivedTokenRouterConfig; // cast because baseConfig doesn't fully confirm to DerivedTokenRouterConfig
};

// Deploy using WarpModule
const evmERC20WarpModule = await EvmERC20WarpModule.create({
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
decimals: TOKEN_DECIMALS,
totalSupply: TOKEN_SUPPLY,
...baseConfig,
} as DerivedTokenRouterConfig; // cast because baseConfig doesn't fully confirm to DerivedTokenRouterConfig
};

// Deploy using WarpModule
const evmERC20WarpModule = await EvmERC20WarpModule.create({
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('EvmERC20WarpHyperlaneModule', async () => {
type: TokenType.native,
hook: hookAddress,
...baseConfig,
} as DerivedTokenRouterConfig; // cast because baseConfig doesn't fully confirm to DerivedTokenRouterConfig
} as TokenRouterConfig;

// Deploy using WarpModule
const evmERC20WarpModule = await EvmERC20WarpModule.create({
Expand Down
30 changes: 12 additions & 18 deletions typescript/sdk/src/token/EvmERC20WarpModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ import { serializeContracts } from '../contracts/contracts.js';
import { HyperlaneAddresses } from '../contracts/types.js';
import {
HyperlaneModule,
HyperlaneModuleArgs,
HyperlaneModuleParams,
} from '../core/AbstractHyperlaneModule.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { EthersV5Transaction } from '../providers/ProviderType.js';
import { AnnotatedEV5Transaction } from '../providers/ProviderType.js';
import { ChainNameOrId } from '../types.js';

import {
DerivedTokenRouterConfig,
EvmERC20WarpRouteReader,
} from './EvmERC20WarpRouteReader.js';
import { HypERC20Config } from './config.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,
DerivedTokenRouterConfig,
TokenRouterConfig,
HyperlaneAddresses<HypERC20Factories> & {
deployedTokenRoute: Address;
}
Expand All @@ -32,8 +29,8 @@ export class EvmERC20WarpModule extends HyperlaneModule<

constructor(
protected readonly multiProvider: MultiProvider,
args: HyperlaneModuleArgs<
DerivedTokenRouterConfig,
args: HyperlaneModuleParams<
TokenRouterConfig,
HyperlaneAddresses<HypERC20Factories> & {
deployedTokenRoute: Address;
}
Expand All @@ -50,7 +47,7 @@ export class EvmERC20WarpModule extends HyperlaneModule<
* @param address - The address to derive the token router configuration from.
* @returns A promise that resolves to the token router configuration.
*/
public async read(): Promise<DerivedTokenRouterConfig> {
public async read(): Promise<TokenRouterConfig> {
return this.reader.deriveWarpRouteConfig(
this.args.addresses.deployedTokenRoute,
);
Expand All @@ -65,8 +62,8 @@ export class EvmERC20WarpModule extends HyperlaneModule<
* @returns An array of Ethereum transactions that were executed to update the contract, or an error if the update failed.
*/
public async update(
_expectedConfig: DerivedTokenRouterConfig,
): Promise<EthersV5Transaction[]> {
_expectedConfig: TokenRouterConfig,
): Promise<AnnotatedEV5Transaction[]> {
throw Error('Not implemented');
}

Expand All @@ -80,16 +77,13 @@ export class EvmERC20WarpModule extends HyperlaneModule<
*/
public static async create(params: {
chain: ChainNameOrId;
config: DerivedTokenRouterConfig;
config: TokenRouterConfig;
multiProvider: MultiProvider;
}): Promise<EvmERC20WarpModule> {
const { chain, config, multiProvider } = params;
const chainName = multiProvider.getChainName(chain);
const deployer = new HypERC20Deployer(multiProvider);
const deployedContracts = await deployer.deployContracts(
chainName,
config as HypERC20Config,
);
const deployedContracts = await deployer.deployContracts(chainName, config);

return new EvmERC20WarpModule(multiProvider, {
addresses: {
Expand Down
96 changes: 46 additions & 50 deletions typescript/sdk/src/token/EvmERC20WarpRouteReader.hardhat-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
HyperlaneContractsMap,
RouterConfig,
TestChainName,
TokenRouterConfig,
} from '@hyperlane-xyz/sdk';

import { TestCoreApp } from '../core/TestCoreApp.js';
Expand All @@ -24,11 +25,8 @@ import { HyperlaneIsmFactory } from '../ism/HyperlaneIsmFactory.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { ChainMap } from '../types.js';

import {
DerivedTokenRouterConfig,
EvmERC20WarpRouteReader,
} from './EvmERC20WarpRouteReader.js';
import { TokenConfig, TokenType } from './config.js';
import { EvmERC20WarpRouteReader } from './EvmERC20WarpRouteReader.js';
import { TokenType } from './config.js';
import { HypERC20Deployer } from './deploy.js';

describe('ERC20WarpRouterReader', async () => {
Expand Down Expand Up @@ -106,9 +104,7 @@ describe('ERC20WarpRouterReader', async () => {
},
};
// Deploy warp route with config
const warpRoute = await deployer.deploy(
config as ChainMap<TokenConfig & RouterConfig>,
);
const warpRoute = await deployer.deploy(config);
const derivedTokenType = await evmERC20WarpRouteReader.deriveTokenType(
warpRoute[chain][type].address,
);
Expand All @@ -124,23 +120,29 @@ describe('ERC20WarpRouterReader', async () => {
type: TokenType.collateral,
token: token.address,
hook: await mailbox.defaultHook(),
interchainsecurityModule: await mailbox.defaultIsm(),
...baseConfig,
},
};
// Deploy with config
const warpRoute = await deployer.deploy(
config as ChainMap<TokenConfig & RouterConfig>,
);
const warpRoute = await deployer.deploy(config);

// Derive config and check if each value matches
const derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
warpRoute[chain].collateral.address,
);
for (const [key, value] of Object.entries(derivedConfig)) {
const deployedValue = (config[chain] as any)[key];
if (deployedValue) expect(deployedValue).to.equal(value);
if (deployedValue && typeof value === 'string')
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 if token values matches
if (derivedConfig.type === TokenType.collateral) {
expect(derivedConfig.name).to.equal(TOKEN_NAME);
Expand All @@ -164,17 +166,16 @@ describe('ERC20WarpRouterReader', async () => {
},
};
// Deploy with config
const warpRoute = await deployer.deploy(
config as ChainMap<TokenConfig & RouterConfig>,
);
const warpRoute = await deployer.deploy(config);

// Derive config and check if each value matches
const derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
warpRoute[chain].synthetic.address,
);
for (const [key, value] of Object.entries(derivedConfig)) {
const deployedValue = (config[chain] as any)[key];
if (deployedValue) expect(deployedValue).to.equal(value);
if (deployedValue && typeof value === 'string')
expect(deployedValue).to.equal(value);
}

// Check if token values matches
Expand All @@ -192,19 +193,18 @@ describe('ERC20WarpRouterReader', async () => {
hook: await mailbox.defaultHook(),
...baseConfig,
},
};
} as ChainMap<TokenRouterConfig>;
// Deploy with config
const warpRoute = await deployer.deploy(
config as ChainMap<TokenConfig & RouterConfig>,
);
const warpRoute = await deployer.deploy(config);

// Derive config and check if each value matches
const derivedConfig = (await evmERC20WarpRouteReader.deriveWarpRouteConfig(
const derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
warpRoute[chain].native.address,
)) as Extract<DerivedTokenRouterConfig, { type: TokenType.native }>;
);
for (const [key, value] of Object.entries(derivedConfig)) {
const deployedValue = (config[chain] as any)[key];
if (deployedValue) expect(deployedValue).to.equal(value);
if (deployedValue && typeof value === 'string')
expect(deployedValue).to.equal(value);
}

// Check if token values matches
Expand All @@ -213,7 +213,7 @@ describe('ERC20WarpRouterReader', async () => {

it('should return undefined if ism is not set onchain', async () => {
// Create config
let config = {
const config = {
[chain]: {
type: TokenType.collateral,
token: token.address,
Expand All @@ -222,40 +222,36 @@ describe('ERC20WarpRouterReader', async () => {
},
};
// Deploy with config
let warpRoute = await deployer.deploy(
config as ChainMap<TokenConfig & RouterConfig>,
);
const warpRoute = await deployer.deploy(config);

// Derive config and check if each value matches
let derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
const derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
warpRoute[chain].collateral.address,
);

expect(derivedConfig.interchainSecurityModule).to.be.undefined;
const interchainSecurityModule = await mailbox.defaultIsm();
// const interchainSecurityModule = await mailbox.defaultIsm();

// Try with Ism set
config = {
[chain]: {
type: TokenType.collateral,
token: token.address,
hook: await mailbox.defaultHook(),
interchainSecurityModule,
...baseConfig,
},
};
// Deploy with config
warpRoute = await deployer.deploy(
config as ChainMap<TokenConfig & RouterConfig>,
);
// // Try with Ism set
// config = {
// [chain]: {
// type: TokenType.collateral,
// token: token.address,
// hook: await mailbox.defaultHook(),
// interchainSecurityModule,
// ...baseConfig,
// },
// };
// // Deploy with config
// warpRoute = await deployer.deploy(config);

// Derive config and check if each value matches
derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
warpRoute[chain].collateral.address,
);
// // Derive config and check if each value matches
// derivedConfig = await evmERC20WarpRouteReader.deriveWarpRouteConfig(
// warpRoute[chain].collateral.address,
// );

expect(derivedConfig.interchainSecurityModule?.address).to.be.equal(
interchainSecurityModule,
);
// expect(derivedConfig.interchainSecurityModule).to.be.equal(
// interchainSecurityModule,
// );
});
});
Loading

0 comments on commit 7b40cca

Please sign in to comment.