Skip to content

odos-xyz/odos-limit-orders

Repository files navigation

Odos Limit Order Smart Contract

Summary

This product allows users to place orders that will be executed at a specified limit price. Orders are placed gaslessly via signed EIP-712 data, and support multiple inputs and multiple outputs.

Limit order execution flow

  1. Check if msg.sender is allowed
  2. Check if order still valid
  3. Check tokens, amounts
  4. Get order hash
  5. Recover order owner account [and validate the signature]
  6. Extract previously filled amounts for order from storage, or create
  7. Check if fill possible:
  • If partiallyFillable, total amount do not exceed
  • If not partiallyFillable - it was not filled previously
  1. Transfer tokens from order owner
  2. Update order filled amounts in storage
  3. Get output token balances before
  4. Execute path with the OdosExecutor
  5. Get output token balances difference
  6. Calculate and transfer referral fee if any
  7. Check slippage, adjust amountOut
  8. Check surplus
  9. Transfer tokens to order owner account
  10. Emit LimitOrderFilled (MultiLimitOrderFilled) event

Deployment Addresses

Chain Limit Order Router Address

Ethereum
0x0F26B03961eb5D625BD6001278F0DB13f3e583d8

Optimism
0xafF142fBc8FA5B1885FE54E4C889985F8a579b24

BNB
0xFA198dF5167dc5fb7DDA2Ad413310Be67394bF3d

Polygon
0xBefe4BC7f39771CF7C2CcCE6E4e7Ef393deb6704

Fantom
0x275278CEA8d36b879917B51d250F04Be95F905Ed

Fraxtal
0x926fAAfcE6148884CD5cF98Cd1878f865E8911Bf

zkSync Era
0xa688F1d16b44b9A3110C3b4413b6081F271A643B

Mantle
0x51Ea3db8b67462b0A66b3F1fF50cA87C076Acc7a

Base
0x8c8c3E8465B911186aDeC83a53C7De8c587eDDaB

Mode
0x65005f4Bea4005D48eE9Bdaae960832c6CECC557

Arbitrum
0x83564b903c0311877accEE8f99e6BEb712AD8E43

Avalanche
0xD10634297961fEa132ac7b6e7451BC4E5B17359b

Linea
0x5Ab73021e0648f46Da303cE7f5a0F2F15a3944c6

Scroll
0x014F335e0161B4EdDf3fF5b297BA6A31004Ca528

Smart Contracts

Build

forge build

Test

forge test

Test the EIP-712 hash generation to ensure that the Solidity hash is generated correctly.

cd test/eip712test
chmod +x ./runTest.sh
./runTest.sh

Gas report

forge test --gas-report

Linter

npm install -g solhint
solhint 'contracts/*.sol' 'interfaces/*.sol'

Coverage

forge coverage --report lcov
genhtml -o report lcov.info

Then open the report/index.html in the browser.

Audit tools

Install Mythril

solc-select install 0.8.19
export SOLC_VERSION=0.8.19
myth analyze contracts/OdosLimitOrderRouter.sol --solc-json ./mythril.config.json

Audit

This contract was audited by Halborn in April 2024. A link to the report can be found on the Halborn Website. A copy of the report is included on this page.