> For the complete documentation index, see [llms.txt](https://docs.lighter.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lighter.xyz/trading/funding.md).

# Funding

### Overview

The funding mechanism is a crucial component of perpetual futures trading. It ensures that the price of the perpetual contract closely tracks the underlying asset’s spot price. Unlike traditional futures contracts, perpetual futures do not have an expiration date. To maintain price stability and avoid significant deviations from the spot price, a periodic funding mechanism is implemented.

Funding payments occur at each hour mark. Traders holding long and short positions pay or receive a funding fee based on the difference between the contract price and the spot price. These payments are fully peer-to-peer with no fees taken by the exchange. The funding payment for an account position depends on the size and side of the position, as well as the funding rate.

The funding rate represents the difference between the mark price of the perpetual futures market and the index price, which is equivalent to the spot market price of the underlying asset.

When the funding rate is positive, users with long positions pay a funding fee to users with short positions. When the funding rate is negative, users with short positions pay a fee to users with long positions.

### Premium Calculation

For each minute, at a random time, Lighter calculates the premium of each market, which represents the deviation of the mark price from the index price for the corresponding market:

$$
\text{premium}\_t
=================

\frac{
\max(0,\ \text{ImpactBidPrice}\_t - \text{index}\_t)
----------------------------------------------------

\max(0,\ \text{index}\_t - \text{ImpactAskPrice}\_t)
}{
\text{index}\_t
}
$$

{% hint style="info" %}
For the premium to be positive (i.e. for long positions to pay funding to short positions), the impact bid price needs to be higher than the index price. When $$\text{ImpactBidPrice}\_t \leq \text{index}\_t \leq \text{ImpactAskPrice}\_t$$, the $$\text{premium}\_t$$ is 0.
{% endhint %}

### Funding Rate Calculation

At the end of each hour, a 1-hour premium is calculated as the time-weighted average of the 60 premiums calculated over the course of the last hour. In addition to the premium component, each market has a fixed interest rate component that accounts for the difference in interest rates of the base and quote currencies. The funding rate is then calculated as:

$$
\begin{aligned}
\text{premium}
&= \text{Average of premium}\_t \text{ since the latest funding}
\times \text{FundingPremiumMultiplier}
\\\[4pt]
\text{smallClamp}
&= \text{SmallClamp} \times \text{FundingPremiumMultiplier}
\\\[4pt]
\text{smallClampedPremium}
&= \text{premium}

* \operatorname{clamp}\bigl(
  \text{InterestRate} - \text{premium},\
  -\text{smallClamp},\
  +\text{smallClamp}
  \bigr)
  \\\[4pt]
  \text{fundingRate}
  &= \frac{
  \operatorname{clamp}\bigl(
  \text{smallClampedPremium},\
  -\text{BigClamp},\
  +\text{BigClamp}
  \bigr)
  }{8}
  \\\[4pt]
  \text{where}\quad
  \operatorname{clamp}(x, a, b)
  &= \max\bigl(a, \min(b, x)\bigr)
  \end{aligned}
  $$

Dividing the 1-hour premium by 8 ensures that funding payments for the premium are distributed over 8 hours, closely aligning with the approach adopted by centralized perpetual exchanges.

#### Parameters

The values used for the majority of the markets are the following:

$$
\text{SmallClamp} = 0.05%,
\qquad
\text{BigClamp} = 4%,
\qquad
\text{InterestRate} = 0.01%
$$

* $$\text{SmallClamp}$$ pulls the $$\text{premium}$$ towards the $$\text{InterestRate}$$. If $$\text{InterestRate} - \text{smallClamp} \leq \text{premium} \leq \text{InterestRate} + \text{smallClamp}$$, then $$\text{fundingRate} = \text{InterestRate} / 8$$. In other words, if the premium is within 5 basis points (scaled by the market’s $$\text{FundingPremiumMultiplier}$$) of the interest rate, funding defaults to the normal value of 1 basis point per 8 hours.
* $$\text{BigClamp}$$ limits funding payments to $$4%$$ per 8 hours, or $$0.5%$$ per hour.
* $$\text{FundingPremiumMultiplier}$$ is configurable per market and ranges over $$(0, 1]$$. It is set to $$1$$ for crypto markets, $$1/2$$ for RWA markets, and $$1/100$$ for Pre-IPO and Pre-Markets.

#### Example

For a crypto market ($$\text{FundingPremiumMultiplier} = 1$$) with a premium of $$0.1%$$:

$$
\begin{aligned}
\text{smallClampedPremium}
&= 0.1%

* \operatorname{clamp}\bigl(
  0.01% - 0.1%,\
  -0.05%,\
  +0.05%
  \bigr)
  \= 0.05%
  \\\[4pt]
  \text{fundingRate}
  &= \frac{\operatorname{clamp}(0.05%,\ -4%,\ +4%)}{8}
  \= 0.00625%
  \end{aligned}
  $$

### Funding Payment

The funding payment for account $$i$$ in market $$j$$ is calculated as follows:

$$
\text{funding}\_{i,j}
=====================

-,\text{position}\_{i,j}
\times
\text{index}\_j
\times
\text{fundingRate}\_j
$$

A positive $$\text{funding}\_{i,j}$$ is credited to the account and a negative value is charged.
