Docs/Technical/SLAMM Engine

SLAMM Engine

Sovereign Liquidity AMM — CPAMM buys, locked-rate sells, bin topology, and fee splits.

How Bins Work

Unlike traditional AMMs that use a single liquidity pool, SLAMM distributes tokens across thousands of discrete bins. Each bin is an independent micro-pool with its own reserves, and the engine walks through them sequentially during trades.

Pool Initialization

When a sovereign finalizes, all tokens are distributed across bins with a linear taper. Bin 0 (the largest) holds the most tokens, and capacity decreases as bin index increases.

// Each bin starts fully loaded with tokens, zero GOR
bin.tokens = capacity    ✓ full
bin.gor_locked = 0      — no buyers yet
bin.status = EMPTY      — untouched

The total supply is fully accounted for: sum of all bin capacities = total token supply.

Bin States

EMPTY
Tokens = full capacity
GOR locked = 0
No purchases yet
PARTIAL
Tokens = partially sold
GOR locked > 0
Active bin frontier
FILLED
Tokens = 0 (sold out)
GOR locked = all buyer GOR
Earns bin fee bonuses

Buy Walk

When a buyer sends GOR, the engine starts at the current active_bin and walks forward:

  1. 1Swap fee is reserved upfront from the GOR input. Only the net GOR enters CPAMM pricing.
  2. 2The engine tries to buy tokens from the current bin using CPAMM: tokens_out = T × gor_in / (G + gor_in).
  3. 3As GOR enters the bin, it's recorded as gor_locked — this is the price buyers paid, locked for sell-side payouts.
  4. 4If the buy exhausts all tokens in the bin (tokens → 0), the bin status flips to FILLED and the engine advances active_bin to the next bin.
  5. 5The remaining GOR continues buying from the next bin at its own CPAMM rate (price naturally increases as bins fill).
  6. 6This repeats until all GOR is spent or a page boundary is hit (partial fill — SDK retries after extending).

Why This Matters

Each bin records exactly how much GOR buyers deposited into it ( gor_locked). When sellers return tokens later, they're paid from this locked GOR at the historical rate — not from a shifting curve. This is how SLAMM eliminates impermanent loss: the sell price is derived from what buyers actually paid, not from current pool ratios.

Constants

ConstantValue
PRICE_PRECISION1,000,000,000
FEE_PRECISION1,000,000,000,000
CORE_BINS5,000
MAX_SWAP_FEE_BPS1,000 (10%)
DEFAULT_BIN_FEE_SHARE_BPS0
MAX_CREATOR_FEE_SHARE_BPS5,000 (50%)
MAX_BIN_FEE_SHARE_BPS5,000 (50%)

Buy Pricing — CPAMM

Buys use standard constant-product AMM math. The buyer sends GOR and receives tokens from the current bin. Price increases as bin reserves deplete.

Buy — Tokens Out
tokens_out = T × gor_in / (G + gor_in)

Where T = token reserve, G = GOR reserve in the bin. Standard x*y=k output formula.

Inverse Buy — Cost to Acquire
cost = ⌈G × tokens / (T − tokens)⌉

Ceiling division ensures the pool never undersells.

Spot Price
price = G × PRICE_PRECISION / T

Scaled to 9 decimal places via PRICE_PRECISION.

Sell Pricing — Locked Rate

Sells do not use CPAMM. Instead, the engine walks backward through bins and pays sellers based on the historical weighted-average purchase rate locked into each bin. This is what eliminates impermanent loss — sellers receive a price derived from what buyers actually paid, not from a shifting x*y=k curve.

Sell — GOR Payout Per Bin
payout = (gor_locked + fee_credit) × tokens_returned / tokens_sold_in_bin

Each bin tracks its own gor_locked (GOR deposited by buyers) and fee_credit (accumulated bin fee bonuses). The payout is proportional to how many tokens are returned.

Fee Deduction
net_payout = total_gor_payout − (total_gor_payout × swap_fee_bps / 10000)

Swap fee is deducted from the gross GOR payout after all bins are processed.

Solvency Floor
gor_reserve ≥ initial_gor_reserve

The engine will never pay out more GOR than the surplus above the initial bond. If a payout would breach this floor, it is clamped and tokens are proportionally adjusted.

How the sell walk works

  1. 1Start at the current active bin and walk downward.
  2. 2For each bin, check how many tokens were purchased (bin_capacity − tokens remaining).
  3. 3Settle any pending bin fee credit from the lazy accumulator.
  4. 4Compute payout from (gor_locked + fee_credit) proportional to tokens returned.
  5. 5Clamp payout against the solvency floor (gor_reserve ≥ initial_gor_reserve).
  6. 6Update bin state — fully refilled bins revert to Empty, partial fills become Partial.
  7. 7Deduct swap fee from the total gross payout. Return net GOR to seller.

Bin Topology

Bins are not equal-sized. Token capacity follows a linear taper — bin 0 is the largest, and capacity decreases toward higher-indexed bins. This creates a natural price curve where earlier bins are cheaper and later bins are more expensive.

Core Bins
5,000
Extension Bins
~1,250
Derived by compute_ext_bins
Total Bins
~6,250
Typical at default taper
Base Capacity (Bin 0)
c0 = S × 20000 / (N × (10000 + p) + K × p)

S = total supply, N = core bins (5,000), K = extension bins, p = p_end_bps (taper endpoint). This formula ensures the sum of all bin capacities equals the total token supply.

Per-Bin Capacity
cap(i) = max(0, c0 − ⌊drop_bps × c0 × i / D⌋)

D = 10000 × (core_bins − 1). With default p_end_bps = 2000, bin 4999 holds 20% of bin 0's capacity. Extension bins continue the taper below that.

Extension bins are computed by compute_ext_bins and allocated incrementally via extend_bin_array calls (max 10,240 bytes per call due to Solana account size limits).

Fee Split Algorithm

Every swap fee is split by compute_fee_split using three parameters and the current recovery state:

compute_fee_split(fee, creator_share_bps, bin_share_bps, recovery_complete)

1. Bin share deducted first:  bin_fee = fee × bin_share_bps / 10000
2. Remainder:                 remaining = fee − bin_fee

During Recovery:
3a. LP gets 100% of remainder
3b. Creator gets 0

Post-Recovery (Active):
3a. Creator gets:   remaining × creator_share_bps / 10000
3b. LP gets:        remaining − creator_fee

Recovery Phase

LPs receive 100% of non-bin fees. Creator share is zero. This accelerates LP principal recovery.

Active Phase

Remaining fees after bin share split between LP and creator based on creator_share_bps.

Math Primitives

Core functions in sovereign-engine-v3/src/math.rs:

compute_bin_capacity()
compute_ext_bins()
compute_c0()
cpamm_tokens_out()
cpamm_cost()
compute_spot_price()
compute_fee_split()
update_bin_fee_accumulator()
settle_bin_fee_credit()
update_fee_per_share()
compute_claimable_fees()
update_twap()
get_lifetime_twap()