Version:YFX Descartes V1

Abstract

The technical whitepaper explains some technical design schemes behind the decentralized perpetual contract trading platform of YFX Descartes V1. It covers the design of smart contracts on the public blockchains such as Ethereum, Tron and Binance Smart Chain (BSC), as well as the technical design of the fair price, forced liquidation of over-loss, and risk fund, etc. Users can trade with any token on Ethereum, Tron or BSC (including ETH, TRX, USDT, USDC, and variousTRC20 and ERC20 tokens) as margin. The indices that can be traded are some Oracle price indices on the ETH or the price index of other external markets.

In addition, this System will systematically introduce the design of the non-over-loss system of the perpetual contract on the blockchain, and the core mechanics of market makers, including the risk control of market makers, fund security and other solutions.

1. Overview

The centralized crypto exchange plays the role of the broker, exchange and bank, with very broad permissions, which results in the malicious operation of the platform, such as price hikes and counterfeit token trading on the platform. To solve these problems, the decentralized trading platform, represented by Uniswap, began to solve the problems of opaque capital, algorithm, and data.

YFX is a transparent decentralized trading platform for perpetual contracts. All funds are hosted by smart contracts. All smart contract codes are open sources, which have been audited by the professional institutions. Users have full control of their funds in smart contract.

QIC-AMM (Quoted Price index and Constant Integral Based Automated Market Maker) is the dynamic depth financial derivatives trading protocol based on quoted price index and constant integral.

2. Trading Mechanics

YFX adopts the trading mechanics of market maker pool. Traders will trade with the market maker pool. Each trading pair corresponds to a market maker pool, and the profit or loss of the traders will be transferred directly to the market maker pool. In the process of market making, the market maker only needs to stake single kind of token to participate in the market making, and at the time of redemption, if the net value is greater than the net value at the time of subscription, a profit can be made.

YFX will simultaneously support the transactions of USDT margined swap, coin margined swap and mixed swap.

USDT Margined Swap

BTC_USDT contract, using USDT as margin and adopting the price index of BTC_USDT and settled with USDT.

Coin Margined Swap

BTC_USD contract, using WBTC as margin, adopting the price index of BTC_USD, and settled with WBTC.

ETH_USD contract, using ETH or WETH as margin, adopting the price index of ETH_USD, and settled with ETH or WETH

Mix Swap

Hybrid contract trade can use BTC, ETH or any ERC20 or TRC20 tokens as margin and settled profit or loss.

2.1. Price mechanics

The price of YFX can come from three main data sources.

Adopting the price data of the Oracles on the Ethereum, such as ChainLink. The Oracle contract provides a price index of the underlying assets of the perpetual contract. Oracle is the key link of the whole perpetual contract system. YFX’s perpetual contract can use Oracle data of ChainLink. With the overall development of the industry, we will continue to use new Oracle technology to improve the product quality and security of perpetual contract.

2.2. Adopting the AMM mechanics of decentralized crypto exchange such as Uniswap. At present, the AMM of Uniswap uses the classical constant product (x * y = k) pricing formula. This formula has been adequately verified in Uniswap and other projects. We think it is a good choice to use this formula as a starting point for AMM.

When applying this pricing formula, we first made AMM’s margin account only have long position and be always fully collateralized. This ensures that AMM’s account will never be liquidated, meaning that AMM’s margin account will always be secure. Furthermore, we substitute the available margin balance of AMM into x and the amount of long position in AMM account into y in the formula. When a trader goes long through AMM, the trader’s long position increases, while the AMM’s amount of long position (y) decreases and its available margin balance (x) increases. Conversely, when a trader goes short through AMM, the trader’s short position increases, while the AMM’s amount of long position (y) increases and its available margin balance (x) decreases. Thus, the pricing formula can give the price of the transaction with AMM.

