From 010ecfa776df731906be1087f64c90cd143e0422 Mon Sep 17 00:00:00 2001 From: Lecky Lao Date: Sun, 16 Aug 2020 02:08:35 +1000 Subject: [PATCH 1/5] fixing 1inch compile issue; added curve_testing.sol and got it compiled; --- contracts/connectors/1inch.sol | 4 +- contracts/connectors/curve_vesting.sol | 54 ++++++++++++++++++++++++++ contracts/tests/mockOneProto.sol | 2 +- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 contracts/connectors/curve_vesting.sol diff --git a/contracts/connectors/1inch.sol b/contracts/connectors/1inch.sol index de7e1f8..dcfd1ee 100644 --- a/contracts/connectors/1inch.sol +++ b/contracts/connectors/1inch.sol @@ -74,7 +74,7 @@ contract OneHelpers is Stores, DSMath { /** * @dev Return 1proto Address */ - function getOneProtoAddress() internal view returns (address payable) { + function getOneProtoAddress() virtual internal view returns (address payable) { return payable(OneProtoMappingInterface(getOneProtoMappingAddress()).oneProtoAddress()); } @@ -642,4 +642,4 @@ contract OneInch is OneProto { contract ConnectOne is OneInch { string public name = "1inch-1proto-v1"; -} \ No newline at end of file +} diff --git a/contracts/connectors/curve_vesting.sol b/contracts/connectors/curve_vesting.sol new file mode 100644 index 0000000..a891be6 --- /dev/null +++ b/contracts/connectors/curve_vesting.sol @@ -0,0 +1,54 @@ +pragma solidity ^0.6.0; + +// import files from common directory +import { Stores } from "../common/stores.sol"; +import { DSMath } from "../common/math.sol"; +import { TokenInterface } from "../common/interfaces.sol"; + +interface ICurve { + function claim(address addr) external; +} + +contract CurveVestingHelpers is Stores, DSMath{ + /** + * @dev Return Curve Token Address + */ + function getCurveTokenAddr() internal pure returns (address) { + return 0xD533a949740bb3306d119CC777fa900bA034cd52; + } + + /** + * @dev Return Curve Vesting Address + */ + function getCurveVestingAddr() internal pure returns (address) { + return 0x575CCD8e2D300e2377B43478339E364000318E2c; + } +} + +contract CurveVestingProtocol is CurveVestingHelpers { + event LogClaim(address sender, uint256 claimable, uint256 getId, uint256 setId); + + /** + * @dev Claim Curve DAO Token. + * @param sender address of the sender. + * @param getId Get token amount at this ID from `InstaMemory` Contract. + * @param setId Set token amount at this ID in `InstaMemory` Contract. + */ + function claim(address sender, uint getId, uint setId) external{ + TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); + uint initialCurveBal = curveTokenContract.balanceOf(address(this)); + + ICurve(getCurveVestingAddr()).claim(address(this)); + + uint finalCurveBal = curveTokenContract.balanceOf(address(this)); + + uint claimedAmt = sub(finalCurveBal, initialCurveBal); + + setUint(setId, claimedAmt); + + emit LogClaim(address(this), claimedAmt, getId, setId); + bytes32 _eventCode = keccak256("LogClaim(address,uint256,uint256,uint256)"); + bytes memory _eventParam = abi.encode(address(this), claimedAmt, getId, setId); + emitEvent(_eventCode, _eventParam); + } +} diff --git a/contracts/tests/mockOneProto.sol b/contracts/tests/mockOneProto.sol index 6311279..a645b52 100644 --- a/contracts/tests/mockOneProto.sol +++ b/contracts/tests/mockOneProto.sol @@ -1,7 +1,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; -import { ConnectOne } from "../connectors/1proto.sol"; +import { ConnectOne } from "../connectors/1inch.sol"; contract MockConnectOne is ConnectOne { address public oneProtoAddr; From 6474ee6b632290fe89a3a36b74e9e4122b158646 Mon Sep 17 00:00:00 2001 From: Lecky Lao Date: Sun, 16 Aug 2020 02:42:09 +1000 Subject: [PATCH 2/5] added test for curve_vesting.sol; added MockCurveVesting.sol; --- contracts/connectors/curve_vesting.sol | 9 +++++-- contracts/tests/MockCurveVesting.sol | 24 +++++++++++++++++ test/CurveVestingProtocol.js | 37 ++++++++++++++++++++++++++ test/abi/curveVesting.json | 1 + 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 contracts/tests/MockCurveVesting.sol create mode 100644 test/CurveVestingProtocol.js create mode 100644 test/abi/curveVesting.json diff --git a/contracts/connectors/curve_vesting.sol b/contracts/connectors/curve_vesting.sol index a891be6..b6f1076 100644 --- a/contracts/connectors/curve_vesting.sol +++ b/contracts/connectors/curve_vesting.sol @@ -13,14 +13,14 @@ contract CurveVestingHelpers is Stores, DSMath{ /** * @dev Return Curve Token Address */ - function getCurveTokenAddr() internal pure returns (address) { + function getCurveTokenAddr() virtual internal view returns (address) { return 0xD533a949740bb3306d119CC777fa900bA034cd52; } /** * @dev Return Curve Vesting Address */ - function getCurveVestingAddr() internal pure returns (address) { + function getCurveVestingAddr() virtual internal view returns (address) { return 0x575CCD8e2D300e2377B43478339E364000318E2c; } } @@ -52,3 +52,8 @@ contract CurveVestingProtocol is CurveVestingHelpers { emitEvent(_eventCode, _eventParam); } } + +contract ConnectCurveVestingProtocol is CurveVestingProtocol { + string public name = "Curve-vesting-v1"; +} + diff --git a/contracts/tests/MockCurveVesting.sol b/contracts/tests/MockCurveVesting.sol new file mode 100644 index 0000000..77e07a9 --- /dev/null +++ b/contracts/tests/MockCurveVesting.sol @@ -0,0 +1,24 @@ +pragma solidity ^0.6.0; + +import { ConnectCurveVestingProtocol } from "../connectors/curve_vesting.sol"; + +contract MockConnectCurveVestingProtocol is ConnectCurveVestingProtocol{ + address public curveTokenAddr; + address public curveVestingAddr; + + constructor(address _curveVestingAddr, address _curveTokenAddr) public { + curveVestingAddr = _curveVestingAddr; + curveTokenAddr = _curveTokenAddr; + } + + function getCurveTokenAddr() override internal view returns (address) { + return curveTokenAddr; + } + + function getCurveVestingAddr() override internal view returns (address) { + return curveVestingAddr; + } + + function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {} + function setUint(uint setId, uint val) override internal {} +} diff --git a/test/CurveVestingProtocol.js b/test/CurveVestingProtocol.js new file mode 100644 index 0000000..5c71b0d --- /dev/null +++ b/test/CurveVestingProtocol.js @@ -0,0 +1,37 @@ +const { + BN, // Big Number support + expectEvent, // Assertions for emitted events + expectRevert, // Assertions for transactions that should fail + balance, + ether +} = require('@openzeppelin/test-helpers'); + +const MockContract = artifacts.require("MockContract"); +const MockConnectCurveVestingProtocol = artifacts.require('MockConnectCurveVestingProtocol'); +const erc20ABI = require("./abi/erc20.js"); +const curveVestingABI = require("./abi/curveVesting.json"); + +contract("ConnectCurveVestingProtocol", async accounts => { + const [sender, receiver] = accounts; + let mock, token, curveVesting; + + before(async function(){ + mock = await MockContract.new(); + mockConnectCurveVestingProtocol = await MockConnectCurveVestingProtocol.new(mock.address, mock.address) + token = new web3.eth.Contract(erc20ABI, mock.address); + curveVesting = new web3.eth.Contract(curveVestingABI, mock.address); + + // mocking balanceOf + let balanceOf = await token.methods.balanceOf(mockConnectCurveVestingProtocol.address).encodeABI(); + await mock.givenMethodReturnUint(balanceOf, 10000000); + }) + + it('can claim CRV', async function() { + const tx = await mockConnectCurveVestingProtocol.claim( + sender, + 0, + 0 + ) + expectEvent(tx, "LogClaim"); + }); +}) diff --git a/test/abi/curveVesting.json b/test/abi/curveVesting.json new file mode 100644 index 0000000..e7247a0 --- /dev/null +++ b/test/abi/curveVesting.json @@ -0,0 +1 @@ +[{"name":"Fund","inputs":[{"type":"address","name":"recipient","indexed":true},{"type":"uint256","name":"amount","indexed":false}],"anonymous":false,"type":"event"},{"name":"Claim","inputs":[{"type":"address","name":"recipient","indexed":true},{"type":"uint256","name":"claimed","indexed":false}],"anonymous":false,"type":"event"},{"name":"ToggleDisable","inputs":[{"type":"address","name":"recipient","indexed":false},{"type":"bool","name":"disabled","indexed":false}],"anonymous":false,"type":"event"},{"name":"CommitOwnership","inputs":[{"type":"address","name":"admin","indexed":false}],"anonymous":false,"type":"event"},{"name":"ApplyOwnership","inputs":[{"type":"address","name":"admin","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"address","name":"_token"},{"type":"uint256","name":"_start_time"},{"type":"uint256","name":"_end_time"},{"type":"bool","name":"_can_disable"},{"type":"address[4]","name":"_fund_admins"}],"stateMutability":"nonpayable","type":"constructor"},{"name":"add_tokens","outputs":[],"inputs":[{"type":"uint256","name":"_amount"}],"stateMutability":"nonpayable","type":"function","gas":39108},{"name":"fund","outputs":[],"inputs":[{"type":"address[100]","name":"_recipients"},{"type":"uint256[100]","name":"_amounts"}],"stateMutability":"nonpayable","type":"function","gas":3962646},{"name":"toggle_disable","outputs":[],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"nonpayable","type":"function","gas":40280},{"name":"disable_can_disable","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":21295},{"name":"disable_fund_admins","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":21325},{"name":"vestedSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":4468},{"name":"lockedSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":5465},{"name":"vestedOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"view","type":"function","gas":5163},{"name":"balanceOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"view","type":"function","gas":6275},{"name":"lockedOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"view","type":"function","gas":6305},{"name":"claim","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function"},{"name":"claim","outputs":[],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"commit_transfer_ownership","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":38032},{"name":"apply_transfer_ownership","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":38932},{"name":"token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1601},{"name":"start_time","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1631},{"name":"end_time","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1661},{"name":"initial_locked","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1845},{"name":"total_claimed","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1875},{"name":"initial_locked_supply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1751},{"name":"unallocated_supply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1781},{"name":"can_disable","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1811},{"name":"disabled_at","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1995},{"name":"admin","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1871},{"name":"future_admin","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1901},{"name":"fund_admins_enabled","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1931},{"name":"fund_admins","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2115}] From 522af88811e1320871205b898db5a4b7ef141f74 Mon Sep 17 00:00:00 2001 From: Lecky Lao Date: Sun, 16 Aug 2020 03:03:57 +1000 Subject: [PATCH 3/5] removing sender as not needed --- contracts/connectors/curve_vesting.sol | 5 ++--- test/CurveVestingProtocol.js | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/connectors/curve_vesting.sol b/contracts/connectors/curve_vesting.sol index b6f1076..74bc8cb 100644 --- a/contracts/connectors/curve_vesting.sol +++ b/contracts/connectors/curve_vesting.sol @@ -26,15 +26,14 @@ contract CurveVestingHelpers is Stores, DSMath{ } contract CurveVestingProtocol is CurveVestingHelpers { - event LogClaim(address sender, uint256 claimable, uint256 getId, uint256 setId); + event LogClaim(address account, uint256 claimable, uint256 getId, uint256 setId); /** * @dev Claim Curve DAO Token. - * @param sender address of the sender. * @param getId Get token amount at this ID from `InstaMemory` Contract. * @param setId Set token amount at this ID in `InstaMemory` Contract. */ - function claim(address sender, uint getId, uint setId) external{ + function claim(uint getId, uint setId) external{ TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); uint initialCurveBal = curveTokenContract.balanceOf(address(this)); diff --git a/test/CurveVestingProtocol.js b/test/CurveVestingProtocol.js index 5c71b0d..d1c4351 100644 --- a/test/CurveVestingProtocol.js +++ b/test/CurveVestingProtocol.js @@ -28,7 +28,6 @@ contract("ConnectCurveVestingProtocol", async accounts => { it('can claim CRV', async function() { const tx = await mockConnectCurveVestingProtocol.claim( - sender, 0, 0 ) From 755298095f2cdea04ef19e6ac322a5e9bea02dbb Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Sat, 15 Aug 2020 23:09:09 +0530 Subject: [PATCH 4/5] Minor changes --- contracts/connectors/curve_vesting.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/connectors/curve_vesting.sol b/contracts/connectors/curve_vesting.sol index 74bc8cb..f6e6833 100644 --- a/contracts/connectors/curve_vesting.sol +++ b/contracts/connectors/curve_vesting.sol @@ -52,7 +52,7 @@ contract CurveVestingProtocol is CurveVestingHelpers { } } -contract ConnectCurveVestingProtocol is CurveVestingProtocol { +contract ConnectCurveVesting is CurveVestingProtocol { string public name = "Curve-vesting-v1"; } From 3dcb3bea93d229bda3e9771852c2e0bcae52fa92 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Sun, 16 Aug 2020 02:54:21 +0530 Subject: [PATCH 5/5] minor changes --- contracts/connectors/curve_vesting.sol | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/contracts/connectors/curve_vesting.sol b/contracts/connectors/curve_vesting.sol index f6e6833..2785527 100644 --- a/contracts/connectors/curve_vesting.sol +++ b/contracts/connectors/curve_vesting.sol @@ -9,7 +9,7 @@ interface ICurve { function claim(address addr) external; } -contract CurveVestingHelpers is Stores, DSMath{ +contract CurveVestingHelpers is Stores, DSMath { /** * @dev Return Curve Token Address */ @@ -26,7 +26,7 @@ contract CurveVestingHelpers is Stores, DSMath{ } contract CurveVestingProtocol is CurveVestingHelpers { - event LogClaim(address account, uint256 claimable, uint256 getId, uint256 setId); + event LogClaim(address account, uint256 claimAmount, uint256 getId, uint256 setId); /** * @dev Claim Curve DAO Token. @@ -35,10 +35,9 @@ contract CurveVestingProtocol is CurveVestingHelpers { */ function claim(uint getId, uint setId) external{ TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); + uint initialCurveBal = curveTokenContract.balanceOf(address(this)); - ICurve(getCurveVestingAddr()).claim(address(this)); - uint finalCurveBal = curveTokenContract.balanceOf(address(this)); uint claimedAmt = sub(finalCurveBal, initialCurveBal);