How it Works

Overview

At its heart, Perpetual Protocol seeks to create a perpetual contracts trading protocol that anyone can use. You will be able to trade with good liquidity and low slippage thanks to our innovative vAMM-based exchange. We use a scaling technology called xDai to increase the speed of trades compared to other Ethereum-based exchanges.

Trades on Perpetual Protocol settle in USDC, so all collateral used on the exchange is in USDC.

Perpetual Protocol uses a streamlined system to allow traders to gain the benefits of xDai scaling without having to set up your wallet or exchange tokens. Simply use your existing wallet to 'deposit' USDC via our trading interface, and you are ready to trade. Your funds are 100% controlled by your existing Metamask wallet or other compatible wallet at all times during the trading process.

Stakers on Perpetual Protocol enjoy zero impermanent loss risk while earning fees and rewards on their staked PERP tokens. This is because staked PERP tokens are not stored in our vAMM or used for liquidity — they are safely stored in the smart contract vault and not a liquidity pool, and are therefore not exposed to impermanent loss.

Perpetual Contract Trading

We highly recommend spending some time learning about perpetual contract trading before starting to use Perpetual Protocol. In general, trading perpetual contracts on our platform is largely similar to trading perpetuals on centralized exchanges. The main differences are:

  • Perpetual Protocol does not use an order book - trades are filled right away and there is no need to wait for a counterparty or pay a taker fee.

  • Trades settle somewhat slower than on centralized exchanges, especially during high volume - to mitigate this, we provide slippage controls, and all trading operations take place on xDai, which is significantly faster than the Ethereum base layer.

Trading can result in financial loss, although with Perpetual Protocol, you are assured of never losing more than your initial investment. Keep two principles in mind at all times:

  • Never invest more than you can afford to lose

  • Always do your own research to understand the tokens, wallets and other tools you are using

Perpetual contract basics

Perpetual contracts are a type of futures contract, pioneered in the cryptocurrency space by Bitmex. Perpetual contracts are one of the most popular derivative products in the space.

Perpetual contracts allow traders to speculate on the future price of a given asset by buying (going long) or selling (going short) perpetual futures contracts. Unlike typical futures, perpetuals do not expire. Instead, they automatically renew after a fixed period (1 hour, in the case of Perpetual Protocol).

The price of perpetual contracts will often diverge from the broader market (aka spot market). These deviations signal sentiment on the exchange - if a majority of traders expect the underlying asset to increase in value over time, the price of the perpetual contract will likely exceed the spot price. Likewise, if most traders expect the price to fall, the price of the perpetual will be below the spot price.

There are two mechanisms that moderate this process, and function to keep the perpetual contract price close to the spot price.

  • Funding payments

    • Every hour, traders with open long or short positions will pay each other a funding payment, depending on market conditions. If the contract price is above the spot price, longs will pay shorts. If the contract price is below the spot price, shorts will pay longs. The size of the funding payment is a function of the difference between the contract price and the spot price, as well as your position size. This incentivizes more traders to take the unpopular side of the trade.

  • Arbitrage

    • If the contract price diverges significantly from the spot price in other exchanges, arbitrageurs can benefit in two ways. 1. If they hold a position elsewhere, they can use Perpetual Protocol to take the inverse position and earn funding payments. 2. They can use Perpetual Protocol to get exposure to an asset they planned to buy/sell otherwise, while entering at a lower price than is available elsewhere (for longs) or higher than elsewhere (for shorts).

Trading

Let's walk through an example trade.

How Perpetual Protocol Works

Example

Step 1 Alice sends 100 USDC to the Clearing House on Perpetual Protocol and specifies to use that amount as the margin to open a 2x leveraged long position.

The primary function of the Clearing House is to record the position ownership and its related information, including initial margin, leverage, and direction (long or short).

Step 2~3 Upon receiving the 100 USDC, the Clearing House deposits the funds into the Vault. After that, Perpetual Protocol updates the asset price in our vAMM according to the margin amount, position direction (long or short), and the amount of leverage.

In contrast to the applications that utilize automated market makers (AMMs) to facilitate token swaps like Uniswap and Balancer, Perpetual Protocol only uses the constant-product curve in our AMMs for price discovery so that we can handle leverage and shorting. This also means there is no risk of impermanent loss for liquidity providers.

As you can see from the diagram above, the deposited tokens from traders aren't stored inside our AMMs, whereas on Uniswap, the deposited tokens from traders are indeed stored inside their AMMs. Due to this difference, we name our AMMs "Virtual AMMs" because there is no actual token swapping involved in our AMMs.

For those who don't know what a constant-product curve is or how Uniswap works, please see:

Back to our trader, Alice. Assume we have 100 ETH/USDC and 10,000 USDC in our vAMM as its initial state.

Action (Chronological)

ETH/USDC (x)

USDC (y)

*Calculation

Initial State

100

10,000

As mentioned before, the amount of ETH/USDC and USDC set in a vAMM aren't real tokens - they're just two numbers credited in a vAMM, and this vAMM uses them as the variables in the constant-product curve formula to calculate the price of the derivative on the platform.

