Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added migrate logic and changed gauge to rewardPool #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .patches/hardhat+2.9.7.patch

This file was deleted.

12 changes: 12 additions & 0 deletions contracts/interfaces/convex/IBooster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.9;

/* solhint-disable func-name-mixedcase */
/* solhint-disable var-name-mixedcase */

interface IBooster {
function deposit(uint256 _pid, uint256 _amount) external returns (bool);

function depositAll(uint256 _pid) external returns (bool);
}
24 changes: 24 additions & 0 deletions contracts/interfaces/convex/IConvexRewardPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.9;

/* solhint-disable func-name-mixedcase */
/* solhint-disable var-name-mixedcase */

interface IConvexRewardPool {
function withdraw(uint256 _amount, bool _claim) external returns (bool);

function withdrawAll(bool claim) external;

function getReward(address _account) external;

function getReward(address _account, address _forwardTo) external;

function user_checkpoint(address _account) external returns (bool);

function claimable_reward(address _account, address _token) external view returns (uint256);

function convexBooster() external view returns (address);

function balanceOf(address) external view returns (uint256);
}
21 changes: 12 additions & 9 deletions contracts/libraries/Logic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { ISwapSimulator } from '../interfaces/ISwapSimulator.sol';
import { ICurveGauge } from '../interfaces/curve/ICurveGauge.sol';
import { ILPPriceGetter } from '../interfaces/curve/ILPPriceGetter.sol';
import { ICurveStableSwap } from '../interfaces/curve/ICurveStableSwap.sol';
import { IBooster } from '../interfaces/convex/IBooster.sol';
import { IConvexRewardPool } from '../interfaces/convex/IConvexRewardPool.sol';

import { SafeCast } from '../libraries/SafeCast.sol';
import { SwapManager } from '../libraries/SwapManager.sol';
Expand Down Expand Up @@ -57,7 +59,7 @@ library Logic {
uint256 stablecoinSlippage,
uint256 crvHarvestThreshold,
uint256 crvSlippageTolerance,
address indexed gauge,
address indexed convexRewardPool,
address indexed crvOracle
);

Expand Down Expand Up @@ -275,7 +277,7 @@ library Logic {
uint256 amount,
uint256 slippage,
ILPPriceGetter lpPriceHolder,
ICurveGauge gauge,
IConvexRewardPool rewardPool,
ICurveStableSwap triCryptoPool,
IERC20 usdt,
ISwapRouter uniV3Router,
Expand All @@ -284,7 +286,7 @@ library Logic {
uint256 pricePerLP = lpPriceHolder.lp_price();
uint256 lpToWithdraw = ((amount * (10**12)) * (10**18)) / pricePerLP;

gauge.withdraw(lpToWithdraw);
rewardPool.withdraw(lpToWithdraw, false);
triCryptoPool.remove_liquidity_one_coin(lpToWithdraw, 0, 0);

uint256 balance = usdt.balanceOf(address(this));
Expand All @@ -308,15 +310,16 @@ library Logic {
}

function migrate() external {
ICurveGauge oldGauge = ICurveGauge(0x97E2768e8E73511cA874545DC5Ff8067eB19B787);
ICurveGauge newGauge = ICurveGauge(0x555766f3da968ecBefa690Ffd49A2Ac02f47aa5f);
ICurveGauge curveGauge = ICurveGauge(0x555766f3da968ecBefa690Ffd49A2Ac02f47aa5f);
IBooster cvxBooster = IBooster(0xF403C135812408BFbE8713b5A23a04b3D48AAE31);
IERC20 triCrypto = IERC20(0x8e0B8c8BB9db49a46697F3a5Bb8A308e744821D2);

uint256 bal = oldGauge.balanceOf(address(this));
uint256 bal = curveGauge.balanceOf(address(this));

triCrypto.approve(address(oldGauge), 0);
triCrypto.approve(address(curveGauge), 0);

oldGauge.withdraw(bal);
newGauge.deposit(bal);
curveGauge.withdraw(bal);
bool success = cvxBooster.depositAll(3);
require(success, 'Boost Failed');
}
}
40 changes: 20 additions & 20 deletions contracts/yieldStrategy/CurveYieldStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { FixedPoint128 } from '@uniswap/v3-core-0.8-support/contracts/libraries/

import { SwapManager } from '../libraries/SwapManager.sol';

import { IBooster } from '../interfaces/convex/IBooster.sol';
import { IConvexRewardPool } from '../interfaces/convex/IConvexRewardPool.sol';
import { Logic } from '../libraries/Logic.sol';

contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
Expand All @@ -29,14 +31,12 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
error CYS_INVALID_SETTER_VALUE();
error CYS_EXTERAL_CALL_FAILED(string reason);

IGaugeFactory private constant GAUGE_FACTORY = IGaugeFactory(0xabC000d88f23Bb45525E447528DBF656A9D55bf5);

IERC20 private usdt; // 6 decimals
IERC20 private weth; // 18 decimals
IERC20 private usdc; // 6 decimals
IERC20 private crvToken; // 18 decimals

ICurveGauge private gauge; // curve gauge, which gives CRV emissions for staking triCrypto LP token
IConvexRewardPool private convexRewardPool; // curve convexRewardPool, which gives CRV emissions for staking triCrypto LP token
ISwapRouter private uniV3Router; // uniswap swap router
ILPPriceGetter private lpPriceHolder; // price-manipulation resistant triCrypto lp price oracle
ICurveStableSwap private triCryptoPool; // triCrypto stableSwap address
Expand Down Expand Up @@ -66,7 +66,7 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
IERC20 usdc;
IERC20 weth;
IERC20 crvToken;
ICurveGauge gauge;
IConvexRewardPool convexRewardPool;
ISwapRouter uniV3Router;
ILPPriceGetter lpPriceHolder;
ICurveStableSwap tricryptoPool;
Expand All @@ -78,7 +78,7 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
usdt = params.usdt;
usdc = params.usdc;
weth = params.weth;
gauge = params.gauge;
convexRewardPool = params.convexRewardPool;
crvToken = params.crvToken;
uniV3Router = params.uniV3Router;
triCryptoPool = params.tricryptoPool;
Expand All @@ -90,12 +90,12 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
uint256 _stablecoinSlippage,
uint256 _crvHarvestThreshold,
uint256 _crvSlippageTolerance,
ICurveGauge _gauge,
IConvexRewardPool _convexRewardPool,
AggregatorV3Interface _crvOracle
) external onlyOwner {
if (_feeBps < MAX_BPS && _stablecoinSlippage < MAX_BPS && _crvSlippageTolerance < MAX_BPS) {
FEE = _feeBps;
gauge = _gauge;
convexRewardPool = _convexRewardPool;
crvOracle = _crvOracle;
crvHarvestThreshold = _crvHarvestThreshold;
crvSwapSlippageTolerance = _crvSlippageTolerance;
Expand All @@ -107,7 +107,7 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
_stablecoinSlippage,
_crvHarvestThreshold,
_crvSlippageTolerance,
address(_gauge),
address(_convexRewardPool),
address(_crvOracle)
);
}
Expand All @@ -116,7 +116,7 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
function grantAllowances() public override onlyOwner {
_grantBaseAllowances();

asset.approve(address(gauge), type(uint256).max);
asset.approve(address(convexRewardPool.convexBooster()), type(uint256).max);
asset.approve(address(triCryptoPool), type(uint256).max);

/// @dev USDT requires allowance set to 0 before re-approving
Expand Down Expand Up @@ -149,7 +149,7 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
/// @param amount amount of LP tokens
function _beforeWithdrawYield(uint256 amount) internal override {
emit Logic.StateInfo(lpPriceHolder.lp_price());
gauge.withdraw(amount);
convexRewardPool.withdraw(amount, false);
_harvestFees();
}

Expand All @@ -167,11 +167,10 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
_stake(asset.balanceOf(address(this)));
}

/// @notice claims the accumulated CRV rewards from the gauge, sells CRV rewards for LP tokens and stakes LP tokens
/// @notice claims the accumulated CRV rewards from the convexRewardPool, sells CRV rewards for LP tokens and stakes LP tokens
function _harvestFees() internal override {
uint256 before = crvToken.balanceOf(address(this));
GAUGE_FACTORY.mint(address(gauge));
gauge.claim_rewards();
convexRewardPool.getReward(address(this));
uint256 afterBal = crvToken.balanceOf(address(this));

uint256 claimable = (afterBal - before) + crvPendingToSwap;
Expand Down Expand Up @@ -220,27 +219,27 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
}
}

/// @notice stakes LP tokens (i.e deposits into reward gauge)
/// @notice stakes LP tokens (i.e deposits into reward convexRewardPool)
/// @param amount amount of LP tokens
function _stake(uint256 amount) internal override {
gauge.deposit(amount);
if (amount > 0) IBooster(convexRewardPool.convexBooster()).deposit(3, amount);
emit Logic.Staked(amount, msg.sender);
}

/// @notice total LP tokens staked in the curve rewards gauge
/// @notice total LP tokens staked in the curve rewards convexRewardPool
function _stakedAssetBalance() internal view override returns (uint256) {
return gauge.balanceOf(address(this));
return convexRewardPool.balanceOf(address(this));
}

/// @notice withdraws LP tokens from gauge, sells LP token for settlementToken
/// @notice withdraws LP tokens from convexRewardPool, sells LP token for settlementToken
/// @param amount amount of LP tokens
function _convertAssetToSettlementToken(uint256 amount) internal override returns (uint256 usdcAmount) {
return
Logic.convertAssetToSettlementToken(
amount,
stablecoinSlippageTolerance,
lpPriceHolder,
gauge,
convexRewardPool,
triCryptoPool,
usdt,
uniV3Router,
Expand All @@ -259,9 +258,10 @@ contract CurveYieldStrategy is EightyTwentyRangeStrategyVault {
return Logic.getPriceX128(lpPriceHolder);
}

/// @notice migrates funds from curvefi's old gauge to new gauge
/// @notice migrates funds from curvefi's gauge to convex rewardPool
/// @dev this method is intended for one time use
function migrate() external onlyOwner {
//TODO: add harvest of fees and add to crv pending to swap
Logic.migrate();
}
}
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
hardhat: {
forking: {
url: `https://arb-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`,
blockNumber: 22049346, // 9323800,
blockNumber: 40747000
},
blockGasLimit: 0x1fffffffffff,
gasPrice: 0,
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@
"@nomiclabs/hardhat-etherscan": "^3.0.3",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@protodev-rage/hardhat-tenderly": "^1.0.13",
"@ragetrade/sdk": "^0.7.9",
"@ragetrade/sdk": "^1.0.0-alpha.43",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@typechain/hardhat": "^6.1.4",
"@types/chai": "^4.3.1",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.25",
"@uniswap/v3-sdk": "^3.6.2-optimism-regenesis",
"chai": "^4.3.0",
"chai": "^4.3.7",
"copyfiles": "^2.4.1",
"dotenv": "^16.0.0",
"ethereum-waffle": "^3.3.0",
"ethers": "5.6.8",
"ethers": "5.7.2",
"fs-extra": "^10.1.0",
"hardhat": "^2.9.3",
"hardhat": "^2.12.2",
"hardhat-contract-sizer": "^2.1.1",
"hardhat-deploy": "^0.10.5",
"hardhat-gas-reporter": "^1.0.4",
Expand Down
Loading