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

Merkle Tree Hook Deployer changes #2747

Merged
merged 22 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
20 changes: 12 additions & 8 deletions typescript/infra/config/environments/test/interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import {
ChainMap,
InterceptorConfig,
InterceptorType,
} from '@hyperlane-xyz/sdk';
import { ChainMap, InterceptorConfig } from '@hyperlane-xyz/sdk';
import { HookType } from '@hyperlane-xyz/sdk/src/hook/types';
import { objMap } from '@hyperlane-xyz/utils';

import { chainToValidator, merkleRootMultisig } from './multisigIsm';
import {
chainToValidator,
merkleRootMultisig,
messageIdMultisig,
} from './multisigIsm';
import { owners } from './owners';

export const merkleRoot: ChainMap<InterceptorConfig> = objMap(
owners,
(chain, _) => {
const config: InterceptorConfig = {
hook: {
type: InterceptorType.HOOK,
type: HookType.MERKLE_ROOT_HOOK,
},
ism: merkleRootMultisig(chainToValidator[chain]),
ism:
Math.random() < 0.5
? merkleRootMultisig(chainToValidator[chain])
: messageIdMultisig(chainToValidator[chain]),
aroralanuk marked this conversation as resolved.
Show resolved Hide resolved
};
return config;
},
Expand Down
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/test/multisigIsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const messageIdMultisig = (validatorKey: string): MultisigIsmConfig => {
// the addresses here must line up with the e2e test's validator addresses
export const multisigIsm: ChainMap<MultisigIsmConfig> = {
// Validators are anvil accounts 4-6
test1: messageIdMultisig('test1'),
test2: merkleRootMultisig('test2'),
test3: messageIdMultisig('test3'),
test1: messageIdMultisig(chainToValidator['test1']),
test2: merkleRootMultisig(chainToValidator['test2']),
test3: messageIdMultisig(chainToValidator['test3']),
};
34 changes: 23 additions & 11 deletions typescript/sdk/src/hook/MerkleRootInterceptorDeployer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import debug from 'debug';

import {
StaticMerkleRootMultisigIsm,
StaticMessageIdMultisigIsm,
} from '@hyperlane-xyz/core';
import { Address } from '@hyperlane-xyz/utils';

import { HyperlaneContracts } from '../contracts/types';
import { HyperlaneDeployer } from '../deploy/HyperlaneDeployer';
import { HyperlaneIsmFactory } from '../ism/HyperlaneIsmFactory';
import { MultisigIsmConfig } from '../ism/types';
import { ModuleType, MultisigIsmConfig } from '../ism/types';
import { MultiProvider } from '../providers/MultiProvider';
import { ChainMap, ChainName } from '../types';

import {
MerkleRootHookFactories,
MerkleRootInterceptorFactories,
MerkleRootIsmFactories,
MultisigIsmFactories,
merkleRootHookFactories,
merkleRootIsmFactories,
} from './contracts';
Expand Down Expand Up @@ -64,14 +68,22 @@ export class MerkleRootInterceptorDeployer extends HyperlaneDeployer<
async deployIsmContracts(
chain: ChainName,
config: MultisigIsmConfig,
): Promise<HyperlaneContracts<MerkleRootIsmFactories>> {
this.logger(`Deploying MerkleRootMultisigIsm to ${chain}`);
const ism = await this.ismFactory.deployMerkleRootMultisigIsm(
chain,
config,
);
return {
ism: ism,
};
): Promise<HyperlaneContracts<MultisigIsmFactories>> {
const ism = await this.ismFactory.deploy(chain, config);
if (config.type === ModuleType.MERKLE_ROOT_MULTISIG) {
this.logger(`Deploying StaticMerkleRootMultisigIsm to ${chain}`);
return {
ism: ism as StaticMerkleRootMultisigIsm,
};
} else if (config.type === ModuleType.MESSAGE_ID_MULTISIG) {
this.logger(`Deploying StaticMessageIdMultisigIsm to ${chain}`);
return {
ism: ism as StaticMessageIdMultisigIsm,
};
} else {
throw new Error(
`Unexpected ISM type ${config.type} for MerkleRootInterceptorDeployer`,
);
}
aroralanuk marked this conversation as resolved.
Show resolved Hide resolved
}
}
13 changes: 10 additions & 3 deletions typescript/sdk/src/hook/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import {
MerkleTreeHook__factory,
StaticMerkleRootMultisigIsm__factory,
StaticMessageIdMultisigIsm__factory,
} from '@hyperlane-xyz/core';

export const merkleRootHookFactories = {
hook: new MerkleTreeHook__factory(),
};

export const messageIdMultisigIsmFactory = {
ism: new StaticMessageIdMultisigIsm__factory(),
};
aroralanuk marked this conversation as resolved.
Show resolved Hide resolved

export type MerkleRootHookFactories = typeof merkleRootHookFactories;
export type MerkleRootIsmFactories = typeof merkleRootIsmFactories;
export type MultisigIsmFactories =
| typeof merkleRootIsmFactories
| typeof messageIdMultisigIsmFactory;

export const merkleRootIsmFactories = {
ism: new StaticMerkleRootMultisigIsm__factory(),
};

export type MerkleRootInterceptorFactories = MerkleRootHookFactories &
MerkleRootIsmFactories;
MultisigIsmFactories;

export type HookFactories = MerkleRootHookFactories;
export type IsmFactories = MerkleRootIsmFactories;
export type IsmFactories = MultisigIsmFactories;

export type InterceptorFactories = HookFactories & IsmFactories;
33 changes: 4 additions & 29 deletions typescript/sdk/src/hook/types.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
import { BigNumber } from 'ethers';

import type { Address } from '@hyperlane-xyz/utils';

import type { MultisigIsmConfig } from '../ism/types';
import { ChainName } from '../types';

export enum InterceptorType {
HOOK = 'hook',
ISM = 'ism',
export enum HookType {
MERKLE_ROOT_HOOK = 'merkleRootHook',
aroralanuk marked this conversation as resolved.
Show resolved Hide resolved
}

export type OpStackHookConfig = {
type: InterceptorType.HOOK;
nativeBridge: Address;
remoteIsm?: Address;
destinationDomain: BigNumber;
destination: ChainName;
};

export type MerkleRootHookConfig = {
type: InterceptorType.HOOK;
type: HookType.MERKLE_ROOT_HOOK;
};

export type MerkleRootInterceptorConfig = {
hook: MerkleRootHookConfig;
ism: MultisigIsmConfig;
};

export type OpStackInterceptorConfig = {
hook: OpStackHookConfig;
ism: OPStackIsmConfig;
};

export type HookConfig = OpStackHookConfig | MerkleRootHookConfig;

export type OPStackIsmConfig = {
type: InterceptorType.ISM;
origin: ChainName;
nativeBridge: Address;
};
export type HookConfig = MerkleRootHookConfig;

export type InterceptorConfig = MerkleRootInterceptorConfig;
4 changes: 1 addition & 3 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ export {
export { MerkleRootInterceptorDeployer } from './hook/MerkleRootInterceptorDeployer';
export {
HookConfig,
HookType,
InterceptorConfig,
InterceptorType,
MerkleRootHookConfig,
OPStackIsmConfig,
OpStackHookConfig,
} from './hook/types';
export {
HyperlaneIsmFactory,
Expand Down
20 changes: 0 additions & 20 deletions typescript/sdk/src/ism/HyperlaneIsmFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
IRoutingIsm__factory,
StaticAggregationIsm__factory,
StaticMOfNAddressSetFactory,
StaticMerkleRootMultisigIsm,
StaticMerkleRootMultisigIsm__factory,
} from '@hyperlane-xyz/core';
import { Address, eqAddress, formatMessage, warn } from '@hyperlane-xyz/utils';

Expand Down Expand Up @@ -124,24 +122,6 @@ export class HyperlaneIsmFactory extends HyperlaneApp<IsmFactoryFactories> {
return IMultisigIsm__factory.connect(address, signer);
}

public async deployMerkleRootMultisigIsm(
chain: ChainName,
config: MultisigIsmConfig,
): Promise<StaticMerkleRootMultisigIsm> {
this.logger(`Deploying Merkle Root Multisig ISM to ${chain}`);
const signer = this.multiProvider.getSigner(chain);
const multisigIsmFactory =
this.getContracts(chain).merkleRootMultisigIsmFactory;
const address = await this.deployMOfNFactory(
chain,
multisigIsmFactory,
config.validators,
config.threshold,
);

return StaticMerkleRootMultisigIsm__factory.connect(address, signer);
}

private async deployRoutingIsm(chain: ChainName, config: RoutingIsmConfig) {
const signer = this.multiProvider.getSigner(chain);
const routingIsmFactory = this.getContracts(chain).routingIsmFactory;
Expand Down
13 changes: 7 additions & 6 deletions typescript/sdk/src/ism/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ import {
IInterchainSecurityModule,
IMultisigIsm,
IRoutingIsm,
StaticMerkleRootMultisigIsm,
StaticMessageIdMultisigIsm,
} from '@hyperlane-xyz/core';
import type { Address } from '@hyperlane-xyz/utils';

import { OPStackIsmConfig } from '../hook/types';
import { ChainMap } from '../types';

export type DeployedIsm =
| IInterchainSecurityModule
| IMultisigIsm
| IAggregationIsm
| IRoutingIsm;
| IRoutingIsm
| StaticMessageIdMultisigIsm
| StaticMerkleRootMultisigIsm;

export enum ModuleType {
UNUSED,
ROUTING,
AGGREGATION,
// DEPRECATED
LEGACY_MULTISIG,
LEGACY_MULTISIG, // DEPRECATED
MERKLE_ROOT_MULTISIG,
MESSAGE_ID_MULTISIG,
}
Expand Down Expand Up @@ -50,5 +52,4 @@ export type IsmConfig =
| Address
| RoutingIsmConfig
| MultisigIsmConfig
| AggregationIsmConfig
| OPStackIsmConfig;
| AggregationIsmConfig;
aroralanuk marked this conversation as resolved.
Show resolved Hide resolved