mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Merge pull request #19 from InstaDApp/curve-gauge-connector-feature
adding curve gauge connector
This commit is contained in:
commit
c08f9cc73d
241
contracts/connectors/curve_gauge.sol
Normal file
241
contracts/connectors/curve_gauge.sol
Normal file
|
|
@ -0,0 +1,241 @@
|
||||||
|
pragma solidity ^0.6.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
// import files from common directory
|
||||||
|
import { Stores } from "../common/stores.sol";
|
||||||
|
import { DSMath } from "../common/math.sol";
|
||||||
|
import { TokenInterface } from "../common/interfaces.sol";
|
||||||
|
|
||||||
|
interface IGauge {
|
||||||
|
function claim_rewards() external;
|
||||||
|
function deposit(uint256 value) external;
|
||||||
|
function withdraw(uint256 value) external;
|
||||||
|
function lp_token() external view returns(address token);
|
||||||
|
function rewarded_token() external view returns(address token);
|
||||||
|
function crv_token() external view returns(address token);
|
||||||
|
function balanceOf(address user) external view returns(uint256 amt);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IMintor{
|
||||||
|
function mint(address gauge) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ICurveGaugeMapping {
|
||||||
|
|
||||||
|
struct GaugeData {
|
||||||
|
address gaugeAddress;
|
||||||
|
bool rewardToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
function gaugeMapping(bytes32) external view returns(GaugeData memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract GaugeHelper is DSMath, Stores{
|
||||||
|
function getCurveGaugeMappingAddr() internal virtual view returns (address){
|
||||||
|
return 0x1C800eF1bBfE3b458969226A96c56B92a069Cc92;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurveMintorAddr() internal virtual view returns (address){
|
||||||
|
return 0xd061D61a4d941c39E5453435B6345Dc261C2fcE0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Convert String to bytes32.
|
||||||
|
*/
|
||||||
|
function stringToBytes32(string memory str) internal pure returns (bytes32 result) {
|
||||||
|
require(bytes(str).length != 0, "string-empty");
|
||||||
|
// solium-disable-next-line security/no-inline-assembly
|
||||||
|
assembly {
|
||||||
|
result := mload(add(str, 32))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract CurveGaugeEvent is GaugeHelper {
|
||||||
|
event LogDeposit(
|
||||||
|
string indexed gaugePoolName,
|
||||||
|
uint amount,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdraw(
|
||||||
|
string indexed gaugePoolName,
|
||||||
|
uint amount,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogClaimedReward(
|
||||||
|
string indexed gaugePoolName,
|
||||||
|
uint amount,
|
||||||
|
uint rewardAmt,
|
||||||
|
uint setId,
|
||||||
|
uint setIdReward
|
||||||
|
);
|
||||||
|
|
||||||
|
function emitLogWithdraw(string memory gaugePoolName, uint _amt, uint getId, uint setId) internal {
|
||||||
|
emit LogWithdraw(gaugePoolName, _amt, getId, setId);
|
||||||
|
bytes32 _eventCodeWithdraw = keccak256("LogWithdraw(string,uint256,uint256,uint256)");
|
||||||
|
bytes memory _eventParamWithdraw = abi.encode(gaugePoolName, _amt, getId, setId);
|
||||||
|
emitEvent(_eventCodeWithdraw, _eventParamWithdraw);
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitLogClaimedReward(string memory gaugePoolName, uint crvAmt, uint rewardAmt, uint setIdCrv, uint setIdReward) internal {
|
||||||
|
emit LogClaimedReward(gaugePoolName, crvAmt, rewardAmt, setIdCrv, setIdReward);
|
||||||
|
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256,uint256,uint256)");
|
||||||
|
bytes memory _eventParam = abi.encode(gaugePoolName, crvAmt, rewardAmt, setIdCrv, setIdReward);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract CurveGauge is CurveGaugeEvent {
|
||||||
|
struct Balances{
|
||||||
|
uint intialCRVBal;
|
||||||
|
uint intialRewardBal;
|
||||||
|
uint finalCRVBal;
|
||||||
|
uint finalRewardBal;
|
||||||
|
uint crvRewardAmt;
|
||||||
|
uint rewardAmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit Cruve LP Token.
|
||||||
|
* @param gaugePoolName Curve gauge pool name.
|
||||||
|
* @param amt deposit amount.
|
||||||
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
function deposit(
|
||||||
|
string calldata gaugePoolName,
|
||||||
|
uint amt,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
) external payable {
|
||||||
|
uint _amt = getUint(getId, amt);
|
||||||
|
ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr());
|
||||||
|
ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping(
|
||||||
|
bytes32(stringToBytes32(gaugePoolName)
|
||||||
|
));
|
||||||
|
require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name");
|
||||||
|
IGauge gauge = IGauge(curveGaugeData.gaugeAddress);
|
||||||
|
TokenInterface lp_token = TokenInterface(address(gauge.lp_token()));
|
||||||
|
|
||||||
|
_amt = _amt == uint(-1) ? lp_token.balanceOf(address(this)) : _amt;
|
||||||
|
lp_token.approve(address(curveGaugeData.gaugeAddress), _amt);
|
||||||
|
|
||||||
|
gauge.deposit(_amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
emit LogDeposit(gaugePoolName, _amt, getId, setId);
|
||||||
|
bytes32 _eventCode = keccak256("LogDeposit(string,uint256,uint256,uint256)");
|
||||||
|
bytes memory _eventParam = abi.encode(gaugePoolName, _amt, getId, setId);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw LP Token and claim both CRV and Reward token.
|
||||||
|
* @param gaugePoolName gauge pool name.
|
||||||
|
* @param amt LP token amount.
|
||||||
|
* @param getId Get LP token amount at this ID from `InstaMemory` Contract.
|
||||||
|
* @param setId Set LP token amount at this ID in `InstaMemory` Contract.
|
||||||
|
* @param setIdCrv Set CRV token reward amount at this ID in `InstaMemory` Contract.
|
||||||
|
* @param setIdReward Set reward amount at this ID in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
function withdraw(
|
||||||
|
string calldata gaugePoolName,
|
||||||
|
uint amt,
|
||||||
|
uint getId,
|
||||||
|
uint setId,
|
||||||
|
uint setIdCrv,
|
||||||
|
uint setIdReward
|
||||||
|
) external payable {
|
||||||
|
uint _amt = getUint(getId, amt);
|
||||||
|
ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr());
|
||||||
|
ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping(
|
||||||
|
bytes32(stringToBytes32(gaugePoolName))
|
||||||
|
);
|
||||||
|
require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name");
|
||||||
|
IGauge gauge = IGauge(curveGaugeData.gaugeAddress);
|
||||||
|
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
||||||
|
TokenInterface rewarded_token;
|
||||||
|
Balances memory balances;
|
||||||
|
|
||||||
|
_amt = _amt == uint(-1) ? gauge.balanceOf(address(this)) : _amt;
|
||||||
|
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
||||||
|
|
||||||
|
if (curveGaugeData.rewardToken) {
|
||||||
|
rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
||||||
|
balances.intialRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
IMintor(getCurveMintorAddr()).mint(curveGaugeData.gaugeAddress);
|
||||||
|
gauge.withdraw(_amt);
|
||||||
|
|
||||||
|
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
||||||
|
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
setUint(setIdCrv, balances.crvRewardAmt);
|
||||||
|
|
||||||
|
if (curveGaugeData.rewardToken) {
|
||||||
|
balances.finalRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
|
balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal);
|
||||||
|
setUint(setIdReward, balances.rewardAmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
emitLogWithdraw(gaugePoolName, _amt, getId, setId);
|
||||||
|
emitLogClaimedReward(gaugePoolName, balances.crvRewardAmt, balances.rewardAmt, setIdCrv, setIdReward);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Claim CRV Reward with Staked Reward token
|
||||||
|
* @param gaugePoolName gauge pool name.
|
||||||
|
* @param setId Set CRV reward amount at this ID in `InstaMemory` Contract.
|
||||||
|
* @param setIdReward Set token reward amount at this ID in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
function claimReward(
|
||||||
|
string calldata gaugePoolName,
|
||||||
|
uint setId,
|
||||||
|
uint setIdReward
|
||||||
|
) external payable {
|
||||||
|
ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr());
|
||||||
|
ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping(
|
||||||
|
bytes32(stringToBytes32(gaugePoolName))
|
||||||
|
);
|
||||||
|
require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name");
|
||||||
|
IMintor mintor = IMintor(getCurveMintorAddr());
|
||||||
|
IGauge gauge = IGauge(curveGaugeData.gaugeAddress);
|
||||||
|
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
||||||
|
TokenInterface rewarded_token;
|
||||||
|
Balances memory balances;
|
||||||
|
|
||||||
|
if (curveGaugeData.rewardToken) {
|
||||||
|
rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
||||||
|
balances.intialRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
||||||
|
|
||||||
|
mintor.mint(curveGaugeData.gaugeAddress);
|
||||||
|
|
||||||
|
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
||||||
|
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
||||||
|
|
||||||
|
setUint(setId, balances.crvRewardAmt);
|
||||||
|
|
||||||
|
if(curveGaugeData.rewardToken){
|
||||||
|
balances.finalRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
|
balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal);
|
||||||
|
setUint(setIdReward, balances.rewardAmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
emitLogClaimedReward(gaugePoolName, balances.crvRewardAmt, balances.rewardAmt, setId, setIdReward);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectCurveGauge is CurveGauge {
|
||||||
|
string public name = "Curve-Gauge-v1.0";
|
||||||
|
}
|
||||||
|
|
||||||
109
contracts/mapping/curve_gauge_mapping.sol
Normal file
109
contracts/mapping/curve_gauge_mapping.sol
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
pragma solidity ^0.6.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
interface ConnectorsInterface {
|
||||||
|
function chief(address) external view returns (bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IndexInterface {
|
||||||
|
function master() external view returns (address);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract BytesHelper {
|
||||||
|
/**
|
||||||
|
* @dev Convert String to bytes32.
|
||||||
|
*/
|
||||||
|
function stringToBytes32(string memory str) internal pure returns (bytes32 result) {
|
||||||
|
require(bytes(str).length != 0, "String-Empty");
|
||||||
|
// solium-disable-next-line security/no-inline-assembly
|
||||||
|
assembly {
|
||||||
|
result := mload(add(str, 32))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Helpers is BytesHelper {
|
||||||
|
address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c;
|
||||||
|
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
||||||
|
uint public version = 1;
|
||||||
|
|
||||||
|
mapping (bytes32 => GaugeData) public gaugeMapping;
|
||||||
|
|
||||||
|
struct GaugeData {
|
||||||
|
address gaugeAddress;
|
||||||
|
bool rewardToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
event LogAddGaugeMapping(
|
||||||
|
string gaugeName,
|
||||||
|
address gaugeAddress,
|
||||||
|
bool rewardToken
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogRemoveGaugeMapping(
|
||||||
|
string gaugeName,
|
||||||
|
address gaugeAddress
|
||||||
|
);
|
||||||
|
|
||||||
|
modifier isChief virtual {
|
||||||
|
require(
|
||||||
|
ConnectorsInterface(connectors).chief(msg.sender) ||
|
||||||
|
IndexInterface(instaIndex).master() == msg.sender, "not-Chief");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _addGaugeMapping(
|
||||||
|
string memory gaugeName,
|
||||||
|
address gaugeAddress,
|
||||||
|
bool rewardToken
|
||||||
|
) internal {
|
||||||
|
require(gaugeAddress != address(0), "gaugeAddress-not-vaild");
|
||||||
|
require(bytes(gaugeName).length <= 32, "Length-exceeds");
|
||||||
|
bytes32 gaugeType = stringToBytes32(gaugeName);
|
||||||
|
require(gaugeMapping[gaugeType].gaugeAddress == address(0), "gaugePool-already-added");
|
||||||
|
|
||||||
|
gaugeMapping[gaugeType].gaugeAddress = gaugeAddress;
|
||||||
|
gaugeMapping[gaugeType].rewardToken = rewardToken;
|
||||||
|
|
||||||
|
emit LogAddGaugeMapping(gaugeName, gaugeAddress, rewardToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addGaugeMappings(
|
||||||
|
string[] memory gaugeNames,
|
||||||
|
address[] memory gaugeAddresses,
|
||||||
|
bool[] memory rewardTokens
|
||||||
|
) public isChief {
|
||||||
|
require(gaugeNames.length == gaugeAddresses.length && gaugeAddresses.length == rewardTokens.length, "length-not-match");
|
||||||
|
for (uint32 i; i < gaugeNames.length; i++) {
|
||||||
|
_addGaugeMapping(gaugeNames[i], gaugeAddresses[i], rewardTokens[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeGaugeMapping(string memory gaugeName, address gaugeAddress) public isChief {
|
||||||
|
require(gaugeAddress != address(0), "gaugeAddress-not-vaild");
|
||||||
|
bytes32 gaugeType = stringToBytes32(gaugeName);
|
||||||
|
require(gaugeMapping[gaugeType].gaugeAddress == gaugeAddress, "different-gauge-pool");
|
||||||
|
|
||||||
|
delete gaugeMapping[gaugeType];
|
||||||
|
|
||||||
|
emit LogRemoveGaugeMapping(
|
||||||
|
gaugeName,
|
||||||
|
gaugeAddress
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract CurveGaugeMapping is Helpers {
|
||||||
|
string constant public name = "Curve-Gauge-Mapping-v1";
|
||||||
|
|
||||||
|
constructor (
|
||||||
|
string[] memory gaugeNames,
|
||||||
|
address[] memory gaugeAddresses,
|
||||||
|
bool[] memory rewardTokens
|
||||||
|
) public {
|
||||||
|
require(gaugeNames.length == gaugeAddresses.length && gaugeAddresses.length == rewardTokens.length, "length-not-match");
|
||||||
|
for (uint32 i; i < gaugeNames.length; i++) {
|
||||||
|
_addGaugeMapping(gaugeNames[i], gaugeAddresses[i], rewardTokens[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -40,6 +40,7 @@ contract BytesHelper {
|
||||||
return (string(bytesArray));
|
return (string(bytesArray));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract Helpers is BytesHelper {
|
contract Helpers is BytesHelper {
|
||||||
address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c;
|
address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c;
|
||||||
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
||||||
|
|
@ -113,7 +114,6 @@ contract Helpers is BytesHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract InstaStakingMapping is Helpers {
|
contract InstaStakingMapping is Helpers {
|
||||||
string constant public name = "Staking-Mapping-v1";
|
string constant public name = "Staking-Mapping-v1";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
contracts/tests/MockCurveGauge.sol
Normal file
27
contracts/tests/MockCurveGauge.sol
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
pragma solidity ^0.6.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { ConnectCurveGauge } from "../connectors/curve_gauge.sol";
|
||||||
|
|
||||||
|
contract MockCurveGauge is ConnectCurveGauge{
|
||||||
|
address public curveMintorAddr;
|
||||||
|
address public curveGaugeMappingAddr;
|
||||||
|
|
||||||
|
constructor(address _curveMintorAddr, address _curveGaugeMappingAddr) public {
|
||||||
|
curveMintorAddr = _curveMintorAddr;
|
||||||
|
curveGaugeMappingAddr = _curveGaugeMappingAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {}
|
||||||
|
|
||||||
|
function getCurveGaugeMappingAddr() override internal view returns (address) {
|
||||||
|
return curveGaugeMappingAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurveMintorAddr() override internal view returns (address) {
|
||||||
|
return curveMintorAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setUint(uint setId, uint val) override internal {}
|
||||||
|
}
|
||||||
|
|
||||||
14
contracts/tests/MockCurveGaugeMapping.sol
Normal file
14
contracts/tests/MockCurveGaugeMapping.sol
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
pragma solidity ^0.6.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { CurveGaugeMapping } from "../mapping/curve_gauge_mapping.sol";
|
||||||
|
|
||||||
|
contract MockCurveGaugeMapping is CurveGaugeMapping {
|
||||||
|
constructor(
|
||||||
|
string[] memory gaugeNames,
|
||||||
|
address[] memory gaugeAddresses,
|
||||||
|
bool[] memory rewardTokens
|
||||||
|
) public CurveGaugeMapping(gaugeNames, gaugeAddresses, rewardTokens) {
|
||||||
|
}
|
||||||
|
modifier isChief override {_;}
|
||||||
|
}
|
||||||
157
test/CurveGauge.js
Normal file
157
test/CurveGauge.js
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
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 MockCurveGauge = artifacts.require('MockCurveGauge');
|
||||||
|
const MockCurveGaugeMapping = artifacts.require('MockCurveGaugeMapping');
|
||||||
|
const erc20ABI = require("./abi/erc20.js");
|
||||||
|
const gaugeABI = require("./abi/curveGauge.json");
|
||||||
|
|
||||||
|
contract("ConnectCurveGauge", async accounts => {
|
||||||
|
const [sender, receiver] = accounts;
|
||||||
|
let mock, mockCurveGauge, mockCurveGaugeMapping;
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
mock = await MockContract.new();
|
||||||
|
let names = ["compound", "susd"]
|
||||||
|
let poolAddress = [mock.address, mock.address]
|
||||||
|
let rewardArr = [false, true]
|
||||||
|
mockCurveGaugeMapping = await MockCurveGaugeMapping.new(names, poolAddress, rewardArr);
|
||||||
|
mockCurveGauge = await MockCurveGauge.new(mock.address, mockCurveGaugeMapping.address);
|
||||||
|
// lp_token = new web3.eth.Contract(erc20ABI, mock.address);
|
||||||
|
curveGauge = new web3.eth.Contract(gaugeABI, mock.address)
|
||||||
|
// mocking lp_token
|
||||||
|
let lp_token = await curveGauge.methods.lp_token().encodeABI();
|
||||||
|
await mock.givenMethodReturnAddress(lp_token, mock.address);
|
||||||
|
// mocking crv_token
|
||||||
|
let crv_token = await curveGauge.methods.crv_token().encodeABI();
|
||||||
|
await mock.givenMethodReturnAddress(crv_token, mock.address);
|
||||||
|
// mocking rewarded_token
|
||||||
|
let rewarded_token = await curveGauge.methods.rewarded_token().encodeABI();
|
||||||
|
await mock.givenMethodReturnAddress(rewarded_token, mock.address);
|
||||||
|
|
||||||
|
// await mockCurveGaugeMapping.addGaugeMapping('compound', mock.address, false);
|
||||||
|
// await mockCurveGaugeMapping.addGaugeMapping('susd', mock.address, true);
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can deposit into compound gauge', async function() {
|
||||||
|
const tx = await mockCurveGauge.deposit(
|
||||||
|
"compound",
|
||||||
|
10000000,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogDeposit", {
|
||||||
|
amount: "10000000",
|
||||||
|
getId: "0",
|
||||||
|
setId: "0"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can claim reward from compound gauge', async function() {
|
||||||
|
const tx = await mockCurveGauge.claimReward(
|
||||||
|
"compound",
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogClaimedReward");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can withdraw from compound gauge', async function() {
|
||||||
|
const tx = await mockCurveGauge.withdraw(
|
||||||
|
"compound",
|
||||||
|
10000000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogClaimedReward");
|
||||||
|
expectEvent(tx, "LogWithdraw", {
|
||||||
|
amount: "10000000",
|
||||||
|
getId: "0",
|
||||||
|
setId: "0"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can deposit into susd gauge', async function() {
|
||||||
|
const tx = await mockCurveGauge.deposit(
|
||||||
|
"susd",
|
||||||
|
10000000,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogDeposit", {
|
||||||
|
amount: "10000000",
|
||||||
|
getId: "0",
|
||||||
|
setId: "0"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can claim reward from susd gauge', async function() {
|
||||||
|
const tx = await mockCurveGauge.claimReward(
|
||||||
|
"susd",
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogClaimedReward");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can withdraw from susd gauge', async function() {
|
||||||
|
const tx = await mockCurveGauge.withdraw(
|
||||||
|
"susd",
|
||||||
|
10000000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expectEvent(tx, "LogClaimedReward");
|
||||||
|
expectEvent(tx, "LogWithdraw", {
|
||||||
|
amount: "10000000",
|
||||||
|
getId: "0",
|
||||||
|
setId: "0"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cannot deposit into unknown gauge', async function() {
|
||||||
|
const tx = mockCurveGauge.deposit(
|
||||||
|
"unknown",
|
||||||
|
10000000,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
await expectRevert(tx, "wrong-gauge-pool-name")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cannot claim reward from unknown gauge', async function() {
|
||||||
|
const tx = mockCurveGauge.claimReward(
|
||||||
|
"unknown",
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
await expectRevert(tx, "wrong-gauge-pool-name")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cannot withdraw from unknown gauge', async function() {
|
||||||
|
const tx = mockCurveGauge.withdraw(
|
||||||
|
"unknown",
|
||||||
|
10000000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
await expectRevert(tx, "wrong-gauge-pool-name")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can add multiple gauge mappings', async function() {
|
||||||
|
const tx = await mockCurveGaugeMapping.addGaugeMappings(['sbtc'], [mock.address], [true]);
|
||||||
|
expectEvent(tx, "LogAddGaugeMapping");
|
||||||
|
});
|
||||||
|
})
|
||||||
1
test/abi/curveGauge.json
Normal file
1
test/abi/curveGauge.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user