mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 04:41:03 +00:00
8349c8d18a
* restructure macro related exports * restructure macro related exports * wip * wip * update cargo lock * refactor RuntimeDebug on unincluded segment * fmt * Companion: restructure `benchmarking` macro related exports (#3039) * wip * wip * restructure benchmarking macro related exports * add cargo lock --------- Co-authored-by: parity-processbot <>
66 lines
2.5 KiB
Rust
66 lines
2.5 KiB
Rust
use crate::impls::AccountIdOf;
|
|
use core::marker::PhantomData;
|
|
use frame_support::{
|
|
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, ContainsPair},
|
|
weights::Weight,
|
|
};
|
|
use log;
|
|
use sp_runtime::traits::Get;
|
|
use xcm::latest::prelude::*;
|
|
|
|
/// 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,
|
|
AssetInstance: 'static,
|
|
>(PhantomData<(Runtime, WeightToFee, BalanceConverter, AssetInstance)>);
|
|
impl<CurrencyBalance, Runtime, WeightToFee, BalanceConverter, AssetInstance>
|
|
cumulus_primitives_utility::ChargeWeightInFungibles<
|
|
AccountIdOf<Runtime>,
|
|
pallet_assets::Pallet<Runtime, AssetInstance>,
|
|
> for AssetFeeAsExistentialDepositMultiplier<Runtime, WeightToFee, BalanceConverter, AssetInstance>
|
|
where
|
|
Runtime: pallet_assets::Config<AssetInstance>,
|
|
WeightToFee: frame_support::weights::WeightToFee<Balance = CurrencyBalance>,
|
|
BalanceConverter: ConversionToAssetBalance<
|
|
CurrencyBalance,
|
|
<Runtime as pallet_assets::Config<AssetInstance>>::AssetId,
|
|
<Runtime as pallet_assets::Config<AssetInstance>>::Balance,
|
|
>,
|
|
AccountIdOf<Runtime>:
|
|
From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>,
|
|
{
|
|
fn charge_weight_in_fungibles(
|
|
asset_id: <pallet_assets::Pallet<Runtime, AssetInstance> as Inspect<
|
|
AccountIdOf<Runtime>,
|
|
>>::AssetId,
|
|
weight: Weight,
|
|
) -> Result<
|
|
<pallet_assets::Pallet<Runtime, AssetInstance> 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)
|
|
}
|
|
}
|
|
|
|
/// Accepts an asset if it is a native asset from a particular `MultiLocation`.
|
|
pub struct ConcreteNativeAssetFrom<Location>(PhantomData<Location>);
|
|
impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
|
for ConcreteNativeAssetFrom<Location>
|
|
{
|
|
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
|
log::trace!(target: "xcm::filter_asset_location",
|
|
"ConcreteNativeAsset asset: {:?}, origin: {:?}, location: {:?}",
|
|
asset, origin, Location::get());
|
|
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
|
|
}
|
|
}
|