Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Statemint runtimes to accept sufficient assets as xcm fee payment #1278

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
b4ae54e
point to my branch
girazoki May 19, 2022
28553a0
girazoki-add-TakeFirstAssetTrader-to-utility
girazoki May 18, 2022
df1c4da
Commit lock
girazoki May 19, 2022
6adb10d
point at custom branch
girazoki May 18, 2022
c9e9f8c
add new trader to statemine runtimes
girazoki May 19, 2022
9b80254
compiles
girazoki May 19, 2022
7b93596
Back to master
girazoki May 20, 2022
9863c61
Update last tomls
girazoki May 20, 2022
6d0c084
Imports up
girazoki May 20, 2022
bac87a3
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki May 20, 2022
ab1103c
remove non-needing imports
girazoki May 20, 2022
d65b568
FMT
girazoki May 20, 2022
212f32e
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki May 24, 2022
8c14940
log messages properly
girazoki May 25, 2022
ee07ca2
Use TakeRevenue instead of HandleCredit
notlesh May 25, 2022
63fb3f2
Introduce xcm fee handler
girazoki May 26, 2022
7efb86b
check total supply in tests
girazoki May 26, 2022
b6d9b8d
FMT
girazoki May 26, 2022
916ab52
fix test
girazoki May 26, 2022
a0f2d3d
Start decoupling balance calculation into different traits
girazoki May 26, 2022
496b8fc
Make traits a bit more generic
girazoki May 26, 2022
02b617d
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki Jun 2, 2022
fe02000
PR suggestions
girazoki Jun 6, 2022
a19805d
add import
girazoki Jun 6, 2022
1d506a2
import well
girazoki Jun 6, 2022
428191d
Place xcmfeesassethandler into parachains common
girazoki Jun 6, 2022
668151c
fix tests
girazoki Jun 7, 2022
1a25dee
config parameters
girazoki Jun 13, 2022
77c275f
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki Jun 24, 2022
6cbc21c
Min amount to fee receiver
girazoki Jun 27, 2022
1e782b4
Make minimum amount for block author to be at least the ED
girazoki Jun 28, 2022
8618899
Doc in AssetFeeAsExistentialDepositMultiplier
girazoki Jun 28, 2022
0137d32
saturating sub
girazoki Jul 6, 2022
b9b83e7
make sure we dont enter twice
girazoki Jul 11, 2022
465aab9
FMT
girazoki Jul 11, 2022
a510288
fmt again
girazoki Jul 11, 2022
e5bf219
adapt tests
girazoki Jul 11, 2022
b4f45fa
Add doc and struct for weight refund
girazoki Jul 18, 2022
c6b8eaa
Doc
girazoki Jul 18, 2022
91d0878
More doc
girazoki Jul 18, 2022
f882b79
PR suggestions
girazoki Jul 19, 2022
9f74532
store all info related to asset payment as multiasset
girazoki Jul 19, 2022
dc7cc23
return AssetNotFound instead of TooExpensive
girazoki Jul 19, 2022
ad97b64
Use asset transactor to deposit fee
girazoki Jul 20, 2022
7ec6100
uninstall from statemint
girazoki Jul 20, 2022
a433035
R for RUntime and CON for BalanceConverter
girazoki Jul 20, 2022
10cb93e
Rework logic to avoid unnecesary match and error
girazoki Jul 20, 2022
3523ace
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki Jul 20, 2022
83f44c5
Rework ED check, also in case of refund
girazoki Jul 20, 2022
846ceae
rework typo
girazoki Jul 20, 2022
5078b77
In case refund makes drop below ED, just refund the difference
girazoki Jul 21, 2022
d8a0669
fix test westmint
girazoki Jul 21, 2022
77b7f23
clone id
girazoki Jul 21, 2022
d316bb3
move test imports to preamble
joepetrowski Jul 28, 2022
0ea3471
move test imports to preamble
joepetrowski Jul 28, 2022
8a79315
test-utils with builderS
girazoki Aug 1, 2022
7e2ea86
lock file updated
girazoki Aug 1, 2022
9d513de
Merge remote-tracking branch 'origin' into girazoki-statemint-runtime…
joepetrowski Aug 3, 2022
e3b65f6
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki Aug 3, 2022
7b894ae
Merge branch 'girazoki-statemint-runtimes-to-accept-sufficient-assets…
girazoki Aug 3, 2022
be89676
Merge remote-tracking branch 'upstream/master' into girazoki-statemin…
girazoki Aug 3, 2022
20584ac
remove unused imports
girazoki Aug 3, 2022
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
27 changes: 27 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions parachains/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

# Cumulus
pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false }
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }

