Introducing UDTswap:Automated token exchange using multiple liquidity pool economy building on Nervos (+ Nervos design)

Mike MU
GrowFi
Published in
13 min readJul 14, 2020

UDTswap Feature

  • UDTswap building on Nervos network.
  • Token pairs are not limited.
  • Trade any UDT to any UDT direct swap support.
  • Automated pricing using Constant Product (x * y = k) market maker formula.
  • Anyone on-chain liquidity pool can participate.
  • Supports CKB and any UDT based pools.
  • Supports multiple pools for same CKB and UDT pairs.
  • Supports multiple swaps for different pools.
  • Liquidity-providers (LPs) earn exchange fees.
  • Front running can be prevented.
  • Protocol protection fees.

Introduction

UDTswap is an automated exchange protocol using multiple liquidity pool economy on Nervos. UDTswap is a decentralized exchange that replaces order books with an on-chain liquidity pool. Any liquidity pool can be created. In addition, existing automated market maker (AMM) protocols can set a base currency and create a token pair, but there is no limit to the base currency in UDT swap. When liquidity is added to the liquidity pool, the price is automatically formed through the constant product market maker mechanism (x * y = k). Liquidity pool providers will earn exchange fees (0.3%) incurred in the corresponding token pair swap.

*UDT: UDT is a User Defined Token and is a token type that can be issued on Nervos network. This is similar to the ERC-20 token type used on Ethereum.

Each liquidity pool has two CKB or UDTs. To deposit in a liquidity pool, you deposit the equivalent value of a UDT pair. When deposited, The pool’s “Liquidity Pool token (UDT type)” of the pool is issued to all liquidity pool providers and is used to verify the provider’s liquidity pool contribution. In addition, Liquidity Pool Tokens are burned in proportion to the withdrawal of funds deposited in the liquidity pool.

Anyone can do UDTswap listings and there are no restrictions on the base currency in the listings.

‌At UDTswap, anyone can list tokens, and UDT as well as CKB can be listed as a base currency. For example, you can make a CKB/BTC pair that is a CKB base currency, but you can also create a BTC/USDT pair as the BTC base currency. Users can only swap if there is a liquidity pool for that token pair.

Multiple pool:

For example, there can be multiple liquidity pools in CKB / USDT token pairs (EX:CKB / USDT Pool A, Pool B, Pool C etc).

Unlike traditional decentralized exchanges using AMM models, which operate as a single liquidity pool, UDTswap supports multiple pools. For example, there can be multiple liquidity pools in CKB / USDT token pairs (EX:CKB / USDT Pool A, Pool B, Pool C etc). This is the same token pair, but since the price formed for each pool(size) is different, arbitrage trading can be realized. Arbitrage will get more profit from liquidity providers and traders.

The main features of the multiple pool model are as follows.

1.Solving pool occupancy problems

As one live cell per liquidity pool, if a user tries to add / remove / swap from that pool, other users will not be able to use the pool until the status is updated. Since this can cause pool occupancy problems, UDTswap can solve the problem by supporting multiple pools and Protocol Protection Fees(PPF).

Liquidity Pool occupancy may occur frequently as UDTswap transactions increase. Each liquidity pool has a maximum number of transactions (average 8~9000) that can be accommodated daily. That’s why Liquidity-Providers (LPs) create Liquidity Pools to distribute transactions to provide users with a smooth trading environment. LPs can also operate multiple Liquidity Pools to broaden the path to revenue. In principle, ordinary users will do a simple token swap. However, if a malicious attacker deliberately seizes the Liquidity Pool, it will be a big obstacle for users and LPs. Nowadays, Nervos’ network fee is very low, so it is possible to realize a liquidity pool occupancy attack at no cost. Protocol Protection Fees were introduced to prevent this attack of Liquidity Pool.

The Protocol Protection Fees(PPF) are set to 61 CKB. Users must pay protocol protection fees when using UDTswap. Subsequent figures can be changed through the governance process. The protocol protection fees are used not only to increase the security of UDTswap, but also to build a continuously growing open finance infrastructure.

