RewardsManager
Inherits: IRewardsManager, Initializable
Author: Morpho Labs
Contract managing Aave's protocol rewards.
State Variables
_REWARDS_CONTROLLER
The address of Aave's rewards controller.
The rewards controller is, in theory, specific to an asset. In practice, it is the same for all assets and it is supposed to be true for future assets as well.
IRewardsController internal immutable _REWARDS_CONTROLLER;
_MORPHO
The address of the Morpho protocol.
IMorpho internal immutable _MORPHO;
_localAssetData
The local data related to a given asset (either aToken or debt token). asset -> reward -> RewardData
mapping(address => mapping(address => RewardData)) internal _localAssetData;
Functions
onlyMorpho
Prevents a user to call function allowed for the main Morpho contract only.
modifier onlyMorpho();
constructor
Contract constructor.
The implementation contract disables initialization upon deployment to avoid being hijacked.
constructor(address rewardsController, address morpho);
Parameters
Name | Type | Description |
---|---|---|
rewardsController | address | The address of the Aave rewards controller. |
morpho | address | The address of the main Morpho contract. |
claimRewards
Accrues unclaimed rewards for the given assets and returns the total unclaimed rewards.
function claimRewards(address[] calldata assets, address user)
external
onlyMorpho
returns (address[] memory rewardsList, uint256[] memory claimedAmounts);
Parameters
Name | Type | Description |
---|---|---|
assets | address[] | The assets for which to accrue rewards (aToken or variable debt token). |
user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
rewardsList | address[] | The list of reward tokens. |
claimedAmounts | uint256[] | The list of claimed reward amounts. |
updateUserRewards
Updates the unclaimed rewards of a user.
Only called by Morpho at positions updates in the data structure.
function updateUserRewards(address user, address asset, uint256 userBalance) external onlyMorpho;
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user. |
asset | address | The address of the reference asset of the distribution (aToken or variable debt token). |
userBalance | uint256 | The current user asset balance. |
MORPHO
Returns the Morpho protocol address.
function MORPHO() external view returns (address);
REWARDS_CONTROLLER
Returns the rewards controller address.
function REWARDS_CONTROLLER() external view returns (address);
getRewardData
Returns the last updated index and timestamp for a specific asset and reward token.
function getRewardData(address asset, address reward)
external
view
returns (uint256 startingIndex, uint256 index, uint256 lastUpdateTimestamp);
Parameters
Name | Type | Description |
---|---|---|
asset | address | The address of the asset. |
reward | address | The address of the reward token. |
Returns
Name | Type | Description |
---|---|---|
startingIndex | uint256 | The index from which the rewards manager begins tracking the rewards controller. |
index | uint256 | The last updated index. |
lastUpdateTimestamp | uint256 | The last updated timestamp. |
getUserData
Returns the user's index and accrued rewards for a specific asset and rewards pair.
function getUserData(address asset, address reward, address user)
external
view
returns (uint256 index, uint256 accrued);
Parameters
Name | Type | Description |
---|---|---|
asset | address | The address of the asset. |
reward | address | The address of the reward token. |
user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
index | uint256 | The user's index. |
accrued | uint256 | The user's accrued rewards. |
getUserAccruedRewards
Returns user's accrued rewards for the specified assets and reward token
function getUserAccruedRewards(address[] calldata assets, address user, address reward)
external
view
returns (uint256 totalAccrued);
Parameters
Name | Type | Description |
---|---|---|
assets | address[] | The list of assets to retrieve accrued rewards. |
user | address | The address of the user. |
reward | address | The address of the reward token. |
Returns
Name | Type | Description |
---|---|---|
totalAccrued | uint256 | The total amount of accrued rewards. |
getAllUserRewards
Returns user's rewards for the specified assets and for all reward tokens.
function getAllUserRewards(address[] calldata assets, address user)
external
view
returns (address[] memory rewardsList, uint256[] memory unclaimedAmounts);
Parameters
Name | Type | Description |
---|---|---|
assets | address[] | The list of assets to retrieve rewards. |
user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
rewardsList | address[] | The list of reward tokens. |
unclaimedAmounts | uint256[] | The list of unclaimed reward amounts. |
getUserRewards
Returns user's rewards for the specified assets and reward token.
function getUserRewards(address[] calldata assets, address user, address reward) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | address[] | The list of assets to retrieve rewards. |
user | address | The address of the user. |
reward | address | The address of the reward token |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The user's rewards in reward token. |
getUserAssetIndex
Returns the user's index for the specified asset and reward token.
If an already listed AaveV3 reward token is not yet tracked (startingIndex == 0), this view function ignores that it will get updated upon interaction.
function getUserAssetIndex(address user, address asset, address reward) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user. |
asset | address | The address of the reference asset of the distribution (aToken or variable debt token). |
reward | address | The address of the reward token. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The user's index. |
getAssetIndex
Returns the virtually updated asset index for the specified asset and reward token.
function getAssetIndex(address asset, address reward) external view returns (uint256 assetIndex);
Parameters
Name | Type | Description |
---|---|---|
asset | address | The address of the reference asset of the distribution (aToken or variable debt token). |
reward | address | The address of the reward token. |
Returns
Name | Type | Description |
---|---|---|
assetIndex | uint256 | The reward token's virtually updated asset index. |
_updateRewardData
Updates the state of the distribution for the specified reward.
function _updateRewardData(
RewardData storage localRewardData,
address asset,
address reward,
uint256 scaledTotalSupply,
uint256 assetUnit
) internal returns (uint256 newIndex, bool indexUpdated);
Parameters
Name | Type | Description |
---|---|---|
localRewardData | RewardData | The local reward's data. |
asset | address | The asset being rewarded. |
reward | address | The address of the reward token. |
scaledTotalSupply | uint256 | The current scaled total supply of underlying assets for this distribution. |
assetUnit | uint256 | The asset's unit (10**decimals). |
Returns
Name | Type | Description |
---|---|---|
newIndex | uint256 | The new distribution index. |
indexUpdated | bool | True if the index was updated, false otherwise. |
_updateUserData
Updates the state of the distribution for the specific user.
function _updateUserData(
RewardData storage localRewardData,
address user,
uint256 userBalance,
uint256 newAssetIndex,
uint256 assetUnit
) internal returns (uint256 rewardsAccrued, bool dataUpdated);
Parameters
Name | Type | Description |
---|---|---|
localRewardData | RewardData | The local reward's data |
user | address | The address of the user. |
userBalance | uint256 | The current user asset balance. |
newAssetIndex | uint256 | The new index of the asset distribution. |
assetUnit | uint256 | The asset's unit (10**decimals). |
Returns
Name | Type | Description |
---|---|---|
rewardsAccrued | uint256 | The rewards accrued since the last update. |
dataUpdated | bool | True if the data was updated, false otherwise. |
_updateData
Iterates and accrues all the rewards for asset of the specific user.
function _updateData(address user, address asset, uint256 userBalance, uint256 scaledTotalSupply) internal;
Parameters
Name | Type | Description |
---|---|---|
user | address | The user address. |
asset | address | The address of the reference asset of the distribution. |
userBalance | uint256 | The current user asset balance. |
scaledTotalSupply | uint256 | The current scaled total supply for this distribution. |
_updateDataMultiple
Accrues all the rewards of the assets specified in the userAssetBalances list.
function _updateDataMultiple(address user, UserAssetBalance[] memory userAssetBalances) internal;
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user. |
userAssetBalances | UserAssetBalance[] | The list of structs with the user balance and total supply of a set of assets. |
_getUserReward
Returns the accrued unclaimed amount of a reward from a user over a list of distribution.
function _getUserReward(address user, address reward, UserAssetBalance[] memory userAssetBalances)
internal
view
returns (uint256 unclaimedRewards);
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user. |
reward | address | The address of the reward token. |
userAssetBalances | UserAssetBalance[] | List of structs with the user balance and total supply of a set of assets. |
Returns
Name | Type | Description |
---|---|---|
unclaimedRewards | uint256 | The accrued rewards for the user until the moment. |
_getPendingRewards
Computes the pending (not yet accrued) rewards since the last user action.
function _getPendingRewards(address user, address reward, UserAssetBalance memory userAssetBalance)
internal
view
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the user. |
reward | address | The address of the reward token. |
userAssetBalance | UserAssetBalance | The struct with the user balance and total supply of the incentivized asset. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The pending rewards for the user since the last user action. |
_getRewards
Computes user's accrued rewards on a distribution.
function _getRewards(uint256 userBalance, uint256 reserveIndex, uint256 userIndex, uint256 assetUnit)
internal
pure
returns (uint256 rewards);
Parameters
Name | Type | Description |
---|---|---|
userBalance | uint256 | The current user asset balance. |
reserveIndex | uint256 | The current index of the distribution. |
userIndex | uint256 | The index stored for the user, representing its staking moment. |
assetUnit | uint256 | The asset's unit (10**decimals). |
Returns
Name | Type | Description |
---|---|---|
rewards | uint256 | The rewards accrued. |
_getAssetIndex
Computes the next value of an specific distribution index, with validations.
function _getAssetIndex(
RewardData storage localRewardData,
address asset,
address reward,
uint256 scaledTotalSupply,
uint256 assetUnit
) internal view returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
localRewardData | RewardData | The local reward's data. |
asset | address | The asset being rewarded. |
reward | address | The address of the reward token. |
scaledTotalSupply | uint256 | The current total supply of underlying assets for this distribution. |
assetUnit | uint256 | The asset's unit (10**decimals). |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The former index and the new index in this order. |
<none> | uint256 |
_getUserAssetBalances
Returns user balances and total supply of all the assets specified by the assets parameter.
function _getUserAssetBalances(address[] calldata assets, address user)
internal
view
returns (UserAssetBalance[] memory userAssetBalances);
Parameters
Name | Type | Description |
---|---|---|
assets | address[] | List of assets to retrieve user balance and total supply. |
user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
userAssetBalances | UserAssetBalance[] | The list of structs with user balance and total supply of the given assets. |
_computeUserIndex
Computes the index of a user for a specific reward distribution.
function _computeUserIndex(RewardData storage localRewardData, address user) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
localRewardData | RewardData | The local reward's data. |
user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The index of the user for the distribution. |