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

Ref docs frame currency #2683

Closed
wants to merge 9 commits into from
Closed

Conversation

juangirini
Copy link
Contributor

@juangirini juangirini commented Dec 11, 2023

Closes paritytech/polkadot-sdk-docs#49

polkadot address: 12zshjtBEmK43evpHZXyQEVHkfVhW7J5sUvs64EmusSCxPUp

Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

I think it's worth defining a clear goal of what this ref doc should achieve, then outlining the sections and writing each sentence to ensure they are maximally fulfilling this goal.

I understood it as something to disambiguate the different traits, trait implementations, and terminology we have for handling tokens. We should be careful not to let the scope creep and start writing documentation for the actual traits / implementations here.

docs/sdk/src/reference_docs/frame_currency.rs Outdated Show resolved Hide resolved
docs/sdk/src/reference_docs/frame_currency.rs Outdated Show resolved Hide resolved
docs/sdk/src/reference_docs/frame_currency.rs Outdated Show resolved Hide resolved
docs/sdk/src/reference_docs/frame_currency.rs Outdated Show resolved Hide resolved
docs/sdk/src/reference_docs/frame_currency.rs Outdated Show resolved Hide resolved
@juangirini
Copy link
Contributor Author

I think it's worth defining a clear goal of what this ref doc should achieve, then outlining the sections and writing each sentence to ensure they are maximally fulfilling this goal.

I understood it as something to disambiguate the different traits, trait implementations, and terminology we have for handling tokens. We should be careful not to let the scope creep and start writing documentation for the actual traits / implementations here.

Indeed, we have different goals in mind for this document. We definitely don't want to talk (only) about the Currency trait here, but what is Currency in FRAME if not a very important use case of the fungible traits?
What would be a valid structure for this document from your point of view?

@liamaharon
Copy link
Contributor

what is Currency in FRAME if not a very important use case of the fungible traits?

Not sure what you mean here?

Indeed, we have different goals in mind for this document.

What is/was your goal for this doc?

What would be a valid structure for this document from your point of view?

Primarily I think the goal of an overarching doc for token traits and trait impls should be to allow a reader with zero prior knowledge of Substrate come away with

  • A good understanding of the patterns used for tokens in Substrate (traits and trait impls), and why we use these patterns
  • A good understanding of which traits and pallets exist, the differences between the traits and pallets, and how to choose a trait or pallet for their use case

This could look something loosely like

## Tokens in Substrate

briefly explains 
- how Substrate follows the pattern of traits and trait implementation for tokens
- why this approach was chosen

### Fungible Traits and Pallets

list and compare fungible traits and pallets

### Non-fungible Traits and Pallets

list and compare non-fungible traits and pallets

I don't think this needs to be long. Each sentence should be genuinely informative and contribute to the goal of the document.

Let me know what you think, I'm open to other ideas.

@juangirini
Copy link
Contributor Author

what is Currency in FRAME if not a very important use case of the fungible traits?

Not sure what you mean here?

This is supposed to be a Currency documentation, being currency a fungible token I think we should talk about both of them.

Indeed, we have different goals in mind for this document.

What is/was your goal for this doc?

Give a high level overview of currency and fungible traits.

## Tokens in Substrate

briefly explains 
- how Substrate follows the pattern of traits and trait implementation for tokens
- why this approach was chosen

### Fungible Traits and Pallets

list and compare fungible traits and pallets

### Non-fungible Traits and Pallets

list and compare non-fungible traits and pallets

I don't think we should generalize it to "all" tokens, and therefore I wouldn't touch NFT in the Currency documentation, that should belong somewhere else.
The current PR already explains the Fungible Traits and Pallets part, this could of course improved and adapted.
I like the idea of the first part you propose as long as we stick to currency

  • how Substrate follows the pattern of traits and trait implementation for tokens
  • why this approach was chosen
    WDYT? Do you want to add that to the PR?

@juangirini
Copy link
Contributor Author

The more broader/generic tokens document will be taken care of in paritytech/polkadot-sdk-docs#70

