Skip to content
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

#xcm polishing #xtokens README.md #856

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions xtokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

## Overview

The xtokens module provides cross-chain token transfer functionality, by cross-consensus messages(XCM).
The `xtokens` module provides cross-chain token transfer functionality, by cross-consensus messages(XCM).

The xtokens module provides functions for
The `xtokens` module provides functions for
- Token transfer from parachains to relay chain.
- Token transfer between parachains, including relay chain tokens like DOT,
KSM, and parachain tokens like ACA, aUSD.
KSM, and parachain tokens like ACA, aUSD, USDT.

## Notes

#### Integration tests

Integration tests could be done manually after integrating orml-xtokens into runtime. To cover the full features, set up at least 4 relay chain validators and 3 collators of different parachains, and use dispatchable calls to include all these scenarios:
Integration tests could be done manually after integrating `xtokens` into a runtime. To cover the full features, set up at least 4 relay chain validators and 3 collators of different parachains, and use dispatchable calls to include all these scenarios:

- Transfer relay chain tokens to relay chain.
- Transfer tokens issued by parachain A, from parachain A to parachain B.
Expand All @@ -34,24 +34,24 @@ Integration tests could be done manually after integrating orml-xtokens into run

- Transfer relay chain tokens to relay chain, and use relay chain token as fee
- Transfer relay chain tokens to parachain, and use relay chain token as fee
- Transfer tokens issued by parachain A, from parachain A to parachain B, and use parachain A token as fee
- Transfer tokens issued by parachain B, from parachain A to parachain B, and use parachain B token as fee
- Transfer tokens issued by parachain C, from parachain A to parachain B, and use parachain C token as fee
- Transfer tokens issued by parachain A, from parachain A to parachain B, and use parachain A token as a fee
- Transfer tokens issued by parachain B, from parachain A to parachain B, and use parachain B token as a fee
- Transfer tokens issued by parachain C, from parachain A to parachain B, and use parachain C token as a fee
- Transfer tokens issued by parachain B, from parachain A to parachain B, and use relay chain token as fee

Notice, in the case of parachain A transfer parachain B token to parachain B, and use relay chain token as fee. Because fee asset is relaychain token, and non fee asset is parachain B token, this is two different chain. We call chain of fee asset as fee_reserve, and chain of non fee asset as non_fee_reserve. And in this case fee_reserve location is also refer to destination parachain.
Notice, in the case of parachain A transfer parachain B token to parachain B, and use relay chain token as fee. Because fee asset is relaychain token, and non fee asset is parachain B token, this is two different chain. We call chain of fee asset as `fee_reserve`, and chain of non fee asset as `non_fee_reserve`. And in this case `fee_reserve` location is also refer to destination parachain.

The current implementation is sent two xcm from sender parachain. first xcm sent to fee reserve chain which will also route xcm message to destination parachain. second xcm directly sent to destination parachain.
The current implementation sends two XCM from a sender parachain. First XCM is sent to the fee reserve chain which will also route the XCM message to the destination parachain. Second XCM directly sent to destination parachain.

the fee amount in fee asset is split into two parts.
1. fee asset sent to fee reserve chain = fee_amount - min_xcm_fee
2. fee asset sent to dest reserve chain = min_xcm_fee
The fee amount in fee asset is split into two parts:
1. Fee asset sent to fee reserve chain = fee_amount - min_xcm_fee
2. Fee asset sent to dest reserve chain = min_xcm_fee

Parachains should implements config `MinXcmFee` in `xtokens` module config:
Parachains should implement config `MinXcmFee` in `xtokens` module config:

```rust
parameter_type_with_key! {
pub ParachainMinFee: |location: MultiLocation| -> Option<u128> {
pub MinXcmReserveFee: |location: MultiLocation| -> Option<u128> {
#[allow(clippy::match_ref_pats)] // false positive
match (location.parents, location.first_interior()) {
(1, Some(Parachain(parachains::statemine::ID))) => Some(4_000_000_000),
Expand All @@ -71,6 +71,6 @@ parameter_type_with_key! {
}
```

Notice the implementation for now also relies on `SelfLocation` which is already in `xtokens` config. The `SelfLocation` is currently set to absolute view `(1, Parachain(id))` and refers to the sender parachain. However `SelfLocation` set to relative view `(0, Here)` will also work.
Notice the implementation for now also relies on `SelfLocation` which is already in `xtokens` config. The `SelfLocation` can be set to the absolute view `(1, Parachain(THIS_PARACHAIN_ID))` and refers to the sender parachain. The alternative is to set `SelfLocation` to relative view `(0, Here)` to adhere to Polkadot guidelines.

We use `SelfLocation` to fund fee to sender's parachain sovereign account on destination parachain, which asset is originated from sender account on sender parachain. This means if user setup too much fee, the fee will not returned to user, instead deposit to sibling parachain sovereign account on destination parachain.
We use `SelfLocation` to fund fee to sender's parachain sovereign account on destination parachain, which asset is originated from sender account on sender parachain. This means if user setup too much fee, the fee will not returned to user, instead deposit to sibling parachain sovereign account on destination parachain.