@kasufinance/kasu-sdk 2.13.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -1
- package/dist/bundle.cjs.js +580 -60
- package/dist/bundle.esm.js +577 -61
- package/dist/domain/index.d.ts +2 -2
- package/dist/domain/pool-tvl.d.ts +104 -0
- package/dist/domain/requests.d.ts +11 -10
- package/dist/facade/index.d.ts +2 -0
- package/dist/facade/strategies.d.ts +17 -1
- package/dist/facade/strategy-deployments.d.ts +65 -0
- package/dist/index.d.ts +1 -1
- package/dist/services/DataService/data-service.d.ts +29 -1
- package/dist/services/DataService/tvl-history.d.ts +49 -0
- package/dist/services/UserLending/subgraph-types.d.ts +2 -8
- package/dist/services/UserLending/types.d.ts +10 -0
- package/dist/services/UserLending/user-lending.d.ts +14 -0
- package/package.json +1 -1
- package/src/domain/index.ts +7 -2
- package/src/domain/pool-tvl.ts +281 -0
- package/src/domain/requests.ts +37 -23
- package/src/facade/index.ts +10 -0
- package/src/facade/strategies.ts +26 -1
- package/src/facade/strategy-deployments.ts +161 -0
- package/src/index.ts +4 -1
- package/src/services/DataService/data-service.ts +103 -7
- package/src/services/DataService/tvl-history.ts +131 -0
- package/src/services/UserLending/queries.ts +2 -7
- package/src/services/UserLending/subgraph-types.ts +2 -8
- package/src/services/UserLending/types.ts +10 -0
- package/src/services/UserLending/user-lending.ts +98 -40
package/dist/domain/index.d.ts
CHANGED
|
@@ -55,8 +55,8 @@ export { compareTrancheSeniority, derivePoolStatus, MIN_TRANCHE_CAPACITY, netTra
|
|
|
55
55
|
export type { ApyBounds, PoolStatus, TrancheCapacitySignal } from './tranches';
|
|
56
56
|
export { classifyWalletFailure, isUnpredictableGas, isUserRejected, } from './wallet-errors';
|
|
57
57
|
export type { WalletFailure } from './wallet-errors';
|
|
58
|
-
export { poolTvl } from './pool-tvl';
|
|
59
|
-
export type { PoolTvlHistoryEntry } from './pool-tvl';
|
|
58
|
+
export { combineTvlHistories, poolTvl, TvlHistoryInputError } from './pool-tvl';
|
|
59
|
+
export type { PoolTvlHistoryEntry, StrategyTvlHistoryEntry, TvlHistoryInputErrorCode, TvlHistoryLeg, } from './pool-tvl';
|
|
60
60
|
export { aggregateYieldHistory, epochTrancheYield } from './yield-history';
|
|
61
61
|
export type { EpochLockShares, EpochTrancheYield, EpochTrancheYieldInput, YieldHistoryEntry, YieldHistoryFilter, YieldHistoryPoint, } from './yield-history';
|
|
62
62
|
export { accruedInterest, dailyInterest, projectedAnnualEarnings, SECONDS_PER_WEEK, weeklyInterest, weightedAverageApy, } from './yields';
|
|
@@ -60,3 +60,107 @@ export interface PoolTvlHistoryEntry {
|
|
|
60
60
|
/** `'clearing'` for a cycle boundary; `'current'` for the closing point. */
|
|
61
61
|
kind: 'clearing' | 'current';
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* One deployment's share of a strategy's history, for `combineTvlHistories`:
|
|
65
|
+
* that pool's `getPoolTvlHistoryWindow` result (`{ entries, opening }`) as it
|
|
66
|
+
* came back, and what one unit of the deployment's stable token is worth in
|
|
67
|
+
* USD (`1` for USDC; today's AUD→USD for AUDD). The SDK fetches no exchange
|
|
68
|
+
* rate: the caller passes it.
|
|
69
|
+
*/
|
|
70
|
+
export interface TvlHistoryLeg {
|
|
71
|
+
/** At least one point: a real pool always returns its `current` point. */
|
|
72
|
+
entries: readonly PoolTvlHistoryEntry[];
|
|
73
|
+
/** USD per unit of the leg's stable token. Finite and above 0. */
|
|
74
|
+
usdRate: number;
|
|
75
|
+
/**
|
|
76
|
+
* The leg's step BEFORE its first entry: the newest clearing before the
|
|
77
|
+
* window, as `getPoolTvlHistoryWindow` read it at its own block. It
|
|
78
|
+
* counts from its own `timestamp` on, and the leg is 0 before that — no
|
|
79
|
+
* value is carried back to a time before it existed. A `'clearing'`
|
|
80
|
+
* point no later than the first entry; it is never drawn. `null` or
|
|
81
|
+
* absent: the pool has no clearing before the window (it started lending
|
|
82
|
+
* later, say) and counts 0 before its first entry.
|
|
83
|
+
*/
|
|
84
|
+
opening?: PoolTvlHistoryEntry | null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* One point of a strategy's TVL summed across its deployments.
|
|
88
|
+
*
|
|
89
|
+
* There is no `epochId`: each chain clears at its own blocks and times, so a
|
|
90
|
+
* merged point belongs to no single epoch. Plot by `timestamp`.
|
|
91
|
+
*/
|
|
92
|
+
export interface StrategyTvlHistoryEntry {
|
|
93
|
+
/** Unix SECONDS. Strictly ascending across the series. */
|
|
94
|
+
timestamp: number;
|
|
95
|
+
/** The sum over legs of each leg's TVL then, times its `usdRate`. */
|
|
96
|
+
tvlUsd: number;
|
|
97
|
+
/** `'clearing'` for a cycle boundary on any leg; `'current'` for the closing point. */
|
|
98
|
+
kind: 'clearing' | 'current';
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* What `combineTvlHistories` refuses, as a code:
|
|
102
|
+
*
|
|
103
|
+
* - `legs` — not a non-empty array (or one with holes);
|
|
104
|
+
* - `leg` — a leg that is not an object;
|
|
105
|
+
* - `usd-rate` — a rate that is not a finite number above 0;
|
|
106
|
+
* - `opening` — an opening that is not a well-formed `'clearing'` point at
|
|
107
|
+
* or before the leg's first entry (or `null`, or absent);
|
|
108
|
+
* - `entries` — a leg's `entries` is not an array;
|
|
109
|
+
* - `empty-leg` — a leg with no entries: pass only the legs you have;
|
|
110
|
+
* - `entry` — an entry that is not an object (or a hole);
|
|
111
|
+
* - `timestamp` / `tvl` — not a finite number at or above 0;
|
|
112
|
+
* - `kind` — neither `'clearing'` nor `'current'`;
|
|
113
|
+
* - `order` — timestamps going backwards within a leg;
|
|
114
|
+
* - `current` — a `current` point that is not the leg's last, or some legs
|
|
115
|
+
* ending in one and others not;
|
|
116
|
+
* - `overflow` — a sum too large to be a finite number.
|
|
117
|
+
*/
|
|
118
|
+
export type TvlHistoryInputErrorCode = 'legs' | 'leg' | 'usd-rate' | 'opening' | 'entries' | 'empty-leg' | 'entry' | 'timestamp' | 'tvl' | 'kind' | 'order' | 'current' | 'overflow';
|
|
119
|
+
/**
|
|
120
|
+
* What `combineTvlHistories` throws instead of returning a number it cannot
|
|
121
|
+
* stand behind. `leg` and `entry` are the zero-based position of the
|
|
122
|
+
* offending input, when there is one.
|
|
123
|
+
*/
|
|
124
|
+
export declare class TvlHistoryInputError extends Error {
|
|
125
|
+
readonly code: TvlHistoryInputErrorCode;
|
|
126
|
+
readonly leg: number | undefined;
|
|
127
|
+
readonly entry: number | undefined;
|
|
128
|
+
constructor(code: TvlHistoryInputErrorCode, leg?: number, entry?: number);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A strategy's TVL in USD over time, from its deployments' histories — Tax
|
|
132
|
+
* Pay runs on Base (USDC) and on XDC (AUDD), and its total lent is both.
|
|
133
|
+
* Pure: the caller fetches each leg (`strategyDeployments` names them) and
|
|
134
|
+
* passes the exchange rates.
|
|
135
|
+
*
|
|
136
|
+
* A step merge by time. At every distinct timestamp where any leg has a
|
|
137
|
+
* clearing, the value is the sum over legs of that leg's latest point at or
|
|
138
|
+
* before then, times its `usdRate`. A leg's `opening` — what it held just
|
|
139
|
+
* before the window — is one more step: it counts from its own timestamp
|
|
140
|
+
* until the leg's first entry, and the leg is 0 before it (or throughout,
|
|
141
|
+
* before its first entry, without one).
|
|
142
|
+
* Points that share a timestamp — clearings run in one block, or two chains
|
|
143
|
+
* clearing in the same second — are one output point. The series ends with
|
|
144
|
+
* one `current` point at the latest of the legs' `current` timestamps, equal
|
|
145
|
+
* to the sum of their `current` values. Every leg must end in a `current`
|
|
146
|
+
* point, or none may.
|
|
147
|
+
*
|
|
148
|
+
* The window is the union of the legs' windows: the series starts at the
|
|
149
|
+
* earliest first entry of any leg. An `opening` is a value, never a point.
|
|
150
|
+
* Without it, two windows cut at offset clearing times would count the
|
|
151
|
+
* later-starting leg 0 at the left edge and draw a false step up; with it,
|
|
152
|
+
* only a genuine late start (`opening: null`) counts 0.
|
|
153
|
+
*
|
|
154
|
+
* Every leg and entry is validated first: a bad input — an empty leg
|
|
155
|
+
* included — throws `TvlHistoryInputError` (its `code` says why), so the
|
|
156
|
+
* result never holds `NaN` or `Infinity`. The inputs are not modified.
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const window = { count: 52 };
|
|
160
|
+
* const points = combineTvlHistories([
|
|
161
|
+
* { ...(await base.strategies.getPoolTvlHistoryWindow(basePool, window)), usdRate: 1 },
|
|
162
|
+
* { ...(await xdc.strategies.getPoolTvlHistoryWindow(xdcPool, window)), usdRate: audToUsd },
|
|
163
|
+
* ]);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function combineTvlHistories(legs: readonly TvlHistoryLeg[]): StrategyTvlHistoryEntry[];
|
|
@@ -65,10 +65,13 @@ export interface RequestState {
|
|
|
65
65
|
statusCode: RequestStatusCode;
|
|
66
66
|
kind: RequestKind;
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* `
|
|
68
|
+
* `UserRequest.requestedAmount`, in assets: the amount still OUTSTANDING,
|
|
69
|
+
* which the subgraph reduces as parts are accepted or rejected (0 once a
|
|
70
|
+
* request is fully resolved). A cancelled request has it zeroed by the
|
|
71
|
+
* subgraph, so for a cancellation it is the `Cancelled` event's amount —
|
|
72
|
+
* what was outstanding when cancelled, top-ups included — falling back to
|
|
73
|
+
* the `Initiated` event (see `initiatedAmount`) only when that event
|
|
74
|
+
* carries none.
|
|
72
75
|
*/
|
|
73
76
|
requestedAmount: number;
|
|
74
77
|
/**
|
|
@@ -207,17 +210,15 @@ export declare function cancelDeadline(request: Pick<RequestState, 'canCancel' |
|
|
|
207
210
|
* Convert a `UserRequest` into a `RequestState`. Pure — no clock, no network,
|
|
208
211
|
* no copy.
|
|
209
212
|
*
|
|
210
|
-
* BRANCH ORDER (this IS the behaviour
|
|
211
|
-
* `deriveTransactionView` check for check):
|
|
213
|
+
* BRANCH ORDER (this IS the behaviour):
|
|
212
214
|
*
|
|
213
215
|
* 1. a `Cancelled` event → `cancelled`, neutral, 0
|
|
214
216
|
* 2. a withdrawal with a `Forced` event → `forced`, outflow, −accepted
|
|
215
217
|
* 3. a reallocated deposit → `reallocated`, inflow, +accepted
|
|
216
|
-
* 4. a withdrawal partly filled
|
|
217
|
-
* remainder (cycle
|
|
218
|
+
* 4. a withdrawal partly filled (paid > 0) with
|
|
219
|
+
* a LIVE remainder (queued > 0, cycle open) → `partial`, outflow, −accepted
|
|
218
220
|
* 5. resolved (`status === 'Processed'`):
|
|
219
|
-
* withdrawal
|
|
220
|
-
* withdrawal, fully filled → `complete`, outflow, −accepted
|
|
221
|
+
* withdrawal (nothing left queued) → `complete`, outflow, −accepted
|
|
221
222
|
* deposit, nothing accepted → `rejected`, neutral, 0
|
|
222
223
|
* deposit, part rejected → `partial`, inflow, +accepted
|
|
223
224
|
* deposit, fully accepted → `complete`, inflow, +accepted
|
package/dist/facade/index.d.ts
CHANGED
|
@@ -8,5 +8,7 @@ export type { RequestWithdrawalCallParams } from './calls';
|
|
|
8
8
|
export type { DepositFlowPortOverrides, WithdrawFlowPortOverrides, } from './flows';
|
|
9
9
|
export { READ_ONLY_MESSAGE } from './read-only';
|
|
10
10
|
export { CHAIN_CONFIGS } from './chain-configs';
|
|
11
|
+
export { StrategyDeploymentInputError, strategyDeployments, } from './strategy-deployments';
|
|
12
|
+
export type { StrategyDeployment, StrategyDeploymentInputErrorCode, } from './strategy-deployments';
|
|
11
13
|
export { fetchUnusedPoolIds } from './unused-pool-ids';
|
|
12
14
|
export type { SupportedChain, ChainConfigEntry, StableAsset, KasuOptions, Strategy, StrategyTranche, FixedTermOption, DepositParams, WithdrawParams, DepositLimits, KycParams, UserPositions, PlatformStats, StrategyRiskPerformance, } from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoolTvlHistoryEntry } from '../domain/pool-tvl';
|
|
2
2
|
import { DataService } from '../services/DataService/data-service';
|
|
3
|
-
import { PoolTvlHistoryOptions } from '../services/DataService/tvl-history';
|
|
3
|
+
import { PoolTvlHistoryOptions, PoolTvlHistoryResult } from '../services/DataService/tvl-history';
|
|
4
4
|
import { PoolDelegateProfileAndHistory } from '../services/DataService/types';
|
|
5
5
|
import { UserLending } from '../services/UserLending/user-lending';
|
|
6
6
|
import { DepositLimits, PlatformStats, Strategy, StrategyRiskPerformance, StrategyTranche } from './types';
|
|
@@ -104,6 +104,22 @@ export declare class StrategiesFacade {
|
|
|
104
104
|
* ```
|
|
105
105
|
*/
|
|
106
106
|
getPoolTvlHistory(poolId: string, options?: PoolTvlHistoryOptions): Promise<PoolTvlHistoryEntry[]>;
|
|
107
|
+
/**
|
|
108
|
+
* `getPoolTvlHistory` plus `opening` — the newest clearing before the
|
|
109
|
+
* window, read at its own block like every other point, or `null` when
|
|
110
|
+
* the pool has none — from the same read. Pass the result to
|
|
111
|
+
* `combineTvlHistories` as a leg with its `usdRate`: the opening is what
|
|
112
|
+
* the leg held before its first point, so a window cut at a different
|
|
113
|
+
* time on another chain does not count it 0. Same options and errors as
|
|
114
|
+
* `getPoolTvlHistory`; the extra cost is one clearing row (or, for
|
|
115
|
+
* `fromEpoch`, one small request) and one block.
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* const leg = await kasu.strategies.getPoolTvlHistoryWindow(poolId, { count: 52 });
|
|
119
|
+
* // { entries: PoolTvlHistoryEntry[], opening: PoolTvlHistoryEntry | null }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
getPoolTvlHistoryWindow(poolId: string, options?: PoolTvlHistoryOptions): Promise<PoolTvlHistoryResult>;
|
|
107
123
|
/**
|
|
108
124
|
* Fetch a single strategy by pool ID. Returns `null` if not found.
|
|
109
125
|
*/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ChainConfigEntry, SupportedChain } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Strategy ↔ deployment resolution. A lending strategy is not tied to one
|
|
4
|
+
* deployment: Tax Pay runs as one pool on Base (USDC) and another on XDC
|
|
5
|
+
* (AUDD), and the two share one CMS record keyed by the BASE pool id — the
|
|
6
|
+
* canonical id. Each chain config's `poolMetadataMapping` maps its
|
|
7
|
+
* chain-local ids to canonical ones; Base, being canonical, has none.
|
|
8
|
+
*
|
|
9
|
+
* Pure: it reads only the built-in `CHAIN_CONFIGS`. The same rules as
|
|
10
|
+
* kasu-ui's counterpart lookup, so both apps sum a strategy over the same
|
|
11
|
+
* pools.
|
|
12
|
+
*/
|
|
13
|
+
/** The pool that represents a strategy on one deployment. */
|
|
14
|
+
export interface StrategyDeployment {
|
|
15
|
+
chain: SupportedChain;
|
|
16
|
+
/**
|
|
17
|
+
* Chain-local pool id, lowercase — what that chain's subgraph is keyed
|
|
18
|
+
* by.
|
|
19
|
+
*/
|
|
20
|
+
poolId: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* What `strategyDeployments` refuses, as a code:
|
|
24
|
+
*
|
|
25
|
+
* - `pool-id` — not a `0x` address;
|
|
26
|
+
* - `chain` — not a `SupportedChain`;
|
|
27
|
+
* - `wrong-chain` — the mapping places the id on ANOTHER deployment (an XDC
|
|
28
|
+
* chain-local id passed as Base, or a Base id passed as XDC). Querying one
|
|
29
|
+
* chain with another's address reads nothing, silently.
|
|
30
|
+
*/
|
|
31
|
+
export type StrategyDeploymentInputErrorCode = 'pool-id' | 'chain' | 'wrong-chain';
|
|
32
|
+
/** What `strategyDeployments` throws for an id it cannot place. */
|
|
33
|
+
export declare class StrategyDeploymentInputError extends Error {
|
|
34
|
+
readonly code: StrategyDeploymentInputErrorCode;
|
|
35
|
+
constructor(code: StrategyDeploymentInputErrorCode);
|
|
36
|
+
}
|
|
37
|
+
type MappingConfigs = Readonly<Record<SupportedChain, Pick<ChainConfigEntry, 'poolMetadataMapping'>>>;
|
|
38
|
+
/**
|
|
39
|
+
* `strategyDeployments` over any configs — the export reads `CHAIN_CONFIGS`;
|
|
40
|
+
* the spec passes its own to cover shapes the built-in mapping lacks.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveStrategyDeployments(configs: MappingConfigs, poolId: string, chain: SupportedChain): StrategyDeployment[];
|
|
43
|
+
/**
|
|
44
|
+
* Every deployment a strategy has a pool on, canonical (Base) first, then the
|
|
45
|
+
* others in `CHAIN_CONFIGS` order — the legs to fetch and pass to
|
|
46
|
+
* `combineTvlHistories`. One entry for a strategy that lives on one chain
|
|
47
|
+
* only (PayFi, on Base).
|
|
48
|
+
*
|
|
49
|
+
* `chain` is the deployment `poolId` was read on — required, because an
|
|
50
|
+
* address alone does not say which chain it belongs to. From either side of
|
|
51
|
+
* a mapping the answer is the same set: Tax Pay's Base id on `'base'` and
|
|
52
|
+
* its XDC id on `'xdc'` both return both pools. An id the mapping does not
|
|
53
|
+
* know is a strategy of one on its own chain. Ids are compared
|
|
54
|
+
* case-insensitively and returned lowercase.
|
|
55
|
+
*
|
|
56
|
+
* Throws `StrategyDeploymentInputError` for a malformed id, an unknown chain,
|
|
57
|
+
* or an id the mapping places on another deployment (`'wrong-chain'`).
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* strategyDeployments(strategy.id, 'base');
|
|
61
|
+
* // [{ chain: 'base', poolId: '0x…' }, { chain: 'xdc', poolId: '0x…' }]
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function strategyDeployments(poolId: string, chain: SupportedChain): StrategyDeployment[];
|
|
65
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { PoolOverview, TrancheData, LendingTotals, PoolRepayment, RiskManag
|
|
|
6
6
|
export type { UserRequest, UserRequestEvent, UserTrancheBalance, UserPoolBalance, UserApyBonus, PortfolioUserTrancheBalance, } from './services/UserLending/types';
|
|
7
7
|
export type { PortfolioSummary, PortfolioLendingPool, PortfolioTranche, PortfolioRewards, PortfolioTrancheDepositDetails, } from './services/Portfolio/types';
|
|
8
8
|
export type { YieldHistoryOptions } from './services/Portfolio/yield-history';
|
|
9
|
-
export type { PoolTvlHistoryOptions } from './services/DataService/tvl-history';
|
|
9
|
+
export type { PoolTvlHistoryOptions, PoolTvlHistoryResult, } from './services/DataService/tvl-history';
|
|
10
10
|
export { PastStateUnavailableError, PoolTvlHistoryAbortedError, PoolTvlHistoryTimeoutError, } from './services/DataService/tvl-history';
|
|
11
11
|
export { NO_HISTORY_PROVIDER_MESSAGE } from './services/DataService/data-service';
|
|
12
12
|
export type { UserLock, UserBonusData, LockPeriod, GQLGetLockingPeriods, SystemVariables, } from './services/Locking/types';
|
|
@@ -4,7 +4,7 @@ import { PoolTvlHistoryEntry } from '../../domain/pool-tvl';
|
|
|
4
4
|
import { SdkConfig } from '../../sdk-config';
|
|
5
5
|
import { NftBoostDirectus, PlatformOverviewDirectus } from './directus-types';
|
|
6
6
|
import { LendingPoolConfigurationSubgraph, LendingPoolSubgraph } from './subgraph-types';
|
|
7
|
-
import { PoolTvlHistoryOptions } from './tvl-history';
|
|
7
|
+
import { PoolTvlHistoryOptions, PoolTvlHistoryResult } from './tvl-history';
|
|
8
8
|
import { BadAndDoubtfulDebts, FinancialReportingDocuments, LendingTotals, PoolCreditMetrics, PoolDelegateProfileAndHistory, PoolOverview, PoolRepayment, PoolTranche, RiskManagement } from './types';
|
|
9
9
|
/** Thrown by `getPoolTvlHistory` when no provider that serves past state is configured. */
|
|
10
10
|
export declare const NO_HISTORY_PROVIDER_MESSAGE = "getPoolTvlHistory: no history provider; pass historyProvider or set historyRpcUrls to RPCs that serve past state";
|
|
@@ -100,6 +100,34 @@ export declare class DataService {
|
|
|
100
100
|
* `PastStateUnavailableError` from a pruned history provider.
|
|
101
101
|
*/
|
|
102
102
|
getPoolTvlHistory(poolId: string, options?: PoolTvlHistoryOptions): Promise<PoolTvlHistoryEntry[]>;
|
|
103
|
+
/**
|
|
104
|
+
* `getPoolTvlHistory` — the same options, errors and `entries` — plus
|
|
105
|
+
* `opening`: the pool's value just before the window, so a strategy
|
|
106
|
+
* summed across deployments (`combineTvlHistories`) knows what each leg
|
|
107
|
+
* held before its first point instead of counting it 0.
|
|
108
|
+
*
|
|
109
|
+
* `opening` is the newest finished clearing STRICTLY before the window's
|
|
110
|
+
* first block (by `pickOpeningClearing`), read at its own block exactly
|
|
111
|
+
* like every other point and through the same past-block cache; `null`
|
|
112
|
+
* when the pool has no clearing before the window. Extra cost over
|
|
113
|
+
* `getPoolTvlHistory`:
|
|
114
|
+
*
|
|
115
|
+
* - `count` only: one more clearing row in the same request (`count + 1`,
|
|
116
|
+
* which always reaches past the window when older history exists);
|
|
117
|
+
* - `fromEpoch` above 0: one more one-row subgraph request, in parallel
|
|
118
|
+
* with the clearings;
|
|
119
|
+
* - only when every left-out clearing finished in the window's first
|
|
120
|
+
* block (a catch-up block that closed several epochs at once): one
|
|
121
|
+
* more one-row request by block (`fetchClearingBeforeBlock`), after
|
|
122
|
+
* the clearings — the common case never makes it;
|
|
123
|
+
* - either way, the opening's block in the same batched time-travel read
|
|
124
|
+
* and one more `externalTVLOfPool` read (cached once final).
|
|
125
|
+
*
|
|
126
|
+
* `{ entries: [], opening: null }` wherever `getPoolTvlHistory` returns
|
|
127
|
+
* `[]`.
|
|
128
|
+
*/
|
|
129
|
+
getPoolTvlHistoryWindow(poolId: string, options?: PoolTvlHistoryOptions): Promise<PoolTvlHistoryResult>;
|
|
130
|
+
private _poolTvlHistory;
|
|
103
131
|
private _readPoolTvlHistory;
|
|
104
132
|
/** The pool's balance at each block: cached final blocks, then one batch. */
|
|
105
133
|
private _balancesAtBlocks;
|
|
@@ -31,6 +31,21 @@ export interface PoolTvlHistoryOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
signal?: AbortSignal;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* `getPoolTvlHistoryWindow`'s answer: the same entries `getPoolTvlHistory`
|
|
36
|
+
* returns, and the pool's value just before them. Pass it to
|
|
37
|
+
* `combineTvlHistories` as a leg (`{ ...result, usdRate }`).
|
|
38
|
+
*/
|
|
39
|
+
export interface PoolTvlHistoryResult {
|
|
40
|
+
entries: PoolTvlHistoryEntry[];
|
|
41
|
+
/**
|
|
42
|
+
* The newest finished clearing BEFORE the window, in a block strictly
|
|
43
|
+
* before the first entry's, read at its own block like every other point
|
|
44
|
+
* (`kind: 'clearing'`). `null` when the pool has no clearing before the
|
|
45
|
+
* window — its whole history is in `entries`. See `pickOpeningClearing`.
|
|
46
|
+
*/
|
|
47
|
+
opening: PoolTvlHistoryEntry | null;
|
|
48
|
+
}
|
|
34
49
|
/** The resolved, inclusive epoch range; `null` when it is empty. */
|
|
35
50
|
export interface PoolTvlHistoryWindow {
|
|
36
51
|
fromEpoch: number;
|
|
@@ -171,6 +186,40 @@ export declare function fetchPoolClearings(request: GraphRequest, poolId: string
|
|
|
171
186
|
snapshot: PoolTvlSnapshot;
|
|
172
187
|
requests: number;
|
|
173
188
|
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Pure: the opening clearing — the newest of `before` (finished clearings the
|
|
191
|
+
* window left out, older by epoch) that finished STRICTLY before the first
|
|
192
|
+
* in-window clearing's block. Newest by block, then epoch, so a clearing
|
|
193
|
+
* numbered out of order (XDC AUDD's epoch 1, a week before epoch 88) is
|
|
194
|
+
* placed by when it happened. A clearing in the first in-window block itself
|
|
195
|
+
* (a catch-up block that finished several epochs at once) is not an opening:
|
|
196
|
+
* it holds the first entry's own value, not the one before it. `null` when
|
|
197
|
+
* there is none — see `needsClearingBeforeBlock`.
|
|
198
|
+
*/
|
|
199
|
+
export declare function pickOpeningClearing(before: readonly Clearing[], inWindow: readonly Clearing[]): Clearing | null;
|
|
200
|
+
/**
|
|
201
|
+
* Pure: whether the opening needs `fetchClearingBefore`'s by-block read.
|
|
202
|
+
* Only when the window left clearings out but every one of them finished in
|
|
203
|
+
* or after the first in-window block — the extra rows sat in a catch-up
|
|
204
|
+
* block — so an older one, if any, was not fetched. Otherwise the opening
|
|
205
|
+
* (or its absence) is already known and nothing more is read.
|
|
206
|
+
*/
|
|
207
|
+
export declare function needsClearingBeforeBlock(before: readonly Clearing[], opening: Clearing | null): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* The newest finished clearing in a block below `blockLt`, by block: the
|
|
210
|
+
* opening when every clearing the window left out shares its first block.
|
|
211
|
+
* ONE extra request for one row, no snapshot. Clearings that share that
|
|
212
|
+
* older block share its time and balance, so which one comes back does not
|
|
213
|
+
* change the value.
|
|
214
|
+
*/
|
|
215
|
+
export declare const poolTvlClearingBeforeBlockQuery: string;
|
|
216
|
+
export declare function fetchClearingBeforeBlock(request: GraphRequest, poolId: string, blockLt: number, cancellation: Cancellation): Promise<Clearing | null>;
|
|
217
|
+
/**
|
|
218
|
+
* The newest finished clearing numbered below `beforeEpoch`: the opening
|
|
219
|
+
* candidate of a `fromEpoch` window, whose own fetch never reads that far
|
|
220
|
+
* back. ONE extra request for one row, no snapshot.
|
|
221
|
+
*/
|
|
222
|
+
export declare function fetchClearingBefore(request: GraphRequest, poolId: string, beforeEpoch: number, cancellation: Cancellation): Promise<Clearing | null>;
|
|
174
223
|
/**
|
|
175
224
|
* The pool's balance (display units, the subgraph's decimal string) at the end
|
|
176
225
|
* of each block, `TVL_HISTORY_BLOCKS_PER_REQUEST` blocks per request. A block
|
|
@@ -69,8 +69,6 @@ export interface CurrentEpochFtdAmountSubgraph {
|
|
|
69
69
|
amountRequested: string;
|
|
70
70
|
tranche: {
|
|
71
71
|
id: string;
|
|
72
|
-
balance: string;
|
|
73
|
-
shares: string;
|
|
74
72
|
};
|
|
75
73
|
}[];
|
|
76
74
|
}
|
|
@@ -135,13 +133,9 @@ export interface CurrentFtdBalanceSubgraph {
|
|
|
135
133
|
configId: string;
|
|
136
134
|
lendingPoolTranche: {
|
|
137
135
|
id: string;
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
lendingPool: {
|
|
141
|
-
balance: string;
|
|
142
|
-
tranches: {
|
|
136
|
+
balance: string;
|
|
143
137
|
shares: string;
|
|
144
|
-
}
|
|
138
|
+
};
|
|
145
139
|
};
|
|
146
140
|
}[];
|
|
147
141
|
}
|
|
@@ -36,8 +36,18 @@ export interface UserRequest {
|
|
|
36
36
|
requestType: 'Deposit' | 'Withdrawal';
|
|
37
37
|
trancheId: string;
|
|
38
38
|
trancheName: string;
|
|
39
|
+
/**
|
|
40
|
+
* The amount still OUTSTANDING on the request, in assets (the
|
|
41
|
+
* deployment's stable token, display units) — not the amount first asked
|
|
42
|
+
* for: the subgraph takes accepted and rejected amounts off it, and a
|
|
43
|
+
* cancellation zeroes it. A deposit's figure is the asset amount as the
|
|
44
|
+
* subgraph holds it (top-ups included); a withdrawal's is its remaining
|
|
45
|
+
* tranche shares at the tranche's current share price.
|
|
46
|
+
*/
|
|
39
47
|
requestedAmount: string;
|
|
48
|
+
/** Assets accepted so far — deposited, or paid out for a withdrawal. */
|
|
40
49
|
acceptedAmount: string;
|
|
50
|
+
/** Assets rejected and returned — deposits only; 0 for a withdrawal. */
|
|
41
51
|
rejectedAmount: string;
|
|
42
52
|
timestamp: EpochTimeStamp;
|
|
43
53
|
status: UserRequestStatus;
|
|
@@ -3,6 +3,8 @@ import { BigNumber, BigNumberish, BytesLike, ContractTransaction, Signer } from
|
|
|
3
3
|
import { IKasuAllowListAbi__factory } from '../../contracts';
|
|
4
4
|
import { SdkConfig } from '../../sdk-config';
|
|
5
5
|
import { PortfolioUserTrancheBalance, UserApyBonus, UserPoolBalance, UserRequest, UserTrancheBalance } from './types';
|
|
6
|
+
/** Thrown when the subgraph reports a request type with no known unit. */
|
|
7
|
+
export declare const UNKNOWN_REQUEST_TYPE_MESSAGE = "UserLending: unknown request type, its amount unit is unknown";
|
|
6
8
|
export declare class UserLending {
|
|
7
9
|
private _kasuConfig;
|
|
8
10
|
private readonly _graph;
|
|
@@ -60,6 +62,18 @@ export declare class UserLending {
|
|
|
60
62
|
getCurrentFtdBalance(poolId: string, userId: string): Promise<Map<string, number[]>>;
|
|
61
63
|
getCurrentEpochFtdAmount(poolIds: string[], userId: string, currentEpoch: string): Promise<Map<string, string[]>>;
|
|
62
64
|
getCurrentEpochDepositedAmount(lendingPoolIds: string[], userId: string): Promise<Map<string, string>>;
|
|
65
|
+
/**
|
|
66
|
+
* A request's outstanding amount in ASSETS (the deployment's stable token).
|
|
67
|
+
*
|
|
68
|
+
* The subgraph's `UserRequest.amountRequested` is denominated by request
|
|
69
|
+
* type. A DEPOSIT request holds assets: the deposit NFT's `assetAmount`,
|
|
70
|
+
* top-ups added, accepted and rejected amounts taken off. A WITHDRAWAL
|
|
71
|
+
* request holds tranche SHARES: the withdrawal NFT's `sharesAmount`,
|
|
72
|
+
* accepted shares taken off. So only a withdrawal is converted, at the
|
|
73
|
+
* tranche's current share price; a deposit passes through unchanged —
|
|
74
|
+
* pricing it as shares overstated it by the share price.
|
|
75
|
+
*/
|
|
76
|
+
private requestedAmountInAssets;
|
|
63
77
|
convertSharesToAssets(sharesAmount: string, totalAssets: string, totalSupply: string): string;
|
|
64
78
|
isClearingPending(poolId: string): Promise<boolean>;
|
|
65
79
|
isCancelable(status: string, lendingPoolId: string): Promise<boolean>;
|
package/package.json
CHANGED
package/src/domain/index.ts
CHANGED
|
@@ -188,8 +188,13 @@ export {
|
|
|
188
188
|
} from './wallet-errors';
|
|
189
189
|
export type { WalletFailure } from './wallet-errors';
|
|
190
190
|
|
|
191
|
-
export { poolTvl } from './pool-tvl';
|
|
192
|
-
export type {
|
|
191
|
+
export { combineTvlHistories, poolTvl, TvlHistoryInputError } from './pool-tvl';
|
|
192
|
+
export type {
|
|
193
|
+
PoolTvlHistoryEntry,
|
|
194
|
+
StrategyTvlHistoryEntry,
|
|
195
|
+
TvlHistoryInputErrorCode,
|
|
196
|
+
TvlHistoryLeg,
|
|
197
|
+
} from './pool-tvl';
|
|
193
198
|
|
|
194
199
|
export { aggregateYieldHistory, epochTrancheYield } from './yield-history';
|
|
195
200
|
export type {
|