LPStaking lets liquidity providers stake their Uniswap V2 LP tokens to earn CLX rewards continuously. Rewards accumulate per second and are claimable at any time without unstaking.
The contract uses a dividend-per-share accumulator (rewardPerTokenStored) so reward accounting is O(1) per user regardless of pool size â no loops, no snapshots. Each second, rewardRate CLX wei is distributed pro-rata to all stakers based on their share of the total staked supply. Rewards are capped to the contract's actual CLX balance, so the pool can never pay out more than it holds.
await lpToken.approve(stakingAddress, amount);
await staking.stake(amount);
await staking.claimReward();
await staking.withdraw(amount);
// or exit() to withdraw everything + claim in one tx
| Function | Access | Description |
|---|---|---|
stake(uint256 amount) | public | Deposit LP tokens; starts earning immediately |
withdraw(uint256 amount) | public | Withdraw LP tokens; accrued rewards preserved |
claimReward() | public | Transfer all accrued CLX rewards to caller |
exit() | public | Withdraw full balance and claim rewards atomically |
emergencyWithdraw() | public | Withdraw LP with no reward claim â no questions asked |
setRewardRate(uint256) | owner | Adjust CLX wei/second emission rate |
nonReentrant. Reward payouts are capped to address(this).balance so the contract can never be drained beyond its funded amount.