Step 4~5 Considering Alice uses 100 USDC as the margin to open a 2x leveraged long position, which means that the amount of USDC in our vAMMs will become 10,200 (10,000+100*2), the amount of ETH/USDC will become 98.0392156862745 (100*10,000/10,200), which is calculated by the constant-product curve, and the amount of ETH/USDC that Alices gets is 1.9607843137255 (100-98.0392156862745), which is recorded in the Clearing House.

Action (Chronological)

ETH/USDC (x)

USDC (y)

*Calculation

Initial State

100

10,000

Alice gets 1.96 long position

98.0392156862745*

10,200

100*10,000/10,200

Step 6~ Following Alice, Bob also uses 100 USDC as the margin to open a long position with 2x leverage. In return, he receives 1.8853695324283 long positions (98.0392156862745-96.1538461538461) from our vAMM with the price calculated by the constant-product curve.

Action (Chronological)

ETH/USDC (x)

USDC (y)

*Calculation

Initial State

100

10,000

Alice gets 1.96 long position

98.0392156862745*

10,200

100*10,000/10,200

Bob gets 1.89 long position

96.1538461538461*

10,400

98.0392156862745*10,200/10,400

After Bob gets his long position, Alice decides to close her position and realizes a profit of 7.84012298 USDC (10400 - 96.1538461538461*10,400/(96.1538461538461+1.9607843137255)- 200)

Action (Chronological)

ETH/USDC (x)

USDC (y)

*Calculation

Initial State

100

10,000

Alice gets 1.96 long position

98.0392156862745*

10,200

100*10,000/10,200

Bob gets 1.89 long position

96.1538461538461*

10,400

98.0392156862745*10,200/10,400

Alice closes her position

98.1146304675716

10192.15987701770*

96.1538461538461*10,400/98.1146304675716

Seeing Alice makes a profit, Bob wants to close his position too, only to find out that he lost -7.84012298 USDC (10192.1598770177-98.1146304675716*10192.1598770177/ (98.1146304675716+1.8853695324283)-200) after closing his position.

Action (Chronological)

ETH/USDC (x)

USDC (y)

*Calculation

Initial State

100

10,000

Alice gets 1.96 long position

98.0392156862745*

10,200

100*10,000/10,200

Bob gets 1.89 long position

96.1538461538461*

10,400

98.0392156862745*10,200/10,400

Alice closes her position

98.1146304675716

10,192.1598770177*

96.1538461538461*10,400/98.1146305

Bob closes his position

100

10,000*

98.1146304675716*10,192.1598770177/100

So what can learn from the example above?

Unique Properties of Perpetual Protocol's vAMM

  • One trader's gain equals another trader's loss. As you can see Alice's gain equals Bob's loss, which is similar to traditional peer-to-peer futures trading.

  • No liquidity providers are involved because we don't store real tokens inside our vAMMs.

  • The Vault always has enough collateral to pay back every trader because one trader's gain will cancel out another trader's loss.

Trading on xDai Chain

We've decided to move all of the trading activities onto xDai Chain to save traders' gas fees and improve the trading experience. Here is the updated architecture:

The architecture of Perpetual Protocol with Ethereum as Layer 1 and xDai as Layer 2

As you can probably tell, all of the components related to trading activities such as Clearing House, Insurance Fund, etc., are all on xDai now.

Despite this major change, only one additional step is needed for traders to start trading compared to the above example, which assumes the trading activities happening on the main Ethereum network:

  1. You deposit USDC to the Deposit Proxy (using MetaMask/WalletConnect), which is a smart contract that passes your deposit to the Root Bridge Contract, crediting you the same amount of xUSDC to your address on xDai.

