@kasufinance/kasu-sdk 2.11.0 → 2.13.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.
Files changed (70) hide show
  1. package/README.md +37 -2
  2. package/dist/bundle.cjs.js +1516 -71
  3. package/dist/bundle.esm.js +1511 -73
  4. package/dist/domain/index.d.ts +6 -2
  5. package/dist/domain/index.js +2 -0
  6. package/dist/domain/index.js.map +1 -1
  7. package/dist/domain/pool-tvl.d.ts +62 -0
  8. package/dist/domain/pool-tvl.js +22 -0
  9. package/dist/domain/pool-tvl.js.map +1 -0
  10. package/dist/domain/yield-history.d.ts +122 -0
  11. package/dist/domain/yield-history.js +95 -0
  12. package/dist/domain/yield-history.js.map +1 -0
  13. package/dist/facade/chain-configs.js +24 -0
  14. package/dist/facade/chain-configs.js.map +1 -1
  15. package/dist/facade/kasu.d.ts +2 -0
  16. package/dist/facade/kasu.js +13 -5
  17. package/dist/facade/kasu.js.map +1 -1
  18. package/dist/facade/strategies.d.ts +20 -0
  19. package/dist/facade/strategies.js +22 -0
  20. package/dist/facade/strategies.js.map +1 -1
  21. package/dist/facade/types.d.ts +20 -0
  22. package/dist/facade/user-portfolio.d.ts +32 -0
  23. package/dist/facade/user-portfolio.js +34 -0
  24. package/dist/facade/user-portfolio.js.map +1 -1
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/kasu-sdk.d.ts +9 -1
  29. package/dist/kasu-sdk.js +2 -2
  30. package/dist/kasu-sdk.js.map +1 -1
  31. package/dist/sdk-config.d.ts +20 -0
  32. package/dist/sdk-config.js +3 -1
  33. package/dist/sdk-config.js.map +1 -1
  34. package/dist/services/DataService/data-service.d.ts +81 -1
  35. package/dist/services/DataService/data-service.js +211 -6
  36. package/dist/services/DataService/data-service.js.map +1 -1
  37. package/dist/services/DataService/tvl-history.d.ts +296 -0
  38. package/dist/services/DataService/tvl-history.js +558 -0
  39. package/dist/services/DataService/tvl-history.js.map +1 -0
  40. package/dist/services/Portfolio/portfolio.d.ts +37 -0
  41. package/dist/services/Portfolio/portfolio.js +136 -56
  42. package/dist/services/Portfolio/portfolio.js.map +1 -1
  43. package/dist/services/Portfolio/queries.js +15 -3
  44. package/dist/services/Portfolio/queries.js.map +1 -1
  45. package/dist/services/Portfolio/types.d.ts +8 -0
  46. package/dist/services/Portfolio/yield-history.d.ts +162 -0
  47. package/dist/services/Portfolio/yield-history.js +378 -0
  48. package/dist/services/Portfolio/yield-history.js.map +1 -0
  49. package/dist/services/shared.d.ts +16 -0
  50. package/dist/services/shared.js +30 -0
  51. package/dist/services/shared.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/domain/index.ts +15 -10
  54. package/src/domain/pool-tvl.ts +66 -0
  55. package/src/domain/yield-history.ts +194 -0
  56. package/src/facade/chain-configs.ts +26 -0
  57. package/src/facade/kasu.ts +20 -2
  58. package/src/facade/strategies.ts +26 -0
  59. package/src/facade/types.ts +20 -0
  60. package/src/facade/user-portfolio.ts +40 -3
  61. package/src/index.ts +11 -0
  62. package/src/kasu-sdk.ts +19 -2
  63. package/src/sdk-config.ts +22 -0
  64. package/src/services/DataService/data-service.ts +296 -6
  65. package/src/services/DataService/tvl-history.ts +853 -0
  66. package/src/services/Portfolio/portfolio.ts +263 -153
  67. package/src/services/Portfolio/queries.ts +15 -3
  68. package/src/services/Portfolio/types.ts +10 -0
  69. package/src/services/Portfolio/yield-history.ts +541 -0
  70. package/src/services/shared.ts +38 -1
