This spec describes a lock script used in a treasury system. See design document.
A cell with a treasury lock script is called a treasury cell. Treasury cells can only be created by consensus, similar to a cell base. A treasury cell can be consumed via two methods: the burning method or the reward method.
The lock script has the following structure:
code_hash: <code hash to treasury lock script binary>
hash_type: Type
args: <8-byte block number>
The 8-byte block number is parsed as a 64-bit unsigned little-endian integer. It represents the block number at the time the cell was created, set by the CKB node.
The corresponding witness must be in WitnessArgs molecule format. The full data structure is as follows:
WitnessArgs:
lock: <1 byte consuming_method>
input_type: <>
output_type: <>
The 1-byte consuming_method can be 0 (burning method) or 1 (reward method).
Depending on the consuming_method, the treasury lock script can be unlocked via one of two methods: burning or reward.
When this method is chosen, the script iterates over all headers using ckb_load_header (with source = 4, header deps) to fetch all block numbers. It parses each header to extract the block number, and the largest block number found is treated as the current block number. The transaction creator should put the latest block number in header_deps.
A duration block count is then calculated by subtracting the block number in args from the current block number.
This duration must be greater than a predefined value called burn_expiry_blocks, which is stored in the config cell described later.
To encourage anyone to burn expired treasury cells, an incentive mechanism is included. The incentive amount is calculated as follows:
incentive amount = (duration block count - burn_expiry_blocks) * burn_incentive_rate + base_burn_incentive
The config parameters burn_incentive_rate and base_burn_incentive are also stored in the config cell. The incentive amount is denominated in shannons, not CKB.