Skip to main content

Funding Rate

Funding Rate Mechanism

  • Why do we need a funding rate?

    It is the trading platform's responsibility to ensure that the perpetual contract price is anchored to the spot price, using the funding rate is one of the most common ways to achieve that.

  • How does it work

    • If the contract price is higher than the spot, the platform will charge the long side and reward the short side. So the long side traders are motivated to close positions and thus the contract price decreases until it equals the spot price.
    • If the contract price is lower than the spot, the platform will charge the short side and reward the long side. So the short side traders are motivated to close positions and thus the contract price increases until it equals the spot price.
  • Through such reward and punishment measures, the platform makes the contract price converge with the spot price in long term. JOJO team does not make any profit from the fundingRate system, and the funding fee collected will be all given to the traders.

Calculation

  • Samples

    Take a sample every five seconds and each sample requires:

    • External index price
    • JOJO order-book mid price

    And then calculate sample PP:

    P=(midPriceindexPrice)/indexPriceP = (midPrice-indexPrice) /indexPrice

    Index price is the real-time spot price of the market. It is an average of the prices on the major markets constitutesThe. JOJO's index price value is the same with Binance Perpetual's index price. Here is the link: https://www.binance.com/en/support/faq/547ba48141474ab3bddc5d7898f97928.

    Samples are storaged off-chain.

  • Calculate the funding rate

    Every 8 hours, there will be 5760 data points. Calculate the mean of these points (essentially calculate the time-weighted average TWAP, because the time interval is the same, so the mean can be calculated directly).

    F=Pˉ(824)=Pˉ/3F = \bar P * (\frac{8}{24}) = \bar P /3
  • Special case

    The funding rate update will stop when there are not enough index price samples available. If 80% of the points are not taken, the funding fee for the eight hours will fail and pass. Pass means there is no change in funding fees in this round, and it will calculate in the next eight hours.

Update

Now we're going to upload the funding rate to the smart contract and update the balance of every trader. This requires some unique algorithm design:

  • The funding rate adjusts credits according to the paper amount. It is impossible to record the number of credits on the chain, otherwise, it would be too costly to modify thousands of credit values each time when the funding rate is updated.
  • We store reducedCredit instead of credit itself. So that after the funding rate is updated, the credit will update without any extra storage write. FundingRate here is a little different from what it means at CEX. It is a cumulative value, and its absolute value doesn't mean anything but the changes (due to updates transactions) matter. For example: If the fundingRate increases by 5 at a certain update, then you will receive 5 credits for every paper you long. And you will be charged 5 credits for every paper you short. The real credit calculates using the following formula:
credit=(paperfundingRate)+reducedCreditcredit = (paper * fundingRate) + reducedCredit
FundingRatenew=FundingRateold+FmarkPriceFundingRate_{new} = FundingRate_{old} + F * markPrice
  • So each trader's credit is automatically updated whenever fundingRate is updated. FundingRate can be positive or negative. When fundingRate increases, the smart contract will charge fees from short positions and pay long positions. When fundingRate decreases, the smart contract will charge fees from long positions and pay short positions.

JOJO team will update the fundingRate every 8 hours. You can find fundingRate by calling Perpatual#fundingRate. You can call the IPerpetual#balanceOf() function below to check your paper and credit balances:

function balanceOf(address trader) external view returns (int256 paper, int256 credit);