mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
backport #1278
This commit is contained in:
committed by
Ignacio Palacios
parent
45d338cb7c
commit
afb02cbb58
@@ -35,6 +35,7 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features
|
||||
|
||||
# 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 = "polkadot-v0.9.27" }
|
||||
@@ -61,4 +62,6 @@ std = [
|
||||
"sp-io/std",
|
||||
"sp-std/std",
|
||||
"pallet-collator-selection/std",
|
||||
"cumulus-primitives-utility/std",
|
||||
"xcm-builder/std"
|
||||
]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user