#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("t2rn"),
impl_name: create_runtime_str!("t2rn"),
authoring_version: 45,
spec_version: 45,
impl_version: 45,
apis: RUNTIME_API_VERSIONS,
transaction_version: 45,
state_version: 1,
};
use circuit_runtime_types::MILLIUNIT;
use frame_system::EnsureRoot;
use sp_runtime::{
generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256},
};
use sp_std::{
convert::{TryFrom, TryInto},
prelude::*,
};
use codec::Encode;
use frame_support::{dispatch, traits::OnFinalize};
use pallet_3vm_evm::GasWeightMapping;
pub use pallet_3vm_evm_primitives::{FeeCalculator, GenesisAccount};
pub use sp_core::{H160, H256, U256};
use sp_runtime::traits::UniqueSaturatedInto;
pub use sp_runtime::{Perbill, Permill};
use frame_support::weights::ConstantMultiplier;
pub use frame_system::Call as SystemCall;
pub mod accounts_config;
pub mod circuit_config;
pub mod consensus_aura_config;
pub mod contracts_config;
pub mod hooks;
pub mod signed_extrinsics_config;
pub mod system_config;
pub mod treasuries_config;
pub use crate::{consensus_aura_config::*, signed_extrinsics_config::*};
pub use circuit_runtime_types::*;
use pallet_3vm_ethereum::{
Call::transact, EthereumBlockHashMapping, Transaction as EthereumTransaction,
};
use pallet_3vm_evm::Runner;
pub type CurrencyAdapter = accounts_config::AccountManagerCurrencyAdapter<Balances, ()>;
const MT3RN: Balance = MILLIUNIT as Balance;
parameter_types! {
pub const BasicDeposit: Balance = 5 * MT3RN;
pub const FieldDeposit: Balance = MT3RN;
pub const SubAccountDeposit: Balance = 2 * MT3RN;
pub const MaxSubAccounts: u32 = 100;
pub const MaxAdditionalFields: u32 = 100;
pub const MaxRegistrars: u32 = 20;
}
impl pallet_identity::Config for Runtime {
type BasicDeposit = BasicDeposit;
type Currency = Balances;
type FieldDeposit = FieldDeposit;
type ForceOrigin = EnsureRoot<AccountId>;
type MaxAdditionalFields = MaxAdditionalFields;
type MaxRegistrars = MaxRegistrars;
type MaxSubAccounts = MaxSubAccounts;
type RegistrarOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type Slashed = ();
type SubAccountDeposit = SubAccountDeposit;
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
}
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system = 0,
Timestamp: pallet_timestamp = 1,
Aura: pallet_aura = 2,
Grandpa: pallet_grandpa = 3,
Utility: pallet_utility = 6,
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 13,
AssetTxPayment: pallet_asset_tx_payment = 14,
AccountManager: pallet_account_manager = 15,
Treasury: pallet_treasury = 12, EscrowTreasury: pallet_treasury::<Instance1> = 16,
FeeTreasury: pallet_treasury::<Instance2> = 17,
ParachainTreasury: pallet_treasury::<Instance3> = 18,
SlashTreasury: pallet_treasury::<Instance4> = 19,
Clock: pallet_clock= 110,
XDNS: pallet_xdns = 100,
Attesters: pallet_attesters = 101,
Rewards: pallet_rewards = 102,
ContractsRegistry: pallet_contracts_registry = 106,
Circuit: pallet_circuit = 108,
Vacuum: pallet_vacuum = 111,
ThreeVm: pallet_3vm = 119,
Contracts: pallet_3vm_contracts = 120,
Evm: pallet_3vm_evm = 121,
AccountMapping: pallet_3vm_account_mapping = 126,
Ethereum: pallet_3vm_ethereum = 227,
Portal: pallet_portal = 128,
RococoBridge: pallet_grandpa_finality_verifier = 129,
PolkadotBridge: pallet_grandpa_finality_verifier::<Instance1> = 130,
KusamaBridge: pallet_grandpa_finality_verifier::<Instance2> = 131,
EthereumBridge: pallet_eth2_finality_verifier = 132,
SepoliaBridge: pallet_sepolia_finality_verifier = 133,
CelestiaLightClient: pallet_celestia_light_client = 134,
Identity: pallet_identity = 122,
RandomnessCollectiveFlip: pallet_randomness_collective_flip = 200,
MaintenanceMode: pallet_maintenance_mode = 140,
Sudo: pallet_sudo = 255,
}
);
pub use frame_support::{
construct_runtime, parameter_types,
traits::{
ConstU128, ConstU32, ConstU8, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness,
StorageInfo,
},
weights::{
constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
IdentityFee, Weight,
},
StorageValue,
};
pub use pallet_balances::Call as BalancesCall;
use pallet_circuit::ChainId;
use pallet_grandpa::AuthorityId as GrandpaId;
pub use pallet_timestamp::Call as TimestampCall;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::{
traits::{Block as BlockT, NumberFor},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
use t3rn_primitives::{
circuit::ReadSFX,
portal::HeightResult,
xdns::{FullGatewayRecord, GatewayRecord},
TreasuryAccountProvider,
};
pub use crate::consensus_aura_config::*;
use pallet_xdns_rpc_runtime_api::GatewayABIConfig;
use sp_runtime::create_runtime_str;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion {
runtime_version: VERSION,
can_author_with: Default::default(),
}
}
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
}
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
>;
#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
use t3rn_types::sfx::SideEffect;
impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block);
}
fn initialize_block(header: &<Block as BlockT>::Header) {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
OpaqueMetadata::new(Runtime::metadata().into())
}
fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
Runtime::metadata_at_version(version)
}
fn metadata_versions() -> sp_std::vec::Vec<u32> {
Runtime::metadata_versions()
}
}
impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> <Block as BlockT>::Header {
Executive::finalize_block()
}
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
data.create_extrinsics()
}
fn check_inherents(
block: Block,
data: sp_inherents::InherentData,
) -> sp_inherents::CheckInherentsResult {
data.check_extrinsics(&block)
}
}
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
}
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
Executive::offchain_worker(header)
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
}
fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
opaque::SessionKeys::generate(seed)
}
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
}
}
impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
Grandpa::grandpa_authorities()
}
fn current_set_id() -> sp_consensus_grandpa::SetId {
Grandpa::current_set_id()
}
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: sp_consensus_grandpa::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
>,
_key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}
fn generate_key_ownership_proof(
_set_id: sp_consensus_grandpa::SetId,
_authority_id: GrandpaId,
) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
None
}
}
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
}
}
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
fn query_info(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
fn query_fee_details(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment::FeeDetails<Balance> {
TransactionPayment::query_fee_details(uxt, len)
}
fn query_weight_to_fee(weight: Weight) -> Balance {
TransactionPayment::weight_to_fee(weight)
}
fn query_length_to_fee(length: u32) -> Balance {
TransactionPayment::length_to_fee(length)
}
}
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
for Runtime
{
fn query_call_info(
call: RuntimeCall,
len: u32,
) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
TransactionPayment::query_call_info(call, len)
}
fn query_call_fee_details(
call: RuntimeCall,
len: u32,
) -> pallet_transaction_payment::FeeDetails<Balance> {
TransactionPayment::query_call_fee_details(call, len)
}
fn query_weight_to_fee(weight: Weight) -> Balance {
TransactionPayment::weight_to_fee(weight)
}
fn query_length_to_fee(length: u32) -> Balance {
TransactionPayment::length_to_fee(length)
}
}
impl pallet_xdns_rpc_runtime_api::XdnsRuntimeApi<Block, AccountId> for Runtime {
fn fetch_records() -> Vec<GatewayRecord<AccountId>> {
<XDNS as t3rn_primitives::xdns::Xdns<Runtime, Balance>>::fetch_gateways()
}
fn fetch_full_gateway_records() -> Vec<FullGatewayRecord<AccountId>> {
<XDNS as t3rn_primitives::xdns::Xdns<Runtime, Balance>>::fetch_full_gateway_records()
}
fn fetch_abi(_chain_id: ChainId) -> Option<GatewayABIConfig> {
None
}
fn retreive_treasury_address(treasury_account: t3rn_primitives::TreasuryAccount) -> AccountId {
Runtime::get_treasury_account(treasury_account)
}
}
impl pallet_portal_rpc_runtime_api::PortalRuntimeApi<Block, AccountId, Balance, Hash> for Runtime {
fn fetch_head_height(chain_id: ChainId) -> Option<u128> {
let res = <Portal as t3rn_primitives::portal::Portal<Runtime>>::get_fast_height(chain_id);
match res {
Ok(HeightResult::Height(height)) => Some(height.into()),
_ => None,
}
}
fn fetch_all_active_xtx(for_executor: AccountId) -> Vec<(
Hash, Vec<SideEffect<AccountId, Balance>>, Vec<Hash>, )> {
Circuit::get_pending_xtx_for(for_executor)
}
}
impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
<Runtime as pallet_3vm_evm::Config>::ChainId::get()
}
fn account_basic(address: H160) -> pallet_3vm_evm_primitives::Account {
Evm::account_basic(&address).0
}
fn gas_price() -> U256 {
let (gas_price, _) = <Runtime as pallet_3vm_evm::Config>::FeeCalculator::min_gas_price();
gas_price
}
fn account_code_at(address: H160) -> Vec<u8> {
pallet_3vm_evm::AccountCodes::<Runtime>::get(address)
}
fn author() -> H160 {
<pallet_3vm_evm::Pallet<Runtime>>::find_author()
}
fn storage_at(address: H160, index: U256) -> H256 {
let mut tmp = [0u8; 32];
index.to_big_endian(&mut tmp);
pallet_3vm_evm::AccountStorages::<Runtime>::get(address, H256::from_slice(&tmp[..]))
}
fn call(
from: H160,
to: H160,
data: Vec<u8>,
value: U256,
gas_limit: U256,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
estimate: bool,
access_list: Option<Vec<(H160, Vec<H256>)>>,
) -> Result<pallet_3vm_evm::CallInfo, sp_runtime::DispatchError>{
log::info!("fp_rpc::EthereumRuntimeRPCApi::call()");
log::info!("from: {:?}", from);
log::info!("to: {:?}", to);
log::info!("data: {:?}", data);
log::info!("value: {:?}", value);
log::info!("gas_limit: {:?}", gas_limit);
log::info!("max_fee_per_gas: {:?}", max_fee_per_gas);
log::info!("max_priority_fee_per_gas: {:?}", max_priority_fee_per_gas);
log::info!("nonce: {:?}", nonce);
log::info!("estimate: {:?}", estimate);
log::info!("access_list: {:?}", access_list);
let config = if estimate {
let mut config = <Runtime as pallet_3vm_evm::Config>::config().clone();
config.estimate = true;
Some(config)
} else {
None
};
let is_transactional = false;
let validate = true;
let mut estimated_transaction_len = data.len() +
210;
if max_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if max_priority_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if access_list.is_some() {
estimated_transaction_len += access_list.encoded_size();
}
let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;
let (weight_limit, proof_size_base_cost) =
match <Runtime as pallet_3vm_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
}
_ => (None, None),
};
<Runtime as pallet_3vm_evm::Config>::Runner::call(
from,
to,
data,
value,
gas_limit.unique_saturated_into(),
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
Vec::new(),is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config.as_ref().unwrap_or(<Runtime as pallet_3vm_evm::Config>::config()),
).map_err(|err| err.error.into())
}
fn create(
from: H160,
data: Vec<u8>,
value: U256,
gas_limit: U256,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
estimate: bool,
access_list: Option<Vec<(H160, Vec<H256>)>>,
) -> Result<pallet_3vm_evm::CreateInfo, sp_runtime::DispatchError> {
let config = if estimate {
let mut config = <Runtime as pallet_3vm_evm::Config>::config().clone();
config.estimate = true;
Some(config)
} else {
None
};
let is_transactional = false;
let validate = true;
let mut estimated_transaction_len = data.len() +
210;
if max_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if max_priority_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if access_list.is_some() {
estimated_transaction_len += access_list.encoded_size();
}
let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;
let (weight_limit, proof_size_base_cost) =
match <Runtime as pallet_3vm_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
}
_ => (None, None),
};
<Runtime as pallet_3vm_evm::Config>::Runner::create(
from,
data,
value,
gas_limit.unique_saturated_into(),
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
Vec::new(),
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config.as_ref().unwrap_or(<Runtime as pallet_3vm_evm::Config>::config()),
).map_err(|err| err.error.into())
}
fn current_transaction_statuses() -> Option<Vec<fp_rpc::TransactionStatus>> {
pallet_3vm_ethereum::CurrentTransactionStatuses::<Runtime>::get()
}
fn current_block() -> Option<pallet_3vm_ethereum::Block> {
pallet_3vm_ethereum::CurrentBlock::<Runtime>::get()
}
fn current_receipts() -> Option<Vec<pallet_3vm_ethereum::Receipt>> {
pallet_3vm_ethereum::CurrentReceipts::<Runtime>::get()
}
fn current_all() -> (
Option<pallet_3vm_ethereum::Block>,
Option<Vec<pallet_3vm_ethereum::Receipt>>,
Option<Vec<fp_rpc::TransactionStatus>>
) {
(
pallet_3vm_ethereum::CurrentBlock::<Runtime>::get(),
pallet_3vm_ethereum::CurrentReceipts::<Runtime>::get(),
pallet_3vm_ethereum::CurrentTransactionStatuses::<Runtime>::get()
)
}
fn extrinsic_filter(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> Vec<pallet_3vm_ethereum::Transaction> {
xts.into_iter().filter_map(|xt| match xt.0.function {
RuntimeCall::Ethereum(pallet_3vm_ethereum::Call::transact { transaction }) => Some(transaction),
_ => None
}).collect::<Vec<pallet_3vm_ethereum::Transaction>>()
}
fn elasticity() -> Option<Permill> {
Some(Permill::zero())
}
fn gas_limit_multiplier_support() {}
fn pending_block(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> (Option<pallet_3vm_ethereum::Block>, Option<Vec<fp_rpc::TransactionStatus>>) {
for ext in xts.into_iter() {
let _ = Executive::apply_extrinsic(ext);
}
Ethereum::on_finalize(System::block_number() + 1);
(
pallet_3vm_ethereum::CurrentBlock::<Runtime>::get(),
pallet_3vm_ethereum::CurrentTransactionStatuses::<Runtime>::get()
)
}
}
impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {
fn convert_transaction(transaction: EthereumTransaction) -> <Block as BlockT>::Extrinsic {
log::info!("fp_rpc::ConvertTransactionRuntimeApi::convert_transaction(): {:?}", transaction);
UncheckedExtrinsic::new_unsigned(
pallet_3vm_ethereum::Call::<Runtime>::transact { transaction }.into(),
)
}
}
#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
}
fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect
) -> Weight {
Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
}
}
}