@ -12,10 +12,12 @@ import {
IMultisigIsm ,
IMultisigIsm__factory ,
IRoutingIsm ,
IStaticWeightedMultisigIsm ,
OPStackIsm__factory ,
PausableIsm__factory ,
StaticAddressSetFactory ,
StaticThresholdAddressSetFactory ,
StaticWeightedValidatorSetFactory ,
TestIsm__factory ,
TrustedRelayerIsm__factory ,
} from '@hyperlane-xyz/core' ;
@ -48,6 +50,7 @@ import {
MultisigIsmConfig ,
RoutingIsmConfig ,
RoutingIsmDelta ,
WeightedMultisigIsmConfig ,
} from './types.js' ;
import { routingModuleDelta } from './utils.js' ;
@ -109,6 +112,14 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
case IsmType . MERKLE_ROOT_MULTISIG :
contract = await this . deployMultisigIsm ( destination , config , logger ) ;
break ;
case IsmType . WEIGHTED_MESSAGE_ID_MULTISIG :
case IsmType . WEIGHTED_MERKLE_ROOT_MULTISIG :
contract = await this . deployWeightedMultisigIsm (
destination ,
config ,
logger ,
) ;
break ;
case IsmType . ROUTING :
case IsmType . FALLBACK_ROUTING :
contract = await this . deployRoutingIsm ( {
@ -224,6 +235,30 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
return IMultisigIsm__factory . connect ( address , signer ) ;
}
protected async deployWeightedMultisigIsm (
destination : ChainName ,
config : WeightedMultisigIsmConfig ,
logger : Logger ,
) : Promise < IMultisigIsm > {
const signer = this . multiProvider . getSigner ( destination ) ;
const weightedmultisigIsmFactory =
config . type === IsmType . WEIGHTED_MERKLE_ROOT_MULTISIG
? this . getContracts ( destination )
. staticMerkleRootWeightedMultisigIsmFactory
: this . getContracts ( destination )
. staticMessageIdWeightedMultisigIsmFactory ;
const address = await this . deployStaticWeightedValidatorSet (
destination ,
weightedmultisigIsmFactory ,
config . validators ,
config . thresholdWeight ,
logger ,
) ;
return IMultisigIsm__factory . connect ( address , signer ) ;
}
protected async deployRoutingIsm ( params : {
destination : ChainName ;
config : RoutingIsmConfig ;
@ -476,4 +511,48 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
}
return address ;
}
async deployStaticWeightedValidatorSet (
chain : ChainName ,
factory : StaticWeightedValidatorSetFactory ,
values : IStaticWeightedMultisigIsm.ValidatorInfoStruct [ ] ,
thresholdWeight = 66 e8 ,
logger : Logger ,
) : Promise < Address > {
const sorted = [ . . . values ] . sort ( ) ;
const address = await factory [ 'getAddress((address,uint96)[],uint96)' ] (
sorted ,
thresholdWeight ,
) ;
const code = await this . multiProvider . getProvider ( chain ) . getCode ( address ) ;
if ( code === '0x' ) {
logger . debug (
` Deploying new weighted set of ${ values . length } validators with a threshold weight ${ thresholdWeight } on ${ chain } ` ,
) ;
const overrides = this . multiProvider . getTransactionOverrides ( chain ) ;
// estimate gas
const estimatedGas = await factory . estimateGas [
'deploy((address,uint96)[],uint96)'
] ( sorted , thresholdWeight , overrides ) ;
// add 10% buffer
const hash = await factory [ 'deploy((address,uint96)[],uint96)' ] (
sorted ,
thresholdWeight ,
{
. . . overrides ,
gasLimit : estimatedGas.add ( estimatedGas . div ( 10 ) ) , // 10% buffer
} ,
) ;
await this . multiProvider . handleTx ( chain , hash ) ;
// TODO: add proxy verification artifact?
} else {
logger . debug (
` Recovered weighted set of ${ values . length } validators on ${ chain } with a threshold weight ${ thresholdWeight } : ${ address } ` ,
) ;
}
return address ;
}
}