@juangirini juangirini self-assigned this Dec 15, 2023
@juangirini juangirini added R0-silent Changes should not be mentioned in any release notes T11-documentation This PR/Issue is related to documentation. labels Dec 15, 2023
@juangirini juangirini marked this pull request as ready for review December 15, 2023 15:52
@juangirini juangirini requested review from a team December 15, 2023 15:52
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/4739247

@JuaniRios
Copy link
Contributor

JuaniRios commented Dec 19, 2023

Just wanted to comment that we spent 2 days researching the move from currency to fungible/fungibles, and it was very hard to understand.
This doc will definitely help us and other people in the future :)

Our main pain points that we had to clear up:

Do freezes make the same changes to AccountData storage as locks?

Yes

Should all previous locks be freezes, and all reserves be now holds?

No, because previously a lock could assume that the free balance wouldn't be reduced below that amount. But now if a hold happens, then you are considering also the frozen/locked balance, which might lead to unexpected behaviour.
This is why pallet-staking had to go from lock to hold

If a pallet used a currency trait, can another pallet use a fungible/fungibles trait?

Depends very much on the expected behavior. For example if one pallet is using locks, but you are ok with that amount being considered in another pallet's hold, then you could do that.
In our case we could use pallet-vesting which uses LockableCurrency, because if we were to replace it with the fungible trait it would be a Freeze (we don't mind having a hold on the frozen amount). And from our understanding freezes and locks produce the same outcome on the AccountData storage.

What are the bookkeeping functions mentioned by gav?

In here and here Gav explains that since a frozen balance cannot guarantee that the free will ever go below that (due to slashing on holds), then we should add a bookkeeping function which deals with the case where we find less free balance than the frozen one.
We are not sure what this means or how it would look like in the code.

It is mentioned that this is implemented in the conviction-voting pallet, but we couldn't find where that happened.

Why is the output of reducable_balance when the parameter fortitude=Polite calculated like that?

Here Liam's visualisation came in handy.

I think we would benefit from also explaining how the currency and fungible traits relate to the AccountData storage.

If I got anything wrong from my self-answered questions, please let me know :)

@juangirini
Copy link
Contributor Author

juangirini commented Dec 22, 2023

Hey @JuaniRios thanks for your valuable input. We've loosely spoken about fungible/s traits in this doc as there's another one more specific to it paritytech/polkadot-sdk-docs#70. I am cc'ing @liamaharon as he's working on it

@liamaharon
Copy link
Contributor

liamaharon commented Dec 24, 2023

Thank you @JuaniRios, this is super useful! I have a draft PR for token doc here #2802, will add a TODO there to make sure all these points have been covered. If you have any other suggestions for these docs you can comment in that pr :)

@liamaharon liamaharon mentioned this pull request Dec 24, 2023
6 tasks
//! financial operations. The key functions of
//! [`pallet_balances`](../../../pallet_balances/index.html) include transferring tokens between
//! accounts, checking account balances, and adjusting balances for staking or fees. This pallet
//! implements the [`fungible`](../../../frame_support/traits/tokens/fungible/index.html)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the most important detail came last; What I think is the most important piece of info here is that pallet-balances and pallet-assets provide implementations for all of the aforementioned traits. We can list those here (while linking to the proper impl block in the rust-docs).

//! still using the [`Currency`](../../../frame_support/traits/tokens/currency/index.html) trait.
//! There one could find the relevant code examples for upgrading.
//!
//! ## Fungible Traits
Copy link
Contributor

Choose a reason for hiding this comment

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

You are not going to briefly talk about Fungibles?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see fungibles making sense in multiple assets scenario but not here, there is this other PR that covers more generic tokens topics

@@ -15,7 +15,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

This is indeed the right place to document this. Any methods that can also be improved?

//! |__on_hold__|__ed__|
//! ```
//!
//! Freezes require a `Reason`, which is configurable and is expected to be an enum aggregated
Copy link
Contributor

