diff --git a/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol b/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol index 4637c4d5b5..57c3c49a9e 100644 --- a/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol +++ b/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol @@ -84,7 +84,7 @@ abstract contract BaseAuraStrategy is BaseBalancerStrategy { true // also claim reward tokens ); } - + /** * @dev Withdraw all Balancer Pool Tokens (BPT) from * the Aura rewards pool to this strategy contract. diff --git a/contracts/contracts/strategies/balancer/BaseBalancerStrategy.sol b/contracts/contracts/strategies/balancer/BaseBalancerStrategy.sol index 2ccccb1811..b94f6562ed 100644 --- a/contracts/contracts/strategies/balancer/BaseBalancerStrategy.sol +++ b/contracts/contracts/strategies/balancer/BaseBalancerStrategy.sol @@ -100,13 +100,13 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy { * This is not denominated in OUSD/ETH value of the assets in the Balancer pool. * @param _asset Address of the Vault collateral asset * @return amount the amount of vault collateral assets - * + * * IMPORTANT if this function is overridden it needs to have a whenNotInVaultContext - * modifier on it or it is susceptible to read-only re-entrancy attack + * modifier on it or it is susceptible to read-only re-entrancy attack * * @dev it is important that this function is not affected by reporting inflated * values of assets in case of any pool manipulation. Such a manipulation could easily - * exploit the protocol by: + * exploit the protocol by: * - minting OETH * - tilting Balancer pool to report higher balances of assets * - rebasing() -> all that extra token balances get distributed to OETH holders @@ -128,21 +128,6 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy { uint256 bptBalance = _getBalancerPoolTokens(); - // sum of all of the token's inverted rates - uint256 invertedRateAccumulator = 0; - // queried asset inverted rate - uint256 assetInvertedRate = 0; - uint256 assetRate = 0; - for (uint256 i = 0; i < tokens.length; ++i) { - uint256 rate = getRateProviderRate(address(tokens[i])); - uint256 rateInverted = uint256(1e18).divPrecisely(rate); - invertedRateAccumulator += rateInverted; - if (toPoolAsset(_asset) == address(tokens[i])) { - assetInvertedRate = rateInverted; - assetRate = rate; - } - } - /* To calculate the worth of queried asset in accordance with pool token * rates (provided by asset rateProvider) * - convert complete balance of BPT to underlying tokens ETH denominated amount @@ -153,11 +138,19 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy { * - divide the amount of the previous step with assetRate to convert the ETH * denominated representation to asset denominated */ - amount = ((bptBalance.mulTruncate( + amount = (bptBalance.mulTruncate( IRateProvider(platformAddress).getRate() - ) * assetInvertedRate) / invertedRateAccumulator).divPrecisely( - assetRate - ); + ) / tokens.length); + + /* If pool asset is equals _asset it means a rate provider for that asset + * exists and that asset is not necessarily pegged to a unit (ETH). + * + * Because this function returns the balance of the asset not denominated in + * ETH units we need to convert the amount to asset amount. + */ + if (toPoolAsset(_asset) == _asset) { + amount = amount.divPrecisely(getRateProviderRate(_asset)); + } } /** @@ -165,9 +158,9 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy { * Uses the Balancer pool's rate (virtual price) to convert the strategy's * Balancer Pool Tokens (BPT) to ETH value. * @return value The ETH value - * + * * IMPORTANT if this function is overridden it needs to have a whenNotInVaultContext - * modifier on it or it is susceptible to read-only re-entrancy attack + * modifier on it or it is susceptible to read-only re-entrancy attack */ function checkBalance() external diff --git a/contracts/test/strategies/balancerMetaStablePool.fork-test.js b/contracts/test/strategies/balancerMetaStablePool.fork-test.js index ce18c8db65..2ce86e789c 100644 --- a/contracts/test/strategies/balancerMetaStablePool.fork-test.js +++ b/contracts/test/strategies/balancerMetaStablePool.fork-test.js @@ -429,7 +429,7 @@ forkOnlyDescribe( ); log(`Aura BPTs before: ${formatUnits(bptBefore)}`); - const withdrawAmount = 29800; + const withdrawAmount = 29700; const withdrawAmountUnits = oethUnits(withdrawAmount.toString(), 18); await balancerREthStrategy diff --git a/contracts/utils/funding.js b/contracts/utils/funding.js index 90086b36d1..e027486433 100644 --- a/contracts/utils/funding.js +++ b/contracts/utils/funding.js @@ -159,8 +159,15 @@ const fundAccounts = async () => { const ousdCoins = [dai, usdc, usdt, tusd, ogn]; const oethCoins = [weth, rETH, stETH, frxETH]; - const allCoins = [...ousdCoins, ...oethCoins]; - + const skipOUSDCoins = !!process.env.SKIP_OUSD_COINS; + const skipOETHCoins = !!process.env.SKIP_OETH_COINS; + let allCoins = []; + if (!skipOUSDCoins) { + allCoins = [...allCoins, ...ousdCoins]; + } + if (!skipOETHCoins) { + allCoins = [...allCoins, ...oethCoins]; + } const signers = await hre.ethers.getSigners(); const addressPromises = new Array(10)