Skip to main content

Track Pool Rewards

Learn how to track rewards accrued from Compound or Aave V2 through Morpho, onchain via a smart contract & offchain via ethers.js.

Anyone can, at anytime, query Morpho's Lens to get information about the rewards from Compound or Aave V2 accrued with a position on Morpho. Here are concrete examples 👇

Morpho Aave Optimizer Instances​

There are currently no rewards distributed by Aave V2, or Aave V3.

Morpho CompoundV2 Optimizer​

// SPDX-License-Identifier: GNU AGPLv3
pragma solidity ^0.8.16;

import {ILens} from "@morpho-org/morpho-optimizers/contracts/compound/interfaces/ILens.sol";

contract MorphoCompoundSupplier {
address public constant CWBTC = 0xC11b1268C1A384e55C48c2391d8d480264A3A7F4;

address public constant LENS = 0x930f1b46e1D081Ec1524efD95752bE3eCe51EF67;

function getUnclaimedComp() external view returns (uint256) {
address[] memory markets = new address[](1);
markets[0] = CDAI; // the DAI market, represented by the cDAI ERC20 token

return
ILens(LENS).getUserUnclaimedRewards(
markets, // the markets to query unclaimed COMP rewards on
address(this) // the address of the user you want to query unclaimed COMP rewards of
);
}
}

ERC4626 Vaults​

Morpho's vaults are another way to interact with Morpho according to the ERC4626 standard.

// SPDX-License-Identifier: GNU AGPLv3
pragma solidity ^0.8.13;

import {ISupplyVault} from "@morpho-org/morpho-tokenized-vaults/src/compound/interfaces/ISupplyVault.sol";

contract MorphoCompoundVaultSupplier {
address public constant MC_DAI = 0xd99D793B8FDaE42C1867293C172b9CBBD3ea49FF;

/// @notice Returns the amount of rewards this contract accrued through the vault.
/// @return unclaimed The amount of COMP rewards this contract accrued through the vault.
function getUnclaimedRewards() public view returns (uint256 unclaimed) {
(, unclaimed) = ISupplyVault(MC_DAI).userRewards(address(this));
}
}