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

Abstract strategy gas improvements #1719

Merged
Merged
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
13 changes: 7 additions & 6 deletions contracts/contracts/strategies/AaveStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ contract AaveStrategy is InitializableAbstractStrategy {
IAaveIncentivesController public incentivesController;
IAaveStakedToken public stkAave;

/**
* @param _stratConfig The platform and OToken vault addresses
*/
constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* Initializer for setting up strategy internal state. This overrides the
* InitializableAbstractStrategy initializer as AAVE needs several extra
* addresses for the rewards program.
* @param _platformAddress Address of the AAVE pool
* @param _vaultAddress Address of the vault
* @param _rewardTokenAddresses Address of the AAVE token
* @param _assets Addresses of supported assets
* @param _pTokens Platform Token corresponding addresses
* @param _incentivesAddress Address of the AAVE incentives controller
* @param _stkAaveAddress Address of the stkAave contract
*/
function initialize(
address _platformAddress, // AAVE pool
address _vaultAddress,
address[] calldata _rewardTokenAddresses, // AAVE
address[] calldata _assets,
address[] calldata _pTokens,
Expand All @@ -46,8 +49,6 @@ contract AaveStrategy is InitializableAbstractStrategy {
incentivesController = IAaveIncentivesController(_incentivesAddress);
stkAave = IAaveStakedToken(_stkAaveAddress);
InitializableAbstractStrategy._initialize(
_platformAddress,
_vaultAddress,
_rewardTokenAddresses,
_assets,
_pTokens
Expand Down
11 changes: 2 additions & 9 deletions contracts/contracts/strategies/BaseConvexMetaStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import { Helpers } from "../utils/Helpers.sol";
abstract contract BaseConvexMetaStrategy is BaseCurveStrategy {
using StableMath for uint256;
using SafeERC20 for IERC20;

event MaxWithdrawalSlippageUpdated(
uint256 _prevMaxSlippagePercentage,
uint256 _newMaxSlippagePercentage
);

// used to circumvent the stack too deep issue
struct InitConfig {
address platformAddress; //Address of the Curve 3pool
address vaultAddress; //Address of the vault
address cvxDepositorAddress; //Address of the Convex depositor(AKA booster) for this pool
address metapoolAddress; //Address of the Curve MetaPool
address metapoolMainToken; //Address of Main metapool token
Expand Down Expand Up @@ -82,13 +81,7 @@ abstract contract BaseConvexMetaStrategy is BaseCurveStrategy {
metapoolAssets = [metapool.coins(0), metapool.coins(1)];
crvCoinIndex = _getMetapoolCoinIndex(pTokenAddress);
mainCoinIndex = _getMetapoolCoinIndex(initConfig.metapoolMainToken);
super._initialize(
initConfig.platformAddress,
initConfig.vaultAddress,
_rewardTokenAddresses,
_assets,
_pTokens
);
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
_approveBase();
}

Expand Down
6 changes: 5 additions & 1 deletion contracts/contracts/strategies/CompoundStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ pragma solidity ^0.8.0;
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import { ICERC20 } from "./ICompound.sol";
import { BaseCompoundStrategy } from "./BaseCompoundStrategy.sol";
import { BaseCompoundStrategy, InitializableAbstractStrategy } from "./BaseCompoundStrategy.sol";
import { IComptroller } from "../interfaces/IComptroller.sol";
import { IERC20 } from "../utils/InitializableAbstractStrategy.sol";

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

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* @dev Collect accumulated COMP and send to Harvester.
*/
Expand Down
13 changes: 5 additions & 8 deletions contracts/contracts/strategies/ConvexEthMetaStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy {
// used to circumvent the stack too deep issue
struct InitializeConfig {
address curvePoolAddress; //Address of the Curve pool
address vaultAddress; //Address of the vault
address cvxDepositorAddress; //Address of the Convex depositor(AKA booster) for this pool
address oethAddress; //Address of OETH token
address cvxRewardStakerAddress; //Address of the CVX rewards staker
address curvePoolLpToken; //Address of metapool LP token
uint256 cvxDepositorPTokenId; //Pid of the pool referred to by Depositor and staker
}

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* Initializer for setting up strategy internal state. This overrides the
* InitializableAbstractStrategy initializer as Curve strategies don't fit
Expand Down Expand Up @@ -75,13 +78,7 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy {
ethCoinIndex = uint128(_getCoinIndex(ETH_ADDRESS));
oethCoinIndex = uint128(_getCoinIndex(initConfig.oethAddress));

super._initialize(
initConfig.curvePoolAddress,
initConfig.vaultAddress,
_rewardTokenAddresses,
_assets,
_pTokens
);
super._initialize(_rewardTokenAddresses, _assets, _pTokens);

/* needs to be called after super._initialize so that the platformAddress
* is correctly set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import "@openzeppelin/contracts/utils/Strings.sol";
import { IRewardStaking } from "./IRewardStaking.sol";
import { IConvexDeposits } from "./IConvexDeposits.sol";
import { ICurvePool } from "./ICurvePool.sol";
import { IERC20 } from "./BaseCurveStrategy.sol";
import { IERC20, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
import { BaseConvexMetaStrategy } from "./BaseConvexMetaStrategy.sol";
import { StableMath } from "../utils/StableMath.sol";

contract ConvexGeneralizedMetaStrategy is BaseConvexMetaStrategy {
using StableMath for uint256;
using SafeERC20 for IERC20;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/* Take 3pool LP and deposit it to metapool. Take the LP from metapool
* and deposit them to Convex.
*/
Expand Down
6 changes: 5 additions & 1 deletion contracts/contracts/strategies/ConvexOUSDMetaStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "@openzeppelin/contracts/utils/math/Math.sol";
import { IRewardStaking } from "./IRewardStaking.sol";
import { IConvexDeposits } from "./IConvexDeposits.sol";
import { ICurvePool } from "./ICurvePool.sol";
import { IERC20 } from "./BaseCurveStrategy.sol";
import { IERC20, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
import { BaseConvexMetaStrategy } from "./BaseConvexMetaStrategy.sol";
import { StableMath } from "../utils/StableMath.sol";
import { IVault } from "../interfaces/IVault.sol";
Expand All @@ -22,6 +22,10 @@ contract ConvexOUSDMetaStrategy is BaseConvexMetaStrategy {
using StableMath for uint256;
using SafeERC20 for IERC20;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/* Take 3pool LP and mint the corresponding amount of ousd. Deposit and stake that to
* ousd Curve Metapool. Take the LP from metapool and deposit them to Convex.
*/
Expand Down
18 changes: 6 additions & 12 deletions contracts/contracts/strategies/ConvexStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
import { ICurvePool } from "./ICurvePool.sol";
import { IRewardStaking } from "./IRewardStaking.sol";
import { IConvexDeposits } from "./IConvexDeposits.sol";
import { IERC20, BaseCurveStrategy } from "./BaseCurveStrategy.sol";
import { IERC20, BaseCurveStrategy, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
import { StableMath } from "../utils/StableMath.sol";
import { Helpers } from "../utils/Helpers.sol";

Expand All @@ -32,12 +32,14 @@ contract ConvexStrategy is BaseCurveStrategy {
address public _deprecated_cvxRewardTokenAddress;
uint256 internal cvxDepositorPTokenId;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* Initializer for setting up strategy internal state. This overrides the
* InitializableAbstractStrategy initializer as Curve strategies don't fit
* well within that abstraction.
* @param _platformAddress Address of the Curve 3pool
* @param _vaultAddress Address of the vault
* @param _rewardTokenAddresses Address of CRV & CVX
* @param _assets Addresses of supported assets. MUST be passed in the same
* order as returned by coins on the pool contract, i.e.
Expand All @@ -48,8 +50,6 @@ contract ConvexStrategy is BaseCurveStrategy {
* @param _cvxDepositorPTokenId Pid of the pool referred to by Depositor and staker
*/
function initialize(
address _platformAddress, // 3Pool address
address _vaultAddress,
address[] calldata _rewardTokenAddresses, // CRV + CVX
address[] calldata _assets,
address[] calldata _pTokens,
Expand All @@ -65,13 +65,7 @@ contract ConvexStrategy is BaseCurveStrategy {
cvxDepositorPTokenId = _cvxDepositorPTokenId;
pTokenAddress = _pTokens[0];

super._initialize(
_platformAddress,
_vaultAddress,
_rewardTokenAddresses,
_assets,
_pTokens
);
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
_approveBase();
}

Expand Down
7 changes: 5 additions & 2 deletions contracts/contracts/strategies/FraxETHStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ pragma solidity ^0.8.0;
*/
import { IERC4626 } from "../../lib/openzeppelin/interfaces/IERC4626.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "../utils/InitializableAbstractStrategy.sol";
import { IWETH9 } from "../interfaces/IWETH9.sol";
import { IFraxETHMinter } from "../interfaces/IFraxETHMinter.sol";
import { Generalized4626Strategy } from "./Generalized4626Strategy.sol";
import { Generalized4626Strategy, IERC20 } from "./Generalized4626Strategy.sol";

contract FraxETHStrategy is Generalized4626Strategy {
using SafeERC20 for IERC20;
Expand All @@ -21,6 +20,10 @@ contract FraxETHStrategy is Generalized4626Strategy {
IFraxETHMinter public constant fraxETHMinter =
IFraxETHMinter(0xbAFA44EFE7901E04E39Dad13167D089C559c1138);

constructor(BaseStrategyConfig memory _stratConfig)
Generalized4626Strategy(_stratConfig)
{}

function _deposit(address _asset, uint256 _amount) internal override {
require(_amount > 0, "Must deposit something");

Expand Down
4 changes: 4 additions & 0 deletions contracts/contracts/strategies/Generalized4626Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ contract Generalized4626Strategy is InitializableAbstractStrategy {
// For future use
uint256[50] private __gap;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* @dev Deposit assets by converting them to shares
* @param _asset Address of asset to deposit
Expand Down
16 changes: 6 additions & 10 deletions contracts/contracts/strategies/MorphoAaveStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,22 @@ contract MorphoAaveStrategy is InitializableAbstractStrategy {
using SafeERC20 for IERC20;
using StableMath for uint256;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* @dev Initialize function, to set up initial internal state
* @param _vaultAddress Address of the Vault
* @param _rewardTokenAddresses Address of reward token for platform
* @param _assets Addresses of initial supported assets
* @param _pTokens Platform Token corresponding addresses
*/
function initialize(
address _vaultAddress,
address[] calldata _rewardTokenAddresses,
address[] calldata _assets,
address[] calldata _pTokens
) external onlyGovernor initializer {
super._initialize(
MORPHO,
_vaultAddress,
_rewardTokenAddresses,
_assets,
_pTokens
);
) external override onlyGovernor initializer {
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
}

/**
Expand Down
19 changes: 7 additions & 12 deletions contracts/contracts/strategies/MorphoCompoundStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ pragma solidity ^0.8.0;
* @author Origin Protocol Inc
*/
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { BaseCompoundStrategy } from "./BaseCompoundStrategy.sol";
import { IERC20 } from "../utils/InitializableAbstractStrategy.sol";
import { IERC20, BaseCompoundStrategy, InitializableAbstractStrategy } from "./BaseCompoundStrategy.sol";
import { IMorpho } from "../interfaces/morpho/IMorpho.sol";
import { ILens } from "../interfaces/morpho/ILens.sol";
import { StableMath } from "../utils/StableMath.sol";
Expand All @@ -20,26 +19,22 @@ contract MorphoCompoundStrategy is BaseCompoundStrategy {
using SafeERC20 for IERC20;
using StableMath for uint256;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* @dev Initialize function, to set up initial internal state
* @param _vaultAddress Address of the Vault
* @param _rewardTokenAddresses Address of reward token for platform
* @param _assets Addresses of initial supported assets
* @param _pTokens Platform Token corresponding addresses
*/
function initialize(
address _vaultAddress,
address[] calldata _rewardTokenAddresses,
address[] calldata _assets,
address[] calldata _pTokens
) external onlyGovernor initializer {
super._initialize(
MORPHO,
_vaultAddress,
_rewardTokenAddresses,
_assets,
_pTokens
);
) external override onlyGovernor initializer {
super._initialize(_rewardTokenAddresses, _assets, _pTokens);
}

/**
Expand Down
18 changes: 6 additions & 12 deletions contracts/contracts/strategies/ThreePoolStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
import { ICurveGauge } from "./ICurveGauge.sol";
import { ICurvePool } from "./ICurvePool.sol";
import { ICRVMinter } from "./ICRVMinter.sol";
import { IERC20, BaseCurveStrategy } from "./BaseCurveStrategy.sol";
import { IERC20, BaseCurveStrategy, InitializableAbstractStrategy } from "./BaseCurveStrategy.sol";
import { StableMath } from "../utils/StableMath.sol";
import { Helpers } from "../utils/Helpers.sol";

Expand All @@ -29,12 +29,14 @@ contract ThreePoolStrategy is BaseCurveStrategy {
address internal crvGaugeAddress;
address internal crvMinterAddress;

constructor(BaseStrategyConfig memory _stratConfig)
InitializableAbstractStrategy(_stratConfig)
{}

/**
* Initializer for setting up strategy internal state. This overrides the
* InitializableAbstractStrategy initializer as Curve strategies don't fit
* well within that abstraction.
* @param _platformAddress Address of the Curve 3pool
* @param _vaultAddress Address of the vault
* @param _rewardTokenAddress Address of CRV
* @param _assets Addresses of supported assets. MUST be passed in the same
* order as returned by coins on the pool contract, i.e.
Expand All @@ -44,8 +46,6 @@ contract ThreePoolStrategy is BaseCurveStrategy {
* @param _crvMinterAddress Address of the CRV minter for rewards
*/
function initialize(
address _platformAddress, // 3Pool address
address _vaultAddress,
address[] calldata _rewardTokenAddress, // CRV
address[] calldata _assets,
address[] calldata _pTokens,
Expand All @@ -58,13 +58,7 @@ contract ThreePoolStrategy is BaseCurveStrategy {
crvGaugeAddress = _crvGaugeAddress;
crvMinterAddress = _crvMinterAddress;
pTokenAddress = _pTokens[0];
super._initialize(
_platformAddress,
_vaultAddress,
_rewardTokenAddress,
_assets,
_pTokens
);
super._initialize(_rewardTokenAddress, _assets, _pTokens);
_approveBase();
}

Expand Down
Loading