PerpRewardDistributor
Inherits: RewardDistributor, IPerpRewardDistributor
Author: webthethird
Handles reward accrual and distribution for liquidity providers in Perpetual markets
State Variables
clearingHouse
Clearing House contract
_earlyWithdrawalThreshold
Amount of time after which LPs can remove liquidity without penalties
_withdrawTimerStartByUserByMarket
Last timestamp when user changed their position in a market
First address is user, second is the market
Functions
onlyClearingHouse
Modifier for functions that can only be called by the ClearingHouse, i.e., updatePosition
constructor
PerpRewardDistributor constructor
Parameters
Name | Type | Description |
---|---|---|
|
| The initial inflation rate for the first reward token, scaled by 1e18 |
|
| The initial reduction factor for the first reward token, scaled by 1e18 |
|
| The address of the first reward token |
|
| The address of the ClearingHouse contract, which calls |
|
| The address of the EcosystemReserve contract, which stores reward tokens |
|
| The amount of time after which LPs can remove liquidity without penalties |
|
| The initial reward weights for the first reward token, as basis points |
updatePosition
Accrues rewards and updates the stored LP position of a user and the total LP of a market
Only callable by the clearing house, executes whenever a user's liquidity is updated for any reason
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the perpetual market |
|
| Address of the liquidity provider |
earlyWithdrawalThreshold
Gets the number of seconds that a user must leave their liquidity in the market to avoid the early withdrawal penalty
Returns
Name | Type | Description |
---|---|---|
|
| Length of the early withdrawal period in seconds |
withdrawTimerStartByUserByMarket
Start time of the user's early withdrawal timer for a specific market, i.e., when they last changed their position in the market
The user can withdraw their liquidity without penalty after withdrawTimerStartByUserByMarket(user, market) + earlyWithdrawalThreshold
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the user |
|
| Address of the market |
Returns
Name | Type | Description |
---|---|---|
|
| Timestamp when user last changed their position in the market |
paused
Indicates whether claiming rewards is currently paused
Contract is paused if either this contract or the ClearingHouse has been paused
Returns
Name | Type | Description |
---|---|---|
|
| True if paused, false otherwise |
initMarketStartTime
Sets the start time for accruing rewards to a market which has not been initialized yet
Only callable by governance
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the market (i.e., perpetual market or staking token) |
setEarlyWithdrawalThreshold
Sets the number of seconds that a user must leave their liquidity in the market to avoid the early withdrawal penalty
Only callable by governance
Parameters
Name | Type | Description |
---|---|---|
|
| New early withdrawal threshold in seconds |
_getNumMarkets
Gets the number of markets to be used for reward distribution
Markets are the perpetual markets (for the PerpRewardDistributor) or staked tokens (for the SafetyModule)
Returns
Name | Type | Description |
---|---|---|
|
| Number of markets |
_getMarketAddress
Gets the address of a market at a given index
Markets are the perpetual markets (for the PerpRewardDistributor) or staked tokens (for the SafetyModule)
Parameters
Name | Type | Description |
---|---|---|
|
| Index of the market |
Returns
Name | Type | Description |
---|---|---|
|
| Address of the market |
_getMarketIdx
Gets the index of an allowlisted market
Markets are the perpetual markets (for the PerpRewardDistributor) or staked tokens (for the SafetyModule)
Parameters
Name | Type | Description |
---|---|---|
|
| Index of the market in the allowlist |
Returns
Name | Type | Description |
---|---|---|
|
| Index of the market in the market list |
_getCurrentPosition
Returns the current position of the user in the market (i.e., perpetual market or staked token)
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the user |
|
| Address of the market |
Returns
Name | Type | Description |
---|---|---|
|
| Current position of the user in the market |
_accrueRewards
Accrues rewards and updates the stored LP position of a user and the total liquidity in the market
Called by updatePosition
, which can only be called by the ClearingHouse when an LP's position changes, and claimRewards
, which always passes msg.sender
as the user
Parameters
Name | Type | Description |
---|---|---|
|
| Address of the market in |
|
| Address of the user |
Last updated