-
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
Merged
Merged
Tokens in FRAME Docs #2802
Changes from 58 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
8a4b955
wip
liamaharon 4aa41fd
Merge branch 'master' into liam-tokens-docs
liamaharon 8e24dbc
update cargo.lock
liamaharon ef7c3dd
wip
liamaharon 8a9a95a
Merge branch 'master' into liam-tokens-docs
liamaharon 1204191
Merge branch 'master' into liam-tokens-docs
liamaharon 1d1b71e
wip fungible docs
liamaharon db18a5f
Merge branch 'master' into liam-tokens-docs
liamaharon 96c2993
Merge branch 'master' into liam-tokens-docs
liamaharon 3a0c39c
document pallets and traits
liamaharon c34c01d
Merge branch 'master' into liam-tokens-docs
liamaharon 5d4e2d4
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon f0e9ce5
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon 304b6a7
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon bacaa72
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon 25c1cb3
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon e86c7a9
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon 41a3cb8
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon f389aa7
Update docs/sdk/src/reference_docs/mod.rs
liamaharon 9ff81e1
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon c8d04a9
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon 34d33a3
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon 39227f2
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon fc10027
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon 4ad31f5
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon e56bcbf
Update substrate/frame/balances/src/lib.rs
liamaharon 58aca97
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon ca849d0
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon 6101352
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon 44e22cd
Merge branch 'master' into liam-tokens-docs
liamaharon 566dd5d
rename frame tokens
liamaharon c0eab83
rustfmt
liamaharon b884b43
address comments
liamaharon 32a86a0
Update substrate/frame/assets/src/lib.rs
liamaharon 1b27d16
Update substrate/frame/balances/src/lib.rs
liamaharon 7ac73c5
link back to parent doc
liamaharon af05963
add note regarding ItemOf
liamaharon 28ef429
remove frame_currency
liamaharon d59f203
add additional notes on holds and freezes
liamaharon cbc8752
further freeze vs hold discussion
liamaharon 463eb3e
Merge branch 'master' into liam-tokens-docs
liamaharon dd14974
Update substrate/frame/balances/src/lib.rs
liamaharon 1986c08
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon b6924b2
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon 193ae2b
address comments
liamaharon 2248dfb
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon 7894ca0
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon a4fd664
address comments
liamaharon 1817539
merge
liamaharon 11ebcfa
Merge branch 'master' into liam-tokens-docs
liamaharon ed3bfff
fmt
liamaharon 3521ea2
add note about removing hold/freeze reasons
liamaharon 5654274
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon 1774c51
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon 1e67f42
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon 77d9fc9
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon c7cca8a
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon 0cb5e77
fix nft docs
liamaharon 0f33d96
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon d4fd9e0
Merge branch 'master' into liam-tokens-docs
liamaharon 3a8f2b2
Merge branch 'master' into liam-tokens-docs
kianenigma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // 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. | ||
|
|
||
| //! # FRAME Tokens | ||
| //! | ||
| //! This reference doc serves as a high-level overview of the token-related logic in FRAME, and | ||
| //! how to properly apply it to your use case. | ||
| //! | ||
| //! On completion of reading this doc, you should have a good understanding of: | ||
| //! - The distinction between token traits and trait implementations in FRAME, and why this | ||
| //! distinction is helpful | ||
| //! - Token-related traits avaliable in FRAME | ||
| //! - Token-related trait implementations in FRAME | ||
| //! - How to choose the right trait or trait implementation for your use case | ||
| //! - Where to go next | ||
| //! | ||
| //! ## Getting Started | ||
| //! | ||
| //! The most ubiquitous way to add a token to a FRAME runtime is [`pallet_balances`]. Read | ||
| //! more about pallets [here](crate::polkadot_sdk::frame_runtime#pallets). | ||
| //! | ||
| //! You may then write custom pallets that interact with [`pallet_balances`]. The fastest way to | ||
| //! get started with that is by | ||
| //! [tightly coupling](crate::reference_docs::frame_pallet_coupling#tight-coupling-pallets) your | ||
| //! custom pallet to [`pallet_balances`]. | ||
| //! | ||
| //! However, to keep pallets flexible and modular, it is often prefered to | ||
| //! [loosely couple](crate::reference_docs::frame_pallet_coupling#loosely--coupling-pallets). | ||
| //! | ||
| //! To achieve | ||
| //! loose coupling, | ||
liamaharon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! we separate token logic into traits and trait implementations. | ||
| //! | ||
| //! ## Traits and Trait Implementations | ||
| //! | ||
| //! Broadly speaking, token logic in FRAME can be divided into two categories: traits and | ||
| //! trait implementations. | ||
| //! | ||
| //! **Traits** define common interfaces that types of tokens should implement. For example, the | ||
| //! [`fungible::Inspect`](`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 | ||
| //! [`fungible::Inspect`](`frame_support::traits::fungible::Inspect`)*. It provides the concrete way | ||
| //! of inspecting the total issuance, balance of accounts, etc. There can be many implementations of | ||
| //! the same traits. | ||
| //! | ||
| //! The distinction between traits and trait implementations is helpful because it allows pallets | ||
| //! and other logic to be generic over their dependencies, avoiding tight coupling. | ||
| //! | ||
| //! To illustrate this with an example let's consider [`pallet_preimage`]. This pallet takes a | ||
| //! deposit in exchange for storing a preimage for later use. A naive implementation of the | ||
| //! pallet may use [`pallet_balances`] in a tightly coupled manner, directly calling methods | ||
| //! on the pallet to reserve and unreserve deposits. This approach works well, | ||
| //! until someone has a use case requiring that an asset from a different pallet such as | ||
| //! [`pallet_assets`] is used for the deposit. Rather than tightly couple [`pallet_preimage`] to | ||
| //! [`pallet_balances`], [`pallet_assets`], and every other token-handling pallet a user | ||
| //! could possibly specify, [`pallet_preimage`] does not specify a concrete pallet as a dependency | ||
| //! but instead accepts any dependency which implements the | ||
| //! [`currency::ReservableCurrency`](`frame_support::traits::tokens::currency::ReservableCurrency`) | ||
| //! trait, namely via its [`Config::Currency`](`pallet_preimage::pallet::Config::Currency`) | ||
| //! associated type. 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. | ||
| //! | ||
| //! Read more about coupling, and the benefits of loose coupling | ||
| //! [here](crate::reference_docs::frame_pallet_coupling). | ||
| //! | ||
| //! ##### *Rust Advanced Tip | ||
liamaharon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| //! | ||
| //! The knowledge that [`pallet_balances`] implements | ||
| //! [`fungible::Inspect`](`frame_support::traits::fungible::Inspect`) is not some arcane knowledge | ||
| //! that you have to know by heart or memorize. One can simply look at the list of the implementors | ||
| //! of any trait in the Rust Doc to find all implementors (e.g. | ||
| //! <https://paritytech.github.io/polkadot-sdk/master/frame/traits/tokens/fungible/trait.Mutate.html#implementors>), | ||
| //! or use the `rust-analyzer` `Implementations` action. | ||
| //! | ||
| //! ## Fungible Token Traits in FRAME | ||
| //! | ||
| //! The [`fungible`](`frame_support::traits::fungible`) crate contains the latest set of FRAME | ||
| //! fungible token traits, and is recommended to use for all new logic requiring a fungible token. | ||
| //! See the crate documentation for more info about these fungible traits. | ||
| //! | ||
| //! [`fungibles`](`frame_support::traits::fungibles`) provides very similar functionality to | ||
| //! [`fungible`](`frame_support::traits::fungible`), except it supports managing multiple tokens. | ||
| //! | ||
| //! You may notice the trait [`Currency`](`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 [`fungible`](`frame_support::traits::fungible`) ([tracking issue](https://github.com/paritytech/polkadot-sdk/issues/226)). | ||
| //! | ||
| //! ## Fungible Token Trait Implementations in FRAME | ||
| //! | ||
| //! [`pallet_balances`] implements [`fungible`](`frame_support::traits::fungible`), and is the most | ||
| //! commonly used fungible implementation in FRAME. Most of the time, it's used for managing the | ||
| //! native token of the blockchain network it's used in. | ||
| //! | ||
| //! [`pallet_assets`] implements [`fungibles`](`frame_support::traits::fungibles`), and is another | ||
| //! popular fungible token implementation. It supports the creation and management of multiple | ||
| //! assets in a single crate, making it a good choice when a network requires more assets in | ||
| //! addition to its native token. | ||
| //! | ||
| //! ## Non-Fungible Tokens in FRAME | ||
| //! | ||
| //! [`pallet_nfts`] is recommended to use for all NFT use cases in FRAME. | ||
| //! See the crate documentation for more info about this pallet. | ||
| //! | ||
| //! [`pallet_uniques`] is deprecated and should not be used. | ||
| //! | ||
| //! | ||
| //! # What Next? | ||
| //! | ||
| //! - If you are interested in implementing a single fungible token, continue reading the | ||
| //! [`fungible`](`frame_support::traits::fungible`) and [`pallet_balances`] docs. | ||
| //! - If you are interested in implementing a set of fungible tokens, continue reading the | ||
| //! [`fungibles`](`frame_support::traits::fungibles`) trait and [`pallet_assets`] docs. | ||
| //! - If you are interested in implementing an NFT, continue reading the [`pallet_nfts`] docs. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.