From 6c88c0e063d700c1cd6a29a7c05cbcca43faab8b Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sun, 31 Jul 2022 09:02:53 +0400 Subject: [PATCH 1/7] Euler reward claim contracts added --- .../connectors/euler/euler-rewards/events.sol | 13 ++++++ .../euler/euler-rewards/helpers.sol | 13 ++++++ .../euler/euler-rewards/interface.sol | 6 +++ .../connectors/euler/euler-rewards/main.sol | 46 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 contracts/mainnet/connectors/euler/euler-rewards/events.sol create mode 100644 contracts/mainnet/connectors/euler/euler-rewards/helpers.sol create mode 100644 contracts/mainnet/connectors/euler/euler-rewards/interface.sol create mode 100644 contracts/mainnet/connectors/euler/euler-rewards/main.sol diff --git a/contracts/mainnet/connectors/euler/euler-rewards/events.sol b/contracts/mainnet/connectors/euler/euler-rewards/events.sol new file mode 100644 index 00000000..c1f17625 --- /dev/null +++ b/contracts/mainnet/connectors/euler/euler-rewards/events.sol @@ -0,0 +1,13 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogClaimed( + address user, + address token, + uint256 amt, + bytes32[] proof, + uint256 getId, + uint256 setId + ); +} diff --git a/contracts/mainnet/connectors/euler/euler-rewards/helpers.sol b/contracts/mainnet/connectors/euler/euler-rewards/helpers.sol new file mode 100644 index 00000000..b056659a --- /dev/null +++ b/contracts/mainnet/connectors/euler/euler-rewards/helpers.sol @@ -0,0 +1,13 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +import "./interface.sol"; +import { Basic } from "../../../common/basic.sol"; + +contract Helpers is Basic { + + /** + * @dev Euler Incentives Distributor + */ + IEulerDistributor internal constant eulerDistribute = IEulerDistributor(0xd524E29E3BAF5BB085403Ca5665301E94387A7e2); + +} diff --git a/contracts/mainnet/connectors/euler/euler-rewards/interface.sol b/contracts/mainnet/connectors/euler/euler-rewards/interface.sol new file mode 100644 index 00000000..59aab085 --- /dev/null +++ b/contracts/mainnet/connectors/euler/euler-rewards/interface.sol @@ -0,0 +1,6 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IEulerDistributor { + function claim(address account, address token, uint claimable, bytes32[] calldata proof, address stake) external; +} diff --git a/contracts/mainnet/connectors/euler/euler-rewards/main.sol b/contracts/mainnet/connectors/euler/euler-rewards/main.sol new file mode 100644 index 00000000..d3d9e66a --- /dev/null +++ b/contracts/mainnet/connectors/euler/euler-rewards/main.sol @@ -0,0 +1,46 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +import "./helpers.sol"; +import "./events.sol"; + +/** + * @title Euler Rewards. + * @dev Claim Euler rewards. + */ + +contract EulerIncentives is Helpers, Events { + + /** + * @dev Claim Pending Rewards. + * @notice Claim Pending Rewards from Euler incentives contract. + * @param user Address that should receive tokens. + * @param token Address of token being claimed (ie EUL) + * @param amt The amount of reward to claim. + * @param proof Merkle proof that validates this claim. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of rewards claimed. + */ + function claim( + address user, + address token, + uint256 amt, + bytes32[] memory proof, + uint256 getId, + uint256 setId + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + + require(proof.length > 0, "invalid-assets"); + + eulerDistribute.claim(user, token, _amt, proof, address(0)); + + setUint(setId, _amt); + + _eventName = "LogClaimed(address,address,uint256,bytes32[],uint256,uint256)"; + _eventParam = abi.encode(user, token, _amt, proof, getId, setId); + } +} + +contract ConnectV2EulereIncentives is EulerIncentives { + string public constant name = "Euler-Incentives-v1"; +} From dcc54217f6b1f62e72235e5244ae2610a42d0089 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sun, 31 Jul 2022 09:03:20 +0400 Subject: [PATCH 2/7] added testcases --- .../euler-rewards/euler-rewards.test.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/mainnet/euler-rewards/euler-rewards.test.ts diff --git a/test/mainnet/euler-rewards/euler-rewards.test.ts b/test/mainnet/euler-rewards/euler-rewards.test.ts new file mode 100644 index 00000000..0c707a0b --- /dev/null +++ b/test/mainnet/euler-rewards/euler-rewards.test.ts @@ -0,0 +1,73 @@ +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { ethers } from "hardhat"; +import { ConnectV2EulereIncentives, ConnectV2EulereIncentives__factory } from "../../../typechain"; +import hre from "hardhat"; + +describe("Euler Rewards Claim Test", () => { + let signer: SignerWithAddress; + let signer_user: any; + const user = "0x9F60699cE23f1Ab86Ec3e095b477Ff79d4f409AD"; + const EUL = "0xd9Fcd98c322942075A5C3860693e9f4f03AAE07b"; + + before(async () => { + [signer] = await ethers.getSigners(); + }); + + describe("Euler Functions", () => { + let contract: ConnectV2EulereIncentives; + + before(async () => { + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + blockNumber: 15247044, + }, + }, + ], + }); + + const deployer = new ConnectV2EulereIncentives__factory(signer); + contract = await deployer.deploy(); + await contract.deployed(); + console.log("Contract deployed at: ", contract.address); + + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [user], + }) + + signer_user = await ethers.getSigner(user) + }); + + it("Returns the positions on Euler", async () => { + let response = await contract + .connect(signer_user) + .claim( + user, + EUL, + "459635735326895", + ["0x7289f1c53c25e201538b91f7f6582388677bd6ff2fca03082267dbb1d96258ac", + '0xc85ccc67cd68d38b0da6eec50c3c897757832450e22ca103543589fb610b79ee', + '0x7e57faa32389a498f27187bc1c8ebb993a2065f019e3840cf36d599866ea5504', + '0x38aae0a5be3e76eef383cc55c48d029acb1c6c4ed91c8385a501c1cc8c2031ca', + '0x8bfd0363720bf2e5671b2689adbf667b74e47be7a5e91d36c3bdb24e4abad4f4', + '0xc23081eb1f3001535376d454a070abd67a27de6f3db68089568cf981adeb480f', + '0x8356b1a7033ff341b75749de37aab0d3a6a9420f20c03b9e07d0f7d3d1840753', + '0x4300ab0ed87f84baa140f31113e2eee8d20dea7d7ff7848cf6806ecd8067b1c9', + '0x83248015245f51e6d42021617415097cde157288d1c1de17f4de5fcbbd97b70e', + '0x785649546b18cad99c2aea8d889689b5b2d4fabc15e6a9ea1ff2b9310beebc44', + '0x310fdf199874bf9f992c02125278b4592bec5cd5ad1ee30fac130fa2b9ffc0ae', + '0x6d0a8568a994d5b8a356cf1a933ff8f5c195ea72f0f213f38a08ff3d87b3c4da' + ], + "0", + "0" + ) + console.log(response); + }); + }); +}); From be3d76d71e1232fe500df160045bb4ec47107ad3 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi <47134275+shriyatyagii@users.noreply.github.com> Date: Sun, 31 Jul 2022 22:27:12 +0400 Subject: [PATCH 3/7] Update contracts/mainnet/connectors/euler/euler-rewards/main.sol Co-authored-by: Thrilok kumar --- contracts/mainnet/connectors/euler/euler-rewards/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/euler/euler-rewards/main.sol b/contracts/mainnet/connectors/euler/euler-rewards/main.sol index d3d9e66a..f2c5cd6c 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/main.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/main.sol @@ -30,7 +30,7 @@ contract EulerIncentives is Helpers, Events { ) external payable returns (string memory _eventName, bytes memory _eventParam) { uint _amt = getUint(getId, amt); - require(proof.length > 0, "invalid-assets"); + require(proof.length > 0, "proofs-empty"); eulerDistribute.claim(user, token, _amt, proof, address(0)); From 2bc364f6322ab2b5cfa4b7240221a7c122db9c01 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sun, 31 Jul 2022 22:30:15 +0400 Subject: [PATCH 4/7] Removed proof from events --- contracts/mainnet/connectors/euler/euler-rewards/events.sol | 1 - contracts/mainnet/connectors/euler/euler-rewards/main.sol | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/mainnet/connectors/euler/euler-rewards/events.sol b/contracts/mainnet/connectors/euler/euler-rewards/events.sol index c1f17625..e0d702e8 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/events.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/events.sol @@ -6,7 +6,6 @@ contract Events { address user, address token, uint256 amt, - bytes32[] proof, uint256 getId, uint256 setId ); diff --git a/contracts/mainnet/connectors/euler/euler-rewards/main.sol b/contracts/mainnet/connectors/euler/euler-rewards/main.sol index d3d9e66a..9d7c0c7a 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/main.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/main.sol @@ -36,8 +36,8 @@ contract EulerIncentives is Helpers, Events { setUint(setId, _amt); - _eventName = "LogClaimed(address,address,uint256,bytes32[],uint256,uint256)"; - _eventParam = abi.encode(user, token, _amt, proof, getId, setId); + _eventName = "LogClaimed(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode(user, token, _amt, getId, setId); } } From 472ddf20abd26792083adc45fc96524bcf6c6a7b Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 1 Aug 2022 00:58:41 +0400 Subject: [PATCH 5/7] getId removed --- .../mainnet/connectors/euler/euler-rewards/events.sol | 1 - .../mainnet/connectors/euler/euler-rewards/main.sol | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/contracts/mainnet/connectors/euler/euler-rewards/events.sol b/contracts/mainnet/connectors/euler/euler-rewards/events.sol index e0d702e8..7c32023d 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/events.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/events.sol @@ -6,7 +6,6 @@ contract Events { address user, address token, uint256 amt, - uint256 getId, uint256 setId ); } diff --git a/contracts/mainnet/connectors/euler/euler-rewards/main.sol b/contracts/mainnet/connectors/euler/euler-rewards/main.sol index 3062c0bf..60cba7ea 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/main.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/main.sol @@ -17,7 +17,6 @@ contract EulerIncentives is Helpers, Events { * @param token Address of token being claimed (ie EUL) * @param amt The amount of reward to claim. * @param proof Merkle proof that validates this claim. - * @param getId ID to retrieve amt. * @param setId ID stores the amount of rewards claimed. */ function claim( @@ -25,19 +24,16 @@ contract EulerIncentives is Helpers, Events { address token, uint256 amt, bytes32[] memory proof, - uint256 getId, uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _amt = getUint(getId, amt); - require(proof.length > 0, "proofs-empty"); - eulerDistribute.claim(user, token, _amt, proof, address(0)); + eulerDistribute.claim(user, token, amt, proof, address(0)); - setUint(setId, _amt); + setUint(setId, amt); _eventName = "LogClaimed(address,address,uint256,uint256,uint256)"; - _eventParam = abi.encode(user, token, _amt, getId, setId); + _eventParam = abi.encode(user, token, amt, setId); } } From 984f06531e5763ffef4f60173db6544f2f81a049 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Mon, 1 Aug 2022 12:51:31 +0530 Subject: [PATCH 6/7] Update contracts/mainnet/connectors/euler/euler-rewards/main.sol --- contracts/mainnet/connectors/euler/euler-rewards/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/euler/euler-rewards/main.sol b/contracts/mainnet/connectors/euler/euler-rewards/main.sol index 60cba7ea..61bf0d1c 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/main.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/main.sol @@ -32,7 +32,7 @@ contract EulerIncentives is Helpers, Events { setUint(setId, amt); - _eventName = "LogClaimed(address,address,uint256,uint256,uint256)"; + _eventName = "LogClaimed(address,address,uint256,uint256)"; _eventParam = abi.encode(user, token, amt, setId); } } From 8d0e64b826c55172fd99ae853c4e1482833fd69e Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 1 Aug 2022 20:04:19 +0400 Subject: [PATCH 7/7] spelling fix --- contracts/mainnet/connectors/euler/euler-rewards/main.sol | 2 +- test/mainnet/euler-rewards/euler-rewards.test.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/contracts/mainnet/connectors/euler/euler-rewards/main.sol b/contracts/mainnet/connectors/euler/euler-rewards/main.sol index 61bf0d1c..457e02a0 100644 --- a/contracts/mainnet/connectors/euler/euler-rewards/main.sol +++ b/contracts/mainnet/connectors/euler/euler-rewards/main.sol @@ -37,6 +37,6 @@ contract EulerIncentives is Helpers, Events { } } -contract ConnectV2EulereIncentives is EulerIncentives { +contract ConnectV2EulerIncentives is EulerIncentives { string public constant name = "Euler-Incentives-v1"; } diff --git a/test/mainnet/euler-rewards/euler-rewards.test.ts b/test/mainnet/euler-rewards/euler-rewards.test.ts index 0c707a0b..e5634198 100644 --- a/test/mainnet/euler-rewards/euler-rewards.test.ts +++ b/test/mainnet/euler-rewards/euler-rewards.test.ts @@ -1,6 +1,6 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { ethers } from "hardhat"; -import { ConnectV2EulereIncentives, ConnectV2EulereIncentives__factory } from "../../../typechain"; +import { ConnectV2EulerIncentives, ConnectV2EulerIncentives__factory } from "../../../typechain"; import hre from "hardhat"; describe("Euler Rewards Claim Test", () => { @@ -14,7 +14,7 @@ describe("Euler Rewards Claim Test", () => { }); describe("Euler Functions", () => { - let contract: ConnectV2EulereIncentives; + let contract: ConnectV2EulerIncentives; before(async () => { await hre.network.provider.request({ @@ -31,7 +31,7 @@ describe("Euler Rewards Claim Test", () => { ], }); - const deployer = new ConnectV2EulereIncentives__factory(signer); + const deployer = new ConnectV2EulerIncentives__factory(signer); contract = await deployer.deploy(); await contract.deployed(); console.log("Contract deployed at: ", contract.address); @@ -64,7 +64,6 @@ describe("Euler Rewards Claim Test", () => { '0x310fdf199874bf9f992c02125278b4592bec5cd5ad1ee30fac130fa2b9ffc0ae', '0x6d0a8568a994d5b8a356cf1a933ff8f5c195ea72f0f213f38a08ff3d87b3c4da' ], - "0", "0" ) console.log(response);