# Compressors

> Markdown export of the Gearbox Protocol documentation page for agents and retrieval systems.

Canonical page: https://docs.gearbox.finance/developers/gm-ref-compressors
Source file: content/developers/gm-ref-compressors.mdx
Section router: https://docs.gearbox.finance/developers/llms.txt
Section full export: https://docs.gearbox.finance/developers/llms-full.txt

Compressor contracts are read-only data aggregation contracts. Instead of dozens of individual calls, a single compressor call returns complete protocol state. The SDK uses compressors internally.

## Discovering Compressor Addresses

Use `AddressProvider` to find compressor addresses:

```solidity
address compressor = addressProvider.getLatestAddressByContractType(
    AP_MARKET_COMPRESSOR,
    VERSION_RANGE_310
);
```

```typescript
const [compressor] = sdk.addressProvider.mustGetLatest(
  AP_MARKET_COMPRESSOR,
  VERSION_RANGE_310
);
```

---

## MarketCompressor

Aggregates complete market state including pools, credit managers, and price oracles.

### View Methods

#### getMarkets

Returns market data for all markets matching the filter.

```solidity
function getMarkets(MarketFilter memory filter) external view returns (MarketData[] memory);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `filter` | `MarketFilter` | Filter criteria (see below) |

**Returns:** Array of `MarketData` structs.

---

#### getMarketData

Returns complete data for a single market identified by its pool address.

```solidity
function getMarketData(address pool) external view returns (MarketData memory);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `pool` | `address` | Pool address identifying the market |

---

#### getPoolState

Returns the pool state for a given pool.

```solidity
function getPoolState(address pool) external view returns (PoolState memory);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `pool` | `address` | Pool address |

---

### Data Structures

#### MarketFilter

```solidity
struct MarketFilter {
    address[] configurators;  // Filter by Risk Curator addresses
    address[] pools;          // Filter by specific pool addresses
    address underlying;       // Filter by underlying token (e.g., USDC)
}
```

Pass empty arrays and `address(0)` for no filtering.

#### MarketData

```solidity
struct MarketData {
    PoolState pool;
    QuotaKeeperState quotaKeeper;
    CreditSuiteData[] creditManagers;
    PriceOracleState priceOracle;
    TokenData[] tokens;
}
```

#### PoolState (key fields)

| Field | Type | Description |
| --- | --- | --- |
| `baseParams.addr` | `address` | Pool contract address |
| `availableLiquidity` | `uint256` | Borrowable liquidity |
| `dieselRate` | `uint256` | Share price (RAY) |
| `supplyRate` | `uint256` | Lender APY (RAY) |
| `baseInterestRate` | `uint256` | Borrower APR (RAY) |
| `totalAssets` | `uint256` | Total pool value |

#### CreditSuiteData (key fields)

| Field | Type | Description |
| --- | --- | --- |
| `creditManager` | `address` | Credit Manager address |
| `creditFacade` | `address` | Credit Facade address |
| `creditConfigurator` | `address` | Configurator address |
| `debtLimits` | `DebtLimits` | Min/max debt per account |
| `collateralTokens` | `CollateralToken[]` | Allowed tokens + LTs |

---

## CreditAccountCompressor

Fetches credit account data with filtering and pagination.

### View Methods

#### getCreditAccounts

Returns credit accounts matching the filter with pagination support.

```solidity
function getCreditAccounts(
    address creditManager,
    CreditAccountFilter memory filter,
    uint256 offset
) external view returns (CreditAccountData[] memory accounts, uint256 total);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `creditManager` | `address` | Credit Manager to query |
| `filter` | `CreditAccountFilter` | Filter criteria (see below) |
| `offset` | `uint256` | Pagination offset |

**Returns:** Matching accounts and total count.

---

#### countCreditAccounts

Returns the count of credit accounts matching the filter.

```solidity
function countCreditAccounts(
    address creditManager,
    CreditAccountFilter memory filter
) external view returns (uint256);
```

---

#### getCreditAccountData

Returns complete data for a single credit account.

```solidity
function getCreditAccountData(
    address creditManager,
    address creditAccount
) external view returns (CreditAccountData memory);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `creditManager` | `address` | Parent Credit Manager |
| `creditAccount` | `address` | Account to query |

---

### Data Structures

#### CreditAccountFilter

```solidity
struct CreditAccountFilter {
    address owner;           // Filter by owner (address(0) = any)
    uint256 minHealthFactor; // Minimum HF (0 = no min)
    uint256 maxHealthFactor; // Maximum HF (type(uint256).max = no max)
    bool includeZeroDebt;    // Include accounts with no debt
    bool reverting;          // Include reverting accounts
}
```

#### CreditAccountData (key fields)

| Field | Type | Description |
| --- | --- | --- |
| `addr` | `address` | Credit Account address |
| `owner` | `address` | Account owner |
| `creditManager` | `address` | Parent Credit Manager |
| `debt` | `uint256` | Total debt (principal + interest) |
| `enabledTokensMask` | `uint256` | Bitmask of enabled tokens |
| `healthFactor` | `uint256` | Current HF (10000 = 1.0) |
| `tokens` | `TokenInfo[]` | Token balances and values |
| `isLiquidatable` | `bool` | Whether account can be liquidated |

---

## PriceFeedCompressor

Aggregates price feed state for oracle monitoring and updates.

### View Methods

#### getUpdatablePriceFeeds

Returns all price feeds that may need updating for a given price oracle.

```solidity
function getUpdatablePriceFeeds(address priceOracle) external view returns (PriceFeedData[] memory);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `priceOracle` | `address` | PriceOracle contract to query |

**Returns:** Array of price feed data including staleness information.

---

#### loadPriceFeedTree

Returns the full price feed dependency tree for a specific token.

```solidity
function loadPriceFeedTree(address priceOracle, address token) external view returns (PriceFeedTreeNode memory);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `priceOracle` | `address` | PriceOracle contract |
| `token` | `address` | Token to query |

---

## When to Use Compressors vs SDK

| Scenario | Approach |
| --- | --- |
| General market data | SDK `marketRegister` |
| Credit account queries | SDK services |
| Custom filtering logic | Direct compressor calls |
| Liquidation bots | Direct compressor (gas-optimized) |
| On-chain integration | Direct compressor (no SDK in contracts) |
| Real-time monitoring | Direct compressor with specific filters |

---

## Related Pages

- [Pool (PoolV3)](https://docs.gearbox.finance/developers/gm-ref-pool) -- Pool state returned by MarketCompressor
- [Credit Manager](https://docs.gearbox.finance/developers/gm-ref-cm) -- Credit accounts queried by CreditAccountCompressor
- [Quota Keeper](https://docs.gearbox.finance/developers/gm-ref-qk) -- Quota data included in MarketData
- [Smart Contracts Overview](https://docs.gearbox.finance/developers/gm-contracts) -- Full contract architecture
