@ -84,6 +84,12 @@ export interface HookReader {
export class EvmHookReader extends HyperlaneReader implements HookReader {
export class EvmHookReader extends HyperlaneReader implements HookReader {
protected readonly logger = rootLogger . child ( { module : 'EvmHookReader' } ) ;
protected readonly logger = rootLogger . child ( { module : 'EvmHookReader' } ) ;
/ * *
* HookConfig cache for already retrieved configs . Useful to avoid recomputing configs
* when they have already been retrieved in previous calls where ` deriveHookConfig ` was called by
* the specific hook methods .
* /
private _cache : Map < Address , any > = new Map ( ) ;
constructor (
constructor (
protected readonly multiProvider : MultiProvider ,
protected readonly multiProvider : MultiProvider ,
@ -96,12 +102,25 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
}
}
async deriveHookConfig ( address : Address ) : Promise < DerivedHookConfig > {
async deriveHookConfig ( address : Address ) : Promise < DerivedHookConfig > {
this . logger . debug ( 'Deriving HookConfig:' , { address } ) ;
const cachedValue = this . _cache . get ( address ) ;
if ( cachedValue ) {
this . logger . debug (
` Cache hit for HookConfig on chain ${ this . chain } at: ${ address } ` ,
) ;
return cachedValue ;
}
this . logger . debug (
` Cache miss for HookConfig on chain ${ this . chain } at: ${ address } ` ,
) ;
return retryAsync ( async ( ) = > {
return retryAsync ( async ( ) = > {
let onchainHookType : OnchainHookType | undefined = undefined ;
let onchainHookType : OnchainHookType | undefined = undefined ;
let derivedHookConfig : DerivedHookConfig ;
let derivedHookConfig : DerivedHookConfig ;
try {
try {
const hook = IPostDispatchHook__factory . connect ( address , this . provider ) ;
const hook = IPostDispatchHook__factory . connect ( address , this . provider ) ;
this . logger . debug ( 'Deriving HookConfig:' , { address } ) ;
// Temporarily turn off SmartProvider logging
// Temporarily turn off SmartProvider logging
// Provider errors are expected because deriving will call methods that may not exist in the Bytecode
// Provider errors are expected because deriving will call methods that may not exist in the Bytecode
@ -171,10 +190,14 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const hook = MerkleTreeHook__factory . connect ( address , this . provider ) ;
const hook = MerkleTreeHook__factory . connect ( address , this . provider ) ;
this . assertHookType ( await hook . hookType ( ) , OnchainHookType . MERKLE_TREE ) ;
this . assertHookType ( await hook . hookType ( ) , OnchainHookType . MERKLE_TREE ) ;
return {
const config : WithAddress < MerkleTreeHookConfig > = {
address ,
address ,
type : HookType . MERKLE_TREE ,
type : HookType . MERKLE_TREE ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveAggregationConfig (
async deriveAggregationConfig (
@ -190,11 +213,15 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
( hook ) = > this . deriveHookConfig ( hook ) ,
( hook ) = > this . deriveHookConfig ( hook ) ,
) ;
) ;
return {
const config : WithAddress < AggregationHookConfig > = {
address ,
address ,
type : HookType . AGGREGATION ,
type : HookType . AGGREGATION ,
hooks : hookConfigs ,
hooks : hookConfigs ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveIgpConfig ( address : Address ) : Promise < WithAddress < IgpHookConfig > > {
async deriveIgpConfig ( address : Address ) : Promise < WithAddress < IgpHookConfig > > {
@ -262,7 +289,7 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
oracleKey = resolvedOracleKeys [ 0 ] ;
oracleKey = resolvedOracleKeys [ 0 ] ;
}
}
return {
const config : WithAddress < IgpHookConfig > = {
owner ,
owner ,
address ,
address ,
type : HookType . INTERCHAIN_GAS_PAYMASTER ,
type : HookType . INTERCHAIN_GAS_PAYMASTER ,
@ -271,6 +298,10 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
overhead ,
overhead ,
oracleConfig ,
oracleConfig ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveProtocolFeeConfig (
async deriveProtocolFeeConfig (
@ -284,7 +315,7 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const protocolFee = await hook . protocolFee ( ) ;
const protocolFee = await hook . protocolFee ( ) ;
const beneficiary = await hook . beneficiary ( ) ;
const beneficiary = await hook . beneficiary ( ) ;
return {
const config : WithAddress < ProtocolFeeHookConfig > = {
owner ,
owner ,
address ,
address ,
type : HookType . PROTOCOL_FEE ,
type : HookType . PROTOCOL_FEE ,
@ -292,6 +323,10 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
protocolFee : protocolFee.toString ( ) ,
protocolFee : protocolFee.toString ( ) ,
beneficiary ,
beneficiary ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveOpStackConfig (
async deriveOpStackConfig (
@ -306,13 +341,17 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const destinationChainName =
const destinationChainName =
this . multiProvider . getChainName ( destinationDomain ) ;
this . multiProvider . getChainName ( destinationDomain ) ;
return {
const config : WithAddress < OpStackHookConfig > = {
owner ,
owner ,
address ,
address ,
type : HookType . OP_STACK ,
type : HookType . OP_STACK ,
nativeBridge : messengerContract ,
nativeBridge : messengerContract ,
destinationChain : destinationChainName ,
destinationChain : destinationChainName ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveArbL2ToL1Config (
async deriveArbL2ToL1Config (
@ -324,12 +363,17 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const destinationDomain = await hook . destinationDomain ( ) ;
const destinationDomain = await hook . destinationDomain ( ) ;
const destinationChainName =
const destinationChainName =
this . multiProvider . getChainName ( destinationDomain ) ;
this . multiProvider . getChainName ( destinationDomain ) ;
return {
const config : WithAddress < ArbL2ToL1HookConfig > = {
address ,
address ,
type : HookType . ARB_L2_TO_L1 ,
type : HookType . ARB_L2_TO_L1 ,
destinationChain : destinationChainName ,
destinationChain : destinationChainName ,
arbSys ,
arbSys ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveDomainRoutingConfig (
async deriveDomainRoutingConfig (
@ -341,12 +385,16 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const owner = await hook . owner ( ) ;
const owner = await hook . owner ( ) ;
const domainHooks = await this . fetchDomainHooks ( hook ) ;
const domainHooks = await this . fetchDomainHooks ( hook ) ;
return {
const config : WithAddress < DomainRoutingHookConfig > = {
owner ,
owner ,
address ,
address ,
type : HookType . ROUTING ,
type : HookType . ROUTING ,
domains : domainHooks ,
domains : domainHooks ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
async deriveFallbackRoutingConfig (
async deriveFallbackRoutingConfig (
@ -367,13 +415,17 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const fallbackHook = await hook . fallbackHook ( ) ;
const fallbackHook = await hook . fallbackHook ( ) ;
const fallbackHookConfig = await this . deriveHookConfig ( fallbackHook ) ;
const fallbackHookConfig = await this . deriveHookConfig ( fallbackHook ) ;
return {
const config : WithAddress < FallbackRoutingHookConfig > = {
owner ,
owner ,
address ,
address ,
type : HookType . FALLBACK_ROUTING ,
type : HookType . FALLBACK_ROUTING ,
domains : domainHooks ,
domains : domainHooks ,
fallback : fallbackHookConfig ,
fallback : fallbackHookConfig ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
private async fetchDomainHooks (
private async fetchDomainHooks (
@ -409,12 +461,16 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
const owner = await hook . owner ( ) ;
const owner = await hook . owner ( ) ;
const paused = await hook . paused ( ) ;
const paused = await hook . paused ( ) ;
return {
const config : WithAddress < PausableHookConfig > = {
owner ,
owner ,
address ,
address ,
paused ,
paused ,
type : HookType . PAUSABLE ,
type : HookType . PAUSABLE ,
} ;
} ;
this . _cache . set ( address , config ) ;
return config ;
}
}
assertHookType (
assertHookType (