2026-10-31
Pricing a trade from curve reserves
Every swap row carries the curve's virtual reserves after the trade. The curve keeps their product constant, so the spot price is simply quote reserve divided by token reserve, adjusted for decimals.
SOL = 10**9
TOKEN = 10**6
def spot_price_sol(row):
return (row.virtual_lamports_reserve / SOL) / (row.virtual_token_reserve / TOKEN)What a buy of a given size would cost
For a buy that puts dx of quote into the curve, the tokens out are dy = y - k / (x + dx), where x and y are the quote and token reserves before the trade and k = x * y. Fees come out of the quote first; the fee legs are separate columns, so you can model them exactly.
def tokens_out(x, y, dx_after_fees):
k = x * y
return y - k / (x + dx_after_fees)On PumpSwap, use the effective pricing reserves (virtual_lamports_reserve on those rows), not the vault balance: since September 2026 the pool adds a signed virtual adjustment to its quote side.