Skip to content

Commit

Permalink
runtime implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Jul 25, 2024
1 parent 62fcf1b commit 678f66b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pallets/processor/src/assigner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use core::marker::PhantomData;
use frame_support::weights::WeightToFee;
use order_primitives::ParaId;
use pallet_broker::RegionId;
#[cfg(not(feature = "std"))]
use scale_info::prelude::{vec, vec::Vec};
use sp_runtime::{traits::Get, DispatchResult};
use xcm::latest::prelude::*;

Expand Down
8 changes: 3 additions & 5 deletions pallets/processor/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ parameter_types! {

#[derive(Encode, Decode)]
enum CoretimeRuntimeCalls {
#[codec(index = 92)]
#[codec(index = 50)]
Broker(BrokerPalletCalls),
}

/// Broker pallet calls.
//
// NOTE: We only use the `CreateOrder` call.
/// Broker pallet calls. We don't define all of them, only the ones we use.
#[derive(Encode, Decode)]
enum BrokerPalletCalls {
#[codec(index = 0)]
#[codec(index = 10)]
Assign(RegionId, ParaId),
}

Expand Down
6 changes: 6 additions & 0 deletions runtime/cocos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ smallvec = { workspace = true }
regionx-runtime-common = { workspace = true, default-features = false }
pallet-market = { workspace = true, default-features = false }
pallet-orders = { workspace = true, default-features = false }
pallet-processor = { workspace = true, default-features = false }
pallet-regions = { workspace = true, default-features = false }
order-primitives = { workspace = true, default-features = false }

# Polytope Labs
ismp = { workspace = true }
Expand Down Expand Up @@ -141,6 +143,7 @@ std = [
"orml-traits/std",
"orml-unknown-tokens/std",
"orml-xcm-support/std",
"order-primitives/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-asset-rate/std",
Expand All @@ -151,6 +154,7 @@ std = [
"pallet-conviction-voting/std",
"pallet-collator-selection/std",
"pallet-referenda/std",
"pallet-processor/std",
"pallet-regions/std",
"regionx-runtime-common/std",
"pallet-market/std",
Expand Down Expand Up @@ -222,6 +226,7 @@ runtime-benchmarks = [
"pallet-orders/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-processor/runtime-benchmarks",
"pallet-regions/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
Expand Down Expand Up @@ -270,6 +275,7 @@ try-runtime = [
"pallet-orders/try-runtime",
"pallet-proxy/try-runtime",
"pallet-preimage/try-runtime",
"pallet-processor/try-runtime",
"pallet-regions/try-runtime",
"pallet-referenda/try-runtime",
"pallet-session/try-runtime",
Expand Down
23 changes: 23 additions & 0 deletions runtime/cocos/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ use frame_support::traits::{
fungibles, tokens::ConversionToAssetBalance, Defensive, ExistenceRequirement, Imbalance,
InstanceFilter, OnUnbalanced,
};
use order_primitives::ParaId;
use orml_asset_registry::DefaultAssetMetadata;
use orml_traits::{asset_registry::AssetProcessor, GetByKey};
use pallet_asset_tx_payment::HandleCredit;
use pallet_broker::RegionId;
use pallet_processor::assigner::AssignmentCallEncoder as AssignmentCallEncoderT;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AccountIdConversion, CheckedDiv},
Expand Down Expand Up @@ -193,6 +196,26 @@ impl pallet_orders::FeeHandler<AccountId, Balance> for OrderCreationFeeHandler {
}
}

#[derive(Encode, Decode)]
enum CoretimeRuntimeCalls {
#[codec(index = 50)]
Broker(BrokerPalletCalls),
}

/// Broker pallet calls. We don't define all of them, only the ones we use.
#[derive(Encode, Decode)]
enum BrokerPalletCalls {
#[codec(index = 10)]
Assign(RegionId, ParaId),
}

pub struct AssignmentCallEncoder;
impl AssignmentCallEncoderT for AssignmentCallEncoder {
fn encode_assignment_call(region_id: RegionId, para_id: ParaId) -> Vec<u8> {
CoretimeRuntimeCalls::Broker(BrokerPalletCalls::Assign(region_id, para_id)).encode()
}
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks {
use crate::*;
Expand Down
20 changes: 19 additions & 1 deletion runtime/cocos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod ismp;

use impls::*;

use crate::xcm_config::CoretimeChainLocation;
use codec::Encode;
use cumulus_pallet_parachain_system::{
RelayChainState, RelayNumberMonotonicallyIncreases, RelaychainDataProvider,
Expand All @@ -48,7 +49,8 @@ use frame_support::traits::{
tokens::{PayFromAccount, UnityAssetBalanceConversion},
Currency as PalletCurrency, EqualPrivilegeOnly, LinearStoragePrice, TransformOrigin,
};
use pallet_orders::OrderId;
use order_primitives::OrderId;
use pallet_processor::assigner::XcmRegionAssigner;
use pallet_regions::primitives::StateMachineHeightProvider as StateMachineHeightProviderT;
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
Expand Down Expand Up @@ -785,6 +787,20 @@ impl pallet_orders::Config for Runtime {
type WeightInfo = weights::pallet_orders::WeightInfo<Runtime>;
}

impl pallet_processor::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type Balance = Balance;
type Orders = Orders;
type OrderToAccountId = OrderToAccountId;
type Regions = Regions;
type AssignmentCallEncoder = AssignmentCallEncoder;
type RegionAssigner = XcmRegionAssigner<Self>;
type CoretimeChain = CoretimeChainLocation;
type WeightToFee = WeightToFee;
type WeightInfo = ();
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down Expand Up @@ -849,6 +865,7 @@ construct_runtime!(
Regions: pallet_regions = 90,
Market: pallet_market = 91,
Orders: pallet_orders = 92,
Processor: pallet_processor = 93,
}
);

Expand All @@ -875,6 +892,7 @@ mod benches {
[pallet_message_queue, MessageQueue]
[pallet_orders, Orders]
[pallet_preimage, Preimage]
[pallet_processor, Processor]
[pallet_referenda, NativeReferenda]
[pallet_referenda, DelegatedReferenda]
[pallet_scheduler, Scheduler]
Expand Down

0 comments on commit 678f66b

Please sign in to comment.