Gav Wood
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Fungibles Module to act as single entry point to fungible tokens supported by a chain. This module only handles asset balance querying and, if available, transfer; it *does not* act as a registry for discovery purposes (that may be handled in a separate module). This is created for two actors: - Wallets & other external RPC-based agents, to be able to query and list all fungible assets on any compatible chain. - Inter-chain asset transfers; specifically for chains to be able to query and transfer assets between them. Realistically, the second use-case will eventually be fulfilled by a fungibles SPREE module, therefore the greatest amount of effort will be spent ensuring the design requirements of the first. ## Identifying and utilising a fungible asset on Polkadot Polkadot will have many chains. Each chain may have 0, 1 or many fungibles. Assets may be hosted by one or more modules, for example the Balances module is able to host a single fungible token whereas the `assets` module can manage multiple. Chains may also be nested, or otherwise host multiple distinct sets of fungibles. We can imagine a simple URI-like format to allow a wallet to be able to identify and index any given asset on Polkadot: `polkadot://<Chain index or address>/<API or module ID>/<Asset index or ID>` For example: - Polkadot DOT token: `polkadot:///balances` - Polkadot single-instance of Balances module on parachain 1: `polkadot://1/balances` - Polkadot multi-instanced index 3 of Balances module on parachain 2: `polkadot://2/balances[3]` - Assuming parachain 3 is a bridge hub, then the asset 5 in the `assets` module of bridge index 4 of that hub: `polkadot://3.4/assets/5` - Assuming parachain 4 is a smart contract chain, then the erc20 asset at address `0xabcdef`: `polkadot://4/erc20/0xabcdef` (A name resolution chain is likely to exist on Polkadot in order to obviate the need for numeric indices, but that's beyond the scope here.) In case a chain writes its own module for managing balances, then there needs to be some abstract (and standard) API that is fulfilled and which wallets can rely on. While we can rely on the module name, instance and/or indexing and to ensure a single asset may be identified, there is the practical matter of actually interacting with a module whose API, though introspectable, is unfamiliar. Wallets, and in particular *light-client* wallets, need some way of "understanding" how to use the module in order to deliver at least two pieces of practical functionality: - How to inspect storage to determine the balance of a particular account. - How to construct a transaction that transfers some balance to a different account. For the latter we will, for now, assume that the transfer is to an account on the same chain. An associate SPREE module will likely handle standards for interchain transfer. Finally, we would also want to expose some meta-API, particularly the capabilities and version information. The fact that this must fully support light-clients means that we cannot use Substrate's runtime APIs and expect it to work (at least not on day 1). Rather, we must work only with events, storage and transactions. One major advantage is that we can assume the existence of the metadata API, which allows us to query constant values, extrinsic/transaction formats and storage item formats. This dramatically reduces the amount of low-level information that needs to be provided when defining a module's API. ## Specifying transaction construction formats Transaction construction formats, at least initially, are likely to be clones of the APIs provided by the Assets and Balances module. As such, it makes sense to simply ratify these APIs by naming portions of them as *capabilities* that may be advertised. Versioning allows us update these APIs, and we can also add entirely new ones should it be needed. These APIs, expressed as strings, may be placed, and thus inspected by wallets, in the module's metadata. In principle, two APIs can be defined (we'll use JSON here), though these may end up just being standard formats obviating the need for any explicit definition in the module itself: - "balances": `{ call: 'transfer', args=[ { contents: DESTINATION }, { contents: VALUE } ]` - "assets": `{ call: 'transfer', args=[ { contents: ID }, { contents: DESTINATION }, { contents: VALUE } ] }` Importantly, `DESTINATION`, `ID` and `VALUE` are all placeholder values. Their datatypes (and thus encoding format can be derived from the metadata of the chain in question). Thus the wallet is capable of filling them with appropriate values (i.e. from its own interface). If, practically speaking, chain metadata isn't enough to allow wallets to accurately deliver these values, then additional fields may be added alongside `contents` to facilitate matters. ## Specifying storage formats While transaction formats are relatively simple, storage of balance data tends to be more complex in practical situations, handling complexities such as reserved and free balances, locks and vesting schedules. While it may be an interesting possibility to design a JSON-based format that can adequately and abstractly express all of these minutiae, it is unneeded for an initial implementation. Rather, we can simply define three possible storage-level APIs supported by the module: - "balances": Conforms to the standard Substrate Balances module's storage format. - "assets": Conforms to the standard Substrate Assets module's storage format. - "custom": Conforms to a custom format as defined by a string, found in the module's metadata. The format of the string in the case of `"custom"` would likely take the form of a list specifying each of several items of storage and how to combine them into a single value. E.g.: - Assuming one single storage item, mapping `AccountId` to `Balance`, then the format specification would be quite trivial: `{ total: [ { item: "Balances", key: ACCOUNT } ] }`. - Supposing that the map was instead from `AccountId` to `(FreeBalance, ReservedBalance)`, then we might specify the format: ``` { total: [ { item: "Balances", key: ACCOUNT, tuple: 0 }, { item: "Balances", key: ACCOUNT, tuple: 1, } ], spendable: [ { item: "Balances", key: ACCOUNT, tuple: 0 } ]` } ``` - Different operations may be used to combine things, for example suppose the mapping is to `(TotalBalance, SpendableBalance)`, then we might specify the format: ``` { total: [ { item: "Balances", key: ACCOUNT, tuple: 0 } ], spendable: [ { item: "Balances", key: ACCOUNT, tuple: 0 }, { item: "Balances", key: ACCOUNT, tuple: 1, combine: MINUS, } ]` } ``` ## WebAssembly A later version of this spec may allow for WebAssembly components to be added into metadata to provide a much richer possibility to inspect and combine storage. Such an API would need to be lightweight (to avoid bloating the runtime), isolatable (to avoid introducing security issues into the runtime) and manage with the fact the all APIs available to light-clients (and thus also to this Wasm blob) for inspecting storage are fully asynchronous.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully