Pair
ThePair account stores the state of a trading pair, including reserves, debt, and pricing information.
Account Structure
Fields
Mint address of token0. Must be less than token1 (canonical ordering).
Mint address of token1. Must be greater than token0 (canonical ordering).
Mint address of the LP token for this pair.
Decimal places for token0.
Decimal places for token1.
Address of the rate model account for this pair.
Swap fee in basis points (0-10000). Applied to all swaps.
EMA half-life in seconds. Controls how quickly EMA prices adjust to spot prices.
Optional fixed collateral factor in basis points. If
Some, overrides dynamic CF calculation.Virtual reserve of token0. Used for AMM pricing. Related to cash and debt by:
reserve = cash_reserve + total_debtVirtual reserve of token1. Used for AMM pricing. Related to cash and debt by:
reserve = cash_reserve + total_debtActual available liquidity of token0 in vaults. Protocol fees are tracked as
vault_balance - cash_reserve.Actual available liquidity of token1 in vaults. Protocol fees are tracked as
vault_balance - cash_reserve.Double-EMA price tracking for token0. Contains both
symmetric (two-way) and directional (one-way) EMA values, scaled by NAD (1e9).Double-EMA price tracking for token1. Contains both
symmetric (two-way) and directional (one-way) EMA values, scaled by NAD (1e9).Slot number of last state update.
Last interest rate for token0, scaled by NAD (1e9).
Last interest rate for token1, scaled by NAD (1e9).
Total debt of token0 across all positions (including accrued interest).
Total debt of token1 across all positions (including accrued interest).
Total debt shares for token0. Used for proportional debt tracking. Stored as
u128 for precision.Total debt shares for token1. Used for proportional debt tracking. Stored as
u128 for precision.Total supply of LP tokens. Includes MIN_LIQUIDITY that is permanently locked.
Per-pair reduce-only mode. When enabled, prevents new borrows and liquidity additions.
Total collateral of token0 across all positions.
Total collateral of token1 across all positions.
SHA256 hash of pair parameters. Used for PDA derivation.
Protocol version. Currently 1.
PDA bump seed.
PDA Derivation
The pair account is a PDA derived from:PAIR_SEED_PREFIX = b"gamm_pair".
Reserve Relationship
The three reserve types are related by the solvency invariant:Fee Surplus
Protocol fees are tracked implicitly as the surplus between actual vault balances and accounted cash reserves: This surplus accumulates from two sources:| Fee Source | Mechanism |
|---|---|
| Swap Fees | Futarchy portion transferred immediately; LP portion added to reserves |
| Interest Fees | Cash-covered portion reduces cash_reserve, creating vault surplus |
claim_protocol_fees.
Interest Fee Handling
When interest accrues and cash reserves are limited, the protocol uses a cash coverage mechanism:- Cash covered fee: Reduces
cash_reserve, creating immediate surplus - Uncovered fee: Added to
reserve(virtual); LPs get temporary claim until borrowers repay
ΔR_virtual = ΔR_cash + ΔR_debt always holds.
Key Methods
spot_price0_nad() -> u64
Returns the current spot price of token0 in token1 terms, scaled by NAD.
spot_price1_nad() -> u64
Returns the current spot price of token1 in token0 terms, scaled by NAD.
ema_price0_nad() -> u64
Returns the symmetric EMA price of token0 in token1 terms, scaled by NAD.
ema_price1_nad() -> u64
Returns the symmetric EMA price of token1 in token0 terms, scaled by NAD.
directional_ema_price0_nad() -> u64
Returns the directional (one-way) EMA price of token0, scaled by NAD.
directional_ema_price1_nad() -> u64
Returns the directional (one-way) EMA price of token1, scaled by NAD.
k() -> u128
Returns the constant product reserve0 * reserve1.