2.Complementing bad exchange rate setting

In the existing AMM swap model, a single pool can provide problems for token economy by first providing an abnormal proportion of liquidity pool. UDTswap can create a new liquidity pool and provide a good trading environment for users through normal token exchange rate.

3.Exact token swap price

When the token price changes rapidly in the market, the existing AMM models cannot guarantee the real-time transaction confirmation order, so it is impossible to detect the rapid change in price. Because of this, users need to set up slippage to take care of the risk. Users who have not set slippage may have fewer tokens that can actually be received. UDTswap fetches the price each time the Cell status is updated, so users can swap tokens at the correct price and reduce the risk of liability.

4.Arbitrage between liquidity pools

Although it is the same token pair, it is possible to realize arbitrage trading because the price formed for each pool (size) is different. Arbitrage will get more profit from liquidity providers and traders.

UDTswap supports not only CKB but also UDT for basic assets to expand the Nervos and long tail asset ecosystem in the future. Also, the liquidity pool of most existing swap models only supports a single pool, but UDTswap supports multiple pools. As a result, UDTswap offers more economic opportunities for liquidity providers (LP).

Why UDTswap build on Nervos network?

Nervos is Layer 1 designed for layer architecture purposes. Layer 1 is responsible for decentralization and security, helping to safely operate Layer 2/DApp/on-chain assets. Layer 2 is responsible for scalability, providing performance for applications that value the user experience. This can solve the fundamental problem of the blockchain, the trilema, through the interoperability of Layer 1 and Layer 2. In Layer Architecture, Layer 1, Nervos CKB, a high level of decentralization and security is essential. Nervos has the following features for decentralization and security.

  • Consensus Algorithm: Proof-of-Work(NC-MAX)

The security of Nakamoto Consensus has already been tested and verified for 10 years. In recent years, the proposed consensus algorithm in the blockchain ecosystem has been designed based on high security assumptions, but new attacks have been discovered. Nervos uses NC-MAX, an upgrade of Bitcoin’s Nakamoto Consensus, which has proven security. This makes it possible to solve the problem of the bitcoin network, low TPS and long time for transaction confirmation, and through the dynamic difficulty adjustment mechanism, all valid blocks are included in the difficulty adjustment, making selfish mining impossible.

Source: 51% Attack cost data

Nervos has developed a new hash algorithm, Eaglesong, for anyone to participate in an open and decentralized hash market. Thanks to this, ASIC developers competed and distributed ASICs with good performance to miners. Currently, the hash rate of Nervos is about 14PH/s, and when the Lina mainnet is launched, the hash rate is about 190 times higher than the 74TH/s hash rate. As the hash rate increased, the cost of the 51% attack on the Nervos network became very high. This means that the security of the Nervos network is continually increasing, and the scope of on-chain value care has been expanded.

  • Store-of-Value Crypto-Economics

1.Solved state explosion problem
Both historical data and state data must consume storage resources. Bitcoin’s UTXO model and Ethereum’s Account model are managed according to the growth of history and state, but there is no mechanism to control the size of history and state.

Growth of Ethereum storage. Source: talk.nervos.org

In the figure above, we can see that the state data accumulation has increased exponentially with the development of the Ethereum network. Bitcoin’s status data accumulated from 0 to 3 GB for 10 years, and Ethereum’s status data accumulated from 0 to 10 to 15 GB for 4 years. For example, a transaction or smart contract used by a user in Ethereum remains on the network forever once the transaction fee is paid. This allows the full node to continue to pay for storage, but users do not need to pay for storage continuously. This should be considered by the full node of the blockchain network for permanent storage costs.

If DeFi has become a major use on the blockchain, the history of the blockchain and the accumulation rate of the state can accumulate exponentially. As data continues to accumulate, the storage resources required to run a full node increase, the entry barrier of the full node continues to increase, and the level of decentralization of the network decreases. This problem is called a state explosion problem.

