Skip to content

Commit 75329db

Browse files
Balancer review changes (#1726)
* Generated contract docs * Refactor Balancer storage variables * Small Balancer changes * Natspec updates Added missing licensing getPoolAssets gas optimized * Updated generated Balancer strategy contract diagrams * fix contract linter * Removed restrictions on tests * Small gas improvements Fixed Slither * Change BalancerError version * Updated constant names Addresses to use checksum format * JS lint tasks * Updated Balancer and Aura pool id constants * Removed getRateProviderRate as it wasn't being used Refactored to remove poolAssetsMapped storage variable * Updated OETH Contracts diagrams Generated new Balancer contract diagrams * Fix failing test * Fix merge conflict * Restored getRateProviderRate * Natspec updates Added toPoolAsset override * Removed unused getRateProviderRate * Natspec updates Gas optimization of InitializableAbstractStrategy * Abstract strategy gas improvements (#1719) * Refactor base strategy to use immutables * Fixed strategy deployments in 001_core and fixtures * Generated new strategy diagrams * Deploy rETH instead of the stETH Balancer MetaStable Pool * removed unused Aura config * Balancer fork tests * Added check that BPT amount equals Aura LP amount Added rETH conversion to ETH value * Updated balancer strat fork tests * Updated Balancer fork tests * Added optional deposit with multiple assets to the strategy * Single asset deposit to use multi asset deposit * Added optional checkBalance to Balancer strategy * Added checkBalance() to BaseBalancerStrategy * Fix slither Fix curve HH task * Added multi-asset withdraw to balancer strategy * Fix multi-asset withdraw * Updated Balancer and Vault diagrams * Fix js linter * Fixed checkBalance of rETH asset in Balancer strategy * Only wrap assets if amount > 0 Added depositAll fork test for Balancer strat * Removed Vault changes for multi-asset strategy support * Updated generated docs * Add tests for wstETH/WETH Balancer pool (#1725) * Split deployment and fix fixtures * Deposit tests for wstETH/WETH pool * Add withdraw test * prettier * remove .only in fork tests --------- Co-authored-by: Shahul Hameed <[email protected]>
1 parent c77a296 commit 75329db

File tree

70 files changed

+4401
-2281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4401
-2281
lines changed

contracts/contracts/governance/Governable.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
/**
5-
* @title OUSD Governable Contract
5+
* @title Base for contracts that are managed by the Origin Protocol's Governor.
66
* @dev Copy of the openzeppelin Ownable.sol contract with nomenclature change
77
* from owner to governor and renounce methods removed. Does not use
88
* Context.sol like Ownable.sol does for simplification.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
interface IRETH {
5+
function getEthValue(uint256 _rethAmount) external view returns (uint256);
6+
7+
function getRethValue(uint256 _ethAmount) external view returns (uint256);
8+
9+
function totalSupply() external view returns (uint256);
10+
11+
function balanceOf(address account) external view returns (uint256);
12+
13+
function transfer(address recipient, uint256 amount)
14+
external
15+
returns (bool);
16+
17+
function allowance(address owner, address spender)
18+
external
19+
view
20+
returns (uint256);
21+
22+
function approve(address spender, uint256 amount) external returns (bool);
23+
24+
function transferFrom(
25+
address sender,
26+
address recipient,
27+
uint256 amount
28+
) external returns (bool);
29+
30+
function name() external view returns (string memory);
31+
32+
function symbol() external view returns (string memory);
33+
34+
function decimals() external view returns (uint8);
35+
}

contracts/contracts/interfaces/IWstETH.sol

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: MIT
12
pragma solidity ^0.8.0;
23

34
interface IWstETH {

contracts/contracts/proxies/Proxies.sol

+11-2
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,18 @@ contract OETHMorphoAaveStrategyProxy is InitializeGovernedUpgradeabilityProxy {
158158
}
159159

160160
/**
161-
* @notice OETHBalancerMetaPoolStrategyProxy delegates calls to a BalancerMetaPoolStrategy implementation
161+
* @notice OETHBalancerMetaPoolrEthStrategyProxy delegates calls to a BalancerMetaPoolStrategy implementation
162162
*/
163-
contract OETHBalancerMetaPoolWstEthWethStrategyProxy is
163+
contract OETHBalancerMetaPoolrEthStrategyProxy is
164+
InitializeGovernedUpgradeabilityProxy
165+
{
166+
167+
}
168+
169+
/**
170+
* @notice OETHBalancerMetaPoolwstEthStrategyProxy delegates calls to a BalancerMetaPoolStrategy implementation
171+
*/
172+
contract OETHBalancerMetaPoolwstEthStrategyProxy is
164173
InitializeGovernedUpgradeabilityProxy
165174
{
166175

contracts/contracts/strategies/AaveStrategy.sol

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ contract AaveStrategy is InitializableAbstractStrategy {
2222
IAaveIncentivesController public incentivesController;
2323
IAaveStakedToken public stkAave;
2424

25+
/**
26+
* @param _stratConfig The platform and OToken vault addresses
27+
*/
28+
constructor(BaseStrategyConfig memory _stratConfig)
29+
InitializableAbstractStrategy(_stratConfig)
30+
{}
31+
2532
/**
2633
* Initializer for setting up strategy internal state. This overrides the
2734
* InitializableAbstractStrategy initializer as AAVE needs several extra
2835
* addresses for the rewards program.
29-
* @param _platformAddress Address of the AAVE pool
30-
* @param _vaultAddress Address of the vault
3136
* @param _rewardTokenAddresses Address of the AAVE token
3237
* @param _assets Addresses of supported assets
3338
* @param _pTokens Platform Token corresponding addresses
3439
* @param _incentivesAddress Address of the AAVE incentives controller
3540
* @param _stkAaveAddress Address of the stkAave contract
3641
*/
3742
function initialize(
38-
address _platformAddress, // AAVE pool
39-
address _vaultAddress,
4043
address[] calldata _rewardTokenAddresses, // AAVE
4144
address[] calldata _assets,
4245
address[] calldata _pTokens,
@@ -46,8 +49,6 @@ contract AaveStrategy is InitializableAbstractStrategy {
4649
incentivesController = IAaveIncentivesController(_incentivesAddress);
4750
stkAave = IAaveStakedToken(_stkAaveAddress);
4851
InitializableAbstractStrategy._initialize(
49-
_platformAddress,
50-
_vaultAddress,
5152
_rewardTokenAddresses,
5253
_assets,
5354
_pTokens

contracts/contracts/strategies/BaseConvexMetaStrategy.sol

+2-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ import { Helpers } from "../utils/Helpers.sol";
1818
abstract contract BaseConvexMetaStrategy is BaseCurveStrategy {
1919
using StableMath for uint256;
2020
using SafeERC20 for IERC20;
21+
2122
event MaxWithdrawalSlippageUpdated(
2223
uint256 _prevMaxSlippagePercentage,
2324
uint256 _newMaxSlippagePercentage
2425
);
2526

2627
// used to circumvent the stack too deep issue
2728
struct InitConfig {
28-
address platformAddress; //Address of the Curve 3pool
29-
address vaultAddress; //Address of the vault
3029
address cvxDepositorAddress; //Address of the Convex depositor(AKA booster) for this pool
3130
address metapoolAddress; //Address of the Curve MetaPool
3231
address metapoolMainToken; //Address of Main metapool token
@@ -82,13 +81,7 @@ abstract contract BaseConvexMetaStrategy is BaseCurveStrategy {
8281
metapoolAssets = [metapool.coins(0), metapool.coins(1)];
8382
crvCoinIndex = _getMetapoolCoinIndex(pTokenAddress);
8483
mainCoinIndex = _getMetapoolCoinIndex(initConfig.metapoolMainToken);
85-
super._initialize(
86-
initConfig.platformAddress,
87-
initConfig.vaultAddress,
88-
_rewardTokenAddresses,
89-
_assets,
90-
_pTokens
91-
);
84+
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
9285
_approveBase();
9386
}
9487

contracts/contracts/strategies/CompoundStrategy.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ pragma solidity ^0.8.0;
99
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
1010

1111
import { ICERC20 } from "./ICompound.sol";
12-
import { BaseCompoundStrategy } from "./BaseCompoundStrategy.sol";
12+
import { BaseCompoundStrategy, InitializableAbstractStrategy } from "./BaseCompoundStrategy.sol";
1313
import { IComptroller } from "../interfaces/IComptroller.sol";
1414
import { IERC20 } from "../utils/InitializableAbstractStrategy.sol";
1515

1616
contract CompoundStrategy is BaseCompoundStrategy {
1717
using SafeERC20 for IERC20;
1818
event SkippedWithdrawal(address asset, uint256 amount);
1919

20+
constructor(BaseStrategyConfig memory _stratConfig)
21+
InitializableAbstractStrategy(_stratConfig)
22+
{}
23+
2024
/**
2125
* @dev Collect accumulated COMP and send to Harvester.
2226
*/

contracts/contracts/strategies/ConvexEthMetaStrategy.sol

+5-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy {
3838
// used to circumvent the stack too deep issue
3939
struct InitializeConfig {
4040
address curvePoolAddress; //Address of the Curve pool
41-
address vaultAddress; //Address of the vault
4241
address cvxDepositorAddress; //Address of the Convex depositor(AKA booster) for this pool
4342
address oethAddress; //Address of OETH token
4443
address cvxRewardStakerAddress; //Address of the CVX rewards staker
4544
address curvePoolLpToken; //Address of metapool LP token
4645
uint256 cvxDepositorPTokenId; //Pid of the pool referred to by Depositor and staker
4746
}
4847

48+
constructor(BaseStrategyConfig memory _stratConfig)
49+
InitializableAbstractStrategy(_stratConfig)
50+
{}
51+
4952
/**
5053
* Initializer for setting up strategy internal state. This overrides the
5154
* InitializableAbstractStrategy initializer as Curve strategies don't fit
@@ -75,13 +78,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy {
7578
ethCoinIndex = uint128(_getCoinIndex(ETH_ADDRESS));
7679
oethCoinIndex = uint128(_getCoinIndex(initConfig.oethAddress));
7780

78-
super._initialize(
79-
initConfig.curvePoolAddress,
80-
initConfig.vaultAddress,
81-
_rewardTokenAddresses,
82-
_assets,
83-
_pTokens
84-
);
81+
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
8582

8683
/* needs to be called after super._initialize so that the platformAddress
8784
* is correctly set

contracts/contracts/strategies/ConvexGeneralizedMetaStrategy.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import "@openzeppelin/contracts/utils/Strings.sol";
1212
import { IRewardStaking } from "./IRewardStaking.sol";
1313
import { IConvexDeposits } from "./IConvexDeposits.sol";
1414
import { ICurvePool } from "./ICurvePool.sol";
15-
import { IERC20 } from "./BaseCurveStrategy.sol";
15+
import { IERC20, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
1616
import { BaseConvexMetaStrategy } from "./BaseConvexMetaStrategy.sol";
1717
import { StableMath } from "../utils/StableMath.sol";
1818

1919
contract ConvexGeneralizedMetaStrategy is BaseConvexMetaStrategy {
2020
using StableMath for uint256;
2121
using SafeERC20 for IERC20;
2222

23+
constructor(BaseStrategyConfig memory _stratConfig)
24+
InitializableAbstractStrategy(_stratConfig)
25+
{}
26+
2327
/* Take 3pool LP and deposit it to metapool. Take the LP from metapool
2428
* and deposit them to Convex.
2529
*/

contracts/contracts/strategies/ConvexOUSDMetaStrategy.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import "@openzeppelin/contracts/utils/math/Math.sol";
1313
import { IRewardStaking } from "./IRewardStaking.sol";
1414
import { IConvexDeposits } from "./IConvexDeposits.sol";
1515
import { ICurvePool } from "./ICurvePool.sol";
16-
import { IERC20 } from "./BaseCurveStrategy.sol";
16+
import { IERC20, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
1717
import { BaseConvexMetaStrategy } from "./BaseConvexMetaStrategy.sol";
1818
import { StableMath } from "../utils/StableMath.sol";
1919
import { IVault } from "../interfaces/IVault.sol";
@@ -22,6 +22,10 @@ contract ConvexOUSDMetaStrategy is BaseConvexMetaStrategy {
2222
using StableMath for uint256;
2323
using SafeERC20 for IERC20;
2424

25+
constructor(BaseStrategyConfig memory _stratConfig)
26+
InitializableAbstractStrategy(_stratConfig)
27+
{}
28+
2529
/* Take 3pool LP and mint the corresponding amount of ousd. Deposit and stake that to
2630
* ousd Curve Metapool. Take the LP from metapool and deposit them to Convex.
2731
*/

contracts/contracts/strategies/ConvexStrategy.sol

+6-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
1111
import { ICurvePool } from "./ICurvePool.sol";
1212
import { IRewardStaking } from "./IRewardStaking.sol";
1313
import { IConvexDeposits } from "./IConvexDeposits.sol";
14-
import { IERC20, BaseCurveStrategy } from "./BaseCurveStrategy.sol";
14+
import { IERC20, BaseCurveStrategy, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
1515
import { StableMath } from "../utils/StableMath.sol";
1616
import { Helpers } from "../utils/Helpers.sol";
1717

@@ -32,12 +32,14 @@ contract ConvexStrategy is BaseCurveStrategy {
3232
address public _deprecated_cvxRewardTokenAddress;
3333
uint256 internal cvxDepositorPTokenId;
3434

35+
constructor(BaseStrategyConfig memory _stratConfig)
36+
InitializableAbstractStrategy(_stratConfig)
37+
{}
38+
3539
/**
3640
* Initializer for setting up strategy internal state. This overrides the
3741
* InitializableAbstractStrategy initializer as Curve strategies don't fit
3842
* well within that abstraction.
39-
* @param _platformAddress Address of the Curve 3pool
40-
* @param _vaultAddress Address of the vault
4143
* @param _rewardTokenAddresses Address of CRV & CVX
4244
* @param _assets Addresses of supported assets. MUST be passed in the same
4345
* order as returned by coins on the pool contract, i.e.
@@ -48,8 +50,6 @@ contract ConvexStrategy is BaseCurveStrategy {
4850
* @param _cvxDepositorPTokenId Pid of the pool referred to by Depositor and staker
4951
*/
5052
function initialize(
51-
address _platformAddress, // 3Pool address
52-
address _vaultAddress,
5353
address[] calldata _rewardTokenAddresses, // CRV + CVX
5454
address[] calldata _assets,
5555
address[] calldata _pTokens,
@@ -65,13 +65,7 @@ contract ConvexStrategy is BaseCurveStrategy {
6565
cvxDepositorPTokenId = _cvxDepositorPTokenId;
6666
pTokenAddress = _pTokens[0];
6767

68-
super._initialize(
69-
_platformAddress,
70-
_vaultAddress,
71-
_rewardTokenAddresses,
72-
_assets,
73-
_pTokens
74-
);
68+
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
7569
_approveBase();
7670
}
7771

contracts/contracts/strategies/FraxETHStrategy.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ pragma solidity ^0.8.0;
88
*/
99
import { IERC4626 } from "../../lib/openzeppelin/interfaces/IERC4626.sol";
1010
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
11-
import { IERC20 } from "../utils/InitializableAbstractStrategy.sol";
1211
import { IWETH9 } from "../interfaces/IWETH9.sol";
1312
import { IFraxETHMinter } from "../interfaces/IFraxETHMinter.sol";
14-
import { Generalized4626Strategy } from "./Generalized4626Strategy.sol";
13+
import { Generalized4626Strategy, IERC20 } from "./Generalized4626Strategy.sol";
1514

1615
contract FraxETHStrategy is Generalized4626Strategy {
1716
using SafeERC20 for IERC20;
@@ -21,6 +20,10 @@ contract FraxETHStrategy is Generalized4626Strategy {
2120
IFraxETHMinter public constant fraxETHMinter =
2221
IFraxETHMinter(0xbAFA44EFE7901E04E39Dad13167D089C559c1138);
2322

23+
constructor(BaseStrategyConfig memory _stratConfig)
24+
Generalized4626Strategy(_stratConfig)
25+
{}
26+
2427
function _deposit(address _asset, uint256 _amount) internal override {
2528
require(_amount > 0, "Must deposit something");
2629

contracts/contracts/strategies/Generalized4626Strategy.sol

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ contract Generalized4626Strategy is InitializableAbstractStrategy {
1919
// For future use
2020
uint256[50] private __gap;
2121

22+
constructor(BaseStrategyConfig memory _stratConfig)
23+
InitializableAbstractStrategy(_stratConfig)
24+
{}
25+
2226
/**
2327
* @dev Deposit assets by converting them to shares
2428
* @param _asset Address of asset to deposit

contracts/contracts/strategies/MorphoAaveStrategy.sol

+6-10
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,22 @@ contract MorphoAaveStrategy is InitializableAbstractStrategy {
1919
using SafeERC20 for IERC20;
2020
using StableMath for uint256;
2121

22+
constructor(BaseStrategyConfig memory _stratConfig)
23+
InitializableAbstractStrategy(_stratConfig)
24+
{}
25+
2226
/**
2327
* @dev Initialize function, to set up initial internal state
24-
* @param _vaultAddress Address of the Vault
2528
* @param _rewardTokenAddresses Address of reward token for platform
2629
* @param _assets Addresses of initial supported assets
2730
* @param _pTokens Platform Token corresponding addresses
2831
*/
2932
function initialize(
30-
address _vaultAddress,
3133
address[] calldata _rewardTokenAddresses,
3234
address[] calldata _assets,
3335
address[] calldata _pTokens
34-
) external onlyGovernor initializer {
35-
super._initialize(
36-
MORPHO,
37-
_vaultAddress,
38-
_rewardTokenAddresses,
39-
_assets,
40-
_pTokens
41-
);
36+
) external override onlyGovernor initializer {
37+
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
4238
}
4339

4440
/**

contracts/contracts/strategies/MorphoCompoundStrategy.sol

+7-12
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ pragma solidity ^0.8.0;
77
* @author Origin Protocol Inc
88
*/
99
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
10-
import { BaseCompoundStrategy } from "./BaseCompoundStrategy.sol";
11-
import { IERC20 } from "../utils/InitializableAbstractStrategy.sol";
10+
import { IERC20, BaseCompoundStrategy, InitializableAbstractStrategy } from "./BaseCompoundStrategy.sol";
1211
import { IMorpho } from "../interfaces/morpho/IMorpho.sol";
1312
import { ILens } from "../interfaces/morpho/ILens.sol";
1413
import { StableMath } from "../utils/StableMath.sol";
@@ -20,26 +19,22 @@ contract MorphoCompoundStrategy is BaseCompoundStrategy {
2019
using SafeERC20 for IERC20;
2120
using StableMath for uint256;
2221

22+
constructor(BaseStrategyConfig memory _stratConfig)
23+
InitializableAbstractStrategy(_stratConfig)
24+
{}
25+
2326
/**
2427
* @dev Initialize function, to set up initial internal state
25-
* @param _vaultAddress Address of the Vault
2628
* @param _rewardTokenAddresses Address of reward token for platform
2729
* @param _assets Addresses of initial supported assets
2830
* @param _pTokens Platform Token corresponding addresses
2931
*/
3032
function initialize(
31-
address _vaultAddress,
3233
address[] calldata _rewardTokenAddresses,
3334
address[] calldata _assets,
3435
address[] calldata _pTokens
35-
) external onlyGovernor initializer {
36-
super._initialize(
37-
MORPHO,
38-
_vaultAddress,
39-
_rewardTokenAddresses,
40-
_assets,
41-
_pTokens
42-
);
36+
) external override onlyGovernor initializer {
37+
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
4338
}
4439

4540
/**

0 commit comments

Comments
 (0)