DocumentationOpen App

History & Events

Query historical time-series data and track parameter changes across Gearbox Markets using the SDK vNext. History and event feeds require the backend enrichment service but degrade gracefully when it is unavailable.

Historical Metrics

Use sdk.history.getMetric() to retrieve time-series data for any pool or strategy metric.

TypeScript
import { GearboxSDK } from "@gearbox-protocol/sdk/official"; const sdk = await GearboxSDK.init({ chains: [1, 42161], startFromCache: true, }); // APY history for a pool over the last 90 days const apyHistory = await sdk.history.getMetric({ entity: poolAddress, chainId: 1, metric: "apy", period: "90d", }); for (const point of apyHistory.data) { console.log(`${point.date}: ${point.value}%`); }

Available Metrics

MetricEntity TypeDescription
"apy"PoolComposite supply APY (organic + incentives)
"utilization"PoolPool utilization rate (0-1)
"tvl"PoolTotal value locked in underlying token
"borrow_rate"PoolCurrent borrow rate for the pool
"share_price"PoolDiesel token price in underlying — drops indicate bad debt
"oracle_price"TokenOracle price history for a collateral token

Parameters

ParameterTypeRequiredDescription
entitystringYesPool address, strategy ID, or token address
chainIdnumberYesChain ID for the entity
metricstringYesOne of the metrics listed above
periodstringNoTime window: "7d", "30d", "90d", "1y". Default "90d"
resolutionstringNoData point interval: "1h", "1d", "1w". Default "1d"

Multi-Metric Query

Fetch several metrics at once for a single entity:

TypeScript
const [apy, utilization, tvl] = await Promise.all([ sdk.history.getMetric({ entity: poolAddress, chainId: 1, metric: "apy", period: "90d" }), sdk.history.getMetric({ entity: poolAddress, chainId: 1, metric: "utilization", period: "90d" }), sdk.history.getMetric({ entity: poolAddress, chainId: 1, metric: "tvl", period: "90d" }), ]);

Share Price Monitoring

Share price is the primary indicator for bad debt socialization. A drop in share price means losses were distributed to LPs:

TypeScript
const sharePrice = await sdk.history.getMetric({ entity: poolAddress, chainId: 1, metric: "share_price", period: "90d", resolution: "1d", }); // Detect any drops for (let i = 1; i < sharePrice.data.length; i++) { const prev = sharePrice.data[i - 1].value; const curr = sharePrice.data[i].value; if (curr < prev) { console.warn(`Share price dropped on ${sharePrice.data[i].date}: ${prev}${curr}`); } }

Event Feed

Use sdk.events.getFeed() to retrieve a log of parameter changes — both past governance actions and pending scheduled changes.

TypeScript
const feed = await sdk.events.getFeed({ entity: poolAddress, chainId: 1, since: "2025-01-01T00:00:00Z", }); for (const event of feed.events) { console.log(`[${event.timestamp}] ${event.type}: ${event.description}`); }

Event Types

Event TypeDescription
"collateral_added"New collateral token added to a credit manager
"collateral_removed"Token forbidden or removed
"lt_changed"Liquidation threshold updated
"debt_limit_changed"Credit manager debt limit adjusted
"irm_updated"Interest rate model parameters changed
"cm_added"New credit manager connected to pool
"quota_rate_changed"Token quota rate adjusted
"curator_changed"Pool curator address updated
"oracle_changed"Oracle feed updated for a collateral token

Feed Parameters

ParameterTypeRequiredDescription
entitystringYesPool address or credit manager address
chainIdnumberYesChain ID
sincestringNoISO timestamp — only events after this time
includeProjectedbooleanNoInclude pending/scheduled changes. Default true

State Projections

Instead of abstract event labels, the SDK provides concrete before/after snapshots through State Projections. This lets you see exactly how a pending governance change will affect parameters.

PoolStateProjection

TypeScript
const projection = await sdk.events.getProjection({ entity: poolAddress, chainId: 1, }); // Current state console.log("Current parameters:", projection.current); // Projected state after pending changes if (projection.projected) { console.log("Projected parameters:", projection.projected); // See individual parameter diffs for (const diff of projection.changes) { console.log(`${diff.parameter}: ${diff.from}${diff.to} (ETA: ${diff.eta})`); } }

Projection Fields

FieldTypeDescription
currentParameterSnapshotCurrent on-chain parameter values
projectedParameterSnapshot | nullParameters after all pending changes apply. null when backend unavailable
changesParameterDiff[]List of individual parameter diffs

ParameterDiff

Each diff in changes is a concrete before/after comparison:

FieldTypeDescription
parameterstringParameter name (e.g. "quotaRate", "debtLimit", "liquidationThreshold")
tokenstring | nullAffected token address, if parameter is token-scoped
fromstring | numberCurrent value
tostring | numberValue after change applies
etastringISO timestamp when the change takes effect
status"pending" | "queued" | "executed"Current status of the change

Example: Quota Rate Change

TypeScript
const projection = await sdk.events.getProjection({ entity: poolAddress, chainId: 1, }); // Find quota rate changes const quotaChanges = projection.changes.filter(d => d.parameter === "quotaRate"); for (const change of quotaChanges) { console.log( `${change.token} quota rate: ${change.from}% → ${change.to}% (ETA: ${change.eta})` ); // Output: "USDC quota rate: 3% → 4% (ETA: 2025-04-20T12:00:00Z)" }

Graceful Degradation

History and event data come from the Gearbox backend (GET /v2/history/:metric, GET /v2/events). When the backend is unavailable, the SDK degrades gracefully:

FeatureBackend AvailableBackend Unavailable
sdk.history.getMetric()Full time-series dataThrows or returns empty data[]
sdk.events.getFeed()Past + pending eventsOn-chain events only, no pending
projection.projectedConcrete snapshotnull
projection.changesFull diff list[] (empty array)

Check backend availability before relying on enriched data:

TypeScript
const result = await sdk.history.getMetric({ entity: poolAddress, chainId: 1, metric: "apy", }); if (!result.meta.backendAvailable) { console.warn("Backend unavailable — historical data may be incomplete"); }

Backend Endpoints

The SDK vNext communicates with these backend endpoints for history and events:

EndpointSDK MethodDescription
GET /v2/history/:metricsdk.history.getMetric()Time-series metric data
GET /v2/eventssdk.events.getFeed()Parameter change feed

Learn More

  • Opportunities — discovering yield opportunities
  • Markets Data — reading current pool metrics and credit manager state
  • Interest Rates — understanding the interest rate model
  • Positions — managing positions with prepare/preview/execute