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

Xtokens Polkadot 1.5 XCM with Different Reserves #973

Open
albertov19 opened this issue Jan 9, 2024 · 12 comments
Open

Xtokens Polkadot 1.5 XCM with Different Reserves #973

albertov19 opened this issue Jan 9, 2024 · 12 comments

Comments

@albertov19
Copy link

As part of paritytech/polkadot-sdk@e7651cf - pallet XCM now allows to send reserve and non-reserve assets in a single XCM message.

Nevertheless, Xtokens requires that both the asset and feeAsset should come from the same reserve - https://github.com/open-web3-stack/open-runtime-module-library/blob/master/xtokens/src/lib.rs#L549-L554

It would be great if Xtokens supports the scenario that is supported now by pallet-xcm

@xlc
Copy link
Member

xlc commented Jan 16, 2024

Yeah we can add this

@xlc
Copy link
Member

xlc commented Mar 4, 2024

Actually, can you elaborate a bit more about this issue? In what case that pallet-xcm is supported but xtokens is not?

https://github.com/paritytech/polkadot-sdk/blob/5c79ed37dc6485d2b3f4fc69b8cf8456b86b4e17/polkadot/xcm/pallet-xcm/src/lib.rs#L1479-L1481 it looks to me also doesn't support sending assets with different reserve in a single call.

@albertov19
Copy link
Author

Hey @xlc - The PR I referenced in the initial comment adds the new transfer_asset function that, from what I understand, supports transferring assets from different reserves.

@Agusrodri tried this already on an internal network, and it worked.

This is the function: https://github.com/paritytech/polkadot-sdk/blob/5c79ed37dc6485d2b3f4fc69b8cf8456b86b4e17/polkadot/xcm/pallet-xcm/src/lib.rs#L1287

@xlc
Copy link
Member

xlc commented Mar 8, 2024

I can't find the code in asset_transfer that does the magic. Could you provide an example of the usage in your internal network? What kinds of assets are been transferred?

@Agusrodri
Copy link
Contributor

Hey @xlc! Here is a test that checks the following scenario:

  • Send two tokens (ParaAToken and ParaBToken) from an account on para A to an account on para B (A -> B).
  • Chain A is the reserve for ParaAToken.
  • Chain B is the reserve for ParaBToken.

The new extrinsic transfer_assets allows to actually combine fee assets and non-fee assets in several ways. This use case is just one of them.

In this case, the asset used to pay fees is ParaAToken, and the process of actually "sending" this asset is done by depositing the remaining amount in the destination account after paying for fees with it, so you end up having both ParaAToken and ParaBToken in the destination account.

Of course, for this use case to work, both chains have to support each corresponding foreign asset.

@xlc
Copy link
Member

xlc commented Mar 11, 2024

Thanks for the example. I have identified a few improvements that we need to do to support such use case:

  • Improve fee asset handling for multi-hop transfer. Currently we use MinXcmFee to calculate the dest fee and assume the rest are the fee for the intermediary transfer. We should make it in such way that it to queries the intermediary fee instead and then deposit the rest to dest so we can actually perform transfer of the fee asset.
  • Use the new trait config in XcmExecutor to detect asset type if is teleport or reserve transfer
  • Identify the case that we only need a single xcm transfer instead of two

@xlc
Copy link
Member

xlc commented Mar 27, 2024

A quick update. I started the refactor work to improve xtokens based on the asset_transfer implementation. However, recently there are also few more issues and improvements have been raised about the asset_transfer. So I will wait a bit and see how it goes.

Also the complexity of this is kinda getting out of control and that means something is wrong. Not sure if there is anything we can do though.

@xlc
Copy link
Member

xlc commented Apr 12, 2024

With all the additional complicated requirements, I am considering maybe we should just deprecate xtokens and use pallet-xcm instead. xtokens is built because there was no pallet offers such functionality. Now that pallet-xcm should support all the transfer needs, I don't feel the needs to support an alternative implementation.

@albertov19
Copy link
Author

I agree. I think Moonbeam is moving away from Xtokens in favor of Pallet XCM.

@IkerAlus
Copy link

@albertov19 @xlc is there any update around this?

Note that the incoming 1.2.4 release will implement a new interface from pallet XCM which will allow all the scenarios mentioned above plus many more complex cases.

@albertov19
Copy link
Author

@IkerAlus We are slowly transitioning to PalletXCM, but there is no hard deadline and this will be a slow process as there are many teams still using our Xtokens precompile

@xlc
Copy link
Member

xlc commented May 22, 2024

I think it is best to keep xtokens as it is for compatibility reason and for new use cases, use new features from the pallet-xcm

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

No branches or pull requests

4 participants