Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for XCM delivery fees in all runtimes #2851

Closed
wants to merge 10 commits into from
Closed
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion pallets/xcm-transactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,19 @@ pub mod pallet {
transact_message.0.insert(0, DescendOrigin(interior));

// Send to destination chain
let (ticket, _price) =
let (ticket, price) =
T::XcmSender::validate(&mut Some(dest), &mut Some(transact_message))
.map_err(|_| Error::<T>::ErrorValidating)?;

// Extract XCM Delivery fees from the origin account.
// Same way as the XCM executor does.
// See https://github.com/paritytech/polkadot-sdk/blob/release-crates-io-v1.11.0
// /polkadot/xcm/xcm-executor/src/lib.rs#L445-L447
for asset in price.inner() {
T::AssetTransactor::withdraw_asset(&asset, &origin_as_mult, None)
.map_err(|_| Error::<T>::UnableToWithdrawAsset)?;
}

T::XcmSender::deliver(ticket).map_err(|_| Error::<T>::ErrorDelivering)?;

Ok(())
Expand Down
26 changes: 13 additions & 13 deletions precompiles/xtokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn transfer_self_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(2000)
.expect_cost(3000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -139,7 +139,7 @@ fn transfer_to_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -186,7 +186,7 @@ fn transfer_to_reserve_with_unlimited_weight_works() {
weight: u64::MAX,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -235,7 +235,7 @@ fn transfer_to_reserve_with_fee_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -290,7 +290,7 @@ fn transfer_non_reserve_to_non_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -339,7 +339,7 @@ fn transfer_non_reserve_to_non_reserve_with_fee_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -394,7 +394,7 @@ fn transfer_multi_asset_to_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -442,7 +442,7 @@ fn transfer_multi_asset_self_reserve_works() {
weight: 4_000_000,
},
)
.expect_cost(2000)
.expect_cost(3000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -490,7 +490,7 @@ fn transfer_multi_asset_self_reserve_with_fee_works() {
weight: 4_000_000,
},
)
.expect_cost(2000)
.expect_cost(3000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -542,7 +542,7 @@ fn transfer_multi_asset_non_reserve_to_non_reserve() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -591,7 +591,7 @@ fn transfer_multi_asset_non_reserve_to_non_reserve_with_fee() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -645,7 +645,7 @@ fn transfer_multi_currencies() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down Expand Up @@ -718,7 +718,7 @@ fn transfer_multi_assets() {
weight: 4_000_000,
},
)
.expect_cost(3000)
.expect_cost(4000)
.expect_no_logs()
.execute_returns(());

Expand Down
26 changes: 19 additions & 7 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//!

use super::{
governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees,
EmergencyParaXcm, Erc20XcmBridge, MaintenanceMode, MessageQueue, ParachainInfo,
currency::MICROUNIT, governance, AccountId, AssetId, AssetManager, Balance, Balances,
DealWithFees, EmergencyParaXcm, Erc20XcmBridge, MaintenanceMode, MessageQueue, ParachainInfo,
ParachainSystem, Perbill, PolkadotXcm, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent,
RuntimeOrigin, Treasury, XcmpQueue,
};
Expand Down Expand Up @@ -73,6 +73,7 @@ use sp_std::{
};

use orml_traits::parameter_type_with_key;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;

use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot};

Expand All @@ -85,7 +86,6 @@ parameter_types! {
pub UniversalLocation: InteriorLocation =
[GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();


// Self Reserve location, defines the multilocation identifiying the self-reserve currency
// This is used to match it also against our Balances pallet when we receive such
// a Location: (Self Balances pallet index)
Expand All @@ -96,6 +96,12 @@ parameter_types! {
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
].into()
};

// XCM BaseDeliveryFee
pub const BaseDeliveryFee: u128 = 100 * MICROUNIT;

// Cost of every XCM transaction byte
pub const TransactionByteFee: u128 = 100;
}

/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -321,11 +327,19 @@ impl xcm_executor::Config for XcmExecutorConfig {
// Converts a Signed Local Origin into a Location
pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, RelayNetwork>;

/// XCM Delivery fees for sibling chains.
pub type PriceForSiblingParachainDelivery =
ExponentialPrice<SelfReserve, BaseDeliveryFee, TransactionByteFee, XcmpQueue>;

/// XCM Delivery fees for the relay chain.
pub type PriceForParentDelivery =
ExponentialPrice<SelfReserve, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;

/// The means for routing XCM messages which are not for local execution into the right message
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, PriceForParentDelivery>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
Expand Down Expand Up @@ -376,9 +390,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type WeightInfo = moonbeam_weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery<
cumulus_primitives_core::ParaId,
>;
type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
}

parameter_types! {
Expand Down
Loading
Loading