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.
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.
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 (CF) value. Your personal obligation is calculated by comparing the global CF value now against what it was the last time your position was touched (settled).
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.
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:
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
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_sessionfunction)Explicitly calls the
update_fundingfunctionExplicitly calls the
update_twapsfunction
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 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.\
TWAs are always updated before funding
Last updated