#![cfg_attr(not(feature = "std"), no_std)]
#![feature(more_qualified_paths)]
#![recursion_limit = "256"]
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub mod accounts_config;
pub mod circuit_config;
pub mod contracts_config;
pub mod hooks;
pub mod parachain_config;
pub mod signed_extrinsics_config;
pub mod system_config;
pub mod treasuries_config;
pub mod xbi_config;
pub use crate::{parachain_config::*, signed_extrinsics_config::*};
pub use circuit_runtime_types::*;
use frame_system::EnsureRoot;
use pallet_xdns_rpc_runtime_api::{ChainId, GatewayABIConfig};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic,
traits::{AccountIdLookup, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
use sp_std::{convert::TryInto, prelude::*};
use t3rn_primitives::{
xdns::{FullGatewayRecord, GatewayRecord},
TreasuryAccountProvider,
};
use t3rn_types::sfx::SideEffect;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
pub use frame_support::traits::EqualPrivilegeOnly;
use frame_support::{
construct_runtime, parameter_types,
traits::{Imbalance, OnUnbalanced},
weights::{
constants::ExtrinsicBaseWeight, ConstantMultiplier, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
},
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use t3rn_primitives::light_client::HeightResult;
use polkadot_runtime_common::BlockHashCount;
use polkadot_runtime_constants::weights::RocksDbWeight;
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
>;
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("t3rn"),
impl_name: create_runtime_str!("t3rn Circuit Collator"),
authoring_version: 53,
spec_version: 53,
impl_version: 53,
apis: RUNTIME_API_VERSIONS,
transaction_version: 53,
state_version: 1, };
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion {
runtime_version: VERSION,
can_author_with: Default::default(),
}
}
pub const fn deposit(items: u32, bytes: u32) -> Balance {
(items as Balance) * 56 * MILLIUNIT + (bytes as Balance) * 50 * MICROUNIT
}
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>;
}
impl pallet_asset_tx_payment::Config for Runtime {
type Fungibles = Assets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
CreditToBlockAuthor,
>;
type RuntimeEvent = RuntimeEvent;
}
parameter_types! {
pub const AssetDeposit: Balance = 0; pub const ApprovalDeposit: Balance = 0;
pub const AssetsStringLimit: u32 = 50;
pub const MetadataDepositBase: Balance = 0;
pub const MetadataDepositPerByte: Balance = 0;
pub const AssetAccountDeposit: Balance = 0;
}
use crate::system_config::CreditToBlockAuthor;
use frame_support::traits::AsEnsureOriginWithArg;
use sp_runtime::traits::{ConstU32, ConvertInto};
impl pallet_assets::Config for Runtime {
type ApprovalDeposit = ApprovalDeposit;
type AssetAccountDeposit = AssetAccountDeposit;
type AssetDeposit = AssetDeposit;
type AssetId = circuit_runtime_types::AssetId;
type AssetIdParameter = circuit_runtime_types::AssetId;
type Balance = Balance;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<AccountId>;
type Freezer = ();
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type RemoveItemsLimit = ConstU32<1>;
type RuntimeEvent = RuntimeEvent;
type StringLimit = AssetsStringLimit;
type WeightInfo = ();
}
impl pallet_withdraw_teleport::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_withdraw_teleport::weights::SubstrateWeight<Runtime>;
}
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system = 0,
ParachainSystem: cumulus_pallet_parachain_system = 1,
Timestamp: pallet_timestamp = 2,
ParachainInfo: parachain_info = 3,
Preimage: pallet_preimage = 4,
Scheduler: pallet_scheduler = 5,
Utility: pallet_utility = 6,
Identity: pallet_identity = 122,
RandomnessCollectiveFlip: pallet_randomness_collective_flip = 200,
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
AccountManager: pallet_account_manager = 14,
AssetTxPayment: pallet_asset_tx_payment = 15,
Treasury: pallet_treasury = 13, EscrowTreasury: pallet_treasury::<Instance1> = 16,
FeeTreasury: pallet_treasury::<Instance2> = 17,
ParachainTreasury: pallet_treasury::<Instance3> = 18,
SlashTreasury: pallet_treasury::<Instance4> = 19,
Authorship: pallet_authorship = 20,
CollatorSelection: pallet_collator_selection = 21,
Session: pallet_session = 22,
Aura: pallet_aura = 23,
AuraExt: cumulus_pallet_aura_ext = 24,
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
DmpQueue: cumulus_pallet_dmp_queue = 33,
AssetRegistry: pallet_asset_registry = 35,
WithdrawTeleport: pallet_withdraw_teleport = 36,
XDNS: pallet_xdns = 100,
Attesters: pallet_attesters = 101,
Rewards: pallet_rewards = 102,
ContractsRegistry: pallet_contracts_registry = 106,
Circuit: pallet_circuit = 108,
Clock: pallet_clock = 110,
Vacuum: pallet_vacuum = 111,
ThreeVm: pallet_3vm = 119,
Contracts: pallet_3vm_contracts = 120,
Evm: pallet_3vm_evm = 121,
AccountMapping: pallet_3vm_account_mapping = 126,
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,
Maintenance: pallet_maintenance_mode = 140,
Sudo: pallet_sudo = 255,
}
);
use frame_system::EventRecord;
use sp_core::H256;
use t3rn_primitives::circuit::ReadSFX;
impl_runtime_apis! {
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_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_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
}
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
SessionKeys::decode_into_raw_public_keys(&encoded)
}
}
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
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_3vm_contracts::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash, EventRecord<RuntimeEvent, H256>>
for Runtime
{
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_3vm_contracts_primitives::ContractExecResult<Balance, EventRecord<RuntimeEvent, H256>> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_call(
origin,
dest,
value,
gas_limit,
storage_deposit_limit,
input_data,
pallet_3vm_contracts::DebugInfo::UnsafeDebug,
pallet_3vm_contracts::CollectEvents::UnsafeCollect,
pallet_3vm_contracts::Determinism::Enforced,
)
}
fn instantiate(
origin: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_3vm_contracts_primitives::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_3vm_contracts_primitives::ContractInstantiateResult<AccountId, Balance, EventRecord<RuntimeEvent, H256>>
{
Contracts::bare_instantiate(origin, value, gas_limit.unwrap_or_default(), storage_deposit_limit, code, data, salt, pallet_3vm_contracts::DebugInfo::UnsafeDebug, pallet_3vm_contracts::CollectEvents::UnsafeCollect,)
}
fn upload_code(
origin: AccountId,
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
determinism: pallet_3vm_contracts::Determinism,
) -> pallet_3vm_contracts_primitives::CodeUploadResult<Hash, Balance>
{
Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism)
}
fn get_storage(
address: AccountId,
key: Vec<u8>,
) -> pallet_3vm_contracts_primitives::GetStorageResult {
Contracts::get_storage(address, key)
}
}
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 cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
let collation_info = ParachainSystem::collect_collation_info(header);
if let Some(ref new_validation_code) = collation_info.new_validation_code {
log::info!("RuntimeUpgrade::submitting new validation code via HRMP to relay chain {:?}", new_validation_code.hash());
}
collation_info
}
}
#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade parachain-template.");
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
fn execute_block_no_check(block: Block) -> Weight {
Executive::execute_block_no_check(block)
}
}
}