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

Fix/arb crv tricrypto #191

Open
wants to merge 2 commits into
base: master
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
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.7;

import "./strategy-base.sol";
import "../strategy-base.sol";

import "../../../interfaces/curve.sol";

import "../../interfaces/curve.sol";

// Base contract for Curve based staking contract interfaces

abstract contract StrategyCurveBase is StrategyBase {
// curve dao
address public gauge;
address public curve;

// token addresses
address public usdt = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9;
address public wbtc = 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f;
address public mintr = 0xabC000d88f23Bb45525E447528DBF656A9D55bf5;

// rewards
address public crv = 0x11cDb42B0EB46D95f990BeDD4695A6e3fA034978;
Expand All @@ -33,6 +31,8 @@ abstract contract StrategyCurveBase is StrategyBase {
{
curve = _curve;
gauge = _gauge;
IERC20(want).safeApprove(gauge, type(uint256).max);
IERC20(weth).safeApprove(curve, type(uint256).max);
}

// **** Getters ****
Expand All @@ -50,8 +50,6 @@ abstract contract StrategyCurveBase is StrategyBase {
function deposit() public override {
uint256 _want = IERC20(want).balanceOf(address(this));
if (_want > 0) {
IERC20(want).safeApprove(gauge, 0);
IERC20(want).safeApprove(gauge, _want);
ICurveGauge(gauge).deposit(_want);
}
}
Expand Down
39 changes: 12 additions & 27 deletions src/strategies/arbitrum/curve/strategy-curve-tricrypto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import "../../../interfaces/curve.sol";
import "../../../interfaces/uniswapv2.sol";
import "../../../interfaces/controller.sol";

import "../strategy-curve-base.sol";
import "./strategy-curve-base.sol";

contract StrategyCurveTricrypto is StrategyCurveBase {
// Curve stuff
address public tri_pool = 0x960ea3e3C7FB317332d990873d354E18d7645590;
address public tri_gauge = 0x97E2768e8E73511cA874545DC5Ff8067eB19B787;
address public tricrypto = 0x8e0B8c8BB9db49a46697F3a5Bb8A308e744821D2;
address private _pool = 0x960ea3e3C7FB317332d990873d354E18d7645590;
address private _gauge = 0x555766f3da968ecBefa690Ffd49A2Ac02f47aa5f;
address private _want = 0x8e0B8c8BB9db49a46697F3a5Bb8A308e744821D2;

address public swaprRouter = 0x530476d5583724A89c8841eB6Da76E7Af4C0F17E;

Expand All @@ -24,54 +24,39 @@ contract StrategyCurveTricrypto is StrategyCurveBase {
address _strategist,
address _controller,
address _timelock
)
public
StrategyCurveBase(
tri_pool,
tri_gauge,
tricrypto,
_governance,
_strategist,
_controller,
_timelock
)
{
sushiRouter = swaprRouter; // Best liquidity for CRV
) public StrategyCurveBase(_pool, _gauge, _want, _governance, _strategist, _controller, _timelock) {
sushiRouter = swaprRouter; // Best liquidity for CRV
IERC20(crv).safeApprove(sushiRouter, type(uint256).max);
}


function getName() external override pure returns (string memory) {
function getName() external pure override returns (string memory) {
return "StrategyCurveTricrypto";
}

// **** State Mutations ****

function harvest() public onlyBenevolent override {
function harvest() public override {
// Anyone can harvest it at any given time.
// I understand the possibility of being frontrun
// But ETH is a dark forest, and I wanna see how this plays out
// i.e. will be be heavily frontrunned?
// if so, a new strategy will be deployed.

ICurveGauge(gauge).claim_rewards(address(this));
ICurveMintr(mintr).mint(gauge);

uint256 _crv = IERC20(crv).balanceOf(address(this));
if (_crv > 0) {
IERC20(crv).safeApprove(sushiRouter, 0);
IERC20(crv).safeApprove(sushiRouter, _crv);
_swapSushiswap(crv, weth, _crv);
}
_distributePerformanceFeesNative();

uint256 _weth = IERC20(weth).balanceOf(address(this));
// Adds liquidity to curve.fi's pool
if (_weth > 0) {
IERC20(weth).safeApprove(curve, 0);
IERC20(weth).safeApprove(curve, _weth);
uint256[3] memory liquidity;
liquidity[2] = _weth;
ICurveFi_3(curve).add_liquidity(liquidity, 0);
}

_distributePerformanceFeesAndDeposit();
deposit();
}
}
11 changes: 11 additions & 0 deletions src/strategies/arbitrum/strategy-base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,15 @@ abstract contract StrategyBase {
deposit();
}
}

function _distributePerformanceFeesNative() internal {
uint256 _weth = IERC20(weth).balanceOf(address(this));
if (_weth > 0) {
// Treasury fees
IERC20(weth).safeTransfer(
IController(controller).treasury(),
_weth.mul(performanceTreasuryFee).div(performanceTreasuryMax)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {toWei} = require("../../../utils/testHelper");
const {getWantFromWhale} = require("../../../utils/setupHelper");
const {doTestBehaviorBase} = require("../../testBehaviorBase");

describe("StrategyCurveTricrypto", () => {
const want_addr = "0x8e0B8c8BB9db49a46697F3a5Bb8A308e744821D2";
const whale_addr = "0xf78A4411E98eB741bcB552950034a731b32E2f95";

before("Get want token", async () => {
[alice] = await hre.ethers.getSigners();
await getWantFromWhale(want_addr, toWei(5, 18), alice, whale_addr);
});

doTestBehaviorBase("StrategyCurveTricrypto", want_addr, true);
});