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 dispatch::CollectionDispatchT, ethereum::sponsoring::EvmSponsorshipHandler,11 config::sponsoring::DefaultSponsoringRateLimit, DealWithFees,12 },13 Runtime, Aura, Balances, RuntimeEvent, ChainId,14};15use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};16use up_common::constants::*;1718pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;1920212223parameter_types! {24 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND.ref_time() / <Runtime as frame_system::Config>::DbWeight::get().write;25 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;26 pub const WeightTimePerGas: u64 = WEIGHT_PER_SECOND.ref_time() / GasPerSecond::get();2728 pub const WeightPerGas: Weight = Weight::from_ref_time(WeightTimePerGas::get());29}3031323334const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);35parameter_types! {36 pub BlockGasLimit: U256 = U256::from((NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightTimePerGas::get()).ref_time());37}3839pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);40impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {41 fn find_author<'a, I>(digests: I) -> Option<H160>42 where43 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,44 {45 if let Some(author_index) = F::find_author(digests) {46 let authority_id = Aura::authorities()[author_index as usize].clone();47 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));48 }49 None50 }51}5253impl pallet_evm::Config for Runtime {54 type CrossAccountId = CrossAccountId;55 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;56 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;57 type BlockGasLimit = BlockGasLimit;58 type FeeCalculator = pallet_configuration::FeeCalculator<Self>;59 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;60 type WeightPerGas = WeightPerGas;61 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;62 type CallOrigin = EnsureAddressTruncated<Self>;63 type WithdrawOrigin = EnsureAddressTruncated<Self>;64 type AddressMapping = HashedAddressMapping<Self::Hashing>;65 type PrecompilesType = ();66 type PrecompilesValue = ();67 type Currency = Balances;68 type RuntimeEvent = RuntimeEvent;69 type OnMethodCall = (70 pallet_evm_migration::OnMethodCall<Self>,71 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,72 CollectionDispatchT<Self>,73 pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,74 );75 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;76 type ChainId = ChainId;77 type Runner = pallet_evm::runner::stack::Runner<Self>;78 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;79 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;80 type FindAuthor = EthereumFindAuthor<Aura>;81}8283impl pallet_evm_migration::Config for Runtime {84 type RuntimeEvent = RuntimeEvent;85 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;86}8788impl pallet_ethereum::Config for Runtime {89 type RuntimeEvent = RuntimeEvent;90 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;91}9293parameter_types! {94 95 pub const HelpersContractAddress: H160 = H160([96 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,97 ]);9899 100 pub const EvmCollectionHelpersAddress: H160 = H160([101 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,102 ]);103}104105impl pallet_evm_contract_helpers::Config for Runtime {106 type RuntimeEvent = RuntimeEvent;107 type ContractAddress = HelpersContractAddress;108 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;109}110111impl pallet_evm_coder_substrate::Config for Runtime {}112113impl pallet_evm_transaction_payment::Config for Runtime {114 type EvmSponsorshipHandler = EvmSponsorshipHandler;115}