From 23c966d2df1d61b025d4d905ac34df79460c0a5c Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Thu, 20 Oct 2022 01:04:55 +0400 Subject: [PATCH 1/4] Rewards contract set up --- .../connectors/morpho-rewards/events.sol | 21 ++++ .../connectors/morpho-rewards/helpers.sol | 16 +++ .../connectors/morpho-rewards/interface.sol | 17 ++++ .../connectors/morpho-rewards/main.sol | 99 +++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 contracts/mainnet/connectors/morpho-rewards/events.sol create mode 100644 contracts/mainnet/connectors/morpho-rewards/helpers.sol create mode 100644 contracts/mainnet/connectors/morpho-rewards/interface.sol create mode 100644 contracts/mainnet/connectors/morpho-rewards/main.sol diff --git a/contracts/mainnet/connectors/morpho-rewards/events.sol b/contracts/mainnet/connectors/morpho-rewards/events.sol new file mode 100644 index 00000000..4a78cd8a --- /dev/null +++ b/contracts/mainnet/connectors/morpho-rewards/events.sol @@ -0,0 +1,21 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +contract Events { + event LogClaimedMorpho(uint256 claimable, bytes32[] proofs); + + event LogClaimedAave( + address[] poolTokenAddresses, + bool tradeForMorphoToken, + uint256 amountOfRewards, + uint256 setId + ); + + event LogClaimedCompound( + address[] poolTokenAddresses, + bool tradeForMorphoToken, + uint256 amountOfRewards, + uint256 setId + ); +} diff --git a/contracts/mainnet/connectors/morpho-rewards/helpers.sol b/contracts/mainnet/connectors/morpho-rewards/helpers.sol new file mode 100644 index 00000000..7cd6799d --- /dev/null +++ b/contracts/mainnet/connectors/morpho-rewards/helpers.sol @@ -0,0 +1,16 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; +import "./interface.sol"; +import { Basic } from "../../common/basic.sol"; + +abstract contract Helpers is Basic { + IMorphoCore public constant MORPHO_COMPOUND = + IMorphoCore(0x8888882f8f843896699869179fB6E4f7e3B58888); + + IMorphoCore public constant MORPHO_AAVE = + IMorphoCore(0x777777c9898D384F785Ee44Acfe945efDFf5f3E0); + + IMorphoRewardsDistributor public constant MORPHO_REWARDS = + IMorphoRewardsDistributor(0x3B14E5C73e0A56D607A8688098326fD4b4292135); +} diff --git a/contracts/mainnet/connectors/morpho-rewards/interface.sol b/contracts/mainnet/connectors/morpho-rewards/interface.sol new file mode 100644 index 00000000..46fefd84 --- /dev/null +++ b/contracts/mainnet/connectors/morpho-rewards/interface.sol @@ -0,0 +1,17 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IMorphoCore { + function claimRewards( + address[] calldata _tokenAddresses, + bool _tradeForMorphoToken + ) external returns (uint256 _claimedAmount); +} + +interface IMorphoRewardsDistributor { + function claim( + address _account, + uint256 _claimable, + bytes32[] calldata _proof + ) external; +} diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol new file mode 100644 index 00000000..1902f1af --- /dev/null +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -0,0 +1,99 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; +import "./helpers.sol"; +import "./events.sol"; + +/** + * @title Morpho Rewards. + * @dev Claim Morpho and Underlying Pool Rewards. + */ + +abstract contract MorphoRewards is Helpers, Events { + /** + * @dev Claim Pending MORPHO Rewards. + * @notice Claims rewards. + * @param _claimable The overall claimable amount of token rewards. + * @param _proofs The merkle proof that validates this claim. + */ + function claimMorpho(uint256 _claimable, bytes32[] calldata _proofs) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + require(_proofs.length > 0, "proofs-empty"); + + MORPHO_REWARDS.claim(address(this), _claimable, _proofs); + + _eventName = "LogClaimedMorpho(uint256,bytes32[])"; + _eventParam = abi.encode(_claimable, _proofs); + } + + /** + * @dev Claim Underlying Pool Rewards. + * @notice Claims rewards for the given assets. + * @param _poolTokenAddresses The cToken addresses to claim rewards from. + * @param _tradeForMorphoToken Whether or not to trade reward tokens for MORPHO tokens. + * @param _setId Set ID for claimed amount(in COMP). + */ + function claimCompound( + address[] calldata _poolTokenAddresses, + bool _tradeForMorphoToken, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amountOfRewards = MORPHO_COMPOUND.claimRewards( + _poolTokenAddresses, + _tradeForMorphoToken + ); + + setUint(_setId, _amountOfRewards); + + _eventName = "LogClaimedCompound(address[],bool,uint256,uint256)"; + _eventParam = abi.encode( + _poolTokenAddresses, + _tradeForMorphoToken, + _amountOfRewards, + _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 _tradeForMorphoToken Whether or not to trade reward tokens for MORPHO tokens. + * @param _setId Set ID for claimed amount(in reward token). + */ + function claimAave( + address[] calldata _poolTokenAddresses, + bool _tradeForMorphoToken, + uint256 _setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amountOfRewards = MORPHO_AAVE.claimRewards( + _poolTokenAddresses, + _tradeForMorphoToken + ); + + setUint(_setId, _amountOfRewards); + + _eventName = "LogClaimedAave(address[],bool,uint256,uint256)"; + _eventParam = abi.encode( + _poolTokenAddresses, + _tradeForMorphoToken, + _amountOfRewards, + _setId + ); + } +} + +contract ConnectV2MorphoCompound is MorphoRewards { + string public constant name = "Morpho-Rewards-v1.0"; +} From 671bf7a7143962879f85ca07714047a4a87e54ea Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Fri, 21 Oct 2022 04:10:04 +0400 Subject: [PATCH 2/4] minor update --- .../mainnet/connectors/morpho-rewards/events.sol | 6 +++++- .../mainnet/connectors/morpho-rewards/main.sol | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-rewards/events.sol b/contracts/mainnet/connectors/morpho-rewards/events.sol index 4a78cd8a..7698318f 100644 --- a/contracts/mainnet/connectors/morpho-rewards/events.sol +++ b/contracts/mainnet/connectors/morpho-rewards/events.sol @@ -3,7 +3,11 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; contract Events { - event LogClaimedMorpho(uint256 claimable, bytes32[] proofs); + event LogClaimedMorpho( + address account, + uint256 claimable, + bytes32[] proof + ); event LogClaimedAave( address[] poolTokenAddresses, diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol index 1902f1af..cf2c53e3 100644 --- a/contracts/mainnet/connectors/morpho-rewards/main.sol +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -13,20 +13,21 @@ abstract contract MorphoRewards is Helpers, Events { /** * @dev Claim Pending MORPHO Rewards. * @notice Claims rewards. + * @param _account The address of the claimer. * @param _claimable The overall claimable amount of token rewards. - * @param _proofs The merkle proof that validates this claim. + * @param _proof The merkle proof that validates this claim. */ - function claimMorpho(uint256 _claimable, bytes32[] calldata _proofs) + function claimMorpho(address _account, uint256 _claimable, bytes32[] calldata _proof) external payable returns (string memory _eventName, bytes memory _eventParam) { - require(_proofs.length > 0, "proofs-empty"); + require(_proof.length > 0, "proofs-empty"); - MORPHO_REWARDS.claim(address(this), _claimable, _proofs); + MORPHO_REWARDS.claim(_account, _claimable, _proof); - _eventName = "LogClaimedMorpho(uint256,bytes32[])"; - _eventParam = abi.encode(_claimable, _proofs); + _eventName = "LogClaimedMorpho(address,uint256,bytes32[])"; + _eventParam = abi.encode(_account, _claimable, _proof); } /** From fbb2c3a8769758251cfd886ff97481c43a24a90e Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sat, 22 Oct 2022 04:33:20 +0400 Subject: [PATCH 3/4] Added setId for claimMorpho --- .../mainnet/connectors/morpho-rewards/events.sol | 3 ++- .../mainnet/connectors/morpho-rewards/main.sol | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-rewards/events.sol b/contracts/mainnet/connectors/morpho-rewards/events.sol index 7698318f..6f57ae99 100644 --- a/contracts/mainnet/connectors/morpho-rewards/events.sol +++ b/contracts/mainnet/connectors/morpho-rewards/events.sol @@ -6,7 +6,8 @@ contract Events { event LogClaimedMorpho( address account, uint256 claimable, - bytes32[] proof + bytes32[] proof, + uint256 setId ); event LogClaimedAave( diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol index cf2c53e3..5a9559bf 100644 --- a/contracts/mainnet/connectors/morpho-rewards/main.sol +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -17,7 +17,12 @@ abstract contract MorphoRewards is Helpers, Events { * @param _claimable The overall claimable amount of token rewards. * @param _proof The merkle proof that validates this claim. */ - function claimMorpho(address _account, uint256 _claimable, bytes32[] calldata _proof) + function claimMorpho( + address _account, + uint256 _claimable, + bytes32[] calldata _proof, + uint256 _setId + ) external payable returns (string memory _eventName, bytes memory _eventParam) @@ -26,8 +31,10 @@ abstract contract MorphoRewards is Helpers, Events { MORPHO_REWARDS.claim(_account, _claimable, _proof); - _eventName = "LogClaimedMorpho(address,uint256,bytes32[])"; - _eventParam = abi.encode(_account, _claimable, _proof); + setUint(_setId, _claimable); + + _eventName = "LogClaimedMorpho(address,uint256,bytes32[],uint256)"; + _eventParam = abi.encode(_account, _claimable, _proof, _setId); } /** @@ -95,6 +102,6 @@ abstract contract MorphoRewards is Helpers, Events { } } -contract ConnectV2MorphoCompound is MorphoRewards { +contract ConnectV2MorphoRewards is MorphoRewards { string public constant name = "Morpho-Rewards-v1.0"; } From 1effd77cc27718b99d81a767001fe0dea004f774 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Tue, 25 Oct 2022 23:01:29 +0530 Subject: [PATCH 4/4] removed proof from event --- contracts/mainnet/connectors/morpho-rewards/events.sol | 1 - contracts/mainnet/connectors/morpho-rewards/main.sol | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/mainnet/connectors/morpho-rewards/events.sol b/contracts/mainnet/connectors/morpho-rewards/events.sol index 6f57ae99..905a08b4 100644 --- a/contracts/mainnet/connectors/morpho-rewards/events.sol +++ b/contracts/mainnet/connectors/morpho-rewards/events.sol @@ -6,7 +6,6 @@ contract Events { event LogClaimedMorpho( address account, uint256 claimable, - bytes32[] proof, uint256 setId ); diff --git a/contracts/mainnet/connectors/morpho-rewards/main.sol b/contracts/mainnet/connectors/morpho-rewards/main.sol index 5a9559bf..f096c6e4 100644 --- a/contracts/mainnet/connectors/morpho-rewards/main.sol +++ b/contracts/mainnet/connectors/morpho-rewards/main.sol @@ -33,8 +33,8 @@ abstract contract MorphoRewards is Helpers, Events { setUint(_setId, _claimable); - _eventName = "LogClaimedMorpho(address,uint256,bytes32[],uint256)"; - _eventParam = abi.encode(_account, _claimable, _proof, _setId); + _eventName = "LogClaimedMorpho(address,uint256,uint256)"; + _eventParam = abi.encode(_account, _claimable, _setId); } /**