From 9f8e58496acf4ffc08ae2e7331602bf82ec7a4e8 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Fri, 5 Aug 2022 00:10:29 +0530 Subject: [PATCH 1/4] aave-rewards-optimism --- .../aave/aave-rewards/v3/events.sol | 13 ++++ .../aave/aave-rewards/v3/helpers.sol | 14 ++++ .../aave/aave-rewards/v3/interface.sol | 15 ++++ .../connectors/aave/aave-rewards/v3/main.sol | 78 +++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 contracts/optimism/connectors/aave/aave-rewards/v3/events.sol create mode 100644 contracts/optimism/connectors/aave/aave-rewards/v3/helpers.sol create mode 100644 contracts/optimism/connectors/aave/aave-rewards/v3/interface.sol create mode 100644 contracts/optimism/connectors/aave/aave-rewards/v3/main.sol diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol new file mode 100644 index 00000000..4d91ea53 --- /dev/null +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol @@ -0,0 +1,13 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogClaimed( + address[] assets, + uint256 amt, + uint256 getId, + uint256 setId + ); + + event LogAllClaimed(address[] assets, uint256[] amt); +} diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/helpers.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/helpers.sol new file mode 100644 index 00000000..ff7322a6 --- /dev/null +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/helpers.sol @@ -0,0 +1,14 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { DSMath } from "../../../../common/math.sol"; +import { Basic } from "../../../../common/basic.sol"; +import { AaveIncentivesInterface } from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + /** + * @dev Aave v3 Incentives + */ + AaveIncentivesInterface internal constant incentives = + AaveIncentivesInterface(0x929EC64c34a17401F460460D4B9390518E5B473e); +} diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/interface.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/interface.sol new file mode 100644 index 00000000..f2ab4704 --- /dev/null +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/interface.sol @@ -0,0 +1,15 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface AaveIncentivesInterface { + function claimRewards( + address[] calldata assets, + uint256 amount, + address to, + address reward + ) external returns (uint256); + + function claimAllRewards(address[] calldata assets, address to) + external + returns (address[] memory rewardsList, uint256[] memory claimedAmounts); +} diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol new file mode 100644 index 00000000..f94ba509 --- /dev/null +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol @@ -0,0 +1,78 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +/** + * @title Aave v3 Rewards. + * @dev Claim Aave v3 rewards. + */ + +import { TokenInterface } from "../../../../common/interfaces.sol"; +import { Stores } from "../../../../common/stores.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; + +abstract contract IncentivesResolver is Helpers, Events { + /** + * @dev Claim Pending Rewards. + * @notice Claim Pending Rewards from Aave v3 incentives contract. + * @param assets The list of assets supplied and borrowed. + * @param amt The amount of reward to claim. (uint(-1) for max) + * @param reward The address of reward token to claim. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of rewards claimed. + */ + function claim( + address[] calldata assets, + uint256 amt, + address reward, + uint256 getId, + uint256 setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, amt); + + require(assets.length > 0, "invalid-assets"); + + _amt = incentives.claimRewards(assets, _amt, address(this), reward); + + TokenInterface weth = TokenInterface(wethAddr); + uint256 wethAmount = weth.balanceOf(address(this)); + convertWethToEth(wethAmount > 0, weth, wethAmount); + + setUint(setId, _amt); + + _eventName = "LogClaimed(address[],uint256,uint256,uint256)"; + _eventParam = abi.encode(assets, _amt, getId, setId); + } + + /** + * @dev Claim All Pending Rewards. + * @notice Claim All Pending Rewards from Aave v3 incentives contract. + * @param assets The list of assets supplied and borrowed. + */ + function claimAll(address[] calldata assets) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + require(assets.length > 0, "invalid-assets"); + uint256[] memory _amt = new uint256[](assets.length); + address[] memory _rewards = new address[](assets.length); + + (_rewards, _amt) = incentives.claimAllRewards(assets, address(this)); + + TokenInterface weth = TokenInterface(wethAddr); + uint256 wethAmount = weth.balanceOf(address(this)); + convertWethToEth(wethAmount > 0, weth, wethAmount); + + _eventName = "LogAllClaimed(address[],uint256[])"; + _eventParam = abi.encode(assets, _amt); + } +} + +contract ConnectV3AaveIncentivesOptimism is IncentivesResolver { + string public constant name = "Aave-V3-Incentives-v1"; +} From 4c8f97079c01d1a5a5ae7fd01b07105573d0b184 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Fri, 5 Aug 2022 00:38:52 +0530 Subject: [PATCH 2/4] updated events --- contracts/optimism/connectors/aave/aave-rewards/v3/events.sol | 2 +- contracts/optimism/connectors/aave/aave-rewards/v3/main.sol | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol index 4d91ea53..374c844b 100644 --- a/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol @@ -9,5 +9,5 @@ contract Events { uint256 setId ); - event LogAllClaimed(address[] assets, uint256[] amt); + event LogAllClaimed(address[] assets, address[] rewards, uint256[] amt); } diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol index f94ba509..d885f65f 100644 --- a/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol @@ -68,8 +68,8 @@ abstract contract IncentivesResolver is Helpers, Events { uint256 wethAmount = weth.balanceOf(address(this)); convertWethToEth(wethAmount > 0, weth, wethAmount); - _eventName = "LogAllClaimed(address[],uint256[])"; - _eventParam = abi.encode(assets, _amt); + _eventName = "LogAllClaimed(address[],address[],uint256[])"; + _eventParam = abi.encode(assets, _rewards, _amt); } } From e0d40f6a453be14ca8eb0be24e0ddfddb05f49f3 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Fri, 5 Aug 2022 00:40:38 +0530 Subject: [PATCH 3/4] variable change --- contracts/optimism/connectors/aave/aave-rewards/v3/main.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol index d885f65f..18a6f3d6 100644 --- a/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/main.sol @@ -59,17 +59,17 @@ abstract contract IncentivesResolver is Helpers, Events { returns (string memory _eventName, bytes memory _eventParam) { require(assets.length > 0, "invalid-assets"); - uint256[] memory _amt = new uint256[](assets.length); + uint256[] memory _amts = new uint256[](assets.length); address[] memory _rewards = new address[](assets.length); - (_rewards, _amt) = incentives.claimAllRewards(assets, address(this)); + (_rewards, _amts) = incentives.claimAllRewards(assets, address(this)); TokenInterface weth = TokenInterface(wethAddr); uint256 wethAmount = weth.balanceOf(address(this)); convertWethToEth(wethAmount > 0, weth, wethAmount); _eventName = "LogAllClaimed(address[],address[],uint256[])"; - _eventParam = abi.encode(assets, _rewards, _amt); + _eventParam = abi.encode(assets, _rewards, _amts); } } From 548e8e7773ca8bf876d6f6add1af21f63a06c0b5 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Fri, 5 Aug 2022 00:42:43 +0530 Subject: [PATCH 4/4] Update contracts/optimism/connectors/aave/aave-rewards/v3/events.sol --- contracts/optimism/connectors/aave/aave-rewards/v3/events.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol b/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol index 374c844b..683f3049 100644 --- a/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol +++ b/contracts/optimism/connectors/aave/aave-rewards/v3/events.sol @@ -9,5 +9,5 @@ contract Events { uint256 setId ); - event LogAllClaimed(address[] assets, address[] rewards, uint256[] amt); + event LogAllClaimed(address[] assets, address[] rewards, uint256[] amts); }