Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
8a4b955
wip
liamaharon Dec 23, 2023
4aa41fd
Merge branch 'master' into liam-tokens-docs
liamaharon Feb 28, 2024
8e24dbc
update cargo.lock
liamaharon Feb 28, 2024
ef7c3dd
wip
liamaharon Feb 28, 2024
8a9a95a
Merge branch 'master' into liam-tokens-docs
liamaharon Feb 29, 2024
1204191
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 1, 2024
1d1b71e
wip fungible docs
liamaharon Mar 13, 2024
db18a5f
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 13, 2024
96c2993
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 13, 2024
3a0c39c
document pallets and traits
liamaharon Mar 15, 2024
c34c01d
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 15, 2024
5d4e2d4
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
f0e9ce5
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
304b6a7
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
bacaa72
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
25c1cb3
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
e86c7a9
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
41a3cb8
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
f389aa7
Update docs/sdk/src/reference_docs/mod.rs
liamaharon Mar 15, 2024
9ff81e1
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
c8d04a9
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
34d33a3
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
39227f2
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
fc10027
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
4ad31f5
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
e56bcbf
Update substrate/frame/balances/src/lib.rs
liamaharon Mar 15, 2024
58aca97
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
ca849d0
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 15, 2024
6101352
Update docs/sdk/src/reference_docs/tokens_in_substrate.rs
liamaharon Mar 15, 2024
44e22cd
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 19, 2024
566dd5d
rename frame tokens
liamaharon Mar 19, 2024
c0eab83
rustfmt
liamaharon Mar 19, 2024
b884b43
address comments
liamaharon Mar 19, 2024
32a86a0
Update substrate/frame/assets/src/lib.rs
liamaharon Mar 19, 2024
1b27d16
Update substrate/frame/balances/src/lib.rs
liamaharon Mar 19, 2024
7ac73c5
link back to parent doc
liamaharon Mar 20, 2024
af05963
add note regarding ItemOf
liamaharon Mar 20, 2024
28ef429
remove frame_currency
liamaharon Mar 20, 2024
d59f203
add additional notes on holds and freezes
liamaharon Mar 21, 2024
cbc8752
further freeze vs hold discussion
liamaharon Mar 21, 2024
463eb3e
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 21, 2024
dd14974
Update substrate/frame/balances/src/lib.rs
liamaharon Mar 22, 2024
1986c08
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
b6924b2
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
193ae2b
address comments
liamaharon Mar 26, 2024
2248dfb
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 26, 2024
7894ca0
Update substrate/frame/support/src/traits/tokens/fungible/mod.rs
liamaharon Mar 26, 2024
a4fd664
address comments
liamaharon Mar 26, 2024
1817539
merge
liamaharon Mar 26, 2024
11ebcfa
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 26, 2024
ed3bfff
fmt
liamaharon Mar 26, 2024
3521ea2
add note about removing hold/freeze reasons
liamaharon Mar 26, 2024
5654274
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
1774c51
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
1e67f42
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
77d9fc9
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
c7cca8a
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 26, 2024
0cb5e77
fix nft docs
liamaharon Mar 26, 2024
0f33d96
Update docs/sdk/src/reference_docs/frame_tokens.rs
liamaharon Mar 29, 2024
d4fd9e0
Merge branch 'master' into liam-tokens-docs
liamaharon Mar 29, 2024
3a8f2b2
Merge branch 'master' into liam-tokens-docs
kianenigma Mar 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
liamaharon committed Mar 19, 2024
commit b884b43e86586c5f019c7c5989e19f694bb71cc8
2 changes: 1 addition & 1 deletion docs/sdk/src/reference_docs/frame_pallet_coupling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
//! For example, all pallets in `polkadot-sdk` that needed to work with currencies could have been
//! tightly coupled with [`pallet_balances`]. But, `polkadot-sdk` also provides [`pallet_assets`]
//! (and more implementations by the community), therefore all pallets use traits to loosely couple
//! with balances or assets pallet. More on this in [`crate::reference_docs::frame_currency`].
//! with balances or assets pallet. More on this in [`crate::reference_docs::frame_tokens`].
//!
//! ## Further References
//!
Expand Down
79 changes: 54 additions & 25 deletions docs/sdk/src/reference_docs/frame_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,74 @@
//! 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 Substrate, and why this
//! - The distinction between token traits and trait implementations in FRAME, and why this
//! distinction is helpful
//! - Token-related traits avaliable in Substrate
//! - Token-related trait implementations in Substrate
//! - 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 with [`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](crate::reference_docs::frame_pallet_coupling#loosely--coupling-pallets),
//! we seperate token logic into traits and trait implementations.
//!
//! ## Traits and Trait Implementations
//!
//! Broadly speaking, token logic in Substrate can be divided into two categories: traits and
//! 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
//! [`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`].
//! 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.
//! 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 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
//! [`pallet_balances`] 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`] AND
//! [`pallet_assets`], along with 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 [`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
//! 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
//! [`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.
//!
//! Read more about coupling, and the benefits to loose coupling
//! [here](crate::reference_docs::frame_pallet_coupling).
//!
//! ##### *Rust Advanced Tip
//!
//! The knowledge that [`pallet_balances`] implements [`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 [`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.
//!
Expand All @@ -70,20 +99,20 @@
//! 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
//! ## Fungible Token Trait Implementations in FRAME
//!
//! [`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
//! 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 [`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 Substrate
//! ## Non-Fungible Tokens in FRAME
//!
//! [`pallet_uniques`] is recommended to use for all NFT use cases in Substrate.
//! [`pallet_uniques`] is recommended to use for all NFT use cases in FRAME.
//! See the crate documentation for more info about this pallet.
//!
//! [`pallet_nfts`] is deprecated and should not be used.
Expand Down