Track Pool Rewards

Learn how to track rewards accrued from Compound or Aave V2 through Morpho, on-chain via a Smart Contract & off-chain 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

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

Morpho-Compound

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

import {ILens} from "@morpho-org/morpho-v1/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
            );
    }
}

ERC-4626 Vaults

Morpho's vaults are a new way to interact with Morpho according to the ERC-4626 standard. Learn more on the dedicated page.

// 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));
    }
}

Last updated

Logo

This documentation is provided by MorphoLabs, main contributor to Morpho DAO. For any question, reach out.