Skip to content

Commit

Permalink
".git/.scripts/commands/fmt/fmt.sh"
Browse files Browse the repository at this point in the history
  • Loading branch information
command-bot committed Dec 14, 2023
1 parent 9d7d8df commit 51aec90
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 517 deletions.
14 changes: 6 additions & 8 deletions polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
//!
//! This example shows how to configure a parachain to only deal with the relay chain token.
//!
//! The first step is using the [`xcm_builder::CurrencyAdapter`] to create an `AssetTransactor` that can
//! handle the relay chain token.
//!
//! The first step is using the [`xcm_builder::CurrencyAdapter`] to create an `AssetTransactor` that
//! can handle the relay chain token.
#![doc = docify::embed!("src/cookbook/relay_token_transactor/parachain/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 get derivatives from the relay chain by using the xcm pallet's
//! `transfer_assets` extrinsic.
//! With this, you'll be able to easily get derivatives 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/parachain/xcm_config.rs", is_reserve)]
//!
//! With this setup, we are able to do a reserve asset transfer to and from the parachain and relay chain.
//!
//! With this setup, we are able to do a reserve asset transfer to and from the parachain 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.
Expand Down
48 changes: 23 additions & 25 deletions polkadot/xcm/docs/src/cookbook/relay_token_transactor/network.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Mock network

use frame::deps::frame_system;
use frame::deps::sp_runtime::{BuildStorage, AccountId32};
use frame::deps::sp_io::TestExternalities;
use frame::deps::{
frame_system,
sp_io::TestExternalities,
sp_runtime::{AccountId32, BuildStorage},
};
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};

use super::{parachain, relay_chain};
Expand Down Expand Up @@ -44,33 +46,29 @@ decl_test_network! {
}

pub fn para_ext() -> TestExternalities {
use parachain::{MessageQueue, Runtime, System};
use parachain::{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
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};
use relay_chain::{Runtime, System};

let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(ALICE, INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();
pallet_balances::GenesisConfig::<Runtime> { balances: vec![(ALICE, INITIAL_BALANCE)] }
.assimilate_storage(&mut t)
.unwrap();

let mut ext = TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
ext
let mut ext = TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
ext
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
//! # Runtime

use frame::prelude::*;
use frame::runtime::prelude::*;
use frame::deps::frame_system;
use frame::traits::IdentityLookup;
use frame::{deps::frame_system, prelude::*, runtime::prelude::*, traits::IdentityLookup};
use xcm_executor::XcmExecutor;

mod xcm_config;
use xcm_config::XcmConfig;
use crate::mock_message_queue;
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,
}
pub struct Runtime {
System: frame_system,
MessageQueue: mock_message_queue,
Balances: pallet_balances,
XcmPallet: pallet_xcm,
}
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type Block = Block;
type AccountId = AccountId;
type Lookup = IdentityLookup<AccountId>;
type AccountData = pallet_balances::AccountData<Balance>;
type Block = Block;
type AccountId = AccountId;
type Lookup = IdentityLookup<AccountId>;
type AccountData = pallet_balances::AccountData<Balance>;
}

