Skip to content

Commit b238232

Browse files
authored
Abstract strategy gas improvements (#1719) (#1724)
* Abstract strategy gas improvements (#1719)
1 parent ed7ed35 commit b238232

31 files changed

+1474
-1109
lines changed

contracts/contracts/strategies/AaveStrategy.sol

Lines changed: 7 additions & 6 deletions
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

Lines changed: 2 additions & 9 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 5 additions & 8 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 6 additions & 12 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 6 additions & 10 deletions
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
/**

0 commit comments

Comments
 (0)