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 Perpetual Protocol) and the index price (the average price from major exchanges).
Perpetual Protocol calculates funding payments every hour.
Perpetual Protocol follows FTX's method to calculate the funding payments, which is done according to the formula below:
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. (Note: FTX's formula results in funding denominated in position size, whereas our calculation expresses funding in quote asset, ie. USDC.)
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. Other oracles will be added as needed.
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.
Sound complicated? Let's take a look at another 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.
Alice gets 1.96 long position
Bob gets 1.89 long position
Alice closes her position
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.
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
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