Skip to content

Commit

Permalink
Use EVMFungibleAdapter as default implementation (#1416)
Browse files Browse the repository at this point in the history
* Use EVMFungibleAdapter as default value

* Format
  • Loading branch information
boundless-forest authored May 7, 2024
1 parent 9af8d5b commit 0b524e8
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,7 @@ impl<T: Config> Pallet<T> {
/// Get the account basic in EVM format.
pub fn account_basic(address: &H160) -> (Account, frame_support::weights::Weight) {
let account_id = T::AddressMapping::into_account_id(*address);

let nonce = frame_system::Pallet::<T>::account_nonce(&account_id);
// keepalive `true` takes into account ExistentialDeposit as part of what's considered liquid balance.
let balance =
T::Currency::reducible_balance(&account_id, Preservation::Preserve, Fortitude::Polite);

Expand Down Expand Up @@ -1125,23 +1123,18 @@ where

/// Implementation for () does not specify what to do with imbalance
impl<T> OnChargeEVMTransaction<T> for ()
where
where
T: Config,
<T::Currency as Currency<<T as frame_system::Config>::AccountId>>::PositiveImbalance:
Imbalance<<T::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance, Opposite = <T::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance>,
<T::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance:
Imbalance<<T::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance, Opposite = <T::Currency as Currency<<T as frame_system::Config>::AccountId>>::PositiveImbalance>,
U256: UniqueSaturatedInto<BalanceOf<T>>,

T::Currency: Balanced<T::AccountId>,
U256: UniqueSaturatedInto<
<<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance,
>,
{
// Kept type as Option to satisfy bound of Default
type LiquidityInfo = Option<NegativeImbalanceOf<T::Currency, T>>;
type LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>;

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

fn correct_and_deposit_fee(
Expand All @@ -1150,11 +1143,16 @@ U256: UniqueSaturatedInto<BalanceOf<T>>,
base_fee: U256,
already_withdrawn: Self::LiquidityInfo,
) -> Self::LiquidityInfo {
<EVMCurrencyAdapter::<<T as Config>::Currency, ()> as OnChargeEVMTransaction<T>>::correct_and_deposit_fee(who, corrected_fee, base_fee, already_withdrawn)
<EVMFungibleAdapter<T::Currency, ()> as OnChargeEVMTransaction<T>>::correct_and_deposit_fee(
who,
corrected_fee,
base_fee,
already_withdrawn,
)
}

fn pay_priority_fee(tip: Self::LiquidityInfo) {
<EVMCurrencyAdapter::<<T as Config>::Currency, ()> as OnChargeEVMTransaction<T>>::pay_priority_fee(tip);
<EVMFungibleAdapter<T::Currency, ()> as OnChargeEVMTransaction<T>>::pay_priority_fee(tip);
}
}

Expand Down

0 comments on commit 0b524e8

Please sign in to comment.