This document offers a description of the design and implementation of the Fungible Resource Manager blueprint. Additionally, this document provides an API reference for all its methods, functions and events.
Background
In Radix, a Resource is a native concept used to implement use-cases typically associated with “tokens” or “assets”. You can learn more about its high-level design at Resources.
A “Fungible Resource” is a kind of Resource operating on arbitrary quantities, which can be split and combined freely (i.e. its units do not have distinct identity nor individual metadata). Detailed behaviors of all units of a specific Fungible Resource is defined by its Fungible Resource Manager. This includes the rules for:
the Resource’s maximum divisibility,
minting and burning the Resource’s units,
freezing and recalling the Resource from Vaults,
tracking the Resource’s total supply.
Many functionalities of a Fungible Resource are implemented by Fungible Vault, Fungible Bucket and Fungible Proof, which are separate Native Blueprints (covered in detail by their respective documentation pages). The sections below focus on the FungibleResourceManager
Blueprint itself.
Optional Features
Not every Fungible Resource needs to satisfy the same set of use-cases. For this reason, the set of blueprint Features which can be optionally present on a FungibleResourceManager
instance is quite broad:
track_total_supply
- whether the total supply of the Resource should be tracked,vault_freeze
- whether a Vault holding the Resource can ever be frozen,vault_recall
- whether the Resource can ever be recalled from a Vault,mint
- whether more of the Resource (above initial supply) can ever be minted,burn
- whether the Resource can ever be burned.
On-ledger State
The FungibleResourceManager
blueprint defines two fields:
divisibility
, holding an integer in the inclusive range[0, 18]
, denoting a number of decimal places that the Resource can be split into. In other words: a precision of fixed-point fractional operations performed on the Resource’s amounts.total_supply
(only present if thetrack_total_supply
Feature is enabled), holds an automatically-maintained amount of all units in circulation at any moment (i.e. minted so far and not burned yet).
API Reference
Functions
create
Defines a new fungible Resource (i.e. creates its Manager).
Name |
|
Type | Function |
Callable By | Public |
Arguments |
|
Returns |
|
create_with_initial_supply
Defines a new fungible Resource (i.e. creates its Manager) in the same way as create does, and simultaneously mints the requested amount.
This variant is useful e.g. for creating a fixed supply of a non-mintable Resource.
Name |
|
Type | Function |
Callable By | Public |
Arguments |
|
Returns | A tuple containing:
|
Methods
mint
Creates the requested amount of the Resource.
Note: the mint
feature must be enabled on the Resource Manager.
Name |
|
Type | Method |
Callable By | Public - requires the |
Arguments |
|
Returns |
|
burn
Destroys the given bucket of the Resource.
Note: the burn
feature must be enabled on the Resource Manager.
Name |
|
Type | Method |
Callable By | Public - requires the |
Arguments |
|
Returns | Nothing |
package_burn
Destroys the given bucket of the Resource, in the same way as burn
does. This is an internal method needed to allow burning Resources from a Vault.
Note: the burn
feature must be enabled on the Resource Manager.
Name |
|
Type | Method |
Callable By | Own package only. |
Arguments |
|
Returns | Nothing |
create_empty_vault
Creates a new empty Vault tailored for storing the managed Resource and supporting the features configured on this Resource Manager.
Name |
|
Type | Method |
Callable By | Public |
Arguments | None |
Returns |
|
create_empty_bucket
Creates a new empty Fungible Bucket tailored for holding the managed Resource.
Name |
|
Type | Method |
Callable By | Public |
Arguments | None |
Returns |
|
get_resource_type
Queries the managed Resource’s type.
Name |
|
Type | Method |
Callable By | Public |
Arguments | None |
Returns |
|
get_total_supply
Queries the total amount of all units of this Resource currently in circulation.
Note: the track_total_supply
feature must be enabled on the Resource Manager.
Name |
|
Type | Method |
Callable By | Public |
Arguments | None |
Returns |
|
amount_for_withdrawal
Converts the input amount to an actual withdrawal amount, taking the Resource’s configured divisibility
and the given rounding mode into account.
Name |
|
Type | Method |
Callable By | Public |
Arguments |
|
Returns |
|
drop_empty_bucket
Drops the given empty Fungible Bucket.
Note: passing a non-empty Bucket will result in an error.
Name |
|
Type | Method |
Callable By | Public |
Arguments |
|
Returns | Nothing |
Events
A FungibleResourceManager
component instance can be a source of the following events:
VaultCreationEvent
{
// The ID of the created Vault.
vault_id: NodeId
}
Emitted when a new Vault for the managed Resource is created (i.e. on create_empty_vault
API call).
MintFungibleResourceEvent
{
// The minted amount.
amount: Decimal,
}
Emitted when some amount of the managed Resource is minted (i.e. on the explicit mint
API call, but also on create_with_initial_supply
).
BurnFungibleResourceEvent
{
// The burned amount.
amount: Decimal
}
Emitted when some amount of the managed Resource is burned (i.e. on the explicit burn/package_burn
API calls, but also internally when burning the transaction fees).