A blockchain-based perpetual futures trading platform featuring automated liquidation, funding rate mechanisms, and a virtual AMM system.
Access the trading platform (Deployed on Vercel — works with the Sepolia testnet)
This project uses a three-tier architecture:
- Frontend: React application hosted on Vercel
- Backend: Node.js service running on Google Cloud's e2-micro VM instance
- Smart Contract: Deployed on Ethereum's Sepolia testnet
- Open long or short positions with customizable parameters
- Multiple leverage options: 1x, 2x, 5x, 10x, or 20x
- Adjustable slippage tolerance (0.01% to 100.00%)
- Position management (close positions at any time)
- Automated liquidation system when net margin falls below maintenance margin
- Liquidation price warning
- Ability to add margin to existing positions to prevent liquidation
- Separate deposit management from position margin
- 8-hour funding rate cycle for balancing long and short interest
- TWAP (Time-Weighted Average Price) implementation using the last ten perpetual prices
- Virtual AMM with constant product algorithm for price determination
- Platform fees:
- 0.05% of total trade size when opening positions
- 5% of remaining margin after liquidation
- 10% of gains during funding rate settlements
- Price-based heap data structure for optimized liquidation processing
- Fault-tolerant backend with:
- PostgreSQL database for historical data persistence
- Self-healing WebSocket connections
- Blockchain polling for missed events
- Fallback funding rate execution mechanism
- Email notifications for system events
- Interactive price charts with multiple timeframes (1min to 1week)
- Real-time position metrics (margin, maintenance margin, PnL)
- Notification system for important events
- Oracle price display for underlying asset (SNX)
- Tooltips for trading terminology
- OpenZeppelin ReentrancyGuard implementation to prevent re-entrancy attacks
- Multi-layer validation (both frontend and smart contract)
- Protected administrative functions
- Single Asset Trading: Currently only SNX perpetual futures are supported
- No Partial Position Changes: Positions must be fully closed before opening new ones
- No Partial Liquidations: Positions are fully liquidated when triggered
- Integer-Only Trading: Cannot trade fractional perpetual amounts
- Fixed Maintenance Margin: Set at 2% of total position size
- Transaction Requirements: All state-changing operations require wallet signature
- Comprehensive test suite for all external smart contract functions
- Frontend validation to prevent common transaction errors
For questions or feedback, please open an issue on this repository or reach out at Jaisinghtomar9211@gmail.com.