Reference
Trading SDK
The shared TypeScript package @zoltar/trading-shared holds the pure Trading math that the UI and the Solidity parity tests share. All chain quantities are bigint.
Pure math
quoteExactOutput(trading/math) mirrors the Solidity ceil behavior for an exact-output swap and returns gross input, output, net input, and fee.maximumInsuredExit(trading/positions) binary-searches the greatest complete-set amount allowed by INVALID, long balance, opposite reserve, and an optional long-input ceiling.
Transaction helpers
Transaction-facing helpers live in the Trading UI at ui/trading/ts/protocol/tradeQuote.ts: minimumAfterSlippage and maximumAfterSlippage build conservative bounds, stableSimulation reads the latest canonical block identity (number and hash) and passes it to the simulation callback, whose reads must all use that block hash, retainApprovedMinimum and retainApprovedMaximum keep the approved bounds when the submission-time simulation still satisfies them, and deadlineAtBlock derives router deadlines from the quote block.
Pure math is a responsive preview only. Transaction summaries must simulate the actual router call, use its returned values, and revalidate network, account, balances, approvals, reserves, deadline, and simulation immediately before wallet submission.