Skip to content

exec009/orderbook-dex

Repository files navigation

orderbook-dex

A Solidity smart contract backend for a lightweight order-book decentralized exchange. Combines ERC-20 token custody, market pair registration, EIP-712 signed orders, and single or batched trade settlement through a matching engine contract.

The repository also includes a market data UDF service under binanceudf/ for serving TradingView-compatible chart data during frontend development.

What is included

  • contracts/MatchingEngine.sol - verifies signed buy and sell orders, tracks filled quantities, and settles matched trades.
  • contracts/Wallets.sol - handles token deposits, withdrawals, and internal balances.
  • contracts/Markets.sol - registers active tokens and base/market pairs.
  • contracts/Tokens.sol - local ERC-20 test tokens.
  • scripts/ - Brownie deployment and EIP-712 helper scripts.
  • tests/ - Brownie tests for signatures, deposits, single trades, and batched trades.
  • binanceudf/ - optional TradingView UDF data source backed by market data.

Requirements

  • Python 3 with Brownie
  • Node.js and npm
  • Python packages:
    • eip712-structs
    • eth_abi

Setup

Install Solidity dependencies:

npm install

Install Python dependencies:

pip install eth-brownie eip712-structs eth_abi

Test

Run the Brownie test suite from the repository root:

brownie test

The tests use local Brownie accounts and exercise deposit, signature verification, and trade settlement flows.

Deploy

Deploy to a local development chain:

export BROWNIE_ACCOUNT="your-brownie-account"
brownie run scripts/deploy.py --network development

Deploy to a testnet:

export BROWNIE_ACCOUNT="your-brownie-account"
export BOT_ACCOUNT="0x0000000000000000000000000000000000000000"
brownie run scripts/deploy.py --network <network-name>

BROWNIE_ACCOUNT is required. BOT_ACCOUNT is optional and defaults to the deployer address when not set.

UDF Service

The optional market data UDF service lives in binanceudf/.

cd binanceudf
npm install
npm start

Default port is 80. See binanceudf/README.md for Docker setup details.

Notes

  • Orders are signed using EIP-712 with domain name OrderBook and version 1.0.0.
  • tradeMulti batches paired buy and sell orders to reduce settlement overhead.
  • Pair ID 1 is assumed by the current batched trade path; update before generalizing to multiple markets.

Security

This code is experimental and has not been audited. Do not deploy with real funds until the contracts, signing flow, and settlement logic have been reviewed and tested for production use.

About

Solidity smart contract backend for a lightweight order-book decentralized exchange with EIP-712 signed order matching.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors