-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Introduce XcmFeesToAccount fee manager #7005
base: master
Are you sure you want to change the base?
Changes from 6 commits
272c31d
13f5944
3d0cfde
c28700d
d5b760b
a2d3604
7e99987
04d4410
5d6e2c2
7e4cc0a
17c0f5c
12b816e
d22046f
6c9f3f9
424c903
7b140f0
a852957
e1b6af0
20b4f66
09828da
0e06f73
6a4fd76
6eccb05
2df8cbf
de0e397
8bb8fb9
3ea877f
4843e58
7c3bb1a
50a008e
76a4cd0
7d61d2e
18945f8
6f4a8bb
4fa5016
88b9582
2c7d14c
57b3a6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,15 @@ | |
|
|
||
| use super::{ | ||
| parachains_origin, AccountId, AllPalletsWithSystem, Balances, Fellows, ParaId, Runtime, | ||
| RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, WeightToFee, XcmPallet, | ||
| RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, Treasury, WeightToFee, XcmPallet, | ||
| }; | ||
| use frame_support::{ | ||
| match_types, parameter_types, | ||
| traits::{Contains, Everything, Nothing}, | ||
| weights::Weight, | ||
| }; | ||
| use frame_system::EnsureRoot; | ||
| use kusama_runtime_constants::system_parachain::*; | ||
| use runtime_common::{crowdloan, paras_registrar, xcm_sender, ToAuthor}; | ||
| use sp_core::ConstU32; | ||
| use xcm::latest::prelude::*; | ||
|
|
@@ -36,7 +37,7 @@ use xcm_builder::{ | |
| CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete, | ||
| MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32, | ||
| SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds, | ||
| WithComputedOrigin, | ||
| WithComputedOrigin, XcmFeesToAccount, | ||
| }; | ||
| use xcm_executor::traits::WithOriginFilter; | ||
|
|
||
|
|
@@ -55,6 +56,8 @@ parameter_types! { | |
| pub CheckAccount: AccountId = XcmPallet::check_account(); | ||
| /// The check account that is allowed to mint assets locally. | ||
| pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); | ||
| /// The treasury account where XCM fees would be sent to. | ||
| pub TreasuryAccount: Option<AccountId> = Some(Treasury::account_id()); | ||
| } | ||
|
|
||
| /// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine | ||
|
|
@@ -112,7 +115,7 @@ pub type XcmRouter = ( | |
|
|
||
| parameter_types! { | ||
| pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); | ||
| pub const Statemine: MultiLocation = Parachain(1000).into_location(); | ||
| pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); | ||
KiChjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub const Encointer: MultiLocation = Parachain(1001).into_location(); | ||
| pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get()); | ||
| pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get()); | ||
|
|
@@ -125,6 +128,9 @@ match_types! { | |
| pub type OnlyParachains: impl Contains<MultiLocation> = { | ||
| MultiLocation { parents: 0, interior: X1(Parachain(_)) } | ||
| }; | ||
| pub type SystemParachains: impl Contains<MultiLocation> = { | ||
| MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID)) } | ||
| }; | ||
| } | ||
|
|
||
| /// The barriers one of which must be passed for an XCM message to be executed. | ||
|
|
@@ -335,7 +341,7 @@ impl xcm_executor::Config for XcmConfig { | |
| type SubscriptionService = XcmPallet; | ||
| type PalletInstancesInfo = AllPalletsWithSystem; | ||
| type MaxAssetsIntoHolding = MaxAssetsIntoHolding; | ||
| type FeeManager = (); | ||
| type FeeManager = XcmFeesToAccount<Self, SystemParachains, AccountId, TreasuryAccount>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There shouldn't be -- with or without a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actual so I think this is the change, that origin needs to have some balance > ED + fees, but I dont know how much this is a really issue. I can imaging just some scenarios/calls from some non-system parachain that does not have sovereign account with balance on relay chain, so after this change they will need to drip some DOTs/KSMs to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, so I just took a look at where we collect fees in the XCM executor: it looks like any instruction where it creates and sends an XCM back to the origin would require the origin to pay for fees, and this includes the This isn't a huge deal, I think what we do need to do is to display delivery fees in the UI clearly so that users are informed about how much they need to pay, otherwise their XCM would fail to be sent. |
||
| // No bridges yet... | ||
| type MessageExporter = (); | ||
| type UniversalAliases = Nothing; | ||
|
|
@@ -352,7 +358,7 @@ parameter_types! { | |
|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| parameter_types! { | ||
| pub ReachableDest: Option<MultiLocation> = Some(Parachain(1000).into()); | ||
| pub ReachableDest: Option<MultiLocation> = Some(Parachain(STATEMINE_ID).into()); | ||
KiChjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use core::marker::PhantomData; | ||
| use frame_support::traits::{Contains, Get}; | ||
| use xcm::prelude::*; | ||
| use xcm_executor::traits::{FeeManager, FeeReason, TransactAsset}; | ||
|
|
||
| /// A `FeeManager` implementation that simply deposits the fees handled into a specific on-chain | ||
| /// `ReceiverAccount`. | ||
| /// | ||
| /// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets, and also | ||
| /// permits specifying `WaivedLocations` for locations that are privileged to not pay for fees. | ||
gilescope marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub struct XcmFeesToAccount<XcmConfig, WaivedLocations, AccountId, ReceiverAccount>( | ||
| PhantomData<(XcmConfig, WaivedLocations, AccountId, ReceiverAccount)>, | ||
| ); | ||
| impl< | ||
| XcmConfig: xcm_executor::Config, | ||
| WaivedLocations: Contains<MultiLocation>, | ||
| AccountId: Clone + Into<[u8; 32]>, | ||
| ReceiverAccount: Get<Option<AccountId>>, | ||
| > FeeManager for XcmFeesToAccount<XcmConfig, WaivedLocations, AccountId, ReceiverAccount> | ||
| { | ||
| fn is_waived(origin: Option<&MultiLocation>, _: FeeReason) -> bool { | ||
| let Some(loc) = origin else { return false }; | ||
| WaivedLocations::contains(loc) | ||
| } | ||
|
|
||
| fn handle_fee(fees: MultiAssets, context: Option<&XcmContext>) { | ||
| if let Some(receiver) = ReceiverAccount::get() { | ||
| let dest = AccountId32 { network: None, id: receiver.into() }.into(); | ||
| for asset in fees.into_inner() { | ||
| let ok = XcmConfig::AssetTransactor::deposit_asset(&asset, &dest, context).is_ok(); | ||
KiChjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| debug_assert!(ok, "`deposit_asset` cannot generally fail"); | ||
franciscoaguirre marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.