Agentic MarketAgentic Market Docs
Protocol Architecture

Economics & AMM Math

Complete-Set FPMM equations, unbalanced seeding bounds, symmetric dynamic & opening fees, saturating position caps, and O(1) Leaky Bucket Vault.

All AMM formulas are implemented identically in Solidity (BinaryFpmmLib, FeeMathLib, LeakyBucketLib) and TypeScript (app/src/lib/math.ts), with every rounding step strictly favoring the pool or protocol.


Complete-Set Conservation & Spot Price

Let NN be the number of outcomes (N=2N=2 in BinaryEngine, N∈[3,5]N \in [3, 5] in MultiEngine), rir_i the pool reserve of outcome ii, viv_i Vault shares, uiu_i aggregate trader shares, and CC total market collateral.

Complete-set conservation holds after every operation (INV-2):

∀i:ri+vi+ui=C\forall i:\quad r_i + v_i + u_i = C

Marginal spot probability (PRICE_SCALE =109= 10^9):

Pi=∏j≠irj∑m=1N∏j≠mrj(Binary: P0=r1r0+r1, P1=1−P0)P_i = \frac{\prod_{j \ne i} r_j}{\sum_{m=1}^{N} \prod_{j \ne m} r_j} \qquad \text{(Binary: } P_0 = \frac{r_1}{r_0 + r_1},\ P_1 = 1 - P_0\text{)}

Buy Formula (Collateral In → Shares Out)

Given gross collateral input a≥a \ge MIN_TRADE_AMOUNT (1_000_000 units = 1.00 USDT):

  1. Compute fee with upward rounding (ceilDiv) and net minted sets xx:
fee=⌈a⋅feeBps10,000⌉,x=a−fee\text{fee} = \left\lceil \frac{a \cdot \text{feeBps}}{10{,}000} \right\rceil, \qquad x = a - \text{fee}
  1. Mint xx complete sets into every reserve (rj←rj+xr_j \leftarrow r_j + x) and solve the updated reserve ri′r_i' rounding up:
ri′=⌈ri∏j≠irjrj+x⌉,sharesout=ri+x−ri′r_i' = \left\lceil r_i \prod_{j \ne i} \frac{r_j}{r_j + x} \right\rceil, \qquad \text{shares}_{\text{out}} = r_i + x - r_i'
  1. Update collateral += x, feeAcc += fee, shares[i] += sharesOut, and netCostBasis += a (enforcing netCostBasis <= key.maxPosition).

Binary Sell Formula (Closed-Form Quadratic)

When a trader sells ss shares of outcome ii (with opposing reserve rjr_j), the pool burns cc complete sets preserving (ri+s−c)(rj−c)≥rirj(r_i + s - c)(r_j - c) \ge r_i r_j:

c=⌊B−⌈B2−4srj⌉2⌋,B=ri+rj+sc = \left\lfloor \frac{B - \left\lceil \sqrt{B^2 - 4 s r_j} \right\rceil}{2} \right\rfloor, \qquad B = r_i + r_j + s

Net payout after symmetric fee is net=c−⌈c⋅feeBps/10,000⌉\text{net} = c - \lceil c \cdot \text{feeBps} / 10{,}000 \rceil.

  • Full-Exit Exemption (INV-8): Selling 100% of remaining shares (sharesIn == type(uint40).max) bypasses MIN_TRADE_AMOUNT (1 USDT) so small dust balances are never stranded.
  • Saturating netCostBasis (INV-7): Profitable sells clamp netCostBasis to 0 without underflow.

For N∈[3,5]N \in [3, 5] (MultiEngine V1.1), sell() uses Verify-Don't-Compute: /quote supplies uint48 hintCollateralOut, verified on-chain in O(1)O(1) via f(h)≤0<f(h+1)f(h) \le 0 < f(h + 1) with a bounded 48-iteration bisection fallback if stale.


Dynamic & Opening Fees

Effective fee is feeBps=max⁡(dynamicFeeBps(t), openingFeeBps(t))\text{feeBps} = \max(\text{dynamicFeeBps}(t),\ \text{openingFeeBps}(t)):

  • Symmetric Dynamic Fee (OD-3): Linear ramp from 100 bps (1.0%) to 300 bps (3.0%) over the final 15 minutes of 1h BTC markets and final 30 minutes of 4h BTC & trend markets—applied identically to buys and sells.
  • Opening Fee (Price Markets Only): Linear decay from 250 bps (2.5%) to 100 bps (1.0%) over the first 120s after launch to neutralize launch-second oracle latency arbitrage.

Unbalanced Seeding & O(1)O(1) Leaky Bucket Vault

  • Adaptive Seeding Bounds (OD-6):
    • MIN_SEED = 30 USDT, hard reserve floor R_MIN >= 5 USDT on every outcome.
    • Lean seed (< 100 USDT): initial probabilities constrained to [15%, 85%].
    • Deep seed (>= 100 USDT): initial probabilities constrained to [10%, 90%].
  • Proportional Position Cap (OD-5): maxPosition = min(1.5 * seed, 500 USDT).
  • Rolling 7-Day Leaky Bucket (INV-10): Net Vault outflows over any rolling 7d window (LEAK_WINDOW) are capped by maxOutflowPerWindow (recommended 25% of Active Float) using a single storage slot with continuous linear decay, guaranteeing net Vault loss on any single market never exceeds key.seed.