@gearbox-protocol/periphery-v3 1.7.0-next.20 → 1.7.0-next.22

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.
@@ -19,10 +19,10 @@ import {PERCENTAGE_FACTOR} from "@gearbox-protocol/core-v3/contracts/libraries/C
19
19
  import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol";
20
20
  import {ICreditAccountCompressor} from "../interfaces/ICreditAccountCompressor.sol";
21
21
 
22
- import {IAddressProviderV3} from "@gearbox-protocol/governance/contracts/interfaces/IAddressProviderV3.sol";
22
+ import {IAddressProviderV3_1} from "@gearbox-protocol/governance/contracts/interfaces/IAddressProviderV3_1.sol";
23
23
  import {IMarketConfiguratorV3} from "@gearbox-protocol/governance/contracts/interfaces/IMarketConfiguratorV3.sol";
24
24
 
25
- import {CreditAccountData, CreditAccountFilter, CreditManagerFilter, TokenInfo} from "../types/CreditAccountState.sol";
25
+ import {CreditAccountData, CreditAccountFilter, MarketFilter, TokenInfo} from "../types/CreditAccountState.sol";
26
26
 
27
27
  import {Contains} from "../libraries/Contains.sol";
28
28
 
@@ -47,7 +47,7 @@ contract CreditAccountCompressor is ICreditAccountCompressor, SanityCheckTrait {
47
47
  /// @param addressProvider Address provider contract address
48
48
  constructor(address addressProvider) nonZeroAddress(addressProvider) {
49
49
  if (addressProvider.code.length == 0) revert InvalidAddressProviderException();
50
- try IAddressProviderV3(addressProvider).marketConfigurators() {}
50
+ try IAddressProviderV3_1(addressProvider).marketConfigurators() {}
51
51
  catch {
52
52
  revert InvalidAddressProviderException();
53
53
  }
@@ -64,26 +64,26 @@ contract CreditAccountCompressor is ICreditAccountCompressor, SanityCheckTrait {
64
64
  return _getCreditAccountData(creditAccount, creditManager);
65
65
  }
66
66
 
67
- /// @notice Returns data for credit accounts that match `caFilter` in credit managers matching `cmFilter`
67
+ /// @notice Returns data for credit accounts that match `caFilter` in credit managers matching `marketFilter`
68
68
  /// @dev The non-zero value of `nextOffset` return variable indicates that gas supplied with a call was
69
69
  /// insufficient to process all the accounts and next iteration starting from this value is needed
70
- function getCreditAccounts(CreditManagerFilter memory cmFilter, CreditAccountFilter memory caFilter, uint256 offset)
70
+ function getCreditAccounts(MarketFilter memory marketFilter, CreditAccountFilter memory caFilter, uint256 offset)
71
71
  external
72
72
  view
73
73
  returns (CreditAccountData[] memory data, uint256 nextOffset)
74
74
  {
75
- address[] memory creditManagers = _getCreditManagers(cmFilter);
75
+ address[] memory creditManagers = _getCreditManagers(marketFilter);
76
76
  return _getCreditAccounts(creditManagers, caFilter, offset, type(uint256).max);
77
77
  }
78
78
 
79
79
  /// @dev Same as above but with `limit` parameter that specifies the number of accounts to process
80
80
  function getCreditAccounts(
81
- CreditManagerFilter memory cmFilter,
81
+ MarketFilter memory marketFilter,
82
82
  CreditAccountFilter memory caFilter,
83
83
  uint256 offset,
84
84
  uint256 limit
85
85
  ) public view returns (CreditAccountData[] memory data, uint256 nextOffset) {
86
- address[] memory creditManagers = _getCreditManagers(cmFilter);
86
+ address[] memory creditManagers = _getCreditManagers(marketFilter);
87
87
  return _getCreditAccounts(creditManagers, caFilter, offset, limit);
88
88
  }
89
89
 
@@ -116,13 +116,13 @@ contract CreditAccountCompressor is ICreditAccountCompressor, SanityCheckTrait {
116
116
  // COUNTING //
117
117
  // -------- //
118
118
 
119
- /// @notice Counts credit accounts that match `caFilter` in credit managers matching `cmFilter`
120
- function countCreditAccounts(CreditManagerFilter memory cmFilter, CreditAccountFilter memory caFilter)
119
+ /// @notice Counts credit accounts that match `caFilter` in credit managers matching `marketFilter`
120
+ function countCreditAccounts(MarketFilter memory marketFilter, CreditAccountFilter memory caFilter)
121
121
  external
122
122
  view
123
123
  returns (uint256)
124
124
  {
125
- address[] memory creditManagers = _getCreditManagers(cmFilter);
125
+ address[] memory creditManagers = _getCreditManagers(marketFilter);
126
126
  return _countCreditAccounts(creditManagers, caFilter, 0, type(uint256).max);
127
127
  }
128
128
 
@@ -358,12 +358,8 @@ contract CreditAccountCompressor is ICreditAccountCompressor, SanityCheckTrait {
358
358
  }
359
359
 
360
360
  /// @dev Credit managers discovery
361
- function _getCreditManagers(CreditManagerFilter memory filter)
362
- internal
363
- view
364
- returns (address[] memory creditManagers)
365
- {
366
- address[] memory configurators = IAddressProviderV3(ADDRESS_PROVIDER).marketConfigurators();
361
+ function _getCreditManagers(MarketFilter memory filter) internal view returns (address[] memory creditManagers) {
362
+ address[] memory configurators = IAddressProviderV3_1(ADDRESS_PROVIDER).marketConfigurators();
367
363
 
368
364
  // rough estimate of maximum number of credit managers
369
365
  uint256 max;
@@ -4,14 +4,16 @@
4
4
  pragma solidity ^0.8.17;
5
5
 
6
6
  import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
7
+ import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol";
7
8
  import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol";
8
9
  import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IContractsRegister.sol";
9
10
  import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
10
11
 
11
12
  import {Contains} from "../libraries/Contains.sol";
12
13
 
13
- import {IAddressProviderV3} from "@gearbox-protocol/governance/contracts/interfaces/IAddressProviderV3.sol";
14
+ import {IAddressProviderV3_1} from "@gearbox-protocol/governance/contracts/interfaces/IAddressProviderV3_1.sol";
14
15
  import {IMarketConfiguratorV3} from "@gearbox-protocol/governance/contracts/interfaces/IMarketConfiguratorV3.sol";
16
+ import {MarketFilter} from "../types/CreditAccountState.sol";
15
17
 
16
18
  import {PoolCompressorV3} from "./PoolCompressor.sol";
17
19
  import {PriceFeedCompressor} from "./PriceFeedCompressor.sol";
@@ -51,6 +53,15 @@ contract MarketCompressor is IMarketCompressor {
51
53
  priceOracleCompressor = PriceFeedCompressor(priceOracleCompressorAddress);
52
54
  }
53
55
 
56
+ function getMarkets(MarketFilter memory filter) external view returns (MarketData[] memory result) {
57
+ address[] memory pools = _getPools(filter);
58
+ result = new MarketData[](pools.length);
59
+
60
+ for (uint256 i = 0; i < pools.length; i++) {
61
+ result[i] = getMarketData(pools[i]);
62
+ }
63
+ }
64
+
54
65
  function getMarketData(address pool) public view returns (MarketData memory result) {
55
66
  result.pool = poolCompressor.getPoolState(pool);
56
67
  result.poolQuotaKeeper = poolCompressor.getPoolQuotaKeeperState(result.pool.poolQuotaKeeper);
@@ -78,36 +89,44 @@ contract MarketCompressor is IMarketCompressor {
78
89
  return ICreditManagerV3(ps.creditManagerDebtParams[0].creditManager).priceOracle();
79
90
  }
80
91
 
81
- /// @dev Credit managers discovery
82
- function _getPools(address[] memory riskCurators) internal view returns (address[] memory pools) {
83
- address[] memory configurators = IAddressProviderV3(ADDRESS_PROVIDER).marketConfigurators();
92
+ /// @dev Pools discovery
93
+ function _getPools(MarketFilter memory filter) internal view returns (address[] memory pools) {
94
+ address[] memory configurators = IAddressProviderV3_1(ADDRESS_PROVIDER).marketConfigurators();
84
95
 
85
- // rough estimate of maximum number of credit managers
96
+ // rough estimate of maximum number of credit pools
86
97
  uint256 max;
87
98
  for (uint256 i; i < configurators.length; ++i) {
88
- if (riskCurators.contains(IMarketConfiguratorV3(configurators[i]).owner())) {
89
- address cr = IMarketConfiguratorV3(configurators[i]).contractsRegister();
90
- max += IContractsRegister(cr).getCreditManagers().length;
91
- }
99
+ max += IMarketConfiguratorV3(configurators[i]).pools().length;
92
100
  }
93
101
 
94
- // allocate the array with maximum potentially needed size (total number of credit managers can be assumed
102
+ // allocate the array with maximum potentially needed size (total number of credit pools can be assumed
95
103
  // to be relatively small and the function is only called once, so memory expansion cost is not an issue)
96
104
  pools = new address[](max);
97
105
  uint256 num;
98
106
 
99
107
  for (uint256 i; i < configurators.length; ++i) {
100
- if (riskCurators.contains(IMarketConfiguratorV3(configurators[i]).owner())) {
101
- address cr = IMarketConfiguratorV3(configurators[i]).contractsRegister();
102
- address[] memory managers = IContractsRegister(cr).getPools();
103
- for (uint256 j; j < managers.length; ++j) {
104
- // we're only concerned with v3 contracts
105
- uint256 ver = IVersion(managers[j]).version();
106
- if (ver < 3_00 || ver > 3_99) continue;
107
-
108
- pools[num++] = managers[j];
108
+ if (filter.curators.length != 0) {
109
+ if (!filter.curators.contains(IMarketConfiguratorV3(configurators[i]).owner())) continue;
110
+ }
111
+
112
+ address[] memory poolsMC = IMarketConfiguratorV3(configurators[i]).pools();
113
+ for (uint256 j; j < poolsMC.length; ++j) {
114
+ address currentPool = poolsMC[j];
115
+ if (filter.pools.length != 0) {
116
+ if (!filter.pools.contains(currentPool)) continue;
117
+ }
118
+
119
+ if (filter.underlying != address(0)) {
120
+ if (IPoolV3(currentPool).asset() != filter.underlying) continue;
109
121
  }
122
+
123
+ pools[num++] = currentPool;
110
124
  }
111
125
  }
126
+
127
+ // trim the array to its actual size
128
+ assembly {
129
+ mstore(pools, num)
130
+ }
112
131
  }
113
132
  }
@@ -96,7 +96,11 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
96
96
  {
97
97
  result.addr = priceOracle;
98
98
  result.version = IPriceOracleV3(priceOracle).version();
99
- result.contractType = IVersion(priceOracle).contractType();
99
+ try IVersion(priceOracle).contractType() returns (bytes32 contractType) {
100
+ result.contractType = contractType;
101
+ } catch {
102
+ result.contractType = "PRICE_ORACLE";
103
+ }
100
104
 
101
105
  (result.priceFeedMapping, result.priceFeedStructure) = getPriceFeeds(priceOracle, tokens);
102
106
  }
@@ -4,7 +4,7 @@
4
4
  pragma solidity ^0.8.17;
5
5
 
6
6
  import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
7
- import {CreditAccountData, CreditAccountFilter, CreditManagerFilter, TokenInfo} from "../types/CreditAccountState.sol";
7
+ import {CreditAccountData, CreditAccountFilter, MarketFilter, TokenInfo} from "../types/CreditAccountState.sol";
8
8
 
9
9
  /// @title Credit account compressor
10
10
  /// @notice Allows to fetch data on all credit accounts matching certain criteria in an efficient manner
@@ -17,14 +17,14 @@ interface ICreditAccountCompressor is IVersion {
17
17
  /// @notice Returns data for credit accounts that match `caFilter` in credit managers matching `cmFilter`
18
18
  /// @dev The non-zero value of `nextOffset` return variable indicates that gas supplied with a call was
19
19
  /// insufficient to process all the accounts and next iteration starting from this value is needed
20
- function getCreditAccounts(CreditManagerFilter memory cmFilter, CreditAccountFilter memory caFilter, uint256 offset)
20
+ function getCreditAccounts(MarketFilter memory cmFilter, CreditAccountFilter memory caFilter, uint256 offset)
21
21
  external
22
22
  view
23
23
  returns (CreditAccountData[] memory data, uint256 nextOffset);
24
24
 
25
25
  /// @dev Same as above but with `limit` parameter that specifies the number of accounts to process
26
26
  function getCreditAccounts(
27
- CreditManagerFilter memory cmFilter,
27
+ MarketFilter memory cmFilter,
28
28
  CreditAccountFilter memory caFilter,
29
29
  uint256 offset,
30
30
  uint256 limit
@@ -47,7 +47,7 @@ interface ICreditAccountCompressor is IVersion {
47
47
  ) external view returns (CreditAccountData[] memory data, uint256 nextOffset);
48
48
 
49
49
  /// @notice Counts credit accounts that match `caFilter` in credit managers matching `cmFilter`
50
- function countCreditAccounts(CreditManagerFilter memory cmFilter, CreditAccountFilter memory caFilter)
50
+ function countCreditAccounts(MarketFilter memory cmFilter, CreditAccountFilter memory caFilter)
51
51
  external
52
52
  view
53
53
  returns (uint256);
@@ -1,6 +1,8 @@
1
1
  import {MarketData} from "../types/MarketData.sol";
2
2
  import {PoolState} from "../types/PoolState.sol";
3
3
  import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
4
+ import {MarketFilter} from "../types/CreditAccountState.sol";
5
+
4
6
  import "forge-std/console.sol";
5
7
 
6
8
  /// @title Data compressor 3.0.
@@ -8,4 +10,6 @@ import "forge-std/console.sol";
8
10
  /// Do not use for data from data compressor for state-changing functions
9
11
  interface IMarketCompressor is IVersion {
10
12
  function getMarketData(address pool) external view returns (MarketData memory result);
13
+
14
+ function getMarkets(MarketFilter memory filter) external view returns (MarketData[] memory result);
11
15
  }
@@ -5,18 +5,19 @@ pragma solidity ^0.8.17;
5
5
 
6
6
  import {Test} from "forge-std/Test.sol";
7
7
 
8
+ import {IAddressProviderV3_1} from "@gearbox-protocol/governance/contracts/interfaces/IAddressProviderV3_1.sol";
9
+
8
10
  import {
9
11
  AP_ACL,
10
12
  AP_CONTRACTS_REGISTER,
11
- IAddressProviderV3,
12
13
  NO_VERSION_CONTROL
13
- } from "@gearbox-protocol/core-v3/contracts/test/interfaces/IAddressProviderV3.sol";
14
+ } from "@gearbox-protocol/governance/contracts/libraries/ContractLiterals.sol";
14
15
 
15
16
  import {ACL} from "@gearbox-protocol/governance/contracts/market/ACL.sol";
16
17
  import {IContractsRegisterExt} from "./interfaces/IContractsRegisterExt.sol";
17
18
 
18
19
  abstract contract ForkTest is Test {
19
- IAddressProviderV3 addressProvider;
20
+ IAddressProviderV3_1 addressProvider;
20
21
  ACL acl;
21
22
  IContractsRegisterExt register;
22
23
  address configurator;
@@ -36,7 +37,7 @@ abstract contract ForkTest is Test {
36
37
  vm.createSelectFork(rpcUrl, blockNumber);
37
38
  }
38
39
 
39
- addressProvider = IAddressProviderV3(vm.envAddress("FORK_ADDRESS_PROVIDER"));
40
+ addressProvider = IAddressProviderV3_1(vm.envAddress("FORK_ADDRESS_PROVIDER"));
40
41
  acl = ACL(addressProvider.getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL));
41
42
  register = IContractsRegisterExt(addressProvider.getAddressOrRevert(AP_CONTRACTS_REGISTER, NO_VERSION_CONTROL));
42
43
  configurator = acl.owner();
@@ -59,7 +59,7 @@ struct CreditAccountFilter {
59
59
  /// @param curators If set, match credit managers managed by given curators
60
60
  /// @param pools If set, match credit managers connected to given pools
61
61
  /// @param underlying If set, match credit managers with given underlying
62
- struct CreditManagerFilter {
62
+ struct MarketFilter {
63
63
  address[] curators;
64
64
  address[] pools;
65
65
  address underlying;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.7.0-next.20",
3
+ "version": "1.7.0-next.22",
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>",