HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism Design

HashKey Capital
2021-03-25 12:08:09
Collection
Perpetual Protocol achieves decentralized perpetual contract trading through the vAMM model, which addresses the issues of AMM liquidity and impermanent loss to some extent.

This article was published by HashKey Capital, author: Hao Kai.

Market makers are widely present in trading markets, maintaining market liquidity and meeting traders' trading needs through market-making systems. With the rise of DeFi projects, Automated Market Makers (AMMs) have received increasing attention. AMMs use mathematical functions to determine asset prices and play a significant role in promoting DeFi development and providing liquidity.

Perpetual contracts fit well with the characteristics and needs of traders in the cryptocurrency market and have become the main product in the futures contract market of centralized exchanges. As a key technology for achieving decentralized exchanges (DEX), AMMs have been successfully applied to spot trading. Some DeFi projects aim to implement perpetual contracts through AMMs, with Perpetual Protocol being a typical representative. According to the data in the table below, Perpetual Protocol has the highest trading volume among decentralized exchanges in the derivatives category.

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism DesignTable 1: Major DeFi Projects Related to Decentralized Exchanges, Data Source: www.oklink.com, March 15, 2021

Project Design

AMMs achieve on-chain trading between two or more assets in a fully decentralized manner, using mathematical functions to determine asset prices. For example, Uniswap uses a constant product function x*y=k; when the supply of x increases, the supply of y decreases to maintain a constant product k, and vice versa. However, AMMs also have many limitations, including impermanent loss, low capital efficiency, and the inability to use leverage.

Virtual Automated Market Maker

To address the current issues with AMMs, Perpetual Protocol introduces the Virtual Automated Market Maker (vAMM). A virtual automated market maker refers to the fact that traders' real assets are not stored in the vAMM but are instead stored in a smart contract that manages all vAMM collateral.

For liquidity, the liquidity of an AMM comes from the assets provided by liquidity providers in the liquidity pool. The liquidity of a vAMM does not rely on liquidity providers and comes directly from collateral outside the vAMM. In a vAMM, traders themselves can provide liquidity to each other without needing other liquidity providers. Therefore, there is always liquidity in the vAMM.

Regarding impermanent loss, since vAMM does not require other liquidity providers to pre-deposit assets to provide liquidity, and traders' real assets are stored in a smart contract managing the collateral, there is no impermanent loss in the vAMM model.

vAMM also uses the constant product function x*y=k, and Perpetual Protocol allows traders to use 1-10x leverage for perpetual contract trading. Unlike AMMs, vAMMs do not require real liquidity providers to provide assets; the values of x, y, and k are set by the creator.

Since the k value is virtual, it can be adjusted based on market data such as trading volume, position size, and funding rates. In the future, the k value may be determined in a decentralized autonomous organization format. By adjusting to a higher k value, vAMM can effectively address the issue of trading slippage. However, the k value cannot be set too high, or it will affect the incentive for arbitrageurs to participate.

Trading Process

The creator creates the vAMM and sets the initial quantities of virtual assets x0 and y0 in the vAMM. At any given moment, assets x and y satisfy the constant product function x*y=k, with the initial price of asset x relative to asset y being y0/x0.

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism Design

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism Design

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism DesignTable 2: Schematic Diagram of the Trading Process

When traders close their positions, they need to withdraw the asset x they hold and calculate the final actual amount of asset y they receive based on the constant product function.

Funding Rate

To ensure the long-term convergence of perpetual contract prices and spot prices, preventing significant deviations from spot prices, Perpetual Protocol also introduces a funding rate mechanism. Perpetual Protocol settles the funding rate every hour. The funding rate determines the payer and payee: if the price of the perpetual contract is significantly higher than the spot price, the funding rate is positive, and longs need to pay funding to shorts; conversely, if the price of the perpetual contract is significantly lower than the spot price, the funding rate is negative, and shorts pay funding to longs. Moreover, the greater the price deviation, the higher the funding rate. If there is a significant deviation between the perpetual contract price and the spot price, arbitrageurs will engage in arbitrage across the two markets. At the same time, Perpetual Protocol also uses a marked price to avoid the effects of market manipulation.