2. The Economic Model of the Nervos Common Knowledge Base
To solve the state explosion problem, Nervos’ state model was designed based on the Cell model. The Cell model can upgrade the Bitcoin UTXO model to create a wide range of complex smart contracts, including tokens, DeFi, and contextual business logic through type scripts and lock scripts. In addition, the biggest feature of the Nervos state model is that it enables the on-chain storage space to be used as a common resource. As long as the user has deposited CKB (CK Byte), the native token of Nervos CKB, it can occupy the state space of the Nervos network. For example, if Bob has 1000 CK bytes, he can create a cell with a space of 1000 bytes, or multiple cells with a total space of up to 1000 bytes. This means that if a user occupies a state on the network, it will come at a price.

Another problem of the state explosion problem is the problem of decentralization/security decrease due to full node departure. To address this, Nervos designed a sustainable crypto economy. The CKB issuing methods are “base issuance” and “secondary issuance”.

Base issuance: The “base issuance” has a finite total supply with a Bitcoin like issuance schedule — the number of base issuance halves approximately every 4 years until all the base issuance tokens are mined out. All base issuance tokens are rewarded to the miners as incentives to protect the network.

Secondary issuance: The “secondary issuance” is designed to collect state rent, and has issuance amount that is constant over time. After base issuance stops, there will only be secondary issuance.

Nervos DAO can help long-term investors on the effects of inflation due to secondary issuance. For example, if we hold 10,000 CKB tokens and expect profit from long-term investment, we can lock up the tokens in the Nervos DAO contract, and get a constant interest rate and won’t be lost due to the inflation effect of the second issuance.

Before the base issuance ends, the miner’s income (base issuance + secondary issuance + Tx fee) has a distribution curve similar to Bitcoin, and in the third halving, the network issues most of the block rewards. Unlike Bitcoin, even if the base issuance ends completely, you can still be rewarded through the second issue.

Ex: For example, 60% of all CK Bytes are used to store state, 35% of all CK Bytes are deposited and locked in the NervosDAO, and 5% of all CK Bytes are kept liquid. Then 60% of the secondary issuance goes to the miners, 35% of the issuance goes to the NervosDAO to be distributed to the locked tokens proportionally. The use of the rest of the secondary issuance — in this example, 5% of the that issuance — is determined by the community through the governance mechanism. Before the community can reach agreement, this part of the secondary issuance is going to be burned.

Secondary issuance can be thought of as a rent for state data, and was designed to solve the above-mentioned “You can use storage forever by paying a Tx fee once” mentioned in the State Explosion Problem. In the case of development, if the data occupies storage using the CKB held by the developer, the storage cost must be paid. This is designed to ease the burden of the second inflation effect.

When using storage space, secondary issuance is used to pay “rents” to miners. Miners will continue to inject hash power to earn secondary issuance when the return of the block rewards decreases.

We believe that base issuance and secondary issuance provide a solution to the state explosion problem of blockchain. If a developer occupies a state for a long period of time, a fixed rent is charged, and there is no longer a saying that “You can use storage forever by paying a Tx fee once.” And it will bring long-term predictable returns to miners and holders. A stable issuance policy will give linear changes to holders, miners, and developers without changing instantaneous fluctuations and participant motivations due to changes in issuance policy.

Nervos network’s NC-MAX and Crypto Economy models have been designed to solve the long-term incentive problem of miners and blockchain state explosions to design sustainable layer 1. The decentralization and security provided by Layer 1 provides a way for the Layer 2 and DAPP to grow together as a springboard for network effects.

What are the advantages of DeFi protocol and UDTswap have on Nervos?

For secure DeFi (DEX) operation, Layer 1 with a high level of decentralization and security is essential, but in recent Ethereum DeFi attack cases, structures such as gas design and Layer 1 smart contracts are also important. The decentralization and security of Nervos is already at a high level. What makes gas design and smart contract structure different from Ethereum, and what are the benefits of running the DeFi protocol on Nervos CKB?

  • Layer 1 network bottleneck& TX fee design (EX: Ethereum DeFi Black thursday case)
