Supra Fungible Asset (FA) Module
The Supra Framework's fungible asset module provides a comprehensive standard for creating, managing, and transferring fungible tokens on the Supra. This module enables the creation of fungible assets with any metadata object that is equipped with the Metadata resource.
Module Structure
module supra_framework::fungible_asset {
use supra_framework::aggregator_v2;
use supra_framework::create_signer;
use supra_framework::event;
use supra_framework::function_info;
use supra_framework::object;
use std::string;
use std::features;
use std::error;
use std::option;
use std::signer;
}Friend Modules
The module declares the following friend relationships:
supra_framework::coin- For coin-to-FA migration supportsupra_framework::primary_fungible_store- For primary store managementsupra_framework::supra_account- For account integrationsupra_framework::dispatchable_fungible_asset- For custom dispatch logic
Supply and Validation Constrants
Core Data Structures
FungibleAsset
Represents a specific amount of fungible asset with type safety guarantees. This is ephemeral and cannot be stored directly - it must be deposited back into a store.
Metadata
FungibleStore
Supply Management
Reference Types
Dispatch Functions
Concurrent Balance Tracking
Untransferable Assets
Events
Utility Functions
Returns whether concurrent fungible supply is enabled by default.
Returns whether upgrading to concurrent fungible balance is allowed.
Returns whether concurrent fungible balance is enabled by default.
Returns whether the provided address has a store initialized.
Inline version of store existence check for internal use.
Returns whether the provided address has concurrent fungible balance initialized.
Checks whether the balance of a store is >= amount.
Friend function to check if address balance is at least the specified amount.
Core Functions
Asset Creation
add_fungibility
Creates a fungible asset by adding metadata and supply tracking to an existing object. This returns the capabilities to mint, burn, and transfer.
Parameters:
constructor_ref- Object constructor referencemaximum_supply- Maximum supply behavior:option::none()- Unlimited supply monitoringoption::some(max)- Fixed supply withmaxas maximum
name- Asset name (≤32 characters)symbol- Asset symbol (≤10 characters)decimals- Decimal places (≤32)icon_uri- Icon URI (≤512 characters)project_uri- Project URI (≤512 characters)
Reference Generation
generate_mint_ref
Creates a mint reference that can be used to mint fungible assets. Can only be called at object creation time.
generate_burn_ref
Creates a burn reference that can be used to burn fungible assets. Can only be called at object creation time.
generate_transfer_ref
Creates a transfer reference for freeze/unfreeze/transfer operations. Can only be called at object creation time.
generate_mutate_metadata_ref
Creates a metadata mutation reference. Can only be called at object creation time.
Store Management
create_store
Creates a store for holding fungible assets of a specific type. Applications can use this to create multiple stores for isolating fungible assets for different purposes.
remove_store
Removes an empty store. The store must be completely empty prior to removal.
Asset Operations
mint
Mints the specified amount of fungible asset.
mint_internal
Friend function for minting - can only be called by coin.move for migration.
mint_to
Mints the specified amount directly to a destination store.
burn
Burns a fungible asset, removing it from circulation.
burn_internal
Friend function for burning - can only be called by coin.move for migration.
burn_from
Burns the specified amount from the given store.
address_burn_from
Friend function to burn from a specific address.
Transfer Operations
transfer
Transfers an amount of fungible asset from one store to another. The sender must own the source store.
withdraw
Withdraws an amount of fungible asset from a store by the owner.
deposit
Deposits a fungible asset into a store.
Sanity Check Functions
withdraw_sanity_check
Checks the permissions and conditions for withdraw operations, including:
Owner verification
Dispatch function validation
Frozen state checking
deposit_sanity_check
Validates conditions for deposit operations, including:
Dispatch function validation
Frozen state checking
Internal Operations
deposit_internal
Internal function for depositing fungible assets with event emission.
withdraw_internal
Internal function for withdrawing fungible assets with event emission.
Reference-Based Operations
withdraw_with_ref
Withdraws fungible assets using a TransferRef, ignoring frozen status.
deposit_with_ref
Deposits fungible assets using a TransferRef, ignoring frozen status.
transfer_with_ref
Transfers fungible assets with TransferRef even if stores are frozen.
Asset Manipulation
extract
Extracts a given amount from a fungible asset and returns a new one.
merge
Merges two fungible assets. The destination asset will have the sum of both amounts.
zero
Creates a fungible asset with zero amount. Useful for starting computations.
destroy_zero
Destroys an empty fungible asset.
Metadata Accessor Functions
metadata_from_asset
Returns the underlying metadata object from a fungible asset.
store_metadata
Returns the underlying metadata object from a store.
amount
Returns the amount of a given fungible asset.
asset_metadata
Returns the metadata object from a fungible asset.
mint_ref_metadata
Gets the underlying metadata object from a MintRef.
transfer_ref_metadata
Gets the underlying metadata object from a TransferRef.
burn_ref_metadata
Gets the underlying metadata object from a BurnRef.
object_from_metadata_ref
Gets the underlying metadata object from a MutateMetadataRef.
View Functions
Returns the current supply from the metadata object.
Returns the maximum supply. Returns none if unlimited.
Returns the name of the fungible asset.
Returns the symbol of the fungible asset.
Returns the decimals from the metadata object.
Returns the icon URI from the metadata object.
Returns the project URI from the metadata object.
Returns the complete metadata struct from the metadata object.
Returns the balance of a given store.
Returns whether a store is frozen. Defaults to false if store doesn't exist.
Migration Support
Supra provides migration support from the legacy coin standard through friend functions:
These functions are restricted to the supra_framework::coin module for seamless migration.
Testing Support
The module includes comprehensive test functions for development:
Last updated
