Explore the Stability Pool, the cornerstone of the Roots protocol’s liquidation mechanism and a source of earning opportunities for MEAD depositors. This contract secures the system by absorbing debt from liquidated Troves and rewards participants with the liquidated collateral. Delve into its functions for managing deposits, claiming gains, and tracking rewards, alongside the events that signal its critical operations.

Functions

DECIMAL_PRECISION()

Returns the decimal precision used in calculations. (View)

function DECIMAL_PRECISION() -> uint256 [view]

P()

Returns the product P, a factor used in calculating depositor rewards. (View)

function P() -> uint256 [view]

ROOTS_CORE()

Returns the address of the IRootsCore contract. (View)

function ROOTS_CORE() -> address (contract IRootsCore) [view]

SCALE_FACTOR()

Returns the scale factor used in reward calculations. (View)

function SCALE_FACTOR() -> uint256 [view]

SUNSET_DURATION()

Returns the duration of the sunset period for collateral types. (View)

function SUNSET_DURATION() -> uint128 [view]

accountDeposits

Returns deposit amounts for a specific account. (View)

function accountDeposits(_account: address) -> (uint128, uint128) [view]

claimCollateralGains

Allows a depositor to claim their accrued collateral gains.

function claimCollateralGains(recipient: address, collateralIndexes: uint256[]) [nonpayable]

claimReward

Allows a depositor to claim their MEAD rewards from staking in the Stability Pool.

function claimReward(recipient: address) -> uint256 [nonpayable]

claimableReward

Returns the amount of MEAD reward a depositor can currently claim. (View)

function claimableReward(_depositor: address) -> uint256 [view]

collateralGainsByDepositor

Returns collateral gains for a depositor by collateral index. (View)

function collateralGainsByDepositor(depositor: address, _index: uint256) -> uint80 [view]

collateralTokens

Returns the address of a collateral token at a given index. (View)

function collateralTokens(_index: uint256) -> address (contract IERC20) [view]

currentEpoch()

Returns the current epoch. (View)

function currentEpoch() -> uint128 [view]

currentScale()

Returns the current scale. (View)

function currentScale() -> uint128 [view]

debtToken()

Returns the address of the IDebtToken contract. (View)

function debtToken() -> address (contract IDebtToken) [view]

depositSnapshots

Returns snapshot data for a specific depositor. (View)

function depositSnapshots(_depositor: address) -> (uint256, uint256, uint128, uint128) [view]

depositSums

Returns deposit sums for an account and index. (View)

function depositSums(_account: address, _index: uint256) -> uint256 [view]

enableCollateral

Enables a new collateral type to be managed by the Stability Pool.

function enableCollateral(_collateral: address (contract IERC20)) [nonpayable]

endCollateralSunset

Ends the sunset period for a specific collateral index.

function endCollateralSunset(idx: uint256) [nonpayable]

epochToScaleToG

Returns the G value (cumulative sum of collateral gains per unit of stake) for a given epoch and scale. (View)

function epochToScaleToG(_epoch: uint128, _scale: uint128) -> uint256 [view]

epochToScaleToSums

Returns sum values related to epochs and scales for a specific index. (View)

function epochToScaleToSums(_epoch: uint128, _scale: uint128, _index: uint256) -> uint256 [view]

factory()

Returns the factory address. (View)

function factory() -> address [view]

getCompoundedDebtDeposit

Calculates and returns the compounded debt deposit for a depositor. (View)

function getCompoundedDebtDeposit(_depositor: address) -> uint256 [view]

getDepositorCollateralGain

Returns all collateral gains for a specific depositor across all collateral types. (View)

function getDepositorCollateralGain(_depositor: address) -> uint256[] [view]

getTotalDebtTokenDeposits()

Returns the total amount of MEAD (debt token) deposited in the Stability Pool. (View)

function getTotalDebtTokenDeposits() -> uint256 [view]

getWeek()

Returns the current week number. (View)

function getWeek() -> uint256 [view]

guardian()

Returns the guardian address. (View)

function guardian() -> address [view]

indexByCollateral

Returns the index for a given collateral token address. (View)

function indexByCollateral(collateral: address (contract IERC20)) -> uint256 [view]

initialize

Initializes the StabilityPool contract.

function initialize(_debtTokenAddress: address (contract IDebtToken), _factory: address, _liquidationManager: address, _scheduler: address) [nonpayable]

lastCollateralError_Offset

Returns the last collateral error offset for a given index. (View)

function lastCollateralError_Offset(_index: uint256) -> uint256 [view]

lastDebtLossError_Offset()

Returns the last debt loss error offset. (View)

function lastDebtLossError_Offset() -> uint256 [view]

lastRewardsError()

Returns the last rewards error value. (View)

function lastRewardsError() -> uint256 [view]

lastUpdate()

Returns the timestamp of the last update. (View)

function lastUpdate() -> uint32 [view]

liquidationManager()

Returns the address of the Liquidation Manager contract. (View)

function liquidationManager() -> address [view]

offset

Offsets debt with collateral gains when a Trove is liquidated.

function offset(collateral: address (contract IERC20), _debtToOffset: uint256, _collToAdd: uint256) [nonpayable]

owner()

Returns the owner address of the contract. (View)

function owner() -> address [view]

periodFinish()

Returns the timestamp when the current reward period finishes. (View)

function periodFinish() -> uint32 [view]

provideToSP

Deposits a specified amount of MEAD into the Stability Pool.

function provideToSP(_amount: uint256) [nonpayable]

rewardRate()

Returns the current reward rate. (View)

function rewardRate() -> uint128 [view]

scheduler()

Returns the address of the EmissionScheduler contract. (View)

function scheduler() -> address (contract EmissionScheduler) [view]

startCollateralSunset

Initiates the sunset period for a specific collateral type.

function startCollateralSunset(collateral: address (contract IERC20)) [nonpayable]

withdrawFromSP

Withdraws a specified amount of MEAD from the Stability Pool.

function withdrawFromSP(_amount: uint256) [nonpayable]

Events

CollateralGainWithdrawn

Emitted when a depositor withdraws their collateral gains.

event CollateralGainWithdrawn(_depositor: address, _collateral: uint256[])

CollateralOverwritten

Emitted when an old collateral token is overwritten with a new one.

event CollateralOverwritten(oldCollateral: address, newCollateral: address)

CollateralSunset

Emitted when a collateral type starts its sunset period.

event CollateralSunset(collateral: address (contract IERC20), index: uint256)

DepositSnapshotUpdated (Version 1)

Emitted when a depositor’s snapshot (P and G values) is updated.

event DepositSnapshotUpdated(_depositor: address, _P: uint256, _G: uint256)

DepositSnapshotUpdated (Version 2)

Emitted when a depositor’s snapshot (P value) is updated.

event DepositSnapshotUpdated(_depositor: address, _P: uint256)

EpochUpdated

Emitted when the current epoch is updated.

event EpochUpdated(_currentEpoch: uint128)

G_Updated

Emitted when the G value (cumulative sum of collateral gains) is updated for an epoch and scale.

event G_Updated(_G: uint256, _epoch: uint128, _scale: uint128)

P_Updated

Emitted when the P value (product factor for rewards) is updated.

event P_Updated(_P: uint256)

RewardClaimed

Emitted when a user claims rewards.

event RewardClaimed(account: address, recipient: address, claimed: uint256)

S_Updated

Emitted when the S value (sum of stakes with factor S) is updated for an index, epoch, and scale.

event S_Updated(idx: uint256, _S: uint256, _epoch: uint128, _scale: uint128)

ScaleUpdated

Emitted when the current scale is updated.

event ScaleUpdated(_currentScale: uint128)

StabilityPoolDebtBalanceUpdated

Emitted when the Stability Pool’s total MEAD (debt token) balance is updated.

event StabilityPoolDebtBalanceUpdated(_newBalance: uint256)

UserDepositChanged

Emitted when a user’s MEAD deposit in the Stability Pool changes.

event UserDepositChanged(_depositor: address, _newDeposit: uint256)