Skip to content

Commit

Permalink
rename variable, add test for double withdrawal. Gas optimisation whe…
Browse files Browse the repository at this point in the history
…n withdrawingAll with no BPT
  • Loading branch information
sparrowDom committed Dec 6, 2023
1 parent 8fb75ec commit 6dbb9cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ contract BalancerMetaPoolStrategy is BaseAuraStrategy {
}
}

uint256 minBPT = _getBPTExpected(
uint256 minBpt = _getBPTExpected(

Check warning on line 177 in contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol#L177

Added line #L177 was not covered by tests
strategyAssetsToPoolAssets,
strategyAssetAmountsToPoolAssetAmounts
);
uint256 minBPTwDeviation = minBPT.mulTruncate(
uint256 minBptWDeviation = minBpt.mulTruncate(

Check warning on line 181 in contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol#L181

Added line #L181 was not covered by tests
1e18 - maxDepositDeviation
);

Expand All @@ -192,7 +192,7 @@ contract BalancerMetaPoolStrategy is BaseAuraStrategy {
bytes memory userData = abi.encode(
IBalancerVault.MetaStablePoolJoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT,
_getUserDataEncodedAmounts(amountsIn),
minBPTwDeviation
minBptWDeviation
);

IBalancerVault.JoinPoolRequest memory request = IBalancerVault
Expand Down Expand Up @@ -471,9 +471,15 @@ contract BalancerMetaPoolStrategy is BaseAuraStrategy {
// STEP 1 - Withdraw all Balancer Pool Tokens (BPT) from Aura to this strategy contract
_lpWithdrawAll();
// Get the BPTs withdrawn from Aura plus any that were already in this strategy contract
uint256 BPTtoWithdraw = IERC20(platformAddress).balanceOf(
uint256 bptToWithdraw = IERC20(platformAddress).balanceOf(

Check warning on line 474 in contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol#L474

Added line #L474 was not covered by tests
address(this)
);

// Do not proceed with withdrawal if there is nothing to withdraw
if (bptToWithdraw == 0) {
return;

Check warning on line 480 in contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol#L480

Added line #L480 was not covered by tests
}

uint256[] memory minAmountsOut = new uint256[](_poolAssets.length);

Check warning on line 483 in contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/balancer/BalancerMetaPoolStrategy.sol#L483

Added line #L483 was not covered by tests

// STEP 2 - Withdraw the Balancer pool assets from the pool
Expand All @@ -495,7 +501,7 @@ contract BalancerMetaPoolStrategy is BaseAuraStrategy {
isRecoveryModeWithdrawal
? RECOVERY_MODE_EXIT_KIND
: _exactBptInTokensOutIndex(),
BPTtoWithdraw
bptToWithdraw
);

if (isRecoveryModeWithdrawal) {
Expand Down
9 changes: 9 additions & 0 deletions contracts/test/strategies/balancerMetaStablePool.fork-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,15 @@ describe("ForkTest: Balancer MetaStablePool wstETH/WETH Strategy", function () {
expect(wethBalanceDiff).to.be.gte(await units("15", weth), 1);
expect(stEthBalanceDiff).to.be.gte(await units("15", stETH), 1);
});

it("Should be able to call withdrawAll twice (second time musn't revert)", async function () {
const { oethVault, balancerWstEthStrategy } = fixture;

const oethVaultSigner = await impersonateAndFund(oethVault.address);

await balancerWstEthStrategy.connect(oethVaultSigner).withdrawAll();
await balancerWstEthStrategy.connect(oethVaultSigner).withdrawAll();
});
});

describe("Harvest rewards", function () {
Expand Down

0 comments on commit 6dbb9cd

Please sign in to comment.