SMRewardDistributor
Inherits: RewardDistributor, ISMRewardDistributor
Author: webthethird
Reward distributor for the Safety Module
State Variables
safetyModule
The SafetyModule contract which stores the list of StakedTokens and can call updatePosition
_maxRewardMultiplier
The maximum reward multiplier, scaled by 1e18
_smoothingValue
The smoothing value, scaled by 1e18
The higher the value, the slower the multiplier approaches its max
_multiplierStartTimeByUser
The starting timestamp used to calculate the user's reward multiplier for a given staked token
First address is user, second is staked token
Functions
onlySafetyModule
Modifier for functions that should only be called by the SafetyModule, i.e., initMarketStartTime
constructor
SafetyModule constructor
Parameters
_safetyModule
ISafetyModule
The address of the SafetyModule contract
_maxMultiplier
uint256
The maximum reward multiplier, scaled by 1e18
_smoothingVal
uint256
The smoothing value, scaled by 1e18
_ecosystemReserve
address
The address of the EcosystemReserve contract, where reward tokens are stored
updatePosition
Accrues rewards and updates the stored stake position of a user and the total tokens staked
Only callable by a registered StakedToken, executes whenever a user's stake is updated for any reason
Parameters
market
address
Address of the staked token in SafetyModule.stakedTokens
user
address
Address of the staker
getMaxRewardMultiplier
Gets the maximum reward multiplier set by governance
Returns
<none>
uint256
Maximum reward multiplier, scaled by 1e18
getSmoothingValue
Gets the smoothing value set by governance
Returns
<none>
uint256
Smoothing value, scaled by 1e18
multiplierStartTimeByUser
Gets the starting timestamp used to calculate the user's reward multiplier for a given staked token
This value is updated whenever updatePosition
is called, according to the user's change in stake
Parameters
_user
address
Address of the user
_stakedToken
address
Address of the staked token
Returns
<none>
uint256
User's multiplier starting timestamp
paused
Indicates whether claiming rewards is currently paused
Contract is paused if either this contract or the SafetyModule has been paused
Returns
<none>
bool
True if paused, false otherwise
computeRewardMultiplier
Computes the user's reward multiplier for the given staked token
Based on the max multiplier, smoothing factor and time since last withdrawal (or first deposit)
Parameters
_user
address
Address of the staker
_stakedToken
address
Address of staked token earning rewards
Returns
<none>
uint256
User's reward multiplier, scaled by 1e18
initMarketStartTime
Sets the start time for accruing rewards to a market which has not been initialized yet
Can only be called by the SafetyModule
Parameters
_market
address
Address of the market (i.e., perpetual market or staking token)
setSafetyModule
Replaces the SafetyModule contract
Only callable by governance
Parameters
_newSafetyModule
ISafetyModule
Address of the new SafetyModule contract
setMaxRewardMultiplier
Sets the maximum reward multiplier
Only callable by governance, reverts if the new value is less than 1e18 (100%) or greater than 10e18 (1000%)
Parameters
_newMaxMultiplier
uint256
New maximum reward multiplier, scaled by 1e18
setSmoothingValue
Sets the smoothing value used in calculating the reward multiplier
Only callable by governance, reverts if the new value is less than 10e18 or greater than 100e18
Parameters
_newSmoothingValue
uint256
New smoothing value, scaled by 1e18
pause
Pause the contract
Only callable by governance
unpause
Unpause the contract
Only callable by governance
togglePausedReward
Pauses/unpauses the reward accrual for a particular reward token
Only callable by governance
Parameters
_rewardToken
address
Address of the reward token
_getNumMarkets
_getMarketAddress
_getMarketIdx
_getCurrentPosition
Returns the user's staked token balance
Parameters
staker
address
Address of the user
token
address
Address of the staked token
Returns
<none>
uint256
Current balance of the user in the staked token
_accrueRewards
Accrues rewards and updates the stored stake position of a user and the total tokens staked
Called by updatePosition
, which can only be called by a StakedToken when a user's stake changes, and claimRewards
, which always passes msg.sender
as the user
Parameters
market
address
Address of the token in stakedTokens
user
address
Address of the user
_registerPosition
Registers a user's pre-existing position for a given market
User should have a position predating this contract's deployment, which can only be registered once
Parameters
_user
address
Address of the user to register
_market
address
Address of the market for which to register the user's position
Last updated