Skip to content

Commit

Permalink
addressing asa and rossy's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Jul 11, 2023
1 parent 5bfbf78 commit 7321318
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 123 deletions.
4 changes: 2 additions & 2 deletions rust/agents/relayer/src/msg/metadata/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::msg::metadata::multisig::{
MessageIdMultisigMetadataBuilder,
};
use crate::msg::metadata::{
AggregationIsmMetadataBuilder, NoMetadataBuilder, RoutingIsmMetadataBuilder,
AggregationIsmMetadataBuilder, NullMetadataBuilder, RoutingIsmMetadataBuilder,
};

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -86,7 +86,7 @@ impl MetadataBuilder for BaseMetadataBuilder {
ModuleType::MessageIdMultisig => Box::new(MessageIdMultisigMetadataBuilder::new(base)),
ModuleType::Routing => Box::new(RoutingIsmMetadataBuilder::new(base)),
ModuleType::Aggregation => Box::new(AggregationIsmMetadataBuilder::new(base)),
ModuleType::Null => Box::new(NoMetadataBuilder::new()),
ModuleType::Null => Box::new(NullMetadataBuilder::new()),
_ => return Err(MetadataBuilderError::UnsupportedModuleType(module_type).into()),
};
metadata_builder
Expand Down
4 changes: 2 additions & 2 deletions rust/agents/relayer/src/msg/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod aggregation;
mod base;
mod multisig;
mod no_metadata;
mod null_metadata;
mod routing;

use aggregation::AggregationIsmMetadataBuilder;
pub(crate) use base::BaseMetadataBuilder;
pub(crate) use base::MetadataBuilder;
use no_metadata::NoMetadataBuilder;
use null_metadata::NullMetadataBuilder;
use routing::RoutingIsmMetadataBuilder;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use tracing::instrument;
use hyperlane_core::{HyperlaneMessage, H256};

#[derive(Clone, Debug, new)]
pub struct NoMetadataBuilder {}
pub struct NullMetadataBuilder {}

