From c224c1e2e1e4056152dc64dbd42d813b6a20f86c Mon Sep 17 00:00:00 2001 From: lemunozm Date: Mon, 12 Aug 2024 16:47:43 +0200 Subject: [PATCH] router support --- libs/traits/src/liquidity_pools.rs | 6 ++++++ runtime/common/src/routing.rs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index 6a60a5e9eb..24febe10c9 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -39,6 +39,7 @@ pub trait LPEncoding: Sized { } /// The trait required for sending outbound messages. +/// TODO: remove this pub trait Router { /// The sender type of the outbound message. type Sender; @@ -50,6 +51,11 @@ pub trait Router { fn send(&self, sender: Self::Sender, message: Vec) -> DispatchResultWithPostInfo; } +pub trait RouterSupport: Sized { + /// Returns a list of routers supported for the given domain. + fn for_domain(domain: Domain) -> Vec; +} + /// The behavior of an entity that can send messages pub trait MessageSender { /// The middleware by where this message is sent diff --git a/runtime/common/src/routing.rs b/runtime/common/src/routing.rs index 1cd4f2934d..ffe852ca65 100644 --- a/runtime/common/src/routing.rs +++ b/runtime/common/src/routing.rs @@ -1,4 +1,4 @@ -use cfg_traits::liquidity_pools::{MessageReceiver, MessageSender}; +use cfg_traits::liquidity_pools::{MessageReceiver, MessageSender, RouterSupport}; use cfg_types::domain_address::{Domain, DomainAddress}; use frame_support::{ dispatch::{DispatchResult, DispatchResultWithPostInfo}, @@ -11,7 +11,7 @@ use sp_std::marker::PhantomData; /// RouterId is more specific than Domain, because RouterId also identify by /// where the message is sent/received pub enum RouterId { - /// The message must be sent/received by EVM using axelar + /// The message must be sent/received by EVM using Axelar Axelar(AxelarId), } @@ -23,6 +23,15 @@ impl From for Domain { } } +impl RouterSupport for RouterId { + fn for_domain(domain: Domain) -> Vec { + match domain { + Domain::EVM(chain_id) => vec![RouterId::Axelar(AxelarId::Evm(chain_id))], + Domain::Centrifuge => vec![], + } + } +} + /// This type choose the correct router implementation given a router id struct RouterDispatcher(PhantomData);