RewardsManager
Inherits: IRewardsManager, Initializable
Author: Morpho Labs.
This contract is used to manage the COMP rewards from the Compound protocol.
State Variables
userUnclaimedCompRewards
STORAGE ///
mapping(address => uint256) public userUnclaimedCompRewards;
compSupplierIndex
mapping(address => mapping(address => uint256)) public compSupplierIndex;
compBorrowerIndex
mapping(address => mapping(address => uint256)) public compBorrowerIndex;
localCompSupplyState
mapping(address => IComptroller.CompMarketState) public localCompSupplyState;
localCompBorrowState
mapping(address => IComptroller.CompMarketState) public localCompBorrowState;
morpho
IMorpho public morpho;
comptroller
IComptroller public comptroller;
Functions
onlyMorpho
MODIFIERS ///
Thrown when an other address than Morpho triggers the function.
modifier onlyMorpho();
constructor
CONSTRUCTOR ///
Constructs the contract.
The contract is automatically marked as initialized when deployed so that nobody can highjack the implementation contract.
constructor() initializer;
initialize
UPGRADE ///
Initializes the RewardsManager contract.
function initialize(address _morpho) external initializer;
Parameters
Name | Type | Description |
---|---|---|
_morpho | address | The address of Morpho's main contract's proxy. |
getLocalCompSupplyState
EXTERNAL ///
Returns the local COMP supply state.
function getLocalCompSupplyState(address _poolToken) external view returns (IComptroller.CompMarketState memory);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The cToken address. |
Returns
Name | Type | Description |
---|---|---|
<none> | IComptroller.CompMarketState | The local COMP supply state. |
getLocalCompBorrowState
Returns the local COMP borrow state.
function getLocalCompBorrowState(address _poolToken) external view returns (IComptroller.CompMarketState memory);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The cToken address. |
Returns
Name | Type | Description |
---|---|---|
<none> | IComptroller.CompMarketState | The local COMP borrow state. |
claimRewards
Accrues unclaimed COMP rewards for the given cToken addresses and returns the total COMP unclaimed rewards.
This function is called by the morpho
to accrue COMP rewards and reset them to 0.
The transfer of tokens is done in the morpho
.
function claimRewards(address[] calldata _poolTokens, address _user)
external
onlyMorpho
returns (uint256 totalUnclaimedRewards);
Parameters
Name | Type | Description |
---|---|---|
_poolTokens | address[] | The cToken addresses for which to claim rewards. |
_user | address | The address of the user. |
accrueUserSupplyUnclaimedRewards
Updates the unclaimed COMP rewards of the user.
function accrueUserSupplyUnclaimedRewards(address _user, address _poolToken, uint256 _userBalance)
external
onlyMorpho;
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user. |
_poolToken | address | The cToken address. |
_userBalance | uint256 | The user balance of tokens in the distribution. |
accrueUserBorrowUnclaimedRewards
Updates the unclaimed COMP rewards of the user.
function accrueUserBorrowUnclaimedRewards(address _user, address _poolToken, uint256 _userBalance)
external
onlyMorpho;
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user. |
_poolToken | address | The cToken address. |
_userBalance | uint256 | The user balance of tokens in the distribution. |
_accrueUserUnclaimedRewards
INTERNAL ///
Accrues unclaimed COMP rewards for the cToken addresses and returns the total unclaimed COMP rewards.
function _accrueUserUnclaimedRewards(address[] calldata _poolTokens, address _user)
internal
returns (uint256 unclaimedRewards);
Parameters
Name | Type | Description |
---|---|---|
_poolTokens | address[] | The cToken addresses for which to accrue rewards. |
_user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
unclaimedRewards | uint256 | The user unclaimed rewards. |
_accrueSupplierComp
Updates supplier index and returns the accrued COMP rewards of the supplier since the last update.
function _accrueSupplierComp(address _supplier, address _poolToken, uint256 _balance) internal returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_supplier | address | The address of the supplier. |
_poolToken | address | The cToken address. |
_balance | uint256 | The user balance of tokens in the distribution. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The accrued COMP rewards. |
_accrueBorrowerComp
Updates borrower index and returns the accrued COMP rewards of the borrower since the last update.
function _accrueBorrowerComp(address _borrower, address _poolToken, uint256 _balance) internal returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_borrower | address | The address of the borrower. |
_poolToken | address | The cToken address. |
_balance | uint256 | The user balance of tokens in the distribution. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The accrued COMP rewards. |
_updateSupplyIndex
Updates the COMP supply index.
function _updateSupplyIndex(address _poolToken) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The cToken address. |
_updateBorrowIndex
Updates the COMP borrow index.
function _updateBorrowIndex(address _poolToken) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The cToken address. |
Errors
OnlyMorpho
ERRORS ///
Thrown when only Morpho can call the function.
error OnlyMorpho();
InvalidCToken
Thrown when an invalid cToken address is passed to claim rewards.
error InvalidCToken();