moonbeam_runtime_common/
impl_on_charge_evm_transaction.rs1#[macro_export]
18macro_rules! impl_on_charge_evm_transaction {
19 {} => {
20 type FungibleAccountId<T> = <T as frame_system::Config>::AccountId;
21
22 type BalanceFor<T> =
23 <<T as pallet_evm::Config>::Currency as Inspect<FungibleAccountId<T>>>::Balance;
24
25 pub struct OnChargeEVMTransaction<BaseFeesOU, PriorityFeesOU>(
26 sp_std::marker::PhantomData<(BaseFeesOU, PriorityFeesOU)>
27 );
28
29 impl<T, BaseFeesOU, PriorityFeesOU> OnChargeEVMTransactionT<T>
30 for OnChargeEVMTransaction<BaseFeesOU, PriorityFeesOU>
31 where
32 T: pallet_evm::Config,
33 T::Currency: Balanced<pallet_evm::AccountIdOf<T>>,
34 BaseFeesOU: OnUnbalanced<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>,
35 PriorityFeesOU: OnUnbalanced<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>,
36 U256: UniqueSaturatedInto<<T::Currency as Inspect<pallet_evm::AccountIdOf<T>>>::Balance>,
37 T::AddressMapping: pallet_evm::AddressMapping<T::AccountId>,
38 {
39 type LiquidityInfo = Option<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>;
40
41 fn withdraw_fee(who: &H160, fee: U256) -> Result<Self::LiquidityInfo, pallet_evm::Error<T>> {
42 EVMFungibleAdapter::<<T as pallet_evm::Config>::Currency, ()>::withdraw_fee(who, fee)
43 }
44
45 fn can_withdraw(who: &H160, amount: U256) -> Result<(), pallet_evm::Error<T>> {
46 EVMFungibleAdapter::<<T as pallet_evm::Config>::Currency, ()>::can_withdraw(who, amount)
47 }
48
49 fn correct_and_deposit_fee(
50 who: &H160,
51 corrected_fee: U256,
52 base_fee: U256,
53 already_withdrawn: Self::LiquidityInfo,
54 ) -> Self::LiquidityInfo {
55 <EVMFungibleAdapter<<T as pallet_evm::Config>::Currency, BaseFeesOU> as OnChargeEVMTransactionT<
56 T,
57 >>::correct_and_deposit_fee(who, corrected_fee, base_fee, already_withdrawn)
58 }
59
60 fn pay_priority_fee(tip: Self::LiquidityInfo) {
61 if let Some(tip) = tip {
62 PriorityFeesOU::on_unbalanced(tip);
63 }
64 }
65 }
66 }
67}