[dev-dependencies]
pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand All @@ -60,4 +62,6 @@ std = [
"sp-io/std",
"sp-std/std",
"pallet-collator-selection/std",
"cumulus-primitives-utility/std",
"xcm-builder/std"
]
43 changes: 42 additions & 1 deletion parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::impls::AccountIdOf;
use core::marker::PhantomData;
use frame_support::{log, weights::Weight};
use frame_support::{
log,
traits::{fungibles::Inspect, tokens::BalanceConversion},
weights::{Weight, WeightToFee, WeightToFeePolynomial},
};
use xcm::latest::prelude::*;
use xcm_executor::traits::ShouldExecute;

Expand Down Expand Up @@ -66,3 +71,39 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
Ok(())
}
}

/// A `ChargeFeeInFungibles` implementation that converts the output of
/// a given WeightToFee implementation an amount charged in
/// a particular assetId from pallet-assets
pub struct AssetFeeAsExistentialDepositMultiplier<Runtime, WeightToFee, BalanceConverter>(
PhantomData<(Runtime, WeightToFee, BalanceConverter)>,
);
impl<CurrencyBalance, Runtime, WeightToFee, BalanceConverter>
cumulus_primitives_utility::ChargeWeightInFungibles<
AccountIdOf<Runtime>,
pallet_assets::Pallet<Runtime>,
> for AssetFeeAsExistentialDepositMultiplier<Runtime, WeightToFee, BalanceConverter>
where
Runtime: pallet_assets::Config,
WeightToFee: WeightToFeePolynomial<Balance = CurrencyBalance>,
BalanceConverter: BalanceConversion<
CurrencyBalance,
<Runtime as pallet_assets::Config>::AssetId,
<Runtime as pallet_assets::Config>::Balance,
>,
AccountIdOf<Runtime>:
From<polkadot_primitives::v2::AccountId> + Into<polkadot_primitives::v2::AccountId>,
{
fn charge_weight_in_fungibles(
asset_id: <pallet_assets::Pallet<Runtime> as Inspect<AccountIdOf<Runtime>>>::AssetId,
weight: Weight,
) -> Result<<pallet_assets::Pallet<Runtime> as Inspect<AccountIdOf<Runtime>>>::Balance, XcmError>
{
let amount = WeightToFee::weight_to_fee(&weight);
// If the amount gotten is not at least the ED, then make it be the ED of the asset
// This is to avoid burning assets and decreasing the supply
let asset_amount = BalanceConverter::to_asset_balance(amount, asset_id)
.map_err(|_| XcmError::TooExpensive)?;
Ok(asset_amount)
}
}
1 change: 1 addition & 0 deletions parachains/runtimes/assets/statemine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ parachains-common = { path = "../../../common", default-features = false }

[dev-dependencies]
hex-literal = "0.3.4"
asset-test-utils = { path = "../test-utils"}

[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
33 changes: 29 additions & 4 deletions parachains/runtimes/assets/statemine/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.

use super::{
AccountId, AssetId, Assets, Balance, Balances, Call, Event, Origin, ParachainInfo,
AccountId, AssetId, Assets, Authorship, Balance, Balances, Call, Event, Origin, ParachainInfo,
ParachainSystem, PolkadotXcm, Runtime, WeightToFee, XcmpQueue,
};
use frame_support::{
Expand All @@ -25,9 +25,12 @@ use frame_support::{
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{DenyReserveTransferToRelayChain, DenyThenTry},
xcm_config::{
AssetFeeAsExistentialDepositMultiplier, DenyReserveTransferToRelayChain, DenyThenTry,
},
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::ConvertInto;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
Expand Down Expand Up @@ -129,6 +132,7 @@ parameter_types! {
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: Weight = 1_000_000_000;
pub const MaxInstructions: u32 = 100;
pub XcmAssetFeesReceiver: Option<AccountId> = Authorship::author();
}

match_types! {
Expand Down Expand Up @@ -170,8 +174,29 @@ impl xcm_executor::Config for XcmConfig {
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type Trader =
UsingComponents<WeightToFee, KsmLocation, AccountId, Balances, ToStakingPot<Runtime>>;
type Trader = (
UsingComponents<WeightToFee, KsmLocation, AccountId, Balances, ToStakingPot<Runtime>>,
cumulus_primitives_utility::TakeFirstAssetTrader<
AccountId,
AssetFeeAsExistentialDepositMultiplier<
Runtime,
WeightToFee,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
>,
ConvertedConcreteAssetId<
AssetId,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
JustTry,
>,
Assets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
FungiblesTransactor,
AccountId,
XcmAssetFeesReceiver,
>,
>,
);
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
Expand Down
Loading