1use sp_core::{U256, H160};2use frame_support::{3 weights::{Weight, constants::WEIGHT_PER_SECOND},4 traits::{FindAuthor},5 parameter_types, ConsensusEngineId,6};7use sp_runtime::{RuntimeAppPublic, Perbill};8use crate::{9 runtime_common::{10 constants::*, dispatch::CollectionDispatchT, ethereum::sponsoring::EvmSponsorshipHandler,11 config::sponsoring::DefaultSponsoringRateLimit, DealWithFees,12 },13 Runtime, Aura, Balances, Event, ChainId,14};15use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};1617pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;1819impl pallet_evm::account::Config for Runtime {20 type CrossAccountId = CrossAccountId;21 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;22 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;23}2425262728parameter_types! {29 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;30 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;31 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();32}3334353637const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);38parameter_types! {39 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());40}4142pub enum FixedGasWeightMapping {}43impl pallet_evm::GasWeightMapping for FixedGasWeightMapping {44 fn gas_to_weight(gas: u64) -> Weight {45 gas.saturating_mul(WeightPerGas::get())46 }47 fn weight_to_gas(weight: Weight) -> u64 {48 weight / WeightPerGas::get()49 }50}5152pub struct FixedFee;53impl pallet_evm::FeeCalculator for FixedFee {54 fn min_gas_price() -> (U256, u64) {55 (MIN_GAS_PRICE.into(), 0)56 }57}5859pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);60impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {61 fn find_author<'a, I>(digests: I) -> Option<H160>62 where63 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,64 {65 if let Some(author_index) = F::find_author(digests) {66 let authority_id = Aura::authorities()[author_index as usize].clone();67 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));68 }69 None70 }71}7273impl pallet_evm::Config for Runtime {74 type BlockGasLimit = BlockGasLimit;75 type FeeCalculator = FixedFee;76 type GasWeightMapping = FixedGasWeightMapping;77 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;78 type CallOrigin = EnsureAddressTruncated<Self>;79 type WithdrawOrigin = EnsureAddressTruncated<Self>;80 type AddressMapping = HashedAddressMapping<Self::Hashing>;81 type PrecompilesType = ();82 type PrecompilesValue = ();83 type Currency = Balances;84 type Event = Event;85 type OnMethodCall = (86 pallet_evm_migration::OnMethodCall<Self>,87 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,88 CollectionDispatchT<Self>,89 pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,90 );91 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;92 type ChainId = ChainId;93 type Runner = pallet_evm::runner::stack::Runner<Self>;94 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;95 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;96 type FindAuthor = EthereumFindAuthor<Aura>;97}9899impl pallet_evm_migration::Config for Runtime {100 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;101}102103impl pallet_ethereum::Config for Runtime {104 type Event = Event;105 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;106}107108parameter_types! {109 110 pub const HelpersContractAddress: H160 = H160([111 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,112 ]);113114 115 pub const EvmCollectionHelpersAddress: H160 = H160([116 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,117 ]);118}119120impl pallet_evm_contract_helpers::Config for Runtime {121 type ContractAddress = HelpersContractAddress;122 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;123}124125impl pallet_evm_coder_substrate::Config for Runtime {}126127impl pallet_evm_transaction_payment::Config for Runtime {128 type EvmSponsorshipHandler = EvmSponsorshipHandler;129 type Currency = Balances;130}