Staking Contracts
QsnDEX provides three staking contracts that serve different purposes: protocol-level revenue sharing, and permissionless staking pool creation for any ERC20 token pair.
QsnStakeVault
The QsnStakeVault is the protocol's primary staking mechanism. Users stake QSN tokens and earn WETH rewards sourced from protocol trading fees.
Reward Mechanism
The vault uses a Synthetix-style reward distribution model:
- Rewards are distributed linearly over 7-day periods.
- Each staker earns rewards proportional to their share of the total staked QSN.
- Reward rate is recalculated each time new WETH is deposited into the vault by the FeeCollector.
- Unclaimed rewards accumulate and can be withdrawn at any time.
How It Works
- The FeeCollector sends WETH to the StakeVault, initiating or extending a reward period.
- Stakers deposit QSN via
stake(uint256 amount). - Rewards accrue continuously based on the staker's proportion of total staked tokens.
- Stakers call
claimReward()to withdraw accumulated WETH. - Stakers can
withdraw(uint256 amount)their QSN at any time (no lock-up).
Key Functions
| Function | Description |
|---|---|
stake(uint256 amount) | Deposit QSN tokens into the vault. |
withdraw(uint256 amount) | Withdraw staked QSN tokens. |
claimReward() | Claim accumulated WETH rewards. |
exit() | Withdraw all staked QSN and claim all pending rewards. |
QsnStakingFactory
The QsnStakingFactory enables permissionless creation of staking pools for any ERC20 token pair. Anyone can deploy a new staking pool by paying the creation fee.
Creation Fee
| Component | Amount |
|---|---|
| ETH fee | 0.01 ETH |
| Token fee | 2% of deposited reward tokens |
The ETH fee is sent to the factory owner. The 2% token fee is retained by the factory contract.
Pool Creation
To create a new staking pool, the creator specifies:
- Staking token -- The ERC20 token users will stake.
- Reward token -- The ERC20 token distributed as rewards.
- Reward amount -- The total reward tokens to distribute.
- Duration -- The reward distribution period in seconds.
- Max stake per user (optional) -- Cap on individual staking amounts.
The factory deploys a new QsnStakingPool contract and transfers the reward tokens (minus the 2% fee) into it.
QsnStakingPool
Each QsnStakingPool is an independent staking contract created by the factory. It supports any ERC20 staking/reward token pair with configurable parameters.
Features
- Configurable duration -- Reward distribution period set at creation.
- Per-user staking limits -- Optional maximum stake amount per address.
- Synthetix-style rewards -- Same linear distribution model as the StakeVault.
- No lock-up -- Stakers can withdraw at any time.
Key Functions
| Function | Description |
|---|---|
stake(uint256 amount) | Deposit staking tokens. |
withdraw(uint256 amount) | Withdraw staked tokens. |
getReward() | Claim accumulated reward tokens. |
exit() | Withdraw all staked tokens and claim all rewards. |
Pool Lifecycle
- Creator deploys the pool via the factory with reward tokens and parameters.
- Users stake their tokens and begin earning rewards.
- Rewards distribute linearly over the configured duration.
- After the duration ends, no new rewards accrue (unless the creator deposits additional rewards).
- Users can withdraw staked tokens and claim remaining rewards at any time.