Skip to content

DexFun smart contracts deployed on Hyperliquid, providing the core on-chain logic for the DEXFun perpetual DEX trading application

Notifications You must be signed in to change notification settings

earthskyorg/hyperliquid-smart-contract-dexfun

Repository files navigation

Dexfun Hyperliquid Contracts

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.

🙋‍♂️ Cᴏɴᴛᴀᴄᴛ ᴍᴇ Oɴ ʜᴇʀᴇ: 👋

Telegram: https://t.me/opensea712

Telegram Discord

Overview

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

Capabilities At A Glance

  • 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

Architecture Snapshot

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

Tooling & Standards

  • 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

Getting Started

Prerequisites

  • Node.js 18+
  • pnpm (preferred) or npm
  • Git

Installation

git clone https://github.com/earthskyorg/hyperliquid-smart-contract-dexfun.git
cd hyperliquid-smart-contract-dexfun
pnpm install   # or npm install

Environment

cp .env.example .env
# populate deployer keys, RPC endpoints, and reporting flags

Core Development Workflow

# 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.


Network Targets

  • 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.


Operational Scripts

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>).


Configuration

Environment variables

  • ACCOUNT_KEY – primary deployer key
  • NEOX_T4_ACCOUNT_KEY – optional dedicated key for NeoXT4
  • ACCOUNT_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.


Testing & Quality

# 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 test

Foundry tests can be integrated via forge test once foundry.toml is configured with the desired profiles.


Security Posture

  • 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.


Token Universe

Synthetic markets: FUNGAS, FUNETH, FUNBTC, FUNUSDC, FUNUSDT
Collateral primitives: WGAS, WETH, WBTC, USDC, USDT (expandable through config)


Contributing & Support

  1. Fork the repository and create a feature branch
  2. Implement changes with accompanying tests
  3. Run pnpm lint && pnpm test
  4. Open a pull request with context and deployment notes

License

Business Source License 1.1 (BUSL-1.1). See LICENSE for the grant, limitations, and change date.

About

DexFun smart contracts deployed on Hyperliquid, providing the core on-chain logic for the DEXFun perpetual DEX trading application

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published