-
Notifications
You must be signed in to change notification settings - Fork 767
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
Ref docs frame currency #2683
Changes from 8 commits
8c94c41
c94350a
14f11bb
9a94042
3fe82bc
cbb7291
6babc75
933a8e2
80ff2ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,51 @@ | ||||||
//! FRAME Currency Abstractions and Traits | ||||||
//! # FRAME Currency Abstractions and Traits | ||||||
//! | ||||||
//! Notes: | ||||||
//! Currency related traits in FRAME provide standardized interfaces for implementing various | ||||||
//! currency functionalities. These traits enable developers to create, transfer, and manage | ||||||
//! different forms of digital assets within the blockchain environment, ensuring that the economic | ||||||
//! aspects of the chain are robust and adaptable to different use cases. | ||||||
juangirini marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
//! | ||||||
//! - History, `Currency` trait. | ||||||
//! - `Hold` and `Freeze` with diagram. | ||||||
//! - `HoldReason` and `FreezeReason` | ||||||
//! - This footgun: <https://github.com/paritytech/polkadot-sdk/pull/1900#discussion_r1363783609> | ||||||
//! ## The Currency Trait | ||||||
//! | ||||||
//! The [`Currency`](../../../frame_support/traits/tokens/currency/index.html) trait was initially | ||||||
juangirini marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
//! introduced in Substrate to manage the native token balances. This trait was later deprecated in | ||||||
juangirini marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
//! favor of the [`fungible`](../../../frame_support/traits/tokens/fungible/index.html) traits in | ||||||
//! Substrate's PR [#12951](https://github.com/paritytech/substrate/pull/12951). This shift is part | ||||||
//! of a broader initiative to enhance token management capabilities within the framework. This | ||||||
//! deprecation is aimed at providing improved safety and more flexibility for managing assets, | ||||||
//! beyond the capabilities of the original | ||||||
//! [`Currency`](../../../frame_support/traits/tokens/currency/index.html) trait. This transition | ||||||
//! enables more diverse economic models in Substrate. For more details, you can view the discussion | ||||||
//! on the [Tokens Horizon issue](https://github.com/paritytech/polkadot-sdk/issues/327). The | ||||||
//! [`Currency`](../../../frame_support/traits/tokens/currency/index.html) trait is still available | ||||||
//! in Substrate, but it is recommended to use the **fungible** traits instead. The | ||||||
//! [deprecation PR](https://github.com/paritytech/substrate/pull/12951) has a dedicated section on | ||||||
//! upgrading from **Currency** to **fungible**. Besides, this [issue](https://github.com/paritytech/polkadot-sdk/issues/226) | ||||||
//! lists the pallets that have been upgraded to the **fungible** traits, and the ones that are | ||||||
//! still using the [`Currency`](../../../frame_support/traits/tokens/currency/index.html) trait. | ||||||
//! There one could find the relevant code examples for upgrading. | ||||||
//! | ||||||
//! ## Fungible Traits | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are not going to briefly talk about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see |
||||||
//! | ||||||
//! The [`fungible`](../../../frame_support/traits/tokens/fungible/index.html) traits are designed | ||||||
//! for managing currency types, providing a streamlined approach for single-asset operations. | ||||||
//! Fungible is currently preferred over currency as the latter is deprecated. | ||||||
//! | ||||||
//! #### Holds and Freezes | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
//! | ||||||
//! Learn more about this two concepts in | ||||||
//! [`frame_support::traits::tokens::fungible::hold`][1] and | ||||||
//! [`frame_support::traits::tokens::fungible::freeze`][2]. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I believe the link is added automatically in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be able to add it as a dep? |
||||||
//! | ||||||
//! ## Pallet Balances | ||||||
juangirini marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
//! The [`pallet_balances`](../../../pallet_balances/index.html) is a key component in FRAME. It | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
//! is designed for managing native token balances. It plays a crucial role in tracking and | ||||||
//! manipulating the balance of accounts, providing functionalities essential for a wide range of | ||||||
//! 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
//! traits, aligning with the standardized approach for asset management in Substrate. | ||||||
//! | ||||||
//! [1]: ../../../frame_support/traits/tokens/fungible/hold/index.html | ||||||
//! [2]: ../../../frame_support/traits/tokens/fungible/freeze/index.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,26 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! # Freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
//! | ||
//! The traits for putting freezes within a single fungible token class. | ||
//! | ||
//! Freezes can overlap with [Holds](crate::traits::fungible::hold). Since Holds are designed to be | ||
//! infallibly slashed, this means that any logic using a `Freeze` must handle the possibility of | ||
//! the frozen amount being reduced, potentially to zero. A permissionless function should be | ||
//! provided in order to allow bookkeeping to be updated in this instance. E.g. some balance is | ||
//! frozen when it is used for voting, one could use held balance for voting, but nothing prevents | ||
//! this frozen balance from being reduced if the overlapping hold is slashed. | ||
//! | ||
//! ``` | ||
//! |__total__________________________________| | ||
//! |__on_hold__|_____________free____________| | ||
//! |__________frozen___________| | ||
//! |__on_hold__|__ed__| | ||
//! ``` | ||
//! | ||
//! Freezes require a `Reason`, which is configurable and is expected to be an enum aggregated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly mention or link to the exact keyword of |
||
//! across all pallet instances of the runtime. | ||
|
||
use scale_info::TypeInfo; | ||
use sp_arithmetic::{ | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?