-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce new fee calculator for evm domain and refactor eth constant…
…s to primitives
- Loading branch information
Showing
16 changed files
with
186 additions
and
260 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//! Fees module for EVM domain | ||
use crate::Config; | ||
use core::marker::PhantomData; | ||
use domain_runtime_primitives::Balance; | ||
use pallet_block_fees::Pallet as BlockFees; | ||
use pallet_evm::FeeCalculator; | ||
use pallet_transaction_payment::Pallet as TransactionPayment; | ||
use sp_core::U256; | ||
use sp_evm_tracker::WEIGHT_PER_GAS; | ||
use sp_runtime::traits::Get; | ||
use sp_runtime::{FixedPointNumber, Perbill}; | ||
use sp_weights::Weight; | ||
|
||
/// Evm gas price calculator for EVM domains. | ||
/// TransactionWeightFee is the fee for 1 unit of Weight. | ||
/// GasPerByte is the gas for 1 byte | ||
pub struct EvmGasPriceCalculator<T, TransactionWeightFee, GasPerByte, StorageFeePercent>( | ||
PhantomData<(T, TransactionWeightFee, GasPerByte, StorageFeePercent)>, | ||
); | ||
|
||
impl<T, TransactionWeightFee, GasPerByte, StorageFeePercent> FeeCalculator | ||
for EvmGasPriceCalculator<T, TransactionWeightFee, GasPerByte, StorageFeePercent> | ||
where | ||
T: Config | ||
+ frame_system::Config | ||
+ pallet_transaction_payment::Config | ||
+ pallet_block_fees::Config<Balance = Balance>, | ||
TransactionWeightFee: Get<T::Balance>, | ||
GasPerByte: Get<T::Balance>, | ||
{ | ||
fn min_gas_price() -> (U256, Weight) { | ||
// spread the storage fee across the gas price based on the Gas Per Byte. | ||
let storage_fee_per_gas = | ||
BlockFees::<T>::final_domain_transaction_byte_fee().saturating_div(GasPerByte::get()); | ||
// adjust the fee per weight using the multiplier | ||
let weight_fee = TransactionWeightFee::get().saturating_mul(WEIGHT_PER_GAS.into()); | ||
let adjusted_weight_fee = | ||
TransactionPayment::<T>::next_fee_multiplier().saturating_mul_int(weight_fee); | ||
|
||
// finally add the storage_fee_per_gas and adjusted_weight_fee to calculate the final | ||
// min_gas_price. | ||
let min_gas_price = adjusted_weight_fee.saturating_add(storage_fee_per_gas); | ||
( | ||
min_gas_price.into(), | ||
<T as frame_system::Config>::DbWeight::get().reads(2), | ||
) | ||
} | ||
} | ||
|
||
impl<T, TransactionWeightFee, BytePerFee, StorageFeePercent> | ||
EvmGasPriceCalculator<T, TransactionWeightFee, BytePerFee, StorageFeePercent> | ||
where | ||
StorageFeePercent: Get<Perbill>, | ||
{ | ||
pub fn split_fee_into_storage_and_execution(fee: Balance) -> (Balance, Balance) { | ||
let ratio = StorageFeePercent::get(); | ||
let storage_fee = ratio.mul_ceil(fee); | ||
(storage_fee, fee.saturating_sub(storage_fee)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.