Skip to content

Commit 0a5a2df

Browse files
authored
use relaychain asset as fee (#700)
* support relaychain as fee * add weight * clean and comment * clean * use non fee asset as reserve * update * clippy * update weight * too many fee * two xcm and split fee * clean * fix tests * more test * clippy * fmt * remove FeeNotEnough * clean * add parachain min fee setting * more test and some limitation * some notes * fmt * Revert "Polkadot v0.9.17 (#705)" This reverts commit aac79b3. * update comments * Revert "Revert "Polkadot v0.9.17 (#705)"" This reverts commit dba578f. * fix * update README and add FeeNotEnough Error
1 parent aac79b3 commit 0a5a2df

File tree

5 files changed

+476
-78
lines changed

5 files changed

+476
-78
lines changed

xtokens/README.md

+46
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,49 @@ Integration tests could be done manually after integrating orml-xtokens into run
2828
- Sending the tx from parachain A.
2929
- Set the destination as Parachain B.
3030
- Set the currency ID as parachain C token.
31+
32+
33+
#### Transfer multiple currencies
34+
35+
- Transfer relay chain tokens to relay chain, and use relay chain token as fee
36+
- Transfer relay chain tokens to parachain, and use relay chain token as fee
37+
- Transfer tokens issued by parachain A, from parachain A to parachain B, and use parachain A token as fee
38+
- Transfer tokens issued by parachain B, from parachain A to parachain B, and use parachain B token as fee
39+
- Transfer tokens issued by parachain C, from parachain A to parachain B, and use parachain C token as fee
40+
- Transfer tokens issued by parachain B, from parachain A to parachain B, and use relay chain token as fee
41+
42+
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.
43+
44+
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.
45+
46+
the fee amount in fee asset is split into two parts.
47+
1. fee asset sent to fee reserve chain = fee_amount - min_xcm_fee
48+
2. fee asset sent to dest reserve chain = min_xcm_fee
49+
50+
Parachains should implements config `MinXcmFee` in `xtokens` module config:
51+
52+
```rust
53+
parameter_type_with_key! {
54+
pub ParachainMinFee: |location: MultiLocation| -> u128 {
55+
#[allow(clippy::match_ref_pats)] // false positive
56+
match (location.parents, location.first_interior()) {
57+
(1, Some(Parachain(parachains::statemine::ID))) => 4_000_000_000,
58+
_ => u128::MAX,
59+
}
60+
};
61+
}
62+
```
63+
64+
If Parachain don't want have this case, can simply return Max value:
65+
66+
```rust
67+
parameter_type_with_key! {
68+
pub ParachainMinFee: |_location: MultiLocation| -> u128 {
69+
u128::MAX
70+
};
71+
}
72+
```
73+
74+
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.
75+
76+
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.

0 commit comments

Comments
 (0)