Enterprise-grade smart contract system for synthetic perpetual trading on NeoX and Hyperliquid-aligned chains. The repository contains every on-chain component required to launch a non-custodial derivatives exchange, from collateral management and order routing to data readers and operational tooling.
Telegram: https://t.me/opensea712
dexFun delivers a fully on-chain exchange primitive that prioritizes deterministic execution, configurable risk controls, and institutional-grade operations. The stack is modular, audited in-house, and optimized for rapid iteration across multiple deployments.
Key outcomes
- Unified flow for deposits, withdrawals, swaps, and leveraged trading
- Deterministic liquidation and oracle safety controls
- Configurable markets, fees, and routing logic via governance-controlled registries
- Synthetic Market Engine – Cash-settled exposure to BTC, ETH, stablecoins, and additional synthetic assets
- Advanced Order Flows – Limit, market, conditional, and stop orders with flexible triggers
- Position Lifecycle – Margining, funding, inventory tracking, and cross/isolated collateral support
- Oracle & Risk Layer – Multi-source price validation plus configurable circuit breakers
- Fee & Incentives – Protocol fees, referral routing, and incentive accounting baked in
- Role-aware Operations – Fine-grained access control for governance, execution, automation, and emergency responders
contracts/
├── access, role, feature # Governance + permissioning
├── exchange, router, order # User-facing trading surface
├── position, pricing, fee # Core risk, funding, payout logic
├── oracle, price, event # Market data and messaging
├── market, config, utils # Registries and shared libraries
├── deposit, withdrawal, bank # Collateral lifecycle
├── reader, data # View helpers for indexers/UIs
└── mock, test, external # Harnesses and integrations
deploy/ # Hardhat-deploy scripts per network
scripts/ # Operational utilities and runbooks
test/ # TypeScript/Hardhat test suites
- Solidity ^0.8.26 with custom errors and assembly-guarded math
- Hardhat + hardhat-deploy for compilation, deployments, and task automation
- Foundry (optional) for fuzzing and invariant suites
- TypeScript + Ethers v5 tooling ecosystem
- OpenZeppelin Contracts for vetted primitives
- Node.js 18+
- pnpm (preferred) or npm
- Git
git clone https://github.com/earthskyorg/hyperliquid-smart-contract-dexfun.git
cd hyperliquid-smart-contract-dexfun
pnpm install # or npm installcp .env.example .env
# populate deployer keys, RPC endpoints, and reporting flags# Compile with Hardhat
npx hardhat compile
# Run the automated suite
npx hardhat test
# Start a local network
npx hardhat node
# Deploy to a target network
npx hardhat deploy --network <network>For faster iteration, use pnpm run lint, pnpm run test, and Foundry scripts where applicable.
- NeoX Mainnet (
chainId 47763) - NeoXT4 Testnet (
chainId 12227332) - Hardhat Local Fork (
chainId 31337)
Network definitions, RPC URLs, gas tuning, and account management live in hardhat.config.ts.
Key runbooks live under scripts/ and cover:
- Market lifecycle (
createMarket*,removeMarkets,toggleMarkets) - Deposits, withdrawals, and order orchestration helpers
- Oracle signer and price feed management (
printOracleConfig,updateOracleConfig,validatePriceFeeds) - Governance + role maintenance (
updateRoles,printRoles,changeOwnershipOfOwnableMintableTokens) - Parsing, debugging, and diagnostics (
decodeInputData,getRevertReason,print*)
Each script is written in TypeScript and intended to be executed with ts-node/Hardhat (npx hardhat run scripts/<name>.ts --network <network>).
Environment variables
ACCOUNT_KEY– primary deployer keyNEOX_T4_ACCOUNT_KEY– optional dedicated key for NeoXT4ACCOUNT_KEY_FILE– path to encrypted key material (if any)REPORT_GAS– enable Hardhat gas reporting
Hardhat networks
- RPC endpoints and confirmations tuned per network
- Deterministic deployment tags via
hardhat-deploy - Shared named accounts for governance, keeper, treasury, etc.
Refer to config/ for token, market, oracle, and role registries that feed into deployment scripts.
# Run the full suite
pnpm test
# Target a specific spec
npx hardhat test test/market/Market.test.ts
# Enable gas analytics
REPORT_GAS=true pnpm testFoundry tests can be integrated via forge test once foundry.toml is configured with the desired profiles.
- Reentrancy guards and mutexes around external entry points
- Role-separated execution paths and emergency pause hooks
- Extensive input validation and invariant checks
- Oracle quorum plus fallback readers to mitigate data manipulation
- Upgrade patterns limited to governance-controlled proxies, with immutable cores where possible
Security reviews are ongoing; please reach out for the latest reports or to schedule an external audit.
Synthetic markets: FUNGAS, FUNETH, FUNBTC, FUNUSDC, FUNUSDT
Collateral primitives: WGAS, WETH, WBTC, USDC, USDT (expandable through config)
- Fork the repository and create a feature branch
- Implement changes with accompanying tests
- Run
pnpm lint && pnpm test - Open a pull request with context and deployment notes
Business Source License 1.1 (BUSL-1.1). See LICENSE for the grant, limitations, and change date.