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

Balancer review changes #1726

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
05cc1bc
Generated contract docs
naddison36 Jul 25, 2023
0df54bf
Refactor Balancer storage variables
naddison36 Jul 25, 2023
8a1e6df
Small Balancer changes
naddison36 Jul 25, 2023
451b3cc
Natspec updates
naddison36 Jul 25, 2023
debb826
Updated generated Balancer strategy contract diagrams
naddison36 Jul 25, 2023
1cd2763
fix contract linter
naddison36 Jul 25, 2023
066a331
Removed restrictions on tests
naddison36 Jul 25, 2023
6644176
Small gas improvements
naddison36 Jul 25, 2023
51e2a1a
Change BalancerError version
shahthepro Jul 25, 2023
718ad10
Updated constant names
naddison36 Jul 25, 2023
faf0611
Merge branch 'nicka/balancer-sfrxETH-stETH-rETH' of github.com:Origin…
naddison36 Jul 25, 2023
c692575
JS lint tasks
naddison36 Jul 25, 2023
daeb5be
Updated Balancer and Aura pool id constants
naddison36 Jul 25, 2023
4b5ea06
Removed getRateProviderRate as it wasn't being used
naddison36 Jul 25, 2023
ee0d8aa
Updated OETH Contracts diagrams
naddison36 Jul 25, 2023
534f091
Fix failing test
shahthepro Jul 25, 2023
ad5a137
Fix merge conflict
shahthepro Jul 25, 2023
8f205a5
Merge remote-tracking branch 'origin/nicka/balancer-sfrxETH-stETH-rET…
naddison36 Jul 25, 2023
aba5c27
Restored getRateProviderRate
naddison36 Jul 25, 2023
bd4eae8
Natspec updates
naddison36 Jul 25, 2023
67ea12f
Removed unused getRateProviderRate
naddison36 Jul 25, 2023
26b5fd2
Natspec updates
naddison36 Jul 26, 2023
732d60b
Abstract strategy gas improvements (#1719)
naddison36 Jul 26, 2023
2fd0260
Deploy rETH instead of the stETH Balancer MetaStable Pool
naddison36 Jul 27, 2023
d593738
removed unused Aura config
naddison36 Jul 27, 2023
eff92a0
Balancer fork tests
naddison36 Jul 27, 2023
7194e44
Added check that BPT amount equals Aura LP amount
naddison36 Jul 28, 2023
cb4d46e
Updated balancer strat fork tests
naddison36 Jul 28, 2023
9270c3b
Updated Balancer fork tests
naddison36 Jul 28, 2023
acd7cb8
Added optional deposit with multiple assets to the strategy
naddison36 Jul 28, 2023
809d4b1
Single asset deposit to use multi asset deposit
naddison36 Jul 28, 2023
2563d67
Added optional checkBalance to Balancer strategy
naddison36 Jul 28, 2023
7f808d0
Added checkBalance() to BaseBalancerStrategy
naddison36 Jul 28, 2023
d3ef14a
Fix slither
naddison36 Jul 28, 2023
344cfe1
Added multi-asset withdraw to balancer strategy
naddison36 Jul 30, 2023
0c37ba9
Fix multi-asset withdraw
naddison36 Jul 31, 2023
7ee53e5
Updated Balancer and Vault diagrams
naddison36 Jul 31, 2023
c4b712e
Fix js linter
naddison36 Jul 31, 2023
fb68e6c
Fixed checkBalance of rETH asset in Balancer strategy
naddison36 Jul 31, 2023
49dee14
Only wrap assets if amount > 0
naddison36 Jul 31, 2023
9f274d3
Removed Vault changes for multi-asset strategy support
naddison36 Jul 31, 2023
d60fe7e
Updated generated docs
naddison36 Jul 31, 2023
cd71860
Add tests for wstETH/WETH Balancer pool (#1725)
shahthepro Jul 31, 2023
0f7ab81
prettier
naddison36 Jul 31, 2023
ece1a85
remove .only in fork tests
naddison36 Jul 31, 2023
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
2 changes: 1 addition & 1 deletion contracts/contracts/governance/Governable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

/**
* @title OUSD Governable Contract
* @title Base for contracts that are managed by the Origin Protocol's Governor.
* @dev Copy of the openzeppelin Ownable.sol contract with nomenclature change
* from owner to governor and renounce methods removed. Does not use
* Context.sol like Ownable.sol does for simplification.
Expand Down
4 changes: 4 additions & 0 deletions contracts/contracts/interfaces/IERC20Details.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can delete this file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can be deleted. I was using it in a Hardhat test as I needed to access an asset's decimals but that is no longer being used.


import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
35 changes: 35 additions & 0 deletions contracts/contracts/interfaces/IRETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IRETH {
function getEthValue(uint256 _rethAmount) external view returns (uint256);

function getRethValue(uint256 _ethAmount) external view returns (uint256);

function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

function transfer(address recipient, uint256 amount)
external
returns (bool);

function allowance(address owner, address spender)
external
view
returns (uint256);

function approve(address spender, uint256 amount) external returns (bool);

function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint8);
}
1 change: 1 addition & 0 deletions contracts/contracts/interfaces/IWstETH.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IWstETH {
Expand Down
13 changes: 11 additions & 2 deletions contracts/contracts/proxies/Proxies.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,18 @@ contract OETHMorphoAaveStrategyProxy is InitializeGovernedUpgradeabilityProxy {
}

/**
* @notice OETHBalancerMetaPoolStrategyProxy delegates calls to a BalancerMetaPoolStrategy implementation
* @notice OETHBalancerMetaPoolrEthStrategyProxy delegates calls to a BalancerMetaPoolStrategy implementation
*/
contract OETHBalancerMetaPoolWstEthWethStrategyProxy is
contract OETHBalancerMetaPoolrEthStrategyProxy is
InitializeGovernedUpgradeabilityProxy
{

}

/**
* @notice OETHBalancerMetaPoolwstEthStrategyProxy delegates calls to a BalancerMetaPoolStrategy implementation
*/
contract OETHBalancerMetaPoolwstEthStrategyProxy is
InitializeGovernedUpgradeabilityProxy
{

Expand Down
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
Loading