Sunswap Universal Router is a unified routing smart contract for the SunSwap ecosystem, designed to efficiently route token swaps and liquidity across different pools and swap paths.
Supported pool list:
- SunSwap V4 Pools
- SunSwap V3 Pools
- SunSwap V2 Pools
- SunSwap V1 Pools
- SunSwap Curve Pools
- HTX-SUN Fixed rate pool
This repository contains the smart contracts, deployment scripts, and tests based on Hardhat and Foundry, with additional support for the TRON network.
- Unified routing layer: A single router interface that can aggregate multiple swap/pool/aggregator logics.
- Multi-network support:
- EVM local development network (
localhost) - TRON testnet (via
tronwebandtronSolc)
- EVM local development network (
- Gas / resource efficiency: Solidity compiler optimization enabled (
runs=999999,viaIR: true).
| contract | chain | address |
|---|---|---|
| UniversalRouter | TRON Mainnet | TSJEtPuqHpvSaVnSwvCsngaeBxrGUzp95Q |
| NILE Testnet | TEgq4237arNE7jX74KCDkc1MXdZeWNkGVj |
- Hardhat 2.25.0 (configured via
@sun-protocol/sun-studio) +- Hardhat Toolbox & Hardhat Foundry plugin - Foundry (
forge test) - TronWeb 6.x
- Solidity 0.8.26 / Vyper 0.2.8 & 0.3.10
contracts/: Core contracts and libraries.deploy/: Deployment scripts for EVM networks (following Hardhat Deploy conventions).deployTron/: Deployment scripts targeting TRON.scripts/: Helper scripts (e.g.postinstall).test/: Hardhat-based tests.
Requirements:
- Node.js >= 18 (recommended)
- npm / yarn / pnpm (examples below use npm)
- Foundry installed (optional, for
forge test)
Clone and install:
git clone https://github.com/your-repo/sunswap-universal-router.git
cd sunswap-universal-router
# Install dependencies
npm installAfter installation, the postinstall hook will automatically run scripts/postinstall.sh for basic initialization.
Create a .env file in the project root (not committed to Git) with at least:
PRIVATE_KEY=your_private_key_for_deploymentNotes:
- Use a test/development account only; do not use a production account with real funds.
- The same
PRIVATE_KEYis reused for the TRON network (seenetworks.tron.accountsinhardhat.config.ts).
All scripts are defined under the scripts field in package.json and can be run via npm run <script>.
-
Local node
npm run start # Equivalent to: hardhat node -
Compile contracts (EVM)
npm run compile # Equivalent to: hardhat compile --verbose --force -
Compile contracts (TRON)
npm run compile-tron # Equivalent to: hardhat compile --network tron --verbose --force -
Clean build artifacts
npm run clean # Equivalent to: hardhat clean && rm -rf lib/ -
Hardhat tests
npm test # or npm run test
-
Foundry tests (optional)
npm run init-foundry # Initialize Foundry project structure (run once) npm run test-foundry # Equivalent to: forge test -vvv
Start a local Hardhat node in one terminal:
npm run startDeploy contracts from another terminal:
npm run deploy
deployis equivalent to:npx hardhat --network localhost deploy --tags lumi
Make sure PRIVATE_KEY is set in .env, then run:
npm run deploy-tronThis uses the scripts under
deployTron/and compiles/deploys viatronSolc.
hardhat.config.ts already includes a commented-out example configuration for the sepolia network.
To enable it:
-
Uncomment the
sepolianetwork configuration inhardhat.config.tsand set a properurlandaccounts. -
Run:
npm run deploy-sepolia
-
Before committing, it is recommended to run:
npm run compile npm test -
Add unit tests or Foundry tests for any new routing logic or contracts.
-
Follow the existing style and configuration (Solidity 0.8.26 / viaIR / high optimization runs).
Contributions via Issues and Pull Requests are welcome.
Unless otherwise specified, this project follows the open-source license used by the upstream repository (for example, MIT or a similar permissive license).
Before using it in production, please review the upstream repository and related license terms.
If you have questions about this project, find bugs, or would like to contribute, you can reach the team and community via:
Please follow official announcements from these channels for the latest information on deployments, upgrades, and security notices.