diff --git a/libs/types/src/locations.rs b/libs/types/src/locations.rs index 08c9b31863..1229a4bd85 100644 --- a/libs/types/src/locations.rs +++ b/libs/types/src/locations.rs @@ -21,7 +21,7 @@ use staging_xcm::VersionedLocation; use crate::domain_address::DomainAddress; /// Location types for destinations that can receive restricted transfers #[derive(Clone, RuntimeDebugNoBound, Encode, Decode, Eq, PartialEq, MaxEncodedLen, TypeInfo)] -pub enum CfgLocation { +pub enum RestrictedTransferLocation { /// Local chain account sending destination. Local(AccountId), /// XCM MultiLocation sending destinations. @@ -33,13 +33,13 @@ pub enum CfgLocation { Address(DomainAddress), } -impl From for CfgLocation { +impl From for RestrictedTransferLocation { fn from(value: AccountId32) -> Self { Self::Local(value) } } -impl From for CfgLocation { +impl From for RestrictedTransferLocation { fn from(vml: VersionedLocation) -> Self { // using hash here as multilocation is significantly larger than any other enum // type here -- 592 bytes, vs 40 bytes for domain address (next largest) @@ -50,7 +50,7 @@ impl From for CfgLocation { } } -impl From for CfgLocation { +impl From for RestrictedTransferLocation { fn from(da: DomainAddress) -> Self { Self::Address(da) } @@ -68,10 +68,10 @@ mod test { fn from_xcm_versioned_address_works() { // TODO-1.7: Must be changed to V4? let xa = VersionedLocation::V3(MultiLocation::default()); - let l = CfgLocation::from(xa.clone()); + let l = RestrictedTransferLocation::from(xa.clone()); assert_eq!( l, - CfgLocation::XCM(sp_core::H256( + RestrictedTransferLocation::XCM(sp_core::H256( <[u8; 32]>::from_hex( "a943e30c855a123a9506e69e678dc65ae9f5b70149cb6b26eb2ed58a59b4bf77" ) @@ -86,8 +86,8 @@ mod test { 1284, <[u8; 20]>::from_hex("1231231231231231231231231231231231231231").unwrap(), ); - let l = CfgLocation::from(da.clone()); + let l = RestrictedTransferLocation::from(da.clone()); - assert_eq!(l, CfgLocation::Address(da)) + assert_eq!(l, RestrictedTransferLocation::Address(da)) } } diff --git a/runtime/common/src/transfer_filter.rs b/runtime/common/src/transfer_filter.rs index 445a4cc446..fe999ec1a4 100644 --- a/runtime/common/src/transfer_filter.rs +++ b/runtime/common/src/transfer_filter.rs @@ -14,7 +14,7 @@ use cfg_primitives::{AccountId, Balance}; use cfg_traits::{PreConditions, TransferAllowance}; use cfg_types::{ domain_address::DomainAddress, - locations::CfgLocation, + locations::RestrictedTransferLocation, tokens::{CurrencyId, FilterCurrency}, }; use frame_support::{traits::IsSubType, RuntimeDebugNoBound}; @@ -34,7 +34,11 @@ use staging_xcm::v4::{Asset, Location}; pub struct PreXcmTransfer(sp_std::marker::PhantomData<(T, C)>); impl< - T: TransferAllowance, + T: TransferAllowance< + AccountId, + CurrencyId = FilterCurrency, + Location = RestrictedTransferLocation, + >, C: Convert>, > PreConditions> for PreXcmTransfer { @@ -45,12 +49,12 @@ impl< amalgamate_allowance( T::allowance( sender.clone(), - CfgLocation::XCM(BlakeTwo256::hash(&destination.encode())), + RestrictedTransferLocation::XCM(BlakeTwo256::hash(&destination.encode())), FilterCurrency::Specific(currency), ), T::allowance( sender, - CfgLocation::XCM(BlakeTwo256::hash(&destination.encode())), + RestrictedTransferLocation::XCM(BlakeTwo256::hash(&destination.encode())), FilterCurrency::All, ), ) @@ -136,8 +140,13 @@ impl< pub struct PreNativeTransfer(sp_std::marker::PhantomData); -impl> - PreConditions> for PreNativeTransfer +impl< + T: TransferAllowance< + AccountId, + CurrencyId = FilterCurrency, + Location = RestrictedTransferLocation, + >, + > PreConditions> for PreNativeTransfer { type Result = bool; @@ -145,12 +154,12 @@ impl(sp_std::marker::PhantomData); -impl> - PreConditions<(AccountId, DomainAddress, CurrencyId)> for PreLpTransfer +impl< + T: TransferAllowance< + AccountId, + CurrencyId = FilterCurrency, + Location = RestrictedTransferLocation, + >, + > PreConditions<(AccountId, DomainAddress, CurrencyId)> for PreLpTransfer { type Result = DispatchResult; @@ -170,10 +184,14 @@ impl::RuntimeCall> + pallet_proxy::Config::RuntimeCall> + pallet_remarks::Config::RuntimeCall> - + pallet_transfer_allowlist::Config - + Sync + + pallet_transfer_allowlist::Config< + CurrencyId = FilterCurrency, + Location = RestrictedTransferLocation, + > + Sync + Send, ::RuntimeCall: IsSubType> + IsSubType> @@ -329,12 +349,12 @@ where amalgamate_allowance( pallet_transfer_allowlist::pallet::Pallet::::allowance( who.clone(), - CfgLocation::Local(recv.clone()), + RestrictedTransferLocation::Local(recv.clone()), FilterCurrency::All, ), pallet_transfer_allowlist::pallet::Pallet::::allowance( who.clone(), - CfgLocation::Local(recv.clone()), + RestrictedTransferLocation::Local(recv.clone()), FilterCurrency::Specific(CurrencyId::Native), ), ) @@ -344,8 +364,8 @@ where } fn amalgamate_allowance( - first: Result, DispatchError>, - second: Result, DispatchError>, + first: Result, DispatchError>, + second: Result, DispatchError>, ) -> DispatchResult { match (first, second) { // There is an allowance set for `Specific(id)`, but NOT for the given recv