Skip to main content

Security & Deployment

Security Considerations

Access Control

Critical functions are restricted to specific roles (Owner, Maintainer) to prevent unauthorized changes to system parameters.

Attack Mitigation

  • Reentrancy: Both contracts use OpenZeppelin’s ReentrancyGuard modifier on all state-changing external functions to prevent reentrancy via token callbacks.
  • Price Manipulation:
    • Slippage Protection: User-specified minAmountOut prevents execution at unfavorable prices.
    • Price Verification: Limit price is validated against actual execution price after fees.
  • Fee Underflow Prevention: Total fees (protocol + bot) are capped at 100% (10,000 basis points).
  • Adapter Validation: All adapters are validated through a whitelist before any interaction.

Emergency Procedures

The LimitOrderEscrow contract includes emergency pause functionality:

  • pause(): Immediately stops all order creation and execution.
  • unpause(): Resumes normal operations.

Order cancellation remains available during pause to allow users to withdraw their funds.

Deployment Guide

Router Deployment

Requires setting up the initial owner and maintainer addresses.

Limit Order Deployment

Requires the address of the deployed Router and Fee Collector addresses.

Post-Deployment Configuration

  1. Configure Stable Tokens: Call addStableTokens() on LimitOrderEscrow with stablecoin addresses.
  2. Authorize Initial Bots: Call authorizeBot() for each bot address that will execute orders.
  3. Verify Fee Collectors: Ensure feeCollector and botCollector addresses are correctly configured.

Gas Optimization

  • Dust Handling: Last hop/split receives remaining amount to avoid precision loss.
  • O(1) Lookups: isTrustedAdapter and authorizedBots mappings provide constant-time validation.
  • Immutable Variables: Used for addresses that never change to save gas.