-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Derive CoreConfig from Mailbox address (#3657)
### Description Creates a new class to derive CoreConfig from Mailbox and their respective hooks and isms ### Drive-by changes <!-- Are there any minor or drive-by changes also included? --> ### Related issues - Fixes #3578 ### Backward compatibility Yes ### Testing Unit Tests through CoreDeployer.hardhat-test.ts
- Loading branch information
Showing
7 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hyperlane-xyz/sdk': minor | ||
--- | ||
|
||
Add EvmCoreReader, minor updates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const DEFAULT_CONTRACT_READ_CONCURRENCY = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { providers } from 'ethers'; | ||
|
||
import { Mailbox__factory } from '@hyperlane-xyz/core'; | ||
import { Address, objMap, promiseObjAll } from '@hyperlane-xyz/utils'; | ||
|
||
import { DEFAULT_CONTRACT_READ_CONCURRENCY } from '../consts/crud.js'; | ||
import { EvmHookReader } from '../hook/read.js'; | ||
import { EvmIsmReader } from '../ism/read.js'; | ||
import { MultiProvider } from '../providers/MultiProvider.js'; | ||
import { ChainName } from '../types.js'; | ||
|
||
import { CoreConfig } from './types.js'; | ||
|
||
interface CoreReader { | ||
deriveCoreConfig(address: Address): Promise<CoreConfig>; | ||
} | ||
|
||
export class EvmCoreReader implements CoreReader { | ||
provider: providers.Provider; | ||
evmHookReader: EvmHookReader; | ||
evmIsmReader: EvmIsmReader; | ||
constructor( | ||
protected readonly multiProvider: MultiProvider, | ||
protected readonly chain: ChainName, | ||
protected readonly concurrency: number = DEFAULT_CONTRACT_READ_CONCURRENCY, | ||
) { | ||
this.provider = this.multiProvider.getProvider(chain); | ||
this.evmHookReader = new EvmHookReader(multiProvider, chain, concurrency); | ||
this.evmIsmReader = new EvmIsmReader(multiProvider, chain, concurrency); | ||
} | ||
|
||
/** | ||
* Derives the core configuration for a given Mailbox address. | ||
* | ||
* @param address - The address of the Mailbox contract. | ||
* @returns A promise that resolves to the CoreConfig object, containing the owner, default ISM, default Hook, and required Hook configurations. | ||
*/ | ||
async deriveCoreConfig(address: Address): Promise<CoreConfig> { | ||
const mailbox = Mailbox__factory.connect(address, this.provider); | ||
const [defaultIsm, defaultHook, requiredHook] = await Promise.all([ | ||
mailbox.defaultIsm(), | ||
mailbox.defaultHook(), | ||
mailbox.requiredHook(), | ||
]); | ||
|
||
// Parallelize each configuration request | ||
const results = await promiseObjAll( | ||
objMap( | ||
{ | ||
owner: mailbox.owner(), | ||
defaultIsm: this.evmIsmReader.deriveIsmConfig(defaultIsm), | ||
defaultHook: this.evmHookReader.deriveHookConfig(defaultHook), | ||
requiredHook: this.evmHookReader.deriveHookConfig(requiredHook), | ||
}, | ||
async (_, readerCall) => readerCall, | ||
), | ||
); | ||
|
||
return results as CoreConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters