mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
changed CurveGaugeMapping to use GaugeData to include gaugeAddress and rewardToken;
removed function overload for withdraw and claim by using curveGaugeData;
This commit is contained in:
parent
a2b929a794
commit
0f9e5f69f1
|
@ -1,4 +1,5 @@
|
||||||
pragma solidity ^0.6.0;
|
pragma solidity ^0.6.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
// import files from common directory
|
// import files from common directory
|
||||||
import { Stores } from "../common/stores.sol";
|
import { Stores } from "../common/stores.sol";
|
||||||
|
@ -19,8 +20,14 @@ interface IMintor{
|
||||||
function mint(address gauge) external;
|
function mint(address gauge) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CurveGaugeMapping {
|
interface ICurveGaugeMapping {
|
||||||
function gaugeMapping(bytes32) external view returns(address gaugeAddress);
|
|
||||||
|
struct GaugeData {
|
||||||
|
address gaugeAddress;
|
||||||
|
bool rewardToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
function gaugeMapping(bytes32) external view returns(GaugeData memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract GaugeHelper is DSMath, Stores{
|
contract GaugeHelper is DSMath, Stores{
|
||||||
|
@ -97,14 +104,14 @@ contract CurveGauge is GaugeHelper {
|
||||||
uint setId
|
uint setId
|
||||||
) external payable {
|
) external payable {
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
CurveGaugeMapping curveGaugeMapping = CurveGaugeMapping(getCurveGaugeMappingAddr());
|
ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr());
|
||||||
address curveGaugeAddr = curveGaugeMapping.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
||||||
require(curveGaugeAddr != address(0), "wrong-gauge-pool-name");
|
require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name");
|
||||||
IGauge gauge = IGauge(curveGaugeAddr);
|
IGauge gauge = IGauge(curveGaugeData.gaugeAddress);
|
||||||
TokenInterface lp_token = TokenInterface(address(gauge.lp_token()));
|
TokenInterface lp_token = TokenInterface(address(gauge.lp_token()));
|
||||||
|
|
||||||
_amt = _amt == uint(-1) ? lp_token.balanceOf(address(this)) : _amt;
|
_amt = _amt == uint(-1) ? lp_token.balanceOf(address(this)) : _amt;
|
||||||
lp_token.approve(address(curveGaugeAddr), _amt);
|
lp_token.approve(address(curveGaugeData.gaugeAddress), _amt);
|
||||||
gauge.deposit(_amt);
|
gauge.deposit(_amt);
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
@ -114,47 +121,6 @@ contract CurveGauge is GaugeHelper {
|
||||||
emitEvent(_eventCode, _eventParam);
|
emitEvent(_eventCode, _eventParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Withdraw LP Token and claim CRV reward.
|
|
||||||
* @param gaugePoolName gauge pool name.
|
|
||||||
* @param amt LP token amount.
|
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
|
||||||
* @param setIdCRVReward Set CRV token reward amount at this ID in `InstaMemory` Contract.
|
|
||||||
*/
|
|
||||||
function withdraw(
|
|
||||||
string calldata gaugePoolName,
|
|
||||||
uint amt,
|
|
||||||
uint getId,
|
|
||||||
uint setId,
|
|
||||||
uint setIdCRVReward
|
|
||||||
) external payable {
|
|
||||||
uint _amt = getUint(getId, amt);
|
|
||||||
address curveGaugeAddr = CurveGaugeMapping(getCurveGaugeMappingAddr())
|
|
||||||
.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
|
||||||
require(curveGaugeAddr != address(0), "wrong-gauge-pool-name");
|
|
||||||
IGauge gauge = IGauge(curveGaugeAddr);
|
|
||||||
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
|
||||||
Balances memory balances;
|
|
||||||
|
|
||||||
_amt = _amt == uint(-1) ? gauge.balanceOf(address(this)) : _amt;
|
|
||||||
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
|
||||||
IMintor(getCurveMintorAddr()).mint(curveGaugeAddr);
|
|
||||||
gauge.withdraw(_amt);
|
|
||||||
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
|
||||||
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
|
||||||
|
|
||||||
setUint(setId, _amt);
|
|
||||||
setUint(setIdCRVReward, balances.crvRewardAmt);
|
|
||||||
|
|
||||||
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setIdCRVReward);
|
|
||||||
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256)");
|
|
||||||
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setIdCRVReward);
|
|
||||||
emitEvent(_eventCode, _eventParam);
|
|
||||||
|
|
||||||
emitLogWithdraw(gaugePoolName, _amt, getId, setId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw LP Token and claim both CRV and Reward token.
|
* @dev Withdraw LP Token and claim both CRV and Reward token.
|
||||||
* @param gaugePoolName gauge pool name.
|
* @param gaugePoolName gauge pool name.
|
||||||
|
@ -173,34 +139,46 @@ contract CurveGauge is GaugeHelper {
|
||||||
uint setIdReward
|
uint setIdReward
|
||||||
) external payable {
|
) external payable {
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
address curveGaugeAddr = CurveGaugeMapping(getCurveGaugeMappingAddr())
|
ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr());
|
||||||
.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
||||||
require(curveGaugeAddr != address(0), "wrong-gauge-pool-name");
|
require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name");
|
||||||
IGauge gauge = IGauge(curveGaugeAddr);
|
IGauge gauge = IGauge(curveGaugeData.gaugeAddress);
|
||||||
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
||||||
TokenInterface rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
|
||||||
Balances memory balances;
|
Balances memory balances;
|
||||||
|
|
||||||
_amt = _amt == uint(-1) ? gauge.balanceOf(address(this)) : _amt;
|
_amt = _amt == uint(-1) ? gauge.balanceOf(address(this)) : _amt;
|
||||||
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
||||||
balances.intialRewardBal = rewarded_token.balanceOf(address(this));
|
|
||||||
IMintor(getCurveMintorAddr()).mint(curveGaugeAddr);
|
|
||||||
gauge.withdraw(_amt);
|
|
||||||
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
|
||||||
balances.finalRewardBal = rewarded_token.balanceOf(address(this));
|
|
||||||
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
|
||||||
balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal);
|
|
||||||
|
|
||||||
|
if(curveGaugeData.rewardToken == true){
|
||||||
|
TokenInterface 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(setId, _amt);
|
||||||
setUint(setIdCRVReward, balances.crvRewardAmt);
|
setUint(setIdCRVReward, balances.crvRewardAmt);
|
||||||
setUint(setIdReward, balances.rewardAmt);
|
|
||||||
|
|
||||||
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setIdCRVReward, balances.rewardAmt, setIdReward);
|
|
||||||
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256,uint256,uint256)");
|
|
||||||
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setIdCRVReward, balances.rewardAmt, setIdReward);
|
|
||||||
emitEvent(_eventCode, _eventParam);
|
|
||||||
|
|
||||||
emitLogWithdraw(gaugePoolName, _amt, getId, setId);
|
emitLogWithdraw(gaugePoolName, _amt, getId, setId);
|
||||||
|
|
||||||
|
if(curveGaugeData.rewardToken == true){
|
||||||
|
TokenInterface rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
||||||
|
balances.finalRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
|
balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal);
|
||||||
|
setUint(setIdReward, balances.rewardAmt);
|
||||||
|
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setIdCRVReward, balances.rewardAmt, setIdReward);
|
||||||
|
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256,uint256,uint256)");
|
||||||
|
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setIdCRVReward, balances.rewardAmt, setIdReward);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}else{
|
||||||
|
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setIdCRVReward);
|
||||||
|
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256");
|
||||||
|
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setIdCRVReward);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,36 +195,6 @@ contract CurveGauge is GaugeHelper {
|
||||||
emitEvent(_eventCodeWithdraw, _eventParamWithdraw);
|
emitEvent(_eventCodeWithdraw, _eventParamWithdraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Claim CRV Reward.
|
|
||||||
* @param gaugePoolName gauge pool name.
|
|
||||||
* @param setId Set CRV reward amount at this ID in `InstaMemory` Contract.
|
|
||||||
*/
|
|
||||||
function claimReward(
|
|
||||||
string calldata gaugePoolName,
|
|
||||||
uint setId
|
|
||||||
) external payable {
|
|
||||||
CurveGaugeMapping curveGaugeMapping = CurveGaugeMapping(getCurveGaugeMappingAddr());
|
|
||||||
address curveGaugeAddr = curveGaugeMapping.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
|
||||||
require(curveGaugeAddr != address(0), "wrong-gauge-pool-name");
|
|
||||||
IMintor mintor = IMintor(getCurveMintorAddr());
|
|
||||||
IGauge gauge = IGauge(curveGaugeAddr);
|
|
||||||
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
|
||||||
Balances memory balances;
|
|
||||||
|
|
||||||
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
|
||||||
mintor.mint(curveGaugeAddr);
|
|
||||||
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
|
||||||
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
|
||||||
|
|
||||||
setUint(setId, balances.crvRewardAmt);
|
|
||||||
|
|
||||||
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setId);
|
|
||||||
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256)");
|
|
||||||
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setId);
|
|
||||||
emitEvent(_eventCode, _eventParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Claim CRV Reward with Staked Reward token
|
* @dev Claim CRV Reward with Staked Reward token
|
||||||
* @param gaugePoolName gauge pool name.
|
* @param gaugePoolName gauge pool name.
|
||||||
|
@ -258,30 +206,42 @@ contract CurveGauge is GaugeHelper {
|
||||||
uint setId,
|
uint setId,
|
||||||
uint setIdReward
|
uint setIdReward
|
||||||
) external payable {
|
) external payable {
|
||||||
CurveGaugeMapping curveGaugeMapping = CurveGaugeMapping(getCurveGaugeMappingAddr());
|
ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr());
|
||||||
address curveGaugeAddr = curveGaugeMapping.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping(bytes32(stringToBytes32(gaugePoolName)));
|
||||||
require(curveGaugeAddr != address(0), "wrong-gauge-pool-name");
|
require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name");
|
||||||
IMintor mintor = IMintor(getCurveMintorAddr());
|
IMintor mintor = IMintor(getCurveMintorAddr());
|
||||||
IGauge gauge = IGauge(curveGaugeAddr);
|
IGauge gauge = IGauge(curveGaugeData.gaugeAddress);
|
||||||
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
TokenInterface crv_token = TokenInterface(address(gauge.crv_token()));
|
||||||
TokenInterface rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
|
||||||
Balances memory balances;
|
Balances memory balances;
|
||||||
|
|
||||||
|
if(curveGaugeData.rewardToken == true){
|
||||||
|
TokenInterface rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
||||||
|
balances.intialRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
balances.intialCRVBal = crv_token.balanceOf(address(this));
|
||||||
balances.intialRewardBal = rewarded_token.balanceOf(address(this));
|
|
||||||
mintor.mint(curveGaugeAddr);
|
mintor.mint(curveGaugeData.gaugeAddress);
|
||||||
|
|
||||||
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
balances.finalCRVBal = crv_token.balanceOf(address(this));
|
||||||
balances.finalRewardBal = rewarded_token.balanceOf(address(this));
|
|
||||||
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal);
|
||||||
balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal);
|
|
||||||
|
|
||||||
setUint(setId, balances.crvRewardAmt);
|
setUint(setId, balances.crvRewardAmt);
|
||||||
setUint(setIdReward, balances.rewardAmt);
|
|
||||||
|
|
||||||
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setId, balances.rewardAmt, setIdReward);
|
if(curveGaugeData.rewardToken == true){
|
||||||
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256,uint256,uint256)");
|
TokenInterface rewarded_token = TokenInterface(address(gauge.rewarded_token()));
|
||||||
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setId, balances.rewardAmt, setIdReward);
|
balances.finalRewardBal = rewarded_token.balanceOf(address(this));
|
||||||
emitEvent(_eventCode, _eventParam);
|
balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal);
|
||||||
|
setUint(setIdReward, balances.rewardAmt);
|
||||||
|
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setId, balances.rewardAmt, setIdReward);
|
||||||
|
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256,uint256,uint256)");
|
||||||
|
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setId, balances.rewardAmt, setIdReward);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}else{
|
||||||
|
emit LogClaimedReward(gaugePoolName, balances.crvRewardAmt, setId);
|
||||||
|
bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256");
|
||||||
|
bytes memory _eventParam = abi.encode(gaugePoolName, balances.crvRewardAmt, setId);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,17 @@ contract Helpers is BytesHelper {
|
||||||
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
|
||||||
uint public version = 1;
|
uint public version = 1;
|
||||||
|
|
||||||
mapping (bytes32 => address) public gaugeMapping;
|
mapping (bytes32 => GaugeData) public gaugeMapping;
|
||||||
|
|
||||||
|
struct GaugeData {
|
||||||
|
address gaugeAddress;
|
||||||
|
bool rewardToken;
|
||||||
|
}
|
||||||
|
|
||||||
event LogAddGaugeMapping(
|
event LogAddGaugeMapping(
|
||||||
string gaugeName,
|
string gaugeName,
|
||||||
address gaugeAddress
|
address gaugeAddress,
|
||||||
|
bool rewardToken
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogRemoveGaugeMapping(
|
event LogRemoveGaugeMapping(
|
||||||
|
@ -64,22 +70,24 @@ contract Helpers is BytesHelper {
|
||||||
|
|
||||||
function addGaugeMapping(
|
function addGaugeMapping(
|
||||||
string memory gaugeName,
|
string memory gaugeName,
|
||||||
address gaugeAddress
|
address gaugeAddress,
|
||||||
|
bool rewardToken
|
||||||
) public isChief {
|
) public isChief {
|
||||||
require(gaugeAddress != address(0), "gaugeAddress-not-vaild");
|
require(gaugeAddress != address(0), "gaugeAddress-not-vaild");
|
||||||
require(bytes(gaugeName).length <= 32, "Length-exceeds");
|
require(bytes(gaugeName).length <= 32, "Length-exceeds");
|
||||||
bytes32 gaugeType = stringToBytes32(gaugeName);
|
bytes32 gaugeType = stringToBytes32(gaugeName);
|
||||||
require(gaugeMapping[gaugeType] == address(0), "gaugePool-already-added");
|
require(gaugeMapping[gaugeType].gaugeAddress == address(0), "gaugePool-already-added");
|
||||||
|
|
||||||
gaugeMapping[gaugeType] = gaugeAddress;
|
gaugeMapping[gaugeType].gaugeAddress = gaugeAddress;
|
||||||
|
gaugeMapping[gaugeType].rewardToken = rewardToken;
|
||||||
|
|
||||||
emit LogAddGaugeMapping(gaugeName, gaugeAddress);
|
emit LogAddGaugeMapping(gaugeName, gaugeAddress, rewardToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeGaugeMapping(string memory gaugeName, address gaugeAddress) public isChief {
|
function removeGaugeMapping(string memory gaugeName, address gaugeAddress) public isChief {
|
||||||
require(gaugeAddress != address(0), "gaugeAddress-not-vaild");
|
require(gaugeAddress != address(0), "gaugeAddress-not-vaild");
|
||||||
bytes32 gaugeType = stringToBytes32(gaugeName);
|
bytes32 gaugeType = stringToBytes32(gaugeName);
|
||||||
require(gaugeMapping[gaugeType] == gaugeAddress, "different-gauge-pool");
|
require(gaugeMapping[gaugeType].gaugeAddress == gaugeAddress, "different-gauge-pool");
|
||||||
|
|
||||||
delete gaugeMapping[gaugeType];
|
delete gaugeMapping[gaugeType];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user