Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cleanings-pre-audit
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Aug 18, 2024
2 parents 90a6d13 + a1109d8 commit 90c5a1d
Show file tree
Hide file tree
Showing 25 changed files with 1,315 additions and 227 deletions.
22 changes: 22 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",
"pallets/liquidity-pools-gateway",
"pallets/liquidity-pools-gateway-queue",
"pallets/liquidity-pools-forwarder",
"pallets/liquidity-rewards",
"pallets/loans",
"pallets/oracle-feed",
Expand Down Expand Up @@ -236,6 +237,7 @@ pallet-keystore = { path = "pallets/keystore", default-features = false }
pallet-liquidity-pools = { path = "pallets/liquidity-pools", default-features = false }
pallet-liquidity-pools-gateway = { path = "pallets/liquidity-pools-gateway", default-features = false }
pallet-liquidity-pools-gateway-queue = { path = "pallets/liquidity-pools-gateway-queue", default-features = false }
pallet-liquidity-pools-forwarder = { path = "pallets/liquidity-pools-forwarder", default-features = false }
pallet-liquidity-rewards = { path = "pallets/liquidity-rewards", default-features = false }
pallet-loans = { path = "pallets/loans", default-features = false }
pallet-oracle-feed = { path = "pallets/oracle-feed", default-features = false }
Expand Down
33 changes: 18 additions & 15 deletions libs/mocks/src/router_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,52 @@
pub mod pallet {
use cfg_traits::liquidity_pools::{MessageReceiver, MessageSender};
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call, CallHandler};
use mock_builder::{execute_call_instance, register_call_instance, CallHandler};

#[pallet::config]
pub trait Config: frame_system::Config {
pub trait Config<I: 'static = ()>: frame_system::Config {
type Middleware;
type Origin;
type Message;
}

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

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

impl<T: Config> Pallet<T> {
impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub fn mock_receive(
f: impl Fn(T::Middleware, T::Origin, Vec<u8>) -> DispatchResult + 'static,
f: impl Fn(T::Middleware, T::Origin, T::Message) -> DispatchResult + 'static,
) {
register_call!(move |(a, b, c)| f(a, b, c));
register_call_instance!(move |(a, b, c)| f(a, b, c));
}

pub fn mock_send(
f: impl Fn(T::Middleware, T::Origin, Vec<u8>) -> DispatchResult + 'static,
f: impl Fn(T::Middleware, T::Origin, T::Message) -> DispatchResult + 'static,
) -> CallHandler {
register_call!(move |(a, b, c)| f(a, b, c))
register_call_instance!(move |(a, b, c)| f(a, b, c))
}
}

impl<T: Config> MessageReceiver for Pallet<T> {
impl<T: Config<I>, I: 'static> MessageReceiver for Pallet<T, I> {
type Message = T::Message;
type Middleware = T::Middleware;
type Origin = T::Origin;

fn receive(a: Self::Middleware, b: Self::Origin, c: Vec<u8>) -> DispatchResult {
execute_call!((a, b, c))
fn receive(a: Self::Middleware, b: Self::Origin, c: Self::Message) -> DispatchResult {
execute_call_instance!((a, b, c))
}
}

impl<T: Config> MessageSender for Pallet<T> {
impl<T: Config<I>, I: 'static> MessageSender for Pallet<T, I> {
type Message = T::Message;
type Middleware = T::Middleware;
type Origin = T::Origin;

fn send(a: Self::Middleware, b: Self::Origin, c: Vec<u8>) -> DispatchResult {
execute_call!((a, b, c))
fn send(a: Self::Middleware, b: Self::Origin, c: Self::Message) -> DispatchResult {
execute_call_instance!((a, b, c))
}
}
}
33 changes: 28 additions & 5 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
// GNU General Public License for more details.

use frame_support::{dispatch::DispatchResult, weights::Weight};
use sp_runtime::DispatchError;
use sp_runtime::{app_crypto::sp_core::H160, DispatchError};
use sp_std::vec::Vec;

/// Type that represents the hash of an LP message.
pub type MessageHash = [u8; 32];

/// An encoding & decoding trait for the purpose of meeting the
/// LiquidityPools General Message Passing Format
pub trait LPMessage: Sized {
pub trait LpMessage: Sized {
type Domain;

fn serialize(&self) -> Vec<u8>;
fn deserialize(input: &[u8]) -> Result<Self, DispatchError>;

Expand Down Expand Up @@ -55,6 +57,19 @@ pub trait LPMessage: Sized {
/// Hash - hash of the message that should be disputed.
/// Router - the address of the recovery router.
fn dispute_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self;

/// Checks whether a message is a forwarded one.
fn is_forwarded(&self) -> bool;

/// Unwraps a forwarded message.
fn unwrap_forwarded(self) -> Option<(Self::Domain, H160, Self)>;

/// Attempts to wrap into a forwarded message.
fn try_wrap_forward(
domain: Self::Domain,
forwarding_contract: H160,
message: Self,
) -> Result<Self, DispatchError>;
}

pub trait RouterProvider<Domain>: Sized {
Expand All @@ -73,9 +88,15 @@ pub trait MessageSender {
/// The originator of the message to be sent
type Origin;

/// The type of the message
type Message;

/// Sends a message for origin to destination
fn send(middleware: Self::Middleware, origin: Self::Origin, message: Vec<u8>)
-> DispatchResult;
fn send(
middleware: Self::Middleware,
origin: Self::Origin,
message: Self::Message,
) -> DispatchResult;
}

/// The behavior of an entity that can receive messages
Expand All @@ -86,11 +107,13 @@ pub trait MessageReceiver {
/// The originator of the received message
type Origin;

type Message;

/// Sends a message for origin to destination
fn receive(
middleware: Self::Middleware,
origin: Self::Origin,
message: Vec<u8>,
message: Self::Message,
) -> DispatchResult;
}

Expand Down
7 changes: 7 additions & 0 deletions libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ impl Domain {
pub fn into_account<AccountId: Encode + Decode>(&self) -> AccountId {
self.into_account_truncating()
}

pub fn get_evm_chain_id(&self) -> Option<EVMChainId> {
match self {
Domain::Centrifuge => None,
Domain::Evm(id) => Some(*id),
}
}
}

#[derive(Encode, Decode, Clone, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
Expand Down
17 changes: 13 additions & 4 deletions pallets/axelar-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,17 @@ pub mod pallet {
/// messages from
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The target of the messages comming from other chains
type Receiver: MessageReceiver<Middleware = Self::Middleware, Origin = DomainAddress>;
/// The target of the messages coming from other chains
type Receiver: MessageReceiver<
Middleware = Self::Middleware,
Origin = DomainAddress,
Message = Vec<u8>,
>;

/// Middleware used by the gateway
type Middleware: From<AxelarId>;

/// The target of the messages comming from this chain
/// The target of the messages coming from this chain
type Transactor: EthereumTransactor;

/// Checker to ensure an evm account code is registered
Expand Down Expand Up @@ -313,10 +317,15 @@ pub mod pallet {
}

impl<T: Config> MessageSender for Pallet<T> {
type Message = Vec<u8>;
type Middleware = AxelarId;
type Origin = DomainAddress;

fn send(axelar_id: AxelarId, origin: Self::Origin, message: Vec<u8>) -> DispatchResult {
fn send(
axelar_id: AxelarId,
origin: Self::Origin,
message: Self::Message,
) -> DispatchResult {
let chain_name = ChainNameById::<T>::get(axelar_id)
.ok_or(Error::<T>::RouterConfigurationNotFound)?;
let config = Configuration::<T>::get(&chain_name)
Expand Down
1 change: 1 addition & 0 deletions pallets/axelar-router/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl frame_system::Config for Runtime {
}

impl cfg_mocks::router_message::pallet::Config for Runtime {
type Message = Vec<u8>;
type Middleware = Middleware;
type Origin = DomainAddress;
}
Expand Down
65 changes: 65 additions & 0 deletions pallets/liquidity-pools-forwarder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[package]
name = "pallet-liquidity-pools-forwarder"
description = "Centrifuge Liquidity Pools Relayer Pallet"
version = "0.0.1"
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
documentation.workspace = true

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

[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Benchmarking
frame-benchmarking = { workspace = true, optional = true }

# Our custom pallets
cfg-traits = { workspace = true }
cfg-types = { workspace = true }

[dev-dependencies]
cfg-mocks = { workspace = true, default-features = true }
cfg-primitives = { workspace = true }
sp-io = { workspace = true, default-features = true }

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

0 comments on commit 90c5a1d

Please sign in to comment.