Skip to content

RewardsDistributor

Contract used to configure, track and distribute rewards to users based on their actions (borrows and supplies) in the protocol. Users can receive additional rewards through a RewardsDistributor. Each RewardsDistributor proxy is initialized with a specific reward token and Comptroller, which can then distribute the reward token to users that supply or borrow in the associated pool. Authorized users can set the reward token borrow and supply speeds for each market in the pool. This sets a fixed amount of reward token to be released each block for borrowers and suppliers, which is distributed based on a user’s percentage of the borrows or supplies respectively. The owner can also set up reward distributions to contributor addresses (distinct from suppliers and borrowers) by setting their contributor reward token speed, which similarly allocates a fixed amount of reward token per block.

The owner has the ability to transfer any amount of reward tokens held by the contract to any other address. Rewards are not distributed automatically and must be claimed by a user calling claimRewardToken(). Users should be aware that it is up to the owner and other centralized entities to ensure that the RewardsDistributor holds enough tokens to distribute the accumulated rewards of users and contributors.

struct RewardToken {
uint224 index;
uint32 block;
uint32 lastRewardingBlock;
}

The initial REWARD TOKEN index for a market

uint224 INITIAL_INDEX

The REWARD TOKEN market supply state for each market

mapping(address => struct RewardsDistributor.RewardToken) rewardTokenSupplyState

The REWARD TOKEN borrow index for each market for each supplier as of the last time they accrued REWARD TOKEN

mapping(address => mapping(address => uint256)) rewardTokenSupplierIndex

The REWARD TOKEN accrued but not yet transferred to each user

mapping(address => uint256) rewardTokenAccrued

The rate at which rewardToken is distributed to the corresponding borrow market (per block)

mapping(address => uint256) rewardTokenBorrowSpeeds

The rate at which rewardToken is distributed to the corresponding supply market (per block)

mapping(address => uint256) rewardTokenSupplySpeeds

The REWARD TOKEN market borrow state for each market

mapping(address => struct RewardsDistributor.RewardToken) rewardTokenBorrowState

The portion of REWARD TOKEN that each contributor receives per block

mapping(address => uint256) rewardTokenContributorSpeeds

Last block at which a contributor’s REWARD TOKEN rewards have been allocated

mapping(address => uint256) lastContributorBlock

The REWARD TOKEN borrow index for each market for each borrower as of the last time they accrued REWARD TOKEN

mapping(address => mapping(address => uint256)) rewardTokenBorrowerIndex

RewardsDistributor initializer

function initialize(contract Comptroller comptroller_, contract IERC20Upgradeable rewardToken_, uint256 loopsLimit_, address accessControlManager_) external
NameTypeDescription
comptroller_contract ComptrollerComptroller to attach the reward distributor to
rewardToken_contract IERC20UpgradeableReward token to distribute
loopsLimit_uint256Maximum number of iterations for the loops in this contract
accessControlManager_addressAccessControlManager contract address

Calculate reward token accrued by a borrower and possibly transfer it to them Borrowers will begin to accrue after the first interaction with the protocol.

function distributeBorrowerRewardToken(address vToken, address borrower, struct ExponentialNoError.Exp marketBorrowIndex) external
NameTypeDescription
vTokenaddressThe market in which the borrower is interacting
borroweraddressThe address of the borrower to distribute REWARD TOKEN to
marketBorrowIndexstruct ExponentialNoError.ExpThe current global borrow index of vToken

Transfer REWARD TOKEN to the recipient

function grantRewardToken(address recipient, uint256 amount) external
NameTypeDescription
recipientaddressThe address of the recipient to transfer REWARD TOKEN to
amountuint256The amount of REWARD TOKEN to (possibly) transfer

Set REWARD TOKEN borrow and supply speeds for the specified markets

function setRewardTokenSpeeds(contract VToken[] vTokens, uint256[] supplySpeeds, uint256[] borrowSpeeds) external
NameTypeDescription
vTokenscontract VToken[]The markets whose REWARD TOKEN speed to update
supplySpeedsuint256[]New supply-side REWARD TOKEN speed for the corresponding market
borrowSpeedsuint256[]New borrow-side REWARD TOKEN speed for the corresponding market

Set REWARD TOKEN last rewarding block for the specified markets

function setLastRewardingBlocks(contract VToken[] vTokens, uint32[] supplyLastRewardingBlocks, uint32[] borrowLastRewardingBlocks) external
NameTypeDescription
vTokenscontract VToken[]The markets whose REWARD TOKEN last rewarding block to update
supplyLastRewardingBlocksuint32[]New supply-side REWARD TOKEN last rewarding block for the corresponding market
borrowLastRewardingBlocksuint32[]New borrow-side REWARD TOKEN last rewarding block for the corresponding market

Set REWARD TOKEN speed for a single contributor

function setContributorRewardTokenSpeed(address contributor, uint256 rewardTokenSpeed) external
NameTypeDescription
contributoraddressThe contributor whose REWARD TOKEN speed to update
rewardTokenSpeeduint256New REWARD TOKEN speed for contributor

Claim all the rewardToken accrued by holder in all markets

function claimRewardToken(address holder) external
NameTypeDescription
holderaddressThe address to claim REWARD TOKEN for

Set the limit for the loops can iterate to avoid the DOS

function setMaxLoopsLimit(uint256 limit) external
NameTypeDescription
limituint256Limit for the max loops can execute at a time

Calculate additional accrued REWARD TOKEN for a contributor since last accrual

function updateContributorRewards(address contributor) public
NameTypeDescription
contributoraddressThe address to calculate contributor rewards for

Claim all the rewardToken accrued by holder in the specified markets

function claimRewardToken(address holder, contract VToken[] vTokens) public
NameTypeDescription
holderaddressThe address to claim REWARD TOKEN for
vTokenscontract VToken[]The list of markets to claim REWARD TOKEN in