func New
New builds a curve with reciprocal slope d and position cap. A larger d is a gentler price rise. cap bounds the position so cap² stays inside 128 bits and the token's own supply ceiling is respected.
Package curve is a linear, one-way bonding curve for issuing a token against a reserve: price rises linearly with the...
Package curve is a linear, one-way bonding curve for issuing a token against a reserve: price rises linearly with the position on the curve, and the cost of minting is the exact integral, computed in 128-bit so it never overflows and never issues a coin for less than its backing.
The marginal price is p(s) = s/D — a RECIPROCAL denominator D, not a numerator slope. That is not cosmetic. The cost of moving from s0 to s1 is the integral (s1²−s0²)/(2D). With a numerator slope k the product k·(s1²−s0²) can exceed 2^128 for a realistic k at a large supply, and the single 128-bit multiply overflows. As 1/D the numerator is only s1²−s0², at most cap² which for a cap near 9.2e14 is about 2^100 — always inside 128 bits — and D sits safely in the divisor. D is chosen from economics: larger D is a gentler curve.
Two rounding rules, and one belt-and-suspenders check, guarantee it:
A Curve is immutable configuration (the slope denominator and the position cap); it holds no mutable state and is never a heap object. The CURVE POSITION — how far up the curve issuance has walked — lives in the consuming realm as a monotonic counter it passes in as `from`. Burning or redeeming the token must NOT move that counter back: the curve prices the next mint off total-ever- minted, and walking it backward would let the same region be bought twice.
Curve is a linear one-way bonding curve. Build it with New.
Cost is the coin a buyer must pay to move the position from `from` to `from+delta`, the integral of the price over that span, ROUNDED UP. ok is false when the move would pass the cap or the cost would not fit in an int64 (only at absurd positions). Minting zero costs zero.
D and Cap expose the construction parameters.
Minted is the largest whole number of coins `coin` can buy starting at position `from`, and the coin actually spent on them (≤ coin; the caller keeps or refunds the remainder). It floors: it finds a candidate with a 128-bit integer square root, then corrects ±1 against the canonical Cost, so issued coin is never worth more than what was paid, and it is zero when even one coin costs more than `coin`.
Price is the marginal price at position s (coin per unit), floor(s/d). Backing is the reserve behind one unit at position s, exactly half the marginal price — the reason every buyer pays about twice the backing of the coin they buy.