2.3.With respect to the quoted price of the centralized index, the price index represents the market consensus price of the underlying asset. Specifically, the calculation process of price index consists of two parts: data availability verification and reference exchange weight correction. Data availability verification includes the judgment of its timeliness and effectiveness. The quoted price of the reference exchange that has passed the availability verification will obtain the corresponding adjusted weight according to the difference between it and the weighted average price of the reference exchange.

Detailed rules for price index calculation: Taking BTCUSDT price index as an example

.yBTC is the sum of the weighted BTC spot trading prices of these exchanges: Huobi, Binance, Bittrex and BitMEX. The weighted mean is the monthly trading volume of each exchange in the previous month.

.yBTC = Trading Volume Weight(A)×Quoted Price A+Trading Volume Weight(B) ×Quoted Price B+Trading Volume Weight(C) ×Quoted Price C

Spreads=|Exchange Price−.yBTC|

By adjusting the reciprocal of the squared spreads of each exchange, we get the weight of the exchange:

PS for price spread.

The price index is obtained by multiplying the spot price of the exchange by the respective exchange weight.

Price index= (Quoted Price A ×Exchange Weight A) + (Quoted Price B× Exchange Weight B)+(Quoted Price C × Exchange Weight C)

YFX would temporarily remove the exchange quotation from the index calculation if any of the following conditions is triggered:

(1) The latest quoted price from the exchange remains unchanged for more than a minute. Price index will eliminate the exchange’s price.

(2) The average deviation between the quoted price of the exchange and those of the other four exchanges is more than 3%. This can avoid the occurrence of price anomalies.

All data sources have their own advantages. However, due to the high demand for real-time data in the contract, the YFX Descartes V1 version will mainly adopt the centralized price index quotation mechanics, offering tape quotes on an average of 1–5 times per second.

2.4. Dynamic trading depth of automatic market making

The System employs the constant integral formula to calculate the dynamic depth of the maker pool. By employing the normal distribution probability model, the tape depth of the automated market maker calculated based on the available balance of LP pool, X~N (price index, 500).

Example:

If current price_index = 10000, the available balance of the maker pool is 100000 USDT, and the entry cost for a user to go long is 100 USDT, then P (index_ price < θ <price) = 100/100000 = 0.001, what is the price?

price = 10001.25

The depth can be adjusted according to the standard deviation.

3. Trading

YFX optimize specific designs for smart contracts and simplify the on-chain calculation.

When a trader place an order, the margin at the time of opening the position must be greater than the initial margin. When the margin balance is lower than the maintenance margin, the system will liquidate the position and carry out the liquidation.

The formula for calculating the margin and profit and loss of USDT swap are as follows:

P&L for long position = Quantity x (Average exit price- Average entry price)

LP for long position = Average entry price *(1–1/Leverage)/(1-MM)

P&L for short position = Quantity x (Average entry price — Average exit price)

LP for short position = Average entry price *(1+1/Leverage)/(1+MM)

Initial margin = Average entry price * Quantity /Leverage

Maintenance Margin(MM)= Average entry price *Quantity *Maintenance Margin rate

The formula for calculating the margin and profit and loss of coin margined swap are as follows:

P&L for long position = Quantity x (1/Average entry price — 1/Average exit price)

LP for long position = Average entry price *(1+MMR)/(1+1/Leverage)

P&L for short position = Quantity x (1/Average exit price — 1/Average entry price)

LP for short position = Average entry price *(1-MMR)/(1–1/Leverage)

Initial margin = Quantity /(Leverage*Average entry price )

Maintenance Margin(MM) = Quantity *Maintenance Margin rate /Average entry price

USDT/USDC margined swaps take USDT or USDC as collateral, while coin margined swaps take the underlying assets as collateral.

4. Market Maker

Due to the delay and low efficiency of blockchain, the traditional matchmaking transaction can hardly be realized on- chain, because to place order, cancel order and the transaction need to run the smart contract, which cost a lot of gas. In extreme cases, place order, cancel order and transaction cannot be confirmed in real time in the blockchain. Therefore, most of the on-chain trading solutions have abandoned the order book mode and adopted a more certain trading pool trading mode.

