Claim Pool Rewards
Learn how to claim rewards accrued through Morpho, onchain via a smart contract & offchain via ethers.js.
Claim rewards accrued from the underlying pool through Morpho, offchain through Etherscan or with ethers.js, or onchain using a smart contract. Here are concrete examples 👇
Morpho AaveV2 Optimizer​
There are currently no rewards distributed by Aave V2.
Morpho CompoundV2 Optimizer​
- Solidity
- ethers.js
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity ^0.8.16;
import {IMorpho} from "@morpho-org/morpho-core-v1/contracts/compound/interfaces/IMorpho.sol";
contract MorphoCompoundRepayer {
address public constant CDAI = 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643;
address public constant CWBTC2 = 0xccF4429DB6322D5C611ee964527D42E5d685DD6a;
address public constant MORPHO = 0x8888882f8f843896699869179fB6E4f7e3B58888;
function claimRewards() public {
address[] memory poolTokens = new address[](2);
poolTokens[0] = CDAI;
poolTokens[1] = CWBTC2;
IMorpho(MORPHO).claimRewards(poolTokens, false);
}
}
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 cEthAddress = "0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5";
const cDaiAddress = "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643";
const morpho = new ethers.Contract(
"0x8888882f8f843896699869179fB6E4f7e3B58888",
[
"function claimRewards(address[], bool) external returns (uint256)",
],
signer
);
async function claimRewards() {
return morpho.claimRewards([cEthAddress, cDaiAddress], false); // signer has received pool rewards accrued through Morpho
}