impl mock_message_queue::Config for Runtime {
Expand All @@ -38,6 +35,6 @@ impl mock_message_queue::Config for Runtime {

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type AccountStore = System;
type Balance = Balance;
type AccountStore = System;
}
Original file line number Diff line number Diff line change
@@ -1,147 +1,148 @@
//! # XCM Configuration

use frame::runtime::prelude::*;
use frame::traits::{Nothing, Everything};
use frame::deps::frame_system;
use xcm_builder::{
IsConcrete, CurrencyAdapter, HashedDescription, DescribeFamily, DescribeAllTerminal,
EnsureXcmOrigin, SignedToAccountId32, AccountId32Aliases,
use frame::{
deps::frame_system,
runtime::prelude::*,
traits::{Everything, Nothing},
};
use xcm::v3::prelude::*;
use xcm_builder::{
AccountId32Aliases, CurrencyAdapter, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin,
HashedDescription, IsConcrete, SignedToAccountId32,
};
use xcm_executor::XcmExecutor;

use super::{
Runtime, Balances, AccountId, RuntimeCall, RuntimeOrigin, RuntimeEvent, MessageQueue,
};
use super::{AccountId, Balances, MessageQueue, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin};

parameter_types! {
pub RelayLocation: MultiLocation = MultiLocation::parent();
pub ThisNetwork: NetworkId = NetworkId::Polkadot;
pub RelayLocation: MultiLocation = MultiLocation::parent();
pub ThisNetwork: NetworkId = NetworkId::Polkadot;
}

pub type LocationToAccountId = (
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
AccountId32Aliases<ThisNetwork, AccountId>,
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
AccountId32Aliases<ThisNetwork, AccountId>,
);

#[docify::export]
mod asset_transactor {
use super::*;

/// AssetTransactor for handling the relay chain token
pub type CurrencyTransactor = CurrencyAdapter<
// Use this Currency implementation
Balances,
// Use this transactor for dealing with the relay chain token
IsConcrete<RelayLocation>,
// How to convert an XCM MultiLocation into a local account id
LocationToAccountId,
// The account id type, needed because Currency is generic over it
AccountId,
// Not tracking teleports
(),
>;

/// All asset transactors, in this case only one
pub type AssetTransactor = CurrencyTransactor;
use super::*;

/// AssetTransactor for handling the relay chain token
pub type CurrencyTransactor = CurrencyAdapter<
// Use this Currency implementation
Balances,
// Use this transactor for dealing with the relay chain token
IsConcrete<RelayLocation>,
// How to convert an XCM MultiLocation into a local account id
LocationToAccountId,
// The account id type, needed because Currency is generic over it
AccountId,
// Not tracking teleports
(),
>;

/// All asset transactors, in this case only one
pub type AssetTransactor = CurrencyTransactor;
}

#[docify::export]
mod is_reserve {
use super::*;
use super::*;

parameter_types! {
pub RelayTokenForRelay: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { id: Concrete(Parent.into()), fun: WildFungible }), Parent.into());
}
parameter_types! {
pub RelayTokenForRelay: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { id: Concrete(Parent.into()), fun: WildFungible }), Parent.into());
}

/// Put it all together
pub type IsReserve = xcm_builder::Case<RelayTokenForRelay>;
/// Put it all together
pub type IsReserve = xcm_builder::Case<RelayTokenForRelay>;
}

mod weigher {
use super::*;
use xcm_builder::FixedWeightBounds;
use super::*;
use xcm_builder::FixedWeightBounds;

parameter_types! {
pub const WeightPerInstruction: Weight = Weight::from_parts(1, 1);
pub const MaxInstructions: u32 = 100;
}
parameter_types! {
pub const WeightPerInstruction: Weight = Weight::from_parts(1, 1);
pub const MaxInstructions: u32 = 100;
}

pub type Weigher = FixedWeightBounds<WeightPerInstruction, RuntimeCall, MaxInstructions>;
pub type Weigher = FixedWeightBounds<WeightPerInstruction, RuntimeCall, MaxInstructions>;
}

parameter_types! {
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(NetworkId::Polkadot), Parachain(2222));
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(NetworkId::Polkadot), Parachain(2222));
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = ();
type AssetTransactor = asset_transactor::AssetTransactor;
type OriginConverter = ();
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 RuntimeCall = RuntimeCall;
type XcmSender = ();
type AssetTransactor = asset_transactor::AssetTransactor;
type OriginConverter = ();
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;
}

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::ParachainXcmRouter<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
// We turn off sending for these tests
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;
type XcmRouter = super::super::network::ParachainXcmRouter<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 = frame::traits::ConstU32<3>;
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
// No locking
// No locking
type TrustedLockers = ();
type MaxLockers = frame::traits::ConstU32<0>;
type MaxRemoteLockConsumers = frame::traits::ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
// How to turn locations into accounts
// How to turn locations into accounts
type SovereignAccountOf = LocationToAccountId;
// A currency to pay for things and its matcher, we are using the relay token
// 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 example
// Pallet benchmarks, no need for this example
type WeightInfo = pallet_xcm::TestWeightInfo;
// Runtime types
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
// Runtime types
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
}
Loading

0 comments on commit 51aec90

Please sign in to comment.