Skip to content

use relaychain asset as fee#700

Merged
shaunxw merged 27 commits into
masterfrom
different_fee_reserve
Mar 3, 2022
Merged

use relaychain asset as fee#700
shaunxw merged 27 commits into
masterfrom
different_fee_reserve

Conversation

@zqhxuyuan
Copy link
Copy Markdown
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 requested review from shaunxw and xlc February 22, 2022 05:16
@zqhxuyuan zqhxuyuan marked this pull request as ready for review February 22, 2022 05:31
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 22, 2022

Codecov Report

❌ Patch coverage is 83.40807% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.39%. Comparing base (aac79b3) to head (cadcc9f).
⚠️ Report is 219 commits behind head on master.

Files with missing lines Patch % Lines
xtokens/src/lib.rs 62.76% 35 Missing ⚠️
xtokens/src/mock/mod.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
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.

Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/mock/para.rs Outdated
@zqhxuyuan
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
@zqhxuyuan
Copy link
Copy Markdown
Contributor Author

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

Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
@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
Comment thread xtokens/src/lib.rs
Comment thread xtokens/src/lib.rs Outdated
// 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
Copy Markdown
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
Copy Markdown
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 thread xtokens/src/lib.rs Outdated
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
Copy Markdown
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
Copy Markdown
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 thread xtokens/src/lib.rs
Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs Outdated
}

/// Send xcm with given assets and fee to dest or reserve chain.
fn send_xcm(
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread xtokens/src/lib.rs Outdated
Comment thread xtokens/src/lib.rs
}

fn subtract_fee(asset: &MultiAsset, amount: u128) -> MultiAsset {
let final_amount = fungible_amount(asset).checked_sub(amount).expect("fee too low; qed");
Copy link
Copy Markdown
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
Copy Markdown
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.

4 participants