diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index 973f8c4ac9..fef4973d36 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -1796,14 +1796,20 @@ mod centrifuge { } mod restricted_transfers { - use cfg_types::locations::Location; - use frame_support::{pallet_prelude::GenesisBuild, traits::fungibles::Mutate}; + use cfg_types::{ + domain_address::{Domain, DomainAddress}, + locations::Location, + }; + use frame_support::{pallet_prelude::GenesisBuild, traits::fungibles::Mutate, BoundedVec}; + use liquidity_pools_gateway_routers::{ + DomainRouter, EthereumXCMRouter, XCMRouter, XcmDomain, + }; use polkadot_parachain::primitives::ValidationCode; use polkadot_runtime_parachains::{ paras, paras::{ParaGenesisArgs, ParaKind}, }; - use sp_core::Hasher; + use sp_core::{Hasher, H160}; use sp_runtime::traits::BlakeTwo256; use super::*; @@ -1925,6 +1931,86 @@ mod centrifuge { }); } + fn restrict_lp_eth_usdc_lp_transfer<T: Runtime + FudgeSupport>() { + let mut env = FudgeEnv::<T>::from_parachain_storage( + Genesis::default() + .add(genesis::balances::<T>(cfg(10))) + .add(orml_tokens::GenesisConfig::<T> { + balances: vec![( + Keyring::Alice.to_account_id(), + LP_ETH_USDC, + T::ExistentialDeposit::get() + lp_eth_usdc(TRANSFER_AMOUNT), + )], + }) + .storage(), + ); + + setup_xcm(&mut env); + + env.parachain_state_mut(|| { + register_usdc::<T>(); + register_lp_eth_usdc::<T>(); + + assert_ok!(orml_tokens::Pallet::<T>::set_balance( + <T as frame_system::Config>::RuntimeOrigin::root(), + <T as pallet_liquidity_pools_gateway::Config>::Sender::get().into(), + USDC, + usdc(1_000), + 0, + )); + + let router = DomainRouter::EthereumXCM(EthereumXCMRouter::<T> { + router: XCMRouter { + xcm_domain: XcmDomain { + location: Box::new( + MultiLocation::new(1, X1(Parachain(T::FudgeHandle::SIBLING_ID))) + .into(), + ), + ethereum_xcm_transact_call_index: BoundedVec::truncate_from(vec![ + 38, 0, + ]), + contract_address: H160::from_low_u64_be(11), + max_gas_limit: 700_000, + transact_required_weight_at_most: Default::default(), + overall_weight: Default::default(), + fee_currency: USDC, + fee_amount: usdc(1), + }, + _marker: Default::default(), + }, + _marker: Default::default(), + }); + + assert_ok!( + pallet_liquidity_pools_gateway::Pallet::<T>::set_domain_router( + <T as frame_system::Config>::RuntimeOrigin::root(), + Domain::EVM(1), + router, + ) + ); + + let receiver = H160::from_slice( + &<sp_runtime::AccountId32 as AsRef<[u8; 32]>>::as_ref( + &Keyring::Charlie.to_account_id(), + )[0..20], + ); + + assert_ok!(pallet_liquidity_pools::Pallet::<T>::transfer( + RawOrigin::Signed(Keyring::Alice.into()).into(), + LP_ETH_USDC, + DomainAddress::EVM(1, receiver.into()), + lp_eth_usdc(TRANSFER_AMOUNT), + )); + + let domain_acc = Domain::convert(Domain::EVM(1)); + + assert_eq!( + orml_tokens::Pallet::<T>::free_balance(LP_ETH_USDC, &domain_acc), + lp_eth_usdc(TRANSFER_AMOUNT), + ); + }); + } + fn restrict_usdc_transfer<T: Runtime>() { let mut env = RuntimeEnv::<T>::from_parachain_storage( Genesis::default() @@ -2286,6 +2372,7 @@ mod centrifuge { } crate::test_for_runtimes!([centrifuge], restrict_lp_eth_usdc_transfer); + crate::test_for_runtimes!([centrifuge], restrict_lp_eth_usdc_lp_transfer); crate::test_for_runtimes!([centrifuge], restrict_usdc_transfer); crate::test_for_runtimes!([centrifuge], restrict_usdc_xcm_transfer); crate::test_for_runtimes!([centrifuge], restrict_dot_transfer); diff --git a/runtime/integration-tests/src/generic/config.rs b/runtime/integration-tests/src/generic/config.rs index a295d8c90a..16c9a8bf86 100644 --- a/runtime/integration-tests/src/generic/config.rs +++ b/runtime/integration-tests/src/generic/config.rs @@ -16,10 +16,12 @@ use cfg_types::{ use codec::Codec; use fp_self_contained::{SelfContainedCall, UncheckedExtrinsic}; use frame_support::{ - dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo}, - traits::IsType, + dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo, RawOrigin}, + traits::{IsType, OriginTrait}, Parameter, }; +use liquidity_pools_gateway_routers::DomainRouter; +use pallet_liquidity_pools::Router; use pallet_transaction_payment::CurrencyAdapter; use runtime_common::{ apis, @@ -49,6 +51,7 @@ pub trait Runtime: RuntimeEvent = Self::RuntimeEventExt, BlockNumber = BlockNumber, Lookup = AccountIdLookup<AccountId, ()>, + RuntimeOrigin = Self::RuntimeOriginExt, > + pallet_pool_system::Config< CurrencyId = CurrencyId, Balance = Balance, @@ -100,6 +103,11 @@ pub trait Runtime: + pallet_restricted_tokens::Config<Balance = Balance, CurrencyId = CurrencyId> + pallet_restricted_xtokens::Config + pallet_transfer_allowlist::Config<CurrencyId = CurrencyId, Location = Location> + + pallet_liquidity_pools::Config<CurrencyId = CurrencyId, Balance = Balance> + + pallet_liquidity_pools_gateway::Config<Router = DomainRouter<Self>> + + pallet_xcm_transactor::Config<CurrencyId = CurrencyId> + + pallet_ethereum::Config + + pallet_ethereum_transaction::Config { /// Just the RuntimeCall type, but redefined with extra bounds. /// You can add `From` bounds in order to convert pallet calls to @@ -139,6 +147,13 @@ pub trait Runtime: + From<pallet_pool_system::Event<Self>> + From<orml_oracle::Event<Self>>; + type RuntimeOriginExt: Into<Result<RawOrigin<Self::AccountId>, <Self as frame_system::Config>::RuntimeOrigin>> + + From<RawOrigin<Self::AccountId>> + + Clone + + OriginTrait<Call = <Self as frame_system::Config>::RuntimeCall> + + From<pallet_ethereum::RawOrigin> + + Into<Result<pallet_ethereum::Origin, <Self as frame_system::Config>::RuntimeOrigin>>; + /// Block used by the runtime type Block: Block< Hash = H256, diff --git a/runtime/integration-tests/src/generic/env.rs b/runtime/integration-tests/src/generic/env.rs index adda8b3087..ad2ebd2ff8 100644 --- a/runtime/integration-tests/src/generic/env.rs +++ b/runtime/integration-tests/src/generic/env.rs @@ -59,7 +59,7 @@ impl<Event> Blocks<Event> { } /// Define an environment behavior -pub trait Env<T: Runtime> { +pub trait Env<T: Runtime>: Default { /// Load the environment from a parachain storage fn from_parachain_storage(parachain_storage: Storage) -> Self; diff --git a/runtime/integration-tests/src/generic/impls.rs b/runtime/integration-tests/src/generic/impls.rs index 933b1a952e..6b79a21938 100644 --- a/runtime/integration-tests/src/generic/impls.rs +++ b/runtime/integration-tests/src/generic/impls.rs @@ -13,6 +13,7 @@ macro_rules! impl_runtime { type MaxTranchesExt = $runtime_path::MaxTranches; type RuntimeCallExt = $runtime_path::RuntimeCall; type RuntimeEventExt = $runtime_path::RuntimeEvent; + type RuntimeOriginExt = $runtime_path::RuntimeOrigin; const KIND: RuntimeKind = RuntimeKind::$kind; }