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
ISafetyModule public safetyModule;
_maxRewardMultiplier
The maximum reward multiplier, scaled by 1e18
uint256 internal _maxRewardMultiplier;
_smoothingValue
The smoothing value, scaled by 1e18
The higher the value, the slower the multiplier approaches its max
uint256 internal _smoothingValue;
_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
mapping(address => mapping(address => uint256)) internal _multiplierStartTimeByUser;
Functions
onlySafetyModule
Modifier for functions that should only be called by the SafetyModule, i.e., initMarketStartTime
modifier onlySafetyModule();
constructor
SafetyModule constructor
constructor(ISafetyModule _safetyModule, uint256 _maxMultiplier, uint256 _smoothingVal, address _ecosystemReserve)
payable
RewardDistributor(_ecosystemReserve);
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
function updatePosition(address market, address user) external virtual override;
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
function getMaxRewardMultiplier() external view returns (uint256);
Returns
<none>
uint256
Maximum reward multiplier, scaled by 1e18
getSmoothingValue
Gets the smoothing value set by governance
function getSmoothingValue() external view returns (uint256);
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
function multiplierStartTimeByUser(address _user, address _stakedToken) public view override returns (uint256);
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
function paused() public view override returns (bool);
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)
function computeRewardMultiplier(address _user, address _stakedToken) public view returns (uint256);
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
function initMarketStartTime(address _market) external onlySafetyModule;
Parameters
_market
address
Address of the market (i.e., perpetual market or staking token)
setSafetyModule
Replaces the SafetyModule contract
Only callable by governance
function setSafetyModule(ISafetyModule _newSafetyModule) external onlyRole(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%)
function setMaxRewardMultiplier(uint256 _newMaxMultiplier) external onlyRole(GOVERNANCE);
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
function setSmoothingValue(uint256 _newSmoothingValue) external onlyRole(GOVERNANCE);
Parameters
_newSmoothingValue
uint256
New smoothing value, scaled by 1e18
pause
Pause the contract
Only callable by governance
function pause() external override onlyRole(GOVERNANCE);
unpause
Unpause the contract
Only callable by governance
function unpause() external override onlyRole(GOVERNANCE);
togglePausedReward
Pauses/unpauses the reward accrual for a particular reward token
Only callable by governance
function togglePausedReward(address _rewardToken) external override onlyRole(GOVERNANCE);
Parameters
_rewardToken
address
Address of the reward token
_getNumMarkets
function _getNumMarkets() internal view virtual override returns (uint256);
_getMarketAddress
function _getMarketAddress(uint256 index) internal view virtual override returns (address);
_getMarketIdx
function _getMarketIdx(uint256 i) internal view virtual override returns (uint256);
_getCurrentPosition
Returns the user's staked token balance
function _getCurrentPosition(address staker, address token) internal view virtual override returns (uint256);
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
function _accrueRewards(address market, address user) internal virtual override;
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
function _registerPosition(address _user, address _market) internal override;
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