RewardsManager

Git Source

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

NameTypeDescription
_morphoaddressThe 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

NameTypeDescription
_poolTokenaddressThe cToken address.

Returns

NameTypeDescription
<none>IComptroller.CompMarketStateThe local COMP supply state.

getLocalCompBorrowState

Returns the local COMP borrow state.

function getLocalCompBorrowState(address _poolToken) external view returns (IComptroller.CompMarketState memory);

Parameters

NameTypeDescription
_poolTokenaddressThe cToken address.

Returns

NameTypeDescription
<none>IComptroller.CompMarketStateThe 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

NameTypeDescription
_poolTokensaddress[]The cToken addresses for which to claim rewards.
_useraddressThe address of the user.

accrueUserSupplyUnclaimedRewards

Updates the unclaimed COMP rewards of the user.

function accrueUserSupplyUnclaimedRewards(address _user, address _poolToken, uint256 _userBalance)
    external
    onlyMorpho;

Parameters

NameTypeDescription
_useraddressThe address of the user.
_poolTokenaddressThe cToken address.
_userBalanceuint256The 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

NameTypeDescription
_useraddressThe address of the user.
_poolTokenaddressThe cToken address.
_userBalanceuint256The 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

NameTypeDescription
_poolTokensaddress[]The cToken addresses for which to accrue rewards.
_useraddressThe address of the user.

Returns

NameTypeDescription
unclaimedRewardsuint256The 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

NameTypeDescription
_supplieraddressThe address of the supplier.
_poolTokenaddressThe cToken address.
_balanceuint256The user balance of tokens in the distribution.

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
_borroweraddressThe address of the borrower.
_poolTokenaddressThe cToken address.
_balanceuint256The user balance of tokens in the distribution.

Returns

NameTypeDescription
<none>uint256The accrued COMP rewards.

_updateSupplyIndex

Updates the COMP supply index.

function _updateSupplyIndex(address _poolToken) internal;

Parameters

NameTypeDescription
_poolTokenaddressThe cToken address.

_updateBorrowIndex

Updates the COMP borrow index.

function _updateBorrowIndex(address _poolToken) internal;

Parameters

NameTypeDescription
_poolTokenaddressThe 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();