When you want to open a position from our trading platform, the only thing you need to do is to sign a transaction with your wallet (using MetaMask/WalletConnect); the signature will be submitted to the Meta Transaction Relayer (no gas is involved in this step, since it's a meta transaction). The position is opened on xDai, and the trading platform is updated.

One thing we want to emphasize is that, despite using xDai to launch on Ethereum mainnet, with the above architecture, it’s possible to migrate the whole system to other scaling solutions (L2 and other chains alike) without much hassle. One can imagine the Perpetual DAO voting to pause trading activities on xDai, snapshot the state (traders’ active positions, balances, etc.), and proceed to ‘paste’ every trader’s state onto another L2/chain and resume trading activities.

You can check this Medium post to know the rationale behind the move to xDai and the pros and cons of this decision.

Hourly Funding Payment

Periodic funding payments are the most common mechanism used by exchanges to do perpetual swaps. Funding payments act to converge the mark price (the price on the exchange) and the index price (the average price from major exchanges).

Perpetual Protocol follows FTX's method to calculate the funding payments, which is done according to the formula below:

fundingPayment=positionSizefundingRatefundingPayment = positionSize * fundingRate

The fundingRate in the formula above is calculated by, firstly, subtracting the hourly time-weighted average price (TWAP) of the index price from the hourly TWAP of the mark price, and secondly, dividing the result from the previous step by 24.

fundingRate=TWAPperpetualTWAPindex24fundingRate = {TWAP_{perpetual} - TWAP_{index} \over 24}

We use the price feed from Chainlink as the data source for the index price because it is currently the most battle-tested Oracle solution on the market.

If the fundingRate is positive, long position holders need to pay the funding payment while short position holders will receive the funding payment, and vice versa if the rate is negative. The funding payment happens at the end of each hour on Perpetual Protocol, which is similar to a conventional futures contract that expires once per day.

Sound complicated? Let's take a look at another example.

Example

Similar to the example from the previous section, 100 ETH/USDC and 10,000 USDC are set as the initial state in our vAMM at launch. Both Alice and Bob use 100 USDC as the margin to open long positions with 2x leverage, one after the other. And right after Bob opens his position, Alice closes her long position and realizes a profit of 7.84012298 USDC.

Action (Chronological)

ETH/USDC (x)

USDC (y)

Mark Price

*Calculation

Initial State

100

10,000

100

Alice gets 1.96 long position

98.0392156862745*

10,200

104.04

100*10,000/10,200

Bob gets 1.89 long position

96.1538461538461*

10,400

108.16

98.0392156862745*10,200/10,400

Alice closes her position

98.1146304675716

10,192.1598770177*

103.880123

96.1538461538461*10,400/98.1146305

If we draw a line chart with the mark price from each action above on the y-axis and each chronological action on the x-axis, below is what we'll get:

Supposing there isn't any action after Alice closing her position and now the time is close to the end of the hour in which all of those actions have happened.

We can imagine two distinct scenarios depending on the difference between the TWAP of the mark price and the TWAP of the index price.

TWAP of the Mark Price > TWAP of the Index Price (Positive Funding Rate)

In this scenario, the long position holders need to pay the funding payment whereas the short holders can receive the funding payment. Participants in our ecosystem will respond in different ways to this situation:

  • Bob might want to close his position or part of his margin will be used to pay the funding payment

  • Arbitrageurs might want to come in and open a short position so they can receive funding payment from the long position holders

TWAP of the Mark Price < TWAP of the Index Price (Negative Funding Rate)

In this scenario, the short position holders need to pay the funding payment whereas the long holders can receive the funding payment. Participants in our ecosystem will behave differently in this situation:

  • Alice might feel frustrated because she could have received the funding payment if she didn't close her position

  • Arbitrageurs might want to come in and open a long position so they can receive funding payment from the short position holders

Staking

PERP holders can lock-up, or "stake", the PERP in their possession for a fixed amount of time to the Staking Pool. In return, stakers are rewarded with the staking incentive, which includes staking rewards in PERP and a part of the transaction fees in USDC.

There are five things that stakers need to be aware of:

  • During a staking period, which is known as "an epoch" on Perpetual Protocol, stakers cannot withdraw their tokens from the Staking Pool. An epoch lasts for 7 days at the time of writing and can be adjusted through the governance process.

  • If stakers want to withdraw their staked PERP after the end of the current epoch, they must submit a transaction to unstake their tokens in the present epoch.

  • PERP holders can start staking their PERP tokens anytime during an epoch, but the staking incentives are time-weighted in each epoch. In other words, the earlier you join an epoch, the more staking incentive in this epoch you will receive proportionally.

  • Transaction fees are claimable right after the epoch, but staking rewards for that epoch are locked until the first day of the same month in the subsequent year.

  • By default, if a staker doesn't unstake their tokens in an epoch, their staked PERP will be rolled over to the next epoch.

Example

Step 1

Assuming the first epoch on Perpetual Protocol starts at 0:00 AM on 4/24/2020. Right after the first epoch starts, PERP token holder Bob stakes 100 PERP to the Staking Pool, and that amount accounts for 10% of the value stored inside it.

Even though anyone who holds PERP can stake their tokens during any given epoch, to make it easier for readers to understand, we assume there is no staker depositing PERP into Staking Pool after Bob.

Step 2

Throughout an epoch, 50% of the transaction fees will be deposited into the Insurance Fund, which is used as the first line of defense when the system faces unexpected losses such as losses in the liquidation process and funding payments. The other 50% will be deposited into the Transaction Fees Pool, which is used to reward stakers to back-up trading activities on Perpetual Protocol.

Should the Insurance Fund be depleted, the Insurance Fund will trigger PERP’s smart contract to mint new PERP and subsequently sell them for collateral in the Vault to ensure the system’s solvency.

Step 3

Assuming there are 1,000 USDC accumulated in the Transaction Fees Pool at the end of this epoch.

In light of Bob's 10% ownership of the Staking Pool, he is eligible to claim 10% of transaction fees generated in this epoch, which is 100 USDC.

Besides the transaction fees, Perpetual Protocol also provides staking rewards in PERP and issued from the Staking Reward Pool as an extra way to incentivize PERP holders to secure the network. If the total amount of staking rewards for this epoch is 10,000 PERP, then Bob is eligible for 1,000 PERP from that. However, it's not claimable until 4/1/2021.