The calculation of the funding rate for Perpetual Protocol is as follows. Here, TWAP stands for Time Weighted Average Price.

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism Design

Project Token PERP

PERP is the project token of Perpetual Protocol, primarily used for collateral and governance. PERP holders can stake their tokens and proportionally receive dividends from trading fees. Additionally, PERP holders can participate in project governance, such as voting on new trading pairs and modifying project parameters.

Case Analysis

Currently, Perpetual Protocol supports trading pairs such as ETH/USDC, BTC/USDC, and DOT/USDC, with each trading pair using USDC as collateral. Taking ETH/USDC as an example for analysis, suppose the trading price of ETH is 2000 USDC, and the creator sets the initial ratio of ETH to USDC at 1:2000. For example, the creator sets the initial state of the vAMM to 100 vETH and 200,000 vUSDC, as shown in the following table.

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism DesignTable 3: Case Analysis

Trader A wishes to use 1000 USDC as collateral and then go long on ETH with 10x leverage. A deposits 1000 USDC into the collateral smart contract. Perpetual Protocol credits A with 10,000 vUSDC (10 times leverage of 1000 USDC) in the vAMM. At this point, the amount of USDC in the vAMM is 210,000. According to x*y=k, the number of vETH received by A is calculated to be 4.7629 (100-100*200000/210000), equivalent to A holding a long position of 4.762 vETH.

At this point, trader B also wishes to use 1000 USDC as collateral and then go long on ETH with 10x leverage. B deposits 1000 USDC into the collateral smart contract. Perpetual Protocol credits B with 10,000 vUSDC (10 times leverage of 1000 USDC) in the vAMM. At this point, the amount of USDC in the vAMM is 220,000. According to x*y=k, the number of vETH received by B is calculated to be 4.329 (95.2381-100*200000/220000), equivalent to B holding a long position of 4.329 vETH.

Then, trader A withdraws the 4.762 vETH they hold to close their position. At this point, the amount of vETH in the vAMM is 95.671. According to x*y=k, the amount of vUSDC is calculated to be 209049.8, and A's final profit is 950.2 USDC (220000-209049.8-10000).

At this point, trader B withdraws the 4.329 vETH they hold to close their position. At this point, the amount of vETH in the vAMM is 100, and the amount of vUSDC is calculated to be 200000. B's final profit is -950.2 USDC (209049.8-200000-10000), meaning trader B incurred a loss of 950.2 USDC.

Comparison with Centralized Exchange Perpetual Contracts

Counterparty

Centralized exchange perpetual contracts are standardized trading products traded on the exchange. A perpetual contract is a two-sided trading market, and according to the matching mechanism of centralized exchanges, traders must have a counterparty to complete a trade when opening a position. In other words, for a trader going long, there must be a counterparty going short to complete the trade, and vice versa.

However, traders on Perpetual Protocol do not need a counterparty. As seen in the previous chapter's case, there are no real assets being traded in the vAMM model, and traders do not need a counterparty in the opposite direction when opening a position. Ignoring transaction fees and other slippage conditions, the profits of traders in the ecosystem equal the losses of other traders, regardless of the trading direction. Even if two traders in Perpetual Protocol have the same trading direction, it is still possible for one trader to profit while the other incurs a loss.

Consider an extreme case where all traders in the Perpetual Protocol ecosystem establish long positions or all establish short positions. This is impossible in the perpetual contract market of centralized exchanges, but it is possible for Perpetual Protocol. At this point, the price in the Perpetual Protocol market will significantly deviate from the spot market price, and rational arbitrageurs will short to earn the funding rate. If no arbitrageurs join, longs will need to pay the funding rate to the risk reserve.

Profit and Loss Calculation

Centralized exchange perpetual contracts can be divided into coin-margined contracts and USDT-margined contracts. Coin-margined contracts, also known as inverse contracts, require traders to use the corresponding cryptocurrency as collateral for trading, and the final settlement is also in the corresponding cryptocurrency. For example, if a trader participates in a BTC coin-margined contract, they must hold a certain amount of BTC as collateral, and their final profit is also calculated in BTC. USDT-margined contracts are also known as linear contracts, where both the collateral and settlement currency are in USDT. Traders participating in USDT-margined contracts do not need to hold different types of cryptocurrencies; holding USDT is sufficient to participate in all trading pairs of USDT-margined contracts. Additionally, the value of the collateral in USDT-margined contracts does not change, and their profit and loss curve is linear. Assuming a price of $10,000, if 100 contracts are opened in both coin-margined and USDT-margined perpetual contracts for BTC, the profit and loss curves are shown in the following figures.

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism Design

