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, Event, ChainId,14};15use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};16use up_common::constants::*;1718pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;1920impl pallet_evm::account::Config for Runtime {21 type CrossAccountId = CrossAccountId;22 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;23 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;24}2526272829parameter_types! {30 pub const WritesPerSecond: u64 = WEIGHT_PER_SECOND / <Runtime as frame_system::Config>::DbWeight::get().write;31 pub const GasPerSecond: u64 = WritesPerSecond::get() * 20000;32 pub const WeightPerGas: u64 = WEIGHT_PER_SECOND / GasPerSecond::get();33}3435363738const EVM_DISPATCH_RATIO: Perbill = Perbill::from_percent(50);39parameter_types! {40 pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * EVM_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT / WeightPerGas::get());41}4243pub enum FixedGasWeightMapping {}44impl pallet_evm::GasWeightMapping for FixedGasWeightMapping {45 fn gas_to_weight(gas: u64) -> Weight {46 gas.saturating_mul(WeightPerGas::get())47 }48 fn weight_to_gas(weight: Weight) -> u64 {49 weight / WeightPerGas::get()50 }51}5253pub struct FixedFee;54impl pallet_evm::FeeCalculator for FixedFee {55 fn min_gas_price() -> (U256, u64) {56 (MIN_GAS_PRICE.into(), 0)57 }58}5960pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);61impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {62 fn find_author<'a, I>(digests: I) -> Option<H160>63 where64 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,65 {66 if let Some(author_index) = F::find_author(digests) {67 let authority_id = Aura::authorities()[author_index as usize].clone();68 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));69 }70 None71 }72}7374impl pallet_evm::Config for Runtime {75 type BlockGasLimit = BlockGasLimit;76 type FeeCalculator = FixedFee;77 type GasWeightMapping = FixedGasWeightMapping;78 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;79 type CallOrigin = EnsureAddressTruncated<Self>;80 type WithdrawOrigin = EnsureAddressTruncated<Self>;81 type AddressMapping = HashedAddressMapping<Self::Hashing>;82 type PrecompilesType = ();83 type PrecompilesValue = ();84 type Currency = Balances;85 type Event = Event;86 type OnMethodCall = (87 pallet_evm_migration::OnMethodCall<Self>,88 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,89 CollectionDispatchT<Self>,90 pallet_unique::eth::CollectionHelpersOnMethodCall<Self>,91 );92 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;93 type ChainId = ChainId;94 type Runner = pallet_evm::runner::stack::Runner<Self>;95 type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;96 type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;97 type FindAuthor = EthereumFindAuthor<Aura>;98}99100impl pallet_evm_migration::Config for Runtime {101 type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;102}103104impl pallet_ethereum::Config for Runtime {105 type Event = Event;106 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;107}108109parameter_types! {110 111 pub const HelpersContractAddress: H160 = H160([112 0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,113 ]);114115 116 pub const EvmCollectionHelpersAddress: H160 = H160([117 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,118 ]);119}120121impl pallet_evm_contract_helpers::Config for Runtime {122 type ContractAddress = HelpersContractAddress;123 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;124}125126impl pallet_evm_coder_substrate::Config for Runtime {}127128impl pallet_evm_transaction_payment::Config for Runtime {129 type EvmSponsorshipHandler = EvmSponsorshipHandler;130 type Currency = Balances;131}