Skip to main content

Funding Rate

Funding Rate Mechanism

  • Why do we need a funding rate?

    The funding rate is commonly used to anchor the perpetual contract price to the spot price.

  • How does it work

    • The long-side traders are motivated to close positions when the platform charges the long and rewards the short side, causing the contract price to decrease until it equals the spot price.
    • When the contract price is lower than the spot price, the platform charges the short side and rewards the long side. This creates an incentive for short-side traders to close their positions, which results in an increase in the contract price. Eventually, the contract price reaches the spot price.
  • The platform uses reward and punishment mechanisms to ensure the contract price aligns with the spot price in the long run. The JOJO team doesn't profit from the funding rate system, and the funding fee collected is distributed to traders.

Calculation

  • Samples

    Take a sample every five seconds and each sample requires:

    • External index price
    • In the 20X+ market, the impact bid/ask prices in the JoJo order book correspond to the impact price of a 4000U transaction.
    • In the 10X market, the impact bid/ask prices in the JoJo order book align with the impact price of a 2000U transaction.

    And then calculate sample PP:

    P=(Max(0,ImpactBidPriceIndexPrice)Max(0,IndexPriceImpactAskPrice))/IndexPriceP = (Max(0, Impact Bid Price - Index Price) - Max(0, IndexPrice - Impact Ask Price))/Index Price

    The average PP:

    AverageP=Σ(PiVi)/Σ(Vi)Average P = Σ(Pi * Vi) / Σ(Vi)
    Vi=iVi = i

    The index price is the real-time spot price of the market. It is an average of the prices on the significant markets constitutes. JOJO's index price value is the same as 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=Clamp(averageP+Clamp(IaverageP,0.05%,0.05%),minF,maxF)F = Clamp (average P + Clamp(I - average P, -0.05\%, 0.05\%), min F, max F)
    • II is set to 0.01% since it's collected every 8 hours
    • Max F is the maximum value, approximately 1%
    • Min F is the minimum value, approximately -1%
  • 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 will 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, modifying thousands of credit values would be too costly each time 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);