Skip to content

Commit

Permalink
Add framework for new modules (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-lorenzini authored Oct 30, 2024
1 parent b2eb4a7 commit c16ed99
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 12 deletions.
47 changes: 47 additions & 0 deletions rust/main/chains/hyperlane-sovereign/src/interchain_gas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
InterchainGasPaymaster, H256,
};

#[derive(Debug)]
pub struct SovereignInterchainGasPaymaster {
domain: HyperlaneDomain,
address: H256,
provider: SovereignProvider,
}

impl SovereignInterchainGasPaymaster {
pub async fn new(
conf: &ConnectionConf,
locator: ContractLocator<'_>,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = SovereignProvider::new(locator.domain.clone(), &conf.clone(), signer).await;
Ok(SovereignInterchainGasPaymaster {
domain: locator.domain.clone(),
provider,
address: locator.address,
})
}
}

impl HyperlaneContract for SovereignInterchainGasPaymaster {
fn address(&self) -> hyperlane_core::H256 {
self.address
}
}

impl HyperlaneChain for SovereignInterchainGasPaymaster {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
Box::new(self.provider.clone())
}
}

#[async_trait]
impl InterchainGasPaymaster for SovereignInterchainGasPaymaster {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, InterchainSecurityModule, ModuleType, H256, U256,
};

#[derive(Debug)]
pub struct SovereignInterchainSecurityModule {
domain: HyperlaneDomain,
address: H256,
provider: SovereignProvider,
}

impl SovereignInterchainSecurityModule {
pub async fn new(
conf: &ConnectionConf,
locator: ContractLocator<'_>,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = SovereignProvider::new(locator.domain.clone(), &conf.clone(), signer).await;
Ok(SovereignInterchainSecurityModule {
domain: locator.domain.clone(),
provider,
address: locator.address,
})
}
}

impl HyperlaneContract for SovereignInterchainSecurityModule {
fn address(&self) -> hyperlane_core::H256 {
self.address
}
}

impl HyperlaneChain for SovereignInterchainSecurityModule {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
Box::new(self.provider.clone())
}
}

#[async_trait]
impl InterchainSecurityModule for SovereignInterchainSecurityModule {
async fn dry_run_verify(
&self,
_message: &HyperlaneMessage,
_metadata: &[u8],
) -> ChainResult<Option<U256>> {
todo!()
}

async fn module_type(&self) -> ChainResult<ModuleType> {
todo!()
}
}
10 changes: 8 additions & 2 deletions rust/main/chains/hyperlane-sovereign/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
pub use self::{
/*interchain_gas::*,*/ mailbox::*, /*multisig_ism::*,*/ provider::*,
/*routing_ism::*,*/ signers::*, trait_builder::*, validator_announce::*,
interchain_gas::*, interchain_security_module::*, mailbox::*, merkle_tree_hook::*,
multisig_ism::*, provider::*, routing_ism::*, signers::*, trait_builder::*,
validator_announce::*,
};

mod interchain_gas;
mod interchain_security_module;
mod mailbox;
mod merkle_tree_hook;
mod multisig_ism;
mod provider;
mod routing_ism;
mod signers;
mod trait_builder;
mod validator_announce;
60 changes: 60 additions & 0 deletions rust/main/chains/hyperlane-sovereign/src/merkle_tree_hook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
accumulator::incremental::IncrementalMerkle, ChainResult, Checkpoint, ContractLocator,
HyperlaneChain, HyperlaneContract, HyperlaneDomain, MerkleTreeHook, H256,
};
use std::num::NonZeroU64;

#[derive(Debug)]
pub struct SovereignMerkleTreeHook {
domain: HyperlaneDomain,
address: H256,
provider: SovereignProvider,
}

impl SovereignMerkleTreeHook {
pub async fn new(
conf: &ConnectionConf,
locator: ContractLocator<'_>,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = SovereignProvider::new(locator.domain.clone(), &conf.clone(), signer).await;
Ok(SovereignMerkleTreeHook {
domain: locator.domain.clone(),
provider,
address: locator.address,
})
}
}

