paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.67k stars 594 forks source link

Define and implement `Hold` for Assets #4315

Open pandres95 opened 3 months ago

pandres95 commented 3 months ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Motivation

A follow-up of #3342. The current design of pallet-assets doesn't implement holds, while there are multiple use cases for which it would be beneficial to support this behaviour (e.g. bonding, staking, deposits, payment holds, escrowed vesting, etc.).

Request

Because of the above, it is desirable to find a way of implementing inspection and mutation of the [fungibles::holds]() traits.

Solution

Stage 1

Pull Request:

A basic definition and implementation of a HeldBalance (an analogous to FrozenBalance) that can be added as a type in pallet-assets.

pub trait HeldBalance<AssetId, AccountId, Balance> {
    // Required methods
    fn held_balance(asset: AssetId, who: &AccountId) -> Option<Balance>;
    fn died(asset: AssetId, who: &AccountId);
}

Then, by using the held_balance method in Assets, it would be possible to subtract the free balance to obtain the reducible_balance, and adjust to the balance components model.

Analogous to pallet-assets-freezer, this proposed pallet extends the capabilities of pallet-assets to support holding balances.

Are you willing to help with this request?

Yes!

### Tasks
- [ ] https://github.com/paritytech/polkadot-sdk/pull/4530
- [ ] Implement `pallet-assets-holder`
pandres95 commented 2 months ago

Quick question before proceeding with the proposed implementation: after taking a review on #236, I noticed that (at least for fungible tokens) it is expected that holds are not overlapped with free balance, while frozen may be applied to the total balance (including held balances).

This leads me to think the reducible_balance for an asset account should be calculated as total - max(frozen, held).

Is this assumption correct @gavofyork, or does this concept only for fungible tokens?

Polkadot-Forum commented 2 months ago

This issue has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/2024-05-21-technical-fellowship-opendev-call/8264/1

muharem commented 3 days ago

Quick question before proceeding with the proposed implementation: after taking a review on #236, I noticed that (at least for fungible tokens) it is expected that holds are not overlapped with free balance, while frozen may be applied to the total balance (including held balances).

This leads me to think the reducible_balance for an asset account should be calculated as total - max(frozen, held).

Is this assumption correct @gavofyork, or does this concept only for fungible tokens?

there is an issue explaining these relations. you should look for the PR introducing new fungible/s traits. should be linked there.