Asset Tokenization Reference
- tokenized_asset
- proxy
- unlock
The tokenized_asset module operates in a manner similar to the coin library.
When it receives a new One-Time Witness type, it creates a unique representation of a fractional asset. This module uses implementations similar to some methods found in the Coin module. It encompasses functionalities pertinent to asset tokenization, including new asset creation, minting, splitting, joining, and burning. See One-Time Witness in The Move Book for more information.
Structs
-
AssetCapGenerates an
AssetCapfor each new asset represented as a fractional NFT. In most scenarios, create it as an owned object, which you can then transfer to the platform administrator for access-restricted method invocation.struct AssetCap<phantom T> {
id: UID,
// the current supply in circulation
supply: Supply<T>,
// the total max supply allowed to exist at any time
total_supply: u64,
// Determines if the asset can be burned or not
burnable: bool
} -
AssetMetadataThe
AssetMetadatastruct defines the metadata representing the entire asset to fractionalize. This should be a shared object.struct AssetMetadata<phantom T> has key, store {
id: UID,
/// Name of the asset
name: String,
// the total max supply allowed to exist at any time
total_supply: u64,
/// Symbol for the asset
symbol: ascii::String,
/// Description of the asset
description: String,
/// URL for the asset logo
icon_url: Option<Url>
} -
TokenizedAssetThe
TokenizedAssetis minted with a specified balance that is less than or equal to the remaining supply. If theVecMapof an asset is populated with values (indicating multiple unique entries), it is considered an NFT. If theVecMapof an asset is not populated (indicating an absence of individual entries), it is considered an FT.struct TokenizedAsset<phantom T> has key, store {
id: UID,
/// The balance of the tokenized asset
balance: Balance<T>,
/// If the VecMap is populated, it is considered an NFT, else the asset is considered an FT.
metadata: VecMap<String, String>,
/// URL for the asset image (optional)
image_url: Option<Url>,
} -
PlatformCapThe
PlatformCapis the capability issued to the address that deploys the contract. This capability grants specific permissions related to the platform functionalities, allowing the deployer certain controlled actions or access rights within the deployed contract./// Capability that is issued to the one deploying the contract
struct PlatformCap has key, store { id: UID }
Functions
-
initCreates a
PlatformCapand transfers it to the transaction sender.fun init(ctx: &mut TxContext) {} -
new_assetCreates a fresh representation of an asset with its crucial attributes. Returns 2 distinct objects: the
AssetCapandAssetMetadata. These objects encapsulate the necessary information and characteristics that define the asset within the system.public fun new_asset<T: drop>(
witness: T,
total_supply: u64,
symbol: ascii::String,
name: String,
description: String,
icon_url: Option<Url>,
burnable: bool,
ctx: &mut TxContext
): (AssetCap<T>, AssetMetadata<T>) {} -
mintMints a tokenized asset. If new metadata is introduced during this process, the tokenized asset becomes unique, resulting in the creation of an NFT with a balance set to 1. If no new metadata is added, the system classifies the tokenized asset as an FT, permitting its balance to exceed 1 as specified by a provided argument. Returns the tokenized asset object.
public fun mint<T>(
cap: &mut AssetCap<T>,
keys: vector<String>,
values: vector<String>,
value: u64,
ctx: &mut TxContext
): TokenizedAsset<T> {} -
splitReceives a tokenized asset of the FT type with a balance greater than 1 and a value less than the object balance, then performs a split operation. The operation divides the existing tokenized asset into 2 separate tokenized assets. The newly created tokenized asset has a balance equal to the given value, while the balance of the provided object decreases by the specified value. Returns the newly created tokenized asset. This function does not accept tokenized assets of the NFT type.
public fun split<T>(
self: &mut TokenizedAsset<T>,
split_amount: u64,
ctx: &mut TxContext
): TokenizedAsset<T> {} -
joinReceives 2 tokenized assets of the FT type and merges them. The operation increases the balance of the first tokenized asset by the balance of the second one. The system then burns the second tokenized asset. Returns the ID of the burned tokenized asset. This function does not accept tokenized assets of the NFT type.
public fun join<T>(
self: &mut TokenizedAsset<T>,
other: TokenizedAsset<T>
): ID {} -
burnRequires the
AssetCapas a parameter, restricting invocation to the platform admin. Accepts a tokenized asset and burns it. The circulating supply decreases by the balance of the burned item. Requires a tokenized asset that is burnable.public fun burn<T>(
cap: &mut AssetCap<T>,
tokenized_asset: TokenizedAsset<T>
) -
total_supplyReturns the maximum supply of the asset.
public fun total_supply<T>(cap: &AssetCap<T>): u64 {} -
supplyReturns the current circulating supply of the asset.
public fun supply<T>(cap: &AssetCap<T>): u64 {} -
valueReturns the balance of a tokenized asset.
public fun value<T>(tokenized_asset: &TokenizedAsset<T>): u64 {} -
create_vec_map_from_arraysAn internal helper function that populates a
VecMap<String, String>. It assists in the process of filling key-value pairs within theVecMapdata structure.fun create_vec_map_from_arrays(
keys: vector<String>,
values: vector<String>
): VecMap<String, String> {}
The proxy module contains methods that the type owner uses to execute publisher-related operations.
Structs
-
ProxyThe
PROXYstruct represents the One-Time Witness to claim the publisher.struct PROXY has drop {} -
RegistryA shared object that serves as a repository for the
Publisherobject, specifically intended to control and restrict access to the creation and management of transfer policies for tokenized assets. Mutable access to this object is exclusively granted to the actual publisher.struct Registry has key {
id: UID,
publisher: Publisher
} -
ProtectedTPA shared object that stores an empty transfer policy. You must create one per type
<T>generated by a user. The unlock module uses this object.struct ProtectedTP<phantom T> has key, store {
id: UID,
policy_cap: TransferPolicyCap<T>,
transfer_policy: TransferPolicy<T>
}
Functions
-
initCreates the
Publisherobject, encapsulates it within the registry, and shares theRegistryobject.fun init(otw: PROXY, ctx: &mut TxContext) {} -
setup_tpUses the publisher nested within the registry and the sender publisher. Generates and returns a transfer policy and the associated transfer policy cap specific to
TokenizedAsset<T>. The typeTis derived from thePublisherobject.Also generates an empty transfer policy wrapped in a
ProtectedTP<T>object, which is shared. You can use this functionality under specific conditions to override the Kiosk lock rule.public fun setup_tp<T: drop>(
registry: &Registry,
publisher: &Publisher,
ctx: &mut TxContext
): (TransferPolicy<TokenizedAsset<T>>,
TransferPolicyCap<TokenizedAsset<T>>) {} -
new_displayUses the publisher nested within the registry and the sender publisher to generate and return an empty
Displayfor the typeTokenizedAsset<T>, whereTis encapsulated within thePublisherobject.public fun new_display<T: drop>(
registry: &Registry,
publisher: &Publisher,
ctx: &mut TxContext
): Display<TokenizedAsset<T>> {} -
transfer_policyGiven the
ProtectedTP, returns the transfer policy for the typeTokenizedAsset<T>.public(friend) fun transfer_policy<T>(
protected_tp: &ProtectedTP<T>
): &TransferPolicy<T> {} -
publisher_mutOnly accessible by the owner of the platform cap. Requires the registry as an argument to obtain a mutable reference to the publisher.
public fun publisher_mut(
_: &PlatformCap,
registry: &mut Registry
): &mut Publisher {}
The unlock module facilitates the unlocking of a tokenized asset for authorized burning and joining.
It allows tokenized asset type creators to enable these operations for kiosk assets without requiring adherence to the default set of requirements, such as rules or policies.
Structs
-
JoinPromiseA promise object established to prevent attempts of permanently unlocking an object beyond the intended scope of joining.
struct JoinPromise {
/// the item where the balance of the burnt tokenized asset will be added.
item: ID,
/// burned is the id of the tokenized asset that will be burned
burned: ID,
/// the expected final balance of the item after merging
expected_balance: u64
} -
BurnPromiseA promise object created to ensure the permanent burning of a specified object.
struct BurnPromise {
expected_supply: u64
}
Functions
-
asset_from_kiosk_to_joinA helper function that facilitates the joining of tokenized assets locked in a kiosk. It unlocks the tokenized asset set for burning and ensures that another tokenized asset of the same type eventually contains its balance by returning a
JoinPromise.public fun asset_from_kiosk_to_join<T>(
self: &TokenizedAsset<T>, // A
to_burn: &TokenizedAsset<T>, // B
protected_tp: &ProtectedTP<TokenizedAsset<T>>, // unlocker
transfer_request: TransferRequest<TokenizedAsset<T>> // transfer request for b
): JoinPromise {} -
prove_joinDemonstrates that the unlocked tokenized asset is successfully burned and its balance is incorporated into an existing tokenized asset.
public fun prove_join<T>(
self: &TokenizedAsset<T>,
promise: JoinPromise,
proof: ID) {
} -
asset_from_kiosk_to_burnA helper function that facilitates the burning of tokenized assets locked in a kiosk. It assists in unlocking them while ensuring a promise that the circulating supply is reduced, achieved by returning a
BurnPromise.public fun asset_from_kiosk_to_burn<T>(
to_burn: &TokenizedAsset<T>,
asset_cap: &AssetCap<T>,
protected_tp: &ProtectedTP<TokenizedAsset<T>>,
transfer_request: TransferRequest<TokenizedAsset<T>>,
): BurnPromise {
} -
prove_burnEnsures that the circulating supply of the asset cap is reduced by the balance of the burned tokenized asset.
public fun prove_burn<T>(
asset_cap: &AssetCap<T>,
promise: BurnPromise) {
}
template package
An example use case package that enables Rust WASM functionality to support seamless asset creation in the browser.
This is similar to the launchpad approach and serves as the template package whenever a new asset requires representation as a tokenized asset. It effectively allows you to edit fields of this template contract on the fly and publish it with the edits included. This package implements two essential modules, each catering to distinct functionalities required for asset tokenization. More details on how Rust WASM was implemented can be found in the WebAssembly and template package section.
The package contains the following modules:
-
template: This module supports defining a new asset. When you need to represent a new asset as a fractional asset, modify this module to<template>::<TEMPLATE>, with the<template>(in capitals) being the One-Time Witness of this new asset. This module calls theasset_tokenization::tokenized_asset::new_asset(...)method, which facilitates the declaration of new fields for the asset:witness: The One-Time WitnessNEW_ASSETtotal_supply: The total supply allowed to exist at any timesymbol: The symbol for the assetname: The name of the assetdescription: The description of the asseticon_url: The URL for the asset logo (optional)burnable: Boolean that defines if the asset can be burned by an admin
-
genesis: A genesis type of module that includes a One-Time Witness so that the sender can claim the publisher.