1use sp_core::{U256, H160};2use frame_support::{3 weights::{Weight, constants::WEIGHT_REF_TIME_PER_SECOND},4 traits::{FindAuthor},5 parameter_types, ConsensusEngineId,6};7use sp_runtime::{RuntimeAppPublic, Perbill, traits::ConstU32};8use crate::{9 runtime_common::{10 config::sponsoring::DefaultSponsoringRateLimit,11 DealWithFees,12 dispatch::CollectionDispatchT,13 ethereum::{precompiles::UniquePrecompiles, sponsoring::EvmSponsorshipHandler},14 },15 Runtime, Aura, Balances, RuntimeEvent, ChainId,16};17use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};18use pallet_ethereum::PostLogContent;19use up_common::constants::*;2021pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;222324const EVM_SLOAD_PROOF_SIZE: u64 = 96;2526272829303132parameter_types! {33 pub const ReadsPerSecond: u64 = WEIGHT_REF_TIME_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().read;34 pub const GasPerSecond: u64 = ReadsPerSecond::get() * 2100;35 pub const WeightTimePerGas: u64 = WEIGHT_REF_TIME_PER_SECOND / GasPerSecond::get();3637 pub const BytesReadPerSecond: u64 = ReadsPerSecond::get() * EVM_SLOAD_PROOF_SIZE;38 pub const ProofSizePerGas: u64 = 0; 3940 pub const WeightPerGas: Weight = Weight::from_parts(WeightTimePerGas::get(), ProofSizePerGas::get());41}4243444546const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);47parameter_types! {48 pub BlockGasLimit: U256 = U256::from((NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightTimePerGas::get()).ref_time());49 pub PrecompilesValue: UniquePrecompiles<Runtime> = UniquePrecompiles::<_>::new();50}5152pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);53impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {54 fn find_author<'a, I>(digests: I) -> Option<H160>55 where56 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,57 {58 if let Some(author_index) = F::find_author(digests) {59 let authority_id = Aura::authorities()[author_index as usize].clone();60 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));61 }62 None63 }64}6566impl pallet_evm::Config for Runtime {67 type CrossAccountId = CrossAccountId;68 type AddressMapping = HashedAddressMapping<Self::Hashing>;69 type BackwardsAddressMapping = HashedAddressMapping<Self::Hashing>;70 type BlockGasLimit = BlockGasLimit;71 type FeeCalculator = pallet_configuration::FeeCalculator<Self>;72 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;73 type WeightPerGas = WeightPerGas;74 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;75 type CallOrigin = EnsureAddressTruncated<Self>;76 type WithdrawOrigin = EnsureAddressTruncated<Self>;77 type PrecompilesType = UniquePrecompiles<Self>;78 type PrecompilesValue = PrecompilesValue;79 type Currency = Balances;80 type RuntimeEvent = RuntimeEvent;81 type OnMethodCall = (82 pallet_evm_migration::OnMethodCall<Self>,83 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,84 CollectionDispatchT<Self>,85 pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,86 );87 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;88 type ChainId = ChainId;89 type Runner = pallet_evm::runner::stack::Runner<Self>;90 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;91 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;92 type FindAuthor = EthereumFindAuthor<Aura>;93 type Timestamp = crate::Timestamp;94 type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;95 type GasLimitPovSizeRatio = ProofSizePerGas;96}9798impl pallet_evm_migration::Config for Runtime {99 type RuntimeEvent = RuntimeEvent;100 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;101}102103parameter_types! {104 pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;105}106107impl pallet_ethereum::Config for Runtime {108 type RuntimeEvent = RuntimeEvent;109 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;110 type PostLogContent = PostBlockAndTxnHashes;111 112 113 type ExtraDataLength = ConstU32<32>;114}115116parameter_types! {117 118 pub const HelpersContractAddress: H160 = H160([119 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,120 ]);121122 123 pub const EvmCollectionHelpersAddress: H160 = H160([124 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,125 ]);126}127128impl pallet_evm_contract_helpers::Config for Runtime {129 type RuntimeEvent = RuntimeEvent;130 type ContractAddress = HelpersContractAddress;131 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;132}133134impl pallet_evm_coder_substrate::Config for Runtime {}135136impl pallet_evm_transaction_payment::Config for Runtime {137 type EvmSponsorshipHandler = EvmSponsorshipHandler;138}