> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gte.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Funding

Funding is the mechanism that keeps perpetual markets balanced by incentivizing traders to take positions that reduce market skew and bring the price of perp contracts close to the underlying spot price. When there are more longs than shorts, longs pay shorts. When there are more shorts than longs, shorts pay longs.

## How Funding Works

GTE uses a sophisticated funding system that's **cadence-invariant** - meaning the realized funding is independent of when settlements happen. This ensures fairness regardless of timing.

### The Premium Signal

Every minute, GTE samples the **premium** - the difference between the mark price and index price:

$$
\text{premium} = \frac{\text{markPrice} - \text{indexPrice}}{\text{indexPrice}}
$$

This premium tells us how much the perpetual is trading above or below its fair value. The system maintains a rolling average (TWAP) of these premium samples (every 5-15s) over the last 60 minutes to smooth out noise.

### Funding Rate Calculation

At each funding interval, GTE calculates the funding rate using a two-step process:

**Step 0: Premium**

```
P̄_decimal = Mark / Index - 1
P̄ = P̄_bps = 10_000 × P̄_decimal
```

**Step 1: Inner Clamp**

```
F_raw = P̄ + clamp(IR_int - P̄, -K, K)
```

**Step 2: Outer Cap**

```
F = clamp(F_raw, -C, C)
```

Where:

* `P̄` = Premium TWAP (rolling average)
* `IR_int` = Interest rate component (usually 0)
* `K` = Inner clamp (50 bps default)
* `C` = Outer cap (100 bps default)

**Positive funding rate** means longs pay shorts. **Negative funding rate** means shorts pay longs.

### Funding Accrual

The funding rate is converted to a per-second rate and continuously accrued:

```
r_sec = F / T_interval
dQFI = r_sec × I × dt
QFI = QFI + dQFI
```

Where:

* `r_sec` = Per-second funding rate
* `I` = Index price
* `dt` = Time elapsed since last Funding settlement
* `QFI` = Quote Funding Index (cumulative)

### Account Settlement

When your position changes or funding settles, the system calculates your funding payment:

```
funding_pnl = -sign(Q) × |Q| × (QFI - last_QFI)
```

**Sign convention:**

* Long positions (`Q > 0`) pay when `F > 0`
* Short positions (`Q < 0`) pay when `F < 0`

## Dynamic Funding Intervals

GTE can shorten funding intervals during high volatility to respond faster to market conditions. This is called a **RESET**.

### RESET Triggers

The system may trigger a RESET when:

* Premium divergence exceeds certain thresholds
* Market conditions change rapidly
* Risk management requires faster response

### RESET Process

1. **Close** the current interval early
2. **Re-seed** the premium sampling if needed
3. **Start** a new interval with fresh parameters
4. **Continue** QFI accrual (no reset)

RESETs don't affect your funding payments - they just change when settlements happen. The total funding over time remains the same.

## Funding Parameters

GTE uses these default parameters:

| Parameter   | Description                  | Default      | Range              |
| ----------- | ---------------------------- | ------------ | ------------------ |
| `N_minutes` | Premium TWAP window          | 60 minutes   | 5-1440 minutes     |
| `T_nominal` | Nominal funding interval     | 3600 seconds | 1800-86400 seconds |
| `T_min`     | Minimum interval after RESET | 300 seconds  | 60-3600 seconds    |
| `K`         | Inner clamp                  | 50 bps       | 10-200 bps         |
| `C`         | Outer cap                    | 100 bps      | 50-500 bps         |

The funding interval and RESET interval are admin-settable. To start, they are set to **1 hour for funding and 30 minutes for RESETs**.

## Funding Examples

### Example 1: Normal Market

* Index Price: \$1000
* Mark Price: \$1006 (60 bps premium)
* Premium TWAP: 60 bps
* Interest Rate: 0 bps
* Inner Clamp: 50 bps
* Outer Cap: 100 bps

**Calculation:**

```
F_raw = 60 + clamp(0 - 60, -50, 50) = 60 + (-50) = 10 bps
F = clamp(10, -100, 100) = 10 bps
```

**Result:** Longs pay shorts 0.1% per hour

### Example 2: High Premium

* Index Price: \$1000
* Mark Price: \$1020 (200 bps premium)
* Premium TWAP: 200 bps
* Interest Rate: 0 bps
* Inner Clamp: 50 bps
* Outer Cap: 100 bps

**Calculation:**

```
F_raw = 200 + clamp(0 - 200, -50, 50) = 200 + (-50) = 150 bps
F = clamp(150, -100, 100) = 100 bps
```

**Result:** Longs pay shorts 1% per hour (capped at outer limit)
