A fully-featured decentralized perpetual DEX for trading synthetic assets, built using Solidity. The protocol enables leveraged long/short trading, advanced order types, and secure oracle integration—designed for performance, security, and cross-chain extensibility.
Interested in building a perpetual DEX or integrating synthetic asset trading?
- Telegram: @kairosstroud1205
- Twitter: @kairos1205
- 🔁 Synthetic Asset Trading — Trade synthetic assets like BTC, ETH, USDT, USDC, and more
- 📊 Leverage & Position Management — Manage long/short positions with real-time PnL and margin calculations
- 📈 Advanced Order Types — Market, limit, stop-loss, and conditional orders
- 🧠 Oracle Integration — Secure and flexible real-time price feeds
- 💥 Liquidation Engine — Automatic liquidation of undercollateralized positions
- 💸 Fee Distribution — Built-in fee routing to stakeholders and protocols
- 🧩 Modular Architecture — Role-based access, feature toggles, and upgradability
- 🌐 Cross-Chain Support — Currently supports NeoX and NeoXT4
contracts/
├── access/ # Role-based access control
├── adl/ # Auto Dealer Liquidation system
├── bank/ # Vaults and balance accounting
├── callback/ # Callback hooks for external contracts
├── chain/ # Chain-specific logic
├── config/ # Config registries and management
├── data/ # Data storage layout
├── deposit/ # Deposit logic
├── error/ # Custom errors
├── event/ # Event definitions
├── exchange/ # Core exchange logic
├── external/ # 3rd-party contract integration
├── feature/ # Feature flags & toggles
├── fee/ # Fee logic and distribution
├── gas/ # Gas usage optimizations
├── liquidation/ # Liquidation engine
├── market/ # Market creation and control
├── mock/ # Mocks for testing
├── nonce/ # Nonce tracking
├── oracle/ # Price oracle integrations
├── order/ # Order creation, matching, validation
├── position/ # Position tracking and PnL logic
├── pricing/ # Pricing mechanisms
├── reader/ # Read-only views and aggregators
├── referral/ # Referral incentives
├── role/ # RBAC utilities
├── router/ # High-level interaction gateway
├── subaccount/ # Subaccount architecture
├── swap/ # Asset swap functionality
├── token/ # Token interfaces and utilities
├── tokens/ # Token implementations
├── utils/ # Common utilities
└── withdrawal/ # Withdrawal processing
- Solidity
^0.8.26 - Hardhat — Ethereum development framework
- Foundry — High-performance testing and fuzzing
- TypeScript — Project scripting and config
- Ethers.js — Ethereum contract interaction
- OpenZeppelin — Secure contract libraries
- Node.js (v16+)
pnpmornpm- Git
git clone https://github.com/kairos1205/DeXFun-smart-contract-hyperliquid.git
cd DeXFun-smart-contract-hyperliquid
pnpm install
# or
npm installcp .env.example .env
# Configure your environment variables in `.env`npx hardhat compilenpx hardhat test
# or
npm run testnpx hardhat nodenpx hardhat deploy --network localhost| Network | Chain ID |
|---|---|
| NeoX Mainnet | 47763 |
| NeoXT4 Testnet | 12227332 |
| Hardhat Local | 31337 |
Central gateway for all user interactions: deposits, orders, swaps, and withdrawals.
Supports synthetic markets with configurable risk, margin, and pricing parameters.
Handles order creation, matching, cancellation, and conditional triggers:
- Market orders
- Limit orders
- Stop-loss / take-profit
- Conditional triggers
Supports multiple positions with leverage:
- Dynamic margin and PnL
- Liquidation thresholds
- Subaccount management
Integrates with multiple price feeds for high-fidelity pricing:
- Redundant data sources
- Fallback logic
- Tamper resistance
Automated forced liquidation of undercollateralized positions to maintain protocol solvency.
- ✅ Global Reentrancy Guards
- ✅ RBAC via Role Manager
- ✅ Oracle Fallbacks and Integrity Checks
- ✅ Immutable Logic + Upgradeable Proxies
- ✅ Strict Input Validation
FUNGAS(Synthetic Gas)FUNETH(Synthetic Ethereum)FUNBTC(Synthetic Bitcoin)FUNUSDC(Synthetic USD Coin)FUNUSDT(Synthetic Tether)
WGAS,WETH,WBTC,USDC,USDT
# Run full test suite
npm run test
# Specific test file
npx hardhat test test/market/Market.test.ts
# With gas reporting
REPORT_GAS=true npm run test| Command | Description |
|---|---|
npm run test |
Run all tests |
npm run compile |
Compile all contracts |
npm run deploy |
Deploy to selected network |
npm run verify |
Verify contracts (e.g. Etherscan) |
npm run lint |
Run linter on TypeScript code |
npm run fork:neoxt4 |
Fork NeoXT4 network locally |
npx hardhat deploy --network localhostnpx hardhat deploy --network neoXT4npx hardhat deploy --network neoX| Variable | Description |
|---|---|
ACCOUNT_KEY |
Private key for deployment |
NEOX_T4_ACCOUNT_KEY |
Private key for NeoXT4 testnet |
ACCOUNT_KEY_FILE |
Path to private key file |
REPORT_GAS |
Enable gas usage reporting |
Configured in hardhat.config.ts:
- RPC URLs
- Chain IDs
- Gas settings
- Account access
- Fork the repo
- Create a new feature branch
- Write code + tests
- Commit with clear messages
- Open a pull request 🎉
This project is licensed under the Business Source License 1.1 (BUSL-1.1).
See LICENSE for details.