Skip to main content

Smart Contracts Overview

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.

ContractPurpose
QsnFactoryCreates and manages all trading pairs using CREATE2 for deterministic addresses. Handles fee tier management and protocol fee recipient configuration.
QsnPairThe AMM pool contract. Each pair holds two tokens, mints LP tokens, and supports both Constant Product (x*y=k) and StableSwap pricing models.
QsnERC20Base 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.

ContractPurpose
QsnRouterPrimary entry point for swaps and liquidity operations. Supports multi-hop routing, native ETH wrapping, and EIP-2612 permit-based approvals.
QsnLibraryPure math functions for quote calculations, amount computations, and path-based routing logic.
QsnBatchSwapEnables multiple swap outputs in a single transaction with percentage-based allocation.

Token

ContractPurpose
QsnTokenERC20Votes governance token with a hard cap of 100,000,000 QSN. Supports delegation, voting snapshots, and gasless permits.

Staking Contracts

ContractPurpose
QsnStakeVaultProtocol-level staking: stake QSN to earn WETH from protocol fees. Uses Synthetix-style reward distribution with 7-day periods.
QsnStakingFactoryPermissionless factory for creating custom staking pools for any ERC20 token pair.
QsnStakingPoolIndividual staking pool created by the factory. Supports configurable durations and staking limits for any ERC20 pair.

Launchpad

ContractPurpose
QsnLaunchpadFair token launch platform with soft/hard caps, automatic liquidity provisioning, and LP locking.

Utility Contracts

ContractPurpose
QsnLimitOrderOn-chain limit order book with keeper-based execution and expiration handling.
FeeCollectorAggregates protocol fees from trading pairs, wraps ETH to WETH, and distributes rewards to the StakeVault.
WETH9Canonical Wrapped Ether contract for ETH/ERC20 interoperability.
MulticallBatches multiple read calls into a single RPC request for frontend efficiency.

Build Toolchain

  • Solidity: 0.8.20+
  • Framework: Foundry (forge, cast, anvil)
  • Libraries: OpenZeppelin Contracts
  • Testing: Foundry test suite with fuzzing support