Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-router support in LP gateway. #1893

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"pallets/liquidity-pools-gateway",
"pallets/liquidity-pools-gateway/axelar-gateway-precompile",
"pallets/liquidity-pools-gateway/routers",
"pallets/liquidity-pools-gateway/queue",
"pallets/liquidity-rewards",
"pallets/loans",
"pallets/oracle-feed",
Expand Down Expand Up @@ -224,6 +225,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s
# Centrifuge pallets
axelar-gateway-precompile = { path = "pallets/liquidity-pools-gateway/axelar-gateway-precompile", default-features = false }
liquidity-pools-gateway-routers = { path = "pallets/liquidity-pools-gateway/routers", default-features = false }
liquidity-pools-gateway-queue-pallet = { path = "pallets/liquidity-pools-gateway/queue", default-features = false }
pallet-anchors = { path = "pallets/anchors", default-features = false }
pallet-anchors-v2 = { path = "pallets/anchors-v2", default-features = false }
pallet-block-rewards = { path = "pallets/block-rewards", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions libs/mocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod fees;
pub mod foreign_investment;
pub mod investment;
pub mod liquidity_pools;
pub mod liquidity_pools_gateway_queue;
pub mod liquidity_pools_gateway_routers;
pub mod outbound_queue;
pub mod pay_fee;
Expand All @@ -26,6 +27,7 @@ pub use data::pallet as pallet_mock_data;
pub use fees::pallet as pallet_mock_fees;
pub use investment::pallet as pallet_mock_investment;
pub use liquidity_pools::pallet as pallet_mock_liquidity_pools;
pub use liquidity_pools_gateway_queue::pallet as pallet_mock_liquidity_pools_gateway_queue;
pub use liquidity_pools_gateway_routers::{pallet as pallet_mock_routers, RouterMock};
pub use pay_fee::pallet as pallet_mock_pay_fee;
pub use permissions::pallet as pallet_mock_permissions;
Expand Down
8 changes: 4 additions & 4 deletions libs/mocks/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use cfg_traits::liquidity_pools::InboundQueue;
use cfg_traits::liquidity_pools::InboundMessageHandler;
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};

Expand All @@ -17,16 +17,16 @@ pub mod pallet {
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

impl<T: Config> Pallet<T> {
pub fn mock_submit(f: impl Fn(T::DomainAddress, T::Message) -> DispatchResult + 'static) {
pub fn mock_handle(f: impl Fn(T::DomainAddress, T::Message) -> DispatchResult + 'static) {
register_call!(move |(sender, msg)| f(sender, msg));
}
}

impl<T: Config> InboundQueue for Pallet<T> {
impl<T: Config> InboundMessageHandler for Pallet<T> {
type Message = T::Message;
type Sender = T::DomainAddress;

fn submit(sender: Self::Sender, msg: Self::Message) -> DispatchResult {
fn handle(sender: Self::Sender, msg: Self::Message) -> DispatchResult {
execute_call!((sender, msg))
}
}
Expand Down
31 changes: 31 additions & 0 deletions libs/mocks/src/liquidity_pools_gateway_queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use cfg_traits::liquidity_pools::MessageQueue;
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};

#[pallet::config]
pub trait Config: frame_system::Config {
type Message;
}

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::storage]
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

impl<T: Config> Pallet<T> {
pub fn mock_submit(f: impl Fn(T::Message) -> DispatchResult + 'static) {
register_call!(move |msg| f(msg));
}
}

impl<T: Config> MessageQueue for Pallet<T> {
type Message = T::Message;

fn submit(msg: Self::Message) -> DispatchResult {
execute_call!(msg)
}
}
}
38 changes: 35 additions & 3 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ pub trait LPEncoding: Sized {
fn deserialize(input: &[u8]) -> Result<Self, DispatchError>;
}

pub trait LPMessage: LPEncoding {
fn get_message_proof(&self) -> Option<[u8; 32]>;
fn to_message_proof(&self) -> Self;
}
cdamian marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(any(test, feature = "std"))]
pub mod test_util {
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
Expand All @@ -44,6 +49,16 @@ pub mod test_util {
}
}
}

impl LPMessage for Message {
fn get_message_proof(&self) -> Option<[u8; 32]> {
Some([1; 32])
}

fn to_message_proof(&self) -> Self {
Self
}
}
}

/// The trait required for sending outbound messages.
Expand All @@ -58,6 +73,23 @@ pub trait Router {
fn send(&self, sender: Self::Sender, message: Vec<u8>) -> DispatchResultWithPostInfo;
}

/// The trait required for queueing messages.
pub trait MessageQueue {
/// The message type.
type Message;

/// Submit a message to the queue.
fn submit(msg: Self::Message) -> DispatchResult;
}

pub trait MessageProcessor {
/// The message type.
type Message;

/// Process a message.
fn process(msg: Self::Message) -> DispatchResultWithPostInfo;
}

/// The trait required for processing outbound messages.
pub trait OutboundQueue {
/// The sender type of the outgoing message.
Expand All @@ -77,14 +109,14 @@ pub trait OutboundQueue {
) -> DispatchResult;
}

/// The trait required for processing incoming messages.
pub trait InboundQueue {
/// The trait required for handling incoming LP messages.
pub trait InboundMessageHandler {
/// The sender type of the incoming message.
type Sender;

/// The liquidityPools message type.
type Message;

/// Submit a message to the inbound queue.
fn submit(sender: Self::Sender, msg: Self::Message) -> DispatchResult;
fn handle(sender: Self::Sender, msg: Self::Message) -> DispatchResult;
}
17 changes: 17 additions & 0 deletions libs/types/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use frame_support::pallet_prelude::{Decode, Encode, MaxEncodedLen, TypeInfo};

use crate::domain_address::{Domain, DomainAddress};

/// Message type used by the LP gateway.
#[derive(Encode, Decode, Clone, Eq, MaxEncodedLen, PartialEq, TypeInfo)]
pub enum GatewayMessage<AccountId, LPMessage> {
Inbound {
domain_address: DomainAddress,
message: LPMessage,
},
Outbound {
sender: AccountId,
destination: Domain,
message: LPMessage,
},
}
1 change: 1 addition & 0 deletions libs/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod domain_address;
pub mod epoch;
pub mod fee_keys;
pub mod fixed_point;
pub mod gateway;
pub mod ids;
pub mod investments;
pub mod locations;
Expand Down
52 changes: 52 additions & 0 deletions pallets/liquidity-pools-gateway/queue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
authors = ["Centrifuge <[email protected]>"]
description = "Centrifuge Liquidity Pools Gateway Queue Pallet"
edition = "2021"
license = "LGPL-3.0"
name = "pallet-liquidity-pools-gateway-queue"
repository = "https://github.com/centrifuge/centrifuge-chain"
version = "0.0.1"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

cfg-traits = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
"frame-benchmarking/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
Loading
Loading