Earning
The callable surface for the four yield paths. Concept: Stability Pool, MOAI staking, FLX staking, LP staking. Mechanics of the fee split: Fees.
Stability Pool
Per branch, on StabilityPool.
StabilityPool.provideToSP(uint256 _amount, address(0))
StabilityPool.withdrawFromSP(uint256 _amount) // _amount = 0 → claim only
StabilityPool.withdrawAllFromSP() // withdraw as much as possible
StabilityPool.withdrawCollateralGainToTrove(address _upperHint, address _lowerHint)
provideToSPrequires the caller to hold and approve_amountRD. The second argument is a front-end tag. The contracts support front ends that register and take a share of their depositors' MOAI rewards (a kickback rate), but the team promotes a single canonical front end that takes nothing, so this system is unused: passaddress(0). The tag is only recorded when a deposit is first created; top-ups keep the existing tag whatever you pass. Soaddress(0)gives the depositor all of their MOAI only for a new deposit, or one that was already untagged. A deposit that already carries a tag stays subject to that front end's kickback rate until it is fully withdrawn and redeposited withaddress(0). Read the current tag fromdeposits(depositor).frontEndTagbefore telling a user they keep all of their rewards.- Before taking a deposit,
provideToSPtries to liquidate up to 10 troves below MCR that the pool can fully absorb (gas compensation goes to the depositor). - Total deposits are capped at the branch's total debt (
getDepositCap(),getDepositHeadroom()); a deposit over the cap reverts"StabilityPool: deposit exceeds branch debt cap". - Every
provideToSPrestarts a 1-day withdrawal lockup (SP_WITHDRAWAL_LOCKUP()= 86,400 s); a positive withdrawal before it ends reverts"StabilityPool: lockup time has not passed". withdrawFromSPpays out accumulated collateral gain and MOAI, then returnsmin(_amount, your compounded deposit)RD; the pool always keepsMIN_RD_IN_SP= 1 RD. A positive withdrawal reverts while the lowest trove in either sorted list is below MCR. Pass0to claim rewards without touching the deposit.withdrawCollateralGainToTrovemoves your whole collateral gain into your trove on the same branch (you need an active trove there) instead of paying it out, and pays your MOAI.- Your share of the branch's borrow interest is added to your deposit in RD (
getCompoundedRDDeposit(address)).
LP staking
One LPStaking contract per RD market pool (RD/USDC and RD/USDT). Each stakes that pool's RdStableSwapHook ERC-20 LP share. No tier.
LPStaking.deposit(uint256 _amount) // approve the pool's LP share first
LPStaking.withdraw(uint256 _amount) // or withdrawAll(); settles MOAI + RD
LPStaking.claimRewards() // settle MOAI + RD without changing stake
LPStaking.getPendingRewards(address) // view: (moaiReward, rdReward)
Each deposit sets a 48-hour withdrawal lockup on the whole stake (WITHDRAWAL_LOCKUP; early withdrawal reverts LPStaking_LockupNotExpired). Rewards can be claimed during the lockup.
Two reward streams, both via a reward-per-share index:
F_MOAI += MOAI_issued / total_staked // from V4LpIssuance
F_RD += RD_received / total_staked // LP fee share from LpFeeDistributor
my_pending_MOAI = my_stake × (F_MOAI − snapshot_MOAI)
my_pending_RD = my_stake × (F_RD − snapshot_RD)
MOAI staking
Singleton MOAIStaking. Earns borrow interest and other protocol fees in RD; lockup tiers set the reward multiplier. No token approval is needed: MOAIStaking moves the MOAI itself.
MOAIStaking.stake(uint256 _MOAIamount) // new position at tier 0, or top up an active position at its tier
MOAIStaking.stakeWithTier(uint256 _MOAIamount, uint8 _tier) // new position, same-tier top-up, or re-lock an expired position at any tier
MOAIStaking.changeTier(uint8 _newTier) // up any time; down or same tier only after expiry
MOAIStaking.unstake(uint256 _MOAIamount) // only after lock expiry; unstake(0) claims
MOAIStaking.claimReward() // pay pending RD
MOAIStaking.getPendingRDGain(address) // view
- Tier constants:
TIER_0/1/2_MULTIPLIER(1.0× / 1.15× / 1.5×),TIER_0/1/2_LOCKUP(7 d / 30 d / 60 d). Every stake and everychangeTierrestarts the lock at the tier's full length from now. - The multiplier applies only while the lock is active (expiry rounded up to the next 6-hour
BONUS_EPOCH_DURATIONboundary); after that the position counts at 1.0×. - Unstaking before expiry reverts
LockupNotExpired(lockExpiry, now); pending RD can still be claimed. Every state-changing call pays pending RD. - Gotchas:
stake()revertsExpiredStakeRequiresTierSelection()on an expired position (forcing an explicitstakeWithTierre-lock);stakeWithTieron an active position with a different tier revertsTierMismatch(current, requested);changeTierto the current tier while locked revertsAlreadyInTier.
FLX staking
Singleton FLXStaking. Earns a fixed MOAI pot streamed linearly over 365 days (STREAMING_DURATION). No lockup.
FLXStaking.stake(uint256 _FLXamount) // approve FLX first; also pays accrued MOAI
FLXStaking.unstake(uint256 _FLXamount) // pays accrued MOAI; unstake(0) claims only
FLXStaking.getPendingMOAIGain(address) // view: pending MOAI
There is no separate claim function — accrued MOAI is paid out whenever you stake or unstake; use unstake(0) to claim without withdrawing.
F_MOAI += newly_vested_MOAI / total_FLX_staked
my_pending = my_FLX_staked × (F_MOAI − snapshot)