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

[Assets] Implement pallet-assets-holder #4530

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
a0f5015
change(pallet-assets): define HeldBalance
pandres95 May 21, 2024
6d2aa57
change(pallet-assets): implement `Holder` to calculate reducible bala…
pandres95 Jun 10, 2024
029e887
change: add Holder type to missing pallet_assets Config implementations
pandres95 Jun 17, 2024
bf376a5
change(pallet-assets): call died hook for Holder whenever necessary
pandres95 Jun 17, 2024
fe951fa
Merge branch 'master' into pallet-assets-holder
pandres95 Jun 17, 2024
89ea43a
fix(pallet-asset-conversion-ops): missing Holder in mock config
pandres95 Jun 17, 2024
2ab3535
change(pallet-assets): adjust reducible/can_decrease to be in line wi…
pandres95 Jul 10, 2024
9d326b8
Merge branch 'master' into pallet-assets-holder
pandres95 Jul 10, 2024
c76b654
change(pallet-assets): introduce tests to check for holds and freezes…
pandres95 Jul 11, 2024
c5690e1
Merge branch 'master' into pallet-assets-holder
pandres95 Jul 11, 2024
a4bb10c
change(pallet-assets-freezer): adjust mock and tests to changes in `p…
pandres95 Jul 29, 2024
32fa5c1
feat(pallet-assets-holder): pallet implementation
pandres95 Aug 1, 2024
fe0a5e5
Merge branch 'master' into pallet-assets-holder
pandres95 Aug 1, 2024
b93337e
fix: fmt / cargo fmt
pandres95 Aug 1, 2024
4e0ced7
chore: umbrella
pandres95 Aug 1, 2024
c5b103a
chore: pr doc
pandres95 Aug 1, 2024
9cdb256
Merge branch 'master' into pallet-assets-holder
pandres95 Aug 8, 2024
f36b540
fix(staging-xcm-builder): missing references to `Holder`
pandres95 Aug 8, 2024
5829558
change(pallet-assets): set `Holder` and `Freezer` to have default val…
pandres95 Aug 8, 2024
17ce1d9
change(pallet-assets-holder): apply @gui1117's suggestion of tightly …
pandres95 Aug 8, 2024
f2a9e96
change(pallet-assets): account for `held_balance` when calculating `t…
pandres95 Aug 8, 2024
fc41634
change(pallet-assets-holder): test preservation of `total_balance`.
pandres95 Aug 8, 2024
9e9edfb
change(pallet-assets-holder): resolve `VARIANT_COUNT` to match number…
pandres95 Aug 8, 2024
e7155eb
change(pallet-assets-holder): remove assertion in test that fails aft…
pandres95 Aug 9, 2024
4268b76
change(pallet-assets-holder): implement changes suggested by @gui1117
pandres95 Aug 28, 2024
818e590
change(pallet-assets-holder): apply change from HeldBalance to Balanc…
pandres95 Aug 28, 2024
06db701
minor(pallet-assets-holder): small adjustments
pandres95 Aug 28, 2024
be7576e
Merge branch 'master' into pallet-assets-holder
pandres95 Aug 28, 2024
0a0487e
Merge branch 'pallet-assets-holder' of https://github.com/pandres95/p…
pandres95 Aug 28, 2024
7dff111
fix(pallet-revive-mock-network): include Holder on pallet_assets conf…
pandres95 Aug 28, 2024
5d04950
change(prdoc): update prdoc with all impacted crates
pandres95 Aug 28, 2024
44e8f62
change(pallet-assets-holder): add additional assertions to `try_state…
pandres95 Aug 28, 2024
bb1a98d
minor(pallet-assets-holder): rename _held_ references in comments wit…
pandres95 Aug 28, 2024
aab6498
Merge branch 'master' into pallet-assets-holder
pandres95 Aug 28, 2024
3688f89
change(pallet-assets-holder): address changes requested by @muharem
pandres95 Sep 4, 2024
900dbaa
change(pallet-assets-holder): impls -> impl_fungibles
pandres95 Sep 4, 2024
b689e2e
fix(pallet-assets-holder): missing `CheckedAdd` import
pandres95 Sep 5, 2024
2f14b32
change(pallet-assets-holder): make `died` burn balance on hold (if any).
pandres95 Sep 5, 2024
548eee1
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 5, 2024
5d7d874
change(pallet-assets-holder): fast exit for `set_balance_on_hold`.
pandres95 Sep 5, 2024
427a29b
fix(penpal-runtime): missing `Holder` in `PoolAssets` config
pandres95 Sep 6, 2024
7c28175
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 6, 2024
9ccc35c
fix(pallet-assets-holder): lint
pandres95 Sep 6, 2024
c65a4c2
change(pallet-assets-holder): revert `died` to make it an infallible …
pandres95 Sep 6, 2024
174b3d5
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 6, 2024
f1c0983
change(pallet-assets): remark the change of parameters in the `freeze…
pandres95 Sep 9, 2024
ae2f67a
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 9, 2024
92769f1
change(pallet-assets): implement contains_holds / contains_freezes
pandres95 Sep 11, 2024
a02904d
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 11, 2024
b559bda
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 11, 2024
0e848ac
fix(pallet-assets-freezer): missing import
pandres95 Sep 11, 2024
3bd7241
change(pallet-assets): disallow `refund`/`refund_other` for an accoun…
pandres95 Sep 13, 2024
4e25e73
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 13, 2024
3233d48
fix(umbrella): revert unintended misformatting of Cargo.toml
pandres95 Sep 13, 2024
a80e6e3
fix(Cargo): revert unintended regression in Cargo lockfile
pandres95 Sep 13, 2024
668c148
fix(pallet-assets): missing documentation changes
pandres95 Sep 13, 2024
4f27725
fix(pallet-assets): missing borrowing
pandres95 Sep 13, 2024
9d2256d
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 16, 2024
dec2a4c
change: resolve issues raised by ci checks
pandres95 Sep 16, 2024
25d9bb0
change(pallet-assets): make `dead_account` return either `DeadConsequ…
pandres95 Sep 23, 2024
de4702e
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 23, 2024
c81ad85
change(Cargo): update lockfile
pandres95 Sep 23, 2024
bd72de1
fix(pallet-pass): missing clone for asset id
pandres95 Sep 23, 2024
4bab6f1
make ci happy
pandres95 Sep 23, 2024
f1e5b9b
Merge branch 'master' into pallet-assets-holder
pandres95 Sep 25, 2024
8d46fa3
change(pallet-assets): tests to assert calling on `dead_account` fail…
pandres95 Oct 7, 2024
8b9b6db
Merge branch 'master' into pallet-assets-holder
pandres95 Oct 7, 2024
ba8c452
Merge branch 'master' into pallet-assets-holder
pandres95 Oct 7, 2024
7d84bee
change(pallet-assets-holder): make CI happy
pandres95 Oct 7, 2024
608b688
change(prdoc): apply suggestions and clarify changes in balance model
pandres95 Nov 3, 2024
f12acd2
Merge branch 'master' into pallet-assets-holder
pandres95 Nov 3, 2024
6ce2b83
Merge branch 'master' into pallet-assets-holder
pandres95 Nov 3, 2024
189d8d4
change(pallet-assets-freezer): handle `assert_debug`s when calling `d…
pandres95 Nov 3, 2024
6130c60
fix(pallet-assets): on `can_decrease`, return `WouldDie` if there's b…
pandres95 Nov 4, 2024
f7d0a41
change(pallet-assets): assert `died` hooks for both `Freezer` AND `Ho…
pandres95 Nov 4, 2024
6bebe7e
change(pallet-assets): document the `balance` field of `AssetAccount`…
pandres95 Nov 4, 2024
3e797b1
change(pallet-assets): assert deposit
pandres95 Nov 5, 2024
595b838
fix(pallet-assets): typo (thanks to @gui1117 for the suggestion)
pandres95 Nov 5, 2024
17ba78c
change(pallet-assets-holder): comment events as docstring (thanks @gg…
pandres95 Nov 6, 2024
d2e2d18
fix(pallet-assets): add additional storage layout on calls to `T::Cur…
pandres95 Nov 6, 2024
c10123a
fix(prdoc): extend explanation of changes in balance model to better …
pandres95 Nov 6, 2024
99ee590
Merge branch 'master' into pallet-assets-holder
pandres95 Nov 7, 2024
4a55d5c
fix(pallet-assets): add `with_storage_layer` on `transfer_and_die`. J…
pandres95 Nov 8, 2024
12e9a42
fix(pallet-assets): fmt
pandres95 Nov 8, 2024
8615a4c
fix(pallet-assets-freezer): fmt
pandres95 Nov 8, 2024
4f50052
fix(pallet-assets): ensure that an account can die before unreserving…
pandres95 Nov 27, 2024
3fc7ac2
Merge branch 'master' into pallet-assets-holder
pandres95 Nov 27, 2024
17e4b16
change(pallet-assets): apply change in documentation suggestion by @m…
pandres95 Nov 27, 2024
d0005af
fix: re-include pallet-assets-holder on Cargo.lock after merging chan…
pandres95 Nov 27, 2024
d6af473
fix: `ensure_account_can_die` should happen before mutating `dest` on…
pandres95 Dec 9, 2024
f2d33e0
Merge branch 'master' into pallet-assets-holder
pandres95 Dec 9, 2024
a37b00b
fix(pallet-assets): add `ensure_account_can_die` on `decrease_balance`
pandres95 Dec 9, 2024
63dc190
fix(umbrella): missing dependency for `pallet-assets-holder` / fmt
pandres95 Dec 9, 2024
9757514
Merge branch 'master' into pallet-assets-holder
pandres95 Dec 9, 2024
cf07ea7
fix(pallet-assets): unused import
pandres95 Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ members = [
"substrate/frame/asset-rate",
"substrate/frame/assets",
"substrate/frame/assets-freezer",
"substrate/frame/assets-holder",
"substrate/frame/atomic-swap",
"substrate/frame/aura",
"substrate/frame/authority-discovery",
Expand Down Expand Up @@ -887,6 +888,7 @@ pallet-asset-rate = { path = "substrate/frame/asset-rate", default-features = fa
pallet-asset-tx-payment = { path = "substrate/frame/transaction-payment/asset-tx-payment", default-features = false }
pallet-assets = { path = "substrate/frame/assets", default-features = false }
pallet-assets-freezer = { path = "substrate/frame/assets-freezer", default-features = false }
pallet-assets-holder = { path = "substrate/frame/assets-holder", default-features = false }
pallet-atomic-swap = { default-features = false, path = "substrate/frame/atomic-swap" }
pallet-aura = { path = "substrate/frame/aura", default-features = false }
pallet-authority-discovery = { path = "substrate/frame/authority-discovery", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Holder = ();
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_local::WeightInfo<Runtime>;
Expand Down Expand Up @@ -310,6 +311,7 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = ConstU32<50>;
type Holder = ();
type Freezer = PoolAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_pool::WeightInfo<Runtime>;
Expand Down Expand Up @@ -434,6 +436,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
type StringLimit = ForeignAssetsAssetsStringLimit;
type Holder = ();
type Freezer = ForeignAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_foreign::WeightInfo<Runtime>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Holder = ();
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_local::WeightInfo<Runtime>;
Expand Down Expand Up @@ -309,6 +310,7 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ConstU128<0>;
type StringLimit = ConstU32<50>;
type Holder = ();
type Freezer = PoolAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_pool::WeightInfo<Runtime>;
Expand Down Expand Up @@ -433,6 +435,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
type StringLimit = ForeignAssetsAssetsStringLimit;
type Holder = ();
type Freezer = ForeignAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_foreign::WeightInfo<Runtime>;
Expand Down
3 changes: 3 additions & 0 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
Expand Down Expand Up @@ -501,6 +502,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
type StringLimit = ForeignAssetsAssetsStringLimit;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
Expand Down Expand Up @@ -540,6 +542,7 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ConstU128<0>;
type StringLimit = ConstU32<50>;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ impl pallet_assets::Config for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ impl pallet_assets::Config for Test {
type MetadataDepositPerByte = ConstU128<1>;
type ApprovalDeposit = ConstU128<1>;
type StringLimit = ConstU32<50>;
type Holder = ();
type Freezer = ();
type WeightInfo = ();
type CallbackHandle = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type Freezer = ();
type Holder = ();
type CallbackHandle = ();
}

Expand All @@ -97,6 +98,7 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type Freezer = ();
type Holder = ();
type CallbackHandle = ();
}

Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-builder/src/tests/pay/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl pallet_assets::Config for Test {
type AssetAccountDeposit = AssetAccountDeposit;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = ();
Expand Down
1 change: 1 addition & 0 deletions polkadot/xcm/xcm-runtime-apis/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl pallet_assets::Config for TestRuntime {
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type Holder = ();
type Freezer = ();
type AssetDeposit = ConstU128<1>;
type AssetAccountDeposit = ConstU128<10>;
Expand Down
76 changes: 76 additions & 0 deletions prdoc/pr_4530.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
title: "Implement `pallet-assets-holder`"

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.

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
2 changes: 2 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ impl pallet_assets::Config<Instance1> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = StringLimit;
type Holder = ();
type Freezer = ();
type Extra = ();
type CallbackHandle = ();
Expand Down Expand Up @@ -1759,6 +1760,7 @@ impl pallet_assets::Config<Instance2> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = StringLimit;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/asset-conversion/ops/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl pallet_assets::Config<Instance1> for Test {
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Holder = ();
type Freezer = ();
}

Expand All @@ -76,6 +77,7 @@ impl pallet_assets::Config<Instance2> for Test {
type CreateOrigin =
AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, Self::AccountId>>;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Holder = ();
type Freezer = ();
}

Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl pallet_assets::Config<Instance1> for Test {
type MetadataDepositPerByte = ConstU128<1>;
type ApprovalDeposit = ConstU128<1>;
type StringLimit = ConstU32<50>;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = ();
Expand All @@ -108,6 +109,7 @@ impl pallet_assets::Config<Instance2> for Test {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ConstU128<0>;
type StringLimit = ConstU32<50>;
type Holder = ();
type Freezer = ();
type Extra = ();
type WeightInfo = ();
Expand Down
14 changes: 14 additions & 0 deletions substrate/frame/assets-freezer/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use frame_support::traits::{
};
use pallet_assets::FrozenBalance;
use sp_runtime::traits::Zero;
use storage::StorageDoubleMap;

// Implements [`FrozenBalance`] from [`pallet-assets`], so it can understand how much of an
// account balance is frozen, and is able to signal to this pallet when to clear the state of an
Expand All @@ -35,9 +36,22 @@ impl<T: Config<I>, I: 'static> FrozenBalance<T::AssetId, T::AccountId, T::Balanc
}

fn died(asset: T::AssetId, who: &T::AccountId) {
defensive_assert!(
Freezes::<T, I>::get(asset.clone(), who).is_empty(),
"The list of Freezes should be empty before allowing an account to die"
);
defensive_assert!(
FrozenBalances::<T, I>::get(asset.clone(), who).is_none(),
"There should not be a frozen balance before allowing to die"
);

FrozenBalances::<T, I>::remove(asset.clone(), who);
pandres95 marked this conversation as resolved.
Show resolved Hide resolved
Freezes::<T, I>::remove(asset, who);
}

fn contains_freezes(asset: T::AssetId) -> bool {
Freezes::<T, I>::contains_prefix(asset)
}
}

// Implement [`fungibles::Inspect`](frame_support::traits::fungibles::Inspect) as it is bound by
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/assets-freezer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl pallet_assets::Config for Test {
type RemoveItemsLimit = ConstU32<10>;
type CallbackHandle = ();
type Currency = Balances;
type Holder = ();
type Freezer = AssetsFreezer;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
Expand Down
Loading
Loading