-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Assets] Implement pallet-assets-holder
#4530
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
Merged
Merged
Changes from all commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
a0f5015
change(pallet-assets): define HeldBalance
pandres95 6d2aa57
change(pallet-assets): implement `Holder` to calculate reducible bala…
pandres95 029e887
change: add Holder type to missing pallet_assets Config implementations
pandres95 bf376a5
change(pallet-assets): call died hook for Holder whenever necessary
pandres95 fe951fa
Merge branch 'master' into pallet-assets-holder
pandres95 89ea43a
fix(pallet-asset-conversion-ops): missing Holder in mock config
pandres95 2ab3535
change(pallet-assets): adjust reducible/can_decrease to be in line wi…
pandres95 9d326b8
Merge branch 'master' into pallet-assets-holder
pandres95 c76b654
change(pallet-assets): introduce tests to check for holds and freezes…
pandres95 c5690e1
Merge branch 'master' into pallet-assets-holder
pandres95 a4bb10c
change(pallet-assets-freezer): adjust mock and tests to changes in `p…
pandres95 32fa5c1
feat(pallet-assets-holder): pallet implementation
pandres95 fe0a5e5
Merge branch 'master' into pallet-assets-holder
pandres95 b93337e
fix: fmt / cargo fmt
pandres95 4e0ced7
chore: umbrella
pandres95 c5b103a
chore: pr doc
pandres95 9cdb256
Merge branch 'master' into pallet-assets-holder
pandres95 f36b540
fix(staging-xcm-builder): missing references to `Holder`
pandres95 5829558
change(pallet-assets): set `Holder` and `Freezer` to have default val…
pandres95 17ce1d9
change(pallet-assets-holder): apply @gui1117's suggestion of tightly …
pandres95 f2a9e96
change(pallet-assets): account for `held_balance` when calculating `t…
pandres95 fc41634
change(pallet-assets-holder): test preservation of `total_balance`.
pandres95 9e9edfb
change(pallet-assets-holder): resolve `VARIANT_COUNT` to match number…
pandres95 e7155eb
change(pallet-assets-holder): remove assertion in test that fails aft…
pandres95 4268b76
change(pallet-assets-holder): implement changes suggested by @gui1117
pandres95 818e590
change(pallet-assets-holder): apply change from HeldBalance to Balanc…
pandres95 06db701
minor(pallet-assets-holder): small adjustments
pandres95 be7576e
Merge branch 'master' into pallet-assets-holder
pandres95 0a0487e
Merge branch 'pallet-assets-holder' of https://github.com/pandres95/p…
pandres95 7dff111
fix(pallet-revive-mock-network): include Holder on pallet_assets conf…
pandres95 5d04950
change(prdoc): update prdoc with all impacted crates
pandres95 44e8f62
change(pallet-assets-holder): add additional assertions to `try_state…
pandres95 bb1a98d
minor(pallet-assets-holder): rename _held_ references in comments wit…
pandres95 aab6498
Merge branch 'master' into pallet-assets-holder
pandres95 3688f89
change(pallet-assets-holder): address changes requested by @muharem
pandres95 900dbaa
change(pallet-assets-holder): impls -> impl_fungibles
pandres95 b689e2e
fix(pallet-assets-holder): missing `CheckedAdd` import
pandres95 2f14b32
change(pallet-assets-holder): make `died` burn balance on hold (if any).
pandres95 548eee1
Merge branch 'master' into pallet-assets-holder
pandres95 5d7d874
change(pallet-assets-holder): fast exit for `set_balance_on_hold`.
pandres95 427a29b
fix(penpal-runtime): missing `Holder` in `PoolAssets` config
pandres95 7c28175
Merge branch 'master' into pallet-assets-holder
pandres95 9ccc35c
fix(pallet-assets-holder): lint
pandres95 c65a4c2
change(pallet-assets-holder): revert `died` to make it an infallible …
pandres95 174b3d5
Merge branch 'master' into pallet-assets-holder
pandres95 f1c0983
change(pallet-assets): remark the change of parameters in the `freeze…
pandres95 ae2f67a
Merge branch 'master' into pallet-assets-holder
pandres95 92769f1
change(pallet-assets): implement contains_holds / contains_freezes
pandres95 a02904d
Merge branch 'master' into pallet-assets-holder
pandres95 b559bda
Merge branch 'master' into pallet-assets-holder
pandres95 0e848ac
fix(pallet-assets-freezer): missing import
pandres95 3bd7241
change(pallet-assets): disallow `refund`/`refund_other` for an accoun…
pandres95 4e25e73
Merge branch 'master' into pallet-assets-holder
pandres95 3233d48
fix(umbrella): revert unintended misformatting of Cargo.toml
pandres95 a80e6e3
fix(Cargo): revert unintended regression in Cargo lockfile
pandres95 668c148
fix(pallet-assets): missing documentation changes
pandres95 4f27725
fix(pallet-assets): missing borrowing
pandres95 9d2256d
Merge branch 'master' into pallet-assets-holder
pandres95 dec2a4c
change: resolve issues raised by ci checks
pandres95 25d9bb0
change(pallet-assets): make `dead_account` return either `DeadConsequ…
pandres95 de4702e
Merge branch 'master' into pallet-assets-holder
pandres95 c81ad85
change(Cargo): update lockfile
pandres95 bd72de1
fix(pallet-pass): missing clone for asset id
pandres95 4bab6f1
make ci happy
pandres95 f1e5b9b
Merge branch 'master' into pallet-assets-holder
pandres95 8d46fa3
change(pallet-assets): tests to assert calling on `dead_account` fail…
pandres95 8b9b6db
Merge branch 'master' into pallet-assets-holder
pandres95 ba8c452
Merge branch 'master' into pallet-assets-holder
pandres95 7d84bee
change(pallet-assets-holder): make CI happy
pandres95 608b688
change(prdoc): apply suggestions and clarify changes in balance model
pandres95 f12acd2
Merge branch 'master' into pallet-assets-holder
pandres95 6ce2b83
Merge branch 'master' into pallet-assets-holder
pandres95 189d8d4
change(pallet-assets-freezer): handle `assert_debug`s when calling `d…
pandres95 6130c60
fix(pallet-assets): on `can_decrease`, return `WouldDie` if there's b…
pandres95 f7d0a41
change(pallet-assets): assert `died` hooks for both `Freezer` AND `Ho…
pandres95 6bebe7e
change(pallet-assets): document the `balance` field of `AssetAccount`…
pandres95 3e797b1
change(pallet-assets): assert deposit
pandres95 595b838
fix(pallet-assets): typo (thanks to @gui1117 for the suggestion)
pandres95 17ba78c
change(pallet-assets-holder): comment events as docstring (thanks @gg…
pandres95 d2e2d18
fix(pallet-assets): add additional storage layout on calls to `T::Cur…
pandres95 c10123a
fix(prdoc): extend explanation of changes in balance model to better …
pandres95 99ee590
Merge branch 'master' into pallet-assets-holder
pandres95 4a55d5c
fix(pallet-assets): add `with_storage_layer` on `transfer_and_die`. J…
pandres95 12e9a42
fix(pallet-assets): fmt
pandres95 8615a4c
fix(pallet-assets-freezer): fmt
pandres95 4f50052
fix(pallet-assets): ensure that an account can die before unreserving…
pandres95 3fc7ac2
Merge branch 'master' into pallet-assets-holder
pandres95 17e4b16
change(pallet-assets): apply change in documentation suggestion by @m…
pandres95 d0005af
fix: re-include pallet-assets-holder on Cargo.lock after merging chan…
pandres95 d6af473
fix: `ensure_account_can_die` should happen before mutating `dest` on…
pandres95 f2d33e0
Merge branch 'master' into pallet-assets-holder
pandres95 a37b00b
fix(pallet-assets): add `ensure_account_can_die` on `decrease_balance`
pandres95 63dc190
fix(umbrella): missing dependency for `pallet-assets-holder` / fmt
pandres95 9757514
Merge branch 'master' into pallet-assets-holder
pandres95 cf07ea7
fix(pallet-assets): unused import
pandres95 3291c66
fix(pallet-assets): call `ensure_account_can_die` before making any n…
pandres95 9a2186f
Merge branch 'master' into pallet-assets-holder
pandres95 9c690fd
Merge branch 'master' into pallet-assets-holder
pandres95 20e807c
fix: make CI happy
pandres95 a425056
Merge branch 'master' into pallet-assets-holder
pandres95 c9c5191
fix: make ci happy / update umbrella after conflict resolution
pandres95 9964c36
Merge branch 'master' into pallet-assets-holder
pandres95 52aa03e
fix(pallet-asset-rewards): remove `ed` subtraction in tests, due to c…
pandres95 cb06ef1
Merge branch 'master' into pallet-assets-holder
pandres95 751e050
Update prdoc/pr_4530.prdoc
gui1117 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| title: "Implement `pallet-assets-holder` and consider ED part of frozen amount in `pallet-assets`" | ||
|
|
||
| doc: | ||
| - audience: Runtime Dev | ||
| description: | | ||
| This change creates the `pallet-assets-holder` pallet, as well as changes `pallet-assets` | ||
| to support querying held balances via a new trait: `BalanceOnHold`. | ||
|
|
||
| ## Changes in Balance Model | ||
|
|
||
| The change also adjusts the balance model implementation for fungible sets. This aligns the | ||
| calculation of the _spendable_ balance (that can be reduced either via withdrawals, like | ||
| paying for fees, or transfer to other accounts) to behave like it works with native tokens. | ||
|
|
||
| As a consequence, when this change is introduced, adding freezes (a.k.a. locks) or balances | ||
| on hold (a.k.a. reserves) to an asset account will constraint the amount of balance for such | ||
| account that can be withdrawn or transferred, and will affect the ability for these accounts | ||
| to be destroyed. | ||
|
|
||
| ### Example | ||
|
|
||
| Before the changes in the balance model, an asset account balance could look like something like this: | ||
|
|
||
| ``` | ||
| |____________balance____________| | ||
| |__frozen__| | ||
| |__ed__| | ||
| |___untouchable___|__spendable__| | ||
| ``` | ||
|
|
||
| In the previous model, you could spend funds up to `ed + frozen` where `ed` is the minimum balance for an asset | ||
| class, and `frozen` is the frozen amount (if any `freezes` are in place). | ||
|
|
||
| Now, the model looks like this: | ||
|
|
||
| ``` | ||
| |__total__________________________________| | ||
| |__on_hold__|_____________free____________| | ||
| |__________frozen___________| | ||
| |__on_hold__|__ed__| | ||
| |__untouchable__|__spendable__| | ||
| ``` | ||
|
|
||
| There's now a balance `on_hold` and a `free` balance. The balance `on_hold` is managed by a `Holder` (typically | ||
| `pallet-assets-holder`) and `free` is the balance that remains in `pallet-assets`. The `frozen` amount can be | ||
| subsumed into the balance `on_hold`, and now you can spend funds up to `max(frozen, ed)`, so if for an account, | ||
| `frozen` is less or equal than `on_hold + ed`, you'd be able to spend your `free` balance up to `ed`. If for | ||
| the account, `frozen` is more than `on_hold + ed`, the remaining amount after subtracting `frozen` to | ||
| `on_hold + ed` is the amount you cannot spend from your `free` balance. | ||
|
|
||
| See [sdk docs](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/fungible/index.html#visualising-balance-components-together-) | ||
| to understand how to calculate the spendable balance of an asset account on the client side. | ||
pandres95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Implementation of `InspectHold` and `MutateHold` | ||
|
|
||
| The `pallet-assets-holder` implements `hold` traits for `pallet-assets`, by extending this | ||
| pallet and implementing the `BalanceOnHold` trait so the held balance can be queried by | ||
| `pallet-assets` to calculate the reducible (a.k.a. spendable) balance. | ||
|
|
||
| These changes imply adding a configuration type in `pallet-assets` for `Holder` | ||
|
|
||
| ## Default implementation of `Holder` | ||
|
|
||
| Use `()` as the default value, when no holding capabilities are wanted in the runtime | ||
| implementation. | ||
|
|
||
| ## Enable `pallet-assets-holder` | ||
|
|
||
| Define an instance of `pallet-assets-holder` (we'll call it `AssetsHolder`) and use | ||
| `AssetsHolder` as the type for `Holder`, when intend to use holding capabilities are | ||
| wanted in the runtime implementation. | ||
|
|
||
| crates: | ||
| - name: asset-hub-rococo-runtime | ||
| bump: minor | ||
| - name: asset-hub-westend-runtime | ||
| bump: minor | ||
| - name: pallet-asset-tx-payment | ||
| bump: patch | ||
| - name: pallet-asset-conversion-ops | ||
| bump: patch | ||
| - name: pallet-asset-conversion-tx-payment | ||
| bump: patch | ||
| - name: pallet-assets | ||
| bump: major | ||
| - name: pallet-assets-holder | ||
| bump: major | ||
| - name: pallet-assets-freezer | ||
| bump: patch | ||
| - name: pallet-contracts-mock-network | ||
| bump: patch | ||
| - name: pallet-nft-fractionalization | ||
| bump: patch | ||
| - name: pallet-revive-mock-network | ||
| bump: patch | ||
| - name: pallet-xcm | ||
| bump: patch | ||
| - name: penpal-runtime | ||
| bump: patch | ||
| - name: rococo-parachain-runtime | ||
| bump: patch | ||
| - name: polkadot-sdk | ||
| bump: minor | ||
| - name: staging-xcm-builder | ||
| bump: patch | ||
| - name: xcm-runtime-apis | ||
| bump: patch | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.