priceAtSupply
Spot price on the linear curve at a given curve supply.
Evaluates the piecewise curve: flat floor through x1, ramp through x2, then the main slope. Result is WAD USDC per AVM (18 decimals).
Pass snapshot.engine and snapshot.curveSupply for the live spot. Sampling many supplies is sampleCurve.
Import
import { priceAtSupply } from "@repo/contract-client/math";
Usage
import { priceAtSupply } from "@repo/contract-client/math";
const spot = priceAtSupply(snapshot.engine, snapshot.curveSupply);
// equals snapshot.spotPriceWad when the snapshot is consistent
Return Value
Wad — USDC per AVM, 18-decimal fixed point.
Parameters
state
- Type:
LinearCurveState
Decoded engine (snapshot.engine): floorPriceWad, rampEndSupplyWad, rampWidthWad, rampScalarWad, mainSlopeWad.
priceAtSupply(snapshot.engine, snapshot.curveSupply);
supply
- Type:
AvmAtoms
Curve supply, not necessarily ERC-20 totalSupply (offset can differ).
priceAtSupply(snapshot.engine, asAvmAtoms(0n)); // floor
Error
InvalidAmountError if supply is negative or the evaluated price is non-positive.
Tips
- v1 launch preset starts at
0.0001USDC/token (PRESET_FLOOR_WAD). - Inverse: supplyForPrice.