mathematically perfect

certified optimal execution

A coin whose program refuses every trade that is not provably the best one.

value
usd, refreshed every second
price
usd per token
supply
on chain, read once
reserve
lamports in the vault, as sol
inventory
tokens held by the program
accepted
residual exactly zero
rejected
residual above zero
binding
constraint holding the optimum
live value · usd price from birdeye multiplied by on chain supply. The line is the last six hours of one minute closes with the live sample as its last point.
abstract

Most trading agents are judged after the fact. This one is judged before. The program holds a reserve of SOL and an inventory of the coin, and it will execute a trade only when the trade arrives together with a certificate that it is the unique maximizer of a fixed concave objective under three hard constraints. The certificate is a point and three multipliers. The program checks the four conditions that characterise a constrained optimum, in exact fixed point arithmetic, and computes a single residual. A residual of zero means no other trade size could have scored higher; the program then executes exactly that size through the coin's own curve. A residual above zero is recorded as a rejection with its parts. The model that proposes trades is therefore not trusted to be good. It is only allowed to be perfect. This page gives the objective, the constraints, the certificate, the pass, and the accounting the program never breaks.

the objective

The program's reserve is R lamports of SOL and its inventory is I base units of the coin. The coin trades on a constant product curve with SOL reserve s and token reserve t, so every trade has an exact cost. Write x for the trade size in tokens, positive for a buy and negative for a sell. The objective is the sum of the logarithms of what the program holds after the trade:

U(x) = ln(R − c(x)) + ln(I + x)objective

Logarithms make the objective care about proportion, not size. Doubling the reserve and halving the inventory leaves the sum where it was. The objective is strictly concave on its domain, which is the single fact the whole mechanism rests on: a concave function over an interval has exactly one maximum, so when the program verifies a certificate it is verifying the best trade, not a good one.

symbolmeaninglive
Rreserve, lamports of sol in the vault
Iinventory, tokens held by the vault
ssol side of the curve
ttoken side of the curve
ks · t, the curve constant
xtrade size in tokens, buy positive, sell negative
c(x)exact cost of the trade in sol

the cost of a trade

The curve is a constant product, so the cost of moving x tokens out of it is closed form. The same expression gives proceeds for a sell, as a negative cost.

c(x) = k / (t − x) − scost
c′(x) = k / (t − x)²marginal cost
p(x) = (s + c(x)) / (t − x)price after

The marginal cost is the slope of the curve at the trade's end point. The price after the trade is simply the new ratio of the reserves. Both appear in the certificate check, and both are computed by the program from the curve account at the moment of verification, never from the submitter.

buysellc(x)
cost curve · The cost of a trade against a constant product curve. The dashed line is the marginal cost at zero; the curve bends away from it in both directions, which is why large trades are penalised on both sides.

the constraints

Three constraints bound the trade. Each is written so that a feasible trade makes it non positive.

g₁(x) = c(x) − (3/4) · R ≤ 0reserve
g₂(x) = |p(x) − p₀| / p₀ − 1/20 ≤ 0impact
g₃(x) = −(I + x) ≤ 0inventory

The reserve constraint stops the program from spending more than three quarters of what it holds in one trade. The impact constraint stops it from moving the price by more than five percent. The inventory constraint stops it from selling tokens it does not have. Together they cut an interval out of the real line, and the objective is maximised over that interval.

constraintboundderivativelive λ
reserve(3/4) · Rc′(x)
impact1/20sign(x) · p′(x) / p₀
inventory0−1
g₁g₁g₂g₂g₃g₃
feasible interval · Each constraint admits an interval of trade sizes. The program maximises over their intersection, drawn in orange. The certified optimum is either interior, where the objective's derivative is zero, or on an edge, where a multiplier is positive.

the certificate

A certificate is four numbers: the proposed trade size and one multiplier per constraint. The program forms the Lagrangian and checks the four conditions that hold at, and only at, a constrained maximum of a concave function.

L(x, λ) = U(x) − λ₁ g₁(x) − λ₂ g₂(x) − λ₃ g₃(x)lagrangian
conditionstatementresidual part
stationarityU′(x*) = λ₁ g₁′(x*) + λ₂ g₂′(x*) + λ₃ g₃′(x*)r_stat
primal feasibilitygᵢ(x*) ≤ 0 for every ir_prim
dual feasibilityλᵢ ≥ 0 for every ir_dual
complementary slacknessλᵢ · gᵢ(x*) = 0 for every ir_slack
residual = r_stat + r_prim + r_dual + r_slackresidual

Each part is a sum of absolute values or positive parts, so the residual is zero exactly when all four conditions hold. The program computes it in Q64.64 fixed point and compares it with zero, not with a tolerance. Submitters who want their trade executed must therefore solve the problem exactly in the same arithmetic the program uses, which is published in the docs. A certificate that is close is a certificate that is rejected.

The saddle point is the geometry of the check. Along x the Lagrangian rises to a peak; along λ it falls to a trough. The certified point sits at the crossing, a maximum in one direction and a minimum in the other. Everything the program accepts is a saddle point of L, and nothing else.

xλ(x*, λ*)
saddle surface · The Lagrangian as a surface. The orange cross section is a maximum along the trade size; the light orange cross section is a minimum along the multipliers. The accepted point is the crossing.

the pass

There is no schedule. The prover subscribes to the curve account and reacts to trades. Every pass has the same shape.

curve changesany buy or sellread states, t, R, Isolvex*, λ₁, λ₂, λ₃submitcertificate txexecuteexactly x*, then recordrejectrecord residual partsresidual = 0yesno
pass flow · A trade by anyone changes the curve, which makes the previous optimum stale. The prover reads the fresh state, solves, and submits a certificate. The program recomputes the residual and either executes the exact size or records why it refused. Both outcomes return the loop to waiting.
stepwhat happens
curve changesThe curve account's reserves move because someone bought or sold. The prover's subscription fires.
read stateThe prover reads s and t from the curve, R and I from the vault, and the current creator fee balance.
solveThe prover maximises U over the feasible interval in Q64.64, producing x* and the multipliers, and sets any λ to zero whose constraint is slack.
submitThe prover sends the submit instruction with the four numbers. Anyone else may do the same.
residualThe program recomputes c, c′, p, every gᵢ and gᵢ′, and the four residual parts from chain state.
executeIf the residual is zero, the program trades exactly x* through the curve by cross program invocation, then writes an accepted entry.
rejectOtherwise the program writes a rejected entry with the four parts and the submitter, and nothing moves.

accounting

The program keeps three invariants, checked at the end of every instruction and visible on the pda page.

invariantstatement
reserve floorAfter an execute, R_after ≥ R_before / 4.
inventory signI_after ≥ 0.
single inflowR rises only through claim; no other instruction can deposit sol.

The reserve floor follows from the reserve constraint, the inventory sign from the inventory constraint, and the single inflow from the instruction set. Nothing here is a promise about price. It is a statement about what the program can and cannot do with its own money, and all of it is readable from the accounts.