Funding
Last updated
Last updated
Funding payments are periodical cashflows exchanged between long- and short-position holders. They are based on the divergence between the price at which the perpetuals are trading for on the orderbook and the price of the underlying given by the oracle. Typically, when the market is bullish and the price of the perpetual is higher than the underlying, payments will be made from long-position holders to short-position holders. Conversely, in a bearish market, short-position holders will pay long-position holders. Thus, funding payments are an incentive for making the price of the perpetual align with its underlying.
The equation for a position's unrealized funding is:
where 𝐶𝐹 ∈ 𝑅 is the market's current cumulative funding rate and 𝐿𝐶𝐹 ( 𝑝 ) ∈ 𝑅 is its value when the position last settled its funding payments in that market.
In other words, the contracts keep a cumulative funding rate and every time a position's funding rates are settled, the value of that cumulative is stored in the position.
The funding rate of a market is given by:
TWA 𝜈 , 𝜔 ( 𝑋 ) ∈ 𝑅 is the time-weighted average (see the following section on TWAs). The parameters 𝜈 and 𝜔 are set at market creation, but can also be changed by the owner of an AdminCapability
. Usual values for funding rates would be 𝜈=1 𝑚 and 𝜔=1 ℎ .
The funding frequency, 𝑓 , is the time span between each funding rate update, e.g., 1 hour. In other words, the aforementioned cumulative funding rate for a market ( 𝐶 𝐹 ) is updated every 𝑓 .
The funding period, 𝜌 , is the period of time over which funding (the difference between book and index prices) gets paid.
Setting the funding period too long may cause the perpetual to start trading at a very dislocated price to the index because there's less of an incentive for basis arbitrageurs to push the prices back in line since they would have to carry the basis risk for a longer period of time. Setting the funding period too short may cause nobody to trade the perpetual because there's too punitive of a price to pay in the case the funding rate flips sign.
We also clip the difference 𝐵𝑜𝑜𝑘 𝑃𝑟𝑖𝑐𝑒 − 𝐼𝑛𝑑𝑒𝑥 𝑃𝑟𝑖𝑐𝑒 to be at most 5% (in absolute value) of the 𝐼𝑛𝑑𝑒𝑥 𝑃𝑟𝑖𝑐𝑒. This is to avoid too punitive of a funding rate.
After sampling the funding rate (once each 𝑓 interval), the market's cumulative funding rate is updated simply as:
𝐶 𝐹 is initialized as 0 at market creation
The TWA used above is updated every time a user performs one of the following actions in a market:
Closes a trading session (calls the end_session
function)
Explicitly calls the update_funding
function
Explicitly calls the update_twaps
function
The formula for the TWA update is a weighted average:
𝑡 is the current timestamp, given by the Clock
object onchain. 𝑡 last is the timestamp for the last computed TWA. 𝑋 𝑡 is the random variable observed at time 𝑡 , e.g., the clipped difference between book and index prices.
𝜔 is the t controlling how smooth the TWA is: the bigger 𝜔 is, the more importance is given to past observations.
𝜈 is the twap frequency, controlling how often the TWA is updated. For example, if 𝜈=5 𝑠 , then once the TWA is updated, transactions for the next 5 seconds are going to use the same value.\
TWAs are always updated before funding