feat: initialize Kurdistan SDK - independent fork of Polkadot SDK

This commit is contained in:
2025-12-13 15:44:15 +03:00
commit 286de54384
6841 changed files with 1848356 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! # XCM Cookbook
//!
//! A collection of XCM recipes.
//!
//! Each recipe is tested and explains all the code necessary to run it -- they're not just snippets
//! to copy and paste.
/// Configuring a teyrchain that only uses the Relay Chain native token.
/// In the case of Pezkuwi, this recipe will show you how to launch a teyrchain with no native
/// token -- dealing only on HEZ.
pub mod relay_token_transactor;
@@ -0,0 +1,52 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! # Relay Asset Transactor
//!
//! This example shows how to configure a teyrchain to only deal with the Relay Chain token.
//!
//! The first step is using the [`xcm_builder::FungibleAdapter`] to create an `AssetTransactor` that
//! can handle the relay chain token.
#![doc = docify::embed!("src/cookbook/relay_token_transactor/teyrchain/xcm_config.rs", asset_transactor)]
//!
//! The second step is to configure `IsReserve` to recognize the relay chain as a reserve for its
//! own asset.
//! With this, you'll be able to easily mint a derivative asset, backed one-to-one from the Relay
//! Chain, by using the xcm pallet's `transfer_assets` extrinsic.
//!
//! The `IsReserve` type takes a type that implements `ContainsPair<MultiAsset, MultiLocation>`.
//! In this case, we want a type that contains the pair `(relay_chain_native_token, relay_chain)`.
#![doc = docify::embed!("src/cookbook/relay_token_transactor/teyrchain/xcm_config.rs", is_reserve)]
//!
//! With this setup, we are able to do a reserve asset transfer to and from the teyrchain and relay
//! chain.
#![doc = docify::embed!("src/cookbook/relay_token_transactor/tests.rs", reserve_asset_transfers_work)]
//!
//! For the rest of the code, be sure to check the contents of this module.
/// The teyrchain runtime for this example
pub mod teyrchain;
/// The relay chain runtime for this example.
pub mod relay_chain;
/// The network for this example.
pub mod network;
/// Tests for this example.
#[cfg(test)]
pub mod tests;
@@ -0,0 +1,94 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! Mock network
use frame::deps::{
frame_system,
sp_io::TestExternalities,
sp_runtime::{AccountId32, BuildStorage},
};
use xcm_simulator::{decl_test_network, decl_test_relay_chain, decl_test_teyrchain, TestExt};
use super::{relay_chain, teyrchain};
pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]);
pub const BOB: AccountId32 = AccountId32::new([1u8; 32]);
pub const UNITS: u64 = 10_000_000_000;
pub const CENTS: u64 = 100_000_000;
pub const INITIAL_BALANCE: u64 = UNITS;
decl_test_teyrchain! {
pub struct ParaA {
Runtime = teyrchain::Runtime,
XcmpMessageHandler = teyrchain::MessageQueue,
DmpMessageHandler = teyrchain::MessageQueue,
new_ext = para_ext(),
}
}
decl_test_relay_chain! {
pub struct Relay {
Runtime = relay_chain::Runtime,
RuntimeCall = relay_chain::RuntimeCall,
RuntimeEvent = relay_chain::RuntimeEvent,
XcmConfig = relay_chain::XcmConfig,
MessageQueue = relay_chain::MessageQueue,
System = relay_chain::System,
new_ext = relay_ext(),
}
}
decl_test_network! {
pub struct MockNet {
relay_chain = Relay,
teyrchains = vec![
(2222, ParaA),
],
}
}
pub fn para_ext() -> TestExternalities {
use teyrchain::{MessageQueue, Runtime, System};
let t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
let mut ext = frame::deps::sp_io::TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
MessageQueue::set_para_id(2222.into());
});
ext
}
pub fn relay_ext() -> TestExternalities {
use relay_chain::{Runtime, System};
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(ALICE, INITIAL_BALANCE)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
ext
}
@@ -0,0 +1,104 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! Relay chain runtime mock.
use frame::{
deps::{frame_support::weights::WeightMeter, sp_runtime::AccountId32},
prelude::*,
runtime::prelude::*,
traits::{IdentityLookup, ProcessMessage, ProcessMessageError},
};
use pezkuwi_runtime_teyrchains::inclusion::{AggregateMessageOrigin, UmpQueueId};
use xcm::latest::prelude::*;
mod xcm_config;
pub use xcm_config::LocationToAccountId;
use xcm_config::XcmConfig;
pub type AccountId = AccountId32;
pub type Balance = u64;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type AccountData = pallet_balances::AccountData<Balance>;
}
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl pallet_balances::Config for Runtime {
type AccountStore = System;
}
type Block = frame_system::mocking::MockBlock<Runtime>;
parameter_types! {
/// Amount of weight that can be spent per block to service messages.
pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000);
pub const MessageQueueHeapSize: u32 = 65_536;
pub const MessageQueueMaxStale: u32 = 16;
}
/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet.
pub struct MessageProcessor;
impl ProcessMessage for MessageProcessor {
type Origin = AggregateMessageOrigin;
fn process_message(
message: &[u8],
origin: Self::Origin,
meter: &mut WeightMeter,
id: &mut [u8; 32],
) -> Result<bool, ProcessMessageError> {
let para = match origin {
AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
};
xcm_builder::ProcessXcmMessage::<
Junction,
xcm_executor::XcmExecutor<XcmConfig>,
RuntimeCall,
>::process_message(message, Junction::Teyrchain(para.into()), meter, id)
}
}
impl pallet_message_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Size = u32;
type HeapSize = MessageQueueHeapSize;
type MaxStale = MessageQueueMaxStale;
type ServiceWeight = MessageQueueServiceWeight;
type MessageProcessor = MessageProcessor;
type QueueChangeHandler = ();
type QueuePausedQuery = ();
type WeightInfo = ();
type IdleMaxServiceWeight = MessageQueueServiceWeight;
}
construct_runtime! {
pub struct Runtime {
System: frame_system,
Balances: pallet_balances,
MessageQueue: pallet_message_queue,
XcmPallet: pallet_xcm,
}
}
@@ -0,0 +1,169 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! Relay chain XCM configuration
use frame::{
deps::frame_system,
runtime::prelude::*,
traits::{Disabled, Everything, Nothing},
};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin,
FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete,
SignedToAccountId32,
};
use xcm_executor::XcmExecutor;
use super::{AccountId, Balances, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin};
parameter_types! {
pub HereLocation: Location = Location::here();
pub ThisNetwork: NetworkId = NetworkId::Pezkuwi;
}
/// Converter from XCM Locations to accounts.
/// This generates sovereign accounts for Locations and converts
/// local AccountId32 junctions to local accounts.
pub type LocationToAccountId = (
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
AccountId32Aliases<ThisNetwork, AccountId>,
);
mod asset_transactor {
use super::*;
/// AssetTransactor for handling the Relay Chain token.
pub type FungibleTransactor = FungibleAdapter<
// Use this `fungible` implementation.
Balances,
// This transactor handles the native token.
IsConcrete<HereLocation>,
// How to convert an XCM Location into a local account id.
// Whenever assets are handled, the location is turned into an account.
// This account is the one where balances are withdrawn/deposited.
LocationToAccountId,
// The account id type, needed because `fungible` is generic over it.
AccountId,
// Not tracking teleports.
(),
>;
/// All asset transactors, in this case only one
pub type AssetTransactor = FungibleTransactor;
}
mod weigher {
use super::*;
use xcm_builder::FixedWeightBounds;
parameter_types! {
pub const WeightPerInstruction: Weight = Weight::from_parts(1, 1);
pub const MaxInstructions: u32 = 100;
}
pub type Weigher = FixedWeightBounds<WeightPerInstruction, RuntimeCall, MaxInstructions>;
}
parameter_types! {
pub UniversalLocation: InteriorLocation = [GlobalConsensus(NetworkId::Pezkuwi)].into();
}
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type XcmEventEmitter = ();
type AssetTransactor = asset_transactor::AssetTransactor;
type OriginConverter = ();
// We don't need to recognize anyone as a reserve
type IsReserve = ();
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
// This is not safe, you should use `xcm_builder::AllowTopLevelPaidExecutionFrom<T>` in a
// production chain
type Barrier = xcm_builder::AllowUnpaidExecutionFrom<Everything>;
type Weigher = weigher::Weigher;
type Trader = ();
type ResponseHandler = ();
type AssetTrap = ();
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = ();
type SubscriptionService = ();
type PalletInstancesInfo = ();
type FeeManager = ();
type MaxAssetsIntoHolding = frame::traits::ConstU32<1>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
type TransactionalProcessor = FrameTransactionalProcessor;
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}
/// Converts a local signed origin into an XCM location. Forms the basis for local origins
/// sending/executing XCMs.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>;
impl pallet_xcm::Config for Runtime {
// No one can call `send`
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
type XcmRouter = super::super::network::RelayChainXcmRouter; // Provided by xcm-simulator
// Anyone can execute XCM programs
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
// We execute any type of program
type XcmExecuteFilter = Everything;
// How we execute programs
type XcmExecutor = XcmExecutor<XcmConfig>;
// We don't allow teleports
type XcmTeleportFilter = Nothing;
// We allow all reserve transfers.
// This is so it can act as a reserve for its native token.
type XcmReserveTransferFilter = Everything;
// Same weigher executor uses to weigh XCM programs
type Weigher = weigher::Weigher;
// Same universal location
type UniversalLocation = UniversalLocation;
// No version discovery needed
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
// No locking
type TrustedLockers = ();
type MaxLockers = frame::traits::ConstU32<0>;
type MaxRemoteLockConsumers = frame::traits::ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
// How to turn locations into accounts
type SovereignAccountOf = LocationToAccountId;
// A currency to pay for things and its matcher, we are using the relay token
type Currency = Balances;
type CurrencyMatcher = IsConcrete<HereLocation>;
// Pallet benchmarks, no need for this example
type WeightInfo = pallet_xcm::TestWeightInfo;
// Runtime types
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
// Aliasing is disabled: xcm_executor::Config::Aliasers is set to `Nothing`.
type AuthorizedAliasConsideration = Disabled;
}
@@ -0,0 +1,137 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
use frame::testing_prelude::*;
use test_log::test;
use xcm::prelude::*;
use xcm_executor::traits::{ConvertLocation, TransferType};
use xcm_simulator::TestExt;
use super::{
network::{MockNet, ParaA, Relay, ALICE, BOB, CENTS, INITIAL_BALANCE},
relay_chain, teyrchain,
};
#[docify::export]
#[test]
fn reserve_asset_transfers_work() {
// Scenario:
// ALICE on the relay chain holds some of Relay Chain's native tokens.
// She transfers them to BOB's account on the teyrchain using a reserve transfer.
// BOB receives Relay Chain native token derivatives on the teyrchain,
// which are backed one-to-one with the real tokens on the Relay Chain.
//
// NOTE: We could've used ALICE on both chains because it's a different account,
// but using ALICE and BOB makes it clearer.
// We restart the mock network.
MockNet::reset();
// ALICE starts with INITIAL_BALANCE on the relay chain
Relay::execute_with(|| {
assert_eq!(relay_chain::Balances::free_balance(&ALICE), INITIAL_BALANCE);
});
// BOB starts with 0 on the teyrchain
ParaA::execute_with(|| {
assert_eq!(teyrchain::Balances::free_balance(&BOB), 0);
});
// ALICE on the Relay Chain sends some Relay Chain native tokens to BOB on the teyrchain.
// The transfer is done with the `transfer_assets` extrinsic in the XCM pallet.
// The extrinsic figures out it should do a reserve asset transfer
// with the local chain as reserve.
Relay::execute_with(|| {
// The teyrchain id is specified in the network.rs file in this recipe.
let destination: Location = Teyrchain(2222).into();
let beneficiary: Location =
AccountId32 { id: BOB.clone().into(), network: Some(NetworkId::Pezkuwi) }.into();
// We need to use `u128` here for the conversion to work properly.
// If we don't specify anything, it will be a `u64`, which the conversion
// will turn into a non-fungible token instead of a fungible one.
let assets: Assets = (Here, 50u128 * CENTS as u128).into();
assert_ok!(relay_chain::XcmPallet::transfer_assets_using_type_and_then(
relay_chain::RuntimeOrigin::signed(ALICE),
Box::new(VersionedLocation::from(destination.clone())),
Box::new(VersionedAssets::from(assets)),
Box::new(TransferType::LocalReserve),
Box::new(VersionedAssetId::from(AssetId(Location::here()))),
Box::new(TransferType::LocalReserve),
Box::new(VersionedXcm::from(
Xcm::<()>::builder_unsafe().deposit_asset(AllCounted(1), beneficiary).build()
)),
WeightLimit::Unlimited,
));
// ALICE now has less Relay Chain tokens.
assert_eq!(relay_chain::Balances::free_balance(&ALICE), INITIAL_BALANCE - 50 * CENTS);
// The funds of the sovereign account of the teyrchain increase by 50 cents,
// the ones transferred over to BOB.
// The funds in this sovereign account represent how many Relay Chain tokens
// have been sent to this teyrchain.
// If the teyrchain wants to send those assets somewhere else they have to go
// via the reserve, and this balance is updated accordingly.
// This is why the derivatives are backed one-to-one.
let teyrchains_sovereign_account =
relay_chain::LocationToAccountId::convert_location(&destination).unwrap();
assert_eq!(relay_chain::Balances::free_balance(teyrchains_sovereign_account), 50 * CENTS);
});
ParaA::execute_with(|| {
// On the teyrchain, BOB has received the derivative tokens
assert_eq!(teyrchain::Balances::free_balance(&BOB), 50 * CENTS);
// BOB gives back half to ALICE in the relay chain
let destination: Location = Parent.into();
let beneficiary: Location =
AccountId32 { id: ALICE.clone().into(), network: Some(NetworkId::Pezkuwi) }.into();
// We specify `Parent` because we are referencing the Relay Chain token.
// This chain doesn't have a token of its own, so we always refer to this token,
// and we do so by the Location of the Relay Chain.
let assets: Assets = (Parent, 25u128 * CENTS as u128).into();
assert_ok!(teyrchain::XcmPallet::transfer_assets_using_type_and_then(
teyrchain::RuntimeOrigin::signed(BOB),
Box::new(VersionedLocation::from(destination)),
Box::new(VersionedAssets::from(assets)),
Box::new(TransferType::DestinationReserve),
Box::new(VersionedAssetId::from(AssetId(Location::parent()))),
Box::new(TransferType::DestinationReserve),
Box::new(VersionedXcm::from(
Xcm::<()>::builder_unsafe().deposit_asset(AllCounted(1), beneficiary).build()
)),
WeightLimit::Unlimited,
));
// BOB's balance decreased
assert_eq!(teyrchain::Balances::free_balance(&BOB), 25 * CENTS);
});
Relay::execute_with(|| {
// ALICE's balance increases
assert_eq!(
relay_chain::Balances::free_balance(&ALICE),
INITIAL_BALANCE - 50 * CENTS + 25 * CENTS
);
// The funds in the teyrchain's sovereign account decrease.
let teyrchain: Location = Teyrchain(2222).into();
let teyrchains_sovereign_account =
relay_chain::LocationToAccountId::convert_location(&teyrchain).unwrap();
assert_eq!(relay_chain::Balances::free_balance(teyrchains_sovereign_account), 25 * CENTS);
});
}
@@ -0,0 +1,56 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! # Runtime
use frame::{deps::frame_system, runtime::prelude::*, traits::IdentityLookup};
use xcm_executor::XcmExecutor;
use xcm_simulator::mock_message_queue;
mod xcm_config;
use xcm_config::XcmConfig;
pub type Block = frame_system::mocking::MockBlock<Runtime>;
pub type AccountId = frame::deps::sp_runtime::AccountId32;
pub type Balance = u64;
construct_runtime! {
pub struct Runtime {
System: frame_system,
MessageQueue: mock_message_queue,
Balances: pallet_balances,
XcmPallet: pallet_xcm,
}
}
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Runtime {
type Block = Block;
type AccountId = AccountId;
type Lookup = IdentityLookup<AccountId>;
type AccountData = pallet_balances::AccountData<Balance>;
}
impl mock_message_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl pallet_balances::Config for Runtime {
type AccountStore = System;
}
@@ -0,0 +1,195 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Pezkuwi.
// Pezkuwi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Pezkuwi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
//! # XCM Configuration
use frame::{
deps::frame_system,
runtime::prelude::*,
traits::{Disabled, Everything, Nothing},
};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin,
FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete,
SignedToAccountId32,
};
use xcm_executor::XcmExecutor;
use super::{AccountId, Balances, MessageQueue, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin};
parameter_types! {
pub RelayLocation: Location = Location::parent();
pub ThisNetwork: NetworkId = NetworkId::Pezkuwi;
}
pub type LocationToAccountId = (
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
AccountId32Aliases<ThisNetwork, AccountId>,
);
/// Configuration related to asset transactors
#[docify::export]
mod asset_transactor {
use super::*;
parameter_types! {
pub ParentRelayLocation: Location = Location::parent();
}
/// AssetTransactor for handling the relay chain token
pub type FungibleTransactor = FungibleAdapter<
// Use this implementation of the `fungible::*` traits.
// `Balances` is the name given to the balances pallet in this particular recipe.
// Any implementation of the traits would suffice.
Balances,
// This transactor deals with the native token of the Relay Chain.
// This token is referenced by the Location of the Relay Chain relative to this chain
// -- Location::parent().
IsConcrete<ParentRelayLocation>,
// How to convert an XCM Location into a local account id.
// This is also something that's configured in the XCM executor.
LocationToAccountId,
// The type for account ids, only needed because `fungible` is generic over it.
AccountId,
// Not tracking teleports.
// This recipe only uses reserve asset transfers to handle the Relay Chain token.
(),
>;
/// Actual configuration item that'll be set in the XCM config.
/// A tuple could be used here to have multiple transactors, each (potentially) handling
/// different assets.
/// In this recipe, we only have one.
pub type AssetTransactor = FungibleTransactor;
}
/// Configuration related to token reserves
#[docify::export]
mod is_reserve {
use super::*;
parameter_types! {
/// Reserves are specified using a pair `(AssetFilter, Location)`.
/// Each pair means that the specified Location is a reserve for all the assets in AssetsFilter.
/// Here, we are specifying that the Relay Chain is the reserve location for its native token.
pub RelayTokenForRelay: (AssetFilter, Location) =
(Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible }), Parent.into());
}
/// The wrapper type xcm_builder::Case is needed in order to use this in the configuration.
pub type IsReserve = xcm_builder::Case<RelayTokenForRelay>;
}
mod weigher {
use super::*;
use xcm_builder::FixedWeightBounds;
parameter_types! {
pub const WeightPerInstruction: Weight = Weight::from_parts(1, 1);
pub const MaxInstructions: u32 = 100;
}
pub type Weigher = FixedWeightBounds<WeightPerInstruction, RuntimeCall, MaxInstructions>;
}
parameter_types! {
pub UniversalLocation: InteriorLocation = [GlobalConsensus(NetworkId::Pezkuwi), Teyrchain(2222)].into();
}
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type XcmEventEmitter = ();
type AssetTransactor = asset_transactor::AssetTransactor;
type OriginConverter = ();
// The declaration of which Locations are reserves for which Assets.
type IsReserve = is_reserve::IsReserve;
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
// This is not safe, you should use `xcm_builder::AllowTopLevelPaidExecutionFrom<T>` in a
// production chain
type Barrier = xcm_builder::AllowUnpaidExecutionFrom<Everything>;
type Weigher = weigher::Weigher;
type Trader = ();
type ResponseHandler = ();
type AssetTrap = ();
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = ();
type SubscriptionService = ();
type PalletInstancesInfo = ();
type FeeManager = ();
type MaxAssetsIntoHolding = frame::traits::ConstU32<1>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
type TransactionalProcessor = FrameTransactionalProcessor;
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}
/// Converts a local signed origin into an XCM location. Forms the basis for local origins
/// sending/executing XCMs.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>;
impl pallet_xcm::Config for Runtime {
// We turn off sending for these tests
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
type XcmRouter = super::super::network::TeyrchainXcmRouter<MessageQueue>; // Provided by xcm-simulator
// Anyone can execute XCM programs
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
// We execute any type of program
type XcmExecuteFilter = Everything;
// How we execute programs
type XcmExecutor = XcmExecutor<XcmConfig>;
// We don't allow teleports
type XcmTeleportFilter = Nothing;
// We allow all reserve transfers
type XcmReserveTransferFilter = Everything;
// Same weigher executor uses to weigh XCM programs
type Weigher = weigher::Weigher;
// Same universal location
type UniversalLocation = UniversalLocation;
// No version discovery needed
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 0;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
// No locking
type TrustedLockers = ();
type MaxLockers = frame::traits::ConstU32<0>;
type MaxRemoteLockConsumers = frame::traits::ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
// How to turn locations into accounts
type SovereignAccountOf = LocationToAccountId;
// A currency to pay for things and its matcher, we are using the relay token
type Currency = Balances;
type CurrencyMatcher = IsConcrete<RelayLocation>;
// Pallet benchmarks, no need for this recipe
type WeightInfo = pallet_xcm::TestWeightInfo;
// Runtime types
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
// Aliasing is disabled: xcm_executor::Config::Aliasers is set to `Nothing`.
type AuthorizedAliasConsideration = Disabled;
}