Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6bcd6a0
Move XCM docs to rust docs
franciscoaguirre Dec 5, 2023
8bbde01
Add an XCM configuration guide
franciscoaguirre Dec 11, 2023
7ac4e96
Move configuration to cookbook instead
franciscoaguirre Dec 12, 2023
1475b56
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre Dec 13, 2023
6556e06
Add relay_token_transactor example to cookbook
franciscoaguirre Dec 14, 2023
ddb2ea8
Put back what got deleted from xcm-simulator-example
franciscoaguirre Dec 14, 2023
9d7d8df
Publish and license
franciscoaguirre Dec 14, 2023
51aec90
".git/.scripts/commands/fmt/fmt.sh"
Dec 14, 2023
cb50a66
fix(xcm-docs): Update to XCM v4
franciscoaguirre Feb 13, 2024
dc97b47
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre Feb 13, 2024
7619a74
chore(xcm-docs): Replace deprecated CurrencyAdapter with FungibleAdapter
franciscoaguirre Feb 15, 2024
d6badb1
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
franciscoaguirre Feb 15, 2024
2df362a
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
franciscoaguirre Feb 15, 2024
4d78127
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
franciscoaguirre Feb 15, 2024
38b9533
Update polkadot/xcm/docs/src/glossary.rs
franciscoaguirre Feb 15, 2024
f038965
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
834492f
Update polkadot/xcm/docs/src/lib.rs
franciscoaguirre Feb 15, 2024
f7278b6
Update polkadot/xcm/docs/src/glossary.rs
franciscoaguirre Feb 15, 2024
0d3092f
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/tests.rs
franciscoaguirre Feb 15, 2024
cd6746d
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
3001aa8
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
d2605cf
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
a2b8978
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
3d022af
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
1863b25
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
17aeea0
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre Feb 15, 2024
845cb40
docs(xcm-docs): Improve relay token transactor recipe
franciscoaguirre Feb 15, 2024
521be8c
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre Feb 15, 2024
6f5e5b1
WIP
franciscoaguirre Mar 14, 2024
e21a588
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre May 1, 2024
a07ef52
fix: Cargo.lock
franciscoaguirre May 1, 2024
7a658d4
doc(xcm-docs): more explanations and diagrams
franciscoaguirre May 1, 2024
0de7bd4
feat: move mock_message_queue to xcm-simulator
franciscoaguirre May 1, 2024
3c603e4
fix: fmt
franciscoaguirre May 1, 2024
ae33cc7
feat: address feedback
franciscoaguirre May 14, 2024
bb564e2
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre May 14, 2024
b918c90
fix(xcm-cookbook): add license to every file
franciscoaguirre May 14, 2024
e9a1a58
fix(xcm-docs): fmt
franciscoaguirre May 14, 2024
8c0721c
fix(xcm-simulator): getters were removed
franciscoaguirre May 14, 2024
8ce59e4
fix(xcm-simulator-example): fmt
franciscoaguirre May 14, 2024
c919085
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre May 14, 2024
f35fe7a
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre May 14, 2024
2f469b3
fix: revert Cargo.lock
franciscoaguirre May 14, 2024
c657f5c
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre May 15, 2024
3b76222
fix: update Cargo.lock
franciscoaguirre May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
".git/.scripts/commands/fmt/fmt.sh"
  • Loading branch information
command-bot committed Dec 14, 2023
commit 51aec90cbac6a1e8ecabada0a182bb19d731e78e
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