@@ -100,13 +100,13 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy {
100
100
* This is not denominated in OUSD/ETH value of the assets in the Balancer pool.
101
101
* @param _asset Address of the Vault collateral asset
102
102
* @return amount the amount of vault collateral assets
103
- *
103
+ *
104
104
* 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
106
106
*
107
107
* @dev it is important that this function is not affected by reporting inflated
108
108
* values of assets in case of any pool manipulation. Such a manipulation could easily
109
- * exploit the protocol by:
109
+ * exploit the protocol by:
110
110
* - minting OETH
111
111
* - tilting Balancer pool to report higher balances of assets
112
112
* - rebasing() -> all that extra token balances get distributed to OETH holders
@@ -128,21 +128,6 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy {
128
128
129
129
uint256 bptBalance = _getBalancerPoolTokens ();
130
130
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
-
146
131
/* To calculate the worth of queried asset in accordance with pool token
147
132
* rates (provided by asset rateProvider)
148
133
* - convert complete balance of BPT to underlying tokens ETH denominated amount
@@ -153,21 +138,29 @@ abstract contract BaseBalancerStrategy is InitializableAbstractStrategy {
153
138
* - divide the amount of the previous step with assetRate to convert the ETH
154
139
* denominated representation to asset denominated
155
140
*/
156
- amount = (( bptBalance.mulTruncate (
141
+ amount = (bptBalance.mulTruncate (
157
142
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
+ }
161
154
}
162
155
163
156
/**
164
157
* @notice Returns the value of all assets managed by this strategy.
165
158
* Uses the Balancer pool's rate (virtual price) to convert the strategy's
166
159
* Balancer Pool Tokens (BPT) to ETH value.
167
160
* @return value The ETH value
168
- *
161
+ *
169
162
* 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
171
164
*/
172
165
function checkBalance ()
173
166
external
0 commit comments