nautechsystems/nautilus_trader · error
Swap quote output amount
Error message
Swap quote output amount {amount} is not a positive output What it means
When extracting a swap quote's output amount, the code selects amount0 or amount1 (zeroForOne) and requires it to be negative (an output is a decrease in that token's balance). If the selected amount is not negative, the quote does not represent a positive output and the adapter bails before converting to U256 via unsigned_abs.
Solutions
- Check the zeroForOne flag matches the swap direction (zeroForOne means output is amount1)
- Re-fetch the quote; it may be from a stale or empty pool state
- Verify pool token0/token1 ordering matches the adapter's assumption
Example fix
// before
let amount = if zero_for_one { quote.amount1 } else { quote.amount0 };
// after
let zero_for_one = quote.currency0 < quote.currency1 ? zero_for_one_in : !zero_for_one_in;
let amount = if zero_for_one { quote.amount1 } else { quote.amount0 }; Defensive patterns
Strategy: validation
Validate before calling
let selected = if zero_for_one { quote.amount1 } else { quote.amount0 };
if !selected.is_negative() {
return Err(anyhow::anyhow!("quote output not negative; check zeroForOne direction"));
} Type guard
fn has_positive_output(q: &Quote, zero_for_one: bool) -> bool {
let amt = if zero_for_one { q.amount1 } else { q.amount0 };
amt.is_negative()
} Try / catch
match build_swap_output(quote, zero_for_one) {
Ok(out) => proceed(out),
Err(e) if e.to_string().contains("not a positive output") => recheck_direction_and_requote(),
Err(e) => return Err(e),
} Prevention
- Derive zeroForOne from sorted token addresses consistently everywhere
- Re-quote once before failing; stale pool state can produce inverted amounts
When it happens
Trigger: Calling the swap-quote helper with a quote whose selected output amount (amount0 for zeroForOne==false, amount1 for zeroForOne==true) is >= 0, e.g. wrong zeroForOne flag or an inverted/invalid quote from the pool.
Common situations: zeroForOne direction computed inconsistently with the pool's token ordering; quote fetched from a pool where tokens were flipped; simulator returning zero/negative-output quotes on illiquid pools.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- All --checkpoint-blocks exceed --to-block
- Allowed token pair -> is not fully pinned by the deployment…
- Chain anchor ID must be nonzero
- Chain checkpoint hash must be nonzero
- Chain checkpoint hash must contain 32 hexadecimal bytes
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/1cffea0dd520a76d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/blockchain/src/execution/client.rs:5278
};
if quantity.is_zero() {
anyhow::bail!(
"Executed amount {amount} is below representable quantity precision {FIXED_PRECISION}"
);
}
Ok(quantity)
}
fn exact_output_amount(quote: &SwapQuote, zero_for_one: bool) -> anyhow::Result<U256> {
let amount = if zero_for_one {
quote.amount1
} else {
quote.amount0
};
if !amount.is_negative() {
anyhow::bail!("Swap quote output amount {amount} is not a positive output");
}
Ok(amount.unsigned_abs())
}
/// Derives the minimum output accepted for the swap: the quoted output reduced by
/// `slippage_bps`, in exact integer arithmetic. Rejects a zero minimum, which would leave
/// the swap without slippage protection.
fn derive_min_amount_out(quoted_amount_out: U256, slippage_bps: u32) -> anyhow::Result<U256> {
if slippage_bps >= BPS_DENOMINATOR {
anyhow::bail!("Slippage {slippage_bps} bps must be below {BPS_DENOMINATOR}");
}
let min_amount_out = quoted_amount_out
.checked_mul(U256::from(BPS_DENOMINATOR - slippage_bps))
.and_then(|scaled| scaled.checked_div(U256::from(BPS_DENOMINATOR)))
.ok_or_else(|| anyhow::anyhow!("Minimum output derivation overflow"))?;
if min_amount_out.is_zero() {
anyhow::bail!(
"Derived minimum output is zero for quoted output {quoted_amount_out} at {slippage_bps} bps slippage"View on GitHub (pinned to 18893faf8b)