impl HyperlaneChain for SovereignMerkleTreeHook {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
Box::new(self.provider.clone())
}
}

impl HyperlaneContract for SovereignMerkleTreeHook {
fn address(&self) -> hyperlane_core::H256 {
self.address
}
}

#[async_trait]
impl MerkleTreeHook for SovereignMerkleTreeHook {
async fn tree(&self, _lag: Option<NonZeroU64>) -> ChainResult<IncrementalMerkle> {
todo!()
}

async fn count(&self, _lag: Option<NonZeroU64>) -> ChainResult<u32> {
todo!()
}

async fn latest_checkpoint(&self, _lag: Option<NonZeroU64>) -> ChainResult<Checkpoint> {
todo!()
}
}
54 changes: 54 additions & 0 deletions rust/main/chains/hyperlane-sovereign/src/multisig_ism.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, MultisigIsm, H256,
};

#[derive(Debug)]
pub struct SovereignMultisigIsm {
domain: HyperlaneDomain,
address: H256,
provider: SovereignProvider,
}

impl SovereignMultisigIsm {
pub async fn new(
conf: &ConnectionConf,
locator: ContractLocator<'_>,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = SovereignProvider::new(locator.domain.clone(), &conf.clone(), signer).await;
Ok(SovereignMultisigIsm {
domain: locator.domain.clone(),
provider,
address: locator.address,
})
}
}

impl HyperlaneContract for SovereignMultisigIsm {
fn address(&self) -> hyperlane_core::H256 {
self.address
}
}

impl HyperlaneChain for SovereignMultisigIsm {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
Box::new(self.provider.clone())
}
}

#[async_trait]
impl MultisigIsm for SovereignMultisigIsm {
async fn validators_and_threshold(
&self,
_message: &HyperlaneMessage,
) -> ChainResult<(Vec<H256>, u8)> {
todo!()
}
}
4 changes: 1 addition & 3 deletions rust/main/chains/hyperlane-sovereign/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{ConnectionConf, Signer};
use async_trait::async_trait;

use hyperlane_core::{
BlockInfo, ChainInfo, ChainResult, HyperlaneChain, HyperlaneDomain, HyperlaneProvider, TxnInfo,
H256, U256,
};

use crate::{ConnectionConf, Signer};

/// A wrapper around a Sovereign provider to get generic blockchain information.
#[derive(Debug, Clone)]
pub struct SovereignProvider {
Expand Down
51 changes: 51 additions & 0 deletions rust/main/chains/hyperlane-sovereign/src/routing_ism.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, RoutingIsm, H256,
};

#[derive(Debug)]
pub struct SovereignRoutingIsm {
domain: HyperlaneDomain,
address: H256,
provider: SovereignProvider,
}

impl SovereignRoutingIsm {
pub async fn new(
conf: &ConnectionConf,
locator: ContractLocator<'_>,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = SovereignProvider::new(locator.domain.clone(), &conf.clone(), signer).await;
Ok(SovereignRoutingIsm {
domain: locator.domain.clone(),
provider,
address: locator.address,
})
}
}

impl HyperlaneContract for SovereignRoutingIsm {
fn address(&self) -> hyperlane_core::H256 {
self.address
}
}

impl HyperlaneChain for SovereignRoutingIsm {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
Box::new(self.provider.clone())
}
}

#[async_trait]
impl RoutingIsm for SovereignRoutingIsm {
async fn route(&self, _message: &HyperlaneMessage) -> ChainResult<H256> {
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{ConnectionConf, Signer, SovereignProvider};

use async_trait::async_trait;

use hyperlane_core::{
Announcement, ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneProvider, SignedType, TxOutcome, ValidatorAnnounce, H256, U256,
Expand Down
Loading

0 comments on commit c16ed99

Please sign in to comment.