QsnDEX is composed of a modular set of smart contracts organized into distinct functional categories. All contracts are written in Solidity 0.8.20+, built with the Foundry development framework, and leverage OpenZeppelin's audited library contracts where applicable.
Architecture
Core Contracts
The core contracts form the foundation of the DEX and are not upgradeable.
| Contract | Purpose |
|---|
| QsnFactory | Creates and manages all trading pairs using CREATE2 for deterministic addresses. Handles fee tier management and protocol fee recipient configuration. |
| QsnPair | The AMM pool contract. Each pair holds two tokens, mints LP tokens, and supports both Constant Product (x*y=k) and StableSwap pricing models. |
| QsnERC20 | Base LP token contract implementing ERC20 with EIP-2612 permit support for gasless approvals. |
Periphery Contracts
Periphery contracts provide user-facing interfaces and helper utilities. They interact with the core contracts but can be replaced or upgraded independently.
| Contract | Purpose |
|---|
| QsnRouter | Primary entry point for swaps and liquidity operations. Supports multi-hop routing, native ETH wrapping, and EIP-2612 permit-based approvals. |
| QsnLibrary | Pure math functions for quote calculations, amount computations, and path-based routing logic. |
| QsnBatchSwap | Enables multiple swap outputs in a single transaction with percentage-based allocation. |
Token
| Contract | Purpose |
|---|
| QsnToken | ERC20Votes governance token with a hard cap of 100,000,000 QSN. Supports delegation, voting snapshots, and gasless permits. |
Staking Contracts
| Contract | Purpose |
|---|
| QsnStakeVault | Protocol-level staking: stake QSN to earn WETH from protocol fees. Uses Synthetix-style reward distribution with 7-day periods. |
| QsnStakingFactory | Permissionless factory for creating custom staking pools for any ERC20 token pair. |
| QsnStakingPool | Individual staking pool created by the factory. Supports configurable durations and staking limits for any ERC20 pair. |
Launchpad
| Contract | Purpose |
|---|
| QsnLaunchpad | Fair token launch platform with soft/hard caps, automatic liquidity provisioning, and LP locking. |
Utility Contracts
| Contract | Purpose |
|---|
| QsnLimitOrder | On-chain limit order book with keeper-based execution and expiration handling. |
| FeeCollector | Aggregates protocol fees from trading pairs, wraps ETH to WETH, and distributes rewards to the StakeVault. |
| WETH9 | Canonical Wrapped Ether contract for ETH/ERC20 interoperability. |
| Multicall | Batches multiple read calls into a single RPC request for frontend efficiency. |
- Solidity: 0.8.20+
- Framework: Foundry (forge, cast, anvil)
- Libraries: OpenZeppelin Contracts
- Testing: Foundry test suite with fuzzing support