From 82c51d643b9d9ad2bdae2110f46b1419d4b0d7b9 Mon Sep 17 00:00:00 2001 From: Erin Shaben Date: Wed, 15 Nov 2023 21:19:44 -0500 Subject: [PATCH 1/4] update kusama fees to v1.0.0 and rollback polkadot links to v0.9.43 --- builders/interoperability/xcm/fees.md | 42 +++++++++++++-------------- variables.yml | 38 ++++++++++++------------ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/builders/interoperability/xcm/fees.md b/builders/interoperability/xcm/fees.md index ff6099417..29992aac2 100644 --- a/builders/interoperability/xcm/fees.md +++ b/builders/interoperability/xcm/fees.md @@ -53,18 +53,18 @@ There are two databases available in Polkadot and Kusama, RocksDB (which is the ### Polkadot {: #polkadot } -As previously mentioned, Polkadot currently uses a [fixed amount of weight](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/polkadot/src/xcm_config.rs#L111){target=_blank} for all XCM instructions, which is `{{ networks.polkadot.xcm_instructions.weight.display }}` weight units per instruction. +As previously mentioned, Polkadot currently uses a [fixed amount of weight](https://github.com/paritytech/polkadot/blob/{{networks.polkadot.spec_version}}/runtime/polkadot/src/xcm_config.rs#L111){target=_blank} for all XCM instructions, which is `{{ networks.polkadot.xcm_instructions.weight.display }}` weight units per instruction. Although Polkadot doesn't currently use database weight units to calculate costs, the weight units for database operations, which have been benchmarked, are shared here for reference. | Database | Read | Write | |:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------:|:----------------------------------------------:| -| [RocksDB (default)](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/polkadot/constants/src/weights/rocksdb_weights.rs){target=_blank} | {{ networks.polkadot.rocks_db.read_weight }} | {{ networks.polkadot.rocks_db.write_weight }} | -| [ParityDB](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/polkadot/constants/src/weights/paritydb_weights.rs){target=_blank} | {{ networks.polkadot.parity_db.read_weight }} | {{ networks.polkadot.parity_db.write_weight }} | +| [RocksDB (default)](https://github.com/paritytech/polkadot/blob/{{networks.polkadot.spec_version}}/runtime/polkadot/constants/src/weights/rocksdb_weights.rs){target=_blank} | {{ networks.polkadot.rocks_db.read_weight }} | {{ networks.polkadot.rocks_db.write_weight }} | +| [ParityDB](https://github.com/paritytech/polkadot/blob/{{networks.polkadot.spec_version}}/runtime/polkadot/constants/src/weights/paritydb_weights.rs){target=_blank} | {{ networks.polkadot.parity_db.read_weight }} | {{ networks.polkadot.parity_db.write_weight }} | With the instruction weight cost established, you can calculate the cost of each instruction in DOT. -In Polkadot, the [`ExtrinsicBaseWeight`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/polkadot/constants/src/weights/extrinsic_weights.rs#L56){target=_blank} is set to `{{ networks.polkadot.extrinsic_base_weight.display }}` which is [mapped to 1/10th](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/polkadot/constants/src/lib.rs#L89){targer=blank} of a cent. Where 1 cent is `10^10 / 100`. +In Polkadot, the [`ExtrinsicBaseWeight`](https://github.com/paritytech/polkadot/blob/{{networks.polkadot.spec_version}}/runtime/polkadot/constants/src/weights/extrinsic_weights.rs#L56){target=_blank} is set to `{{ networks.polkadot.extrinsic_base_weight.display }}` which is [mapped to 1/10th](https://github.com/paritytech/polkadot/blob/{{networks.polkadot.spec_version}}/runtime/polkadot/constants/src/lib.rs#L89){targer=blank} of a cent. Where 1 cent is `10^10 / 100`. Therefore, to calculate the cost of executing an XCM instruction, you can use the following formula: @@ -114,26 +114,26 @@ As an example, you can calculate the total cost of DOT for sending an XCM messag The total weight costs on Kusama take into consideration database reads and writes in addition to the weight required for a given instruction. Database read and write operations have not been benchmarked, while instruction weights have been. The breakdown of weight costs for the database operations is as follows: -| Database | Read | Write | -|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------:|:---------------------------------------------------:| -| [RocksDB (default)](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/constants/src/weights/rocksdb_weights.rs){target=_blank} | {{ networks.kusama.rocks_db.read_weight.display }} | {{ networks.kusama.rocks_db.write_weight.display }} | -| [ParityDB](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/constants/src/weights/paritydb_weights.rs){target=_blank} | {{ networks.kusama.parity_db.read_weight }} | {{ networks.kusama.parity_db.write_weight }} | +| Database | Read | Write | +|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------:|:---------------------------------------------------:| +| [RocksDB (default)](https://github.com/polkadot-fellows/runtimes/blob/{{ networks.kusama.spec_version }}/relay/kusama/constants/src/weights/rocksdb_weights.rs){target=_blank} | {{ networks.kusama.rocks_db.read_weight.display }} | {{ networks.kusama.rocks_db.write_weight.display }} | +| [ParityDB](https://github.com/polkadot-fellows/runtimes/blob/{{ networks.kusama.spec_version }}/relay/kusama/constants/src/weights/paritydb_weights.rs){target=_blank} | {{ networks.kusama.parity_db.read_weight }} | {{ networks.kusama.parity_db.write_weight }} | Now that you are aware of the weight costs for database reads and writes on Kusama, you can calculate the weight cost for a given instruction using the base weight for an instruction. -For example, the [`WithdrawAsset` instruction](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L49-L53){target=_blank} has a base weight of `{{ networks.kusama.xcm_instructions.withdraw.base_weight.display }}`, and performs one database read, and one database write. Therefore, the total weight cost of the `WithdrawAsset` instruction is calculated as: +For example, the [`WithdrawAsset` instruction](https://github.com/polkadot-fellows/runtimes/blob/{{ networks.kusama.spec_version }}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L54-L62){target=_blank} has a base weight of `{{ networks.kusama.xcm_instructions.withdraw.base_weight.display }}`, and performs one database read and one database write. Therefore, the total weight cost of the `WithdrawAsset` instruction is calculated as: ```text {{ networks.kusama.xcm_instructions.withdraw.base_weight.numbers_only }} + {{ networks.kusama.rocks_db.read_weight.numbers_only }} + {{ networks.kusama.rocks_db.write_weight.numbers_only }} = {{ networks.kusama.xcm_instructions.withdraw.total_weight.numbers_only }} ``` -The [`BuyExecution` instruction](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L76){target=_blank} has a base weight of `{{ networks.kusama.xcm_instructions.buy_exec.base_weight }}` and doesn't include any database reads or writes. Therefore, the total weight cost of the `BuyExecution` instruction is `{{ networks.kusama.xcm_instructions.buy_exec.total_weight }}`. +The [`BuyExecution` instruction](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L76-L82){target=_blank} has a base weight of `{{ networks.kusama.xcm_instructions.buy_exec.base_weight }}` and doesn't include any database reads or writes. Therefore, the total weight cost of the `BuyExecution` instruction is `{{ networks.kusama.xcm_instructions.buy_exec.total_weight }}`. -On Kusama, the benchmarked base weights are broken up into two categories: fungible and generic. Fungible weights are for XCM instructions that involve moving assets, and generic weights are for everything else. You can view the current weights for [fungible assets](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L49){target=_blank} and [generic assets](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L50){target=_blank} directly in the Kusama Runtime code. +On Kusama, the benchmarked base weights are broken up into two categories: fungible and generic. Fungible weights are for XCM instructions that involve moving assets, and generic weights are for everything else. You can view the current weights for [fungible assets](https://github.com/polkadot-fellows/runtimes/blob/{{ networks.kusama.spec_version }}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L49){target=_blank} and [generic assets](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L50){target=_blank} directly in the Kusama Runtime code. With the instruction weight cost established, you can calculate the cost of the instruction in KSM. -In Kusama, the [`ExtrinsicBaseWeight`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/constants/src/weights/extrinsic_weights.rs#L56){target=_blank} is set to `{{ networks.kusama.extrinsic_base_weight.display }}` which is [mapped to 1/10th](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/constants/src/lib.rs#L87){target=_blank} of a cent. Where 1 cent is `10^12 / 30,000`. +In Kusama, the [`ExtrinsicBaseWeight`](https://github.com/polkadot-fellows/runtimes/blob/{{networks.polkadot.spec_version}}/relay/kusama/constants/src/weights/extrinsic_weights.rs#L56){target=_blank} is set to `{{ networks.kusama.extrinsic_base_weight.display }}` which is [mapped to 1/10th](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/constants/src/lib.rs#L87){target=_blank} of a cent. Where 1 cent is `10^12 / 30,000`. Therefore, to calculate the cost of executing an XCM instruction, you can use the following formula: @@ -171,13 +171,13 @@ The total cost for that particular instruction is `{{ networks.kusama.xcm_instru As an example, you can calculate the total cost of KSM for sending an XCM message that transfers xcKSM to KSM on Kusama using the following weights and instruction costs: -| Instruction | Weight | Cost | -|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------:|:-----------------------------------------------------------------:| -| [`WithdrawAsset`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L54){target=_blank} | {{ networks.kusama.xcm_instructions.withdraw.total_weight.display }} | {{ networks.kusama.xcm_instructions.withdraw.ksm_cost }} KSM | -| [`ClearOrigin`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L135){target=_blank} | {{ networks.kusama.xcm_instructions.clear_origin.total_weight }} | {{ networks.kusama.xcm_instructions.clear_origin.ksm_cost }} KSM | -| [`BuyExecution`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L76){target=_blank} | {{ networks.kusama.xcm_instructions.buy_exec.total_weight }} | {{ networks.kusama.xcm_instructions.buy_exec.ksm_cost }} KSM | -| [`DepositAsset`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L132){target=_blank} | {{ networks.kusama.xcm_instructions.deposit_asset.total_weight }} | {{ networks.kusama.xcm_instructions.deposit_asset.ksm_cost }} KSM | -| **TOTAL** | **{{ networks.kusama.xcm_message.transfer.weight }}** | **{{ networks.kusama.xcm_message.transfer.cost }} KSM** | +| Instruction | Weight | Cost | +|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------:|:-----------------------------------------------------------------:| +| [`WithdrawAsset`](https://github.com/polkadot-fellows/runtimes/blob/{{ networks.kusama.spec_version }}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L54-L62){target=_blank} | {{ networks.kusama.xcm_instructions.withdraw.total_weight.display }} | {{ networks.kusama.xcm_instructions.withdraw.ksm_cost }} KSM | +| [`ClearOrigin`](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L135-L141){target=_blank} | {{ networks.kusama.xcm_instructions.clear_origin.total_weight }} | {{ networks.kusama.xcm_instructions.clear_origin.ksm_cost }} KSM | +| [`BuyExecution`](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_generic.rs#L76-L82){target=_blank} | {{ networks.kusama.xcm_instructions.buy_exec.total_weight }} | {{ networks.kusama.xcm_instructions.buy_exec.ksm_cost }} KSM | +| [`DepositAsset`](https://github.com/polkadot-fellows/runtimes/blob/{{ networks.kusama.spec_version }}/relay/kusama/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs#L132-L140){target=_blank} | {{ networks.kusama.xcm_instructions.deposit_asset.total_weight }} | {{ networks.kusama.xcm_instructions.deposit_asset.ksm_cost }} KSM | +| **TOTAL** | **{{ networks.kusama.xcm_message.transfer.weight }}** | **{{ networks.kusama.xcm_message.transfer.cost }} KSM** | ## Moonbeam-based Networks XCM Fee Calculation {: #moonbeam-xcm-fee-calc } @@ -185,8 +185,8 @@ Substrate has introduced a weight system that determines how heavy or, in other For all Moonbeam-based networks, the generic XCM instructions are benchmarked, while the fungible XCM instructions still use a fixed amount of weight per instruction. Consequently, the total weight cost of the benchmarked XCM instructions considers the number of database reads/writes in addition to the weight required for a given instruction. The breakdown of weight cost for the database operations is as follows: -| Database | Read | Write | -|:--------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------:|:------------------------------------------:| +| Database | Read | Write | +|:---------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------:|:------------------------------------------:| | [RocksDB (default)](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/support/src/weights/rocksdb_weights.rs#L27-L28){target=_blank} | {{ xcm.db_weights.rocksdb_read.display }} | {{ xcm.db_weights.rocksdb_write.display }} | Now that you know the weight costs for database reads and writes for Moonbase Alpha, you can calculate the weight cost for both fungible and generic XCM instruction using the base weight for instruction and the extra database read/writes if applicable. diff --git a/variables.yml b/variables.yml index 326af6007..29c20623d 100644 --- a/variables.yml +++ b/variables.yml @@ -1080,7 +1080,7 @@ networks: display: 107,648,000 numbers_only: 107648000 kusama: - spec_version: v0.9.43 + spec_version: v1.0.0 rocks_db: read_weight: display: 25,000,000 @@ -1093,32 +1093,32 @@ networks: write_weight: 50,000,000 xcm_message: transfer: - weight: 299,506,000 - cost: '0.000092003956' + weight: 305,952,000 + cost: '0.000081779545' xcm_instructions: buy_exec: - base_weight: 3,697,000 - total_weight: 3,697,000 - ksm_cost: '0.000001135665' + base_weight: 2,714,000 + total_weight: 2,714,000 + ksm_cost: '0.000000725440' withdraw: base_weight: - display: 20,385,000 - numbers_only: 20385000 + display: 24,720,000 + numbers_only: 24720000 total_weight: - display: 145,385,000 - numbers_only: 145385000 - planck_ksm_cost: 44660191.1923 - ksm_cost: '0.000044660191' + display: 149,720,000 + numbers_only: 149720000 + planck_ksm_cost: 40019459.1011 + ksm_cost: '0.000040019459' clear_origin: - total_weight: 3,661,000 - ksm_cost: '0.000001124607' + total_weight: 2,614,000 + ksm_cost: '0.000000698710' deposit_asset: - total_weight: 146,763,000 - ksm_cost: '0.000045083493' - planck_ksm_weight: '0.307185687604' + total_weight: 150,904,000 + ksm_cost: '0.000040335936' + planck_ksm_weight: '0.267295345319' extrinsic_base_weight: - display: 108,512,000 - numbers_only: 108512000 + display: 124,706,000 + numbers_only: 124706000 moonbase_beta: xcm_message: transact: From a3f999103260caabf98e478312af3952398565e0 Mon Sep 17 00:00:00 2001 From: Erin Shaben Date: Wed, 15 Nov 2023 22:26:59 -0500 Subject: [PATCH 2/4] move the snippets back to the files so the variables work --- .../xcm/xc20/x-tokens/xcm-instructions.md | 20 ----------------- builders/interoperability/xcm/fees.md | 22 +++++++++++++++++-- builders/interoperability/xcm/xc20/xtokens.md | 21 +++++++++++++++++- variables.yml | 1 + 4 files changed, 41 insertions(+), 23 deletions(-) delete mode 100644 .snippets/text/builders/interoperability/xcm/xc20/x-tokens/xcm-instructions.md diff --git a/.snippets/text/builders/interoperability/xcm/xc20/x-tokens/xcm-instructions.md b/.snippets/text/builders/interoperability/xcm/xc20/x-tokens/xcm-instructions.md deleted file mode 100644 index 6b7c0dffd..000000000 --- a/.snippets/text/builders/interoperability/xcm/xc20/x-tokens/xcm-instructions.md +++ /dev/null @@ -1,20 +0,0 @@ -For example, to move DOT to Moonbeam, the following XCM instructions are used: - -1. [`TransferReserveAsset`](https://github.com/paritytech/xcm-format#transferreserveasset){target=_blank} - gets executed in Polkadot. Moves assets from the origin account and deposits them into a destination account. In this case, the destination account is Moonbeam's sovereign account on Polkadot. It then sends an XCM message to the destination, which is Moonbeam, with the XCM instructions that are to be executed -2. [`ReserveAssetDeposited`](https://github.com/paritytech/xcm-format#reserveassetdeposited-){target=_blank} - gets executed in Moonbeam. Takes a representation of the assets received in the sovereign account and places them into the holding register, a temporary position in the Cross-Consensus Virtual Machine (XCVM) -3. [`ClearOrigin`](https://github.com/paritytech/xcm-format#clearorigin){target=_blank} - gets executed in Moonbeam. Ensures that later XCM instructions cannot command the authority of the XCM author -4. [`BuyExecution`](https://github.com/paritytech/xcm-format#buyexecution){target=_blank} - gets executed in Moonbeam. Takes the assets from holding to pay for execution fees. The fees to pay are determined by the target chain, which in this case is Moonbeam -5. [`DepositAsset`](https://github.com/paritytech/xcm-format#depositasset){target=_blank} - gets executed in Moonbeam. Removes the assets from holding and sends them to a destination account on Moonbeam - -To check how the instructions for an XCM message are built to transfer self-reserve assets to a target chain, such as DOT to Moonbeam, you can refer to the [X-Tokens Open Runtime Module Library](https://github.com/open-web3-stack/open-runtime-module-library/tree/polkadot-{{networks.polkadot.spec_version}}/xtokens){target=_blank} repository (as an example). You'll want to take a look at the [`transfer_self_reserve_asset`](https://github.com/open-web3-stack/open-runtime-module-library/blob/polkadot-{{networks.polkadot.spec_version}}/xtokens/src/lib.rs#L680){target=_blank} function. You'll notice it calls `TransferReserveAsset` and passes in `assets`, `dest`, and `xcm` as parameters. In particular, the `xcm` parameter includes the `BuyExecution` and `DepositAsset` instructions. If you then head over to the Polkadot GitHub repository, you can find the [`TransferReserveAsset` instruction](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-executor/src/lib.rs#L514){target=_blank}. The XCM message is constructed by combining the `ReserveAssetDeposited` and `ClearOrigin` instructions with the `xcm` parameter, which as mentioned includes the `BuyExecution` and `DepositAsset` instructions. - -To move xcDOT from Moonbeam back to Polkadot, the instructions that are used are: - -1. [`WithdrawAsset`](https://github.com/paritytech/xcm-format#withdrawasset){target=_blank} - gets executed in Moonbeam. Removes assets and places them into the holding register -2. [`InitiateReserveWithdraw`](https://github.com/paritytech/xcm-format#initiatereservewithdraw){target=_blank} - gets executed in Moonbeam. Removes the assets from holding (essentially burning them) and sends an XCM message to the destination chain starting with the `WithdrawAsset` instruction -3. [`WithdrawAsset`](https://github.com/paritytech/xcm-format#withdrawasset){target=_blank} - gets executed in Polkadot. Removes assets and places them into the holding register -4. [`ClearOrigin`](https://github.com/paritytech/xcm-format#clearorigin){target=_blank} - gets executed in Polkadot. Ensures that later XCM instructions cannot command the authority of the XCM author -5. [`BuyExecution`](https://github.com/paritytech/xcm-format#buyexecution){target=_blank} - gets executed in Polkadot. Takes the assets from holding to pay for execution fees. The fees to pay are determined by the target chain, which in this case is Polkadot -6. [`DepositAsset`](https://github.com/paritytech/xcm-format#depositasset){target=_blank} - gets executed in Polkadot. Removes the assets from holding and sends them to a destination account on Polkadot - -To check how the instructions for an XCM message are built to transfer reserve assets to a target chain, such as xcDOT to Polkadot, you can refer to the [X-Tokens Open Runtime Module Library](https://github.com/open-web3-stack/open-runtime-module-library/tree/polkadot-{{networks.polkadot.spec_version}}/xtokens){target=_blank} repository. You'll want to take a look at the [`transfer_to_reserve`](https://github.com/open-web3-stack/open-runtime-module-library/blob/polkadot-{{networks.polkadot.spec_version}}/xtokens/src/lib.rs#L697){target=_blank} function. You'll notice that it calls `WithdrawAsset`, then `InitiateReserveWithdraw` and passes in `assets`, `dest`, and `xcm` as parameters. In particular, the `xcm` parameter includes the `BuyExecution` and `DepositAsset` instructions. If you then head over to the Polkadot GitHub repository, you can find the [`InitiateReserveWithdraw` instruction](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-executor/src/lib.rs#L638){target=_blank}. The XCM message is constructed by combining the `WithdrawAsset` and `ClearOrigin` instructions with the `xcm` parameter, which as mentioned includes the `BuyExecution` and `DepositAsset` instructions. \ No newline at end of file diff --git a/builders/interoperability/xcm/fees.md b/builders/interoperability/xcm/fees.md index 29992aac2..5ac1dcc78 100644 --- a/builders/interoperability/xcm/fees.md +++ b/builders/interoperability/xcm/fees.md @@ -40,8 +40,26 @@ The exact process for Alice's transfer is as follows: ### XCM Instructions {: #xcm-instructions } -An XCM message is comprised of a series of XCM instructions. As a result, different combinations of XCM instructions result in different actions. ---8<-- 'text/builders/interoperability/xcm/xc20/x-tokens/xcm-instructions.md' +An XCM message is comprised of a series of XCM instructions. As a result, different combinations of XCM instructions result in different actions. For example, to move DOT to Moonbeam, the following XCM instructions are used: + +1. [`TransferReserveAsset`](https://github.com/paritytech/xcm-format#transferreserveasset){target=_blank} - gets executed in Polkadot. Moves assets from the origin account and deposits them into a destination account. In this case, the destination account is Moonbeam's sovereign account on Polkadot. It then sends an XCM message to the destination, which is Moonbeam, with the XCM instructions that are to be executed +2. [`ReserveAssetDeposited`](https://github.com/paritytech/xcm-format#reserveassetdeposited-){target=_blank} - gets executed in Moonbeam. Takes a representation of the assets received in the sovereign account and places them into the holding register, a temporary position in the Cross-Consensus Virtual Machine (XCVM) +3. [`ClearOrigin`](https://github.com/paritytech/xcm-format#clearorigin){target=_blank} - gets executed in Moonbeam. Ensures that later XCM instructions cannot command the authority of the XCM author +4. [`BuyExecution`](https://github.com/paritytech/xcm-format#buyexecution){target=_blank} - gets executed in Moonbeam. Takes the assets from holding to pay for execution fees. The fees to pay are determined by the target chain, which in this case is Moonbeam +5. [`DepositAsset`](https://github.com/paritytech/xcm-format#depositasset){target=_blank} - gets executed in Moonbeam. Removes the assets from holding and sends them to a destination account on Moonbeam + +To check how the instructions for an XCM message are built to transfer self-reserve assets to a target chain, such as DOT to Moonbeam, you can refer to the [X-Tokens Open Runtime Module Library](https://github.com/open-web3-stack/open-runtime-module-library/tree/polkadot-{{ networks.polkadot.spec_version }}/xtokens){target=_blank} repository (as an example). You'll want to take a look at the [`transfer_self_reserve_asset`](https://github.com/open-web3-stack/open-runtime-module-library/blob/polkadot-{{ networks.polkadot.spec_version }}/xtokens/src/lib.rs#L680){target=_blank} function. You'll notice it calls `TransferReserveAsset` and passes in `assets`, `dest`, and `xcm` as parameters. In particular, the `xcm` parameter includes the `BuyExecution` and `DepositAsset` instructions. If you then head over to the Polkadot GitHub repository, you can find the [`TransferReserveAsset` instruction](https://github.com/paritytech/polkadot-sdk/blob/{{ polkadot_sdk }}/polkadot/xcm/xcm-executor/src/lib.rs#L514){target=_blank}. The XCM message is constructed by combining the `ReserveAssetDeposited` and `ClearOrigin` instructions with the `xcm` parameter, which as mentioned includes the `BuyExecution` and `DepositAsset` instructions. + +To move xcDOT from Moonbeam back to Polkadot, the instructions that are used are: + +1. [`WithdrawAsset`](https://github.com/paritytech/xcm-format#withdrawasset){target=_blank} - gets executed in Moonbeam. Removes assets and places them into the holding register +2. [`InitiateReserveWithdraw`](https://github.com/paritytech/xcm-format#initiatereservewithdraw){target=_blank} - gets executed in Moonbeam. Removes the assets from holding (essentially burning them) and sends an XCM message to the destination chain starting with the `WithdrawAsset` instruction +3. [`WithdrawAsset`](https://github.com/paritytech/xcm-format#withdrawasset){target=_blank} - gets executed in Polkadot. Removes assets and places them into the holding register +4. [`ClearOrigin`](https://github.com/paritytech/xcm-format#clearorigin){target=_blank} - gets executed in Polkadot. Ensures that later XCM instructions cannot command the authority of the XCM author +5. [`BuyExecution`](https://github.com/paritytech/xcm-format#buyexecution){target=_blank} - gets executed in Polkadot. Takes the assets from holding to pay for execution fees. The fees to pay are determined by the target chain, which in this case is Polkadot +6. [`DepositAsset`](https://github.com/paritytech/xcm-format#depositasset){target=_blank} - gets executed in Polkadot. Removes the assets from holding and sends them to a destination account on Polkadot + +To check how the instructions for an XCM message are built to transfer reserve assets to a target chain, such as xcDOT to Polkadot, you can refer to the [X-Tokens Open Runtime Module Library](https://github.com/open-web3-stack/open-runtime-module-library/tree/polkadot-{{networks.polkadot.spec_version}}/xtokens){target=_blank} repository. You'll want to take a look at the [`transfer_to_reserve`](https://github.com/open-web3-stack/open-runtime-module-library/blob/polkadot-{{networks.polkadot.spec_version}}/xtokens/src/lib.rs#L697){target=_blank} function. You'll notice that it calls `WithdrawAsset`, then `InitiateReserveWithdraw` and passes in `assets`, `dest`, and `xcm` as parameters. In particular, the `xcm` parameter includes the `BuyExecution` and `DepositAsset` instructions. If you then head over to the Polkadot GitHub repository, you can find the [`InitiateReserveWithdraw` instruction](https://github.com/paritytech/polkadot-sdk/blob/{{polkadot_sdk}}/polkadot/xcm/xcm-executor/src/lib.rs#L638){target=_blank}. The XCM message is constructed by combining the `WithdrawAsset` and `ClearOrigin` instructions with the `xcm` parameter, which as mentioned includes the `BuyExecution` and `DepositAsset` instructions. ## Relay Chain XCM Fee Calculation {: #rel-chain-xcm-fee-calc } diff --git a/builders/interoperability/xcm/xc20/xtokens.md b/builders/interoperability/xcm/xc20/xtokens.md index ec1f07800..86def1f33 100644 --- a/builders/interoperability/xcm/xc20/xtokens.md +++ b/builders/interoperability/xcm/xc20/xtokens.md @@ -77,7 +77,26 @@ The XCM instructions used for the X-Tokens Pallet extrinsics are defined in the Regardless of which transfer extrinsic is used, the instructions are the same for sending the native asset back to its origin chain, such as xcDOT from Moonbeam back to Polkadot, and sending the native asset from the origin chain to a destination chain, such as DOT from Polkadot to Moonbeam. ---8<-- 'text/builders/interoperability/xcm/xc20/x-tokens/xcm-instructions.md' +For example, to move DOT to Moonbeam, the following XCM instructions are used: + +1. [`TransferReserveAsset`](https://github.com/paritytech/xcm-format#transferreserveasset){target=_blank} - gets executed in Polkadot. Moves assets from the origin account and deposits them into a destination account. In this case, the destination account is Moonbeam's sovereign account on Polkadot. It then sends an XCM message to the destination, which is Moonbeam, with the XCM instructions that are to be executed +2. [`ReserveAssetDeposited`](https://github.com/paritytech/xcm-format#reserveassetdeposited-){target=_blank} - gets executed in Moonbeam. Takes a representation of the assets received in the sovereign account and places them into the holding register, a temporary position in the Cross-Consensus Virtual Machine (XCVM) +3. [`ClearOrigin`](https://github.com/paritytech/xcm-format#clearorigin){target=_blank} - gets executed in Moonbeam. Ensures that later XCM instructions cannot command the authority of the XCM author +4. [`BuyExecution`](https://github.com/paritytech/xcm-format#buyexecution){target=_blank} - gets executed in Moonbeam. Takes the assets from holding to pay for execution fees. The fees to pay are determined by the target chain, which in this case is Moonbeam +5. [`DepositAsset`](https://github.com/paritytech/xcm-format#depositasset){target=_blank} - gets executed in Moonbeam. Removes the assets from holding and sends them to a destination account on Moonbeam + +To check how the instructions for an XCM message are built to transfer self-reserve assets to a target chain, such as DOT to Moonbeam, you can refer to the [X-Tokens Open Runtime Module Library](https://github.com/open-web3-stack/open-runtime-module-library/tree/polkadot-{{ networks.polkadot.spec_version }}/xtokens){target=_blank} repository (as an example). You'll want to take a look at the [`transfer_self_reserve_asset`](https://github.com/open-web3-stack/open-runtime-module-library/blob/polkadot-{{ networks.polkadot.spec_version }}/xtokens/src/lib.rs#L680){target=_blank} function. You'll notice it calls `TransferReserveAsset` and passes in `assets`, `dest`, and `xcm` as parameters. In particular, the `xcm` parameter includes the `BuyExecution` and `DepositAsset` instructions. If you then head over to the Polkadot GitHub repository, you can find the [`TransferReserveAsset` instruction](https://github.com/paritytech/polkadot-sdk/blob/{{ polkadot_sdk }}/polkadot/xcm/xcm-executor/src/lib.rs#L514){target=_blank}. The XCM message is constructed by combining the `ReserveAssetDeposited` and `ClearOrigin` instructions with the `xcm` parameter, which as mentioned includes the `BuyExecution` and `DepositAsset` instructions. + +To move xcDOT from Moonbeam back to Polkadot, the instructions that are used are: + +1. [`WithdrawAsset`](https://github.com/paritytech/xcm-format#withdrawasset){target=_blank} - gets executed in Moonbeam. Removes assets and places them into the holding register +2. [`InitiateReserveWithdraw`](https://github.com/paritytech/xcm-format#initiatereservewithdraw){target=_blank} - gets executed in Moonbeam. Removes the assets from holding (essentially burning them) and sends an XCM message to the destination chain starting with the `WithdrawAsset` instruction +3. [`WithdrawAsset`](https://github.com/paritytech/xcm-format#withdrawasset){target=_blank} - gets executed in Polkadot. Removes assets and places them into the holding register +4. [`ClearOrigin`](https://github.com/paritytech/xcm-format#clearorigin){target=_blank} - gets executed in Polkadot. Ensures that later XCM instructions cannot command the authority of the XCM author +5. [`BuyExecution`](https://github.com/paritytech/xcm-format#buyexecution){target=_blank} - gets executed in Polkadot. Takes the assets from holding to pay for execution fees. The fees to pay are determined by the target chain, which in this case is Polkadot +6. [`DepositAsset`](https://github.com/paritytech/xcm-format#depositasset){target=_blank} - gets executed in Polkadot. Removes the assets from holding and sends them to a destination account on Polkadot + +To check how the instructions for an XCM message are built to transfer reserve assets to a target chain, such as xcDOT to Polkadot, you can refer to the [X-Tokens Open Runtime Module Library](https://github.com/open-web3-stack/open-runtime-module-library/tree/polkadot-{{networks.polkadot.spec_version}}/xtokens){target=_blank} repository. You'll want to take a look at the [`transfer_to_reserve`](https://github.com/open-web3-stack/open-runtime-module-library/blob/polkadot-{{networks.polkadot.spec_version}}/xtokens/src/lib.rs#L697){target=_blank} function. You'll notice that it calls `WithdrawAsset`, then `InitiateReserveWithdraw` and passes in `assets`, `dest`, and `xcm` as parameters. In particular, the `xcm` parameter includes the `BuyExecution` and `DepositAsset` instructions. If you then head over to the Polkadot GitHub repository, you can find the [`InitiateReserveWithdraw` instruction](https://github.com/paritytech/polkadot-sdk/blob/{{polkadot_sdk}}/polkadot/xcm/xcm-executor/src/lib.rs#L638){target=_blank}. The XCM message is constructed by combining the `WithdrawAsset` and `ClearOrigin` instructions with the `xcm` parameter, which as mentioned includes the `BuyExecution` and `DepositAsset` instructions. ## Building an XCM Message with the X-Tokens Pallet {: #build-xcm-xtokens-pallet} diff --git a/variables.yml b/variables.yml index 29c20623d..e7846daf0 100644 --- a/variables.yml +++ b/variables.yml @@ -1127,6 +1127,7 @@ networks: numbers_only: 400000000 wei_betadev_cost: 20000000000000 betadev_cost: '0.00002' +polkadot_sdk: polkadot-v1.1.0 xcm: db_weights: rocksdb_read: From 82ba0186d7e622c922fef19419c3591fcb97eb2a Mon Sep 17 00:00:00 2001 From: Erin Shaben Date: Wed, 15 Nov 2023 22:32:23 -0500 Subject: [PATCH 3/4] update polkadot-sdk links --- builders/interoperability/xcm/fees.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builders/interoperability/xcm/fees.md b/builders/interoperability/xcm/fees.md index 5ac1dcc78..d5854dce1 100644 --- a/builders/interoperability/xcm/fees.md +++ b/builders/interoperability/xcm/fees.md @@ -205,7 +205,7 @@ For all Moonbeam-based networks, the generic XCM instructions are benchmarked, w | Database | Read | Write | |:---------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------:|:------------------------------------------:| -| [RocksDB (default)](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/support/src/weights/rocksdb_weights.rs#L27-L28){target=_blank} | {{ xcm.db_weights.rocksdb_read.display }} | {{ xcm.db_weights.rocksdb_write.display }} | +| [RocksDB (default)](https://github.com/paritytech/polkadot-sdk/blob/{{polkadot_sdk}}/substrate/frame/support/src/weights/rocksdb_weights.rs#L27-L28){target=_blank} | {{ xcm.db_weights.rocksdb_read.display }} | {{ xcm.db_weights.rocksdb_write.display }} | Now that you know the weight costs for database reads and writes for Moonbase Alpha, you can calculate the weight cost for both fungible and generic XCM instruction using the base weight for instruction and the extra database read/writes if applicable. From c71b4017f8deffd4fe686251b665afebd78f8825 Mon Sep 17 00:00:00 2001 From: Erin Shaben Date: Thu, 16 Nov 2023 23:32:31 -0500 Subject: [PATCH 4/4] fix variable --- builders/interoperability/xcm/fees.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builders/interoperability/xcm/fees.md b/builders/interoperability/xcm/fees.md index d5854dce1..a4e426baf 100644 --- a/builders/interoperability/xcm/fees.md +++ b/builders/interoperability/xcm/fees.md @@ -151,7 +151,7 @@ On Kusama, the benchmarked base weights are broken up into two categories: fungi With the instruction weight cost established, you can calculate the cost of the instruction in KSM. -In Kusama, the [`ExtrinsicBaseWeight`](https://github.com/polkadot-fellows/runtimes/blob/{{networks.polkadot.spec_version}}/relay/kusama/constants/src/weights/extrinsic_weights.rs#L56){target=_blank} is set to `{{ networks.kusama.extrinsic_base_weight.display }}` which is [mapped to 1/10th](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/constants/src/lib.rs#L87){target=_blank} of a cent. Where 1 cent is `10^12 / 30,000`. +In Kusama, the [`ExtrinsicBaseWeight`](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/constants/src/weights/extrinsic_weights.rs#L56){target=_blank} is set to `{{ networks.kusama.extrinsic_base_weight.display }}` which is [mapped to 1/10th](https://github.com/polkadot-fellows/runtimes/blob/{{networks.kusama.spec_version}}/relay/kusama/constants/src/lib.rs#L87){target=_blank} of a cent. Where 1 cent is `10^12 / 30,000`. Therefore, to calculate the cost of executing an XCM instruction, you can use the following formula: