Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

DeFI / XCM Use of XCM ExchangeAsset #47

Open
hbulgarini opened this issue Aug 24, 2022 · 3 comments
Open

DeFI / XCM Use of XCM ExchangeAsset #47

hbulgarini opened this issue Aug 24, 2022 · 3 comments
Assignees

Comments

@hbulgarini
Copy link
Contributor

There is a new instruction in XCM v3 called ExchangeAsset which permits to exchange assets. This use case will be based on the integration of the swap functionality defined in the substrate-dex and this new instruction.

Very high level, the idea is to execute this XCM instruction and configure the AssetExchange type in a way that the substrate-dex pallet is performs the swap, and if successful, the ExchangeAsset makes the swap on the holding register.

As this is a new XCM instruction we need to some time to understanding it and the use case goal might be modified according to the learnt experience.

Contextual information here: #42 (comment)

@Wiezzel
Copy link
Contributor

Wiezzel commented Aug 29, 2022

I've read the specification of ExchangeAsset instruction and I'm not sure how could we implement the Holding register. Exchange functionality offered by pallet-dex operates on accounts, while the mentioned register is described as a kind of temporary, non-persistent asset storage. We need to figure this out first.

@hbulgarini hbulgarini changed the title DeFI / XCM use case no.2 - Use of XCMExchangeAsset DeFI / XCM Use of XCMExchangeAsset Aug 31, 2022
@hbulgarini hbulgarini changed the title DeFI / XCM Use of XCMExchangeAsset DeFI / XCM Use of XCM ExchangeAsset Aug 31, 2022
@hbulgarini
Copy link
Contributor Author

Still there is some some more investigation required until we confirm the XCM ExchangeAsset works in the way as we expect.

@hbulgarini hbulgarini self-assigned this Sep 12, 2022
@bernardoaraujor
Copy link
Contributor

I have written an implementation for the AssetExchange trait. It's on the bar/xcm-exchange-asset branch of substrate-dex.

The implementation is quite simplistic, with many naive assumptions.

  • Only one asset pair is supported per swap. While that is not necessarily a restriction on the ExchangeAsset instruction, I did impose it to simplify my code.
  • The parsing of give/want as currency/asset is rather dirty. There's probably a more elegant way to do it.
  • A correct implementation would require coupling with pallet-asset-registry. I didn't have time to do it, so I wrote a static conversion with AssetId = 100. That is actually pretty dirty and I'm not proud of it 🙈.

bar/xcm-v3-multiple-runtimes-asset-exchange branch has trappist enabled with this implementation, along with an integration test that does a reserve-transfer of xUSD from Base to Trappist and swaps 50% for HOP before depositing into Bob's account.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants