@@ -17,11 +17,13 @@ import {MarketFilter} from "../types/CreditAccountState.sol";
1717
1818import {PoolCompressorV3} from "./PoolCompressor.sol " ;
1919import {PriceFeedCompressor} from "./PriceFeedCompressor.sol " ;
20+ import {TokenCompressor} from "./TokenCompressor.sol " ;
2021
2122// // EXCEPTIONS
2223// import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
2324
24- import {MarketData, TokenInfo} from "../types/MarketData.sol " ;
25+ import {MarketData} from "../types/MarketData.sol " ;
26+ import {TokenData} from "../types/TokenData.sol " ;
2527import {PoolState} from "../types/PoolState.sol " ;
2628
2729import {IMarketCompressor} from "../interfaces/IMarketCompressor.sol " ;
@@ -41,6 +43,7 @@ contract MarketCompressor is IMarketCompressor {
4143 /// @notice Address provider contract address
4244 address public immutable ADDRESS_PROVIDER;
4345
46+ TokenCompressor tokenCompressor;
4447 PriceFeedCompressor priceOracleCompressor;
4548 PoolCompressorV3 poolCompressor;
4649
@@ -49,15 +52,12 @@ contract MarketCompressor is IMarketCompressor {
4952 constructor (address addressProvider , address priceOracleCompressorAddress ) {
5053 ADDRESS_PROVIDER = addressProvider;
5154 addressProvider = addressProvider;
55+ tokenCompressor = new TokenCompressor ();
5256 poolCompressor = new PoolCompressorV3 ();
53- priceOracleCompressor = PriceFeedCompressor (
54- priceOracleCompressorAddress
55- );
57+ priceOracleCompressor = PriceFeedCompressor (priceOracleCompressorAddress);
5658 }
5759
58- function getMarkets (
59- MarketFilter memory filter
60- ) external view returns (MarketData[] memory result ) {
60+ function getMarkets (MarketFilter memory filter ) external view returns (MarketData[] memory result ) {
6161 address [] memory pools = _getPools (filter);
6262 result = new MarketData [](pools.length );
6363
@@ -66,59 +66,39 @@ contract MarketCompressor is IMarketCompressor {
6666 }
6767 }
6868
69- function getMarketData (
70- address pool
71- ) public view returns (MarketData memory result ) {
69+ function getMarketData (address pool ) public view returns (MarketData memory result ) {
7270 result.pool = poolCompressor.getPoolState (pool);
73- result.poolQuotaKeeper = poolCompressor.getPoolQuotaKeeperState (
74- result.pool.poolQuotaKeeper
75- );
76- result.rateKeeper = poolCompressor.getRateKeeperState (
77- result.poolQuotaKeeper.rateKeeper
78- );
79- result.interestRateModel = poolCompressor.getInterestModelState (
80- result.pool.interestRateModel
81- );
71+ result.poolQuotaKeeper = poolCompressor.getPoolQuotaKeeperState (result.pool.poolQuotaKeeper);
72+ result.rateKeeper = poolCompressor.getRateKeeperState (result.poolQuotaKeeper.rateKeeper);
73+ result.interestRateModel = poolCompressor.getInterestModelState (result.pool.interestRateModel);
8274
8375 address priceOracle = _getPriceOracle (result.pool);
84- address [] memory tokens = IPoolQuotaKeeperV3 (
85- result.pool.poolQuotaKeeper
86- ).quotedTokens ();
76+ address [] memory tokens = IPoolQuotaKeeperV3 (result.pool.poolQuotaKeeper).quotedTokens ();
8777
88- // TODO: add token data
89- result.tokens = new TokenInfo [](tokens.length + 1 );
90- // result.tokens[0] = tokenCompressor.getTokenInfo(result.pool.underlying);
78+ result.tokens = new TokenData [](tokens.length + 1 );
79+ address [] memory underlyingAndTokens = new address [](tokens.length + 1 );
80+ result.tokens[0 ] = tokenCompressor.getTokenInfo (result.pool.underlying);
81+ underlyingAndTokens[0 ] = result.pool.underlying;
9182
92- // for (uint256 i = 0; i < tokens.length; i++) {
93- // result.tokens[i + 1] = tokenCompressor.getTokenInfo(tokens[i]);
94- // }
83+ for (uint256 i = 0 ; i < tokens.length ; i++ ) {
84+ result.tokens[i + 1 ] = tokenCompressor.getTokenInfo (tokens[i]);
85+ underlyingAndTokens[i + 1 ] = tokens[i];
86+ }
9587 // How to query if no credit mangers are deployed?
96- // //
97- // TODO: add local address[]
98- // result.priceOracleData = priceOracleCompressor.getPriceOracleState(
99- // priceOracle,
100- // result.tokens
101- // );
88+ result.priceOracleData = priceOracleCompressor.getPriceOracleState (priceOracle, underlyingAndTokens);
10289 }
10390
104- function _getPriceOracle (
105- PoolState memory ps
106- ) internal view returns (address ) {
91+ function _getPriceOracle (PoolState memory ps ) internal view returns (address ) {
10792 if (ps.creditManagerDebtParams.length == 0 ) {
10893 return address (0 );
10994 }
11095
111- return
112- ICreditManagerV3 (ps.creditManagerDebtParams[0 ].creditManager)
113- .priceOracle ();
96+ return ICreditManagerV3 (ps.creditManagerDebtParams[0 ].creditManager).priceOracle ();
11497 }
11598
11699 /// @dev Pools discovery
117- function _getPools (
118- MarketFilter memory filter
119- ) internal view returns (address [] memory pools ) {
120- address [] memory configurators = IAddressProviderV3_1 (ADDRESS_PROVIDER)
121- .marketConfigurators ();
100+ function _getPools (MarketFilter memory filter ) internal view returns (address [] memory pools ) {
101+ address [] memory configurators = IAddressProviderV3_1 (ADDRESS_PROVIDER).marketConfigurators ();
122102
123103 // rough estimate of maximum number of credit pools
124104 uint256 max;
@@ -133,24 +113,20 @@ contract MarketCompressor is IMarketCompressor {
133113
134114 for (uint256 i; i < configurators.length ; ++ i) {
135115 if (filter.curators.length != 0 ) {
136- if (
137- ! filter.curators.contains (
138- IMarketConfiguratorV3 (configurators[i]).owner ()
139- )
140- ) continue ;
116+ if (! filter.curators.contains (IMarketConfiguratorV3 (configurators[i]).owner ())) continue ;
141117 }
142118
143- address [] memory poolsMC = IMarketConfiguratorV3 (configurators[i])
144- .pools ();
119+ address [] memory poolsMC = IMarketConfiguratorV3 (configurators[i]).pools ();
145120 for (uint256 j; j < poolsMC.length ; ++ j) {
146121 address currentPool = poolsMC[j];
147122 if (filter.pools.length != 0 ) {
148123 if (! filter.pools.contains (currentPool)) continue ;
149124 }
150125
151126 if (filter.underlying != address (0 )) {
152- if (IPoolV3 (currentPool).asset () != filter.underlying)
127+ if (IPoolV3 (currentPool).asset () != filter.underlying) {
153128 continue ;
129+ }
154130 }
155131
156132 pools[num++ ] = currentPool;
0 commit comments