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
| Parameter | Description |
|---|
sellToken / buyToken | Token pair addresses |
sellAmount / buyAmount | Trade amounts |
sellTokenPriceOracle | Chainlink-compatible oracle for sell token |
buyTokenPriceOracle | Chainlink-compatible oracle for buy token |
strike | Exchange rate threshold (18 decimals) |
validTo | Order expiration timestamp |
maxTimeSinceLastOracleUpdate | Oracle staleness limit |
Execution Logic
The getTradeableOrder function validates conditions in sequence:
- Confirms the order hasn’t expired
- Retrieves current prices from both oracles
- Verifies prices are positive and recently updated
- Normalizes both to 18 decimals
- Calculates the exchange rate and compares against strike
- 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