Calix Chain

LP Staking

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.

How Rewards Work

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.

User Flow

1
Approve LP tokens
await lpToken.approve(stakingAddress, amount);
2
Stake
await staking.stake(amount);
3
Claim rewards (any time)
await staking.claimReward();
4
Withdraw LP tokens
await staking.withdraw(amount);
// or exit() to withdraw everything + claim in one tx

Key Functions

FunctionAccessDescription
stake(uint256 amount)publicDeposit LP tokens; starts earning immediately
withdraw(uint256 amount)publicWithdraw LP tokens; accrued rewards preserved
claimReward()publicTransfer all accrued CLX rewards to caller
exit()publicWithdraw full balance and claim rewards atomically
emergencyWithdraw()publicWithdraw LP with no reward claim — no questions asked
setRewardRate(uint256)ownerAdjust CLX wei/second emission rate
💡
Compounding rewards. Claim CLX rewards → swap for both pool tokens on the DEX → add liquidity to get more LP tokens → stake again. Automating this cycle maximizes yield over time.
â„šī¸
Security. All functions follow the checks-effects-interactions (CEI) pattern and are guarded with nonReentrant. Reward payouts are capped to address(this).balance so the contract can never be drained beyond its funded amount.