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 👇
There are currently no rewards distributed by Aave V2, or Aave V3.
Solidity
ethers.js
// 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
);
}
}
import ethers from "ethers";
const signer = new ethers.Wallet(
process.env.PRIVATE_KEY,
new ethers.providers.JsonRpcBatchProvider(process.env.RPC_URL)
);
const signerAddress = await signer.getAddress();
const cDaiAddress = "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643";
const cCompAddress = "0x70e36f6BF80a52b3B46b3aF8e106CC0ed743E8e4";
const compDecimals = 18;
const lens = new ethers.Contract(
"0x930f1b46e1D081Ec1524efD95752bE3eCe51EF67",
["function getUserUnclaimedRewards(address[] calldata, address) external view returns (uint256)"],
signer
);