Price an exact input
For a purchase of WHYPE, set buyBase = true and express grossIn in tUSDC atoms. For a sale, set buyBase = false and express the input in WHYPE atoms. The pool contract identifies the pair. One whole WHYPE contains 1018 atoms and one whole tUSDC contains 106.
function previewSwap(bool buyBase, uint256 grossIn)
external view returns (
uint256 out,
uint256 referencePrice,
uint8 last
);
At a specified settlement block, previewSwap reads the reference adapter and walks the bins from the active index. The return values give the aggregate output in output-token atoms, the oracle price in quote atoms per whole base token, and the final bin index. If the walk reaches a book boundary with unspent input, the preview reverts. Request this preview over HTTP →
Bind the reviewed price and output
The public quote service accepts an output tolerance s from 1 to 1,000 basis points. The default is 50. For a preview yielding O output atoms, the quoted minimum is
Suppose a WHYPE sale quotes 68.250000 tUSDC. At 50 bps, the minimum is 67,908,750 atoms, or 67.908750 tUSDC. At execution the pool independently compares its current reference P to the reviewed Pe and requires |P − Pe| ≤ ⌊Pe / 200⌋. This second check applies even if the computed output exceeds the requested minimum.
The HTTP response gives the client a review horizon of 120 seconds from its sampled block timestamp. The pool call takes four arguments. The wallet enforces the review horizon before submission. The contract enforces oracle freshness, reference deviation, available inventory and minOut at inclusion.
Settle through the canonical pool
function swap(
bool buyBase,
uint256 grossIn,
uint256 minOut,
uint256 expectedPrice
) external returns (uint256 out);
Verify the settlement chain ID and canonical pool address against the deployment configuration. Supply otherAmountThreshold as minOut and expectedPrice from the same reviewed quote. When a wallet address is supplied, the API can prepend a base wrapping transaction, an allowance reset and an exact-amount approval as required by its balances and current allowance.
On success, the pool transfers the full input from the caller and the calculated output to the same address. The transfer checks compare both sender and recipient balance deltas to the specified atom count. If a check fails, the swap and its reserve transitions revert together. Any earlier, separately confirmed approval remains in effect.
Reconcile the execution receipt
Filter receipt logs by the canonical pool address. Each BinFilled event identifies a consumed bin, its gross input, output, LP fee valued in base atoms, pre-existing share supply, and the platform and creator fee amounts in input atoms. The trailing Swapped event carries the trader, direction, gross input, aggregate output, reference price and last bin.
Σ BinFilled.out = Swapped.out
Use transaction hash and log index to distinguish individual fills when indexing. Preserve the receipt’s block hash alongside its height. The status endpoint returns a null status while a canonical receipt is unavailable. A returned receipt can have a confirmation level and still report a revert through status.err.