@@ -28,7 +28,10 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
2828 // parameters
2929 IPriceFeedOracle public override priceFeedOracle;
3030 address public swapOperator;
31- uint96 public swapValue;
31+
32+ // SwapOperator assets
33+ uint32 public assetsInSwapOperatorBitmap;
34+ uint public assetInSwapOperator;
3235
3336 /* constants */
3437
@@ -102,13 +105,13 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
102105
103106 /* ========== ASSET RELATED VIEW FUNCTIONS ========== */
104107
105- function getAssetValueInEth (address assetAddress ) internal view returns (uint ) {
108+ function getAssetValueInEth (address assetAddress , uint assetAmountInSwapOperator ) internal view returns (uint ) {
106109
107- uint assetBalance;
110+ uint assetBalance = assetAmountInSwapOperator ;
108111
109112 if (assetAddress.code.length != 0 ) {
110113 try IERC20 (assetAddress).balanceOf (address (this )) returns (uint balance ) {
111- assetBalance = balance;
114+ assetBalance + = balance;
112115 } catch {
113116 // If balanceOf reverts consider it 0
114117 }
@@ -127,17 +130,29 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
127130 ///
128131 function getPoolValueInEth () public override view returns (uint ) {
129132
130- uint total = address (this ).balance + swapValue;
133+ uint total = address (this ).balance;
134+
131135 uint assetCount = assets.length ;
136+ uint _assetsInSwapOperatorBitmap = assetsInSwapOperatorBitmap;
132137
133- // Skip ETH (index 0)
134- for ( uint i = 1 ; i < assetCount; i ++ ) {
138+ for ( uint i = 0 ; i < assetCount; i ++ ) {
139+ Asset memory asset = assets[i];
135140
136- if (assets[i].isAbandoned) {
141+ if (asset.isAbandoned) {
142+ continue ;
143+ }
144+
145+ uint assetAmountInSwapOperator = isAssetInSwapOperator (i, _assetsInSwapOperatorBitmap)
146+ ? assetInSwapOperator
147+ : 0 ;
148+
149+ // check if the asset is ETH and skip the oracle call
150+ if (i == 0 ) {
151+ total += assetAmountInSwapOperator;
137152 continue ;
138153 }
139154
140- total += getAssetValueInEth (assets[i] .assetAddress);
155+ total += getAssetValueInEth (asset .assetAddress, assetAmountInSwapOperator );
141156 }
142157
143158 return total;
@@ -156,6 +171,32 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
156171 return swapDetails[assetAddress];
157172 }
158173
174+ function getAssetId (address assetAddress ) public view returns (uint ) {
175+
176+ uint assetCount = assets.length ;
177+ for (uint i = 0 ; i < assetCount; i++ ) {
178+ if (assets[i].assetAddress == assetAddress) {
179+ return i;
180+ }
181+ }
182+
183+ revert AssetNotFound ();
184+ }
185+
186+ function isAssetInSwapOperator (uint _assetId , uint _assetsInSwapOperatorBitmap ) internal pure returns (bool ) {
187+
188+ if (
189+ // there are assets in the swap operator
190+ _assetsInSwapOperatorBitmap != 0 &&
191+ // asset id is not in the swap operator assets
192+ ((1 << _assetId) & _assetsInSwapOperatorBitmap == 0 )
193+ ) {
194+ return false ;
195+ }
196+
197+ return true ;
198+ }
199+
159200 /* ========== ASSET RELATED MUTATIVE FUNCTIONS ========== */
160201
161202 function addAsset (
@@ -232,7 +273,7 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
232273 return ;
233274 }
234275
235- revert ( " Pool: Asset not found " );
276+ revert AssetNotFound ( );
236277 }
237278
238279 function transferAsset (
@@ -275,8 +316,20 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
275316 swapDetails[assetAddress].lastSwapTime = lastSwapTime;
276317 }
277318
278- function setSwapValue (uint newValue ) external onlySwapOperator whenNotPaused {
279- swapValue = newValue.toUint96 ();
319+ function setSwapAssetAmount (address assetAddress , uint value ) external onlySwapOperator whenNotPaused {
320+
321+ uint assetId = getAssetId (assetAddress);
322+ assetInSwapOperator = value;
323+
324+ if (value > 0 ) {
325+ if (assetsInSwapOperatorBitmap != 0 ) {
326+ revert OrderInProgress ();
327+ }
328+
329+ assetsInSwapOperatorBitmap = uint32 (1 << assetId);
330+ } else {
331+ assetsInSwapOperatorBitmap = 0 ;
332+ }
280333 }
281334
282335 /* ========== CLAIMS RELATED MUTATIVE FUNCTIONS ========== */
@@ -429,7 +482,7 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
429482 }
430483
431484 function updateUintParameters (bytes8 /* code */ , uint /* value */ ) external view onlyGovernance {
432- revert ( " Pool: Unknown parameter " );
485+ revert UnknownParameter ( );
433486 }
434487
435488 function updateAddressParameters (bytes8 code , address value ) external onlyGovernance {
@@ -447,7 +500,7 @@ contract Pool is IPool, MasterAwareV2, ReentrancyGuard {
447500 return ;
448501 }
449502
450- revert ( " Pool: Unknown parameter " );
503+ revert UnknownParameter ( );
451504 }
452505
453506 /* ========== DEPENDENCIES ========== */
0 commit comments