import { PoolTvlHistoryEntry } from '../domain/pool-tvl'; import { StrategyRiskGroup } from '../domain/strategy-details'; import { DataService } from '../services/DataService/data-service'; import { PoolTvlHistoryOptions, PoolTvlHistoryResult } from '../services/DataService/tvl-history'; import { PoolDelegateProfileAndHistory } from '../services/DataService/types'; import { UserLending } from '../services/UserLending/user-lending'; import { DepositLimits, OriginatorHistory, PlatformStats, Strategy, StrategyRiskPerformance, StrategyTranche } from './types'; /** * High-level facade for browsing Kasu lending strategies (pools). * * Handles epoch fetching internally so callers never need to know about epochs. */ export declare class StrategiesFacade { private _dataService; private _userLending; /** * Chain pool id → the pool id its CMS record is keyed by (XDC pools * share their Base counterpart's editorial record). Lowercase keys. */ private _poolMetadataMapping; /** * The clock the CMS start dates are checked against (a date after it * is refused). Injected for tests; the current time otherwise. */ private _now; /** * Milliseconds on a clock that only moves forward, for the shared * CMS reads' 30-second lifetime — separate from `_now`, so a pinned * date clock cannot keep a read alive for ever. Injected for tests; * `Date.now` otherwise. */ private _memoClockMs; constructor(_dataService: DataService, _userLending: UserLending, /** * Chain pool id → the pool id its CMS record is keyed by (XDC pools * share their Base counterpart's editorial record). Lowercase keys. */ _poolMetadataMapping?: Record, /** * The clock the CMS start dates are checked against (a date after it * is refused). Injected for tests; the current time otherwise. */ _now?: () => Date, /** * Milliseconds on a clock that only moves forward, for the shared * CMS reads' 30-second lifetime — separate from `_now`, so a pinned * date clock cannot keep a read alive for ever. Injected for tests; * `Date.now` otherwise. */ _memoClockMs?: () => number); /** * Short-lived, per-instance memo of the two CMS-wide reads the pool * getters share, so a Details screen asking for the loss rate, the risk * groups and the originator together reads each collection once. Keyed * by read; holds the in-flight promise, so concurrent callers share it. * A REJECTED read is dropped at once, never served again — the next call * retries. */ private _cmsReads; private _memoCmsRead; private _riskManagementRecords; private _originatorProfiles; /** * The pool's loss rate and first-loss capital, from its CMS * risk-management record. `null` when the pool has no record. * * Each figure is a NUMBER or `null` — never a guess. The CMS returns * "numeric" fields as a number, a numeric string, an empty string or * null, and an empty string must not become a confident `0`: anything that * is not a finite number reads as `null` (render "—"). `poolLossRate` is a * 0..1 fraction. * * Requires `directusUrl`; without it the call rejects with * `NO_DIRECTUS_URL_MESSAGE`, like every CMS-only read. Shares its CMS * read with `getRiskManagementGroups` for 30 seconds per instance; a * failed read is never reused. */ getRiskPerformance(poolId: string): Promise; /** * The credit originator's profile and lending history for a pool — the * CMS record whose `otherKASUPools` lists it. `null` when none does. * * Matched on the chain pool id, then on its metadata id, case- * insensitively. The record is returned as the service maps it; its * numeric fields are CMS-authored, so read them defensively. * * The service filters `otherKASUPools` through the CURRENT chain's * subgraph with the CMS record's (Base-keyed) ids, so on an XDC * deployment every profile lists no pools and this resolves `null` — * the same answer kasu-ui's own lookup gives there today. The metadata * candidate becomes live once the service resolves the mapping. * * Shares its reads with `getOriginatorHistory` for 30 seconds per * instance; a failed read is never reused. Each call returns its own * copy of the profile, so mutating it changes nothing shared. */ getOriginator(poolId: string): Promise; /** * The credit originator's ENTIRE lending history for a pool — since when, * total originated, loans outstanding, loss rate — read from the profile * `getOriginator` finds, each figure validated. `null` when no profile * lists the pool, or the profile authors none of the four. * * kasu-ui's Details tab shows these as its Credit Originator strip, and * hides the strip when there is no profile. The money figures are * editorial USD on every deployment: never FX-convert them. An XDC pool * resolves `null` today, as it does in kasu-ui (see `getOriginator`). * * Requires `directusUrl`, like every CMS-only read; rejects when the * read fails. Shares its reads with `getOriginator` for 30 seconds per * instance; a failed read is never reused. */ getOriginatorHistory(poolId: string): Promise; /** * The pool's Risk Management groups, from its CMS risk-management record: * each group with its items (name, the pool's description of it split * into lines, the shared tooltip), the groups in `RISK_GROUP_ORDER` * (Security & Recourse, Structural Controls, Financial Covenants, * Reporting Covenants, Key Eligibility Criteria, then any other in CMS * order). See `groupRiskManagementItems`. * * `null` when the pool has no record, or the record has no usable item — * then kasu-ui falls back to `Strategy.securityStructure`. XDC pools * resolve through the metadata mapping to their Base record, like * `getRiskPerformance`. * * REJECTS when the CMS read fails (an outage, or no `directusUrl` — * `NO_DIRECTUS_URL_MESSAGE`), so a failure stays visible rather than * reading as "no items". For what to SHOW, treat a rejection like `null`: * fall back to `Strategy.securityStructure`, which arrives with the * strategy and needs no second read. * * Shares its CMS read with `getRiskPerformance` for 30 seconds per * instance; a failed read is never reused. */ getRiskManagementGroups(poolId: string): Promise; private _metadataIdOf; /** * Fetch all active lending strategies. * * ```ts * const strategies = await kasu.strategies.getAll(); * ``` */ getAll(poolIds?: string[]): Promise; /** * The strategies a lender should actually see: active, not oversubscribed, * with the ones that still have capacity first and the highest max APY * next. `getAll` returns everything the subgraph knows about, including * pools that are wound down. * * The filter runs on the raw `PoolOverview[]` BEFORE mapping, so `_raw` on * every returned `Strategy` is the untouched pool object. */ getVisible(poolIds?: string[]): Promise; /** * The chain's performance fee. * * ⚠️ A PERCENTAGE IN 0..100 (`10` means ten percent), NOT a fraction — * feed it to `netEffectiveApy` as-is. Treating it as `0.10` computes a * nonsense negative rate that still renders as a plausible-looking * percentage, which is why the units are stated here and in * `netEffectiveApy`'s own JSDoc. * * ```ts * const feePercent = await kasu.strategies.getPerformanceFeePercent(); * const net = netEffectiveApy(strategy.tranches[0].apy, feePercent); * ``` */ getPerformanceFeePercent(): Promise; /** * The strategy's TVL (total lent by everyone) at every cycle boundary, * then as of now — the data behind a TVL chart. Ascending in time; the * last point (`kind: 'current'`) equals `strategy.tvl.total` when both * calls' reads succeed (see `PoolTvlHistoryEntry`). * * `tvl` is in display units of the deployment's OWN stable token (USDC on * Base and XDC USDC, AUDD on XDC AUDD); `timestamp` is unix SECONDS. * `{ count }` = the newest `count` epochs, `{ fromEpoch }` = from that * epoch on; `timeoutMs` (default 30 s) and `signal` bound the call. A * malformed option throws before any network read. See * `DataService.getPoolTvlHistory` for the reads, the cost and the errors. * * ```ts * const points = await kasu.strategies.getPoolTvlHistory(poolId, { count: 52 }); * ``` */ getPoolTvlHistory(poolId: string, options?: PoolTvlHistoryOptions): Promise; /** * `getPoolTvlHistory` plus `opening` — the newest clearing before the * window, read at its own block like every other point, or `null` when * the pool has none — from the same read. Pass the result to * `combineTvlHistories` as a leg with its `usdRate`: the opening is what * the leg held before its first point, so a window cut at a different * time on another chain does not count it 0. Same options and errors as * `getPoolTvlHistory`; the extra cost is one clearing row (or, for * `fromEpoch`, one small request) and one block. * * ```ts * const leg = await kasu.strategies.getPoolTvlHistoryWindow(poolId, { count: 52 }); * // { entries: PoolTvlHistoryEntry[], opening: PoolTvlHistoryEntry | null } * ``` */ getPoolTvlHistoryWindow(poolId: string, options?: PoolTvlHistoryOptions): Promise; /** * Fetch a single strategy by pool ID. Returns `null` if not found. */ getById(poolId: string): Promise; /** * Aggregate platform statistics (TVL, loans, yield, loss rate). */ getPlatformStats(): Promise; /** * Calculate deposit limits for a specific tranche. * * @param tranche - A `StrategyTranche` from `getAll()` or `getById()`. * @returns min/max/capacity in ether-formatted USDC strings. */ calculateDepositLimits(tranche: StrategyTranche): DepositLimits; private mapPoolToStrategy; }