diff --git a/traits/src/lib.rs b/traits/src/lib.rs index ea5231dd9..1e24f08db 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -38,6 +38,7 @@ pub mod nft; pub mod price; pub mod rewards; pub mod xcm_transfer; +pub mod native_barrier; /// New data handler #[impl_trait_for_tuples::impl_for_tuples(30)] diff --git a/traits/src/native_barrier.rs b/traits/src/native_barrier.rs new file mode 100644 index 000000000..19212f07f --- /dev/null +++ b/traits/src/native_barrier.rs @@ -0,0 +1,8 @@ +use frame_support::dispatch::DispatchResult; +pub trait NativeBarrier { + fn update_native_barrier(account_id: &AccountId, amount: Balance); + fn ensure_limit_not_exceeded(account_id: &AccountId, amount: Balance) -> DispatchResult; +} +pub trait NativeChecker { + fn is_native(currency_id: &CurrencyId) -> bool; +} diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index aca8523f7..8c57c26ee 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -44,6 +44,7 @@ use xcm_executor::traits::{InvertLocation, WeightBounds}; pub use module::*; use orml_traits::{ location::{Parse, Reserve}, + native_barrier::{NativeBarrier, NativeChecker}, GetByKey, XcmTransfer, }; @@ -102,6 +103,9 @@ pub mod module { /// Asset locations filter for outgoing transfers type OutgoingAssetsFilter: Contains; + /// + type NativeBarrierType: NativeBarrier + NativeChecker; + /// Means of measuring the weight consumed by an XCM message locally. type Weigher: WeightBounds; @@ -397,6 +401,9 @@ pub mod module { Error::::AssetDisabledForOutgoingTransfers ); + if ::is_native(¤cy_id) { + ::ensure_limit_not_exceeded(&who, amount)?; + } let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id).ok_or(Error::::NotCrossChainTransferableCurrency)?; @@ -423,6 +430,10 @@ pub mod module { Error::::AssetDisabledForOutgoingTransfers ); + if ::is_native(¤cy_id) { + ::ensure_limit_not_exceeded(&who, amount)?; + } + let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id).ok_or(Error::::NotCrossChainTransferableCurrency)?; @@ -503,6 +514,10 @@ pub mod module { Error::::AssetDisabledForOutgoingTransfers ); + if ::is_native(¤cy_id) { + ::ensure_limit_not_exceeded(&who, *amount)?; + } + let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id.clone()) .ok_or(Error::::NotCrossChainTransferableCurrency)?; ensure!(!amount.is_zero(), Error::::ZeroAmount);