Skip to content

Commit

Permalink
lp-gateway: Rename RouterSupport to RouterProvider, add separate enti…
Browse files Browse the repository at this point in the history
…ty that implements it
  • Loading branch information
cdamian committed Aug 13, 2024
1 parent 9a22092 commit ed22db0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 26 deletions.
3 changes: 3 additions & 0 deletions libs/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ pub mod types {

/// The type for LP gateway message nonces.
pub type LPGatewayQueueMessageNonce = u64;

/// The type for LP gateway session IDs.
pub type LPGatewaySessionId = u64;
}

/// Common constants for all runtimes
Expand Down
7 changes: 5 additions & 2 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ pub trait LPEncoding: Sized {
fn to_message_proof(&self) -> Self;
}

pub trait RouterSupport<Domain>: Sized {
pub trait RouterProvider<Domain>: Sized {
/// The router identifier.
type RouterId;

/// Returns a list of routers supported for the given domain.
fn for_domain(domain: Domain) -> Vec<Self>;
fn routers_for_domain(domain: Domain) -> Vec<Self::RouterId>;
}

/// The behavior of an entity that can send messages
Expand Down
7 changes: 5 additions & 2 deletions pallets/liquidity-pools-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use core::fmt::Debug;
use cfg_primitives::LP_DEFENSIVE_WEIGHT;
use cfg_traits::liquidity_pools::{
InboundMessageHandler, LPEncoding, MessageProcessor, MessageQueue, MessageReceiver,
MessageSender, OutboundMessageHandler, Proof, RouterSupport,
MessageSender, OutboundMessageHandler, Proof, RouterProvider,
};
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
Expand Down Expand Up @@ -106,7 +106,10 @@ pub mod pallet {
type MessageSender: MessageSender<Middleware = Self::RouterId, Origin = DomainAddress>;

/// An identification of a router
type RouterId: RouterSupport<Domain> + Parameter + Default + MaxEncodedLen;
type RouterId: Parameter + Default + MaxEncodedLen;

/// The type that provides the router available for a domain.
type RouterProvider: RouterProvider<Domain, RouterId = Self::RouterId>;

/// The type that processes inbound messages.
type InboundMessageHandler: InboundMessageHandler<
Expand Down
4 changes: 2 additions & 2 deletions pallets/liquidity-pools-gateway/src/message_processing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cfg_primitives::LP_DEFENSIVE_WEIGHT;
use cfg_traits::liquidity_pools::{
InboundMessageHandler, LPEncoding, MessageQueue, MessageSender, Proof, RouterSupport,
InboundMessageHandler, LPEncoding, MessageQueue, MessageSender, Proof, RouterProvider,
};
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::{
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<T: Config> Pallet<T> {
/// Retrieves all available routers for a domain and then filters them based
/// on the routers that we have in storage.
fn get_router_ids_for_domain(domain: Domain) -> Result<Vec<T::RouterId>, DispatchError> {
let all_routers_for_domain = T::RouterId::for_domain(domain);
let all_routers_for_domain = T::RouterProvider::routers_for_domain(domain);

let stored_routers = Routers::<T>::get().ok_or(Error::<T>::RoutersNotFound)?;

Expand Down
11 changes: 8 additions & 3 deletions pallets/liquidity-pools-gateway/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Debug, Formatter};

use cfg_mocks::{pallet_mock_liquidity_pools, pallet_mock_liquidity_pools_gateway_queue};
use cfg_traits::liquidity_pools::{LPEncoding, Proof, RouterSupport};
use cfg_traits::liquidity_pools::{LPEncoding, Proof, RouterProvider};
use cfg_types::{
domain_address::{Domain, DomainAddress},
EVMChainId,
Expand Down Expand Up @@ -115,8 +115,12 @@ impl LPEncoding for Message {
#[derive(Default, Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen, Hash)]
pub struct RouterId(pub u32);

impl RouterSupport<Domain> for RouterId {
fn for_domain(domain: Domain) -> Vec<RouterId> {
pub struct TestRouterProvider;

impl RouterProvider<Domain> for TestRouterProvider {
type RouterId = RouterId;

fn routers_for_domain(domain: Domain) -> Vec<Self::RouterId> {
match domain {
Domain::Centrifuge => vec![],
Domain::EVM(_) => vec![ROUTER_ID_1, ROUTER_ID_2, ROUTER_ID_3],
Expand Down Expand Up @@ -173,6 +177,7 @@ impl pallet_liquidity_pools_gateway::Config for Runtime {
type MessageQueue = MockLiquidityPoolsGatewayQueue;
type MessageSender = MockMessageSender;
type RouterId = RouterId;
type RouterProvider = TestRouterProvider;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type Sender = Sender;
Expand Down
5 changes: 1 addition & 4 deletions pallets/liquidity-pools-gateway/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::collections::HashMap;
use cfg_primitives::LP_DEFENSIVE_WEIGHT;
use cfg_traits::liquidity_pools::{LPEncoding, MessageProcessor, OutboundMessageHandler};
use cfg_types::domain_address::*;
use frame_support::{
assert_err, assert_noop, assert_ok, dispatch::PostDispatchInfo, pallet_prelude::Pays,
weights::Weight,
};
use frame_support::{assert_err, assert_noop, assert_ok, weights::Weight};
use itertools::Itertools;
use lazy_static::lazy_static;
use parity_scale_codec::MaxEncodedLen;
Expand Down
10 changes: 7 additions & 3 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use cfg_primitives::{
IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, PalletIndex, PoolEpochId,
PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight,
},
LPGatewayQueueMessageNonce,
LPGatewayQueueMessageNonce, LPGatewaySessionId,
};
use cfg_traits::{investments::OrderManager, Millis, PoolUpdateGuard, Seconds};
use cfg_types::{
Expand Down Expand Up @@ -117,7 +117,7 @@ use runtime_common::{
permissions::{IsUnfrozenTrancheInvestor, PoolAdminCheck},
remarks::Remark,
rewards::SingleCurrencyMovement,
routing::{EvmAccountCodeChecker, RouterDispatcher, RouterId},
routing::{EvmAccountCodeChecker, LPGatewayRouterProvider, RouterDispatcher, RouterId},
transfer_filter::{PreLpTransfer, PreNativeTransfer},
xcm::AccountIdToLocation,
xcm_transactor, AllowanceDeposit, CurrencyED,
Expand Down Expand Up @@ -1757,22 +1757,26 @@ impl pallet_liquidity_pools::Config for Runtime {
}

parameter_types! {
pub const MaxIncomingMessageSize: u32 = 1024;
pub Sender: DomainAddress = gateway::get_gateway_account::<Runtime>();
pub const MaxIncomingMessageSize: u32 = 1024;
pub const MaxRouterCount: u32 = 8;
}

impl pallet_liquidity_pools_gateway::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type InboundMessageHandler = LiquidityPools;
type LocalEVMOrigin = pallet_liquidity_pools_gateway::EnsureLocal;
type MaxIncomingMessageSize = MaxIncomingMessageSize;
type MaxRouterCount = MaxRouterCount;
type Message = pallet_liquidity_pools::Message;
type MessageQueue = LiquidityPoolsGatewayQueue;
type MessageSender = RouterDispatcher<Runtime>;
type RouterId = RouterId;
type RouterProvider = LPGatewayRouterProvider;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type Sender = Sender;
type SessionId = LPGatewaySessionId;
type WeightInfo = ();
}

Expand Down
10 changes: 7 additions & 3 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use cfg_primitives::{
IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, PalletIndex, PoolEpochId,
PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight,
},
LPGatewayQueueMessageNonce,
LPGatewayQueueMessageNonce, LPGatewaySessionId,
};
use cfg_traits::{
investments::OrderManager, Millis, Permissions as PermissionsT, PoolUpdateGuard, PreConditions,
Expand Down Expand Up @@ -117,7 +117,7 @@ use runtime_common::{
},
permissions::{IsUnfrozenTrancheInvestor, PoolAdminCheck},
rewards::SingleCurrencyMovement,
routing::{EvmAccountCodeChecker, RouterDispatcher, RouterId},
routing::{EvmAccountCodeChecker, LPGatewayRouterProvider, RouterDispatcher, RouterId},
transfer_filter::{PreLpTransfer, PreNativeTransfer},
xcm::AccountIdToLocation,
xcm_transactor, AllowanceDeposit, CurrencyED,
Expand Down Expand Up @@ -1840,8 +1840,9 @@ impl pallet_liquidity_pools::Config for Runtime {
}

parameter_types! {
pub const MaxIncomingMessageSize: u32 = 1024;
pub Sender: DomainAddress = gateway::get_gateway_account::<Runtime>();
pub const MaxIncomingMessageSize: u32 = 1024;
pub const MaxRouterCount: u32 = 8;
}

parameter_types! {
Expand All @@ -1865,13 +1866,16 @@ impl pallet_liquidity_pools_gateway::Config for Runtime {
type InboundMessageHandler = LiquidityPools;
type LocalEVMOrigin = pallet_liquidity_pools_gateway::EnsureLocal;
type MaxIncomingMessageSize = MaxIncomingMessageSize;
type MaxRouterCount = MaxRouterCount;
type Message = pallet_liquidity_pools::Message;
type MessageQueue = LiquidityPoolsGatewayQueue;
type MessageSender = RouterDispatcher<Runtime>;
type RouterId = RouterId;
type RouterProvider = LPGatewayRouterProvider;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type Sender = Sender;
type SessionId = LPGatewaySessionId;
type WeightInfo = ();
}

Expand Down
11 changes: 8 additions & 3 deletions runtime/common/src/routing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cfg_traits::{
liquidity_pools::{MessageSender, RouterSupport},
liquidity_pools::{MessageSender, RouterProvider},
PreConditions,
};
use cfg_types::domain_address::{Domain, DomainAddress};
Expand Down Expand Up @@ -35,8 +35,13 @@ impl From<RouterId> for Domain {
}
}

impl RouterSupport<Domain> for RouterId {
fn for_domain(domain: Domain) -> Vec<Self> {
/// Static router provider used in the LP gateway.
pub struct LPGatewayRouterProvider;

impl RouterProvider<Domain> for LPGatewayRouterProvider {
type RouterId = RouterId;

fn routers_for_domain(domain: Domain) -> Vec<Self::RouterId> {
match domain {
Domain::EVM(chain_id) => vec![RouterId::Axelar(AxelarId::Evm(chain_id))],
Domain::Centrifuge => vec![],
Expand Down
12 changes: 8 additions & 4 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use cfg_primitives::{
IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, PalletIndex, PoolEpochId,
PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight,
},
LPGatewayQueueMessageNonce,
LPGatewayQueueMessageNonce, LPGatewaySessionId,
};
use cfg_traits::{
investments::OrderManager, Millis, Permissions as PermissionsT, PoolUpdateGuard, PreConditions,
Expand Down Expand Up @@ -125,7 +125,7 @@ use runtime_common::{
permissions::{IsUnfrozenTrancheInvestor, PoolAdminCheck},
remarks::Remark,
rewards::SingleCurrencyMovement,
routing::{EvmAccountCodeChecker, RouterDispatcher, RouterId},
routing::{EvmAccountCodeChecker, LPGatewayRouterProvider, RouterDispatcher, RouterId},
transfer_filter::{PreLpTransfer, PreNativeTransfer},
xcm::AccountIdToLocation,
xcm_transactor, AllowanceDeposit, CurrencyED,
Expand Down Expand Up @@ -1862,27 +1862,31 @@ impl pallet_liquidity_pools::Config for Runtime {
}

parameter_types! {
pub const MaxIncomingMessageSize: u32 = 1024;
pub Sender: DomainAddress = gateway::get_gateway_account::<Runtime>();
pub const MaxIncomingMessageSize: u32 = 1024;
pub const MaxRouterCount: u32 = 8;
}

impl pallet_liquidity_pools_gateway::Config for Runtime {
type AdminOrigin = EnsureRootOr<HalfOfCouncil>;
type InboundMessageHandler = LiquidityPools;
type LocalEVMOrigin = pallet_liquidity_pools_gateway::EnsureLocal;
type MaxIncomingMessageSize = MaxIncomingMessageSize;
type MaxRouterCount = MaxRouterCount;
type Message = pallet_liquidity_pools::Message;
type MessageQueue = LiquidityPoolsGatewayQueue;
type MessageSender = RouterDispatcher<Runtime>;
type RouterId = RouterId;
type RouterProvider = LPGatewayRouterProvider;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type Sender = Sender;
type SessionId = LPGatewaySessionId;
type WeightInfo = ();
}

impl pallet_liquidity_pools_gateway_queue::Config for Runtime {
type Message = GatewayMessage<pallet_liquidity_pools::Message>;
type Message = GatewayMessage<pallet_liquidity_pools::Message, RouterId>;
type MessageNonce = LPGatewayQueueMessageNonce;
type MessageProcessor = LiquidityPoolsGateway;
type RuntimeEvent = RuntimeEvent;
Expand Down

0 comments on commit ed22db0

Please sign in to comment.