Start
Integration
The program never searches for a price. A trader names the exact reserve change it wants, and the program only checks it. Quoting therefore happens off chain, and the best quote has a closed form.
Quote the optimal arbitrage
Given reserves x, outside prices s, weights w and fee g, sort assets by s_k x_k / w_k, grow an active set A while (1 - g) w_k M > s_k x_k, with
M = (sum of s_i x_i outside A) / (1 - (1 - g) * sum of w_k in A)
beta_k = (1 - g) w_k M / (s_k x_k) for k in A, 1 otherwise
x_new = x * beta * prod_i beta_i^(-(1 - g) w_i)
Profit is sum s_i x_i - prod(...) * M; if it is not positive the pool is inside its band and there is nothing to trade. Reference implementation: arb_closed in spike/g1_g3m.py, verified against a numerical optimizer and the paper's Theorem 5 floor.
Send the trade
update(deltas: Vec<i64>): deltas[i] > 0 pays asset i in, < 0 takes it out, in raw base units, in the pool's asset order (USDC first).
Remaining accounts, three per asset in pool order: the mint, the pool's vault, your token account.
const keys = pool.mints.flatMap((mint, i) => [
{ pubkey: mint, isSigner: false, isWritable: false },
{ pubkey: pool.vaults[i], isSigner: false, isWritable: true },
{ pubkey: traderAccounts[i], isSigner: false, isWritable: true },
]);
await program.methods.update(deltas).accounts({ trader, pool: poolKey, lpMint, tokenProgram, token2022Program })
.remainingAccounts(keys).rpc();
Leave a small margin on what you take out. An exact optimum lands on the boundary and the check requires the invariant to clear 1e-14.
Read a pool
Every weight is verifiable from the pool account alone: value weight i is price_i * reserves[i] over the sum, and the target at time t is the linear glide between w_from and w_to. The covenant fields sit next to them and never change.
Events
| Event | When |
|---|---|
Published | a fund is created: mints, weights, fee, covenant, glide end |
Seeded | the first liquidity opens the pool |
Deposited, Withdrawn | shares in or out; deferred_mask marks assets left as claims |
Updated | a trade: deltas, the fee it paid (ln_fee), protocol and author shares, whether the royalty gate was open |
Revised | a new target and its glide end, and the fee |