For example, through a two-token trading pool, Uniswap can well complete trade between market makers and users. Moreover, it simplifies the time sensitive price quotation to a formula.

Like Uniswap, YFX also adopts automated market maker(AMM), under which the traders make a market with the market maker pool when opening or closing a position. The platform sets a corresponding maker pool for each trading pair. Users can choose whether to trade or stake in market maker pool. Staking in the market maker pool is also called adding liquidity and exiting from the market maker pool is also called reducing liquidity. The users participating in market making can obtain 20% of trading fee.

In YFX, the leverage of the user is different from that of the market maker. Through parameter configuration, the leverage of the user is usually 5 times that of the market maker. Supposing that a user pays 100USDT to open a position with a leverage of 10 times, then the total market value of opening the position is 1000USDT. At this time, supposing that the market maker uses a leverage of two times to make a market, the market maker will be frozen by 500USDT. The upper limit of the user’s profit is 500USDT of the margin of the market maker, while the upper limit of the market maker’s profit is 100USDT of the margin of the user. If there is an extreme situation in the blockchain, the platform will carry out liquidation at the bankruptcy price of one party, to avoid the situation that the whole system will be over-loss.

5. Automated Market Maker (AMM)

5.1. Add liquidity

Any trader can act as a platform liquidity provider. When adding liquidity to the pool of the automated market maker, user only needs to stake USDT to the smart contract and received LP token at the same. At present, YFX use USDT for settlement, and more settlement tokens, such as TRX, ETH and BTC, would be added later through community governance.

The calculation of the quantity of LP tokens obtained when adding liquidity:

Amount LP Token = sent USDT Amount /LP Token Price

5.2. Remove liquidity

LP obtains the corresponding share of USDT by sending LP token to the automatic market maker pool to remove liquidity. The amount of USDT can be calculated by the following formula:

Amount USDT=sent LP Token Amount * LP Token Price

5.3. LP Token

LP token is ERC20 token, which is highly divisible. LP token is used to track the market value of the LP pool,

LP Token Amount = Quantify Issued for Adding USDT Liquidity — Quantify Burned for Withdrawing USDT Liquidity

The market value of the LP pool is the sum of the available balance of the pool + position margin + unrealized PNL.

LP Token Price = Market Value of the LP Pool / LP Token Amount

LP’s income mainly consists of the following aspects:

(1) P&L of the market maker, including settlement profit and loss and unrealized P&L.

(2) Trading fee.

(3) Risk fund.

5.4. Global risk parameters and boundary setting of the automated market maker

(1) When the price of the centralized price index is beyond the liquidation price of all current positions, the System will stop adding and reducing liquidity.

(2) When the available balance of the LP pool is less than 20% of the total market value of the LP pool, the System will stop accepting the order.

6. Trading fee

YFX charge trading fee by calculate the trading fee when open a position and charge the fee when close a position, total trading fee is calculated based on the value of the user’s opening the position. The platform presets the service charge rate to be 0.1% (0.05% to open a position, 0.05% to close the position), which can be adjusted through platform token governance.

The trading fee will be divided into four parts:

40% rebatefor the inviter

20% distribute to market maker pool, liquidity provider rewards for staking in Market Maker Pool

40% for YFX token buyback and YFX Team. 50% used for token buy back on Uniswap and Justswap, 50% used for the operation cost of the platform, including the cost of on-chain transaction. And part of the income is used to buy back directly on the Uniswap.

The cost for placing an order is: blockchain network service fee + trading fee + initial margin

7. Minimum Margin Ratio

Referring to the perpetual contract exchanges such as BitMEX and Binance, all platforms would set a maintenance margin rate to avoid the situation that they cannot liquidate positions below zero. The maintenance margin would vary according to the size of the user’s position and leverage. The minimum margin ratio would be 0.5% as the position is small, while the maintenance margin rate can be as high as 10% when the position is large.

The minimum margin ratio of YFX adopts a static minimum margin ratio. In a certain trading pair, the minimum margin ratio is initially determined. Generally, when the leverage is 100 times, the minimum margin ratio is 0.5%, and when the leverage is 50 times, the minimum margin ratio is 1%.

8. Liquidation Price

Liquidation price is where your margin is unable to meet the requirements to keep the position open and is liquidated. After liquidation, the System will automatically trigger the calculation of profit and loss to settle the funds of the user and the market maker.

Liquidation price of USDT margined swap:

LP for long position = Average entry price * (1–1/Leverage)/(1-MM)

LP for short position = Average entry price *(1+1/Leverage)/(1+MM)

Liquidation price of coin margined swap:

LP for long position = Average entry price *(1+MMR)/(1+1/Leverage)

LP for short position = Average entry price *(1-MMR)/(1–1/Leverage)

9. Funding Rate

Funding rate is to keep the price of a perpetual contract in line with the underlying asset’s spot price, discouraging major deviations. YFX offer a limited perpetual contract, which stops the loss that triggers the liquidation price of the market maker. Therefore, for the sake of simplicity and purity of the whole system, YFX Descartes Descartes V1 does not set a funding rate.

10. Position Holding Time

Because the Descartes V1 Version does not set the funding rate related algorithm, it loses some completeness of the perpetual contract. In order to balance the whole system design, the System designs a maximum holding time limit, which is generally limited by the number of blocks. For example, on the Tron, the position limit may be 1 million blocks, while on the ETH, the holding time is 200,000 blocks, which is about 30 days.

11. Insurance Fund

Insurance fund is what prevent the balance of losing traders to drop below zero, also ensuring that winning traders get their profits. If in any case that could cause the trader loss below zero, and system cannot close traders’ position, insurance fund will cover this loss automatically.

Insurance fund belongs to YFX platform not YFX team. Insurance fund could also be used to buy back YFX token if the fund exceeds certain amount.

12. Control System of the Smart Contract

The perpetual contract has some centralized control systems, which are different from coin swap contract. To ensure the stable operation of the margin platform, the platform will set some super permissions for trading platform governance and parameter setting.

Smart contract control

①. Suspend receiving or withdrawing tokens

②.Suspend accepting orders

③.Suspend certain trading pair

④.Clearing and settlement of a certain trading pair

⑤.Liquidation trigger

⑥.Others

Smart contract parameter setting

①. Trading fee ratio

②. Trading fee distribution ratio

③.Minimum margin ratio

④.Other parameters related to the trading pairs

13. YFX Token & Community Governance

YFX trading platform will issue the governance token YFX, which will be used for the community governance. The platform token will be issued by tranches through the mining or market making contribution reward in the community. YFX team and early investors will only have a small portion of YFX token, which will be released linearly in the next four years.

YFX holders will have the rights to participate YFX governance, YFX community vault, create trade pairs.

14. Risk control

The business logic of the YFX perpetual contract is relatively complex, and the risks and challenges it faces are relatively high. In order to maximize the financial security of the users, we can carry out risk control work in on-chain and off-chain ways.

On-chain risk control is the completely decentralized automated risk control mechanics implemented by the on-chain smart contract. The on-chain risk control program is deployed by the administrator, who grants the on-chain risk control program the permission to “suspend the contract function”. When the on-chain risk control strategy is triggered, the on-chain risk control program can suspend the function of the entire contract. After that, the administrator can take further action as the case may be.

Off-chain risk control is a risk control mechanics automatically executed by the off-chain monitoring program. The advantage of off-chain risk control is that it can realize various complex risk control strategies, but the disadvantage is that the degree of centralization of this risk control method is relatively high.

15. Disclaimer

The content of this white paper is not an investment advice and does not constitute any offer or solicitation to offer or recommendation of any investment product. The content is for informational purpose only you should not construe any such information or other material as legal, tax, investment, financial, or other advice.

There will be updates on our website or product and this white paper may not be updated at the same time.

DEX offer 100x trading leverage at yfx.com