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.
The total supply is fully accounted for: sum of all bin capacities = total token supply.
Bin States
GOR locked = 0
No purchases yet
GOR locked > 0
Active bin frontier
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:
- 1Swap fee is reserved upfront from the GOR input. Only the net GOR enters CPAMM pricing.
- 2The engine tries to buy tokens from the current bin using CPAMM: tokens_out = T × gor_in / (G + gor_in).
- 3As GOR enters the bin, it's recorded as gor_locked — this is the price buyers paid, locked for sell-side payouts.
- 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.
- 5The remaining GOR continues buying from the next bin at its own CPAMM rate (price naturally increases as bins fill).
- 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
| Constant | Value |
|---|---|
| PRICE_PRECISION | 1,000,000,000 |
| FEE_PRECISION | 1,000,000,000,000 |
| CORE_BINS | 5,000 |
| MAX_SWAP_FEE_BPS | 1,000 (10%) |
| DEFAULT_BIN_FEE_SHARE_BPS | 0 |
| MAX_CREATOR_FEE_SHARE_BPS | 5,000 (50%) |
| MAX_BIN_FEE_SHARE_BPS | 5,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.
Where T = token reserve, G = GOR reserve in the bin. Standard x*y=k output formula.
Ceiling division ensures the pool never undersells.
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.
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.
Swap fee is deducted from the gross GOR payout after all bins are processed.
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
- 1Start at the current active bin and walk downward.
- 2For each bin, check how many tokens were purchased (bin_capacity − tokens remaining).
- 3Settle any pending bin fee credit from the lazy accumulator.
- 4Compute payout from (gor_locked + fee_credit) proportional to tokens returned.
- 5Clamp payout against the solvency floor (gor_reserve ≥ initial_gor_reserve).
- 6Update bin state — fully refilled bins revert to Empty, partial fills become Partial.
- 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.
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.
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: