/** * A pool's TVL — the total lent into it by everyone — and the shape of its * history. Pure: the reads live in `services/DataService/tvl-history.ts`. */ /** * The ONE definition of a pool's TVL: what lenders have lent on chain * (`lendingPool.balance` in the subgraph) plus the off-chain amount the * pool's `ExternalTVL` contract records (`externalTVLOfPool`). * * Both inputs, and the result, are in DISPLAY units of the deployment's own * stable token (USDC on Base and XDC USDC, AUDD on XDC AUDD) — `'1.5'` is * one and a half tokens, not 1.5 minor units. Convert before formatting as * USD. * * `getPoolOverview` (its `totalValueLocked.total`) and `getPoolTvlHistory` * (every point) both call this, so the chart and the figure above it cannot * be computed two ways. */ export declare function poolTvl(onChainBalance: string, offChainTvl: string): number; /** * One point of a pool's TVL history. * * - `kind: 'clearing'` — the TVL as it stood at the end of the block in which * that epoch's clearing finished (`LendingPoolClearing.endBlockNumber`): * accepted deposits and withdrawals and the applied interest included. * - `kind: 'current'` — the closing "as of now" point, from two sources: the * subgraph's latest balance (and its latest block time) and * `externalTVLOfPool` at `latest` on the history provider. It equals * today's `PoolOverview.totalValueLocked.total` when both that call's reads * and these succeed; `getPoolOverview` falls back to an off-chain 0 when its * own read fails, and the figure can move between the two calls. */ export interface PoolTvlHistoryEntry { /** * The epoch (cycle) number, in the chain's numbering * (`SystemVariables.currentEpochNumber`). * * A clearing point carries the epoch that clearing closed. The `current` * point carries the CURRENT epoch — which may equal the newest clearing's * epoch, because a clearing runs before its epoch rolls over. Epoch * numbers can jump (a pool that did not clear for a while, or a * deployment whose first clearing is numbered far below the next one), so * plot by `timestamp`, never by `epochId`. */ epochId: number; /** * Unix SECONDS. A clearing point: the time of the block its clearing * finished in (`endTimestamp`). The `current` point: the time of the * subgraph's latest indexed block. Clearings that finished in the same * block (a pool catching up several epochs at once) share a timestamp and * a `tvl`. */ timestamp: number; /** * TVL in DISPLAY units of the deployment's own stable token (USDC on Base * and XDC USDC, AUDD on XDC AUDD): `poolTvl(onChain, offChain)` at that * block. Convert before formatting as USD. */ tvl: number; /** `'clearing'` for a cycle boundary; `'current'` for the closing point. */ kind: 'clearing' | 'current'; } /** * One deployment's share of a strategy's history, for `combineTvlHistories`: * that pool's `getPoolTvlHistoryWindow` result (`{ entries, opening }`) as it * came back, and what one unit of the deployment's stable token is worth in * USD (`1` for USDC; today's AUD→USD for AUDD). The SDK fetches no exchange * rate: the caller passes it. */ export interface TvlHistoryLeg { /** At least one point: a real pool always returns its `current` point. */ entries: readonly PoolTvlHistoryEntry[]; /** USD per unit of the leg's stable token. Finite and above 0. */ usdRate: number; /** * The leg's step BEFORE its first entry: the newest clearing before the * window, as `getPoolTvlHistoryWindow` read it at its own block. It * counts from its own `timestamp` on, and the leg is 0 before that — no * value is carried back to a time before it existed. A `'clearing'` * point no later than the first entry; it is never drawn. `null` or * absent: the pool has no clearing before the window (it started lending * later, say) and counts 0 before its first entry. */ opening?: PoolTvlHistoryEntry | null; } /** * One point of a strategy's TVL summed across its deployments. * * There is no `epochId`: each chain clears at its own blocks and times, so a * merged point belongs to no single epoch. Plot by `timestamp`. */ export interface StrategyTvlHistoryEntry { /** Unix SECONDS. Strictly ascending across the series. */ timestamp: number; /** The sum over legs of each leg's TVL then, times its `usdRate`. */ tvlUsd: number; /** `'clearing'` for a cycle boundary on any leg; `'current'` for the closing point. */ kind: 'clearing' | 'current'; } /** * What `combineTvlHistories` refuses, as a code: * * - `legs` — not a non-empty array (or one with holes); * - `leg` — a leg that is not an object; * - `usd-rate` — a rate that is not a finite number above 0; * - `opening` — an opening that is not a well-formed `'clearing'` point at * or before the leg's first entry (or `null`, or absent); * - `entries` — a leg's `entries` is not an array; * - `empty-leg` — a leg with no entries: pass only the legs you have; * - `entry` — an entry that is not an object (or a hole); * - `timestamp` / `tvl` — not a finite number at or above 0; * - `kind` — neither `'clearing'` nor `'current'`; * - `order` — timestamps going backwards within a leg; * - `current` — a `current` point that is not the leg's last, or some legs * ending in one and others not; * - `overflow` — a sum too large to be a finite number. */ export type TvlHistoryInputErrorCode = 'legs' | 'leg' | 'usd-rate' | 'opening' | 'entries' | 'empty-leg' | 'entry' | 'timestamp' | 'tvl' | 'kind' | 'order' | 'current' | 'overflow'; /** * What `combineTvlHistories` throws instead of returning a number it cannot * stand behind. `leg` and `entry` are the zero-based position of the * offending input, when there is one. */ export declare class TvlHistoryInputError extends Error { readonly code: TvlHistoryInputErrorCode; readonly leg: number | undefined; readonly entry: number | undefined; constructor(code: TvlHistoryInputErrorCode, leg?: number, entry?: number); } /** * A strategy's TVL in USD over time, from its deployments' histories — Tax * Pay runs on Base (USDC) and on XDC (AUDD), and its total lent is both. * Pure: the caller fetches each leg (`strategyDeployments` names them) and * passes the exchange rates. * * A step merge by time. At every distinct timestamp where any leg has a * clearing, the value is the sum over legs of that leg's latest point at or * before then, times its `usdRate`. A leg's `opening` — what it held just * before the window — is one more step: it counts from its own timestamp * until the leg's first entry, and the leg is 0 before it (or throughout, * before its first entry, without one). * Points that share a timestamp — clearings run in one block, or two chains * clearing in the same second — are one output point. The series ends with * one `current` point at the latest of the legs' `current` timestamps, equal * to the sum of their `current` values. Every leg must end in a `current` * point, or none may. * * The window is the union of the legs' windows: the series starts at the * earliest first entry of any leg. An `opening` is a value, never a point. * Without it, two windows cut at offset clearing times would count the * later-starting leg 0 at the left edge and draw a false step up; with it, * only a genuine late start (`opening: null`) counts 0. * * Every leg and entry is validated first: a bad input — an empty leg * included — throws `TvlHistoryInputError` (its `code` says why), so the * result never holds `NaN` or `Infinity`. The inputs are not modified. * * ```ts * const window = { count: 52 }; * const points = combineTvlHistories([ * { ...(await base.strategies.getPoolTvlHistoryWindow(basePool, window)), usdRate: 1 }, * { ...(await xdc.strategies.getPoolTvlHistoryWindow(xdcPool, window)), usdRate: audToUsd }, * ]); * ``` */ export declare function combineTvlHistories(legs: readonly TvlHistoryLeg[]): StrategyTvlHistoryEntry[];