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 fork tests #1727

Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 14 additions & 3 deletions contracts/contracts/strategies/balancer/BaseAuraStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pragma solidity ^0.8.0;
* @title OETH Base Balancer Abstract Strategy
* @author Origin Protocol Inc
*/

import "@openzeppelin/contracts/utils/math/Math.sol";
import { BaseBalancerStrategy } from "./BaseBalancerStrategy.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IRateProvider } from "../../interfaces/balancer/IRateProvider.sol";
Expand Down Expand Up @@ -78,8 +80,14 @@ abstract contract BaseAuraStrategy is BaseBalancerStrategy {
* @param numBPTTokens Number of Balancer Pool Tokens (BPT) to withdraw
*/
function _lpWithdraw(uint256 numBPTTokens) internal virtual override {
// Get all the strategy's BPTs in Aura
// maxRedeem is implemented as balanceOf(address) in Aura
uint256 maxBPTTokens = IERC4626(auraRewardPoolAddress).maxRedeem(
address(this)
);

IRewardStaking(auraRewardPoolAddress).withdrawAndUnwrap(
numBPTTokens,
Math.min(numBPTTokens, maxBPTTokens),
Copy link
Member

Choose a reason for hiding this comment

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

I do understand rationale for this, to make it more resilient, but I don't think it is an ok change. I think the caller of this function would expect for AURA to withdraw numBPTTokens or fail if it unable to withdraw all.

true // also claim reward tokens
);
}
Expand All @@ -89,7 +97,9 @@ abstract contract BaseAuraStrategy is BaseBalancerStrategy {
* the Aura rewards pool to this strategy contract.
*/
function _lpWithdrawAll() internal virtual override {
uint256 bptBalance = IERC4626(auraRewardPoolAddress).balanceOf(
// Get all the strategy's BPTs in Aura
// maxRedeem is implemented as balanceOf(address) in Aura
uint256 bptBalance = IERC4626(auraRewardPoolAddress).maxRedeem(
address(this)
);

Expand Down Expand Up @@ -123,7 +133,8 @@ abstract contract BaseAuraStrategy is BaseBalancerStrategy {
{
balancerPoolTokens =
IERC20(platformAddress).balanceOf(address(this)) +
IERC4626(auraRewardPoolAddress).balanceOf(address(this));
// maxRedeem is implemented as balanceOf(address) in Aura
IERC4626(auraRewardPoolAddress).maxRedeem(address(this));
Copy link
Member

Choose a reason for hiding this comment

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

}

function _approveBase() internal virtual override {
Expand Down
38 changes: 31 additions & 7 deletions contracts/test/_fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const defaultFixture = deployments.createFixture(async () => {
LUSDMetaStrategy,
oethHarvester,
oethDripper,
oethZapper,
swapper,
mockSwapper,
swapper1Inch,
Expand Down Expand Up @@ -297,6 +298,8 @@ const defaultFixture = deployments.createFixture(async () => {
oethDripperProxy.address
);

oethZapper = await ethers.getContract("OETHZapper");

// Replace OracelRouter to disable staleness
const dMockOracleRouterNoStale = await deployWithConfirmation(
"MockOracleRouterNoStale"
Expand Down Expand Up @@ -558,6 +561,7 @@ const defaultFixture = deployments.createFixture(async () => {
ConvexEthMetaStrategy,
oethDripper,
oethHarvester,
oethZapper,
swapper,
mockSwapper,
swapper1Inch,
Expand Down Expand Up @@ -834,18 +838,20 @@ async function convexVaultFixture() {
/**
* Configure a Vault with the balancerREthStrategy
*/
function balancerREthFixtureSetup() {
function balancerREthFixtureSetup(config = { defaultStrategy: true }) {
return deployments.createFixture(async () => {
const fixture = await defaultFixture();
const { oethVault, timelock, weth, reth, balancerREthStrategy, josh } =
fixture;

await oethVault
.connect(timelock)
.setAssetDefaultStrategy(reth.address, balancerREthStrategy.address);
await oethVault
.connect(timelock)
.setAssetDefaultStrategy(weth.address, balancerREthStrategy.address);
if (config.defaultStrategy) {
await oethVault
.connect(timelock)
.setAssetDefaultStrategy(reth.address, balancerREthStrategy.address);
await oethVault
.connect(timelock)
.setAssetDefaultStrategy(weth.address, balancerREthStrategy.address);
}

fixture.rEthBPT = await ethers.getContractAt(
"IERC20Metadata",
Expand All @@ -854,12 +860,30 @@ function balancerREthFixtureSetup() {
);
fixture.balancerREthPID = balancer_rETH_WETH_PID;

fixture.auraPool = await ethers.getContractAt(
"IERC4626",
addresses.mainnet.rETH_WETH_AuraRewards
);

fixture.balancerVault = await ethers.getContractAt(
"IBalancerVault",
addresses.mainnet.balancerVault,
josh
);

// Get some rETH from most loaded contracts/wallets
await impersonateAndFundAddress(
addresses.mainnet.rETH,
[
"0xCc9EE9483f662091a1de4795249E24aC0aC2630f",
"0xC6424e862f1462281B0a5FAc078e4b63006bDEBF",
"0x7d6149aD9A573A6E2Ca6eBf7D4897c1B766841B4",
"0x7C5aaA2a20b01df027aD032f7A768aC015E77b86",
"0x1BeE69b7dFFfA4E2d53C2a2Df135C388AD25dCD2",
],
josh.getAddress()
);

return fixture;
});
}
Expand Down
Loading