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
Next Next commit
Move XCM docs to rust docs
  • Loading branch information
franciscoaguirre committed Dec 5, 2023
commit 6bcd6a01bbb6f2862f37001e1e39e2de6a902413
6,230 changes: 3,693 additions & 2,537 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ members = [
"polkadot/utils/generate-bags",
"polkadot/utils/remote-ext-tests/bags-list",
"polkadot/xcm",
"polkadot/xcm/docs",
"polkadot/xcm/pallet-xcm",
"polkadot/xcm/pallet-xcm-benchmarks",
"polkadot/xcm/procedural",
Expand Down
27 changes: 27 additions & 0 deletions polkadot/xcm/docs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "xcm-docs"
description = "Documentation and guides for XCM"
version = "0.0.1"
license.workspace = true
repository.workspace = true
authors.workspace = true
edition.workspace = true

[dependencies]
# For XCM stuff
xcm = { version = "5.0.0", package = "staging-xcm" }
xcm-executor = { version = "5.0.0", package = "staging-xcm-executor" }
xcm-simulator = "5.0.0"

# For building FRAME runtimes
frame = { path = "../../../substrate/frame", features = ["experimental", "runtime"] }
codec = { package = "parity-scale-codec", version = "3.6.9" }
polkadot-parachain-primitives = { path = "../../../polkadot/parachain" }
polkadot-primitives = { path = "../../../polkadot/primitives" }
sp-runtime = { path = "../../../substrate/primitives/runtime" }
sp-std = { path = "../../../substrate/primitives/std" }
sp-io = { path = "../../../substrate/primitives/io" }

# For building docs
simple-mermaid = { git = "https://github.com/kianenigma/simple-mermaid.git", branch = "main" }
docify = "0.2.6"
9 changes: 9 additions & 0 deletions polkadot/xcm/docs/mermaid/location_hierarchy.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
flowchart
relay[Relaychain] --> paraA["Parachain(1000)"]
relay --> paraB["Parachain(2000)"]

paraA --> pallet[Pallet]
pallet --> indexA[Index 1]
pallet --> indexB[Index 2]

paraA --> account[Account]
4 changes: 4 additions & 0 deletions polkadot/xcm/docs/mermaid/structure.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
flowchart
docs[xcm_docs] --> fundamentals
docs --> guides
docs --> cookbook
3 changes: 3 additions & 0 deletions polkadot/xcm/docs/mermaid/universal_location.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flowchart
universe[Universal Location] --> polkadot[Polkadot]
universe --> ethereum[Ethereum]
6 changes: 6 additions & 0 deletions polkadot/xcm/docs/mermaid/usdt_location.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
flowchart
relay[Polkadot] --> assetHub["Asset Hub"]
relay --> anotherPara["Another parachain"]

assetHub --> assetsPallet["Foreign Assets Pallet"]
assetsPallet --> usdt[1984]
1 change: 1 addition & 0 deletions polkadot/xcm/docs/src/cookbook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

141 changes: 141 additions & 0 deletions polkadot/xcm/docs/src/fundamentals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! # XCM Fundamentals
//!
//! XCM standardizes usual actions users take in consensus systems.
//! For example, dealing with assets locally, on other chains, and locking them.
//! XCM programs can both be executed locally or sent to a different consensus system.
//! Examples of consensus systems are blockchains and smart contracts.
//!
//! The goal of XCM is to allow multi-chain ecosystems to thrive via specialization.
//! Very specific functionalities can be abstracted away and standardized in this common language.
//! Then, every member of the ecosystem can implement the subset of the language that makes sense for them.
//!
//! The language evolves over time to accomodate the needs of the community
//! via the [RFC process](https://github.com/paritytech/xcm-format/blob/master/proposals/0001-process.md).
//!
//! XCM is the language, it deals with interpreting and executing programs.
//! It does not deal with actually **sending** these programs from one consensus system to another.
//! This responsability falls to a transport protocol.
//! XCM can even be interpreted on the local system, with no need of a transport protocol.
//! However, automatic and composable workflows can be achieved via the use of one.
//!
//! At the core of XCM lies the XCVM, the Cross-Consensus Virtual Machine.
//! It's the virtual machine that executes XCM programs.
//! It is a specification that comes with the language.
//!
//! For this docs, we'll use a Rust implementation of XCM and the XCVM, consisting of the following parts:
//! - XCM: Holds the definition of an XCM program, the instructions and main concepts.
//! - Executor: Implements the XCVM, capable of executing XCMs. Highly configurable.
//! - Builder: A collection of types used to configure the executor.
//! - XCM Pallet: A FRAME pallet for interacting with the executor.
//! - Simulator: A playground to tinker with different XCM programs and executor configurations.
//!
//! XCM programs are composed of Instructions, which reference Locations and Assets.
//!
//! ## Locations
//!
//! Locations are XCM's vocabulary of places we want to talk about in our XCM programs.
//! They are used to reference things like 32-byte accounts, governance bodies, smart contracts, blockchains and more.
//!
//! Locations are hierarchical.
//! This means some places in consensus are wholly encapsulated in other places.
//! Say we have two systems A and B.
//! If any change in A's state implies a change in B's state, then we say A is interior to B.
//!
#![doc = simple_mermaid::mermaid!("../mermaid/location_hierarchy.mmd")]
//!
//! Parachains are interior to their relaychain, since a change in their state implies a change in the relaychain's state.
//!
//! Because of this hierarchy, the way we represent locations is with both a number of **parents**, times we move __up__ the hierarchy,
//! and a sequence of **junctions**, the steps we take __down__ the hierarchy after going up the specified amount of parents.
//!
//! In Rust, this is specified with the following datatype:
//! ```ignore
//! pub struct Location {
//! parents: u8,
//! interior: Junctions,
//! }
//! ```
//!
//! Many junctions are available, parachains, pallets, 32 and 20 byte accounts, governance bodies, and arbitrary indices
//! are the most common.
//! A full list of available junctions can be found in the [format](https://github.com/paritytech/xcm-format#interior-locations--junctions)
//! and [Junction enum](xcm::v3::prelude::Junction).
//!
//! We'll use a file system notation to represent locations, and start with relative locations.
//! In the diagram, the location of parachain 1000 as seen from all other locations is as follows:
//! - From the relaychain: `Parachain(1000)`
//! - From parachain 1000 itself: `Here`
//! - From parachain 2000: `../Parachain(1000)`
//!
//! Relative locations are interpreted by the system that is executing an XCM program, which is the receiver of a message
//! in the case where it's sent.
//!
//! Locations can also be absolute.
//! Keeping in line with our filesystem analogy, we can imagine the root of our filesystem to exist.
//! This would be a location with no parents, that is also the parent of all systems that derive their own consensus, say
//! Polkadot or Ethereum or Bitcoin.
//! Such a location does not exist concretely, but we can still use this definition for it.
//! This is the **universal location**.
//! We need the universal location to be able to describe locations in an absolute way.
//!
#![doc = simple_mermaid::mermaid!("../mermaid/universal_location.mmd")]
//!
//! Here, the absolute location of parachain 1000 would be `GlobalConsensus(Polkadot)/Parachain(1000)`.
//!
//! ## Assets
//!
//! We want to be able to reference assets in our XCM programs, if only to be able to pay for fees.
//! Assets are represented using locations.
//!
//! The native asset of a chain is represented by the location to that chain.
//! For example, DOT is represented by the location of the Polkadot relaychain.
//! If the interpreting chain has its own asset, it would be represented by `Here`.
//!
//! How do we represent other assets?
//! The asset hub system parachain in Polkadot, for example, holds a lot of assets.
//! To represent each of them, it uses the indices we mentioned, and it makes them interior to the
//! assets pallet instance it uses.
//! USDT, an example asset that lives on asset hub, is identified by the location
//! `Parachain(1000)/PalletInstance(53)/GeneralIndex(1984)`, when seen from the Polkadot relaychain.
//!
#![doc = simple_mermaid::mermaid!("../mermaid/usdt_location.mmd")]
//!
//! The whole type can be seen in the [format](https://github.com/paritytech/xcm-format#6-universal-asset-identifiers)
//! and [rust docs](xcm::v3::prelude::MultiAsset).
//!
//! ## Instructions
//!
//! Given the vocabulary to talk about both locations, chains and accounts, and assets, we now need a way to
//! express what we want the consensus system to do when executing our programs.
//! We need a way of writing our programs.
//!
//! XCM programs are composed of a sequence of instructions.
//!
//! All available instructions can be seen in the [format](https://github.com/paritytech/xcm-format#5-the-xcvm-instruction-set)
//! and the [Instruction enum](xcm::v3::prelude::Instruction).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! and the [Instruction enum](xcm::v3::prelude::Instruction).
//! and the [Instruction enum](xcm::latest::prelude::Instruction).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to the current latest, which is v4, but I'll keep it fixed so we make sure it works, and changing versions is intentional.

//!
//! A very simple example is the following:
//!
//! ```ignore
//! let message = Xcm(vec![
//! TransferAsset { assets, beneficiary },
//! ]);
//! ```
//!
//! This instruction is enough to transfer `assets` from the account of the **origin** of a message to the `beneficiary` account.
//! However, because of XCM's generality, fees need to be paid explicitly.
//! This next example sheds more light on this:
//!
//! ```ignore
//! let message = Xcm(vec![
//! WithdrawAsset(assets),
//! BuyExecution { fees, weight_limit },
//! DepositAsset { assets, beneficiary },
//! ]);
//! ```
//!
//! Here we see the process of transferring assets was broken down into smaller instructions, and we add the explicit fee payment
//! step in the middle.
//! `WithdrawAsset` withdraws assets from the account of the **origin** of the message for usage inside this message's execution.
//! `BuyExecution` explicitly buys execution for this program using the assets specified in `fees`, with a sanity check of `weight_limit`.
//! `DepositAsset` has the same operands as the original `TransferAsset` instruction, specifying `assets` and a `beneficiary` account.
81 changes: 81 additions & 0 deletions polkadot/xcm/docs/src/glossary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//! # Glossary
//!
//! ## XCM (Cross-Consensus Messaging)
//!
//! A messaging format meant to communicate intentions between consensus systems.
//! XCM could also refer to a single message.
//!
//! ## Instructions
//!
//! XCMs are composed of a sequence of instructions.
//! Each instruction aims to convey a particular intention.
//! There are instructions for transferring and locking assets, handling fees, calling arbitrary blobs, and more.
//!
//! ## Consensus system
//!
//! A system that can reach any kind of consensus.
//! For example, relay chains, parachains, smart contracts.
//!
//! ## MultiLocation
//!
//! A way of addressing consensus systems.
//! These could be relative or absolute.
//!
//! ## Junction
//!
//! The different ways of descending down a `MultiLocation` hierarchy.
//! A junction can be a Parachain, an Account, or more.
//!
//! ## MultiAsset
//!
//! A way of identifying assets in the same or another consensus system, by using a `MultiLocation`.
//!
//! ## Sovereign account
//!
//! An account on a consensus system that is controlled by an account in another consensus system.
//!
//! ## Teleport
//!
//! A way of transferring assets between two consensus systems without the need of a third party.
//! It consists of the sender system burning the asset that wants to be sent over and the recipient minting an equivalent amount of that asset.
//! It requires a lot of trust between the two systems, since failure to mint or burn will reduce the total issuance of the token.
//!
//! ## Reserve asset transfer
//!
//! A way of transferring assets between two consensus systems that don't trust each other, by using a third system they both trust, called the reserve.
//! The real asset only exists on the reserve, both sender and recipient only deal with derivatives.
//! It consists of the sender burning a certain amount of derivatives, telling the reserve to move real assets from its sovereign account to the destination's sovereign account, and then telling the recipient to mint the right amount of derivatives.
//!
//! ## XCVM
//!
//! The virtual machine behind XCM.
//! Every XCM is an XCVM programme.
//! Holds state in registers.
//!
//! ## Holding register
//!
//! An XCVM register used to hold arbitrary `Asset`s during the execution of an XCVM programme.
//!
//! ## Barrier
//!
//! An XCM executor configuration item that works as a firewall for incoming XCMs.
//! All XCMs have to pass the barrier to be executed, else they are dropped.
//! It can be used for whitelisting only certain types or messages or messages from certain senders.
//!
//! ## UMP (Upward Message Passing)
//!
//! Transport-layer protocol that allows parachains to send messages upwards to their relay chain.
//!
//! ## DMP (Downward Message Passing)
//!
//! Transport-layer protocol that allows the relay chain to send messages downwards to one of their parachains.
//!
//! ## XCMP (Cross-Consensus Message Passing)
//!
//! Transport-layer protocol that allows parachains to send messages between themselves, without going through the relay chain.
//!
//! ## HRMP (Horizontal Message Passing)
//!
//! Transport-layer protocol that allows a parachain to send messages to a sibling parachain going through the relay chain.
//! It's a precursor to XCMP, also known as XCMP-lite.
//! It uses a mixture of UMP and VMP.
7 changes: 7 additions & 0 deletions polkadot/xcm/docs/src/guides/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! # XCM Guides
//!
//! These guides aim to get you up and running with XCM.

/// Guide on configuring the XCM executor in the most simple way possible for
/// using the relaychain's token for fee payment.
pub mod simple_configuration;
Loading