HashKey Hao Kai: In-depth Analysis of Perpetual Protocol's Perpetual Contract Mechanism DesignFigure 1: Profit and Loss Curves of Coin-Margined Contracts and USDT-Margined Contracts

For coin-margined contracts, the profit and loss for traders need to be calculated based on the average position price, closing transaction price, contract value, and number of contracts: Long profit and loss = (1/ Average Position Price - 1/ Closing Transaction Price) * Number of Long Contracts * Contract Value; Short profit and loss = (1/ Closing Transaction Price - 1/ Average Position Price) * Number of Short Contracts * Contract Value.

For USDT-margined contracts, the profit and loss for traders need to be calculated based on the average position price, closing transaction price, contract value, and number of contracts: Long profit and loss = (Closing Transaction Price - Average Position Price) * Number of Long Contracts * Contract Value; Short profit and loss = (Average Position Price - Closing Transaction Price) * Number of Short Contracts * Contract Value.

For traders on Perpetual Protocol, their final profit and loss calculation is related to the overall state of the system at the time of opening and closing positions.

Risk Reserve

Centralized exchanges provide risk reserves for perpetual contracts. If a trader's perpetual contract is forcibly liquidated, the exchange will activate a liquidation engine to take over the remaining positions in the trader's account and use the risk reserve for reverse liquidation. The existence of the risk reserve effectively provides unlimited liquidity to traders at the price of forced liquidation. If the exchange's risk reserve is insufficient to take over the remaining positions of liquidated users, the exchange will automatically liquidate the profitable party according to the rules. Major centralized exchanges accumulate significant risk reserves to protect traders' interests.

Perpetual Protocol also has a risk reserve. When the market fails to liquidate uncollateralized positions in a timely manner or when the market imbalance requires the vAMM to pay funding rates, the risk reserve will be needed. If the risk reserve is exhausted, the system will mint new PERP tokens to sell in the market to repay debts.

Compared to centralized exchanges, Perpetual Protocol, which has been launched for a short time, has accumulated very limited risk reserves, and the risk reserve mainly consists of its own token PERP, which is also unstable in value. Therefore, the risk reserve of Perpetual Protocol provides relatively less protection for users.

Thoughts and Conclusion

Perpetual Protocol addresses some of the liquidity and impermanent loss issues of AMMs to a certain extent through the vAMM model. Perpetual Protocol adopts a Layer 2 solution, processing transactions on the xDai Chain, which means higher transaction efficiency and no gas fees. At the same time, Perpetual Protocol achieves decentralized perpetual contracts.

In the vAMM model, there are no real assets being traded, and traders do not need a counterparty in the opposite direction when opening a position, similar to projects like Synthetix, where the profits of traders in the ecosystem equal the losses of other traders. In this case, even if traders correctly judge the trading direction, they may still incur losses.

The trading depth of Perpetual Protocol's perpetual contracts is far less than that of centralized exchanges, and the scale of the risk reserve cannot be compared to that of centralized exchanges. Additionally, the profit and loss calculation for traders on Perpetual Protocol is relatively complex. Therefore, the current user experience of Perpetual Protocol still needs improvement, and centralized exchange perpetual contracts are more suitable for traders to participate in.
Disclaimer: As a blockchain information platform, the articles published on this site only represent the author's personal views and do not reflect the position of ChainNews. The information and opinions contained in the article are for reference only and should not be considered or viewed as actual investment advice.

ChainCatcher reminds readers to view blockchain rationally, enhance risk awareness, and be cautious of various virtual token issuances and speculations. All content on this site is solely market information or related party opinions, and does not constitute any form of investment advice. If you find sensitive information in the content, please click "Report", and we will handle it promptly.
ChainCatcher Building the Web3 world with innovators