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

Tokens in FRAME Docs #2802

Merged
merged 61 commits into from
Mar 31, 2024
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
wip fungible docs
  • Loading branch information
liamaharon committed Mar 13, 2024
commit 1d1b71e506d5d57a8549dd266392c0c2af228b6f
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pallet-aura = { path = "../../substrate/frame/aura", default-features = false }
# Pallets and FRAME internals
pallet-timestamp = { path = "../../substrate/frame/timestamp" }
pallet-balances = { path = "../../substrate/frame/balances" }
pallet-assets = { path = "../../substrate/frame/assets" }
pallet-preimage = { path = "../../substrate/frame/preimage" }
pallet-transaction-payment = { path = "../../substrate/frame/transaction-payment" }
pallet-utility = { path = "../../substrate/frame/utility" }
pallet-multisig = { path = "../../substrate/frame/multisig" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
//!
//! TODO: Link to multi block migration example/s once PR is merged (<https://github.com/paritytech/polkadot-sdk/pull/2119>).
//!
//! [`GetStorageVersion`]: frame_support::traits::GetStorageVersion
//! [`OnRuntimeUpgrade`]: frame_support::traits::OnRuntimeUpgrade
//! [`StorageVersion`]: frame_support::traits::StorageVersion
//! [`set_code`]: frame_system::Call::set_code
Expand Down
3 changes: 3 additions & 0 deletions docs/sdk/src/reference_docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub mod glossary;
/// Learn about the WASM meta-protocol of all Substrate-based chains.
pub mod wasm_meta_protocol;

/// Learn about the token-related logic in Substrate and how to use it.
pub mod tokens_in_substrate;
liamaharon marked this conversation as resolved.
Show resolved Hide resolved

/// Learn about the differences between smart contracts and a FRAME-based runtime. They are both
/// "code stored onchain", but how do they differ?
pub mod runtime_vs_smart_contract;
Expand Down
19 changes: 13 additions & 6 deletions docs/sdk/src/reference_docs/tokens_in_substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
//! trait implementations.
//!
//! *Traits* define common interfaces that types of token should implement. For example, the
//! [`fungible::Inspect`] trait specifies that implementations of this trait must contain methods
//! for accessing the total issuance of the token, the balance of individual accounts, etc.
//! [`frame_support::traits::fungible::Inspect`] trait specifies that implementations of this trait
//! must contain methods for accessing 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`].
//! 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 and unwieldy tight
Expand Down Expand Up @@ -82,9 +83,15 @@
//!
//! ## Non-Fungible Tokens in Substrate
//!
//! The [`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 Substrate.
//! See the crate documentation for more info about this pallet.
//!
//! The [`pallet_nfts`] is deprecatd and should not be used.
//! [`pallet_nfts`] is deprecated and should not be used.
//!
//! akkk
//! # What Next?
//!
//! - If you are interested in implementing a single fungible token, continue reading the
//! [`frame_support::traits::fungible`] and [`pallet_balances`] docs.
//! - If you are interested in implementing a set of fungible tokens, continue reading the
//! [`frame_support::traits::fungibles`] trait and [`pallet_assets`] docs.
//! - If you are interested in implementing an NFT, continue reading the [`pallet_uniques`] docs.
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
//! - 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.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions substrate/frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
//!
//! Note, you may find the Balances pallet still functions with an ED of zero in some circumstances,
//! however this is not a configuration which is generally supported, nor will it be.
//!
//! [`tokens_in_substrate`]: ../polkadot_sdk_docs/reference_docs/tokens_in_substrate/index.html

#![cfg_attr(not(feature = "std"), no_std)]
mod benchmarking;
Expand Down
70 changes: 68 additions & 2 deletions substrate/frame/support/src/traits/tokens/fungible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,75 @@
//! funds must be removed from an account before it is known precisely what should be done with
//! them.
//!
//! # Holds vs. Freezes
//! ## Terminology
//!
//! TODO: Differentiate between the two.
//! ### Total Balance
//!
//! The sum of an accounts free and held balances.
//!
//! ### Free Balance
//!
//! A portion of an accounts total balance that is not held.
//!
//! ### Held Balance
//!
//! A portion of a users total balance that is not free.
//!
//! Multiple holds stack rather than overlay. This means that if an account has
//! 3 locks for 100 units, the account can spend it's funds for any reason down to 300 units, at
//! which point the holds will start to come into play.
//!
//! Multiple holds are stack on top of another (cumulative) rather than overlay another.
//!
//! ### Frozen Balance
//!
//! An minimum amount a user should not be allowed to withdraw below.
//!
//! Multiple freezes overlay rather than stack on top of another. This means that if an account has
//! 3 locks for 100 units, the account can spend it's funds for any reason down to 100 units, at
//! which point the freezes will start to come into play.
//!
//! ### Minimum Balance (a.k.a. Existential Deposit, a.k.a. ED)
//!
//! The minimum amount of balance that an account must have to exist.
//!
//! ### Untouchable Balance
//!
//! The part of a users free balance they cannot spend, due to ED or Freeze/s.
//!
//! ### Spendable Balance
//!
//! The part of a users free balance they can spend.
//!
//! ## Visualising Balance Components Together 💫
//!
//! ```ignore
//! |__total__________________________________|
//! |__on_hold__|_____________free____________|
//! |__________frozen___________|
//! |__on_hold__|__ed__|
//! |__untouchable__|__spendable__|
//! ```
//!
//! ## Holds vs. Freezes
//!
//! Both holds and freezes are used to prevent an account from using some of its balance.
//!
//! The primary distinction between the two are that:
//! - Holds are cumulative (do not overlap) and are distinct from the free balance
//! - Freezes are not cumulative, and can overlap with each other or with holds
//!
//! ```ignore
//! |__total_____________________________|
//! |__hold_a__|__hold_b__|_____free_____|
//! |__on_hold____________| // <- the sum of all holds
//! |__freeze_a_______________|
//! |__freeze_b____|
//! |__freeze_c________|
//! |__frozen_________________| // <- the max of all freezes
//! ```
//!
//! [`tokens_in_substrate`]: ../../../../polkadot_sdk_docs/reference_docs/tokens_in_substrate/index.html

pub mod conformance_tests;
pub mod freeze;
Expand Down