1use frame_support::{2 parameter_types,3 traits::FindAuthor,4 weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},5 ConsensusEngineId,6};7use pallet_ethereum::PostLogContent;8use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};9use sp_core::{H160, U256};10use sp_runtime::{traits::ConstU32, Perbill, RuntimeAppPublic};11use up_common::constants::*;1213use crate::{14 runtime_common::{15 config::sponsoring::DefaultSponsoringRateLimit,16 dispatch::CollectionDispatchT,17 ethereum::{precompiles::UniquePrecompiles, sponsoring::EvmSponsorshipHandler},18 DealWithFees,19 },20 Aura, Balances, ChainId, Runtime, RuntimeEvent,21};2223pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;242526const EVM_SLOAD_PROOF_SIZE: u64 = 96;2728293031323334parameter_types! {35 pub const ReadsPerSecond: u64 = WEIGHT_REF_TIME_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().read;36 pub const GasPerSecond: u64 = ReadsPerSecond::get() * 2100;37 pub const WeightTimePerGas: u64 = WEIGHT_REF_TIME_PER_SECOND / GasPerSecond::get();3839 pub const BytesReadPerSecond: u64 = ReadsPerSecond::get() * EVM_SLOAD_PROOF_SIZE;40 pub const ProofSizePerGas: u64 = 0; 4142 pub const WeightPerGas: Weight = Weight::from_parts(WeightTimePerGas::get(), ProofSizePerGas::get());43}4445464748const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);49parameter_types! {50 pub BlockGasLimit: U256 = U256::from((NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightTimePerGas::get()).ref_time());51 pub PrecompilesValue: UniquePrecompiles<Runtime> = UniquePrecompiles::<_>::new();52}5354pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);55impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {56 fn find_author<'a, I>(digests: I) -> Option<H160>57 where58 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,59 {60 if let Some(author_index) = F::find_author(digests) {61 let authority_id = Aura::authorities()[author_index as usize].clone();62 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));63 }64 None65 }66}6768impl pallet_evm::Config for Runtime {69 type CrossAccountId = CrossAccountId;70 type AddressMapping = HashedAddressMapping<Self::Hashing>;71 type BackwardsAddressMapping = HashedAddressMapping<Self::Hashing>;72 type BlockGasLimit = BlockGasLimit;73 type FeeCalculator = pallet_configuration::FeeCalculator<Self>;74 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;75 type WeightPerGas = WeightPerGas;76 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;77 type CallOrigin = EnsureAddressTruncated<Self>;78 type WithdrawOrigin = EnsureAddressTruncated<Self>;79 type PrecompilesType = UniquePrecompiles<Self>;80 type PrecompilesValue = PrecompilesValue;81 type Currency = Balances;82 type RuntimeEvent = RuntimeEvent;83 type OnMethodCall = (84 pallet_evm_migration::OnMethodCall<Self>,85 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,86 CollectionDispatchT<Self>,87 pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,88 );89 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;90 type ChainId = ChainId;91 type Runner = pallet_evm::runner::stack::Runner<Self>;92 type OnChargeTransaction =93 pallet_evm_transaction_payment::WrappedEVMCurrencyAdapter<Balances, DealWithFees>;94 type FindAuthor = EthereumFindAuthor<Aura>;95 type SuicideQuickClearLimit = ConstU32<0>;96 type Timestamp = crate::Timestamp;97 type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;98 type GasLimitPovSizeRatio = ProofSizePerGas;99 type OnCheckEvmTransaction = pallet_evm_transaction_payment::TransactionValidity<Self>;100}101102impl pallet_evm_migration::Config for Runtime {103 type RuntimeEvent = RuntimeEvent;104 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;105}106107parameter_types! {108 pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;109}110111impl pallet_ethereum::Config for Runtime {112 type RuntimeEvent = RuntimeEvent;113 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;114 type PostLogContent = PostBlockAndTxnHashes;115 116 117 type ExtraDataLength = ConstU32<32>;118}119120parameter_types! {121 122 pub const HelpersContractAddress: H160 = H160([123 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,124 ]);125126 127 pub const EvmCollectionHelpersAddress: H160 = H160([128 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,129 ]);130}131132impl pallet_evm_contract_helpers::Config for Runtime {133 type RuntimeEvent = RuntimeEvent;134 type ContractAddress = HelpersContractAddress;135 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;136}137138impl pallet_evm_coder_substrate::Config for Runtime {}139140impl pallet_evm_transaction_payment::Config for Runtime {141 type EvmSponsorshipHandler = EvmSponsorshipHandler;142}