mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-04-22 03:17:56 +00:00
Feemanager for evm (#239)
This commit is contained in:
committed by
Gustavo Gonzalez
parent
d14851cc47
commit
29c6332022
@@ -1,3 +1,5 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess},
|
||||
@@ -5,17 +7,21 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
use pallet_xcm::XcmPassthrough;
|
||||
use polkadot_parachain_primitives::primitives::Sibling;
|
||||
use xcm::latest::prelude::*;
|
||||
use polkadot_parachain_primitives::primitives::{self, Sibling};
|
||||
use xcm::latest::prelude::{Assets as XcmAssets, *};
|
||||
use xcm_builder::{
|
||||
AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
|
||||
ConvertedConcreteId, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
|
||||
FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete,
|
||||
NativeAsset, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
|
||||
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
|
||||
TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
|
||||
FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HandleFee,
|
||||
IsChildSystemParachain, IsConcrete, NativeAsset, NoChecking, ParentIsPreset,
|
||||
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
|
||||
SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
|
||||
UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
|
||||
};
|
||||
use xcm_executor::{
|
||||
traits::{FeeReason, JustTry, TransactAsset},
|
||||
XcmExecutor,
|
||||
};
|
||||
use xcm_executor::{traits::JustTry, XcmExecutor};
|
||||
use xcm_primitives::AsAssetType;
|
||||
|
||||
use crate::{
|
||||
@@ -25,6 +31,7 @@ use crate::{
|
||||
},
|
||||
types::{AccountId, AssetId, Balance, XcmFeesToAccount},
|
||||
weights, AllPalletsWithSystem, AssetManager, Assets, Balances, ParachainInfo, PolkadotXcm,
|
||||
Treasury,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
@@ -141,6 +148,50 @@ pub type Barrier = TrailingSetTopicAsId<
|
||||
>,
|
||||
>;
|
||||
|
||||
/// A `HandleFee` implementation that simply deposits the fees into a specific on-chain
|
||||
/// `ReceiverAccount`.
|
||||
///
|
||||
/// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If
|
||||
/// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be
|
||||
/// logged and the fee burned.
|
||||
pub struct XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>(
|
||||
PhantomData<(AssetTransactor, AccountId, ReceiverAccount)>,
|
||||
);
|
||||
impl<
|
||||
AssetTransactor: TransactAsset,
|
||||
AccountId: Clone + Into<[u8; 20]>,
|
||||
ReceiverAccount: Get<AccountId>,
|
||||
> HandleFee for XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>
|
||||
{
|
||||
fn handle_fee(fee: XcmAssets, context: Option<&XcmContext>, _reason: FeeReason) -> XcmAssets {
|
||||
deposit_or_burn_fee::<AssetTransactor, _>(fee, context, ReceiverAccount::get());
|
||||
|
||||
XcmAssets::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 20]>>(
|
||||
fee: XcmAssets,
|
||||
context: Option<&XcmContext>,
|
||||
receiver: AccountId,
|
||||
) {
|
||||
let dest = AccountKey20 { network: None, key: receiver.into() }.into();
|
||||
for asset in fee.into_inner() {
|
||||
if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) {
|
||||
log::trace!(
|
||||
target: "xcm::fees",
|
||||
"`AssetTransactor::deposit_asset` returned error: {:?}. Burning fee: {:?}. \
|
||||
They might be burned.",
|
||||
e, asset,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub TreasuryAccount: AccountId = Treasury::account_id();
|
||||
}
|
||||
|
||||
pub struct XcmConfig;
|
||||
impl xcm_executor::Config for XcmConfig {
|
||||
type Aliasers = Nothing;
|
||||
@@ -152,7 +203,10 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type AssetTrap = PolkadotXcm;
|
||||
type Barrier = Barrier;
|
||||
type CallDispatcher = RuntimeCall;
|
||||
type FeeManager = ();
|
||||
type FeeManager = XcmFeeManagerFromComponents<
|
||||
IsChildSystemParachain<primitives::Id>,
|
||||
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
|
||||
>;
|
||||
type HrmpChannelAcceptedHandler = ();
|
||||
type HrmpChannelClosingHandler = ();
|
||||
type HrmpNewChannelOpenRequestHandler = ();
|
||||
|
||||
Reference in New Issue
Block a user