diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index 530ed9ee6..3650bf556 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -283,11 +283,11 @@ match_type! { } parameter_type_with_key! { - pub ParachainMinFee: |location: MultiLocation| -> u128 { + pub ParachainMinFee: |location: MultiLocation| -> Option { #[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, } }; } diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index 5e801db17..ee98e4882 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -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}; @@ -78,3 +78,11 @@ impl UnknownAsset for () { Err(DispatchError::Other(NO_UNKNOWN_ASSET_IMPL)) } } + +// Default implementation for xTokens::MinXcmFee +pub struct DisabledParachainFee; +impl GetByKey> for DisabledParachainFee { + fn get(_key: &MultiLocation) -> Option { + None + } +} diff --git a/xtokens/README.md b/xtokens/README.md index df059782a..a5ccd3b1d 100644 --- a/xtokens/README.md +++ b/xtokens/README.md @@ -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 { #[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 { + None }; } ``` diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 1d52a63c6..93e16da42 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -89,7 +89,7 @@ pub mod module { type SelfLocation: Get; /// Minimum xcm execution fee paid on destination chain. - type MinXcmFee: GetByKey; + type MinXcmFee: GetByKey>; /// XCM executor. type XcmExecutor: ExecuteXcm; @@ -173,6 +173,8 @@ pub mod module { FeeNotEnough, /// Not supported MultiLocation NotSupportedMultiLocation, + /// MinXcmFee not registered for certain reserve location + MinXcmFeeNotDefined, } #[pallet::hooks] @@ -538,7 +540,7 @@ pub mod module { ensure!(non_fee_reserve == dest.chain_part(), Error::::InvalidAsset); let reserve_location = non_fee_reserve.clone().ok_or(Error::::AssetHasNoReserve)?; - let min_xcm_fee = T::MinXcmFee::get(&reserve_location); + let min_xcm_fee = T::MinXcmFee::get(&reserve_location).ok_or(Error::::MinXcmFeeNotDefined)?; // min xcm fee should less than user fee let fee_to_dest: MultiAsset = (fee.id.clone(), min_xcm_fee).into(); diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index fc989d9c3..b30ccb891 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -272,11 +272,11 @@ match_types! { } parameter_type_with_key! { - pub ParachainMinFee: |location: MultiLocation| -> u128 { + pub ParachainMinFee: |location: MultiLocation| -> Option { #[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, } }; } diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index 2eff1d5ea..ed4abd521 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -339,11 +339,11 @@ match_types! { } parameter_type_with_key! { - pub ParachainMinFee: |location: MultiLocation| -> u128 { + pub ParachainMinFee: |location: MultiLocation| -> Option { #[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, } }; } diff --git a/xtokens/src/tests.rs b/xtokens/src/tests.rs index 4a056f877..66183e838 100644 --- a/xtokens/src/tests.rs +++ b/xtokens/src/tests.rs @@ -873,7 +873,7 @@ fn transfer_asset_with_relay_fee_failed() { ), 40, ), - Error::::FeeNotEnough + Error::::MinXcmFeeNotDefined ); }); }