#[async_trait]
impl MetadataBuilder for NoMetadataBuilder {
impl MetadataBuilder for NullMetadataBuilder {
#[instrument(err, skip(self))]
async fn build(
&self,
Expand Down
51 changes: 25 additions & 26 deletions typescript/infra/config/environments/mainnet2/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import { ChainMap, objMap } from '@hyperlane-xyz/sdk';
import {
ChainMap,
HookConfig,
HookContractType,
MessageHookConfig,
NativeType,
NoMetadataIsmConfig,
} from '@hyperlane-xyz/sdk/dist/hook/types';
import { types } from '@hyperlane-xyz/utils';
objMap,
} from '@hyperlane-xyz/sdk';
import { filteredOwners } from '@hyperlane-xyz/utils';

import { owners } from './owners';

const filteredOwners: ChainMap<types.Address> = Object.keys(owners).reduce(
(local, chain) => {
if (chain === 'ethereum' || chain === 'optimism') {
local[chain] = owners[chain];
const chainNameFilter = new Set(['ethereum', 'optimism']);
const filteredOwnersResult = filteredOwners(owners, chainNameFilter);

export const hooks: ChainMap<HookConfig> = objMap(
filteredOwnersResult,
(chain) => {
if (chain === 'ethereum') {
const hookConfig: MessageHookConfig = {
hookContractType: HookContractType.HOOK,
nativeBridge: '0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy, remoteISM should be deployed first
destinationDomain: 10,
};
return hookConfig;
} else {
const ismConfig: NoMetadataIsmConfig = {
hookContractType: HookContractType.ISM,
nativeBridge: '0x4200000000000000000000000000000000000007',
};
return ismConfig;
}
return local;
},
{} as ChainMap<types.Address>,
);

export const hooks: ChainMap<HookConfig> = objMap(filteredOwners, (chain) => {
if (chain === 'ethereum') {
return {
nativeType: NativeType.HOOK,
nativeBridge: '0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy, remoteISM should be deployed first
destinationDomain: 10,
} as MessageHookConfig;
} else {
return {
nativeType: NativeType.ISM,
nativeBridge: '0x4200000000000000000000000000000000000007',
} as NoMetadataIsmConfig;
}
});
46 changes: 22 additions & 24 deletions typescript/infra/config/environments/test/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import { ChainMap, objMap } from '@hyperlane-xyz/sdk';
import {
HookConfig,
HookContractType,
MessageHookConfig,
NativeType,
NoMetadataIsmConfig,
} from '@hyperlane-xyz/sdk/dist/hook/types';
import { types } from '@hyperlane-xyz/utils';
import { filteredOwners } from '@hyperlane-xyz/utils';

import { owners } from './owners';

const filteredOwners: ChainMap<types.Address> = Object.keys(owners).reduce(
(local, chain) => {
if (chain === 'test1' || chain === 'test2') {
local[chain] = owners[chain];
const chainNameFilter = new Set(['test1', 'test2']);
const filteredOwnersResult = filteredOwners(owners, chainNameFilter);

export const hooks: ChainMap<HookConfig> = objMap(
filteredOwnersResult,
(chain) => {
if (chain === 'test1') {
const hookConfig: MessageHookConfig = {
hookContractType: HookContractType.HOOK,
nativeBridge: '0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy, remoteISM should be deployed first
destinationDomain: 10,
};
return hookConfig;
} else {
const ismConfig: NoMetadataIsmConfig = {
hookContractType: HookContractType.ISM,
nativeBridge: '0x4200000000000000000000000000000000000007',
};
return ismConfig;
}
return local;
},
{} as ChainMap<types.Address>,
);

export const hooks: ChainMap<HookConfig> = objMap(filteredOwners, (chain) => {
if (chain === 'test1') {
return {
nativeType: NativeType.HOOK,
nativeBridge: '0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy, remoteISM should be deployed first
destinationDomain: 10,
} as MessageHookConfig;
} else {
return {
nativeType: NativeType.ISM,
nativeBridge: '0x4200000000000000000000000000000000000007',
} as NoMetadataIsmConfig;
}
});
46 changes: 22 additions & 24 deletions typescript/infra/config/environments/testnet3/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import { ChainMap, objMap } from '@hyperlane-xyz/sdk';
import {
HookConfig,
HookContractType,
MessageHookConfig,
NativeType,
NoMetadataIsmConfig,
} from '@hyperlane-xyz/sdk/dist/hook/types';
import { types } from '@hyperlane-xyz/utils';
import { filteredOwners } from '@hyperlane-xyz/utils';

import { owners } from './owners';

const filteredOwners: ChainMap<types.Address> = Object.keys(owners).reduce(
(local, chain) => {
if (chain === 'goerli' || chain === 'optimismgoerli') {
local[chain] = owners[chain];
const chainNameFilter = new Set(['goerli', 'optimismgoerli']);
const filteredOwnersResult = filteredOwners(owners, chainNameFilter);

export const hooks: ChainMap<HookConfig> = objMap(
filteredOwnersResult,
(chain) => {
if (chain === 'goerli') {
const hookConfig: MessageHookConfig = {
hookContractType: HookContractType.HOOK,
nativeBridge: '0x5086d1eEF304eb5284A0f6720f79403b4e9bE294',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy, remoteISM should be deployed first
destinationDomain: 420,
};
return hookConfig;
} else {
const ismConfig: NoMetadataIsmConfig = {
hookContractType: HookContractType.ISM,
nativeBridge: '0x4200000000000000000000000000000000000007',
};
return ismConfig;
}
return local;
},
{} as ChainMap<types.Address>,
);

export const hooks: ChainMap<HookConfig> = objMap(filteredOwners, (chain) => {
if (chain === 'goerli') {
return {
nativeType: NativeType.HOOK,
nativeBridge: '0x5086d1eEF304eb5284A0f6720f79403b4e9bE294',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy, remoteISM should be deployed first
destinationDomain: 420,
} as MessageHookConfig;
} else {
return {
nativeType: NativeType.ISM,
nativeBridge: '0x4200000000000000000000000000000000000007',
} as NoMetadataIsmConfig;
}
});
2 changes: 1 addition & 1 deletion typescript/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@types/chai": "^4.2.21",
"@types/mocha": "^9.1.0",
"@types/node": "^18.0.0",
"@types/node": "^16.9.1",
"@types/prompts": "^2.0.14",
"@types/yargs": "^17.0.10",
"chai": "^4.3.4",
Expand Down
1 change: 0 additions & 1 deletion typescript/infra/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ async function main() {
deployer = new HyperlaneHookDeployer(multiProvider);
} else if (module === Modules.INTERCHAIN_GAS_PAYMASTER) {
config = envConfig.igp;
console.log(envConfig);
deployer = new HyperlaneIgpDeployer(multiProvider);
} else if (module === Modules.INTERCHAIN_ACCOUNTS) {
config = await getRouterConfig(environment, multiProvider);
Expand Down
9 changes: 5 additions & 4 deletions typescript/infra/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,12 @@ export async function getHooksProvider(
}
for (const chain of Object.keys(hooksConfig)) {
// need to use different url for two forks simultaneously
// need another rpc param
await useLocalProvider(multiProvider, chain);
const signer = await impersonateAccount(
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
);
hooksProvider.setSigner(chain, signer);
}
const signer = await impersonateAccount(
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
);
hooksProvider.setSharedSigner(signer);
return hooksProvider;
}
2 changes: 1 addition & 1 deletion typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@types/node": "^18.0.0",
"@types/node": "^16.9.1",
"chai": "^4.3.6",
"dotenv": "^10.0.0",
"eslint": "^8.43.0",
Expand Down
27 changes: 5 additions & 22 deletions typescript/sdk/src/hook/HyperlaneHookDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TestRecipient__factory,
} from '@hyperlane-xyz/core';
import { types } from '@hyperlane-xyz/utils';
import { addressToBytes32 } from '@hyperlane-xyz/utils/dist/src/utils';

import { HyperlaneContracts, HyperlaneContractsMap } from '../contracts';
import { HyperlaneDeployer } from '../deploy/HyperlaneDeployer';
Expand Down Expand Up @@ -43,7 +44,7 @@ export class HyperlaneHookDeployer extends HyperlaneDeployer<
}

// Ensure ISM contracts have been deployed
if (!ismContracts) {
if (!ismContracts || !ismContracts?.optimismISM) {
throw new Error('ISM contracts not deployed');
}

Expand All @@ -57,7 +58,7 @@ export class HyperlaneHookDeployer extends HyperlaneDeployer<
}

// Ensure hook contracts have been deployed
if (!hookContracts) {
if (!hookContracts || !hookContracts?.optimismMessageHook) {
throw new Error('Hook contracts not deployed');
}

Expand All @@ -80,7 +81,7 @@ export class HyperlaneHookDeployer extends HyperlaneDeployer<
hookConfig: HookConfig,
): Promise<HyperlaneContracts<HookFactories>> {
let optimismISM, optimismMessageHook, testRecipient;
this.logger(`Deploying ${hookConfig.nativeType} on ${chain}`);
this.logger(`Deploying ${hookConfig.hookContractType} on ${chain}`);
if (isISMConfig(hookConfig)) {
optimismISM = await this.deployOptimismISM(
chain,
Expand All @@ -91,7 +92,7 @@ export class HyperlaneHookDeployer extends HyperlaneDeployer<
optimismISM.address,
);
this.logger(
`Deployed test recipient on ${chain} at ${this.padToBytes32(
`Deployed test recipient on ${chain} at ${addressToBytes32(
testRecipient.address,
)}`,
);
Expand Down Expand Up @@ -165,22 +166,4 @@ export class HyperlaneHookDeployer extends HyperlaneDeployer<
);
return optimismMessageHook;
}

// Function to pad a hexadecimal string to 32 bytes
padToBytes32(hexString: string): string {
// Check that it is indeed a hexidecimal string
if (typeof hexString !== 'string' || !/^0x[0-9a-fA-F]*$/.test(hexString)) {
throw new Error('The input should be a hexadecimal string');
}

// If the hexString is shorter than 64 characters (64 characters = 32 bytes),
// add leading zeroes to make it 32 bytes long
const unprefixedHexString = hexString.replace(/^0x/, ''); // remove '0x'
if (unprefixedHexString.length < 64) {
return `0x${unprefixedHexString.padStart(64, '0')}`;
}

// If it is already 32 bytes long or longer, just return it.
return hexString;
}
}
7 changes: 4 additions & 3 deletions typescript/sdk/src/hook/config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
HookConfig,
HookContractType,
MessageHookConfig,
NativeType,
NoMetadataIsmConfig,
} from './types';

export const isISMConfig = (
config: HookConfig,
): config is NoMetadataIsmConfig => config.nativeType === NativeType.ISM;
): config is NoMetadataIsmConfig =>
config.hookContractType === HookContractType.ISM;

export const isHookConfig = (config: HookConfig): config is MessageHookConfig =>
config.nativeType === NativeType.HOOK;
config.hookContractType === HookContractType.HOOK;
6 changes: 3 additions & 3 deletions typescript/sdk/src/hook/types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { types } from '@hyperlane-xyz/utils';

export enum NativeType {
export enum HookContractType {
HOOK = 'hook',
ISM = 'ism',
}

export type MessageHookConfig = {
nativeType: NativeType.HOOK;
hookContractType: HookContractType.HOOK;
nativeBridge: types.Address;
remoteIsm: types.Address;
destinationDomain: number;
};

export type NoMetadataIsmConfig = {
nativeType: NativeType.ISM;
hookContractType: HookContractType.ISM;
nativeBridge: types.Address;
};

Expand Down
9 changes: 7 additions & 2 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export {
IgpViolationType,
OverheadIgpConfig,
} from './gas/types';
export { HyperlaneHookDeployer } from './hook/HyperlaneHookDeployer';
export {
HookConfig,
HookContractType,
MessageHookConfig,
NoMetadataIsmConfig,
} from './hook/types';
export {
HyperlaneIsmFactory,
collectValidators,
Expand Down Expand Up @@ -172,5 +179,3 @@ export {
} from './utils/objects';
export { delay } from './utils/time';
export { chainMetadataToWagmiChain } from './utils/wagmi';
export { HookConfig } from './hook/types';
export { HyperlaneHookDeployer } from './hook/HyperlaneHookDeployer';
Loading

0 comments on commit 7321318

Please sign in to comment.