Markets Data
Read pool metrics, credit manager configuration, collateral tokens, and interest rates using the Gearbox SDK. All data is cached on SDK initialization and can be refreshed via compressors.
Initialize the SDK
TypeScript
import { GearboxSDK } from "@gearbox-protocol/sdk"; import { createPublicClient, http } from "viem"; import { mainnet } from "viem/chains"; const client = createPublicClient({ chain: mainnet, transport: http(), }); const sdk = await GearboxSDK.attach({ client, marketConfigurators: [], });
Finding Markets
The marketRegister provides cached access to all Gearbox markets:
TypeScript
// All markets const markets = sdk.marketRegister.markets; // Find by pool address const market = sdk.marketRegister.findByPool(poolAddress); // Find by credit manager address const market = sdk.marketRegister.findByCreditManager(cmAddress);
Filtering Markets
Query markets by underlying token, liquidity, or configurator:
TypeScript
// All USDC markets const usdcMarkets = sdk.marketRegister.markets.filter( m => m.pool.underlying.symbol === "USDC" ); // Markets with > 1M available liquidity const liquidMarkets = sdk.marketRegister.markets.filter( m => m.pool.availableLiquidity > 1_000_000n * 10n ** 6n ); // Markets by configurator const curatedMarkets = sdk.marketRegister.markets.filter( m => m.configurator === curatorAddress );
Pool State
Access core pool metrics through the market object:
TypeScript
const pool = market.pool; console.log(`Underlying: ${pool.underlying.symbol}`); console.log(`Total assets: ${pool.totalAssets}`); console.log(`Available liquidity: ${pool.availableLiquidity}`); console.log(`Diesel rate (share price): ${pool.dieselRate}`);
Interest Rates
Rates are stored in RAY precision (27 decimals):
TypeScript
const RAY = 10n ** 27n; const supplyAPY = Number(pool.supplyRate * 10000n / RAY) / 100; const borrowAPR = Number(pool.baseInterestRate * 10000n / RAY) / 100; console.log(`Supply APY: ${supplyAPY.toFixed(2)}%`); console.log(`Borrow APR: ${borrowAPR.toFixed(2)}%`);
| Field | Type | Description |
|---|---|---|
supplyRate | bigint | Annual supply rate for LPs (RAY) |
baseInterestRate | bigint | Annual base borrow rate (RAY) |
dieselRate | bigint | Current share price (RAY) |
totalAssets | bigint | Total underlying in pool |
availableLiquidity | bigint | Underlying available for borrowing |
Credit Manager Data
Each market can have multiple credit managers with different risk profiles:
TypeScript
for (const cm of market.creditManagers) { console.log(`Credit Manager: ${cm.address}`); console.log(`Credit Facade: ${cm.creditFacade}`); console.log(`Min debt: ${cm.minDebt}`); console.log(`Max debt: ${cm.maxDebt}`); // Allowed collateral tokens and their liquidation thresholds for (const token of cm.collateralTokens) { console.log(` ${token.symbol}: LT ${token.liquidationThreshold}`); } }
| Field | Type | Description |
|---|---|---|
minDebt | bigint | Minimum borrowable amount |
maxDebt | bigint | Maximum borrowable amount |
collateralTokens | array | Allowed tokens with liquidation thresholds |
creditFacade | Address | Entry point for user interactions |
Price Oracle Data
Access token prices through the market:
TypeScript
const priceOracle = market.priceOracle; for (const token of market.tokens) { console.log(`${token.symbol}: ${token.price} USD`); }
Real-Time Data via Compressors
The SDK caches data on initialization. For fresh on-chain data, query compressors directly:
TypeScript
import { GearboxSDK, marketCompressorAbi, AP_MARKET_COMPRESSOR, VERSION_RANGE_310, } from "@gearbox-protocol/sdk"; // Get compressor address const [compressor] = sdk.addressProvider.mustGetLatest( AP_MARKET_COMPRESSOR, VERSION_RANGE_310 ); // Fetch fresh market data const freshData = await client.readContract({ address: compressor, abi: marketCompressorAbi, functionName: "getMarketData", args: [poolAddress], }); console.log(`Fresh available liquidity: ${freshData.pool.availableLiquidity}`);
Complete Example
TypeScript
import { GearboxSDK } from "@gearbox-protocol/sdk"; import { createPublicClient, http } from "viem"; import { mainnet } from "viem/chains"; async function getMarketOverview() { const client = createPublicClient({ chain: mainnet, transport: http(), }); const sdk = await GearboxSDK.attach({ client, marketConfigurators: [], }); const RAY = 10n ** 27n; for (const market of sdk.marketRegister.markets) { const pool = market.pool; console.log(`\n=== ${pool.underlying.symbol} Market ===`); console.log(`Pool: ${pool.address}`); console.log(`Total assets: ${pool.totalAssets}`); console.log(`Available: ${pool.availableLiquidity}`); const supplyAPY = Number(pool.supplyRate * 10000n / RAY) / 100; console.log(`Supply APY: ${supplyAPY.toFixed(2)}%`); console.log(`Credit Managers: ${market.creditManagers.length}`); } } getMarketOverview().catch(console.error);
Next Steps
- Pool Operations -- Deposit and withdraw liquidity
- Interest Rates & Quotas -- Understand rate models and quota limits
- Insurance Mechanism -- How protocol revenue protects lenders