mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Merge pull request #18 from InstaDApp/curve-vesting-connector-feature
Curve vesting connector feature
This commit is contained in:
commit
061c12a7ce
57
contracts/connectors/curve_vesting.sol
Normal file
57
contracts/connectors/curve_vesting.sol
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
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() virtual internal view returns (address) {
|
||||||
|
return 0xD533a949740bb3306d119CC777fa900bA034cd52;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Return Curve Vesting Address
|
||||||
|
*/
|
||||||
|
function getCurveVestingAddr() virtual internal view returns (address) {
|
||||||
|
return 0x575CCD8e2D300e2377B43478339E364000318E2c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract CurveVestingProtocol is CurveVestingHelpers {
|
||||||
|
event LogClaim(address account, uint256 claimAmount, uint256 getId, uint256 setId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Claim Curve DAO Token.
|
||||||
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectCurveVesting is CurveVestingProtocol {
|
||||||
|
string public name = "Curve-vesting-v1";
|
||||||
|
}
|
||||||
|
|
24
contracts/tests/MockCurveVesting.sol
Normal file
24
contracts/tests/MockCurveVesting.sol
Normal file
|
@ -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 {}
|
||||||
|
}
|
36
test/CurveVestingProtocol.js
Normal file
36
test/CurveVestingProtocol.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
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(
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogClaim");
|
||||||
|
});
|
||||||
|
})
|
1
test/abi/curveVesting.json
Normal file
1
test/abi/curveVesting.json
Normal file
|
@ -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}]
|
Loading…
Reference in New Issue
Block a user