Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

A Vision for More Friendly Balances and Currencies #8285

Closed
3 of 6 tasks
shawntabrizi opened this issue Mar 8, 2021 · 8 comments
Closed
3 of 6 tasks

A Vision for More Friendly Balances and Currencies #8285

shawntabrizi opened this issue Mar 8, 2021 · 8 comments
Labels
J0-enhancement An additional feature request. J1-meta A specific issue for grouping tasks or bugs of a specific category. Z3-substantial Can be fixed by an experienced coder with a working knowledge of the codebase.

Comments

@shawntabrizi
Copy link
Member

shawntabrizi commented Mar 8, 2021

The entire FRAME ecosystem revolves around the Balances pallet. In fact, nearly every pallet in FRAME uses the Currency trait, which currently is only implemented by our Balances pallet.

The Currency trait itself is not very well designed imo. It exposes functions which are implementation details of how the Balances pallet works, for example Negative/Positive imbalance.

It also assumes that every pallet needs extreme access to a currency, for example to be able to mint it, burn it, set anyone's balance, etc...

I think that we can turn the Currency pallet into a bunch of smaller, more ergonomic traits, and also reduce the trait requirements of many of our FRAME pallets. This would make them MUCH more friendly to alternative implementations of Balances-like pallets, especially when keeping in mind the need for multi-currenty chains of the future.

This is a meta issue to track the following independent tasks:

  • Research, Design, and Define a new set of Currency traits which have in mind the MINIMAL set of functions needed to be exposed to be used by various pallets.
  • Implement these traits into Substrate and FRAME primitives.
  • Implement these traits into the Balances pallet.
  • Downgrade all Currency requirements where possible across existing pallets.
  • Create a "Simple Balances" pallet as an alternative to the balances pallet, something that would be a simple example for any new runtime developer to understand.
  • Traitify the Assets Pallet using these minimal traits

Some ideas:

trait Currency {
    fn total_supply() -> Balance;
    fn minimum_balance() -> Balance;
    fn free_balance(who: AccountId) -> Balance;
    fn transfer(from: AccountId, to: AccountId, amount: Balance) -> Result;
}
trait ReservableCurrency: Currency {
    fn reserved_balance(who: AccountId) -> Balance;
    fn reserve(who: AccountId, amount: Balance) -> Result;
    fn unreserve(who: AccountId, amount: Balance) -> Balance;
}
trait MintableCurrency: Currency {
    fn mint(who: AccountId, amount: AccountId);
}
trait BurnableCurrency: Currency {
    fn burn(who: AccountId, amount: AccountId);
}

etc...

@shawntabrizi shawntabrizi added J0-enhancement An additional feature request. J1-meta A specific issue for grouping tasks or bugs of a specific category. Z3-substantial Can be fixed by an experienced coder with a working knowledge of the codebase. labels Mar 8, 2021
@xlc
Copy link
Contributor

xlc commented Mar 8, 2021

A version without imbalance will be useful. We have already made one in ORML: https://github.com/open-web3-stack/open-runtime-module-library/blob/92db458616cae0da1cc55fa90962e2ed16d45279/traits/src/currency.rs#L187

Also some multi currency support is needed like https://github.com/open-web3-stack/open-runtime-module-library/blob/92db458616cae0da1cc55fa90962e2ed16d45279/traits/src/currency.rs#L16

pallet-assets should also implement some of those new traits.

@shawntabrizi
Copy link
Member Author

shawntabrizi commented Mar 8, 2021

Yes to all of the above. Very happy to steal from you all as much as it makes sense so we can avoid duplication of work.

For example, in your BasicCurrency, I wouldn't include withdraw / deposit / slash. Do you think there is reason to have them in the minimal currency?

@xlc
Copy link
Contributor

xlc commented Mar 8, 2021

A version without withdraw / deposit / slash will be useful for a fixed supply token to enforce no mint / burn.

@shawntabrizi
Copy link
Member Author

Exactly. Yeah, then seems we are very much aligned here. 👍

@shaunxw
Copy link
Contributor

shaunxw commented Mar 24, 2021

It seems #8435 is related to this issue.

@shaunxw
Copy link
Contributor

shaunxw commented Mar 24, 2021

To make traits minimal, I think they don't have to inherit from the base trait Currency. We can compose them instead if needed, like:

pub trait Config: frame_system::Config {
    type ReservableCurrency: Currency + Reservable;
}

@stale
Copy link

stale bot commented Jul 7, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Jul 7, 2021
@shawntabrizi shawntabrizi removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Jul 7, 2021
@kianenigma
Copy link
Contributor

This will be addressed as part of paritytech/polkadot-sdk#327

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. J1-meta A specific issue for grouping tasks or bugs of a specific category. Z3-substantial Can be fixed by an experienced coder with a working knowledge of the codebase.
Projects
None yet
Development

No branches or pull requests

4 participants