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

Convex frxETH/WETH strategy #1846

Closed
wants to merge 159 commits into from
Closed
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
c9dfea2
Removed external initialize function from InitializableAbstractStrategy
naddison36 Sep 26, 2023
9f6fc66
Merge remote-tracking branch 'origin/master' into nicka/strategy-init…
naddison36 Sep 26, 2023
79af137
Deploy script to upgrade frxETH strategy
naddison36 Sep 27, 2023
0fb53a1
Added explicit _initialize calls
naddison36 Sep 27, 2023
f993691
Proxy initialize gas saving by using calldata instead of memory
naddison36 Sep 28, 2023
b7de7df
BaseCurveStrategy using CURVE_BASE_ASSETS constant for the number of …
naddison36 Sep 27, 2023
fbd6202
Added new ConvexTwoAssetStrategy contract
naddison36 Sep 27, 2023
c9a919e
Added frxETH/WETH Curve strategy
naddison36 Sep 27, 2023
a08b894
Add more frxETH/WETH fork tests
naddison36 Sep 27, 2023
0c1abf8
remove liquidity from Curve pool directly to the recipient
naddison36 Sep 28, 2023
c646b8e
prettier
naddison36 Sep 28, 2023
71c2269
BaseCurveStrategy make to work with Curve pools with 2 or 3 coins
naddison36 Sep 28, 2023
43e36b3
Gas improvements to BaseCurveStrategy
naddison36 Sep 29, 2023
f8c1f00
More BaseCurve and ConvexStrategy cleanup
naddison36 Sep 29, 2023
51f9c41
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 3, 2023
9acb342
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-minimal…
naddison36 Oct 3, 2023
44f119c
convexFrxEthFixture can mint when frxETH below peg
naddison36 Oct 3, 2023
4c909e7
Fix OETH AMO fork tests now there is more ETH and OETH in the pool
naddison36 Oct 3, 2023
fbf8af5
minor fix to comment
naddison36 Oct 3, 2023
73b4381
Add ConvexStrategy diagrams
naddison36 Oct 3, 2023
1eb1537
fix OUSD collateral swaps
naddison36 Oct 3, 2023
63d119a
Added governable behaviours to strategy unit tests
naddison36 Oct 3, 2023
89db87f
Merge remote-tracking branch 'origin/nicka/frax-strategy-upgrade' int…
naddison36 Oct 3, 2023
4eca852
fix OUSD AMO fork test
naddison36 Oct 3, 2023
08614ec
Added harvestable behaviour tests
naddison36 Oct 3, 2023
ad23493
wip strategy behaviour tests
naddison36 Oct 3, 2023
65d36ef
Add .VSCodeCounter to gitignore
naddison36 Oct 3, 2023
ff76bed
refactor harvester behaviour
naddison36 Oct 3, 2023
4cfb6de
Got strategy withdraw tests working with Curve and Convex mocks
naddison36 Oct 4, 2023
c80fa80
Fix lint errors in mock
naddison36 Oct 4, 2023
0581e42
fix collateral swap fork tests
naddison36 Oct 4, 2023
05fc952
Updated strategy behaviour tests
naddison36 Oct 4, 2023
d982f8a
Added Withdrawal event to AaveStrategy in withdrawAll
naddison36 Oct 4, 2023
d27ce2a
added mint and burn of shares to MocksfrxETH
naddison36 Oct 4, 2023
c940048
remove Balancer MEV tests for now
naddison36 Oct 4, 2023
d4321cd
Added Convex frxETH/WETH strategy unit tests
naddison36 Oct 5, 2023
7f0f22e
Removed unused imports from Harvester contracts
naddison36 Oct 5, 2023
e9178d7
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 5, 2023
0d673d0
Test removePToken can't be called on convexFrxEthWethStrategy
naddison36 Oct 5, 2023
3b9267b
Restored the Balancer MEV test after merge from master
naddison36 Oct 5, 2023
6733fb3
fix HarvesterAddressesUpdated event
naddison36 Oct 5, 2023
8f221dc
Fix convexFrxEthFixture
naddison36 Oct 5, 2023
5d30578
avoid zero transfers on BaseCurveStrategy.withdrawAll
naddison36 Oct 5, 2023
d2825df
Merge branch 'master' into nicka/convex-frxeth-weth-libs
shahthepro Oct 5, 2023
7f5c5c6
Fix withdraw on MocksfrxETH
naddison36 Oct 5, 2023
4b64655
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Oct 5, 2023
602135d
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 5, 2023
ff970d0
Update MocksfrxETH to match master
naddison36 Oct 5, 2023
d84b34a
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 6, 2023
8388190
Updated OETH contract diagram
naddison36 Oct 6, 2023
9dd4483
Added frxETH and WETH deposits to frxETH/WETH strategy to value flow …
naddison36 Oct 6, 2023
6ee16f1
Added more access tests to strategy behaviour tests
naddison36 Oct 6, 2023
0bf6118
initialize contracts via proxy directly to governor instead of transf…
naddison36 Oct 6, 2023
73d6720
fix js linter
naddison36 Oct 6, 2023
480a974
Prevent setPTokenAddress being called for Curve strategies
naddison36 Oct 6, 2023
1d9defe
Fix assignment of 3rd coin's decimals in BaseCurveStrategy
naddison36 Oct 6, 2023
ec36684
Updated ConvexStrategy document
naddison36 Oct 6, 2023
10b72ef
Fix maths execution order in Matapool mock
naddison36 Oct 7, 2023
7543067
Simplify the virtual price in the Curve mocks
naddison36 Oct 7, 2023
bb37a8c
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 11, 2023
dd0d1ec
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 16, 2023
21e850c
Fix OETH AMO fork tests now there is less invested
naddison36 Oct 16, 2023
1e9a1cb
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 16, 2023
491db5c
Removed unused imports from Harvester contracts
naddison36 Oct 17, 2023
3170b25
Fixes to Convex mock contracts
naddison36 Oct 17, 2023
a24477d
Fix withdraw on sfrxETH mock contract
naddison36 Oct 17, 2023
1a8e0bc
Fixes to Curve mock contracts
naddison36 Oct 17, 2023
95e9529
Added Withdrawal event to Aave and Compound withdrawAll
naddison36 Oct 17, 2023
a7ef9da
Generalized4626Strategy to not emit Withdrawal event when no assets w…
naddison36 Oct 17, 2023
6e62bef
Fix HarvesterAddressesUpdated event in setHarvesterAddress
naddison36 Oct 17, 2023
c2874bb
Added IERC20Metadata which is used by the resolveAsset function
naddison36 Oct 17, 2023
d6391ca
Moved replacing of WETH contract to 000_mock
naddison36 Oct 17, 2023
1747aa7
Minor layout and comment changes
naddison36 Oct 17, 2023
0d1d545
Added behaviour tests
naddison36 Oct 17, 2023
bb65e29
fix linter
naddison36 Oct 17, 2023
a03c762
Fix collateral swap fork tests
naddison36 Oct 17, 2023
7c6bfee
Updated code comments
naddison36 Oct 17, 2023
034be4b
Fix collateral swap fork tests
naddison36 Oct 17, 2023
a104dfa
Updated behaviour tests
naddison36 Oct 17, 2023
e10e0d4
fix collateral swaps to USDT
naddison36 Oct 17, 2023
104c707
frxETH strategy behaviour tests now includes weth
naddison36 Oct 17, 2023
c29556d
Merge remote-tracking branch 'origin/master' into nicka/behaviour-tests
naddison36 Oct 18, 2023
9d5c77c
Fixed merge issues
naddison36 Oct 18, 2023
e0f4d1a
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Oct 18, 2023
2eeb240
Move calc of Curve LP tokens to Curve library (#1863)
naddison36 Oct 18, 2023
9111479
Convex frxETH/WETH Strategy - Hot Fix 01 (#1878)
naddison36 Oct 23, 2023
57c7a9d
Convex frxETH/WETH Strategy - OZ L-01 (#1880)
naddison36 Oct 23, 2023
11958ac
Convex frxETH/WETH Strategy - OZ L-02 (#1881)
naddison36 Oct 23, 2023
ab23368
Update BaseCurveStrategy._getAsset Natspec
naddison36 Oct 23, 2023
93e1711
Update ConvexStrategy Natspec
naddison36 Oct 23, 2023
f154127
Convex frxETH/WETH Strategy - OZ L-03 (#1882)
naddison36 Oct 23, 2023
b338bc6
Improved gas and precision of BaseCurveStrategy.depositAll (#1883)
naddison36 Oct 23, 2023
f7f0cf8
Convex frxETH/WETH Strategy - OZ N-02 (#1884)
naddison36 Oct 23, 2023
2857498
Improve documentation (#1885)
naddison36 Oct 23, 2023
ffad007
Added Natspec for CURVE_POOL and CURVE_LP_TOKEN in BaseCurveStrategy …
naddison36 Oct 23, 2023
4f8d6aa
Convex frxETH/WETH Strategy - N-03 (#1887)
naddison36 Oct 23, 2023
10558c6
Added Natspec for ConvexStrategy._approveBase() (#1888)
naddison36 Oct 23, 2023
2fd1578
Simplified ConvexStrategy constructor by getting cvxRewardStaker from…
naddison36 Oct 24, 2023
aa546e7
Prevent transferring of supported assets from strategies (#1869)
shahthepro Oct 25, 2023
c24cc5c
Merge remote-tracking branch 'origin/master' into nicka/behaviour-tests
naddison36 Oct 25, 2023
6085af2
Increased coverage of behaviour tests
naddison36 Oct 25, 2023
ed1f838
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 25, 2023
16c32ce
Remove forkOnlyDescribe in new fork test
naddison36 Oct 25, 2023
96e8855
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Oct 25, 2023
a243f39
Fix tests and cleanup funding
shahthepro Oct 25, 2023
305dbfe
More cleanup
shahthepro Oct 25, 2023
4a1849d
More cleanup
shahthepro Oct 25, 2023
1fd478a
Merge remote-tracking branch 'origin/master' into nicka/behaviour-tests
naddison36 Oct 25, 2023
f106a12
Try multiple slots
shahthepro Oct 25, 2023
8e7bf4c
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Oct 25, 2023
a63bf8f
Fix Vyper slots
shahthepro Oct 25, 2023
e4801ab
Convex frxETH/WETH Strategy - OZ M-01 (#1879)
naddison36 Oct 25, 2023
69f42f7
Minor tweaks
shahthepro Oct 25, 2023
9d20fdd
Fix MEV tests
shahthepro Oct 25, 2023
cd16fca
Few more fixes
shahthepro Oct 25, 2023
6194dbe
Fix fraxETH
shahthepro Oct 25, 2023
7dbcbc7
Fix 3CRV
shahthepro Oct 25, 2023
26667f0
More tweaks
shahthepro Oct 25, 2023
894d450
Increase tolerance
shahthepro Oct 25, 2023
0fde52a
Increase tolerance
shahthepro Oct 25, 2023
07f2f4f
prettify
shahthepro Oct 25, 2023
d33ceab
Merge remote-tracking branch 'origin/shah/funding-fixes' into nicka/b…
naddison36 Oct 25, 2023
2205019
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Oct 25, 2023
6119b8e
Merge remote-tracking branch 'origin/master' into nicka/behaviour-tests
naddison36 Oct 25, 2023
b0aff22
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Oct 25, 2023
49d75b0
Most merge fixes
naddison36 Oct 25, 2023
602da88
Fix MockCurvePool math order
naddison36 Oct 25, 2023
40f8c4e
Removed unused return from CurveTwoCoinLib.remove_liquidity
naddison36 Oct 26, 2023
a51bf59
Updated BaseCurveStrategy Natspec (#1901)
naddison36 Oct 30, 2023
5825efb
Fix typo in Natspec (#1902)
naddison36 Oct 30, 2023
1ab05aa
Removed StableMath from CurveTwoCoinLib (#1903)
naddison36 Oct 30, 2023
643f1db
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Oct 31, 2023
fd329f2
Reduce queue times in 076_upgrade_fraxeth_strategy
naddison36 Oct 31, 2023
db0e0ef
Convex frxETH/WETH Strategy - OZ L-04 using function types (#1899)
naddison36 Oct 31, 2023
451e0bf
Convex frxETH/WETH Strategy - OZ M-01 fork tests (#1906)
naddison36 Nov 1, 2023
cf9cadc
Merge remote-tracking branch 'origin/master' into nicka/behaviour-tests
naddison36 Nov 1, 2023
909a6b3
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Nov 1, 2023
13bbce6
Generated latest contract diagrams
naddison36 Nov 1, 2023
ee324d3
Removed unreached checkBalance function in BaseCurveStrategy as its a…
naddison36 Nov 3, 2023
9e940d0
chore: updated BaseCurveStrategy Natspec and code comments
naddison36 Nov 6, 2023
bab03f2
Merge remote-tracking branch 'origin/master' into nicka/behaviour-tests
naddison36 Nov 6, 2023
e3bf74a
Merge remote-tracking branch 'origin/nicka/behaviour-tests' into nick…
naddison36 Nov 6, 2023
8222e0f
Updated BaseCurveStrategy Natspec and code comments
naddison36 Nov 7, 2023
1f8b2dd
Remove reference to unused library
naddison36 Nov 7, 2023
cf8c3e8
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Nov 8, 2023
323eec8
Do not run hot deploy for unit tests
naddison36 Nov 9, 2023
2fcbfc4
Removed console.log
naddison36 Nov 9, 2023
e5d9234
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Nov 9, 2023
5389268
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Nov 27, 2023
a05ad25
Added harvestable behaviour for strategies
naddison36 Nov 30, 2023
56db659
Merge remote-tracking branch 'origin/nicka/harvester-behaviour' into …
naddison36 Nov 30, 2023
fd6ea14
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Nov 30, 2023
469818d
Fix fork tests
naddison36 Nov 30, 2023
ff0a884
Fix slither
naddison36 Nov 30, 2023
a4510bb
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
naddison36 Dec 1, 2023
35e11c3
Added Balancer deposit
naddison36 Dec 4, 2023
7de9ac3
Updated Convex AMO and Balancer harvests value flows
naddison36 Dec 4, 2023
f98accd
Merge remote-tracking branch 'origin/nicka/value-flows' into nicka/co…
naddison36 Dec 5, 2023
d65c9c5
Merge remote-tracking branch 'origin/master' into nicka/convex-frxeth…
sparrowDom Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions contracts/contracts/harvest/Harvester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import { StableMath } from "../utils/StableMath.sol";
import { Governable } from "../governance/Governable.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IOracle } from "../interfaces/IOracle.sol";
import { BaseHarvester } from "./BaseHarvester.sol";
import { IStrategy } from "../interfaces/IStrategy.sol";
import { IUniswapV2Router } from "../interfaces/uniswap/IUniswapV2Router02.sol";
import "../utils/Helpers.sol";

Expand Down
2 changes: 0 additions & 2 deletions contracts/contracts/harvest/OETHHarvester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import { StableMath } from "../utils/StableMath.sol";
import { Governable } from "../governance/Governable.sol";
import { IVault } from "../interfaces/IVault.sol";
import { IOracle } from "../interfaces/IOracle.sol";
import { BaseHarvester } from "./BaseHarvester.sol";
import { IStrategy } from "../interfaces/IStrategy.sol";
import { IUniswapV2Router } from "../interfaces/uniswap/IUniswapV2Router02.sol";
import "../utils/Helpers.sol";

Expand Down
6 changes: 6 additions & 0 deletions contracts/contracts/mocks/MockMetadataToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// IERC20Metadata is used in the resolveAsset function in contracts/utils/assets.js
// We just need to import it here to make its ABI available to Hardhat
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6 changes: 3 additions & 3 deletions contracts/contracts/mocks/MocksfrxETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ contract MocksfrxETH is MintableERC20 {
address receiver,
address owner
) external returns (uint256 shares) {
_burn(owner, shares);
_burn(owner, assets);
sparrowDom marked this conversation as resolved.
Show resolved Hide resolved

ERC20(frxETH).transfer(receiver, shares);
ERC20(frxETH).transfer(receiver, assets);

assets = shares;
shares = assets;
}

function submitAndDeposit(address recipient)
Expand Down
9 changes: 3 additions & 6 deletions contracts/contracts/mocks/curve/Mock3CRV.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../MintableERC20.sol";
import { ERC20, MintableERC20 } from "../MintableERC20.sol";
import { BurnableERC20 } from "../BurnableERC20.sol";

contract Mock3CRV is MintableERC20 {
contract Mock3CRV is MintableERC20, BurnableERC20 {
constructor() ERC20("Curve.fi DAI/USDC/USDT", "3Crv") {}

function decimals() public pure override returns (uint8) {
return 18;
}

function burnFrom(address from, uint256 value) public {
_burn(from, value);
}
}
38 changes: 20 additions & 18 deletions contracts/contracts/mocks/curve/MockBooster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IRewardStaking } from "../../strategies/IRewardStaking.sol";
import { IMintableERC20, MintableERC20, ERC20 } from "../MintableERC20.sol";
import { IBurnableERC20, BurnableERC20 } from "../BurnableERC20.sol";

contract MockDepositToken is MintableERC20 {
contract MockDepositToken is MintableERC20, BurnableERC20 {
constructor() ERC20("DCVX", "CVX Deposit Token") {}
}

Expand Down Expand Up @@ -37,9 +37,13 @@ contract MockBooster {
cvx = _cvx;
}

function setPool(uint256 pid, address _lpToken) external returns (bool) {
function setPool(uint256 pid, address _lpToken)
external
returns (address rewards)
{
address token = address(new MockDepositToken());
address rewards = address(
// Deploy a new Convex Rewards Pool
rewards = address(
new MockRewardPool(pid, token, crv, cvx, address(this))
);

Expand All @@ -59,66 +63,64 @@ contract MockBooster {

address lptoken = pool.lptoken;

// hold on to the lptokens
// hold on to the Curve LP tokens
IERC20(lptoken).safeTransferFrom(msg.sender, address(this), _amount);

address token = pool.token;
if (_stake) {
//mint here and send to rewards on user behalf
// mint Convex pool LP tokens and stake in rewards contract on user behalf
IMintableERC20(token).mint(_amount);
address rewardContract = pool.crvRewards;
IERC20(token).safeApprove(rewardContract, 0);
IERC20(token).safeApprove(rewardContract, _amount);
IRewardStaking(rewardContract).stakeFor(msg.sender, _amount);
} else {
//add user balance directly
// mint Convex pool LP tokens and send to user
IMintableERC20(token).mint(_amount);
IERC20(token).transfer(msg.sender, _amount);
}
return true;
}

//deposit all lp tokens and stake
// Deposit all Curve LP tokens and stake
function depositAll(uint256 _pid, bool _stake) external returns (bool) {
address lptoken = poolInfo[_pid].lptoken;
uint256 balance = IERC20(lptoken).balanceOf(msg.sender);
deposit(_pid, balance, _stake);
return true;
}

//withdraw lp tokens
// withdraw Curve LP tokens
function _withdraw(
uint256 _pid,
uint256 _amount,
address _from,
address _to
) internal {
PoolInfo storage pool = poolInfo[_pid];
address lptoken = pool.lptoken;
address token = pool.token;

//remove lp balance
IBurnableERC20(token).burnFrom(_from, _amount);
// burn the Convex pool LP tokens
IBurnableERC20(pool.token).burnFrom(_from, _amount);

//return lp tokens
IERC20(lptoken).safeTransfer(_to, _amount);
// return the Curve LP tokens
IERC20(pool.lptoken).safeTransfer(_to, _amount);
}

//withdraw lp tokens
// withdraw Curve LP tokens
function withdraw(uint256 _pid, uint256 _amount) public returns (bool) {
_withdraw(_pid, _amount, msg.sender, msg.sender);
return true;
}

//withdraw all lp tokens
// withdraw all Curve LP tokens
function withdrawAll(uint256 _pid) public returns (bool) {
address token = poolInfo[_pid].token;
uint256 userBal = IERC20(token).balanceOf(msg.sender);
withdraw(_pid, userBal);
return true;
}

//allow reward contracts to send here and withdraw to user
// allow reward contracts to send here and withdraw to user
function withdrawTo(
uint256 _pid,
uint256 _amount,
Expand All @@ -131,7 +133,7 @@ contract MockBooster {
return true;
}

//callback from reward contract when crv is received.
// callback from reward contract when crv is received.
function rewardClaimed(
uint256 _pid,
// solhint-disable-next-line no-unused-vars
Expand Down
104 changes: 73 additions & 31 deletions contracts/contracts/mocks/curve/MockCurveAbstractMetapool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ pragma solidity ^0.8.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { IMintableERC20 } from "../MintableERC20.sol";
import { ICurvePool } from "../../strategies/ICurvePool.sol";
import { MintableERC20, IMintableERC20 } from "../MintableERC20.sol";
import { StableMath } from "../../utils/StableMath.sol";
import "../../utils/Helpers.sol";
import "../MintableERC20.sol";

abstract contract MockCurveAbstractMetapool is MintableERC20 {
using StableMath for uint256;
Expand All @@ -18,9 +16,8 @@ abstract contract MockCurveAbstractMetapool is MintableERC20 {
// Returns the same amount of LP tokens in 1e18 decimals
function add_liquidity(uint256[2] calldata _amounts, uint256 _minAmount)
external
returns (uint256)
returns (uint256 lpAmount)
{
uint256 sum = 0;
for (uint256 i = 0; i < _amounts.length; i++) {
if (_amounts[i] > 0) {
IERC20(coins[i]).transferFrom(
Expand All @@ -30,42 +27,39 @@ abstract contract MockCurveAbstractMetapool is MintableERC20 {
);
uint256 assetDecimals = Helpers.getDecimals(coins[i]);
// Convert to 1e18 and add to sum
sum += _amounts[i].scaleBy(18, assetDecimals);
lpAmount += _amounts[i].scaleBy(18, assetDecimals);
balances[i] = balances[i] + _amounts[i];
}
}
// Hacky way of simulating slippage to check _minAmount
if (sum == 29000e18) sum = 14500e18;
require(sum >= _minAmount, "Slippage ruined your day");
if (lpAmount == 29000e18) lpAmount = 14500e18;
require(lpAmount >= _minAmount, "Slippage ruined your day");
// Send LP token to sender, e.g. 3CRV
mint(sum);
transfer(msg.sender, sum);
return sum;
_mint(msg.sender, lpAmount);
}

// Dumb implementation that returns the same amount
function calc_withdraw_one_coin(uint256 _amount, int128 _index)
public
view
returns (uint256)
returns (uint256 lpAmount)
{
uint256 assetDecimals = Helpers.getDecimals(coins[uint128(_index)]);
return _amount.scaleBy(assetDecimals, 18);
lpAmount = _amount.scaleBy(assetDecimals, 18);
}

function remove_liquidity_one_coin(
uint256 _amount,
uint256 _lpAmount,
int128 _index,
// solhint-disable-next-line no-unused-vars
uint256 _minAmount
) external {
transferFrom(msg.sender, address(this), _amount);
) external returns (uint256 amount) {
_burn(msg.sender, _lpAmount);
uint256[] memory amounts = new uint256[](coins.length);
amounts[uint128(_index)] = _amount;
uint256 amount = calc_withdraw_one_coin(_amount, _index);
amounts[uint128(_index)] = _lpAmount;
amount = calc_withdraw_one_coin(_lpAmount, _index);
balances[uint128(_index)] -= amount;
IERC20(coins[uint128(_index)]).transfer(msg.sender, amount);
// solhint-disable-next-line reentrancy
balances[uint128(_index)] = balances[uint128(_index)] - amount;
}

function get_virtual_price() external pure returns (uint256) {
Expand All @@ -75,30 +69,78 @@ abstract contract MockCurveAbstractMetapool is MintableERC20 {
// solhint-disable-next-line no-unused-vars
function remove_liquidity(uint256 _amount, uint256[2] memory _min_amounts)
public
returns (uint256[2] memory amounts)
{
transferFrom(msg.sender, address(this), _amount);
_burn(msg.sender, _amount);
uint256 totalSupply = totalSupply();
for (uint256 i = 0; i < 2; i++) {
uint256 amount = (_amount / totalSupply) *
IERC20(coins[i]).balanceOf(address(this));
IERC20(coins[i]).transfer(msg.sender, amount);
// solhint-disable-next-line reentrancy
balances[i] = balances[i] - amount;
amounts[i] = totalSupply > 0
? (_amount / totalSupply) *
naddison36 marked this conversation as resolved.
Show resolved Hide resolved
IERC20(coins[i]).balanceOf(address(this))
: IERC20(coins[i]).balanceOf(address(this));
balances[i] -= amounts[i];
IERC20(coins[i]).transfer(msg.sender, amounts[i]);
}
}

function remove_liquidity_imbalance(
uint256[2] memory _amounts,
uint256 _max_burned_tokens
) public {
transferFrom(msg.sender, address(this), _max_burned_tokens);
) public returns (uint256) {
return
_remove_liquidity_imbalance(
_amounts,
_max_burned_tokens,
msg.sender
);
}

function remove_liquidity_imbalance(
uint256[2] memory _amounts,
uint256 _max_burned_tokens,
address _reveiver
) public returns (uint256) {
return
_remove_liquidity_imbalance(
_amounts,
_max_burned_tokens,
_reveiver
);
}

function _remove_liquidity_imbalance(
uint256[2] memory _amounts,
uint256 _max_burned_tokens,
address _reveiver
) internal returns (uint256 lpTokens) {
lpTokens = _max_burned_tokens;
_burn(msg.sender, lpTokens);
for (uint256 i = 0; i < _amounts.length; i++) {
balances[i] -= _amounts[i];
if (_amounts[i] > 0) {
IERC20(coins[i]).transfer(_reveiver, _amounts[i]);
}
}
}

// Dumb implementation that sums the scaled amounts
function calc_token_amount(uint256[2] memory _amounts, bool)
public
view
returns (uint256 lpTokens)
{
for (uint256 i = 0; i < _amounts.length; i++) {
IERC20(coins[i]).transfer(msg.sender, _amounts[i]);
// solhint-disable-next-line reentrancy
balances[i] = balances[i] - _amounts[i];
uint256 assetDecimals = Helpers.getDecimals(coins[i]);
// Convert to 1e18 and add to lpTokens
lpTokens += _amounts[i].scaleBy(18, assetDecimals);
}
}

/// @notice 0.02% fee
function fee() external pure returns (uint256) {
return 2000000;
}

function decimals() public pure override returns (uint8) {
return 18;
}
Expand Down
13 changes: 13 additions & 0 deletions contracts/contracts/mocks/curve/MockCurveFrxEthWethPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { MockCurveAbstractMetapool } from "./MockCurveAbstractMetapool.sol";
import "../MintableERC20.sol";

contract MockCurveFrxEthWethPool is MockCurveAbstractMetapool {
constructor(address[2] memory _coins)
ERC20("Curve.fi Factory Plain Pool: frxETH/WETH", "frxeth-ng-f")
{
coins = _coins;
}
}
2 changes: 1 addition & 1 deletion contracts/contracts/mocks/curve/MockCurveGauge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import { ICurveGauge } from "../../strategies/ICurveGauge.sol";
import { ICurveGauge } from "../../strategies/curve/ICurveGauge.sol";

contract MockCurveGauge is ICurveGauge {
mapping(address => uint256) private _balances;
Expand Down