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

use relaychain asset as fee #700

Merged
merged 27 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions xtokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,49 @@ Integration tests could be done manually after integrating orml-xtokens into run
- Sending the tx from parachain A.
- Set the destination as Parachain B.
- Set the currency ID as parachain C token.


#### Transfer multiple currencies

- 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 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.

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 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:

```rust
parameter_type_with_key! {
pub ParachainMinFee: |location: MultiLocation| -> u128 {
#[allow(clippy::match_ref_pats)] // false positive
match (location.parents, location.first_interior()) {
(1, Some(Parachain(parachains::statemine::ID))) => 4_000_000_000,
_ => u128::MAX,
}
};
}
```

If Parachain don't want have this case, can simply return Max value:

```rust
parameter_type_with_key! {
pub ParachainMinFee: |_location: MultiLocation| -> u128 {
u128::MAX
};
}
```

Notice the implementation for now also rely on `SelfLocation` which already in `xtokens` config. The `SelfLocation` current is `(1, Parachain(id))` refer to sender parachain. If parachain set `SelfLocation` to (0, Here), it'll be error in this case.

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.
Loading