Skip to content

Commit 346d949

Browse files
authored
Balancer fixes (#1734)
* prettier * adjust how checkBalance is calculated
1 parent 39a7b3f commit 346d949

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

contracts/contracts/strategies/balancer/BaseAuraStrategy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ abstract contract BaseAuraStrategy is BaseBalancerStrategy {
8484
true // also claim reward tokens
8585
);
8686
}
87-
87+
8888
/**
8989
* @dev Withdraw all Balancer Pool Tokens (BPT) from
9090
* the Aura rewards pool to this strategy contract.

contracts/contracts/strategies/balancer/BaseBalancerStrategy.sol

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy {
100100
* This is not denominated in OUSD/ETH value of the assets in the Balancer pool.
101101
* @param _asset Address of the Vault collateral asset
102102
* @return amount the amount of vault collateral assets
103-
*
103+
*
104104
* IMPORTANT if this function is overridden it needs to have a whenNotInVaultContext
105-
* modifier on it or it is susceptible to read-only re-entrancy attack
105+
* modifier on it or it is susceptible to read-only re-entrancy attack
106106
*
107107
* @dev it is important that this function is not affected by reporting inflated
108108
* values of assets in case of any pool manipulation. Such a manipulation could easily
109-
* exploit the protocol by:
109+
* exploit the protocol by:
110110
* - minting OETH
111111
* - tilting Balancer pool to report higher balances of assets
112112
* - rebasing() -> all that extra token balances get distributed to OETH holders
@@ -128,21 +128,6 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy {
128128

129129
uint256 bptBalance = _getBalancerPoolTokens();
130130

131-
// sum of all of the token's inverted rates
132-
uint256 invertedRateAccumulator = 0;
133-
// queried asset inverted rate
134-
uint256 assetInvertedRate = 0;
135-
uint256 assetRate = 0;
136-
for (uint256 i = 0; i < tokens.length; ++i) {
137-
uint256 rate = getRateProviderRate(address(tokens[i]));
138-
uint256 rateInverted = uint256(1e18).divPrecisely(rate);
139-
invertedRateAccumulator += rateInverted;
140-
if (toPoolAsset(_asset) == address(tokens[i])) {
141-
assetInvertedRate = rateInverted;
142-
assetRate = rate;
143-
}
144-
}
145-
146131
/* To calculate the worth of queried asset in accordance with pool token
147132
* rates (provided by asset rateProvider)
148133
* - convert complete balance of BPT to underlying tokens ETH denominated amount
@@ -153,21 +138,29 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy {
153138
* - divide the amount of the previous step with assetRate to convert the ETH
154139
* denominated representation to asset denominated
155140
*/
156-
amount = ((bptBalance.mulTruncate(
141+
amount = (bptBalance.mulTruncate(
157142
IRateProvider(platformAddress).getRate()
158-
) * assetInvertedRate) / invertedRateAccumulator).divPrecisely(
159-
assetRate
160-
);
143+
) / tokens.length);
144+
145+
/* If pool asset is equals _asset it means a rate provider for that asset
146+
* exists and that asset is not necessarily pegged to a unit (ETH).
147+
*
148+
* Because this function returns the balance of the asset not denominated in
149+
* ETH units we need to convert the amount to asset amount.
150+
*/
151+
if (toPoolAsset(_asset) == _asset) {
152+
amount = amount.divPrecisely(getRateProviderRate(_asset));
153+
}
161154
}
162155

163156
/**
164157
* @notice Returns the value of all assets managed by this strategy.
165158
* Uses the Balancer pool's rate (virtual price) to convert the strategy's
166159
* Balancer Pool Tokens (BPT) to ETH value.
167160
* @return value The ETH value
168-
*
161+
*
169162
* IMPORTANT if this function is overridden it needs to have a whenNotInVaultContext
170-
* modifier on it or it is susceptible to read-only re-entrancy attack
163+
* modifier on it or it is susceptible to read-only re-entrancy attack
171164
*/
172165
function checkBalance()
173166
external

contracts/test/strategies/balancerMetaStablePool.fork-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ forkOnlyDescribe(
429429
);
430430
log(`Aura BPTs before: ${formatUnits(bptBefore)}`);
431431

432-
const withdrawAmount = 29800;
432+
const withdrawAmount = 29700;
433433
const withdrawAmountUnits = oethUnits(withdrawAmount.toString(), 18);
434434

435435
await balancerREthStrategy

contracts/utils/funding.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,15 @@ const fundAccounts = async () => {
159159

160160
const ousdCoins = [dai, usdc, usdt, tusd, ogn];
161161
const oethCoins = [weth, rETH, stETH, frxETH];
162-
const allCoins = [...ousdCoins, ...oethCoins];
163-
162+
const skipOUSDCoins = !!process.env.SKIP_OUSD_COINS;
163+
const skipOETHCoins = !!process.env.SKIP_OETH_COINS;
164+
let allCoins = [];
165+
if (!skipOUSDCoins) {
166+
allCoins = [...allCoins, ...ousdCoins];
167+
}
168+
if (!skipOETHCoins) {
169+
allCoins = [...allCoins, ...oethCoins];
170+
}
164171
const signers = await hre.ethers.getSigners();
165172

166173
const addressPromises = new Array(10)

0 commit comments

Comments
 (0)