Core smart contracts implementing upgradeable DEX functionality including routing, pools, trading, and optional governance systems
Last updated Apr 9, 2026
13
Stars
1
Forks
0
Issues
0
Stars/day
Attention Score
1
Language breakdown
No language data available.
โธ Files
click to expand
README
DEX Smart Contracts
Decentralized exchange with margin trading and upgradeable architecture
Quick Start
# Install dependencies
npm install
npx hardhat clean
rm -rf artifacts/ cache/ node_modules/.cache/
Compile contracts
npm run compile
or
npx hardhat compile --force
Start local network
npm run node
Deploy system (in new terminal)
npm run prod:infrastructure
npm run prod:tokens
npm run prod:pools
or
npm run prod:deploy:config
Verifi npm run infoPool
Start services
npm run price-generator-anvil # Price generator
npm run keeper:upgradeable-anvil # Order executor
npm run trading-demo-anvil # Trading demo
Architecture
Core DEX
Upgradeable Proxy Pattern- Router Proxy โ Router Implementation
- Pool Proxy โ Pool Implementation
- Trading Proxy โ Trading Implementation
- Oracle Proxy โ Oracle Implementation
config/anvil_upgradeable-config.json
Governance Token (optional)
Additional features- Trading discounts up to 10%
- Staking with rewards from fees
- Voting system for governance
- Premium access features
config/token-config.json
Main Features
Core DEX
- โ Spot trading
- โ Limit orders
- โ Stop-loss orders
- โ Margin trading
- โ Liquidity providing
- โ Upgradeable contracts
- โ Flash loan protection
- โ Circuit breaker
Governance Token (optional)
- โ ERC-20 with extended functions
- โ Trading discount system
- โ Staking with doubled voting weight
- โ Distribution of part of fees to stakers
- โ Timelock governance with quorum
- โ Premium features for large holders
Deployment and Management
Main system
- Deployment Guide - Step-by-step deployment
- Scripts Overview - Description of all scripts
- Security Analysis - Security analysis
Governance and tokenomics
- Governance Token Guide - User guide
- Monetization Model - Economic model
- Technical Tokenomics - Technical documentation
Development Commands
Deploy and testing
# Full deployment pipeline
npm run prod:infrastructure # Infrastructure
npm run prod:tokens # Tokens and prices
npm run prod:pools # Liquidity
Governance token
npm run deploy:governance-token
npm run verify:governance-token
Testing
npm run test:integration
npm run test:full-upgradeable
npm run verify:upgrades
Services and automation
# Runtime services
npm run price-generator-anvil # Price updates
npm run keeper:upgradeable-anvil # Order execution
npm run trading-demo-anvil # Trading demonstration
Management
npm run pause # Emergency stop
npm run unpause # Resume operation
npm run cancel-all # Cancel all orders
Docker deployment
# Full development environment
./docker-run.sh full
Individual components
./docker-run.sh start # Node only
./docker-run.sh deploy # Contract deployment
./docker-run.sh services # Automation
Operating Principles
Modular architecture
- Core DEX Fully functional without token
- Governance Token Optional addition
- Simple integration Token connects with one command
Router-centric design
- All operations through single Router contract
- Upgradeable without changing addresses
- Backward compatibility guaranteed
Security
- Timelock for all governance changes
- Quorum for decision validity
- Restrictions on critical parameters
- Emergency stop capability
- Flash loan protection
- Circuit breaker mechanisms
Project Structure
โโโ contracts/
โ โโโ upgradeable/ # Main contracts
โ โโโ governance/ # Governance token
โ โโโ libraries/ # Logic libraries
โ โโโ access/ # Access control
โโโ scripts/
โ โโโ prod_* # Production deploy
โ โโโ utils/ # Management utilities
โ โโโ tests/ # Integration tests
โโโ config/ # Configurations
โโโ docs/ # Documentation
Security and Audit
- Upgradeable proxy pattern with timelock protection
- Comprehensive testing with >95% coverage
- Static analysis with Slither
- Emergency pause functionality
- Multi-signature governance for critical operations
License
MIT License - see LICENSE for details
Contact Me
๐ซ Reach out on LinkedIn or Email or Telegram
Support
- Technical documentation in
docs/folder - Usage examples in
scripts/ - Issues and questions through GitHub
๐ More in this category