@kianenigma kianenigma Jan 8, 2024

Choose a reason for hiding this comment

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

Possibly mention or link to the exact keyword of RuntimeFreezeReason.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

This is a good start, but I expect a lot more substance on this particular topic. I expect this to be in #2802? if so, we can merge this already.

@juangirini juangirini requested a review from a team January 9, 2024 14:13
@juangirini
Copy link
Contributor Author

This is a good start, but I expect a lot more substance on this particular topic. I expect this to be in #2802? if so, we can merge this already.

Yes, we have split the topic into two sections, this one focused only on "currency" as a native token, and a more generic one covered by that other PR

//! Notes:
//! Currency related traits in FRAME provide standardized interfaces for implementing various
//! currency functionalities. The fundamental reason to have these traits is to allow pallets to
//! utilize a token without relying on the implementation detail. Or else we could have a perfectly
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! utilize a token without relying on the implementation detail. Or else we could have a perfectly
//! utilize tokens without relying on the implementation detail. Or else we could have a perfectly

//! Notes:
//! Currency related traits in FRAME provide standardized interfaces for implementing various
//! currency functionalities. The fundamental reason to have these traits is to allow pallets to
//! utilize a token without relying on the implementation detail. Or else we could have a perfectly
Copy link
Contributor

Choose a reason for hiding this comment

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

Or else we could have a perfectly fine runtime without these traits.

I don't quite get what this sentence means to say. Could you elaborate/rephrase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be removed as it is redundant, what I meant is that you don't need these traits if your runtime doesn't require a currency

//! currency functionalities. The fundamental reason to have these traits is to allow pallets to
//! utilize a token without relying on the implementation detail. Or else we could have a perfectly
//! fine runtime without these traits.
//! These traits enable developers to create, transfer, and manage different forms of digital assets
Copy link
Contributor

Choose a reason for hiding this comment

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

different forms of digital assets

Nit but the first thing I thought when I read this was NFTs and I believe the Currency traits are not the best abstractions.

//! - This footgun: <https://github.com/paritytech/polkadot-sdk/pull/1900#discussion_r1363783609>
//! ## The Currency Trait
//!
//! The [`Currency`][4] trait was initially introduced in Substrate to manage the native token
Copy link
Contributor

Choose a reason for hiding this comment

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

[Currency][4]

Nit but this is the first time I'm seeing this type of referencing in our docs, maybe we should just add the URL in line? I find it easier to just click on the word/expression directly if I want more details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's a tradeoff... this format helps readability when there are long / too many links
#2683 (comment)

//! approach for single-asset operations. Fungible is currently preferred over currency as the
//! latter is deprecated.
//!
//! #### Holds and Freezes
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! #### Holds and Freezes
//! ### Holds and Freezes

//!
//! Learn more about this two concepts in
//! [`frame_support::traits::tokens::fungible::hold`][1] and
//! [`frame_support::traits::tokens::fungible::freeze`][2].
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! [`frame_support::traits::tokens::fungible::freeze`][2].
//! [`frame_support::traits::tokens::fungible::freeze`].

I believe the link is added automatically in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really as frame_support is not a dependency of polkadot-sdk-docs

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be able to add it as a dep?

//! [`frame_support::traits::tokens::fungible::freeze`][2].
//!
//! ## Balances Pallet
//! The [`pallet_balances`](../../../pallet_balances/index.html) is a key component in FRAME. It
Copy link
Contributor

Choose a reason for hiding this comment

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

This linking looks better to me, maybe we can stick with that and remove the references in the other cases?

Copy link
Contributor Author

@juangirini juangirini Mar 8, 2024

Choose a reason for hiding this comment

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

I have removed them where they made the lines too long or difficult to read

@@ -1,8 +1,55 @@
//! FRAME Currency Abstractions and Traits
//! # FRAME Currency Abstractions and Traits
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be useful to have a table with the comparing the Currency vs Fungible/s terms and a description on how they differ (e.g. locks vs holds, etc). This is usually a place where people get confused and it would be great if we could have a single place to refresh the memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree we can improve this document by adding some more information, maybe we can keep that for another PR, wdyt?

