Skip to content
Merged
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
6 changes: 3 additions & 3 deletions asset-registry/src/mock/para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ match_type! {
}

parameter_type_with_key! {
pub ParachainMinFee: |location: MultiLocation| -> u128 {
pub ParachainMinFee: |location: MultiLocation| -> Option<u128> {
#[allow(clippy::match_ref_pats)] // false positive
match (location.parents, location.first_interior()) {
(1, Some(Parachain(2))) => 40,
_ => u128::MAX,
(1, Some(Parachain(2))) => Some(40),
_ => None,
}
};
}
Expand Down
10 changes: 9 additions & 1 deletion xcm-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sp_std::{marker::PhantomData, prelude::*};
use xcm::latest::prelude::*;
use xcm_executor::traits::{FilterAssetLocation, MatchesFungible};

use orml_traits::location::Reserve;
use orml_traits::{location::Reserve, GetByKey};

pub use currency_adapter::{DepositToAlternative, MultiCurrencyAdapter, OnDepositFail};

Expand Down Expand Up @@ -78,3 +78,11 @@ impl UnknownAsset for () {
Err(DispatchError::Other(NO_UNKNOWN_ASSET_IMPL))
}
}

// Default implementation for xTokens::MinXcmFee
pub struct DisabledParachainFee;
impl GetByKey<MultiLocation, Option<u128>> for DisabledParachainFee {
fn get(_key: &MultiLocation) -> Option<u128> {
None
}
}
12 changes: 6 additions & 6 deletions xtokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ Parachains should implements config `MinXcmFee` in `xtokens` module config:

```rust
parameter_type_with_key! {
pub ParachainMinFee: |location: MultiLocation| -> u128 {
pub ParachainMinFee: |location: MultiLocation| -> Option<u128> {
#[allow(clippy::match_ref_pats)] // false positive
match (location.parents, location.first_interior()) {
(1, Some(Parachain(parachains::statemine::ID))) => 4_000_000_000,
_ => u128::MAX,
(1, Some(Parachain(parachains::statemine::ID))) => Some(4_000_000_000),
_ => None,
}
};
}
```

If Parachain don't want have this case, can simply return Max value:
If Parachain don't want have this case, can simply return None. A default implementation is provided by `DisabledParachainFee` in `xcm-support`.

```rust
parameter_type_with_key! {
pub ParachainMinFee: |_location: MultiLocation| -> u128 {
u128::MAX
pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
None
};
}
```
Expand Down
6 changes: 4 additions & 2 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod module {
type SelfLocation: Get<MultiLocation>;

/// Minimum xcm execution fee paid on destination chain.
type MinXcmFee: GetByKey<MultiLocation, u128>;
type MinXcmFee: GetByKey<MultiLocation, Option<u128>>;

/// XCM executor.
type XcmExecutor: ExecuteXcm<Self::Call>;
Expand Down Expand Up @@ -173,6 +173,8 @@ pub mod module {
FeeNotEnough,
/// Not supported MultiLocation
NotSupportedMultiLocation,
/// MinXcmFee not registered for certain reserve location
MinXcmFeeNotDefined,
}

#[pallet::hooks]
Expand Down Expand Up @@ -538,7 +540,7 @@ pub mod module {
ensure!(non_fee_reserve == dest.chain_part(), Error::<T>::InvalidAsset);

let reserve_location = non_fee_reserve.clone().ok_or(Error::<T>::AssetHasNoReserve)?;
let min_xcm_fee = T::MinXcmFee::get(&reserve_location);
let min_xcm_fee = T::MinXcmFee::get(&reserve_location).ok_or(Error::<T>::MinXcmFeeNotDefined)?;

// min xcm fee should less than user fee
let fee_to_dest: MultiAsset = (fee.id.clone(), min_xcm_fee).into();
Expand Down
6 changes: 3 additions & 3 deletions xtokens/src/mock/para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ match_types! {
}

parameter_type_with_key! {
pub ParachainMinFee: |location: MultiLocation| -> u128 {
pub ParachainMinFee: |location: MultiLocation| -> Option<u128> {
#[allow(clippy::match_ref_pats)] // false positive
match (location.parents, location.first_interior()) {
(1, Some(Parachain(2))) => 40,
_ => u128::MAX,
(1, Some(Parachain(2))) => Some(40),
_ => None,
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions xtokens/src/mock/para_relative_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ match_types! {
}

parameter_type_with_key! {
pub ParachainMinFee: |location: MultiLocation| -> u128 {
pub ParachainMinFee: |location: MultiLocation| -> Option<u128> {
#[allow(clippy::match_ref_pats)] // false positive
match (location.parents, location.first_interior()) {
(1, Some(Parachain(2))) => 40,
_ => u128::MAX,
(1, Some(Parachain(2))) => Some(40),
_ => None,
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion xtokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ fn transfer_asset_with_relay_fee_failed() {
),
40,
),
Error::<para::Runtime>::FeeNotEnough
Error::<para::Runtime>::MinXcmFeeNotDefined
);
});
}
Expand Down