import { Provider } from '@ethersproject/abstract-provider'; import { Signer } from 'ethers'; import { PoolTvlHistoryEntry } from '../../domain/pool-tvl'; import { SdkConfig } from '../../sdk-config'; import { NftBoostDirectus, PlatformOverviewDirectus } from './directus-types'; import { LendingPoolConfigurationSubgraph, LendingPoolSubgraph } from './subgraph-types'; import { PoolTvlHistoryOptions, PoolTvlHistoryResult } from './tvl-history'; import { BadAndDoubtfulDebts, FinancialReportingDocuments, LendingTotals, PoolCreditMetrics, PoolDelegateProfileAndHistory, PoolOverview, PoolRepayment, PoolTranche, RiskManagement } from './types'; /** Thrown by `getPoolTvlHistory` when no provider that serves past state is configured. */ export declare const NO_HISTORY_PROVIDER_MESSAGE = "getPoolTvlHistory: no history provider; pass historyProvider or set historyRpcUrls to RPCs that serve past state"; export declare class DataService { private _kasuConfig; private readonly _graph; private readonly _externalTvlAbi; private readonly _systemVariablesAbi; private readonly _directus; private _directusPoolOverview; private readonly _explicitHistoryProvider; private _builtHistoryProviders; /** Immutable past-block reads, kept for the life of this instance. */ private readonly _tvlHistoryCache; /** * @param historyProvider - a provider that SERVES PAST STATE (an archive * RPC), used only by `getPoolTvlHistory` for the off-chain TVL at old * blocks. Without one, providers are built on `SdkConfig.historyRpcUrls` * (tried in order); with neither, that one call throws * `NO_HISTORY_PROVIDER_MESSAGE`. Never the default provider: a pruned * node refuses old blocks. */ constructor(_kasuConfig: SdkConfig, signerOrProvider: Signer | Provider, historyProvider?: Provider); private getUrlFromFile; /** * Maps a pool ID to its metadata source pool ID. * Used for chains (XDC, Plume) that share Directus metadata with Base pools. */ private getMetadataPoolId; /** * Maps an array of pool IDs to their metadata source pool IDs. */ private getMetadataPoolIds; calculatePoolCapacity(poolCapacities: number[], poolCapacityPercentages: number[], index: number, spillOver: number, lendingPoolSubgraph: LendingPoolSubgraph, lendingPoolConfig: LendingPoolConfigurationSubgraph): { poolCapacity: number[]; poolCapacityPercentage: number[]; }; /** * The subgraph's per-epoch `interestRate` compounded into an APY. * Unchanged arithmetic — `EPOCHS_IN_YEAR` and the formula now come from * `domain/rates` so this file and `KSULocking` cannot drift apart. */ calculateApyForTranche(interestRate: string): number; getPlatformOverview(): Promise; getNftBoost(): Promise>; getOffChainTvl(poolIds: string[]): Promise>; /** * The pool's TVL — the total lent into it by everyone — at every cycle * boundary, then as of now: the data behind a TVL chart. * * One `clearing` point per FINISHED clearing, read at the block it * finished in (`LendingPoolClearing.endBlockNumber`), then one `current` * point. Every point is `poolTvl(onChain, offChain)`, the definition * `getPoolOverview` uses for `totalValueLocked.total`: * * - on-chain: `lendingPool.balance` from the subgraph, read with * time-travel queries (`block: { number }`); * - off-chain: `ExternalTVL.externalTVLOfPool(pool)` at the same block, * through the HISTORY providers (see the constructor). 0 before the * contract was deployed (decided by `getCode`, and only if the same * provider shows the pool's own code there); any failed read throws. * * The `current` point mixes two sources: the subgraph's latest balance * (and its latest block time) and `externalTVLOfPool` at `latest` on the * history provider. `getPoolOverview` reads the same two, the off-chain * one on the default provider, so the last point equals * `totalValueLocked.total` when both reads succeed. They can differ when * `getPoolOverview`'s off-chain read FAILS — it then falls back to 0 — * or when the figure moves between the two calls. * * Units: `tvl` in display units of the deployment's own stable token * (USDC on Base and XDC USDC, AUDD on XDC AUDD); `timestamp` in unix * seconds. Ascending in time. See `PoolTvlHistoryEntry`. * * Cost: one subgraph request for the clearings (per thousand), one per * hundred distinct uncached clearing blocks, a `currentEpochNumber` read; * then, on the history providers, one `externalTVLOfPool` per distinct * uncached block plus the latest, and one to about log2(n) `getCode`s — * at most `TVL_HISTORY_RPC_CONCURRENCY` in flight. Final blocks are * cached on this instance, so a second call reads only what is new. * `timeoutMs` (default 30 s) bounds the whole call. * * `[]` for a pool the subgraph does not know, for a window with no epoch * in it, and on a LITE deployment whose subgraph lacks the entities. On a * full deployment that schema error throws, like every network, indexing * or past-state failure. * * @throws RangeError / TypeError on a malformed option or a pool id that * is not an address, and `NO_HISTORY_PROVIDER_MESSAGE` when the * deployment has an `ExternalTVL` contract but no history provider — all * before any network read. `PoolTvlHistoryTimeoutError` / * `PoolTvlHistoryAbortedError` on the deadline or the signal, * `PastStateUnavailableError` from a pruned history provider. */ getPoolTvlHistory(poolId: string, options?: PoolTvlHistoryOptions): Promise; /** * `getPoolTvlHistory` — the same options, errors and `entries` — plus * `opening`: the pool's value just before the window, so a strategy * summed across deployments (`combineTvlHistories`) knows what each leg * held before its first point instead of counting it 0. * * `opening` is the newest finished clearing STRICTLY before the window's * first block (by `pickOpeningClearing`), read at its own block exactly * like every other point and through the same past-block cache; `null` * when the pool has no clearing before the window. Extra cost over * `getPoolTvlHistory`: * * - `count` only: one more clearing row in the same request (`count + 1`, * which always reaches past the window when older history exists); * - `fromEpoch` above 0: one more one-row subgraph request, in parallel * with the clearings; * - only when every left-out clearing finished in the window's first * block (a catch-up block that closed several epochs at once): one * more one-row request by block (`fetchClearingBeforeBlock`), after * the clearings — the common case never makes it; * - either way, the opening's block in the same batched time-travel read * and one more `externalTVLOfPool` read (cached once final). * * `{ entries: [], opening: null }` wherever `getPoolTvlHistory` returns * `[]`. */ getPoolTvlHistoryWindow(poolId: string, options?: PoolTvlHistoryOptions): Promise; private _poolTvlHistory; private _readPoolTvlHistory; /** The pool's balance at each block: cached final blocks, then one batch. */ private _balancesAtBlocks; /** `null` when the deployment has no `ExternalTVL` contract. */ private _externalTvlAddress; /** Seam for tests: the real reader over the history RPCs. */ private _createOffChainTvlReader; /** * The history RPCs, in fallback order: the explicit provider, else ONE * provider per `historyRpcUrls` entry — built here and nowhere else, * pinned to `SdkConfig.chainId` when known, each with a per-call timeout. * Built once per instance. */ private _historyRpcs; getPoolOverview(epochId: string, id_in?: string[]): Promise; getPerformanceFee(): Promise; getRiskManagement(id_in?: string[]): Promise; getPoolDelegateProfileAndHistory(id_in?: string[]): Promise; getPoolTranches(epochId: string, id_in?: string[]): Promise; getBadAndDoubtfulDebts(id_in?: string[]): Promise; getPoolCreditMetrics(id_in?: string[]): Promise; getFinancialReportingDocuments(id_in?: string[]): Promise; getRepayments(id_in?: string[]): Promise; getLendingTotals(poolOverviews: PoolOverview[]): Promise; calculateCompounding(amount: number, epochInterestRate: number, daysInvested: number, interestFee: number): number[]; calculateBonusInterestEarnings(earnedAmounts: number[], amount: number, bonusEpochInterest: number): number[]; }