This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Documentation for assets module #1945
Merged
Merged
Changes from 10 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
35e32f7
WIP - SRML Assets Module README
ltfschoen 2b11c74
docs: Tweaks for consistency
ltfschoen 7fadb76
docs: Add missing newline
ltfschoen 14d701d
review-fix: Remove non-SRML trait dependencies
ltfschoen bc16608
review-fix: Replace const with let
ltfschoen eaedc6c
review-fix: Remove use of compact in signature
ltfschoen b8fa0a7
review-fix: Change const to let since cannot use result of function call
ltfschoen dd69935
fix: Add backticks around type and mention type it derives from
ltfschoen 94d2f3e
review-fix: Update variable names since changed to lowercase since us…
ltfschoen 0383d9b
fix: Change type to bold instead of code
ltfschoen 33465e1
review-fix: Update Asset module
ltfschoen 93024da
refactor: Consistent bullet points. Remove whitespace between items
ltfschoen 9d0c1bb
review-fix: Remove useless blah
ltfschoen f8ffcee
review-fix: Remove Storage Items
ltfschoen 4852b4d
review-fix: Remove Types
ltfschoen 0b63d4a
review-fix: Remove duplicate instructions
ltfschoen 5979ba9
Update srml/assets/src/lib.rs
joepetrowski 372271f
Update srml/assets/src/lib.rs
joepetrowski e53434d
Update srml/assets/src/lib.rs
joepetrowski 9bbd04e
Update srml/assets/src/lib.rs
joepetrowski 8814fc9
Update srml/assets/src/lib.rs
joepetrowski d335b65
Update srml/assets/src/lib.rs
joepetrowski e6e4391
Update srml/assets/src/lib.rs
joepetrowski e0f123f
Update srml/assets/src/lib.rs
joepetrowski d9e4284
Update srml/assets/src/lib.rs
joepetrowski b91d52a
Update srml/assets/src/lib.rs
joepetrowski d714424
Update srml/assets/src/lib.rs
joepetrowski 75b04b1
Update srml/assets/src/lib.rs
joepetrowski 8f2d0b9
Update srml/assets/src/lib.rs
joepetrowski 31b8ad3
Update srml/assets/src/lib.rs
joepetrowski a2dab4d
Update srml/assets/src/lib.rs
joepetrowski 0a80973
review-fix: Remove since will be replaced after macro expansion #2068…
ltfschoen cf3083e
review-fix: Move Goals within overview
ltfschoen 57f99cf
fix: Fix indentation
ltfschoen 76cd804
Merge remote-tracking branch 'origin/master' into luke-22-assets-modu…
joepetrowski d7d65cf
style and a few minor changes
joepetrowski 0c4dcb7
remove Events
joepetrowski a3948e8
capitalization
joepetrowski ac9f29f
Merge branch 'master' into luke-22-assets-module-docs
ltfschoen 319d763
docs: Reword the Goals to remove mention of cold wallets based on dis…
ltfschoen 4334531
Wording
joepetrowski ef9f200
Update lib.rs
gavofyork 0b75448
Update lib.rs
gavofyork 1709427
Update lib.rs
gavofyork 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
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,108 @@ | ||
| # Assets Module | ||
|
|
||
| ## Overview | ||
|
|
||
| The assets module provides functionality for asset management of fungible asset classes with a fixed supply, including: | ||
|
|
||
| * Asset Issuance | ||
| * Asset Transfer | ||
| * Asset Destruction | ||
|
|
||
| The SRML Support Module implements the `Currency` trait abstraction over the SRML Assets Module's fungible assets system. | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Types | ||
|
|
||
| * `AssetId`: `u32` | ||
|
|
||
| ## Public Interface | ||
|
|
||
| ### Supported Origins | ||
|
|
||
| **signed** - Used to issue, transfer, and destroy an asset holding. | ||
|
|
||
| ### Public Immutable functions (getters) | ||
|
|
||
| #### `balance(id: AssetId, who: T::AccountId) -> T::Balance` | ||
|
|
||
| #### `total_supply(id: AssetId) -> T::Balance` | ||
|
|
||
| ### Public Mutable functions (changing state) | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### `issue(origin, total: T::Balance)` | ||
|
|
||
| #### `transfer(origin, id: AssetId, target: <T::Lookup as StaticLookup>::Source, amount: T::Balance)` | ||
|
|
||
| #### `destroy(origin, id: AssetId)` | ||
|
|
||
| ### Events: | ||
|
|
||
| #### `Issued(AssetId, AccountId, Balance)` | ||
|
|
||
| #### `Transferred(AssetId, AccountId, AccountId, Balance)` | ||
|
|
||
| #### `Destroyed(AssetId, AccountId, Balance)` | ||
|
|
||
| ## Usage | ||
|
|
||
| The following example shows how to use the Asset Module in your custom module to query an account's asset holding, and query the total supply of an asset and an account's asset holding balance. | ||
|
|
||
| **1. Import Asset Module and Types** | ||
|
|
||
| Import the `assets` module and derive your custom module configuration traits from the `assets` module trait. | ||
|
|
||
| ```rust | ||
| use assets; | ||
|
|
||
| pub trait Trait: assets::Trait { } | ||
| ``` | ||
|
|
||
| **2. Import Accounts** | ||
|
|
||
| ```rust | ||
| const ALICE: u64 = 1; | ||
| const BOB: u64 = 2; | ||
|
|
||
| // Initial Asset ID is 0 | ||
| let initial_asset_id: u32 = <assets::Module<T>>::next_asset_id(); | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const FIXED_SUPPLY: u64 = 100; | ||
| ``` | ||
|
|
||
| **3. Issue a new Fungible Asset to an Account** | ||
|
|
||
| Issue the `total` amount of a new class of fungible asset with a fixed supply of units to a signed sender's (`origin`) account (i.e. Alice) and trigger the `Issued` event that contains the generated `AssetId`. | ||
|
|
||
| ```rust | ||
| <assets::Module<T>>::issue(Origin::signed(&ALICE), FIXED_SUPPLY); | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| **4. Transfer a Fungible Asset between Accounts** | ||
|
|
||
| Transfer a signed sender's (i.e. Alice) account holding of an asset's `AssetId` to a `target` recipient account (i.e. Bob) using the public call `transfer`. It only triggers the `Transferred` event if the transfer is valid. | ||
|
|
||
| ```rust | ||
| <assets::Module<T>>::transfer(Origin::signed(&ALICE), initial_asset_id, BOB, FIXED_SUPPLY); | ||
| ``` | ||
|
|
||
| **5. Destroy the Fungible Asset holding of an Account** | ||
|
|
||
| Destroy a signed sender's (i.e. Alice) entire account holding of a fungible asset and trigger the `Destroyed` event if they have a non-zero balance. | ||
|
|
||
| ```rust | ||
| <assets::Module<T>>::destroy(Origin::signed(&ALICE), initial_asset_id); | ||
| ``` | ||
|
|
||
| **6. Query the Fungible Asset holding of an Account** | ||
|
|
||
| Query an account's holding balance (i.e. Alice) of a fungible asset by calling the asset module's `balance` function. | ||
|
|
||
| ```rust | ||
| let balance = <assets::Module<T>>::balance(initial_asset_id, Origin::signed(&ALICE)); | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| **7. Query the Total Supply of a Fungible Asset** | ||
|
|
||
| Query the total supply of a fungible asset that has been issued by calling the asset module's `total_supply` function. | ||
|
|
||
| ```rust | ||
| let total_supply = <assets::Module<T>>::total_supply(initial_asset_id); | ||
| ``` | ||
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.