@@ -0,0 +1,378 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { gql } from 'graphql-request';
11
+ import { epochTrancheYield, } from '../../domain/yield-history';
12
+ /** The subgraph returns at most this many rows per collection per request. */
13
+ export const YIELD_HISTORY_PAGE_SIZE = 1000;
14
+ /**
15
+ * A runaway guard, not a working limit: a collection this many pages long
16
+ * (`MAX × PAGE_SIZE` rows for one lender) is a broken response, not a history.
17
+ */
18
+ export const YIELD_HISTORY_MAX_PAGES = 100;
19
+ /**
20
+ * Throws `RangeError` on a malformed `fromEpoch` / `count`. `getYieldHistory`
21
+ * calls it BEFORE any network read.
22
+ */
23
+ export function validateYieldHistoryOptions(options) {
24
+ const { fromEpoch, count } = options;
25
+ if (fromEpoch !== undefined &&
26
+ (!Number.isSafeInteger(fromEpoch) || fromEpoch < 0)) {
27
+ throw new RangeError(`getYieldHistory: fromEpoch must be a non-negative integer, got ${String(fromEpoch)}`);
28
+ }
29
+ if (count !== undefined && (!Number.isSafeInteger(count) || count < 1)) {
30
+ throw new RangeError(`getYieldHistory: count must be a positive integer, got ${String(count)}`);
31
+ }
32
+ }
33
+ export function resolveYieldHistoryWindow(options, currentEpoch) {
34
+ validateYieldHistoryOptions(options);
35
+ const { fromEpoch, count } = options;
36
+ const newest = currentEpoch - 1;
37
+ if (newest < 0)
38
+ return null;
39
+ let from;
40
+ let to = newest;
41
+ if (fromEpoch !== undefined) {
42
+ from = fromEpoch;
43
+ if (count !== undefined)
44
+ to = Math.min(newest, fromEpoch + count - 1);
45
+ }
46
+ else {
47
+ from = count !== undefined ? Math.max(0, newest - count + 1) : 0;
48
+ }
49
+ return from > to ? null : { fromEpoch: from, toEpoch: to };
50
+ }
51
+ // ---------------------------------------------------------------------------
52
+ // Subgraph reads
53
+ // ---------------------------------------------------------------------------
54
+ /**
55
+ * Round trip 1: the lender's tranche positions and fixed-term locks. Same
56
+ * pool exclusion and the same nested-list size (`$first`) as
57
+ * `lendingPortfolioQuery`, so both read the same lock set.
58
+ */
59
+ export const yieldHistoryPositionsQuery = gql `
60
+ query YieldHistoryPositions(
61
+ $userAddress: ID!
62
+ $unusedPools: [String!]!
63
+ $first: Int!
64
+ ) {
65
+ user(id: $userAddress) {
66
+ lendingPoolUserDetails(
67
+ first: $first
68
+ where: { lendingPool_not_in: $unusedPools }
69
+ ) {
70
+ lendingPool {
71
+ id
72
+ }
73
+ lendingPoolTrancheUserDetails(first: $first) {
74
+ id
75
+ tranche {
76
+ id
77
+ balance
78
+ shares
79
+ }
80
+ userLendingPoolTrancheFixedTermDepositLocks(first: $first) {
81
+ id
82
+ epochLockStart
83
+ epochLockEnd
84
+ initialTrancheShares
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ `;
91
+ /**
92
+ * Round trip 2 onwards: the four per-epoch series, one page of each per
93
+ * request, cursor-paginated by `id`. A series that is exhausted is skipped with
94
+ * `@include`, so a history costs as many requests as its LONGEST series has
95
+ * pages — normally one — never one per epoch.
96
+ *
97
+ * Share snapshots are read up to the window's end with no lower bound: the
98
+ * value AS OF the first epoch may come from an update long before it.
99
+ */
100
+ export const yieldHistoryPageQuery = gql `
101
+ query YieldHistoryPage(
102
+ $tranches: [String!]!
103
+ $userTranches: [String!]!
104
+ $locks: [String!]!
105
+ $fromEpoch: BigInt!
106
+ $toEpoch: BigInt!
107
+ $interestCursor: ID!
108
+ $trancheSharesCursor: ID!
109
+ $userSharesCursor: ID!
110
+ $lockSharesCursor: ID!
111
+ $withInterest: Boolean!
112
+ $withTrancheShares: Boolean!
113
+ $withUserShares: Boolean!
114
+ $withLockShares: Boolean!
115
+ $first: Int!
116
+ ) {
117
+ interest: lendingPoolTrancheEpochInterests(
118
+ first: $first
119
+ orderBy: id
120
+ orderDirection: asc
121
+ where: {
122
+ id_gt: $interestCursor
123
+ lendingPoolTranche_in: $tranches
124
+ epochId_gte: $fromEpoch
125
+ epochId_lte: $toEpoch
126
+ }
127
+ ) @include(if: $withInterest) {
128
+ id
129
+ epochId
130
+ epochInterestAmount
131
+ lendingPoolTranche {
132
+ id
133
+ }
134
+ }
135
+ trancheShares: lendingPoolTrancheShareUpdates(
136
+ first: $first
137
+ orderBy: id
138
+ orderDirection: asc
139
+ where: {
140
+ id_gt: $trancheSharesCursor
141
+ lendingPoolTranche_in: $tranches
142
+ epochId_lte: $toEpoch
143
+ }
144
+ ) @include(if: $withTrancheShares) {
145
+ id
146
+ epochId
147
+ shareUpdatesIndex
148
+ shares
149
+ lendingPoolTranche {
150
+ id
151
+ }
152
+ }
153
+ userShares: lendingPoolTrancheUserEpochSharesUpdates(
154
+ first: $first
155
+ orderBy: id
156
+ orderDirection: asc
157
+ where: {
158
+ id_gt: $userSharesCursor
159
+ lendingPoolTrancheUserDetails_in: $userTranches
160
+ epochId_lte: $toEpoch
161
+ }
162
+ ) @include(if: $withUserShares) {
163
+ id
164
+ epochId
165
+ shareUpdatesIndex
166
+ shares
167
+ lendingPoolTrancheUserDetails {
168
+ id
169
+ }
170
+ }
171
+ lockShares: userLendingPoolTrancheFtdLockShareUpdates(
172
+ first: $first
173
+ orderBy: id
174
+ orderDirection: asc
175
+ where: {
176
+ id_gt: $lockSharesCursor
177
+ userLendingPoolTrancheFixedTermDepositLock_in: $locks
178
+ epochId_lte: $toEpoch
179
+ }
180
+ ) @include(if: $withLockShares) {
181
+ id
182
+ epochId
183
+ shareUpdatesIndex
184
+ shares
185
+ userLendingPoolTrancheFixedTermDepositLock {
186
+ id
187
+ }
188
+ }
189
+ }
190
+ `;
191
+ /**
192
+ * Fetch the four series for the window, paginating each by `id` until a short
193
+ * page. Returns the rows and how many requests it took.
194
+ */
195
+ export function fetchYieldHistorySeries(request, ids, window) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ var _a;
198
+ const rows = {
199
+ interest: [],
200
+ trancheShares: [],
201
+ userShares: [],
202
+ lockShares: [],
203
+ };
204
+ const series = [
205
+ { key: 'interest', flag: 'withInterest', cursor: 'interestCursor' },
206
+ {
207
+ key: 'trancheShares',
208
+ flag: 'withTrancheShares',
209
+ cursor: 'trancheSharesCursor',
210
+ },
211
+ {
212
+ key: 'userShares',
213
+ flag: 'withUserShares',
214
+ cursor: 'userSharesCursor',
215
+ },
216
+ {
217
+ key: 'lockShares',
218
+ flag: 'withLockShares',
219
+ cursor: 'lockSharesCursor',
220
+ },
221
+ ];
222
+ const cursors = {
223
+ interest: '',
224
+ trancheShares: '',
225
+ userShares: '',
226
+ lockShares: '',
227
+ };
228
+ const open = {
229
+ interest: ids.tranches.length > 0,
230
+ trancheShares: ids.tranches.length > 0,
231
+ userShares: ids.userTranches.length > 0,
232
+ lockShares: ids.locks.length > 0,
233
+ };
234
+ let requests = 0;
235
+ while (series.some(({ key }) => open[key])) {
236
+ if (requests >= YIELD_HISTORY_MAX_PAGES) {
237
+ throw new Error(`getYieldHistory: more than ${String(YIELD_HISTORY_MAX_PAGES)} pages for one lender`);
238
+ }
239
+ const variables = {
240
+ tranches: ids.tranches,
241
+ userTranches: ids.userTranches,
242
+ locks: ids.locks,
243
+ fromEpoch: String(window.fromEpoch),
244
+ toEpoch: String(window.toEpoch),
245
+ first: YIELD_HISTORY_PAGE_SIZE,
246
+ };
247
+ for (const { key, flag, cursor } of series) {
248
+ variables[flag] = open[key];
249
+ variables[cursor] = cursors[key];
250
+ }
251
+ const page = yield request(variables);
252
+ requests += 1;
253
+ for (const { key } of series) {
254
+ if (!open[key])
255
+ continue;
256
+ const got = (_a = page[key]) !== null && _a !== void 0 ? _a : [];
257
+ rows[key].push(...got);
258
+ const last = got.at(-1);
259
+ if (got.length < YIELD_HISTORY_PAGE_SIZE || last === undefined) {
260
+ open[key] = false;
261
+ continue;
262
+ }
263
+ if (last.id <= cursors[key]) {
264
+ throw new Error(`getYieldHistory: the ${key} cursor did not advance`);
265
+ }
266
+ cursors[key] = last.id;
267
+ }
268
+ }
269
+ return { rows, requests };
270
+ });
271
+ }
272
+ /**
273
+ * The snapshot in force at `epoch`: among updates with `epochId ≤ epoch`, the
274
+ * one with the highest `shareUpdatesIndex` — exactly what
275
+ * `lendingPortfolioQuery` selects with `orderBy: shareUpdatesIndex, desc,
276
+ * first: 1, where: { epochId_lt: epoch + 1 }`. `undefined` when none.
277
+ */
278
+ export function sharesAsOf(updates, epoch) {
279
+ let found;
280
+ for (const update of updates) {
281
+ if (Number(update.epochId) > epoch)
282
+ continue;
283
+ if (!found || update.shareUpdatesIndex > found.shareUpdatesIndex) {
284
+ found = update;
285
+ }
286
+ }
287
+ return found;
288
+ }
289
+ function groupBy(rows, key) {
290
+ const map = new Map();
291
+ for (const row of rows) {
292
+ const k = key(row);
293
+ const list = map.get(k);
294
+ if (list)
295
+ list.push(row);
296
+ else
297
+ map.set(k, [row]);
298
+ }
299
+ return map;
300
+ }
301
+ /**
302
+ * Pure: the fetched series → one entry per pool, tranche and settled epoch in
303
+ * which the lender held shares (or a lock earned a top-up). Each entry runs the
304
+ * same `epochTrancheYield` as the portfolio's last-epoch figure, with the same
305
+ * share selection, so the newest entry equals that figure.
306
+ *
307
+ * Sorted by `epochId`, then `poolId`, then `trancheId`.
308
+ */
309
+ export function buildYieldHistory(read, window, clock) {
310
+ var _a, _b, _c, _d, _e, _f;
311
+ const user = read.positions.user;
312
+ if (!user)
313
+ return [];
314
+ const interestByTranche = groupBy(read.interest, (row) => row.lendingPoolTranche.id);
315
+ const trancheSharesByTranche = groupBy(read.trancheShares, (row) => row.lendingPoolTranche.id);
316
+ const userSharesByPosition = groupBy(read.userShares, (row) => row.lendingPoolTrancheUserDetails.id);
317
+ const lockSharesByLock = groupBy(read.lockShares, (row) => row.userLendingPoolTrancheFixedTermDepositLock.id);
318
+ const entries = [];
319
+ for (const pool of user.lendingPoolUserDetails) {
320
+ for (const position of pool.lendingPoolTrancheUserDetails) {
321
+ const trancheId = position.tranche.id;
322
+ const trancheUpdates = (_a = trancheSharesByTranche.get(trancheId)) !== null && _a !== void 0 ? _a : [];
323
+ const userUpdates = (_b = userSharesByPosition.get(position.id)) !== null && _b !== void 0 ? _b : [];
324
+ const trancheBalanceNow = parseFloat(position.tranche.balance);
325
+ const trancheSharesNow = parseFloat(position.tranche.shares);
326
+ for (const record of (_c = interestByTranche.get(trancheId)) !== null && _c !== void 0 ? _c : []) {
327
+ const epoch = Number(record.epochId);
328
+ if (epoch < window.fromEpoch || epoch > window.toEpoch) {
329
+ continue;
330
+ }
331
+ const userSnapshot = sharesAsOf(userUpdates, epoch);
332
+ const userShares = parseFloat((_d = userSnapshot === null || userSnapshot === void 0 ? void 0 : userSnapshot.shares) !== null && _d !== void 0 ? _d : '0');
333
+ const locks = position.userLendingPoolTrancheFixedTermDepositLocks.map((lock) => {
334
+ var _a, _b, _c, _d, _e;
335
+ const lockUpdates = (_a = lockSharesByLock.get(lock.id)) !== null && _a !== void 0 ? _a : [];
336
+ return {
337
+ active: parseFloat(lock.epochLockStart) < epoch &&
338
+ parseFloat(lock.epochLockEnd) >= epoch &&
339
+ userSnapshot !== undefined,
340
+ // No snapshot yet = the lock's opening
341
+ // shares: a lock made after clearing E
342
+ // starts at E but its first update is
343
+ // tagged E + 1, and reading that gap as 0
344
+ // would book its principal as a top-up.
345
+ sharesAtEpoch: parseFloat((_c = (_b = sharesAsOf(lockUpdates, epoch)) === null || _b === void 0 ? void 0 : _b.shares) !== null && _c !== void 0 ? _c : lock.initialTrancheShares),
346
+ sharesBeforeEpoch: parseFloat((_e = (_d = sharesAsOf(lockUpdates, epoch - 1)) === null || _d === void 0 ? void 0 : _d.shares) !== null && _e !== void 0 ? _e : lock.initialTrancheShares),
347
+ };
348
+ });
349
+ const { total } = epochTrancheYield({
350
+ epochInterest: parseFloat(record.epochInterestAmount),
351
+ userShares,
352
+ trancheShares: parseFloat((_f = (_e = sharesAsOf(trancheUpdates, epoch)) === null || _e === void 0 ? void 0 : _e.shares) !== null && _f !== void 0 ? _f : '0'),
353
+ trancheBalanceNow,
354
+ trancheSharesNow,
355
+ locks,
356
+ });
357
+ // Nothing held and nothing topped up: not part of this
358
+ // lender's history (a new lender's history is empty).
359
+ if (userShares <= 0 && total === 0)
360
+ continue;
361
+ entries.push({
362
+ epochId: epoch,
363
+ epochEnd: clock.epochZeroStart +
364
+ (epoch + 1) * clock.epochDuration,
365
+ poolId: pool.lendingPool.id,
366
+ trancheId,
367
+ netYield: total,
368
+ });
369
+ }
370
+ }
371
+ }
372
+ return entries.sort((a, b) => a.epochId - b.epochId ||
373
+ a.poolId.localeCompare(b.poolId) ||
374
+ a.trancheId.localeCompare(b.trancheId));
375
+ }
376
+ // Shared with `getPoolTvlHistory`: one Lite-vs-full rule for every history.
377
+ export { isEmptyHistoryError, isMissingEntityError } from '../shared';
378
+ //# sourceMappingURL=yield-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yield-history.js","sourceRoot":"","sources":["../../../src/services/Portfolio/yield-history.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAEH,iBAAiB,GAEpB,MAAM,4BAA4B,CAAC;AAyBpC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CACvC,OAA4B;IAE5B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IACrC,IACI,SAAS,KAAK,SAAS;QACvB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,EACrD,CAAC;QACC,MAAM,IAAI,UAAU,CAChB,kEAAkE,MAAM,CAAC,SAAS,CAAC,EAAE,CACxF,CAAC;IACN,CAAC;IACD,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QACr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CAAC,CACJ,CAAC;gBAEN,MAAM,EAAE,KAAK,EAAE,GAAG,iBAAiB,CAAC;oBAChC,aAAa,EAAE,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC;oBACrD,UAAU;oBACV,aAAa,EAAE,UAAU,CACrB,MAAA,MAAA,UAAU,CAAC,cAAc,EAAE,KAAK,CAAC,0CAAE,MAAM,mCAAI,GAAG,CACnD;oBACD,iBAAiB;oBACjB,gBAAgB;oBAChB,KAAK;iBACR,CAAC,CAAC;gBAEH,uDAAuD;gBACvD,sDAAsD;gBACtD,IAAI,UAAU,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC;oBAAE,SAAS;gBAE7C,OAAO,CAAC,IAAI,CAAC;oBACT,OAAO,EAAE,KAAK;oBACd,QAAQ,EACJ,KAAK,CAAC,cAAc;wBACpB,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa;oBACrC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE;oBAC3B,SAAS;oBACT,QAAQ,EAAE,KAAK;iBAClB,CAAC,CAAC;YACP,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CACf,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACL,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;QACrB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;QAChC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAC7C,CAAC;AACN,CAAC;AAED,4EAA4E;AAC5E,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +1,17 @@
1
1
  export declare function filterArray<T>(array: T[], id_in?: string[]): T[];
