## Motivation
`pallet-xcm` is the main user-facing interface for XCM functionality,
including assets manipulation functions like `teleportAssets()` and
`reserve_transfer_assets()` calls.
While `teleportAsset()` works both ways, `reserve_transfer_assets()`
works only for sending reserve-based assets to a remote destination and
beneficiary when the reserve is the _local chain_.
## Solution
This PR enhances `pallet_xcm::(limited_)reserve_withdraw_assets` to
support transfers when reserves are other chains.
This will allow complete, **bi-directional** reserve-based asset
transfers user stories using `pallet-xcm`.
Enables following scenarios:
- transferring assets with local reserve (was previously supported iff
asset used as fee also had local reserve - now it works in all cases),
- transferring assets with reserve on destination,
- transferring assets with reserve on remote/third-party chain (iff
assets and fees have same remote reserve),
- transferring assets with reserve different than the reserve of the
asset to be used as fees - meaning can be used to transfer random asset
with local/dest reserve while using DOT for fees on all involved chains,
even if DOT local/dest reserve doesn't match asset reserve,
- transferring assets with any type of local/dest reserve while using
fees which can be teleported between involved chains.
All of the above is done by pallet inner logic without the user having
to specify which scenario/reserves/teleports/etc. The correct scenario
and corresponding XCM programs are identified, and respectively, built
automatically based on runtime configuration of trusted teleporters and
trusted reserves.
#### Current limitations:
- while `fees` and "non-fee" `assets` CAN have different reserves (or
fees CAN be teleported), the remaining "non-fee" `assets` CANNOT, among
themselves, have different reserve locations (this is also implicitly
enforced by `MAX_ASSETS_FOR_TRANSFER=2`, but this can be safely
increased in the future).
- `fees` and "non-fee" `assets` CANNOT have **different remote**
reserves (this could also be supported in the future, but adds even more
complexity while possibly not being worth it - we'll see what the future
holds).
Fixes https://github.com/paritytech/polkadot-sdk/issues/1584
Fixes https://github.com/paritytech/polkadot-sdk/issues/2055
---------
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
closes https://github.com/paritytech/polkadot-sdk/issues/1882
## Breaking Changes
This PR introduces a new item to `pallet_balances::Config`:
```diff
trait Config {
++ type RuntimeFreezeReasons;
}
```
This value is only used to check it against `type MaxFreeze`. A similar
check has been added for `MaxHolds` against `RuntimeHoldReasons`, which
is already given to `pallet_balances`.
In all contexts, you should pass the real `RuntimeFreezeReasons`
generated by `construct_runtime` to `type RuntimeFreezeReasons`. Passing
`()` would also work, but it would imply that the runtime uses no
freezes at all.
---------
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Combination of paritytech/polkadot#7005, its addon PR
paritytech/polkadot#7585 and its companion paritytech/cumulus#2433.
This PR introduces a new XcmFeesToAccount struct which implements the
`FeeManager` trait, and assigns this struct as the `FeeManager` in the
XCM config for all runtimes.
The struct simply deposits all fees handled by the XCM executor to a
specified account. In all runtimes, the specified account is configured
as the treasury account.
XCM __delivery__ fees are now being introduced (unless the root origin
is sending a message to a system parachain on behalf of the originating
chain).
# Note for reviewers
Most file changes are tests that had to be modified to account for the
new fees.
Main changes are in:
- cumulus/pallets/xcmp-queue/src/lib.rs <- To make it track the delivery
fees exponential factor
- polkadot/xcm/xcm-builder/src/fee_handling.rs <- Added. Has the
FeeManager implementation
- All runtime xcm_config files <- To add the FeeManager to the XCM
configuration
# Important note
After this change, instructions that create and send a new XCM (Query*,
Report*, ExportMessage, InitiateReserveWithdraw, InitiateTeleport,
DepositReserveAsset, TransferReserveAsset, LockAsset and RequestUnlock)
will require the corresponding origin account in the origin register to
pay for transport delivery fees, and the onward message will fail to be
sent if the origin account does not have the required amount. This
delivery fee is on top of what we already collect as tx fees in
pallet-xcm and XCM BuyExecution fees!
Wallet UIs that want to expose the new delivery fee can do so using the
formula:
```
delivery_fee_factor * (base_fee + encoded_msg_len * per_byte_fee)
```
where the delivery fee factor can be obtained from the corresponding
pallet based on which transport you are using (UMP, HRMP or bridges),
the base fee is a constant, the encoded message length from the message
itself and the per byte fee is the same as the configured per byte fee
for txs (i.e. `TransactionByteFee`).
---------
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
* Rename `polkadot-parachain` to `polkadot-parachain-primitives`
While doing this it also fixes some last `rustdoc` issues and fixes
another Cargo warning related to `pallet-paged-list`.
* Fix compilation
* ".git/.scripts/commands/fmt/fmt.sh"
* Fix XCM docs
---------
Co-authored-by: command-bot <>
* Rename squatted crates
This commit adds the staging- prefix to squatted crates so we can go forward and publish them to crates.io.
Using the staging- prefix is a temp fix until we decide on replacement names.
https://forum.parity.io/t/renaming-squated-crates-in-substrate-polkadot-cumulus/1964/6
* Fix test after crate renames
* Update Lockfile
* Tools for unique topic references
* Formatting
* Naming
* Repot into routing.rs.
* More things done
* Universal Exporter supports topic-as-reference
* Some tests for the topic routing
* More tests
* Paid bridge tests
* Add message ID to sending events
* Formatting
* fix and integrate into test nets
* Move DenyThenTry and friend from Cumulus
* Append SetTopic rather than prepend
* Docs
* Docs
* Work with new ProcessMessage ID API
* Formatting
* Fix build
* Fixes
* Formatting
* Update xcm/xcm-builder/src/barriers.rs
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
* Update xcm/xcm-builder/src/routing.rs
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
* Docs
* Rename message_hash
* Formatting
* ".git/.scripts/commands/fmt/fmt.sh"
* Rename
* Another Rename
* ".git/.scripts/commands/fmt/fmt.sh"
* ".git/.scripts/commands/fmt/fmt.sh"
* Update xcm/xcm-builder/src/routing.rs
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
---------
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* Happy New Year!
* Remove year entierly
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* Remove years from copyright notice in the entire repo
---------
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* Ensure for a configurable origin in XCM (#6442), cherry picked from
5ae05e1a957857c449a43d8759a21292d03fd049
Add new associated type, AdminOrigin, bounded by EnsureOrigin trait in
XCM pallet. Replace ensure_root() with ensure_origin() from a
EnsureOrigin trait. Set AdminOrigin as EnsureRoot<AccountId> in xcm
configs.
* cargo fmt
* small stylistic change
---------
Co-authored-by: serkul <serkul@pop-os.localdomain>
* Some renames
* Fix
* Fix build for new APIs
* Remove diener
* Fixes
* Fixes
* Fix integration tests
* Fixes
* fix nis issuance
* Update Cargo.toml
* Polkadot doesn't have freezes/holds yet
* No networks use freezes/holds
* update lockfile for {"substrate"}
* Fix tests
There are more failing tests; just starting with the easy ones.
Reserved balance does not count towards ED anymore, therefore reducing
all the reserves by ED (1).
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* Fixes for Polkadot pallets
* Fix parachains benchmarks
* Update Substrate
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
---------
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* Use into_account_truncating
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* more truncating
* more truncating
* more
* clean up parachain primitives
* more truncating
* update lockfile for {"substrate"}
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: parity-processbot <>
* Implement transfer_asset on CurrencyAdapter
* Use Currency::transfer in transfer_asset
* Add a test to assert that Currency::transfer was indeed used
* Remove superfluous balance conversion to u128
* Rename transfer_asset and beam_asset
Co-authored-by: Giles Cope <gilescope@gmail.com>
* Change send_xcm MultiLocation argument to be generic
* Change pallet_xcm::send_xcm MultiLocation and Junctions argument to be generic
* Change convert_origin MultiLocation argument to be generic
* Change OnResponse MultiLocation arguments to be generic
* Change UniversalWeigher MultiLocation argumente to be generic
* Change ExecuteXcm MultiLocation argument to be generic
* Remove usages of into for the MultiLocation argument in execute_xcm
* Make use of generic MultiLocation arguments in rustdocs
* Cargo fmt
* Remove unused import in tests
* Resolve conflicts
* cargo fmt
* Appease spellcheck
* impl Into<MultiLocation> in more places
* add integration tests to xcm-builder
* add an integration test for reserve_transfer_assets
* add query holding and teleport tests
* formatting
* add to barrier doc comments and fix doc tests warnings
* use more realistic barrier for integration tests
* improve imports
* adjust base xcm weight and existential deposit to be in line with Kusama
* remove AnyNetwork
Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
* add more comments and remove unnecessary code
* move mock into separate file
* reduce imports
* update cargo.lock
* remove reserve transfer test from xcm builder integration tests
* reword barrier doc comment
* elaborate on QueryHolding test scenario
* add an integration test for reserve based transfers from parachain to parachain
* add teleport tests
* fix failing teleport filter tests
* Update xcm/xcm-builder/src/integration_tests.rs
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
* Update xcm/xcm-builder/src/integration_tests.rs
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
* Update xcm/xcm-builder/src/integration_tests.rs
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
* Move integration tests to tests/ directory
* Fix merge
* Replace All wildcard with a concrete seed amount
* Rename SEED_AMOUNT to REGISTER_AMOUNT
* Fix compilation error
* Check for teleport destination first before checking out assets
* Fix unit test
* Do not run tests in integration mock
* Add a permissive assets filter for teleportation
* Remove check for teleport location in InitiateTeleport XCM
* Remove defunct test
* Apply suggestions from code review
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
* Reword comment
Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>