Bitcoin’s Decentralized Exchange based on UTXO
Just like the news leaked in our WeChat group, a decentralized exchange based on the Bitcoin UTXO model will be released in the near future. We are now advertising it in case only a few people know what we’re doing.
Bitcoin has been given financial attributes from the day it was born. In Block 0, Satoshi Nakamoto reproduced the following sentence
The Times 03/Jan/2009 Chancellor on brink of second bailout for banks.
This sentence has also been extended to understand the vision of Bitcoin: the world currency.
The White Paper describes a new cash system that does not require human operations, is implemented only by stable protocols and software programs, and is guaranteed by miners to participate in the competition to ensure safety.
Decentralized realization of financial needs is the direction of our efforts now. DeFi (decentralized finance) has been widely discussed, developed, and used in Ethereum and compatible chains for the past year. DeFi is driven by the need to manage digital assets deposited on the blockchain. All kinds of financial services have been invented and implemented, from trading to lending and insurance. On Bitcoin, there are also people who are constantly trying, and most of them have encountered the following difficulties.
- The Token protocols
- Token-based decentralized finance
We defined the Bitcoin Token protocol at the end of last year and explained the Token transaction and Token exchange methods in the protocol. With the help of investors in a few months, we wrote a program to realize this agreement. Wallets and Token trading websites that support Token will be released soon.
The following is explained in plain English.
Model
Ethereum uses an account model. For example, each account corresponds to a number that records the number of assets in the account.
The Token on Ethereum, similar to the figure below, has a Map data structure in a smart contract 0x234, which records the Token balance corresponding to each account.
The increase and decrease in the number of Eth and Token is just a change in the number of balance.
The Token of the account model has the following characteristics
- The program is simple and intuitive
- Contracts can call each other
- It has a Map data structure and supports the correspondence relationship of “Address: Quantity.”
- Serial processing (cannot be parallel), through each transaction to change the balance
- Natural state machine solution
The inefficiency brought about by this model method is the main reason for the emergence of the second-tier network, side chain, and compatible chain of Ethereum.
Bitcoin uses the UTXO model. Let’s look at the following example
There is no concept of account in Bitcoin, but it is embodied through UTXO. Analogous to a wallet with Dollar, each UTXO is equivalent to paper money or coins of different denominations in the wallet. It would be best if you counted how much money you have in your wallet. The total amount you get is the balance of your wallet. The benefit of this UTXO model is that it can be processed efficiently in parallel. For example, address 1a1 can choose to send three transactions at the same time:
-(10, 10, 20) a set
-(20, 20, 15) one set
-(5) One set
The payment is also put directly into the wallet and conflicts with other UTXOs.
Features of UTXO model
- There are thresholds for learning contract language
- Scripts cannot call each other
- No MAP data structure
- Parallel processing (also serial)
- Difficulty in state transition (part of the solution: OP_PUSH_TX)
In Bitcoin, the “wallet” has a critical position, and the balance is the result of the wallet’s statistical calculation of UTXO. If the wallet does not recognize a certain UTXO, then statistical errors will occur. And Bitcoin Token should be a special kind of UTXO, let the wallet recognize, check by the wallet, and count the balance.
It is a challenge to design Token under the efficient model of UTXO. Most of the solutions were affected by the Ethereum account model, trying to implement the Ethereum ERC20 Token protocol on Bitcoin, and encountered various difficulties. Even further, they designed the Token to realize the DeFi function under the account model, such as AMM automatic market-making and liquid mining. As a result, neither Token nor DeFi can do well. Either sacrifice the concurrency advantage of UTXO, or use a centralized server solution, or use both.
In other UTXO chains, even add Ethereum-compatible virtual machines, under the guise of UTXO, the medicine of the seller’s account model.
Token and DeFi
After fully understanding the difference between the account and UTXO models, you can know what they are good at and not.
Account model
- Token, the change of balance is the modification of a number
- Swap, Token is put into a pool, AMM will automatically make the market
- NFT, the limitation of the blockchain. NFT cannot be saved on the chain. Only the hash is saved
UTXO model
- Token, division of labor, balance statistics on the wallet, and miners verify transactions.
- OrderBook, each order can be a UTXO
- NFT, a serial UTXO transaction chain, there is no digital change, the content itself can be saved on the chain
Note that we mentioned OrderBook. Order is the two types of UTXO that exist in our Token scheme to buy or sell. Unlocking Order UTXO means that there is an atomic exchange between Bitcoin and Token.
A wallet instance with Token and Order UTXO
This wallet supports four types of UTXO, P2PKH, Token, Order-Buy, Order-Sale
- P2PKH: Bitcoin
- Token: Token1 and Token2
- Order-Buy: buy order, buy a specified amount of a certain token at a specified price
- Order-Sale: A sell order to sell a specified amount of a certain token at a specified price
The wallet is responsible for managing its own tokens and orders. A Swap website monitors transactions on the blockchain network, analyzes UTXO orders issued by others from the wallet, and displays them on the web page in real-time. The flow chart is as follows
Both the wallet and the Swap website are close to completion, and we are making final adjustments.
Post a screenshot leaked in the WeChat group.
We are aware that technology is only one aspect, and complete ecological construction requires more effort. Swap plans to introduce a mechanism for transaction mining and DAO, and part of the transaction fee (0.1%) will be fed back to passing traders. Sending orders and transaction orders will be rewarded with mining coins. Holding the share of Swap mining currency also determines the future development direction of the website and has the right to vote. In addition, users who invested in our CSS equity tokens in the early stage will receive double mining currency rewards. In addition to mining coins that encourage trading, the Singapore Foundation is also preparing to issue stable coins to support decentralized exchange. The detailed rules for mining coins and stable coins are under development.
Welcome join our Discord and talk with us. https://discord.gg/j92h4qDcRX