-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Tokens in FRAME Docs #2802
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
Tokens in FRAME Docs #2802
Changes from 11 commits
8a4b955
4aa41fd
8e24dbc
ef7c3dd
8a9a95a
1204191
1d1b71e
db18a5f
96c2993
3a0c39c
c34c01d
5d4e2d4
f0e9ce5
304b6a7
bacaa72
25c1cb3
e86c7a9
41a3cb8
f389aa7
9ff81e1
c8d04a9
34d33a3
39227f2
fc10027
4ad31f5
e56bcbf
58aca97
ca849d0
6101352
44e22cd
566dd5d
c0eab83
b884b43
32a86a0
1b27d16
7ac73c5
af05963
28ef429
d59f203
cbc8752
463eb3e
dd14974
1986c08
b6924b2
193ae2b
2248dfb
7894ca0
a4fd664
1817539
11ebcfa
ed3bfff
3521ea2
5654274
1774c51
1e67f42
77d9fc9
c7cca8a
0cb5e77
0f33d96
d4fd9e0
3a8f2b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,97 @@ | ||||||
| // This file is part of polkadot-sdk. | ||||||
| // | ||||||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||
| // | ||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| // you may not use this file except in compliance with the License. | ||||||
| // You may obtain a copy of the License at | ||||||
| // | ||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| // | ||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
|
|
||||||
| //! # Tokens in Substrate | ||||||
| //! | ||||||
| //! This reference doc serves as a high-level overview of the token-related logic in Substrate and | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! how to properly apply it to your usecase. | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! | ||||||
| //! On completion of reading this doc, you should have a good understanding of | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! - The distinction between token traits and trait implementations in Substrate, and why this | ||||||
| //! distinction is helpful | ||||||
| //! - Token-related traits avaliable in Substrate | ||||||
| //! - Token-related trait implementations in Substrate | ||||||
| //! - How to choose the right trait or trait implementation for your use case | ||||||
| //! - Where to go next | ||||||
| //! | ||||||
| //! ## Traits and Trait Implementations | ||||||
| //! | ||||||
| //! Broardly speaking, token logic in Substrate can be divided into two categories: traits and | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! trait implementations. | ||||||
| //! | ||||||
| //! **Traits** define common interfaces that types of token should implement. For example, the | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! [`frame_support::traits::fungible::Inspect`] trait specifies an interface for *inspecting* | ||||||
| //! token state such as the total issuance of the token, the balance of individual accounts, etc. | ||||||
| //! | ||||||
| //! **Trait implementations** are concrete implementations of these traits. For example, one of the | ||||||
| //! many traits [`pallet_balances`] implements is [`frame_support::traits::fungible::Inspect`]. | ||||||
| //! | ||||||
| //! The distinction between traits and trait implementations is helpful because it allows pallets | ||||||
| //! and other logic to be generic over their dependencies, avoiding cumbersome pallet tight | ||||||
| //! coupling. | ||||||
| //! | ||||||
| //! To illustrate this with an example let's consider [`pallet_preimage`]. This pallet takes a | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! deposit in exchange for storing some preimage for use later. A naive implementation of the | ||||||
| //! pallet may use [`pallet_balances`] as a dependency, and directly call the methods exposed by | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! [`pallet_balances`] to reserve and unreserve deposits. This approach works well, until someone | ||||||
| //! has a usecase requiring that an asset from a different pallet such as [`pallet_assets`] is | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! used for the deposit. Rather than tightly couple [`pallet_preimage`] to [`pallet_balances`] AND | ||||||
| //! [`pallet_assets`], along with every other token type pallet a user could possibly specify, | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! [`pallet_preimage`] does not specify a concrete pallet as a dependency but instead accepts any | ||||||
| //! dependency which implements the [`frame_support::traits::tokens::currency::ReservableCurrency`] | ||||||
|
||||||
| //! trait. This allows [`pallet_preimage`] to support any arbitrary pallet implementing this trait, | ||||||
| //! without needing any knowledge of what those pallets may be or requiring changes to support new | ||||||
| //! pallets which may be written in the future. | ||||||
| //! | ||||||
| //! ## Fungible Token Traits in Substrate | ||||||
| //! | ||||||
| //! The [`frame_support::traits::fungible`] crate contains the latest set of Substrate | ||||||
| //! fungible token traits, and is recommended to use for all new logic requiring a fungible tokens. | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! See the crate documentation for more info about these fungible traits. | ||||||
| //! | ||||||
| //! [`frame_support::traits::fungibles`] provides very similar functionality to | ||||||
| //! [`frame_support::traits::fungible`], except it supports managing multiple tokens. | ||||||
| //! | ||||||
| //! You may notice the trait [`frame_support::traits::Currency`] with similar functionality is also | ||||||
| //! used in the codebase, however this trait is deprecated and existing logic is in the process of | ||||||
| //! being migrated to [`frame_support::traits::fungible`] ([tracking issue](https://github.com/paritytech/polkadot-sdk/issues/226)). | ||||||
| //! | ||||||
| //! ## Fungible Token Trait Implementations in Substrate | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! | ||||||
| //! [`pallet_balances`] implements [`frame_support::traits::fungible`], and is the most commonly | ||||||
| //! used fungible implementation in Substrate. Most of the time, it's used for managing the native | ||||||
| //! token of the blockchain network. | ||||||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! | ||||||
| //! [`pallet_assets`] implements [`frame_support::traits::fungibles`], and is another popular | ||||||
| //! fungible token implementation. It supports the creation and management of multiple assets in a | ||||||
|
||||||
| //! fungible token implementation. It supports the creation and management of multiple assets in a | |
| //! fungible tokens implementation. It supports the creation and management of multiple assets in a |
Outdated
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.
It's actually the other way around 😅
Outdated
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.
| //! - If you are interested in implementing an NFT, continue reading the [`pallet_uniques`] docs. | |
| //! - If you are interested in implementing an NFT, continue reading the [`pallet_nfts`] docs. |
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,16 @@ | |
|
|
||
| //! # Assets Pallet | ||
| //! | ||
| //! A simple, secure module for dealing with fungible assets. | ||
| //! A simple, secure module for dealing with sets of assets implementing | ||
| //! [`fungible`](frame_support::traits::fungible) traits, via | ||
| //! [`fungibles`](frame_support::traits::fungibles) traits. | ||
| //! | ||
| //! The pallet makes heavy use of concepts such as Holds and Freezes from the | ||
| //! [`frame_support::traits::fungible`] traits, therefore you should read and understand those docs | ||
| //! as a prerequisite to understanding this pallet. | ||
| //! | ||
| //! See the [`tokens_in_substrate`] reference docs for more information about the place of the | ||
| //! Assets pallet in Substrate. | ||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! ## Overview | ||
| //! | ||
|
|
@@ -133,6 +142,8 @@ | |
| //! | ||
| //! * [`System`](../frame_system/index.html) | ||
| //! * [`Support`](../frame_support/index.html) | ||
| //! | ||
| //! [`tokens_in_substrate`]: ../polkadot_sdk_docs/reference_docs/tokens_in_substrate/index.html | ||
|
||
| // This recursion limit is needed because we have too many benchmarks and benchmarking will fail if | ||
| // we add more without this limit. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.