Skip to content

Commit

Permalink
Defer to DealWithFees for treasury/author split
Browse files Browse the repository at this point in the history
  • Loading branch information
Branan Riley committed Aug 21, 2023
1 parent 33b18c2 commit daa1854
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions runtime/common/src/evm/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use core::marker::PhantomData;

use cfg_primitives::constants::TREASURY_FEE_RATIO;
use frame_support::traits::{
Currency, ExistenceRequirement, Imbalance, OnUnbalanced, SignedImbalance, WithdrawReasons,
};
Expand All @@ -25,17 +24,18 @@ use pallet_treasury::Pallet as Treasury;
use sp_core::{H160, U256};
use sp_runtime::{
traits::{UniqueSaturatedInto, Zero},
Perbill, Saturating,
Saturating,
};

use crate::fees::{NegativeImbalance, ToAuthor};
use crate::fees::{DealWithFees, NegativeImbalance};

type AccountIdOf<R> = <R as frame_system::Config>::AccountId;
type Balance<R> = <Balances<R> as Currency<AccountIdOf<R>>>::Balance;
type PositiveImbalance<R> = <Balances<R> as Currency<AccountIdOf<R>>>::PositiveImbalance;

type Error<R> = pallet_evm::Error<R>;

/// Handler for EVM fees
pub struct DealWithEVMFees<R>(PhantomData<R>);

impl<R> OnChargeEVMTransaction<R> for DealWithEVMFees<R>
Expand Down Expand Up @@ -111,20 +111,14 @@ where
.unwrap_or_else(|_| NegativeImbalance::<R>::zero());

let (base_fee, tip) = adjusted_paid.split(base_fee.unique_saturated_into());

// Handle base fee and tips
let (treasury_amount, mut author_amount) = base_fee.ration(
TREASURY_FEE_RATIO.deconstruct(),
(Perbill::one() - TREASURY_FEE_RATIO).deconstruct(),
);
tip.merge_into(&mut author_amount);
<Treasury<R> as OnUnbalanced<_>>::on_unbalanced(treasury_amount);
<ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(author_amount);

DealWithFees::<R>::on_unbalanceds([base_fee, tip].into_iter());
None
}

fn pay_priority_fee(tip: Self::LiquidityInfo) {
// Because we handle the priority fee in the above function,
// there's nothing to do here. Assert for verification
// purposes.
assert!(tip.is_none())
}
}
2 changes: 1 addition & 1 deletion runtime/development/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use frame_system::EnsureRoot;
use pallet_evm::EnsureAddressTruncated;
use runtime_common::{
account_conversion::AccountConverter,
evm::{fees::DealWithEVMFees, precompile::Developmennt, BaseFeeThreshold, WEIGHT_PER_GAS},
evm::{fees::DealWithEVMFees, precompile::Development, BaseFeeThreshold, WEIGHT_PER_GAS},
};
use sp_core::{crypto::ByteArray, H160, U256};
use sp_runtime::Permill;
Expand Down

0 comments on commit daa1854

Please sign in to comment.