Skip to content

Commit

Permalink
fix: updated impl_on_charge_evm_transaction to use EVMFungibleAdapter…
Browse files Browse the repository at this point in the history
… for frontier template
  • Loading branch information
Aleksandar Brayanov committed Nov 21, 2024
1 parent bb9e9ae commit ea4d27b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,22 @@ macro_rules! impl_on_charge_evm_transaction {
type CurrencyAccountId<T> = <T as frame_system::Config>::AccountId;

type BalanceFor<T> =
<<T as pallet_evm::Config>::Currency as CurrencyT<CurrencyAccountId<T>>>::Balance;

type PositiveImbalanceFor<T> =
<<T as pallet_evm::Config>::Currency as CurrencyT<CurrencyAccountId<T>>>::PositiveImbalance;

type NegativeImbalanceFor<T> =
<<T as pallet_evm::Config>::Currency as CurrencyT<CurrencyAccountId<T>>>::NegativeImbalance;
<<T as pallet_evm::Config>::Currency as Inspect<CurrencyAccountId<T>>>::Balance;

pub struct OnChargeEVMTransaction<OU>(sp_std::marker::PhantomData<OU>);
impl<T, OU> OnChargeEVMTransactionT<T> for OnChargeEVMTransaction<OU>
where
T: pallet_evm::Config,
PositiveImbalanceFor<T>: Imbalance<BalanceFor<T>, Opposite = NegativeImbalanceFor<T>>,
NegativeImbalanceFor<T>: Imbalance<BalanceFor<T>, Opposite = PositiveImbalanceFor<T>>,
OU: OnUnbalanced<NegativeImbalanceFor<T>>,
U256: UniqueSaturatedInto<BalanceFor<T>>
T::Currency: Balanced<pallet_evm::AccountIdOf<T>>,
OU: OnUnbalanced<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>,
U256: UniqueSaturatedInto<<T::Currency as Inspect<pallet_evm::AccountIdOf<T>>>::Balance>,
T::AddressMapping: pallet_evm::AddressMapping<T::AccountId>,

{
type LiquidityInfo = Option<NegativeImbalanceFor<T>>;
type LiquidityInfo = Option<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>;

fn withdraw_fee(who: &H160, fee: U256) -> Result<Self::LiquidityInfo, pallet_evm::Error<T>> {
EVMCurrencyAdapter::<<T as pallet_evm::Config>::Currency, ()>::withdraw_fee(who, fee)
EVMFungibleAdapter::<<T as pallet_evm::Config>::Currency, ()>::withdraw_fee(who, fee)
}

fn correct_and_deposit_fee(
Expand All @@ -49,7 +44,7 @@ macro_rules! impl_on_charge_evm_transaction {
base_fee: U256,
already_withdrawn: Self::LiquidityInfo,
) -> Self::LiquidityInfo {
<EVMCurrencyAdapter<<T as pallet_evm::Config>::Currency, OU> as OnChargeEVMTransactionT<
<EVMFungibleAdapter<<T as pallet_evm::Config>::Currency, OU> as OnChargeEVMTransactionT<
T,
>>::correct_and_deposit_fee(who, corrected_fee, base_fee, already_withdrawn)
}
Expand Down
14 changes: 8 additions & 6 deletions container-chains/runtime-templates/frontier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ use {
pallet_prelude::DispatchResult,
parameter_types,
traits::{
tokens::ConversionToAssetBalance, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8,
Contains, Currency as CurrencyT, FindAuthor, Imbalance, InsideBoth, InstanceFilter,
OnFinalize, OnUnbalanced,
fungible::{Balanced, Credit, Inspect},
tokens::ConversionToAssetBalance,
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Contains, Currency as CurrencyT,
FindAuthor, Imbalance, InsideBoth, InstanceFilter, OnFinalize, OnUnbalanced,
},
weights::{
constants::{
Expand All @@ -68,9 +69,10 @@ use {
nimbus_primitives::{NimbusId, SlotBeacon},
pallet_ethereum::{Call::transact, PostLogContent, Transaction as EthereumTransaction},
pallet_evm::{
Account as EVMAccount, EVMCurrencyAdapter, EnsureAddressNever, EnsureAddressRoot,
EnsureCreateOrigin, FeeCalculator, FrameSystemAccountProvider, GasWeightMapping,
IdentityAddressMapping, OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner,
Account as EVMAccount, EVMCurrencyAdapter, EVMFungibleAdapter, EnsureAddressNever,
EnsureAddressRoot, EnsureCreateOrigin, FeeCalculator, FrameSystemAccountProvider,
GasWeightMapping, IdentityAddressMapping,
OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner,
},
pallet_transaction_payment::FungibleAdapter,
parity_scale_codec::{Decode, Encode},
Expand Down

0 comments on commit ea4d27b

Please sign in to comment.