# Funding Payments
Perpetual contracts rely on a scheduled payment between longs and shorts known as funding payments. Funding payments are meant to converge the price between the derivative contract (mark price) and its underlying (index price).
Funding payments on Nibi-Perps occur every half-hour. This setup is analogous to a traditional future that expires once a day. If a perp trades consistently at 2% above its underlying index price, the funding payments would amount to 2% of the position size after a full day.
If the funding rate is positive, mark price is greater than index price and longs pay shorts. Nibi-Perps automatically deducts the funding payment amount from the margin of the long positions.
Here, position size refers to amount of base asset represented by the derivative. I.e., a BTC:USD perp with 7 BTC of exposure would have a position size of 7.
# Price Divergence
When the mark price deviates from the index price, there is a price divergence calculated as
where is the price divergence (unitless), is the mark price (units of USDC/base), and is the index price (units of USDC/base). When people refer to the βfunding rateβ, they are referring to the price divergence.
We call the term, , the premium.
# Funding Payment
The funding payment a trader pays (or receives) is directly proportional to the price divergence and their position size at the time the funding payment is calculated (once every 30 minutes on the Nibiru Chain).
Variable | Description |
---|---|
funding payment in quote units (e.g. USD) | |
Size of all perp positions in base units | |
Payment frequency. The number of daily payments. |
Given that the Nibiru has 30 minute funding intervals, there are n=48 payments per day.
Substituting in and re-arranging terms, we get
The term is called the premium fraction.
# It's better to store premium fraction than price divergence.
Recall from our funding payment equations above that the funding payment is proportional to the index price at the time of the funding rate interval.
Over several funding intervals, there will be new prices at which we compute the funding rate that needs to be applied to each position. There are two main approaches for performing this computation.
Naive Approach: One way to account for each of these payments is to store a history of the index price and divergence at each funding time. The unrealized payments could then be calculated and applied to the positiion the next time it undergoes a size change.
Cumulative Approach: Instead of keeping track of and separately, itβs more efficient to combine them together and store them as . Then, we only need to store the term on-chain and multiply by when calculating the unrealized funding payment for a position.
Nibiru uses the cumulative approach and realizes funding payments lazily.
# Lazily Realized Funding Payments
A funding payment, , occurs at a funding time . The net funding for the exchange is then
Or more correctly accounting for time, weβd write
At the end of a funding rate interval, the premium fraction, , is recomputed using the current mark and index TWAPs. Summing premium fractions over multiple funding intervals produces a cumulative premium fraction (CPF).
Nibiru stores the latest cumulative premium fraction on-chain to determine how much a trader should pay (or receive) in funding.
Every position keeps track of what the most recent CPF value when undergoing a state change. A state change for a position refers to the execution of any perp module message such as MsgOpenPosition
, MsgClosePosition
, MsgAddMargin
, MsgRemoveMargin
, or MsgLiquidate
.
The next time that position changes, the difference between the exchangeβs latest CPF and the positionβs CPF is the unrealized premium fraction that needs to be accounted for on the traderβs position. This value is equivalent to the percentage of the traderβs size that needs to be payed or received in funding.
This method of allowing positions to backpay for missed funding payments is often referred to as βcall by needβ or βlazy evaluationβ in the computing world.
Q: Why are funding payments realized lazily?
Funding payments are realized lazily to prevent a performance bottleneck. Realizing all funding payments at each funding interval would mean iterating over all of the positions for each market at each funding interval. As the number of positions and markets grows on Nibi-Perps, this computation becomes impractical.
# Perpetual Funding Rates on dYdX
The key difference between Nibi-Perps and dYdX funding rates is that Nibiru uses .
The resulting funding payment on dYdX is
- : base interest rate of 0.00125% = 0.125bps = 0.125e-4
- Source: Perpetual Funding Rate - help.dydx.exchange (opens new window)z