@gearbox-protocol/periphery-v3 1.7.0-next.7 → 1.7.0-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,12 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
59
59
  }
60
60
 
61
61
  /// @notice Returns data for credit accounts that match `caFilter` in credit managers matching `cmFilter`
62
- /// @dev The `false` value of `finished` return variable indicates either that gas supplied with a call was
63
- /// insufficient to process all the accounts and next iteration starting from `nextOffset` is needed
62
+ /// @dev The non-zero value of `nextOffset` return variable indicates that gas supplied with a call was
63
+ /// insufficient to process all the accounts and next iteration starting from this value is needed
64
64
  function getCreditAccounts(CreditManagerFilter memory cmFilter, CreditAccountFilter memory caFilter, uint256 offset)
65
65
  external
66
66
  view
67
- returns (CreditAccountData[] memory data, bool finished, uint256 nextOffset)
67
+ returns (CreditAccountData[] memory data, uint256 nextOffset)
68
68
  {
69
69
  address[] memory creditManagers = _getCreditManagers(cmFilter);
70
70
  return _getCreditAccounts(creditManagers, caFilter, offset, type(uint256).max);
@@ -76,18 +76,18 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
76
76
  CreditAccountFilter memory caFilter,
77
77
  uint256 offset,
78
78
  uint256 limit
79
- ) public view returns (CreditAccountData[] memory data, bool finished, uint256 nextOffset) {
79
+ ) public view returns (CreditAccountData[] memory data, uint256 nextOffset) {
80
80
  address[] memory creditManagers = _getCreditManagers(cmFilter);
81
81
  return _getCreditAccounts(creditManagers, caFilter, offset, limit);
82
82
  }
83
83
 
84
84
  /// @notice Returns data for credit accounts that match `caFilter` in a given `creditManager`
85
- /// @dev The `false` value of `finished` return variable indicates either that gas supplied with a call was
86
- /// insufficient to process all the accounts and next iteration starting from `nextOffset` is needed
85
+ /// @dev The non-zero value of `nextOffset` return variable indicates that gas supplied with a call was
86
+ /// insufficient to process all the accounts and next iteration starting from this value is needed
87
87
  function getCreditAccounts(address creditManager, CreditAccountFilter memory caFilter, uint256 offset)
88
88
  external
89
89
  view
90
- returns (CreditAccountData[] memory data, bool finished, uint256 nextOffset)
90
+ returns (CreditAccountData[] memory data, uint256 nextOffset)
91
91
  {
92
92
  address[] memory creditManagers = new address[](1);
93
93
  creditManagers[0] = creditManager;
@@ -100,7 +100,7 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
100
100
  CreditAccountFilter memory caFilter,
101
101
  uint256 offset,
102
102
  uint256 limit
103
- ) external view returns (CreditAccountData[] memory data, bool finished, uint256 nextOffset) {
103
+ ) external view returns (CreditAccountData[] memory data, uint256 nextOffset) {
104
104
  address[] memory creditManagers = new address[](1);
105
105
  creditManagers[0] = creditManager;
106
106
  return _getCreditAccounts(creditManagers, caFilter, offset, limit);
@@ -141,9 +141,9 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
141
141
  CreditAccountFilter memory filter,
142
142
  uint256 offset,
143
143
  uint256 limit
144
- ) internal view returns (CreditAccountData[] memory data, bool finished, uint256 nextOffset) {
144
+ ) internal view returns (CreditAccountData[] memory data, uint256 nextOffset) {
145
145
  uint256 num = _countCreditAccounts(creditManagers, filter, offset, limit);
146
- if (num == 0) return (data, true, 0);
146
+ if (num == 0) return (data, 0);
147
147
 
148
148
  // allocating the `CreditAccountData` array might consume most of the gas leaving no room for computations,
149
149
  // so we instead allocate and gradually fill the array of pointers to structs which takes much less space
@@ -185,15 +185,15 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
185
185
  }
186
186
 
187
187
  // rough approximation of gas that will be needed to accommodate additional memory expansion cost
188
- gasReserve += gasBefore - gasleft();
188
+ gasReserve += (gasBefore - gasleft()) / 2;
189
189
  }
190
190
  --count;
191
191
 
192
- if (dataOffset == dataPointers.length || gasleft() < gasReserve) break;
192
+ if (dataOffset == num || gasleft() < gasReserve) break;
193
193
  }
194
194
 
195
195
  nextOffset += creditAccounts.length - count;
196
- if (dataOffset == dataPointers.length || count != 0) break;
196
+ if (dataOffset == num || count != 0) break;
197
197
 
198
198
  limit -= creditAccounts.length;
199
199
  if (limit == 0) break;
@@ -207,7 +207,8 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
207
207
  mstore(data, dataOffset)
208
208
  }
209
209
 
210
- return (data, dataOffset == num, nextOffset);
210
+ // set `nextOffset` to zero to indicate that scanning is finished
211
+ if (dataOffset == num) nextOffset = 0;
211
212
  }
212
213
 
213
214
  /// @dev Counting implementation
@@ -263,14 +264,14 @@ contract CreditAccountCompressor is IVersion, SanityCheckTrait {
263
264
  // collateral is computed separately since it might revert on `balanceOf` and `latestRoundData` calls
264
265
  try ICreditManagerV3(creditManager).calcDebtAndCollateral(creditAccount, CollateralCalcTask.DEBT_COLLATERAL)
265
266
  returns (CollateralDebtData memory cdd_) {
266
- data.totalDebtUSD = cdd.totalDebtUSD;
267
+ data.totalDebtUSD = cdd_.totalDebtUSD;
267
268
  data.totalValueUSD = cdd_.totalValueUSD;
268
269
  data.twvUSD = cdd_.twvUSD;
269
- data.totalValue = cdd.totalValue;
270
+ data.totalValue = cdd_.totalValue;
270
271
 
271
- data.healthFactor = cdd.twvUSD * PERCENTAGE_FACTOR >= type(uint16).max * cdd.totalDebtUSD
272
+ data.healthFactor = cdd_.twvUSD * PERCENTAGE_FACTOR >= type(uint16).max * cdd_.totalDebtUSD
272
273
  ? type(uint16).max
273
- : uint16(cdd.twvUSD * PERCENTAGE_FACTOR / cdd.totalDebtUSD);
274
+ : uint16(cdd_.twvUSD * PERCENTAGE_FACTOR / cdd_.totalDebtUSD);
274
275
  data.success = true;
275
276
  } catch {}
276
277
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.7.0-next.7",
3
+ "version": "1.7.0-next.9",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:Gearbox-protocol/periphery-v3.git",
6
6
  "author": "Mikael <26343374+0xmikko@users.noreply.github.com>",