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

Configure and test whitelisted XCM reserve transfers #661

Merged
merged 62 commits into from
Nov 25, 2022

Conversation

sea212
Copy link
Member

@sea212 sea212 commented Jun 4, 2022

This PR adjusts the XCM configuration to only allow the necessary XCM instruction necessary to execute a reserve transfer. Asset teleports are disabled (needs trust).

By default no foreign assets are registered. The AssetRegistry pallet is used to register foreign asset, which are identified by CurrencyId::ForeignAsset(id). The AssetRegistry holds all necessary information about an asset, such as the location, existential deposit, name and the number of decimal fractional places. It also contains some custom metadata, which specifies if the asset can be used in a pool and how fees should be determined. Assets can only be added through governance.
Whenever a foreign asset is received, the XCM implementation checks if it convert it to a local CurrencyId representation. It either maps the Zeitgeist parachain multilocation to CurrencyId::Ztg, or queries the asset registry for that multilocation. In case the conversion succeeds, balance updates will happen accordingly. If the multilocation cannot be resolved, the UnknownTokens pallet will be used to store those transferred tokens. XCM currently uses unidirectional channels and there is no response that lets the sender know if the operation succeeded. When another chain has an open channel to Zeitgeist and sends the XCM to reserve transfer some asset, the sending chain already locally updated the token balances to match the transfer. However, at that point in time it does not know if it will succeed in the destination chain. To avoid Zeitgeist receiving reserve asset transfers and just dropping them because the instructions cannot be handled (token conversion failed), the UnknownTokens pallet keeps track of those unknown tokens.
The fee for XCM transfers is calculated based on a formula that is used across all projects. The fees are always taken from the token that is received, such as KSM. Using the AssetRegistry custom metadata, one can specify a multiplier that is used to adjust fees. For example, if 1 KSM is 10x the worth of 1 ZTG, a 10x multiplier must be specified. Those multiplier can be updated through governance. All the fees are put into the treasury for now.
A Barrier does specify whether XCM instructions should be executed. Such a barrier could include the constraint that execution time must be paid using the BuyExecution XCM instruction. The barriers in place in this PR are restrictive default barriers used by most projects.
Reserve Asset Transfers can be executed by calling the dispatchable transfer from the newly added xTokens pallet. It will ensure the XCM message is crafted properly and send it to the destination chain.

The PR adds integration tests that simulate a relay chain and multiple parachains to verify that only the XCM instructions of interest can be executed and that only the whitelisted chains and assets can be transferred. It tests that transfers to and from another parachain and transfer to and from the parent chains works. It checks that fees are correctly calculated and deducted, that all account balances are updated accordingly, that the sovereign account balances are updated accordingly and that the fees are properly put into the treasury. It also tests that custom fees from the AssetRegistry calculated properly.

@sea212 sea212 added the s:in-progress The pull requests is currently being worked on label Jun 4, 2022
@sea212 sea212 added this to the v0.3.4 milestone Jun 4, 2022
@sea212 sea212 self-assigned this Jun 4, 2022
@sea212 sea212 changed the title Reorganize XCM configuration Whitelist, test and configure aUSD XCM reserve transfers Jun 4, 2022
@sea212 sea212 changed the title Whitelist, test and configure aUSD XCM reserve transfers Configure and test whitelisted XCM reserve transfers Jun 6, 2022
- Add TokenInfo macro and implementation for Asset type
- Add fee per second functions for all supported currencies
- Use uppercase names for currencies in Asset enum
@sea212 sea212 modified the milestones: v0.3.5, v0.3.4, v0.3.6 Jul 8, 2022
@sea212 sea212 added s:on-hold Work on the pull request has been paused and removed s:in-progress The pull requests is currently being worked on labels Jul 26, 2022
@sea212 sea212 added s:in-progress The pull requests is currently being worked on and removed s:on-hold Work on the pull request has been paused labels Aug 17, 2022
@sea212 sea212 removed this from the v0.3.6 milestone Sep 27, 2022
@sea212 sea212 added the i:spec-changed ⚠️ Implies change in spec version label Nov 23, 2022
Copy link
Member

@Chralt98 Chralt98 left a comment

Choose a reason for hiding this comment

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

Just a couple more comments.

sea212 and others added 2 commits November 23, 2022 12:18
@Chralt98
Copy link
Member

Just waiting for #850..

@sea212 sea212 added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Nov 24, 2022
Copy link
Member

@Chralt98 Chralt98 left a comment

Choose a reason for hiding this comment

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

Ok, let's try that! Happy inter-chain talk.

@vivekvpandya vivekvpandya added s:accepted This pull request is ready for merge and removed s:review-needed The pull request requires reviews labels Nov 25, 2022
@sea212 sea212 merged commit 380f577 into main Nov 25, 2022
@sea212 sea212 deleted the sea212-integrate-aUSD branch November 25, 2022 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i:spec-changed ⚠️ Implies change in spec version s:accepted This pull request is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants