Funding

What are funding rates?

Funding rates are periodic payments exchanged directly between traders. Their primary purpose is to ensure the Perpetual Contract price stays close to the Underlying Asset (Spot) price.

Unlike transaction fees, funding is peer-to-peer. The exchange does not collect these fees; they are transferred directly between users holding Long positions and users holding Short positions.

How it Works

The funding rate is calculated based on the divergence between the Orderbook price (the price of the perpetual) and the Oracle price (the real-world price of the asset).

  • Positive Funding (Bullish Market): When the Perpetual price is higher than the Oracle price, Longs pay Shorts. This incentivizes traders to sell, driving the price down towards the spot price.

  • Negative Funding (Bearish Market): When the Perpetual price is lower than the Oracle price, Shorts pay Longs. This incentivizes traders to buy, driving the price up towards the spot price.

Thus, funding payments are an incentive for making the price of the perpetual align with its underlying.

circle-info

Aftermath collects no fees on these payments.

Funding Interval & Scaling

While funding is paid hourly, the rate displayed and calculated is based on an 8-hour realization.

  • Displayed Rate: The 8-hour rate (e.g., 0.01%).

  • Hourly Payment: Users pay/receive 1/8 of the computed rate every hour.

circle-info

Funding rates vary per market. Please verify each funding frequency and period on the corresponding market on the front end.

Unrealized Funding

Unrealized funding represents the funding fees that have accrued on your position but have not yet been settled. This mechanism ensures that contracts track the cumulative funding obligations efficiently.

To optimize gas and computation instead of updating every user's balance every second, the protocol tracks a global Cumulative Funding (CFCF) value. Your personal obligation is calculated by comparing the global CFCF value now against what it was the last time your position was touched (settled).

The equation for a position's unrealized funding is:

UnrealizedFundings(p)=BaseAmount(p)βˆ—(CFβˆ’LCF(p)),UnrealizedFundings(p) = BaseAmount(p) * (CF - LCF(p)),

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.

Funding Rates

The Funding Rate determines the velocity of payments between Longs and Shorts. It is driven by the difference between the Book Price (market price) and the Index Price (oracle price).

The funding rate of a market is given by:

Funding=TWAΞ½,Ο‰(BookPriceβˆ’IndexPrice)fρFunding = \text{TWA}_{\nu,\omega}(BookPrice - IndexPrice) \frac{ f }{ \rho }

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.

circle-info

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:

CF←CF+FundingCF \gets CF + Funding
circle-info

𝐢 𝐹 is initialized as 0 at market creation

TWAs (Time-Weighted Averages)

The Time-Weighted Average (TWA) mechanism ensures that the price data used for funding is smooth and resistant to manipulation. The TWA is updated lazily (on-demand) rather than every block.

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:

(TWAΞ½,Ο‰(X),tlast)←(Xtβ‹…(tβˆ’tlast)+TWAΞ½,Ο‰(X)β‹…(tlastβˆ’(tβˆ’Ο‰))Ο‰,t)ifΒ tβ‰₯tlast+Ξ½ (TWA_{\nu,\omega}(X), t_{\text{last}}) \leftarrow \left( \frac{X_t \cdot (t - t_{\text{last}}) + TWA_{\nu,\omega}(X) \cdot (t_{\text{last}} - (t - \omega))}{\omega}, t \right) \quad \textbf{if } t \ge t_{\text{last}} + \nu

𝑑 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 twap period, 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.\

circle-info

TWAs are always updated before funding

Last updated