Skip to main content

Contracts Setup

Guide for building, testing, and deploying QsnDEX smart contracts using Foundry.

Prerequisites

Verify your installation:

forge --version

Build

Compile all contracts:

cd contracts
forge build

Compiled artifacts are output to the out/ directory.

Test

Run the full test suite:

forge test

For verbose output with stack traces:

forge test -vvv

Run a specific test file:

forge test --match-path test/Router.t.sol

Run a specific test function:

forge test --match-test testSwapExactTokensForTokens

Deploy

Deploy contracts using a Foundry script:

forge script script/Deploy.s.sol \
--rpc-url $RPC_URL \
--private-key $DEPLOYER_KEY \
--broadcast \
--verify

Parameters:

ParameterDescription
--rpc-urlTarget chain RPC endpoint
--private-keyDeployer wallet private key
--broadcastActually send transactions (omit for dry run)
--verifyVerify contracts on the block explorer

Configuration

Foundry settings are defined in foundry.toml at the project root. Key settings include:

  • Solidity compiler version
  • Optimizer runs
  • RPC endpoints for different chains
  • Etherscan API keys for verification

Contract Architecture

All contract interfaces are located in src/interfaces/. The main contract groups are:

DirectoryContents
src/core/AMM Factory, Router, Pair contracts
src/periphery/Multicall, WETH helper, utility contracts
src/token/QSN ERC-20 token
src/staking/QSN staking and staking pool factory
src/launchpad/Token sale and distribution contracts
src/utils/Shared libraries (math, sorting, etc.)
src/interfaces/All contract interfaces

Gas Reporting

Generate a gas usage report:

forge test --gas-report

Formatting

Format Solidity source files:

forge fmt