RewardDistributor
Inherits: IRewardDistributor, ExponentialNoError, Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable
Title: Reward distribution manager
Author: Malda Protocol
Distributes reward tokens to suppliers and borrowers across markets.
State Variables
REWARD_INITIAL_INDEX
Initial index used when starting accruals
uint224 public constant REWARD_INITIAL_INDEX = 1e36
operator
The operator that rewards are distributed to
address public operator
rewardMarketState
The Reward state for each reward token for each market
mapping(address rewardToken => mapping(address mToken => IRewardDistributorData.RewardMarketState marketState))
public rewardMarketState
rewardAccountState
The Reward state for each reward token for each account
mapping(
address rewardToken => mapping(address account => IRewardDistributorData.RewardAccountState accountState)
) public rewardAccountState
rewardTokens
Added reward tokens
address[] public rewardTokens
isRewardToken
mapping(address rewardToken => bool status) public isRewardToken
Functions
onlyOperator
Modifier to check if the caller is the operator
modifier onlyOperator() ;
constructor
Disable initializers for the implementation
Note: oz-upgrades-unsafe-allow: constructor
constructor() ;
setOperator
Sets the operator allowed to notify indices
function setOperator(address _operator) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
_operator | address | Operator address |
notifySupplyIndex
Updates supply indices for all reward tokens on a market
function notifySupplyIndex(address mToken) external override onlyOperator;
Parameters
| Name | Type | Description |
|---|---|---|
mToken | address | Market token |
notifyBorrowIndex
Updates borrow indices for all reward tokens on a market
function notifyBorrowIndex(address mToken) external override onlyOperator;
Parameters
| Name | Type | Description |
|---|---|---|
mToken | address | Market token |
notifySupplier
Accrues supplier rewards for all reward tokens on a market
function notifySupplier(address mToken, address supplier) external override onlyOperator;
Parameters
| Name | Type | Description |
|---|---|---|
mToken | address | Market address |
supplier | address | Supplier address |
notifyBorrower
Accrues borrower rewards for all reward tokens on a market
function notifyBorrower(address mToken, address borrower) external override onlyOperator;
Parameters
| Name | Type | Description |
|---|---|---|
mToken | address | Market address |
borrower | address | Borrower address |
initialize
Initializes the upgradeable contract
function initialize(address _owner) public initializer;
Parameters
| Name | Type | Description |
|---|---|---|
_owner | address | Owner address |
claim
Claims rewards for a list of holders across all reward tokens
function claim(address[] memory holders) public override nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
holders | address[] | Account list to claim for |
whitelistToken
Whitelists a new reward token
function whitelistToken(address rewardToken_) public onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken_ | address | Reward token address |
updateRewardSpeeds
Updates reward speeds for multiple markets
function updateRewardSpeeds(
address rewardToken_,
address[] memory mTokens,
uint256[] memory supplySpeeds,
uint256[] memory borrowSpeeds
) public onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken_ | address | Reward token address |
mTokens | address[] | Market addresses |
supplySpeeds | uint256[] | Supply speeds per market |
borrowSpeeds | uint256[] | Borrow speeds per market |
getBlockTimestamp
Get block timestamp
function getBlockTimestamp() public view override returns (uint32);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint32 | timestamp Current block timestamp |
getRewardTokens
Added reward tokens
function getRewardTokens() public view override returns (address[] memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address[] | rewardTokens Array of reward token addresses |
_claim
Claims rewards for holders for a given token
function _claim(address rewardToken, address[] memory holders) internal;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken | address | Reward token address |
holders | address[] | Holder list |
_grantReward
Transfers accrued rewards to a user
function _grantReward(address token, address user, uint256 amount) internal returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | Reward token |
user | address | Recipient address |
amount | uint256 | Amount to grant |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Remaining amount (if transfer not fully executed) |
_updateRewardSpeed
Updates supply/borrow speed and indexes for a market
function _updateRewardSpeed(address rewardToken, address mToken, uint256 supplySpeed, uint256 borrowSpeed) private;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken | address | Reward token address |
mToken | address | Market address |
supplySpeed | uint256 | New supply speed |
borrowSpeed | uint256 | New borrow speed |
_notifySupplyIndex
Updates supply index for a reward token/market pair
function _notifySupplyIndex(address rewardToken, address mToken) private;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken | address | Reward token address |
mToken | address | Market address |
_notifyBorrowIndex
Updates borrow index for a reward token/market pair
function _notifyBorrowIndex(address rewardToken, address mToken) private;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken | address | Reward token address |
mToken | address | Market address |
_notifySupplier
Accrues supplier rewards for a market
function _notifySupplier(address rewardToken, address mToken, address supplier) private;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken | address | Reward token address |
mToken | address | Market address |
supplier | address | Supplier address |
_notifyBorrower
Accrues borrower rewards for a market
function _notifyBorrower(address rewardToken, address mToken, address borrower) private;
Parameters
| Name | Type | Description |
|---|---|---|
rewardToken | address | Reward token address |
mToken | address | Market address |
borrower | address | Borrower address |
Errors
RewardDistributor_OnlyOperator
Error thrown when the caller is not the operator
error RewardDistributor_OnlyOperator();
RewardDistributor_TransferFailed
Error thrown when the transfer fails
error RewardDistributor_TransferFailed();
RewardDistributor_RewardNotValid
Error thrown when the reward token is not valid
error RewardDistributor_RewardNotValid();
RewardDistributor_AddressNotValid
Error thrown when the address is not valid
error RewardDistributor_AddressNotValid();
RewardDistributor_AddressAlreadyRegistered
Error thrown when the address is already registered
error RewardDistributor_AddressAlreadyRegistered();
RewardDistributor_SupplySpeedArrayLengthMismatch
Error thrown when the supply speed array length mismatch
error RewardDistributor_SupplySpeedArrayLengthMismatch();
RewardDistributor_BorrowSpeedArrayLengthMismatch
Error thrown when the borrow speed array length mismatch
error RewardDistributor_BorrowSpeedArrayLengthMismatch();