There's a desire to create hard capped tokens but with SUDT it's not possible. Leveraging the modular design of XUDT, we can build an extension plugin that help create hard-capped tokens.
make all-via docker
By this design, the xudt tokens of this "type" (hard capped) will link to a "remaining amount" cell. In each creation transaction of this type, the "remaining amount cell" must be consumed/destroyed and created with a new remaining amount - effectively maintaining a number for "the remaining amount". Guides to create this remaining amount cell will be put below.
- xudt_rce binary cell
- Hard_cap extension binary cell (hard_cap.so)
- "Remaining amount" cell lock script binary (ramt_cell_lock)
Note: The "remaining amount cell" must be protected by the lockScript ramt_cell_lock.c
A remaining amount cell, just like any other cell, contains following major fields:
{
lock: <remaining-amount-cell-lock-script>,
type: <typeid>,
data: <remaining-amount::4bytes>
}
- With remaining-amount-cell-lock-script:
{
codeHash: <remaining-amount-cell-binary-hash>,
hashType: "data1",
args: "0x"
}
- With typeId: to create a typeId, follow this guide.
- With remaining-amount: a 4 bit LE hexa number that holds the value of the remaining amount.
A hard-capped XUDT token cell, just like any other cell, contains following major fields:
{
lock: <owner-lock>,
type: <hard-capped-xudt-type-script>,
data: <amount>+ ...
}
The important part is the hard-capped-xudt-type-script which lables + marks our tokens:
{
codeHash: <xudt_rce code hash>
hashType: "data1"
args: <owner's lockscript hash> + <xudt flag> + <ScriptVector>
}
- With Script vector contains 1 Script element:
{
codeHash: <hard_cap code hash>
hashType: "data1"
args: <remaining amount cell's typeId hash>
}
In three modes: creation, transfer, and burn. This extension only has effects on the 'creation' mode.
Token creation is as simple as with SUDT but it is required to place the "remaining amount" cell in the inputs, and calculate another "remaning supply" in the outputs and inputs with the correct remaining-amount calculation. Otherwise token creation will fail
![Screenshot 2024-05-08 at 15 05 10](https://private-user-images.githubusercontent.com/70423834/328807324-16a2d9aa-ddfb-485a-975a-55866f49bf98.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTMzNjcsIm5iZiI6MTcyNDMxMzA2NywicGF0aCI6Ii83MDQyMzgzNC8zMjg4MDczMjQtMTZhMmQ5YWEtZGRmYi00ODVhLTk3NWEtNTU4NjZmNDliZjk4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIyVDA3NTEwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMwYTZlYmRjNjZkZmFiZjFiMjY5MGE1MjNlMTU2ZGNmMGJlNTRmMDMwODdiMzk3ODhiMDNkYTE1ODVlOTM3YWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zVKny5Be1PY6aMv2BWWurunp8zgZbi7v2KlaibRweRA)
When you see hashType: "data1",
present in a lockscript or a typescript in this doc, it means the lock or type are not upgradeable. This repo is a personal project and it might contain bugs and need some auditing work to be deploy on-chain forever with option "data1". Consider to use hashType: "type",
and make it upgradeable when needed. For upgradeable scripts, follow https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0022-transaction-structure/0022-transaction-structure.md#upgradable-script for more information.
https://github.com/tea2x/developer-training-course/blob/master/Lab-XUDT/index.js