Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: WarpModule with create() #3838

Merged
merged 80 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
eb2172a
Saving initial work
ltyu Apr 29, 2024
8ac752b
draft push
paulbalaji Apr 30, 2024
3686051
Add read to WarpCrud, change totalSupply to use zod schema type, some…
ltyu Apr 30, 2024
2c74413
Derive WarpConfig from TokenRouter address (#3671)
ltyu Apr 29, 2024
fc4a8a4
Saving initial work
ltyu Apr 29, 2024
4da8778
Add read to WarpCrud, change totalSupply to use zod schema type, some…
ltyu Apr 30, 2024
0ccaa38
Fix unit tests. Incorporate some of Paul's Abstract CrudModule changes
ltyu Apr 30, 2024
3632eb8
fix conflicts
ltyu Apr 30, 2024
2c524cc
Re-add a few more overwritten merge lines
ltyu Apr 30, 2024
186a185
Add EvmERC20WarpCrudModule.create()
ltyu May 1, 2024
635ccf3
Add deploy given an Ism Object
ltyu May 1, 2024
10bd6cb
draft push
paulbalaji Apr 30, 2024
0378f8c
split deploy/update in EvmIsmCreator
paulbalaji May 2, 2024
e140813
Add update logic for Hook and ISM. This commit excludes working logic…
ltyu May 2, 2024
9b0a464
Fix conflicts
ltyu May 2, 2024
707967e
Fix conflicts
ltyu May 2, 2024
d40417f
Derive WarpConfig from TokenRouter address (#3671)
ltyu Apr 29, 2024
f32e5fc
Saving initial work
ltyu Apr 29, 2024
cd2e1a6
Derive WarpConfig from TokenRouter address (#3671)
ltyu Apr 29, 2024
062a00b
Saving initial work
ltyu Apr 29, 2024
76eb931
Add read to WarpCrud, change totalSupply to use zod schema type, some…
ltyu Apr 30, 2024
4e30f18
Fix unit tests. Incorporate some of Paul's Abstract CrudModule changes
ltyu Apr 30, 2024
d4cb141
Add read to WarpCrud, change totalSupply to use zod schema type, some…
ltyu Apr 30, 2024
c3ae3bf
Re-add a few more overwritten merge lines
ltyu Apr 30, 2024
fdc41f4
Add EvmERC20WarpCrudModule.create()
ltyu May 1, 2024
1efd295
Add deploy given an Ism Object
ltyu May 1, 2024
3d27f80
Add update logic for Hook and ISM. This commit excludes working logic…
ltyu May 2, 2024
d435b76
Ensure owners are configured correctly (#3677)
yorhodes Apr 30, 2024
8fcc2bc
Migrate SDK consts to Registry and use new registry utilities (#3615)
jmrossy May 1, 2024
80cc359
Avoid sinon import in exported lib files (#3685)
jmrossy May 1, 2024
965f8cd
feat: Modular Tx Submission – Create Transformer + Submitter + Builde…
nbayindirli May 1, 2024
3d439b3
export tx provider from sdk & remove safe util from infra (#3694)
nbayindirli May 2, 2024
c820d15
do not exit if @safe-global/protocol-kit/**/Multi_send.ts dne (#3696)
nbayindirli May 2, 2024
886b2b9
add defaultDescription to yargs --key option (#3697)
nbayindirli May 2, 2024
9e4c0d2
Fix conflicts
ltyu May 2, 2024
2b65365
Fix conflicts... again
ltyu May 3, 2024
9ac51d3
Fix conflicts
ltyu May 3, 2024
7be39b7
Merge branch 'main' into warpCrudModule
ltyu May 3, 2024
43fac78
Implement deployIsm(), clean up duplicate unit tests, add ismFactoryA…
ltyu May 6, 2024
71849ce
Update to use type DerivedTokenRouterConfig instead of base TokenRout…
ltyu May 6, 2024
5a2a289
Add changeset
ltyu May 6, 2024
d5b615d
Fix test name add comments
ltyu May 6, 2024
119e2e5
Merge branch 'main' into warpCrudModule
ltyu May 6, 2024
9d17eec
Fix conflicts
ltyu May 9, 2024
fc37f4e
Fix conflicts - moved additional logic in reader.ts into new EvmERC20…
ltyu May 13, 2024
988151e
Update according to PR comments
ltyu May 13, 2024
3bffa94
Updates according to comments, IsmConfig to always be an object inste…
ltyu May 14, 2024
88f5a41
Remove Hyperlane from name
ltyu May 14, 2024
3c64619
Use Promise.all, reduce extra read() calls
ltyu May 14, 2024
3b1e502
Update updateHook()
ltyu May 14, 2024
497111d
Add logic to encode tx instead of populateTransaction()
ltyu May 15, 2024
b6c2ba3
Add test4
ltyu May 15, 2024
0f2c953
Update tests to use chain, param
ltyu May 15, 2024
ab25db8
Update ProxyFactoryFactoriesSchema vals to be strings
ltyu May 15, 2024
2921096
nan ism module for cherry-picking
paulbalaji May 16, 2024
1a66022
Remove 'crud' from name. Update unit test to accomedate test4. Update…
ltyu May 16, 2024
fa8024a
Update AddressIsmConfig to CustomIsmConfig
ltyu May 16, 2024
d095c35
Update IsmConfig to use custom instead of address
ltyu May 16, 2024
67ec6b0
Merge branch 'cli-2.0' into warpCrudModule
ltyu May 16, 2024
72de4c5
Add Custom Type to DeployedIsmType
ltyu May 16, 2024
40344ac
Merge branch 'warpCrudModule' of https://github.com/hyperlane-xyz/hyp…
ltyu May 16, 2024
dddd0cf
Merge branch 'cli-2.0' into warpCrudModule
ltyu May 21, 2024
50d5d80
Update to fix bug deriving native and synthetic
ltyu May 21, 2024
2e34aaf
Rip out update logic
ltyu May 22, 2024
bd31efe
Update according to PR comments
ltyu May 23, 2024
26fb6d8
Add new changeset file
ltyu May 24, 2024
95b1945
Update typescript/sdk/src/token/EvmERC20WarpModule.ts
ltyu May 24, 2024
33957ea
Update typescript/sdk/src/token/EvmERC20WarpModule.ts
ltyu May 24, 2024
e99f375
Split out WarpModule and Reader tests
ltyu May 24, 2024
911da47
Clean up deploy.hardhat-test.ts
ltyu May 24, 2024
a910681
Add additional tests for create(), support collateralVault test.
ltyu May 24, 2024
07e68f1
Fix linter errors
ltyu May 24, 2024
9bd4308
yorke PR review
ltyu May 28, 2024
e726f08
Fix conflicts
ltyu Jun 5, 2024
7b40cca
Add deriveNative. Update to simplify deriveTokenType, to use TokenRou…
ltyu Jun 5, 2024
526bfca
Add custom type to descriptions
ltyu Jun 5, 2024
ee18f2b
Merge branch 'cli-2.0' into warpCrudModule_createOnly
ltyu Jun 5, 2024
b43bdd4
Revert promise.any
ltyu Jun 5, 2024
e05cd60
Remove extra deploy test
ltyu Jun 5, 2024
d28ab7d
Update according to PR review
ltyu Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-dancers-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Add EvmWarpCrudModule with create() and update()
ltyu marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions typescript/sdk/src/consts/testChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum TestChainName {
test1 = 'test1',
test2 = 'test2',
test3 = 'test3',
test4 = 'test4',
}

export const testChains: Array<ChainName> = Object.values(TestChainName);
Expand Down Expand Up @@ -65,10 +66,24 @@ export const test3: ChainMetadata = {
name: 'test3',
};

export const test4: ChainMetadata = {
...test1,
blocks: {
confirmations: 1,
estimateBlockTime: 3,
reorgPeriod: 2,
},
chainId: 31337,
displayName: 'Test 4',
domainId: 31337,
name: 'test4',
};

export const testChainMetadata: ChainMap<ChainMetadata> = {
test1,
test2,
test3,
test4,
};

export const testCosmosChain: ChainMetadata = {
Expand Down
8 changes: 8 additions & 0 deletions typescript/sdk/src/deploy/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ export const OwnerSchema = z.union([z.string(), AccountConfigSchema]);
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(),
});
1 change: 1 addition & 0 deletions typescript/sdk/src/hook/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum OnchainHookType {
}

export enum HookType {
ADDRESS = 'address',
ltyu marked this conversation as resolved.
Show resolved Hide resolved
ltyu marked this conversation as resolved.
Show resolved Hide resolved
MERKLE_TREE = 'merkleTreeHook',
INTERCHAIN_GAS_PAYMASTER = 'interchainGasPaymaster',
AGGREGATION = 'aggregationHook',
Expand Down
48 changes: 9 additions & 39 deletions typescript/sdk/src/ism/EvmIsmModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, ProtocolType, rootLogger } from '@hyperlane-xyz/utils';

import { HyperlaneContracts } from '../contracts/types.js';
import { HyperlaneAddresses } from '../contracts/types.js';
import {
HyperlaneModule,
HyperlaneModuleArgs,
Expand All @@ -11,79 +11,49 @@ import { MultiProvider } from '../providers/MultiProvider.js';
import { EthersV5Transaction } from '../providers/ProviderType.js';
import { ChainNameOrId } from '../types.js';

import { EvmIsmCreator } from './EvmIsmCreator.js';
import { EvmIsmReader } from './EvmIsmReader.js';
import { DerivedIsmConfigWithAddress, EvmIsmReader } from './EvmIsmReader.js';
import { IsmConfig } from './types.js';

export class EvmIsmModule extends HyperlaneModule<
ProtocolType.Ethereum,
IsmConfig,
HyperlaneContracts<ProxyFactoryFactories> & {
HyperlaneAddresses<ProxyFactoryFactories> & {
deployedIsm: Address;
}
> {
protected logger = rootLogger.child({ module: 'EvmIsmModule' });
protected reader: EvmIsmReader;
protected creator: EvmIsmCreator;

protected constructor(
protected readonly multiProvider: MultiProvider,
protected readonly deployer: HyperlaneDeployer<any, any>,
args: HyperlaneModuleArgs<
IsmConfig,
HyperlaneContracts<ProxyFactoryFactories> & {
HyperlaneAddresses<ProxyFactoryFactories> & {
deployedIsm: Address;
}
>,
) {
super(args);
this.reader = new EvmIsmReader(multiProvider, args.chain);
this.creator = new EvmIsmCreator(deployer, multiProvider, args.addresses);
}

public async read(): Promise<IsmConfig> {
public async read(): Promise<DerivedIsmConfigWithAddress> {
return await this.reader.deriveIsmConfig(this.args.addresses.deployedIsm);
}

public async update(config: IsmConfig): Promise<EthersV5Transaction[]> {
public async update(_config: IsmConfig): Promise<EthersV5Transaction[]> {
ltyu marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Method not implemented.');

const destination = this.multiProvider.getChainName(this.args.chain);
await this.creator.update({
destination,
config,
existingIsmAddress: this.args.addresses.deployedIsm,
});
return [];
}

// manually write static create function
public static async create({
chain,
config,
deployer,
factories,
multiProvider,
}: {
public static async create(_params: {
chain: ChainNameOrId;
config: IsmConfig;
deployer: HyperlaneDeployer<any, any>;
factories: HyperlaneContracts<ProxyFactoryFactories>;
factories: HyperlaneAddresses<ProxyFactoryFactories>;
multiProvider: MultiProvider;
}): Promise<EvmIsmModule> {
const destination = multiProvider.getChainName(chain);
const ismCreator = new EvmIsmCreator(deployer, multiProvider, factories);
const deployedIsm = await ismCreator.deploy({
config,
destination,
});
return new EvmIsmModule(multiProvider, deployer, {
addresses: {
...factories,
deployedIsm: deployedIsm.address,
},
chain,
config,
});
throw new Error('Method not implemented.');
}
}
1 change: 0 additions & 1 deletion typescript/sdk/src/ism/EvmIsmReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class EvmIsmReader implements IsmReader {
this.provider,
);
const moduleType: ModuleType = await ism.moduleType();

ltyu marked this conversation as resolved.
Show resolved Hide resolved
switch (moduleType) {
case ModuleType.UNUSED:
throw new Error('UNUSED does not have a corresponding IsmType');
Expand Down
4 changes: 2 additions & 2 deletions typescript/sdk/src/ism/HyperlaneIsmFactory.hardhat-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ describe('HyperlaneIsmFactory', async () => {
});
const existingIsm = ism.address;
const domainsBefore = await (ism as DomainRoutingIsm).domains();

// deleting the domain and removing from multiprovider should unenroll the domain
// NB: we'll deploy new multisigIsms for the domains bc of new factories but the routingIsm address should be the same because of existingIsmAddress
delete exampleRoutingConfig.domains['test3'];
multiProvider = multiProvider.intersect([
TestChainName.test1,
'test2',
TestChainName.test2,
ltyu marked this conversation as resolved.
Show resolved Hide resolved
TestChainName.test4,
]).result;
ismFactoryDeployer = new HyperlaneProxyFactoryDeployer(multiProvider);
ismFactory = new HyperlaneIsmFactory(
Expand Down
12 changes: 11 additions & 1 deletion typescript/sdk/src/ism/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
IAggregationIsm,
IInterchainSecurityModule,
IMultisigIsm,
IRoutingIsm,
OPStackIsm,
Expand Down Expand Up @@ -28,6 +29,7 @@ export enum ModuleType {
// this enum can be adjusted as per deployments necessary
// meant for the deployer and checker
export enum IsmType {
CUSTOM = 'custom',
OP_STACK = 'opStackIsm',
ROUTING = 'domainRoutingIsm',
FALLBACK_ROUTING = 'defaultFallbackRoutingIsm',
Expand Down Expand Up @@ -55,6 +57,7 @@ export function ismTypeToModuleType(ismType: IsmType): ModuleType {
case IsmType.OP_STACK:
case IsmType.TEST_ISM:
case IsmType.PAUSABLE:
case IsmType.CUSTOM:
ltyu marked this conversation as resolved.
Show resolved Hide resolved
case IsmType.TRUSTED_RELAYER:
return ModuleType.NULL;
}
Expand Down Expand Up @@ -100,8 +103,14 @@ export type TrustedRelayerIsmConfig = {
relayer: Address;
};

export type CustomIsmConfig = {
type: IsmType.CUSTOM;
address: Address;
};

export type IsmConfig =
| Address
| Address // @todo Remove after https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/3773 is implemented
ltyu marked this conversation as resolved.
Show resolved Hide resolved
| CustomIsmConfig
| RoutingIsmConfig
| MultisigIsmConfig
| AggregationIsmConfig
Expand All @@ -111,6 +120,7 @@ export type IsmConfig =
| TrustedRelayerIsmConfig;

export type DeployedIsmType = {
[IsmType.CUSTOM]: IInterchainSecurityModule;
[IsmType.ROUTING]: IRoutingIsm;
[IsmType.FALLBACK_ROUTING]: IRoutingIsm;
[IsmType.AGGREGATION]: IAggregationIsm;
Expand Down
19 changes: 18 additions & 1 deletion typescript/sdk/src/providers/ProviderType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
TransactionReceipt as VTransactionReceipt,
} from 'viem';

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

export enum ProviderType {
EthersV5 = 'ethers-v5',
Expand Down Expand Up @@ -203,6 +203,23 @@ export interface EthersV5Transaction
transaction: EV5Transaction;
}

export function createAnnotatedEthersV5Transaction(params: {
annotation: string;
chainId: number;
to: string;
data: string;
}): Annotated<EthersV5Transaction> {
return {
annotation: params.annotation,
type: ProviderType.EthersV5,
transaction: {
chainId: params.chainId,
to: params.to,
data: params.data,
},
};
}

// export interface EthersV6Transaction extends TypedTransactionBase<Ev6Transaction> {
// type: ProviderType.EthersV6;
// contract: Ev6Transaction;
Expand Down
2 changes: 1 addition & 1 deletion typescript/sdk/src/router/HyperlaneRouterChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class HyperlaneRouterChecker<
const router = this.app.router(this.app.getContracts(chain));

const checkMailboxClientProperty = async (
property: keyof MailboxClientConfig,
property: keyof Omit<MailboxClientConfig, 'ismFactoryAddresses'>,
ltyu marked this conversation as resolved.
Show resolved Hide resolved
actual: string,
violationType: ClientViolationType,
) => {
Expand Down
6 changes: 5 additions & 1 deletion typescript/sdk/src/router/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { z } from 'zod';

import { OwnableConfigSchema } from '../deploy/schemas.js';
import {
OwnableConfigSchema,
ProxyFactoryFactoriesSchema,
} from '../deploy/schemas.js';
import { ZHash } from '../index.js';
import { IsmConfigSchema } from '../ism/schemas.js';

Expand All @@ -12,6 +15,7 @@ export const MailboxClientConfigSchema = z.object({
mailbox: ZHash,
hook: ZHash.optional(),
interchainSecurityModule: IsmConfigSchema.optional(),
ismFactoryAddresses: ProxyFactoryFactoriesSchema.optional(),
ltyu marked this conversation as resolved.
Show resolved Hide resolved
});

export const routerConfigSchema = MailboxClientConfigSchema.merge(
Expand Down
103 changes: 103 additions & 0 deletions typescript/sdk/src/token/EvmERC20WarpModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Address, ProtocolType, rootLogger } from '@hyperlane-xyz/utils';

import { HyperlaneContracts } from '../contracts/types.js';
import {
HyperlaneModule,
HyperlaneModuleArgs,
} from '../core/AbstractHyperlaneModule.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { EthersV5Transaction } from '../providers/ProviderType.js';
import { RouterConfig } from '../router/types.js';
import { ChainMap, ChainNameOrId } from '../types.js';

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

export class EvmERC20WarpModule extends HyperlaneModule<
ProtocolType.Ethereum,
DerivedTokenRouterConfig,
HyperlaneContracts<HypERC20Factories> & {
deployedTokenRoute: Address;
}
> {
protected logger = rootLogger.child({
module: 'EvmERC20WarpModule',
});
reader: EvmERC20WarpRouteReader;

constructor(
protected readonly multiProvider: MultiProvider,
args: HyperlaneModuleArgs<
DerivedTokenRouterConfig,
HyperlaneContracts<HypERC20Factories> & {
deployedTokenRoute: Address;
}
>,
) {
super(args);

this.reader = new EvmERC20WarpRouteReader(multiProvider, args.chain);
}

/**
* Retrieves the token router configuration for the specified address.
*
* @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> {
return this.reader.deriveWarpRouteConfig(
this.args.addresses.deployedTokenRoute,
);
}

/**
* Updates the Warp Route contract with the provided configuration.
*
* @remark Currently only supports updating ISM or hook
ltyu marked this conversation as resolved.
Show resolved Hide resolved
*
* @param expectedConfig - The configuration for the token router to be updated.
* @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[]> {
throw Error('Not implemented');
}

/**
* Deploys the Warp Route
ltyu marked this conversation as resolved.
Show resolved Hide resolved
*
* @param chain - The chain to deploy the module on.
* @param config - The configuration for the token router.
* @param multiProvider - The multi-provider instance to use.
* @returns A new instance of the EvmERC20WarpHyperlaneModule.
*/
public static async create(params: {
chain: ChainNameOrId;
config: DerivedTokenRouterConfig;
multiProvider: MultiProvider;
}): Promise<EvmERC20WarpModule> {
const { chain, config, multiProvider } = params;
const deployer = new HypERC20Deployer(multiProvider);
const deployedContracts = await deployer.deploy({
[chain]: config,
} as ChainMap<TokenConfig & RouterConfig>);

return new EvmERC20WarpModule(multiProvider, {
addresses: {
...deployedContracts[chain],
deployedTokenRoute:
deployedContracts[chain][config.type as DerivedTokenType].address,
},
chain,
config,
});
}
}
Loading
Loading