Black thursday gas price

At the time of Black Thursday, DeFi protocols had unpredictable transaction fees due to Ethereum network paralysis. Users have had great difficulties in sending transactions. Nervos has a huge merit for transaction fees. Nervos adopts an off-chain calculation and on-chain verification method, so it can send transactions if the rules are met. This means that you know the state change before the transaction occurs, and you can accurately see the fees consumed by the transaction. Users can set the gas price per Cycle only high when Nervos’ network is congested, and the transaction is processed by miners.

Ethereum’s fee design is unconditionally forced to pay only in native token ETH, but Nervos can pay any UDT, not just CKB, as a transaction fee. This allows users to pay with the token they have even without the native token.

  • Minimizing dependency on smart contracts

Issues that cannot be updated after the smart contract is deployed in Ethereum will place great responsibility on the blockchain developer. DeFi protocols that have been released so far are made of smart contracts, so once the damage is done, it cannot be reversed forever. DeFi protocols with minimal third-party trust cost are rather contradictory, so the dependence on smart contracts is too high, resulting in higher trust cost. However, CKB scripts can be created with some ways like Type id. The type id allows developers to update the script at any time. This can significantly reduce the dependency on smart contracts.

  • UDT: First-class asset

Tokens are the key in the asset area of the DeFi ecosystem. There are risks because the transaction and status of ERC-20 tokens are subject to contracts. UDTs are similar to Nervos’ ERC-20 tokens. In the case of UDT, the owner’s tokens are stored in Live Cell and protected by the owner’s lock. Ownership of the asset is always owned by the owner, and it can effectively control the risk of the asset by lowering its dependence on smart contracts.

  • Front running

For example, Ethereum Uniswap has front-running. If someone wants to swap with rate of 1:10, then he sends transaction. And miner can see, or any other can see with pending transaction list. So the malicious one can make another transaction with more gas price or any other way to be mined faster that can benefit with 1:10 transaction and the 1:10 transaction’s rate will be changed. In this case, UDTswap is not possible because of the state model of UDTswap is cell model. If someone wants to use UDTswap, he must use the pool cell as input. And if someone catches the transaction and send another transaction faster, then the first transaction can not be mined because the transaction is not using live pool cell. Therefore, front running cannot be realized.

The DeFi ecosystem is growing, and asset value and the number of users are growing day by day. In addition, interoperable applications using the DeFi protocol have overlapped layers, which is referred to as DEFI LEGO. As the DeFi ecosystem has grown, the number of attack cases is increasing and the attack types are also diversifying. Building a robust DeFi LEGO is not something you can solve by simply pursuing high scalability. The key is whether you can safely hold your assets. As long as the on-chain is stable, the DeFi ecosystem will have the potential to grow. This allows users to experience financial services that do not require trust. Nervos is Layer 1 for creating a robust DeFi Lego and Layer 1 for future DeFi protocols.

UDTswap will focus on creating a transparent and fully decentralized asset market in order to become the infrastructure for layer 2 and Dapp token exchange on Nervos in the future. Come to the Discord channel if you have any feedback on our UDTswap as this meaningful path needs community power!

Finally, Nervos’ crypto economy has been a great inspiration for UDTswap design. I would like to thank the Nervos Foundation once again.

Reference:
Nervos crypto economy:
https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0015-ckb-cryptoeconomics/0015-ckb-cryptoeconomics.md

Improving front running resistance of x*y=k market makers:
https://ethresear.ch/t/improving-front-running-resistance-of-x-y-k-market-makers/1281

Blockchain and state explosion:
https://talk.nervos.org/t/topic/1515

Nervos talk- Growfi UDTswap
https://talk.nervos.org/t/growfi-udt-swap/4382/11

--

--