add claim reward in morpho-v3

This commit is contained in:
q1q0 2023-06-23 05:09:36 -04:00
parent 68fd773773
commit 448817d8ea
5 changed files with 62 additions and 9 deletions

View File

@ -16,6 +16,13 @@ contract Events {
uint256 setId
);
event LogClaimedAaveV3(
address[] poolTokenAddresses,
address onBehalf,
address[] rewardTokens,
uint256[] claimedAmounts
);
event LogClaimedCompound(
address[] poolTokenAddresses,
bool tradeForMorphoToken,

View File

@ -11,6 +11,9 @@ abstract contract Helpers is Basic {
IMorphoCore public constant MORPHO_AAVE =
IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
IMorphoCoreV3 public constant MORPHO_AAVE_V3 =
IMorphoCoreV3(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
IMorphoRewardsDistributor public constant MORPHO_REWARDS =
IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135);
}

View File

@ -15,3 +15,10 @@ interface IMorphoRewardsDistributor {
bytes32[] calldata _proof
) external;
}
interface IMorphoCoreV3 {
function claimRewards(
address[] calldata _assets,
address _onBehalf
) external returns (address[] memory _rewardTokens, uint256[] memory _claimedAmounts);
}

View File

@ -100,6 +100,36 @@ abstract contract MorphoRewards is Helpers, Events {
_setId
);
}
/**
* @dev Claim Underlying Pool Rewards.
* @notice Claims rewards for the given assets.
* @param _poolTokenAddresses The assets to claim rewards from (aToken or variable debt token).
* @param _onBehalf The address for which rewards are claimed and sent to.
*/
function claimAaveV3(
address[] calldata _poolTokenAddresses,
address _onBehalf
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
(address[] memory _rewardTokens, uint256[] memory _claimedAmounts) = MORPHO_AAVE_V3.claimRewards(
_poolTokenAddresses,
_onBehalf
);
// setUint(_setId, _amountOfRewards);
_eventName = "LogClaimedAaveV3(address[],address,address[],uint256[])";
_eventParam = abi.encode(
_poolTokenAddresses,
_onBehalf,
_rewardTokens,
_claimedAmounts
);
}
}
contract ConnectV2MorphoRewards is MorphoRewards {

View File

@ -5,7 +5,7 @@ import { addresses } from "../../../scripts/tests/mainnet/addresses";
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { ConnectV3MorphoAaveV3__factory, IERC20Minimal__factory } from "../../../typechain";
import { ConnectV2MorphoAaveV3__factory, IERC20Minimal__factory } from "../../../typechain";
import { parseEther, parseUnits } from "@ethersproject/units";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens";
@ -72,7 +72,7 @@ describe("Morpho-Aave-v3", function () {
);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV3MorphoAaveV3__factory,
contractArtifact: ConnectV2MorphoAaveV3__factory,
signer: masterSigner,
connectors: instaConnectorsV2,
});
@ -267,7 +267,7 @@ describe("Morpho-Aave-v3", function () {
{
connector: connectorName,
method: "withdraw",
args: [tokens.eth.address, "10000000000000000000", dsaWallet0.address, "0", "0"], // 10 ETH
args: [tokens.eth.address, "10000000000000000000", "0", "0"], // 10 ETH
},
];
@ -281,7 +281,10 @@ describe("Morpho-Aave-v3", function () {
);
})
it("Should revert because behalf is different with dsa address", async function () {
it("Should withdraw on behalf of user", async function () {
let ethBala = await ethers.provider.getBalance(user)
let wethBala = await token_weth.balanceOf(user)
const spells = [
{
connector: connectorName,
@ -290,9 +293,13 @@ describe("Morpho-Aave-v3", function () {
},
];
await expect(dsaWallet0
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress())).to.be.revertedWith("cannot convert");
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
ethBala = await ethers.provider.getBalance(user)
wethBala = await token_weth.balanceOf(user)
})
@ -302,7 +309,7 @@ describe("Morpho-Aave-v3", function () {
{
connector: connectorName,
method: "borrow",
args: [tokens.weth.address, "500000000000000000", dsaWallet0.address, "0", "0"], // 0.7 WETH
args: [tokens.weth.address, "500000000000000000", "0", "0"], // 0.7 WETH
},
];
@ -349,7 +356,6 @@ describe("Morpho-Aave-v3", function () {
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString())
expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance))
.to.be.eq(parseUnits('2', 16));
})
@ -410,7 +416,7 @@ describe("Morpho-Aave-v3", function () {
{
connector: connectorName,
method: "borrow",
args: [tokens.eth.address, "1000000000000000", dsaWallet0.address, "0", "0"], // 20 USDC
args: [tokens.eth.address, "1000000000000000", "0", "0"], // 20 USDC
},
{
connector: connectorName,