2
+ /**
3
+ * A GraphQL VALIDATION error naming an entity, field or argument this
4
+ * deployment's subgraph does not have. A network error, a timeout or an
5
+ * indexing error is not one.
6
+ */
7
+ export declare function isMissingEntityError(error: unknown): boolean;
8
+ /**
9
+ * The only failure a history read (`getYieldHistory`, `getPoolTvlHistory`)
10
+ * turns into `[]`: a missing-schema error
11
+ * on a LITE deployment, whose subgraph may predate the entities. On a full
12
+ * deployment the entities are part of the schema, so the same error means a
13
+ * broken query or subgraph and THROWS — an empty chart there would hide it.
14
+ * Everything else (network, timeout, indexing) throws on every deployment, so
15
+ * a consumer can tell "no history here" from "history unavailable".
16
+ */
17
+ export declare function isEmptyHistoryError(error: unknown, liteDeployment: boolean): boolean;
@@ -9,4 +9,34 @@ export function filterArray(array, id_in) {
9
9
  });
10
10
  }
11
11
  }
12
+ /**
13
+ * A GraphQL VALIDATION error naming an entity, field or argument this
14
+ * deployment's subgraph does not have. A network error, a timeout or an
15
+ * indexing error is not one.
16
+ */
17
+ export function isMissingEntityError(error) {
18
+ if (typeof error !== 'object' || error === null)
19
+ return false;
20
+ const response = error.response;
21
+ const errors = response === null || response === void 0 ? void 0 : response.errors;
22
+ if (!Array.isArray(errors) || errors.length === 0)
23
+ return false;
24
+ return errors.every((e) => {
25
+ const message = e === null || e === void 0 ? void 0 : e.message;
26
+ return (typeof message === 'string' &&
27
+ /has no field|cannot query field|unknown (type|field|argument)|no such (type|field)/i.test(message));
28
+ });
29
+ }
30
+ /**
31
+ * The only failure a history read (`getYieldHistory`, `getPoolTvlHistory`)
32
+ * turns into `[]`: a missing-schema error
33
+ * on a LITE deployment, whose subgraph may predate the entities. On a full
34
+ * deployment the entities are part of the schema, so the same error means a
35
+ * broken query or subgraph and THROWS — an empty chart there would hide it.
36
+ * Everything else (network, timeout, indexing) throws on every deployment, so
37
+ * a consumer can tell "no history here" from "history unavailable".
38
+ */
39
+ export function isEmptyHistoryError(error, liteDeployment) {
40
+ return liteDeployment && isMissingEntityError(error);
41
+ }
12
42
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/services/shared.ts"],"names":[],"mappings":"AAAA,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AAC,CAAmC,OAAO,CAAC;QAC7D,OAAO,CACH,OAAO,OAAO,KAAK,QAAQ;YAC3B,qFAAqF,CAAC,IAAI,CACtF,OAAO,CACV,CACJ,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAAc,EACd,cAAuB;IAEvB,OAAO,cAAc,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kasufinance/kasu-sdk",
3
- "version": "2.11.0",
3
+ "version": "2.13.0",
4
4
  "description": "TypeScript SDK for the Kasu Finance protocol — pool data, portfolio analytics, and KYC-gated deposits and withdrawals on Base and XDC",
