Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 8 additions & 0 deletions traits/src/native_barrier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use frame_support::dispatch::DispatchResult;
pub trait NativeBarrier<AccountId, Balance> {
fn update_native_barrier(account_id: &AccountId, amount: Balance);
fn ensure_limit_not_exceeded(account_id: &AccountId, amount: Balance) -> DispatchResult;
}
pub trait NativeChecker<CurrencyId> {
fn is_native(currency_id: &CurrencyId) -> bool;
}
15 changes: 15 additions & 0 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -102,6 +103,9 @@ pub mod module {
/// Asset locations filter for outgoing transfers
type OutgoingAssetsFilter: Contains<Self::CurrencyId>;

///
type NativeBarrierType: NativeBarrier<Self::AccountId, Self::Balance> + NativeChecker<Self::CurrencyId>;

/// Means of measuring the weight consumed by an XCM message locally.
type Weigher: WeightBounds<Self::RuntimeCall>;

Expand Down Expand Up @@ -397,6 +401,9 @@ pub mod module {
Error::<T>::AssetDisabledForOutgoingTransfers
);

if <T::NativeBarrierType>::is_native(&currency_id) {
<T::NativeBarrierType>::ensure_limit_not_exceeded(&who, amount)?;
}
let location: MultiLocation =
T::CurrencyIdConvert::convert(currency_id).ok_or(Error::<T>::NotCrossChainTransferableCurrency)?;

Expand All @@ -423,6 +430,10 @@ pub mod module {
Error::<T>::AssetDisabledForOutgoingTransfers
);

if <T::NativeBarrierType>::is_native(&currency_id) {
<T::NativeBarrierType>::ensure_limit_not_exceeded(&who, amount)?;
}

let location: MultiLocation =
T::CurrencyIdConvert::convert(currency_id).ok_or(Error::<T>::NotCrossChainTransferableCurrency)?;

Expand Down Expand Up @@ -503,6 +514,10 @@ pub mod module {
Error::<T>::AssetDisabledForOutgoingTransfers
);

if <T::NativeBarrierType>::is_native(&currency_id) {
<T::NativeBarrierType>::ensure_limit_not_exceeded(&who, *amount)?;
}

let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id.clone())
.ok_or(Error::<T>::NotCrossChainTransferableCurrency)?;
ensure!(!amount.is_zero(), Error::<T>::ZeroAmount);
Expand Down