Skip to main content

Stop Loss API

The Stop Loss feature enables automated trading when token prices fall below specified thresholds. It relies on Chainlink-compatible price oracles to monitor token prices and trigger the order when conditions are satisfied.

Key Parameters

ParameterDescription
sellToken / buyTokenToken pair addresses
sellAmount / buyAmountTrade amounts
sellTokenPriceOracleChainlink-compatible oracle for sell token
buyTokenPriceOracleChainlink-compatible oracle for buy token
strikeExchange rate threshold (18 decimals)
validToOrder expiration timestamp
maxTimeSinceLastOracleUpdateOracle staleness limit

Execution Logic

The getTradeableOrder function validates conditions in sequence:
  1. Confirms the order hasn’t expired
  2. Retrieves current prices from both oracles
  3. Verifies prices are positive and recently updated
  4. Normalizes both to 18 decimals
  5. Calculates the exchange rate and compares against strike
  6. Returns the executable order if conditions are met

Failure Scenarios

  • Orders fail permanently with OrderNotValid if expired or oracle prices are invalid
  • They revert with PollTryNextBlock (signaling retry on next block) when prices are stale or the strike hasn’t been reached yet

Design Notes

The contract automatically scales oracle prices to 18 decimals for comparison. Both oracles must quote in the same currency for accurate rate calculations.
Last modified on March 4, 2026