5
5
  "keywords": [
6
6
  "kasu",
@@ -134,11 +134,7 @@ export {
134
134
  lastEventTimestamp,
135
135
  submissionEvents,
136
136
  } from './requests';
137
- export type {
138
- RequestKind,
139
- RequestState,
140
- RequestStatusCode,
141
- } from './requests';
137
+ export type { RequestKind, RequestState, RequestStatusCode } from './requests';
142
138
 
143
139
  export { decodeRevert, extractRevertData } from './revert-errors';
144
140
  export type { DecodedRevert, RevertFamily } from './revert-errors';
@@ -183,11 +179,7 @@ export {
183
179
  trancheHasCapacity,
184
180
  trancheRiskRank,
185
181
  } from './tranches';
186
- export type {
187
- ApyBounds,
188
- PoolStatus,
189
- TrancheCapacitySignal,
190
- } from './tranches';
182
+ export type { ApyBounds, PoolStatus, TrancheCapacitySignal } from './tranches';
191
183
 
192
184
  export {
193
185
  classifyWalletFailure,
@@ -196,6 +188,19 @@ export {
196
188
  } from './wallet-errors';
197
189
  export type { WalletFailure } from './wallet-errors';
198
190
 
191
+ export { poolTvl } from './pool-tvl';
192
+ export type { PoolTvlHistoryEntry } from './pool-tvl';
193
+
194
+ export { aggregateYieldHistory, epochTrancheYield } from './yield-history';
195
+ export type {
196
+ EpochLockShares,
197
+ EpochTrancheYield,
198
+ EpochTrancheYieldInput,
199
+ YieldHistoryEntry,
200
+ YieldHistoryFilter,
201
+ YieldHistoryPoint,
202
+ } from './yield-history';
203
+
199
204
  export {
200
205
  accruedInterest,
201
206
  dailyInterest,
@@ -0,0 +1,66 @@
1
+ /**
2
+ * A pool's TVL — the total lent into it by everyone — and the shape of its
3
+ * history. Pure: the reads live in `services/DataService/tvl-history.ts`.
4
+ */
5
+
6
+ /**
7
+ * The ONE definition of a pool's TVL: what lenders have lent on chain
8
+ * (`lendingPool.balance` in the subgraph) plus the off-chain amount the
9
+ * pool's `ExternalTVL` contract records (`externalTVLOfPool`).
10
+ *
11
+ * Both inputs, and the result, are in DISPLAY units of the deployment's own
12
+ * stable token (USDC on Base and XDC USDC, AUDD on XDC AUDD) — `'1.5'` is
13
+ * one and a half tokens, not 1.5 minor units. Convert before formatting as
14
+ * USD.
15
+ *
16
+ * `getPoolOverview` (its `totalValueLocked.total`) and `getPoolTvlHistory`
17
+ * (every point) both call this, so the chart and the figure above it cannot
18
+ * be computed two ways.
19
+ */
20
+ export function poolTvl(onChainBalance: string, offChainTvl: string): number {
21
+ return parseFloat(onChainBalance) + parseFloat(offChainTvl);
22
+ }
23
+
24
+ /**
25
+ * One point of a pool's TVL history.
26
+ *
27
+ * - `kind: 'clearing'` — the TVL as it stood at the end of the block in which
28
+ * that epoch's clearing finished (`LendingPoolClearing.endBlockNumber`):
29
+ * accepted deposits and withdrawals and the applied interest included.
30
+ * - `kind: 'current'` — the closing "as of now" point, from two sources: the
31
+ * subgraph's latest balance (and its latest block time) and
32
+ * `externalTVLOfPool` at `latest` on the history provider. It equals
33
+ * today's `PoolOverview.totalValueLocked.total` when both that call's reads
34
+ * and these succeed; `getPoolOverview` falls back to an off-chain 0 when its
35
+ * own read fails, and the figure can move between the two calls.
36
+ */
37
+ export interface PoolTvlHistoryEntry {
38
+ /**
39
+ * The epoch (cycle) number, in the chain's numbering
40
+ * (`SystemVariables.currentEpochNumber`).
41
+ *
42
+ * A clearing point carries the epoch that clearing closed. The `current`
43
+ * point carries the CURRENT epoch — which may equal the newest clearing's
44
+ * epoch, because a clearing runs before its epoch rolls over. Epoch
45
+ * numbers can jump (a pool that did not clear for a while, or a
46
+ * deployment whose first clearing is numbered far below the next one), so
47
+ * plot by `timestamp`, never by `epochId`.
48
+ */
49
+ epochId: number;
50
+ /**
51
+ * Unix SECONDS. A clearing point: the time of the block its clearing
52
+ * finished in (`endTimestamp`). The `current` point: the time of the
53
+ * subgraph's latest indexed block. Clearings that finished in the same
54
+ * block (a pool catching up several epochs at once) share a timestamp and
55
+ * a `tvl`.
56
+ */
57
+ timestamp: number;
58
+ /**
59
+ * TVL in DISPLAY units of the deployment's own stable token (USDC on Base
60
+ * and XDC USDC, AUDD on XDC AUDD): `poolTvl(onChain, offChain)` at that
61
+ * block. Convert before formatting as USD.
62
+ */
63
+ tvl: number;
64
+ /** `'clearing'` for a cycle boundary; `'current'` for the closing point. */
65
+ kind: 'clearing' | 'current';
66
+ }