Fee Collection
The FeeCollector contract is the protocol component responsible for aggregating trading fees from all QsnDEX liquidity pools and routing them to the QSN StakeVault for distribution to stakers.
Fee Flow
The end-to-end flow from trade execution to staker rewards:
Trading Pairs
|
v
FeeCollector.skim() -- Collects accumulated fees from pool reserves
|
v
WETH Wrapping -- Converts collected ETH to WETH
|
v
StakeVault.notifyRewardAmount() -- Initiates 7-day reward streaming
How Fee Collection Works
1. Fee Accumulation
Each time a swap occurs in a QsnDEX pool, the fee portion remains in the pool reserves. Over time, the actual reserves grow slightly beyond the tracked reserve values (reserve0, reserve1), creating a surplus.
2. Skim
The skim function on the FeeCollector reads the difference between the actual token balances and the tracked reserves for a given pair, then transfers the surplus to the FeeCollector contract.
3. Batch Collection
The FeeCollector supports batch operations, allowing fees to be collected from multiple trading pairs in a single transaction. This reduces gas costs compared to calling skim individually for each pair.
feeCollector.batchSkim(pairAddresses);
4. WETH Wrapping
After collection, any native ETH held by the FeeCollector is wrapped to WETH. All reward distribution to the StakeVault is denominated in WETH for consistency.
5. Distribution
The FeeCollector calls notifyRewardAmount() on the QsnStakeVault, depositing the collected WETH and initiating (or extending) the 7-day reward streaming period.
Security
Two-Step Ownership Transfer
The FeeCollector uses a two-step ownership transfer pattern to prevent accidental loss of admin control:
- The current owner calls
transferOwnership(newOwner)to nominate a new owner. - The nominated address must call
acceptOwnership()to complete the transfer.
This ensures that ownership is never transferred to an address that cannot interact with the contract.
Contract Permissions
- Only the owner can trigger
skimand distribution operations. - Only the owner can update the target StakeVault address.
- Ownership transfer requires explicit acceptance by the new owner.