Updates
- 2021.11.29 Add Rule 3 and Rule 4 for info_cell od single owner sUDT, add Rule 3 for info_cell of script-drive sUDT.
1. Overview
sUDT is a very simple udt standard. With the udt deployed by this standard, we can only get the balance from the chain, but not the token name, token symbol, decimals and other parameters.
In order to extend the existing sUDT standard, it is necessary to design a scheme to store token information and bind it to the corresponding sUDT, but does not destroy any compatibility with the existing sUDT.
There is a proposal here[A SUDT Information Storage Meta Cell Design Proposal], but need improvement.
2. sUDT Info Cell
In info_cell, the most basic information that must be included is token_name, token_symbol and decimals. As for total supply and balance, they can all be obtained by indexing the cell.
A SUDT Info cell in specification looks like following:
data:
decimals: uint8
name: Common knowledge Byte
symbol: CKB
extra: {website:"https://nervos.org"} // optional
type:
code_hash: sudt_info type script
args: sudt type script hash or type_ID
lock:
sUDT creator defined
The format of the data field encoding can be determined as a certain serialization scheme, such as molecule
or json
, we need to be clear which one to use in order to standardize. It is recommended to use json, but using other formats may reduce the occupation of CKB, so suggestions can be made.
Data:
- decimals: (uint8 type) the number of decimal digits used by the token, if decimals is 8 it means that the token can be divided to 0.00000001 at least.
- tokenname: name of token
- symbol: identifier of the token, such as “HIX”
- extra: Anything you want to write, such as the website, the hash value of a certain picture, etc.
The first three items are parameters that must be filled in, and information can be added as required.
3. For Single Owner sUDT
The issuance of sUDT on CKB is controlled by lockscript, so the simplest sUDT is issued by an individual or organization using a lockscript controlled by a private key, such as USDC and other stable coins.
For this type of UDT, you can construct an info_cell while minting sUDT, whose type code_hash is Info_cell type, its args is sUDT’s type_script hash. Info_cell will check whether the transaction meets the conditions.
// Issue new SUDT/SUDT_Info
Inputs:
<... one of the input cell must have owner lock script as lock>
Outputs:
SUDT_Cell:
Data:
amount: uint128
Type:
code_hash: simple_udt type script
args: owner lock script hash (...)
Lock:
<user defined>
SUDT_Info_Cell:
Data:
decimals: uint8
tokenname: xxxx
symbol: xxx
Type:
code_hash: sudt_info type script
args: sudt type script hash
Lock:
<user defined>
The following rules should be met in a SUDT Info Cell (typescript):
- Rule 1: In this transaction, at least one sUDT cell must exist in the output cell, and the hash of its typescript matches the args of Info_cell.
- Rule 2: In this transaction, at least one cell must exist in the input cell, and its lockscript is the owner lockscript of sUDT.
- Rule 3: the lockscript of info_cell should be set to dead lock by default, in some cases, developers can choose other lockscript.
- Rule 4: If there are multiple Info_cells, choose the info_cell with the smallest block height at the time of generation. If it is at the same block height, choose the info_cell with the smallest transaction index. The same transaction cannot generate two info_cells.
4. For Script-drive sUDT
However, there is another type of sUDT on CKB, which is not issued by a lockscript controlled by a private key, but follows a specific script logic. Such as NexisDAO’s dCKB and Tai, and the previous Info_cell design is no longer suitable for this situation.
Since anyone can mint sUDT while following the script logic, if we continue to use the previous logic, anyone can generate the corresponding info_cell. So we need to add new logic on the basis of the previous design.
// Issue new SUDT/SUDT_Info
Inputs:
<any cell>
Outputs:
SUDT_Info_Cell:
Data:
decimals: uint8
tokenname: xxxx
symbol: xxx
Type:
code_hash: sudt_info type script
args: type_id
Lock:
<user defined>
The following rules should be met in a SUDT Info Cell (typescript):
- Rule1: the cell data conforms to the format.
- Rule2: args conform to the rules of type id.
- Rule 3: the lockscript of info_cell should be set to dead lock by default, in some cases, developers can choose other lockscript.
The type script of the info cell checks whether the transaction satisfies one of the two logics(single-owner or script-driven) above.
After constructing this Info Cell, use the hash of its type_script as the first 32 bytes of the args of the Owner lockscript of sUDT. Then the Info cell is bound to the sUDT, and the owner of the info_cell can continue to change the information of the Info_cell.
Because Info Cell will be generated before sUDT is created, it is recommended to set it to a recognized format standard, otherwise it will be troublesome to upgrade UDT in order to meet the parsing standard later.
Maybe we can refer to the script design, that is, use 33Byte to specify an Info_cell. When theflag byte is 0, the 32Bytes of args is the hash of a certain cell data. When the flag byte is 1, look for a cell whose type_hash conforms to args.