@ -22,6 +22,7 @@ import {
concurrentMap ,
eqAddress ,
getLogLevel ,
retryAsync ,
rootLogger ,
} from '@hyperlane-xyz/utils' ;
@ -95,71 +96,73 @@ export class EvmHookReader extends HyperlaneReader implements HookReader {
}
async deriveHookConfig ( address : Address ) : Promise < DerivedHookConfig > {
let onchainHookType : OnchainHookType | undefined = undefined ;
let derivedHookConfig : DerivedHookConfig ;
try {
const hook = IPostDispatchHook__factory . connect ( address , this . provider ) ;
this . logger . debug ( 'Deriving HookConfig:' , { address } ) ;
// Temporarily turn off SmartProvider logging
// Provider errors are expected because deriving will call methods that may not exist in the Bytecode
this . setSmartProviderLogLevel ( 'silent' ) ;
onchainHookType = await hook . hookType ( ) ;
switch ( onchainHookType ) {
case OnchainHookType . ROUTING :
derivedHookConfig = await this . deriveDomainRoutingConfig ( address ) ;
break ;
case OnchainHookType . AGGREGATION :
derivedHookConfig = await this . deriveAggregationConfig ( address ) ;
break ;
case OnchainHookType . MERKLE_TREE :
derivedHookConfig = await this . deriveMerkleTreeConfig ( address ) ;
break ;
case OnchainHookType . INTERCHAIN_GAS_PAYMASTER :
derivedHookConfig = await this . deriveIgpConfig ( address ) ;
break ;
case OnchainHookType . FALLBACK_ROUTING :
derivedHookConfig = await this . deriveFallbackRoutingConfig ( address ) ;
break ;
case OnchainHookType . PAUSABLE :
derivedHookConfig = await this . derivePausableConfig ( address ) ;
break ;
case OnchainHookType . PROTOCOL_FEE :
derivedHookConfig = await this . deriveProtocolFeeConfig ( address ) ;
break ;
// ID_AUTH_ISM could be OPStackHook, ERC5164Hook or LayerZeroV2Hook
// For now assume it's OP_STACK
case OnchainHookType . ID_AUTH_ISM :
derivedHookConfig = await this . deriveOpStackConfig ( address ) ;
break ;
case OnchainHookType . ARB_L2_TO_L1 :
derivedHookConfig = await this . deriveArbL2ToL1Config ( address ) ;
break ;
default :
throw new Error (
` Unsupported HookType: ${ OnchainHookType [ onchainHookType ] } ` ,
return retryAsync ( async ( ) = > {
let onchainHookType : OnchainHookType | undefined = undefined ;
let derivedHookConfig : DerivedHookConfig ;
try {
const hook = IPostDispatchHook__factory . connect ( address , this . provider ) ;
this . logger . debug ( 'Deriving HookConfig:' , { address } ) ;
// Temporarily turn off SmartProvider logging
// Provider errors are expected because deriving will call methods that may not exist in the Bytecode
this . setSmartProviderLogLevel ( 'silent' ) ;
onchainHookType = await hook . hookType ( ) ;
switch ( onchainHookType ) {
case OnchainHookType . ROUTING :
derivedHookConfig = await this . deriveDomainRoutingConfig ( address ) ;
break ;
case OnchainHookType . AGGREGATION :
derivedHookConfig = await this . deriveAggregationConfig ( address ) ;
break ;
case OnchainHookType . MERKLE_TREE :
derivedHookConfig = await this . deriveMerkleTreeConfig ( address ) ;
break ;
case OnchainHookType . INTERCHAIN_GAS_PAYMASTER :
derivedHookConfig = await this . deriveIgpConfig ( address ) ;
break ;
case OnchainHookType . FALLBACK_ROUTING :
derivedHookConfig = await this . deriveFallbackRoutingConfig ( address ) ;
break ;
case OnchainHookType . PAUSABLE :
derivedHookConfig = await this . derivePausableConfig ( address ) ;
break ;
case OnchainHookType . PROTOCOL_FEE :
derivedHookConfig = await this . deriveProtocolFeeConfig ( address ) ;
break ;
// ID_AUTH_ISM could be OPStackHook, ERC5164Hook or LayerZeroV2Hook
// For now assume it's OP_STACK
case OnchainHookType . ID_AUTH_ISM :
derivedHookConfig = await this . deriveOpStackConfig ( address ) ;
break ;
case OnchainHookType . ARB_L2_TO_L1 :
derivedHookConfig = await this . deriveArbL2ToL1Config ( address ) ;
break ;
default :
throw new Error (
` Unsupported HookType: ${ OnchainHookType [ onchainHookType ] } ` ,
) ;
}
} catch ( e : any ) {
let customMessage : string = ` Failed to derive ${ onchainHookType } hook ( ${ address } ) ` ;
if (
! onchainHookType &&
e . message . includes ( 'Invalid response from provider' )
) {
customMessage = customMessage . concat (
` [The provided hook contract might be outdated and not support hookType()] ` ,
) ;
this . logger . info ( ` ${ customMessage } : \ n \ t ${ e } ` ) ;
} else {
this . logger . debug ( ` ${ customMessage } : \ n \ t ${ e } ` ) ;
}
throw new Error ( ` ${ customMessage } : \ n \ t ${ e } ` ) ;
} finally {
this . setSmartProviderLogLevel ( getLogLevel ( ) ) ; // returns to original level defined by rootLogger
}
} catch ( e : any ) {
let customMessage : string = ` Failed to derive ${ onchainHookType } hook ( ${ address } ) ` ;
if (
! onchainHookType &&
e . message . includes ( 'Invalid response from provider' )
) {
customMessage = customMessage . concat (
` [The provided hook contract might be outdated and not support hookType()] ` ,
) ;
this . logger . info ( ` ${ customMessage } : \ n \ t ${ e } ` ) ;
} else {
this . logger . debug ( ` ${ customMessage } : \ n \ t ${ e } ` ) ;
}
throw new Error ( ` ${ customMessage } : \ n \ t ${ e } ` ) ;
} finally {
this . setSmartProviderLogLevel ( getLogLevel ( ) ) ; // returns to original level defined by rootLogger
}
return derivedHookConfig ;
return derivedHookConfig ;
} ) ;
}
async deriveMerkleTreeConfig (