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
_initialInflationRate
uint88
The initial inflation rate for the first reward token, scaled by 1e18
_initialReductionFactor
uint88
The initial reduction factor for the first reward token, scaled by 1e18
_rewardToken
address
The address of the first reward token
_clearingHouse
address
The address of the ClearingHouse contract, which calls updatePosition
_ecosystemReserve
address
The address of the EcosystemReserve contract, which stores reward tokens
_earlyWithdrawThreshold
uint256
The amount of time after which LPs can remove liquidity without penalties
_initialRewardWeights
uint256[]
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
market
address
Address of the perpetual market
user
address
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
<none>
uint256
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
_user
address
Address of the user
_market
address
Address of the market
Returns
<none>
uint256
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
<none>
bool
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
_market
address
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
_newEarlyWithdrawalThreshold
uint256
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
<none>
uint256
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
idx
uint256
Index of the market
Returns
<none>
address
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
i
uint256
Index of the market in the allowlist ClearingHouse.ids
(for the PerpRewardDistributor) or stakingTokens
(for the SafetyModule)
Returns
<none>
uint256
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
user
address
Address of the user
market
address
Address of the market
Returns
<none>
uint256
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
market
address
Address of the market in ClearingHouse.perpetuals
user
address
Address of the user
Last updated