Contract-Owned CAT Tokens
Each token UTXO has an owner address. It is essentially the hash of a public key, corresponding to a private key. When the owner sends the token, she signs with the private key, which the token contract checks, the same way as sending bitcoins locked in a regular P2PKH address.
There is an alternative path to spend the token: script or contract path. In this path, the public key is derived from a contract using Taproot as follows, where the key spend path is disabled.
Tokens can be deposited to a contract address. It is not controlled by anyone but the contract, since there is no corresponding private key. This is similar to a smart contract account in Ethereum, which also does not have a corresponding private key, unlike an Externally Owned Account (EOA). To transfer the tokens, the CAT token contract ensures there must be a neighboring input in the same transaction, spending a UTXO with the owner contract address (shown by the red arrow). The contract can inspect and place constraints on the transaction using covenant, thus enforce additional transfer rules.
In summary, there are two options to spend a token UTXO, akin to in Taproot:
- key path
- script/contract path.
We can now use option 2 to send existing tokens to arbitrary smart contracts. The contract does not have to be known when tokens are minted and can be developed by a third party independently. This means CAT tokens are infinitely extensible and interoperable with decentralized applications, such as decentralized exchanges and atomic swaps.
Sell Order
To demonstrate how it works, we send tokens to a sell contract, where they can be purchased by anyone as long as they pay the seller a given price.
The sell contract ensures:
- buyer gets the token she pays for
- seller gets paid, per the token price she specifies and the number of tokens sold
- remaining tokens return to the same contract (recursive covenant), if any.
It is worth noting the order allows partial fills, where a buyer can purchase only some portion of tokens in the list order. The rest of tokens can be purchased repeatedly till the order is completely filled. Everything is validated by miners and thus trustless.
A sell order contract can be found on GitHub.