diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index c2bae9ce81..cffd897a47 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -77,18 +77,18 @@ use frame_support::{ dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo}, storage::child::KillStorageResult, traits::{ + fungible::{Balanced, Credit, Debt}, tokens::{ currency::Currency, fungible::Inspect, imbalance::{Imbalance, OnUnbalanced, SignedImbalance}, - ExistenceRequirement, Fortitude, Preservation, WithdrawReasons, + ExistenceRequirement, Fortitude, Precision, Preservation, WithdrawConsequence, + WithdrawReasons, }, FindAuthor, Get, Time, }, weights::Weight, }; -use frame_support::traits::fungible::{Balanced, Credit, Debt}; -use frame_support::traits::tokens::Precision; use frame_system::RawOrigin; use sp_core::{H160, H256, U256}; use sp_runtime::{ @@ -1058,6 +1058,7 @@ where } } } + /// Implements transaction payment for a pallet implementing the [`fungible`] /// trait (eg. pallet_balances) using an unbalance handler (implementing /// [`OnUnbalanced`]). @@ -1067,11 +1068,11 @@ where pub struct EVMFungibleAdapter(sp_std::marker::PhantomData<(F, OU)>); impl OnChargeEVMTransaction for EVMFungibleAdapter - where - T: Config, - F: Balanced, - OU: OnUnbalanced>, - U256: UniqueSaturatedInto<::AccountId>>::Balance>, +where + T: Config, + F: Balanced, + OU: OnUnbalanced>, + U256: UniqueSaturatedInto<::AccountId>>::Balance>, { // Kept type as Option to satisfy bound of Default type LiquidityInfo = Option>; @@ -1088,10 +1089,19 @@ impl OnChargeEVMTransaction for EVMFungibleAdapter Preservation::Preserve, Fortitude::Polite, ) - .map_err(|_| Error::::BalanceLow)?; + .map_err(|_| Error::::BalanceLow)?; Ok(Some(imbalance)) } + fn can_withdraw(who: &H160, amount: U256) -> Result<(), Error> { + let account_id = T::AddressMapping::into_account_id(*who); + let amount = amount.unique_saturated_into(); + if let WithdrawConsequence::Success = F::can_withdraw(&account_id, amount) { + return Ok(()); + } + Err(Error::::BalanceLow) + } + fn correct_and_deposit_fee( who: &H160, corrected_fee: U256,