A coin whose program refuses every trade that is not provably the best one.
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:
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.
| symbol | meaning | live |
|---|---|---|
| R | reserve, lamports of sol in the vault | |
| I | inventory, tokens held by the vault | |
| s | sol side of the curve | |
| t | token side of the curve | |
| k | s · t, the curve constant | |
| x | trade 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.
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.
the constraints
Three constraints bound the trade. Each is written so that a feasible trade makes it non positive.
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.
| constraint | bound | derivative | live λ |
|---|---|---|---|
| reserve | (3/4) · R | c′(x) | |
| impact | 1/20 | sign(x) · p′(x) / p₀ | |
| inventory | 0 | −1 |
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.
| condition | statement | residual part |
|---|---|---|
| stationarity | U′(x*) = λ₁ g₁′(x*) + λ₂ g₂′(x*) + λ₃ g₃′(x*) | r_stat |
| primal feasibility | gᵢ(x*) ≤ 0 for every i | r_prim |
| dual feasibility | λᵢ ≥ 0 for every i | r_dual |
| complementary slackness | λᵢ · gᵢ(x*) = 0 for every i | r_slack |
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.
the pass
There is no schedule. The prover subscribes to the curve account and reacts to trades. Every pass has the same shape.
| step | what happens |
|---|---|
| curve changes | The curve account's reserves move because someone bought or sold. The prover's subscription fires. |
| read state | The prover reads s and t from the curve, R and I from the vault, and the current creator fee balance. |
| solve | The prover maximises U over the feasible interval in Q64.64, producing x* and the multipliers, and sets any λ to zero whose constraint is slack. |
| submit | The prover sends the submit instruction with the four numbers. Anyone else may do the same. |
| residual | The program recomputes c, c′, p, every gᵢ and gᵢ′, and the four residual parts from chain state. |
| execute | If the residual is zero, the program trades exactly x* through the curve by cross program invocation, then writes an accepted entry. |
| reject | Otherwise 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.
| invariant | statement |
|---|---|
| reserve floor | After an execute, R_after ≥ R_before / 4. |
| inventory sign | I_after ≥ 0. |
| single inflow | R 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.