A comprehensive decentralized exchange (DEX) protocol for synthetic asset trading built on Solidity. This project provides a complete infrastructure for trading synthetic assets with advanced features including order management, position tracking, liquidation, and fee distribution.
If you are interested in building perp dex trading dapp, Contact here: Telegram | Twitter
- Synthetic Asset Trading: Trade synthetic versions of popular assets (BTC, ETH, USDC, USDT, etc.)
- Advanced Order Management: Support for limit orders, market orders, and stop-loss orders
- Position Management: Track and manage long/short positions with leverage
- Liquidation System: Automated liquidation of undercollateralized positions
- Oracle Integration: Real-time price feeds for accurate asset pricing
- Fee Distribution: Automated fee collection and distribution system
- Role-Based Access Control: Secure multi-role permission system
- Cross-Chain Support: Deployed on NeoX and NeoXT4 networks
contracts/
βββ access/ # Access control and role management
βββ adl/ # Automated Dealer Liquidation
βββ bank/ # Banking and vault functionality
βββ callback/ # Callback mechanisms
βββ chain/ # Chain-specific utilities
βββ config/ # Configuration management
βββ data/ # Data storage and management
βββ deposit/ # Deposit handling
βββ error/ # Custom error definitions
βββ event/ # Event emission utilities
βββ exchange/ # Core exchange functionality
βββ external/ # External contract integrations
βββ feature/ # Feature flags and toggles
βββ fee/ # Fee calculation and distribution
βββ gas/ # Gas optimization utilities
βββ liquidation/ # Liquidation mechanisms
βββ market/ # Market management
βββ mock/ # Mock contracts for testing
βββ nonce/ # Nonce management
βββ oracle/ # Price oracle integration
βββ order/ # Order management system
βββ position/ # Position tracking and management
βββ pricing/ # Price calculation utilities
βββ reader/ # Data reading utilities
βββ referral/ # Referral system
βββ role/ # Role-based access control
βββ router/ # Exchange router functionality
βββ subaccount/ # Subaccount management
βββ swap/ # Swap functionality
βββ token/ # Token contracts
βββ tokens/ # Token implementations
βββ utils/ # Utility functions
βββ withdrawal/ # Withdrawal handling
- Solidity: ^0.8.26
- Hardhat: Development framework
- Foundry: Additional testing framework
- OpenZeppelin: Security libraries
- TypeScript: Development language
- Ethers.js: Ethereum interaction library
- Node.js (v16 or higher)
- pnpm or npm
- Git
- Clone the repository:
git clone https://github.com/L9T-Development/DeXFun-smart-contract-hyperliquid.git
cd DeXFun-smart-contract-hyperliquid
- Install dependencies:
pnpm install
# or
npm install
- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
- Compile contracts:
npx hardhat compile
- Run tests:
npx hardhat test
- Start local development network:
npx hardhat node
- Deploy contracts:
npx hardhat deploy --network localhost
- NeoX Mainnet (Chain ID: 47763)
- NeoXT4 Testnet (Chain ID: 12227332)
- Hardhat Local (Chain ID: 31337)
npm run test
- Run test suitenpm run compile
- Compile contractsnpm run deploy
- Deploy contractsnpm run verify
- Verify contracts on block explorernpm run lint
- Run lintingnpm run fork:neoxt4
- Fork NeoXT4 testnet
The main entry point for all trading operations, handling deposits, withdrawals, orders, and swaps.
Manages synthetic asset markets with configurable parameters for each trading pair.
Comprehensive order system supporting:
- Limit orders
- Market orders
- Stop-loss orders
- Conditional orders
Track and manage leveraged positions with:
- Real-time P&L calculation
- Margin requirements
- Position sizing
Secure price feed integration with:
- Multiple price sources
- Price validation
- Fallback mechanisms
Automated liquidation system for:
- Undercollateralized positions
- Risk management
- Market stability
- Reentrancy Protection: Global reentrancy guards
- Access Control: Role-based permissions
- Input Validation: Comprehensive parameter validation
- Oracle Security: Multiple price source validation
- Upgrade Safety: Immutable core contracts with proxy patterns
- FUNGAS (Synthetic Gas)
- FUNETH (Synthetic Ethereum)
- FUNBTC (Synthetic Bitcoin)
- FUNUSDC (Synthetic USD Coin)
- FUNUSDT (Synthetic Tether)
- WGAS (Wrapped Gas)
- WETH (Wrapped Ethereum)
- WBTC (Wrapped Bitcoin)
- USDC (USD Coin)
- USDT (Tether)
The project includes comprehensive test coverage:
# Run all tests
npm run test
# Run specific test file
npx hardhat test test/market/Market.test.ts
# Run with gas reporting
REPORT_GAS=true npm run test
npx hardhat deploy --network localhost
npx hardhat deploy --network neoXT4
npx hardhat deploy --network neoX
ACCOUNT_KEY
: Private key for deploymentNEOX_T4_ACCOUNT_KEY
: NeoXT4 specific private keyACCOUNT_KEY_FILE
: Path to key fileREPORT_GAS
: Enable gas reporting
Networks are configured in hardhat.config.ts
with:
- RPC endpoints
- Chain IDs
- Gas settings
- Account management
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the BUSL-1.1 License - see the LICENSE file for details.