mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
add claim reward in morpho-v3
This commit is contained in:
parent
68fd773773
commit
448817d8ea
|
@ -16,6 +16,13 @@ contract Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event LogClaimedAaveV3(
|
||||||
|
address[] poolTokenAddresses,
|
||||||
|
address onBehalf,
|
||||||
|
address[] rewardTokens,
|
||||||
|
uint256[] claimedAmounts
|
||||||
|
);
|
||||||
|
|
||||||
event LogClaimedCompound(
|
event LogClaimedCompound(
|
||||||
address[] poolTokenAddresses,
|
address[] poolTokenAddresses,
|
||||||
bool tradeForMorphoToken,
|
bool tradeForMorphoToken,
|
||||||
|
|
|
@ -11,6 +11,9 @@ abstract contract Helpers is Basic {
|
||||||
IMorphoCore public constant MORPHO_AAVE =
|
IMorphoCore public constant MORPHO_AAVE =
|
||||||
IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
|
IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
|
||||||
|
|
||||||
|
IMorphoCoreV3 public constant MORPHO_AAVE_V3 =
|
||||||
|
IMorphoCoreV3(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0);
|
||||||
|
|
||||||
IMorphoRewardsDistributor public constant MORPHO_REWARDS =
|
IMorphoRewardsDistributor public constant MORPHO_REWARDS =
|
||||||
IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135);
|
IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,3 +15,10 @@ interface IMorphoRewardsDistributor {
|
||||||
bytes32[] calldata _proof
|
bytes32[] calldata _proof
|
||||||
) external;
|
) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IMorphoCoreV3 {
|
||||||
|
function claimRewards(
|
||||||
|
address[] calldata _assets,
|
||||||
|
address _onBehalf
|
||||||
|
) external returns (address[] memory _rewardTokens, uint256[] memory _claimedAmounts);
|
||||||
|
}
|
|
@ -100,6 +100,36 @@ abstract contract MorphoRewards is Helpers, Events {
|
||||||
_setId
|
_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 {
|
contract ConnectV2MorphoRewards is MorphoRewards {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
||||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
||||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
|
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 { parseEther, parseUnits } from "@ethersproject/units";
|
||||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
||||||
import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens";
|
import { dsaMaxValue, tokens } from "../../../scripts/tests/mainnet/tokens";
|
||||||
|
@ -72,7 +72,7 @@ describe("Morpho-Aave-v3", function () {
|
||||||
);
|
);
|
||||||
connector = await deployAndEnableConnector({
|
connector = await deployAndEnableConnector({
|
||||||
connectorName,
|
connectorName,
|
||||||
contractArtifact: ConnectV3MorphoAaveV3__factory,
|
contractArtifact: ConnectV2MorphoAaveV3__factory,
|
||||||
signer: masterSigner,
|
signer: masterSigner,
|
||||||
connectors: instaConnectorsV2,
|
connectors: instaConnectorsV2,
|
||||||
});
|
});
|
||||||
|
@ -267,7 +267,7 @@ describe("Morpho-Aave-v3", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "withdraw",
|
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 = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
|
@ -290,9 +293,13 @@ describe("Morpho-Aave-v3", function () {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
await expect(dsaWallet0
|
const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
.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,
|
connector: connectorName,
|
||||||
method: "borrow",
|
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());
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
await tx.wait();
|
||||||
console.log("====================", balance.toString(), (await token_weth.balanceOf(dsaWallet0.address)).toString())
|
|
||||||
expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance))
|
expect((await token_weth.balanceOf(dsaWallet0.address)).sub(balance))
|
||||||
.to.be.eq(parseUnits('2', 16));
|
.to.be.eq(parseUnits('2', 16));
|
||||||
})
|
})
|
||||||
|
@ -410,7 +416,7 @@ describe("Morpho-Aave-v3", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "borrow",
|
method: "borrow",
|
||||||
args: [tokens.eth.address, "1000000000000000", dsaWallet0.address, "0", "0"], // 20 USDC
|
args: [tokens.eth.address, "1000000000000000", "0", "0"], // 20 USDC
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user