-
Notifications
You must be signed in to change notification settings - Fork 1.1k
XCM Cookbook #2633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
XCM Cookbook #2633
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 8bbde01
Add an XCM configuration guide
franciscoaguirre 7ac4e96
Move configuration to cookbook instead
franciscoaguirre 1475b56
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre 6556e06
Add relay_token_transactor example to cookbook
franciscoaguirre ddb2ea8
Put back what got deleted from xcm-simulator-example
franciscoaguirre 9d7d8df
Publish and license
franciscoaguirre 51aec90
".git/.scripts/commands/fmt/fmt.sh"
cb50a66
fix(xcm-docs): Update to XCM v4
franciscoaguirre dc97b47
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre 7619a74
chore(xcm-docs): Replace deprecated CurrencyAdapter with FungibleAdapter
franciscoaguirre d6badb1
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
franciscoaguirre 2df362a
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
franciscoaguirre 4d78127
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/mod.rs
franciscoaguirre 38b9533
Update polkadot/xcm/docs/src/glossary.rs
franciscoaguirre f038965
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre 834492f
Update polkadot/xcm/docs/src/lib.rs
franciscoaguirre f7278b6
Update polkadot/xcm/docs/src/glossary.rs
franciscoaguirre 0d3092f
Update polkadot/xcm/docs/src/cookbook/relay_token_transactor/tests.rs
franciscoaguirre cd6746d
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre 3001aa8
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre d2605cf
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre a2b8978
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre 3d022af
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre 1863b25
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre 17aeea0
Update polkadot/xcm/docs/src/fundamentals.rs
franciscoaguirre 845cb40
docs(xcm-docs): Improve relay token transactor recipe
franciscoaguirre 521be8c
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre 6f5e5b1
WIP
franciscoaguirre e21a588
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre a07ef52
fix: Cargo.lock
franciscoaguirre 7a658d4
doc(xcm-docs): more explanations and diagrams
franciscoaguirre 0de7bd4
feat: move mock_message_queue to xcm-simulator
franciscoaguirre 3c603e4
fix: fmt
franciscoaguirre ae33cc7
feat: address feedback
franciscoaguirre bb564e2
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre b918c90
fix(xcm-cookbook): add license to every file
franciscoaguirre e9a1a58
fix(xcm-docs): fmt
franciscoaguirre 8c0721c
fix(xcm-simulator): getters were removed
franciscoaguirre 8ce59e4
fix(xcm-simulator-example): fmt
franciscoaguirre c919085
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre f35fe7a
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre 2f469b3
fix: revert Cargo.lock
franciscoaguirre c657f5c
Merge branch 'master' into cis-xcm-rust-docs
franciscoaguirre 3b76222
fix: update Cargo.lock
franciscoaguirre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
".git/.scripts/commands/fmt/fmt.sh"
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 98 additions & 97 deletions
195
polkadot/xcm/docs/src/cookbook/relay_token_transactor/parachain/xcm_config.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
franciscoaguirre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.