From ed22db0f8bdcf2b31e7fa9f83e57b5946e974f54 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Tue, 13 Aug 2024 19:01:51 +0300 Subject: [PATCH] lp-gateway: Rename RouterSupport to RouterProvider, add separate entity that implements it --- libs/primitives/src/lib.rs | 3 +++ libs/traits/src/liquidity_pools.rs | 7 +++++-- pallets/liquidity-pools-gateway/src/lib.rs | 7 +++++-- .../src/message_processing.rs | 4 ++-- pallets/liquidity-pools-gateway/src/mock.rs | 11 ++++++++--- pallets/liquidity-pools-gateway/src/tests.rs | 5 +---- runtime/altair/src/lib.rs | 10 +++++++--- runtime/centrifuge/src/lib.rs | 10 +++++++--- runtime/common/src/routing.rs | 11 ++++++++--- runtime/development/src/lib.rs | 12 ++++++++---- 10 files changed, 54 insertions(+), 26 deletions(-) diff --git a/libs/primitives/src/lib.rs b/libs/primitives/src/lib.rs index d7200cfa29..323cf554f6 100644 --- a/libs/primitives/src/lib.rs +++ b/libs/primitives/src/lib.rs @@ -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 diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index a28f29a5b3..1eefd5510f 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -41,9 +41,12 @@ pub trait LPEncoding: Sized { fn to_message_proof(&self) -> Self; } -pub trait RouterSupport: Sized { +pub trait RouterProvider: Sized { + /// The router identifier. + type RouterId; + /// Returns a list of routers supported for the given domain. - fn for_domain(domain: Domain) -> Vec; + fn routers_for_domain(domain: Domain) -> Vec; } /// The behavior of an entity that can send messages diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 6fc5819942..c2e53c916a 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -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::*}; @@ -106,7 +106,10 @@ pub mod pallet { type MessageSender: MessageSender; /// An identification of a router - type RouterId: RouterSupport + Parameter + Default + MaxEncodedLen; + type RouterId: Parameter + Default + MaxEncodedLen; + + /// The type that provides the router available for a domain. + type RouterProvider: RouterProvider; /// The type that processes inbound messages. type InboundMessageHandler: InboundMessageHandler< diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index a999a9d015..87c23e3def 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -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::{ @@ -49,7 +49,7 @@ impl Pallet { /// 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, 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::::get().ok_or(Error::::RoutersNotFound)?; diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index de08a1216b..a94bf1bc1c 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -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, @@ -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 for RouterId { - fn for_domain(domain: Domain) -> Vec { +pub struct TestRouterProvider; + +impl RouterProvider for TestRouterProvider { + type RouterId = RouterId; + + fn routers_for_domain(domain: Domain) -> Vec { match domain { Domain::Centrifuge => vec![], Domain::EVM(_) => vec![ROUTER_ID_1, ROUTER_ID_2, ROUTER_ID_3], @@ -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; diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 6432962431..202d7e721a 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -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; diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 3889aadaf9..68a80a4288 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -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::{ @@ -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, @@ -1757,8 +1757,9 @@ impl pallet_liquidity_pools::Config for Runtime { } parameter_types! { - pub const MaxIncomingMessageSize: u32 = 1024; pub Sender: DomainAddress = gateway::get_gateway_account::(); + pub const MaxIncomingMessageSize: u32 = 1024; + pub const MaxRouterCount: u32 = 8; } impl pallet_liquidity_pools_gateway::Config for Runtime { @@ -1766,13 +1767,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; type RouterId = RouterId; + type RouterProvider = LPGatewayRouterProvider; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; type Sender = Sender; + type SessionId = LPGatewaySessionId; type WeightInfo = (); } diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index a4e2102a18..d64630fade 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -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, @@ -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, @@ -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::(); + pub const MaxIncomingMessageSize: u32 = 1024; + pub const MaxRouterCount: u32 = 8; } parameter_types! { @@ -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; type RouterId = RouterId; + type RouterProvider = LPGatewayRouterProvider; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; type Sender = Sender; + type SessionId = LPGatewaySessionId; type WeightInfo = (); } diff --git a/runtime/common/src/routing.rs b/runtime/common/src/routing.rs index 575526735b..2cc024cc95 100644 --- a/runtime/common/src/routing.rs +++ b/runtime/common/src/routing.rs @@ -1,5 +1,5 @@ use cfg_traits::{ - liquidity_pools::{MessageSender, RouterSupport}, + liquidity_pools::{MessageSender, RouterProvider}, PreConditions, }; use cfg_types::domain_address::{Domain, DomainAddress}; @@ -35,8 +35,13 @@ impl From for Domain { } } -impl RouterSupport for RouterId { - fn for_domain(domain: Domain) -> Vec { +/// Static router provider used in the LP gateway. +pub struct LPGatewayRouterProvider; + +impl RouterProvider for LPGatewayRouterProvider { + type RouterId = RouterId; + + fn routers_for_domain(domain: Domain) -> Vec { match domain { Domain::EVM(chain_id) => vec![RouterId::Axelar(AxelarId::Evm(chain_id))], Domain::Centrifuge => vec![], diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 973921019e..5fc9aa1b0e 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -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, @@ -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, @@ -1862,8 +1862,9 @@ impl pallet_liquidity_pools::Config for Runtime { } parameter_types! { - pub const MaxIncomingMessageSize: u32 = 1024; pub Sender: DomainAddress = gateway::get_gateway_account::(); + pub const MaxIncomingMessageSize: u32 = 1024; + pub const MaxRouterCount: u32 = 8; } impl pallet_liquidity_pools_gateway::Config for Runtime { @@ -1871,18 +1872,21 @@ 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; 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; + type Message = GatewayMessage; type MessageNonce = LPGatewayQueueMessageNonce; type MessageProcessor = LiquidityPoolsGateway; type RuntimeEvent = RuntimeEvent;