Value
Value
represents an amount of fungible tokens on a universe chain and is associated with a predefined set of materials on the Previous chain. This allows fungible tokens to be programmable on both set contracts and kind contracts.
To understand how a Value
element functions within the protocol, imagine a gift card as an object composed of two elements: a Value
element representing the amount of a token, and a Material
element representing the card's background image.
The set contract acts as a vault, holding the specified amount of tokens in the Value
element and ensuring they are owned by the object (meaning whoever owns the object can withdraw or consume the tokens). The kind contract can read the amount of tokens, load materials such as the token symbol or icon images from the Value
element, and generate a new version of the card's image whenever the Value
element is updated.
For a fungible token to be used within the protocol, it must be registered in the token registry. When a token is registered, information such as the token standard, contract address, and associated hash of the materials must be provided.
Representation
A Value
has the following structure:
#![allow(unused)] fn main() { pub struct Value { token_std: u8, token_index: u56, amount: u192, } }
Field Descriptions
Size (bytes) | Field | Type | Description |
---|---|---|---|
1 | token_std | u8 | The token standard. |
7 | token_index | u56 | A unique index assigned by the token registry under the token standard. |
24 | amount | u192 | The amount of the token represented. |
Token Standards
At genesis, the supported token standards for value elements are:
Standard | Value | Description |
---|---|---|
TOKEN_STD_NATIVE | 1 | Native token of the universe chain. |
TOKEN_STD_20 | 2 | ERC-20-like tokens. |
Additional token standards can be registered to support more types of tokens.
Limitations
The protocol allocates 192 bits to the amount
field, allowing a maximum amount of 2^192 - 1
to be represented. While this accommodates most use cases, tokens with higher decimals may face an upper bound limitation.