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

use relaychain asset as fee #700

merged 27 commits into from
Mar 3, 2022

Conversation

zqhxuyuan
Copy link
Contributor

@zqhxuyuan zqhxuyuan commented Feb 22, 2022

checkout context infomation on: #698

for not breaking current semantic(don't allow different reserve), I use another disptach call instead mixed in do_transfer_multiassets. (i.e. may be need another paramether allow_different_reserve to implemented.)

the transfer_using_relaychain_as_fee only used for parachain(A) send token to sibling parachain(B), and use relaychain token(R) as fee. thus, the reserve location is decided by sibling asset instead of fee asset.

Edit:
for the case of transfer custom asset(RMRK) from Karura to Statemine, we current use two xcm implementation:

  • first one send to relaychain and route to Statemine(Karura-[KSM]-Statemine NonReserve case), transfer user's fee to parachain_2000 sovereign account on Statemine.
  • second one direct send to Statemine(Karura-[KSM,RMRK]-Statemine, ToReserve case)

we also has the case of transfer RMRK from Karura to Bifrost. this case also need use KSM as fee too.

acala statemine tests: AcalaNetwork/Acala#1712

@zqhxuyuan zqhxuyuan marked this pull request as ready for review February 22, 2022 05:31
@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2022

Codecov Report

Merging #700 (cadcc9f) into master (aac79b3) will increase coverage by 0.40%.
The diff coverage is 83.40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #700      +/-   ##
==========================================
+ Coverage   74.99%   75.39%   +0.40%     
==========================================
  Files          83       83              
  Lines        7266     7438     +172     
==========================================
+ Hits         5449     5608     +159     
- Misses       1817     1830      +13     
Impacted Files Coverage Δ
xtokens/src/mock/mod.rs 89.28% <50.00%> (-3.03%) ⬇️
xtokens/src/lib.rs 63.93% <62.76%> (+2.60%) ⬆️
xtokens/src/mock/para.rs 75.75% <100.00%> (+2.42%) ⬆️
xtokens/src/tests.rs 99.35% <100.00%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aac79b3...cadcc9f. Read the comment docs.

Copy link
Member

@shaunxw shaunxw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to update transfer_with_fee impl instead of adding a new dispatchable call.

The new transfer_using_relaychain_as_fee is basically the same with do_transfer_multiassets, but it doesn't require fee and other assets share the same reserve, plus it use non-fee assets as reserve.

Updating do_transfer_multiassets and make it

  1. Only ensure non-fee assets share the same reserve location.
  2. Refer to non-fee assets for reserve location.

should work. As it only extends use cases of it with less limitations, it's not a breaking change for transfer_with_fee.

xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/mock/para.rs Outdated Show resolved Hide resolved
@zqhxuyuan
Copy link
Contributor Author

Only ensure non-fee assets share the same reserve location.
Refer to non-fee assets for reserve location.

That make sense, but I think change transfer_with_fee will break existing case, i.e.

ParaA::execute_with(|| {
assert_ok!(ParaXTokens::transfer_with_fee(
Some(ALICE).into(),
CurrencyId::B,
450,
50,

transfer_with_fee only support one asset and use that asset as fee. If we want to use relaychain asset as fee and transfer another asset, I think we need to change transfer_multiasset_with_fee or transfer_multicurrencies or transfer_multiassets.

@shaunxw
Copy link
Member

shaunxw commented Feb 23, 2022

That make sense, but I think change transfer_with_fee will break existing case, i.e.

My bad, I mean the new updated impl which can specify fee asset type. Updating do_transfer_multiassets impl should work and won't break any existing call.

Copy link
Member

@shaunxw shaunxw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DistinctReserveForAssetAndFee error variant should be removed, as there is not such limitation any more.

xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
@zqhxuyuan
Copy link
Contributor Author

I think DistinctReserveForAssetAndFee still needed, because there maybe case like [R,A,A1] which is valid, but [R,A,B] is invalid.

xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
@zqhxuyuan zqhxuyuan changed the title Different fee reserve use relaychain asset as fee to transfer asset back to Statemine Feb 28, 2022
@zqhxuyuan zqhxuyuan changed the title use relaychain asset as fee to transfer asset back to Statemine use relaychain asset as fee Mar 1, 2022
// destination chain, which asset is originated from sender account on sender
// chain. This means if user setup too much fee, the fee is not returned to
// user, instead deposit to sibling parachain sovereign account on dest chain.
// Notice: if parachain set `SelfLocation` to (0, Here), it'll be error!
Copy link
Member

@shaunxw shaunxw Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented in SelfLocation definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to README

Comment on lines 546 to 552
// Current not ensure xcm order delivery. if second xcm is executed before first
// xcm, then second xcm may failed because of sibling parachain account don't
// have enough fee to withdraw. we can pre-fund some amount to sibling parachain
// sovereign account to fix this issue. when first xcm executed later on, the
// sibling sovereign parachain account is deposit. and next transaction will
// succeed even though second xcm is executed before first xcm if user fee is
// less than parachain sovereign account balance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispatchable calls docstring or pallet readme should include these usage notes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to README

xtokens/src/lib.rs Show resolved Hide resolved
xtokens/src/lib.rs Outdated Show resolved Hide resolved
}

/// Send xcm with given assets and fee to dest or reserve chain.
fn send_xcm(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a better naming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to execute_and_send_reserve_kind_xcm

xtokens/src/lib.rs Outdated Show resolved Hide resolved
@@ -813,3 +920,18 @@ fn half(asset: &MultiAsset) -> MultiAsset {
id: asset.id.clone(),
}
}

fn subtract_fee(asset: &MultiAsset, amount: u128) -> MultiAsset {
let final_amount = fungible_amount(asset).checked_sub(amount).expect("fee too low; qed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no fee_amount >= min_xcm_fee check. This could panic no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we checked before subtract, so it's ok here I think

// min xcm fee should less than user fee
let fee_to_dest: MultiAsset = (fee.id.clone(), min_xcm_fee).into();
ensure!(fee_to_dest < fee, Error::<T>::InvalidAsset);

@shaunxw shaunxw merged commit 0a5a2df into master Mar 3, 2022
@shaunxw shaunxw deleted the different_fee_reserve branch March 3, 2022 09:01
syan095 pushed a commit that referenced this pull request Mar 8, 2022
* origin/master:
  use relaychain asset as fee (#700)
  Polkadot v0.9.17 (#705)
  XTokens refactor (#706)
  Add a test for cliff vesting (#702)
  Girazoki fix index in transfer multicurrencies (#696)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants