Git Product home page Git Product logo

ckb-xudt-extension-plugins's Introduction

Abstraction

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.

1. Build

make all-via docker

2. The idea

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.

3. Setting up

3.1. Executable binary cell deployment

  • 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

3.2. Composing a remaining amount cell

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.

3.3. Composing our hard-capped token's cell

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>
}

4. Creating tokens

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

5. Note

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.

6. Example code in lumos

https://github.com/tea2x/developer-training-course/blob/master/Lab-XUDT/index.js

ckb-xudt-extension-plugins's People

Contributors

tea2x avatar

Watchers

 avatar

ckb-xudt-extension-plugins's Issues

ownerless total-supply cell will make transaction validation fail always

Currently total supply cell belongs to the token owner but this opens a way for him to manipulate the total supply and surpass the hard_cap script. Readme guides telling it should be ownerless is basically wrong since it will fail any transaction that tries to update a total supply cell.

Solution:

  • design a lock script for total supply cell such that it only allows for transations with the corresponding xudt+hard_cap typescript.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.