amountIn with the quote token’s decimals. For sells, use the base token’s decimals. The estimate returns amountInUsed and amountOut in token atoms. The SDK swap write returns a transaction hash, not that result struct. Await a successful receipt and read SpotSwap or the resulting balances for actual amounts. Format token amounts with formatUnits and the corresponding token decimals. The typed ABI read above avoids the SDK 0.2.0 estimate helper’s unknown return type. userId is a uint40, so conversion to a JavaScript number is exact once its range has been validated.
Estimation uses current chain state but cannot predict stateful post-fill-hook output or later state changes. Always use a deadline and nonzero slippage bound appropriate to the application.