@kianenigma
Copy link
Contributor

@juangirini I wonder if you intend to finish the last bits of this, as there seems to be little left? else we can consider mentoring someone else to finish it.

In case you do, feel free to leave your DOT address in the PR description :)

@juangirini
Copy link
Contributor Author

@juangirini I wonder if you intend to finish the last bits of this, as there seems to be little left? else we can consider mentoring someone else to finish it.

In case you do, feel free to leave your DOT address in the PR description :)

@kianenigma, yes I'll finish the PR, there is very little left to do. Thanks for the reminder

@juangirini
Copy link
Contributor Author

@gpestana I have addressed your comments on this other PR as I don't have write access anymore here
cc @liamaharon @kianenigma

@kianenigma
Copy link
Contributor

@liamaharon is looking into how this PR can be incorporated into his more recent and broader PR around tokens, but nonetheless submitting a tip for gratitude.

@kianenigma
Copy link
Contributor

/tip medium

Copy link

@kianenigma A referendum for a medium (80 DOT) tip was successfully submitted for @juangirini (12zshjtBEmK43evpHZXyQEVHkfVhW7J5sUvs64EmusSCxPUp on polkadot).

Referendum number: 585.
tip

Copy link

The referendum has appeared on Polkassembly.

@liamaharon
Copy link
Contributor

liamaharon commented Mar 20, 2024

Closing, will absorb into #2802

@liamaharon liamaharon closed this Mar 20, 2024
github-merge-queue bot pushed a commit that referenced this pull request Mar 31, 2024
Closes paritytech/polkadot-sdk-docs#70

WIP PR for an overview of how to develop tokens in FRAME. 

- [x] Tokens in Substrate Ref Doc
  - High-level overview of the token-related logic in FRAME
- Improve docs with better explanation of how holds, freezes, ed, free
balance, etc, all work
- [x] Update `pallet_balances` docs
  - Clearly mark what is deprecated (currency)
- [x] Write fungible trait docs
- [x] Evaluate and if required update `pallet_assets`, `pallet_uniques`,
`pallet_nfts` docs
- [x] Absorb #2683
- [x] Audit individual trait method docs, and improve if possible

Feel free to suggest additional TODOs for this PR in the comments

---------

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
pgherveou pushed a commit that referenced this pull request Apr 2, 2024
Closes paritytech/polkadot-sdk-docs#70

WIP PR for an overview of how to develop tokens in FRAME. 

- [x] Tokens in Substrate Ref Doc
  - High-level overview of the token-related logic in FRAME
- Improve docs with better explanation of how holds, freezes, ed, free
balance, etc, all work
- [x] Update `pallet_balances` docs
  - Clearly mark what is deprecated (currency)
- [x] Write fungible trait docs
- [x] Evaluate and if required update `pallet_assets`, `pallet_uniques`,
`pallet_nfts` docs
- [x] Absorb #2683
- [x] Audit individual trait method docs, and improve if possible

Feel free to suggest additional TODOs for this PR in the comments

---------

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this pull request Apr 9, 2024
Closes paritytech/polkadot-sdk-docs#70

WIP PR for an overview of how to develop tokens in FRAME. 

- [x] Tokens in Substrate Ref Doc
  - High-level overview of the token-related logic in FRAME
- Improve docs with better explanation of how holds, freezes, ed, free
balance, etc, all work
- [x] Update `pallet_balances` docs
  - Clearly mark what is deprecated (currency)
- [x] Write fungible trait docs
- [x] Evaluate and if required update `pallet_assets`, `pallet_uniques`,
`pallet_nfts` docs
- [x] Absorb paritytech#2683
- [x] Audit individual trait method docs, and improve if possible

Feel free to suggest additional TODOs for this PR in the comments

---------

Co-authored-by: Bill Laboon <laboon@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T11-documentation This PR/Issue is related to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ref docs for frame_currency
6 participants