From dc07a8a7d091f876254a295fae2a9b1b04dac069 Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Fri, 1 Sep 2023 17:23:23 +1000 Subject: [PATCH] Changed Metapool to Curve pool in the AMO strategy --- .../strategies/ConvexEthMetaStrategy.sol | 88 +++--- .../docs/ConvexEthMetaStrategyHierarchy.svg | 294 +++++++++--------- .../docs/ConvexEthMetaStrategySquashed.svg | 56 ++-- 3 files changed, 219 insertions(+), 219 deletions(-) diff --git a/contracts/contracts/strategies/ConvexEthMetaStrategy.sol b/contracts/contracts/strategies/ConvexEthMetaStrategy.sol index dddba7bc25..b1620f1312 100644 --- a/contracts/contracts/strategies/ConvexEthMetaStrategy.sol +++ b/contracts/contracts/strategies/ConvexEthMetaStrategy.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.0; /** - * @title Curve Metapool Strategy - * @notice Investment strategy for investing ether in a Curve Metapool + * @title Convex Automated Market Maker (AMO) Strategy + * @notice AMO strategy for the Curve OETH/ETH pool * @author Origin Protocol Inc */ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; @@ -72,11 +72,11 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /** - * @dev Checks the Metapools balances have improved and the balances + * @dev Checks the Curve pool's balances have improved and the balances * have not tipped to the other side. */ - modifier improveMetapoolBalance() { - // Get the asset and OToken balances in the Curve Metapool + modifier improvePoolBalance() { + // Get the asset and OToken balances in the Curve pool uint256[2] memory balancesBefore = curvePool.get_balances(); // diff = ETH balance - OETH balance int256 diffBefore = int256(balancesBefore[ethCoinIndex]) - @@ -84,7 +84,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { _; - // Get the asset and OToken balances in the Curve Metapool + // Get the asset and OToken balances in the Curve pool uint256[2] memory balancesAfter = curvePool.get_balances(); // diff = ETH balance - OETH balance int256 diffAfter = int256(balancesAfter[ethCoinIndex]) - @@ -154,7 +154,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { ****************************************/ /** - * @notice Deposit WETH into the Curve ETH Metapool + * @notice Deposit WETH into the Curve pool * @param _weth Address of Wrapped ETH (WETH) contract. * @param _amount Amount of WETH to deposit. */ @@ -174,7 +174,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { emit Deposit(_weth, address(lpToken), _wethAmount); - // Get the asset and OToken balances in the Curve Metapool + // Get the asset and OToken balances in the Curve pool uint256[2] memory balances = curvePool.get_balances(); // safe to cast since min value is at least 0 uint256 oethToAdd = uint256( @@ -214,14 +214,14 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { uint256(1e18) - MAX_SLIPPAGE ); - // Do the deposit to the Curve Metapool + // Do the deposit to the Curve pool // slither-disable-next-line arbitrary-send uint256 lpDeposited = curvePool.add_liquidity{ value: _wethAmount }( _amounts, minMintAmount ); - // Deposit the Metapool LP tokens to the Convex rewards pool + // Deposit the Curve pool's LP tokens into the Convex rewards pool require( IConvexDeposits(cvxDepositorAddress).deposit( cvxDepositorPTokenId, @@ -233,7 +233,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /** - * @notice Deposit the strategy's entire balance of WETH into the Curve Metapool + * @notice Deposit the strategy's entire balance of WETH into the Curve pool */ function depositAll() external override onlyVault nonReentrant { uint256 balance = weth.balanceOf(address(this)); @@ -247,7 +247,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { ****************************************/ /** - * @notice Withdraw ETH and OETH from the Curve Metapool, burn the OETH, + * @notice Withdraw ETH and OETH from the Curve pool, burn the OETH, * convert the ETH to WETH and transfer to the recipient. * @param _recipient Address to receive withdrawn asset which is normally the Vault. * @param _weth Address of the Wrapped ETH (WETH) contract. @@ -321,7 +321,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /** - * @notice Remove all ETH and OETH from the Metapool, burn the OETH, + * @notice Remove all ETH and OETH from the Curve pool, burn the OETH, * convert the ETH to WETH and transfer to the Vault contract. */ function withdrawAll() external override onlyVaultOrGovernor nonReentrant { @@ -343,7 +343,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { IVault(vaultAddress).burnForStrategy(oethToBurn); // Get the strategy contract's ether balance. - // This includes all that was removed from the Metapool and + // This includes all that was removed from the Curve pool and // any ether that was sitting in the strategy contract before the removal. uint256 ethBalance = address(this).balance; // Convert all the strategy contract's ether to WETH and transfer to the vault. @@ -358,12 +358,12 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /*************************************** - Metapool Rebalancing + Curve pool Rebalancing ****************************************/ /** - * @notice Mint OTokens and one-sided add to the Metapool. - * This is used when the Metapool does not have enough OTokens and too many ETH. + * @notice Mint OTokens and one-sided add to the Curve pool. + * This is used when the Curve pool does not have enough OTokens and too many ETH. * The OToken/Asset, eg OETH/ETH, price with increase. * The amount of assets in the vault is unchanged. * The total supply of OTokens is increased. @@ -374,11 +374,11 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { external onlyStrategist nonReentrant - improveMetapoolBalance + improvePoolBalance { IVault(vaultAddress).mintForStrategy(_oTokens); - // Convert OETH to Metapool LP tokens + // Convert OETH to Curve pool LP tokens uint256 valueInLpTokens = (_oTokens).divPrecisely( curvePool.get_virtual_price() ); @@ -387,13 +387,13 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { uint256(1e18) - MAX_SLIPPAGE ); - // Add the minted OTokens to the Curve Metapool + // Add the minted OTokens to the Curve pool uint256 lpDeposited = curvePool.add_liquidity( [0, _oTokens], minMintAmount ); - // Deposit the Metapool LP tokens to the Convex rewards pool + // Deposit the Curve pool LP tokens to the Convex rewards pool require( IConvexDeposits(cvxDepositorAddress).deposit( cvxDepositorPTokenId, @@ -407,20 +407,20 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /** - * @notice One-sided remove of OTokens from the Metapool which are then burned. - * This is used when the Metapool has too many OTokens and not enough ETH. + * @notice One-sided remove of OTokens from the Curve pool which are then burned. + * This is used when the Curve pool has too many OTokens and not enough ETH. * The amount of assets in the vault is unchanged. * The total supply of OTokens is reduced. * The asset value of the strategy and vault is reduced. - * @param _lpTokens The amount of Metapool LP tokens to be burned for OTokens. + * @param _lpTokens The amount of Curve pool LP tokens to be burned for OTokens. */ function removeAndBurnOTokens(uint256 _lpTokens) external onlyStrategist nonReentrant - improveMetapoolBalance + improvePoolBalance { - // Withdraw Metapool LP tokens from Convex and remove OTokens from the Metapool + // Withdraw Curve pool LP tokens from Convex and remove OTokens from the Curve pool uint256 oethToBurn = _withdrawAndRemoveFromPool( _lpTokens, oethCoinIndex @@ -433,29 +433,29 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /** - * @notice One-sided remove of ETH from the Metapool, convert to WETH + * @notice One-sided remove of ETH from the Curve pool, convert to WETH * and transfer to the vault. - * This is used when the Metapool does not have enough OTokens and too many ETH. + * This is used when the Curve pool does not have enough OTokens and too many ETH. * The OToken/Asset, eg OETH/ETH, price with decrease. * The amount of assets in the vault increases. * The total supply of OTokens does not change. * The asset value of the strategy reduces. * The asset value of the vault should be close to the same. - * @param _lpTokens The amount of Metapool LP tokens to be burned for ETH. - * @dev Metapool LP tokens is used rather than WETH assets as Curve does not + * @param _lpTokens The amount of Curve pool LP tokens to be burned for ETH. + * @dev Curve pool LP tokens is used rather than WETH assets as Curve does not * have a way to accurately calculate the amount of LP tokens for a required * amount of ETH. Curve's `calc_token_amount` functioun does not include fees. * A 3rd party libary can be used that takes into account the fees, but this * is a gas intensive process. It's easier for the trusted strategist to - * caclulate the amount of Metapool LP tokens required off-chain. + * caclulate the amount of Curve pool LP tokens required off-chain. */ function removeOnlyAssets(uint256 _lpTokens) external onlyStrategist nonReentrant - improveMetapoolBalance + improvePoolBalance { - // Withdraw Metapool LP tokens from Convex and remove ETH from the Metapool + // Withdraw Curve pool LP tokens from Convex and remove ETH from the Curve pool uint256 ethAmount = _withdrawAndRemoveFromPool(_lpTokens, ethCoinIndex); // Convert ETH to WETH and transfer to the vault @@ -469,20 +469,20 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } /** - * @dev Remove Metapool LP tokens from the Convex pool and - * do a one-sided remove of ETH or OETH from the Metapool. - * @param _lpTokens The amount of Metapool LP tokens to be removed from the Convex pool. - * @param coinIndex The index of the coin to be removed from the Metapool. 0 = ETH, 1 = OETH. - * @return coinsRemoved The amount of ETH or OETH removed from the Metapool. + * @dev Remove Curve pool LP tokens from the Convex pool and + * do a one-sided remove of ETH or OETH from the Curve pool. + * @param _lpTokens The amount of Curve pool LP tokens to be removed from the Convex pool. + * @param coinIndex The index of the coin to be removed from the Curve pool. 0 = ETH, 1 = OETH. + * @return coinsRemoved The amount of ETH or OETH removed from the Curve pool. */ function _withdrawAndRemoveFromPool(uint256 _lpTokens, uint128 coinIndex) internal returns (uint256 coinsRemoved) { - // Withdraw Metapool LP tokens from Convex pool + // Withdraw Curve pool LP tokens from Convex pool _lpWithdraw(_lpTokens); - // Convert Metapool LP tokens to ETH value + // Convert Curve pool LP tokens to ETH value uint256 valueInEth = _lpTokens.mulTruncate( curvePool.get_virtual_price() ); @@ -491,7 +491,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { uint256(1e18) - MAX_SLIPPAGE ); - // Remove just the ETH from the Metapool + // Remove just the ETH from the Curve pool coinsRemoved = curvePool.remove_liquidity_one_coin( _lpTokens, int128(coinIndex), @@ -594,13 +594,13 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { {} function _approveBase() internal { - // Approve Curve Metapool for OETH (required for adding liquidity) + // Approve Curve pool for OETH (required for adding liquidity) // No approval is needed for ETH // slither-disable-next-line unused-return oeth.approve(platformAddress, type(uint256).max); - // Approve Convex deposit contract to transfer Curve Metapool LP tokens - // This is needed for deposits if Metapool LP tokens into the Convex rewards pool + // Approve Convex deposit contract to transfer Curve pool LP tokens + // This is needed for deposits if Curve pool LP tokens into the Convex rewards pool // slither-disable-next-line unused-return lpToken.approve(cvxDepositorAddress, type(uint256).max); } diff --git a/contracts/docs/ConvexEthMetaStrategyHierarchy.svg b/contracts/docs/ConvexEthMetaStrategyHierarchy.svg index df2a707a0d..edb0f24d44 100644 --- a/contracts/docs/ConvexEthMetaStrategyHierarchy.svg +++ b/contracts/docs/ConvexEthMetaStrategyHierarchy.svg @@ -4,224 +4,224 @@ - + UmlClassDiagram - + 7 - -Governable -../contracts/governance/Governable.sol + +Governable +../contracts/governance/Governable.sol 40 - -<<Interface>> -IVault -../contracts/interfaces/IVault.sol + +<<Interface>> +IVault +../contracts/interfaces/IVault.sol - + -177 - -VaultStorage -../contracts/vault/VaultStorage.sol +180 + +VaultStorage +../contracts/vault/VaultStorage.sol - + -40->177 - - +40->180 + + 41 - -<<Interface>> -IWETH9 -../contracts/interfaces/IWETH9.sol + +<<Interface>> +IWETH9 +../contracts/interfaces/IWETH9.sol - + -128 - -ConvexEthMetaStrategy -../contracts/strategies/ConvexEthMetaStrategy.sol +130 + +ConvexEthMetaStrategy +../contracts/strategies/ConvexEthMetaStrategy.sol - + -128->40 - - +130->40 + + - + -128->41 - - +130->41 + + - + -141 - -<<Interface>> -IConvexDeposits -../contracts/strategies/IConvexDeposits.sol +144 + +<<Interface>> +IConvexDeposits +../contracts/strategies/IConvexDeposits.sol - + -128->141 - - +130->144 + + - + -142 - -<<Interface>> -ICurveETHPoolV1 -../contracts/strategies/ICurveETHPoolV1.sol +145 + +<<Interface>> +ICurveETHPoolV1 +../contracts/strategies/ICurveETHPoolV1.sol - + -128->142 - - +130->145 + + - + -146 - -<<Interface>> -IRewardStaking -../contracts/strategies/IRewardStaking.sol +149 + +<<Interface>> +IRewardStaking +../contracts/strategies/IRewardStaking.sol - + -128->146 - - +130->149 + + - + -165 - -<<Abstract>> -InitializableAbstractStrategy -../contracts/utils/InitializableAbstractStrategy.sol +168 + +<<Abstract>> +InitializableAbstractStrategy +../contracts/utils/InitializableAbstractStrategy.sol - + -128->165 - - +130->168 + + - + -157 - -OUSD -../contracts/token/OUSD.sol +160 + +OUSD +../contracts/token/OUSD.sol - + -157->7 - - +160->7 + + - + -164 - -<<Abstract>> -Initializable -../contracts/utils/Initializable.sol +167 + +<<Abstract>> +Initializable +../contracts/utils/Initializable.sol - + -157->164 - - +160->167 + + - + -167 - -<<Abstract>> -InitializableERC20Detailed -../contracts/utils/InitializableERC20Detailed.sol +170 + +<<Abstract>> +InitializableERC20Detailed +../contracts/utils/InitializableERC20Detailed.sol - + -157->167 - - +160->170 + + - + -165->7 - - +168->7 + + - + -165->40 - - +168->40 + + - + -165->164 - - +168->167 + + - + -165->165 - - +168->168 + + - + -339 - -<<Interface>> -IERC20 -../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol +342 + +<<Interface>> +IERC20 +../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol - + -165->339 - - +168->342 + + - + -167->339 - - +170->342 + + - + -177->7 - - +180->7 + + - + -177->157 - - +180->160 + + - + -177->164 - - +180->167 + + diff --git a/contracts/docs/ConvexEthMetaStrategySquashed.svg b/contracts/docs/ConvexEthMetaStrategySquashed.svg index 6d39cc74cd..52c4a7dbe6 100644 --- a/contracts/docs/ConvexEthMetaStrategySquashed.svg +++ b/contracts/docs/ConvexEthMetaStrategySquashed.svg @@ -9,9 +9,9 @@ UmlClassDiagram - + -128 +130 ConvexEthMetaStrategy ../contracts/strategies/ConvexEthMetaStrategy.sol @@ -25,26 +25,26 @@   reentryStatusPosition: bytes32 <<Governable>>   _deprecated_platformAddress: address <<InitializableAbstractStrategy>>   _deprecated_vaultAddress: address <<InitializableAbstractStrategy>> -   _reserved: int256[98] <<InitializableAbstractStrategy>> -   _deprecated_cvxDepositorAddress: address <<ConvexEthMetaStrategy>> -   _deprecated_cvxRewardStaker: address <<ConvexEthMetaStrategy>> -   _deprecated_cvxDepositorPTokenId: uint256 <<ConvexEthMetaStrategy>> -   _deprecated_curvePool: address <<ConvexEthMetaStrategy>> -   _deprecated_lpToken: address <<ConvexEthMetaStrategy>> -   _deprecated_oeth: address <<ConvexEthMetaStrategy>> -   _deprecated_weth: address <<ConvexEthMetaStrategy>> -   _deprecated_oethCoinIndex: uint128 <<ConvexEthMetaStrategy>> -   _deprecated_ethCoinIndex: uint128 <<ConvexEthMetaStrategy>> -Internal: -   assetsMapped: address[] <<InitializableAbstractStrategy>> -Public: -   _NOT_ENTERED: uint256 <<Governable>> -   _ENTERED: uint256 <<Governable>> -   platformAddress: address <<InitializableAbstractStrategy>> -   vaultAddress: address <<InitializableAbstractStrategy>> -   assetToPToken: mapping(address=>address) <<InitializableAbstractStrategy>> -   _deprecated_rewardTokenAddress: address <<InitializableAbstractStrategy>> -   _deprecated_rewardLiquidationThreshold: uint256 <<InitializableAbstractStrategy>> +   _deprecated_rewardTokenAddress: address <<InitializableAbstractStrategy>> +   _deprecated_rewardLiquidationThreshold: uint256 <<InitializableAbstractStrategy>> +   _reserved: int256[98] <<InitializableAbstractStrategy>> +   _deprecated_cvxDepositorAddress: address <<ConvexEthMetaStrategy>> +   _deprecated_cvxRewardStaker: address <<ConvexEthMetaStrategy>> +   _deprecated_cvxDepositorPTokenId: uint256 <<ConvexEthMetaStrategy>> +   _deprecated_curvePool: address <<ConvexEthMetaStrategy>> +   _deprecated_lpToken: address <<ConvexEthMetaStrategy>> +   _deprecated_oeth: address <<ConvexEthMetaStrategy>> +   _deprecated_weth: address <<ConvexEthMetaStrategy>> +   _deprecated_oethCoinIndex: uint128 <<ConvexEthMetaStrategy>> +   _deprecated_ethCoinIndex: uint128 <<ConvexEthMetaStrategy>> +Internal: +   assetsMapped: address[] <<InitializableAbstractStrategy>> +Public: +   _NOT_ENTERED: uint256 <<Governable>> +   _ENTERED: uint256 <<Governable>> +   platformAddress: address <<InitializableAbstractStrategy>> +   vaultAddress: address <<InitializableAbstractStrategy>> +   assetToPToken: mapping(address=>address) <<InitializableAbstractStrategy>>   harvesterAddress: address <<InitializableAbstractStrategy>>   rewardTokenAddresses: address[] <<InitializableAbstractStrategy>>   MAX_SLIPPAGE: uint256 <<ConvexEthMetaStrategy>> @@ -71,8 +71,8 @@    _abstractSetPToken(_asset: address, _pToken: address) <<ConvexEthMetaStrategy>>    _deposit(_weth: address, _wethAmount: uint256) <<ConvexEthMetaStrategy>>    calcTokenToBurn(_wethAmount: uint256): (lpToBurn: uint256) <<ConvexEthMetaStrategy>> -    _lpWithdraw(_wethAmount: uint256) <<ConvexEthMetaStrategy>> -    _approveAsset(_asset: address) <<ConvexEthMetaStrategy>> +    _withdrawAndRemoveFromPool(_lpTokens: uint256, coinIndex: uint128): (coinsRemoved: uint256) <<ConvexEthMetaStrategy>> +    _lpWithdraw(_wethAmount: uint256) <<ConvexEthMetaStrategy>>    _approveBase() <<ConvexEthMetaStrategy>>    _max(a: int256, b: int256): int256 <<ConvexEthMetaStrategy>> External: @@ -93,9 +93,9 @@    withdrawAll() <<onlyVaultOrGovernor, nonReentrant>> <<ConvexEthMetaStrategy>>    supportsAsset(_asset: address): bool <<ConvexEthMetaStrategy>>    initialize(_rewardTokenAddresses: address[], _assets: address[]) <<onlyGovernor, initializer>> <<ConvexEthMetaStrategy>> -    removeAndBurnOTokens(_lpTokens: uint256) <<onlyStrategist, improveMetapoolBalance>> <<ConvexEthMetaStrategy>> -    mintAndAddOTokens(_oTokens: uint256) <<onlyStrategist, improveMetapoolBalance>> <<ConvexEthMetaStrategy>> -    removeOnlyAssets(_lpTokens: uint256) <<onlyStrategist, improveMetapoolBalance>> <<ConvexEthMetaStrategy>> +    mintAndAddOTokens(_oTokens: uint256) <<onlyStrategist, nonReentrant, improvePoolBalance>> <<ConvexEthMetaStrategy>> +    removeAndBurnOTokens(_lpTokens: uint256) <<onlyStrategist, nonReentrant, improvePoolBalance>> <<ConvexEthMetaStrategy>> +    removeOnlyAssets(_lpTokens: uint256) <<onlyStrategist, nonReentrant, improvePoolBalance>> <<ConvexEthMetaStrategy>> Public:    <<event>> PendingGovernorshipTransfer(previousGovernor: address, newGovernor: address) <<Governable>>    <<event>> GovernorshipTransferred(previousGovernor: address, newGovernor: address) <<Governable>> @@ -114,7 +114,7 @@    <<modifier>> onlyVaultOrGovernor() <<InitializableAbstractStrategy>>    <<modifier>> onlyVaultOrGovernorOrStrategist() <<InitializableAbstractStrategy>>    <<modifier>> onlyStrategist() <<ConvexEthMetaStrategy>> -    <<modifier>> improveMetapoolBalance() <<ConvexEthMetaStrategy>> +    <<modifier>> improvePoolBalance() <<ConvexEthMetaStrategy>>    constructor() <<Governable>>    governor(): address <<Governable>>    isGovernor(): bool <<Governable>>