@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.
- package/README.md +37 -2
- package/dist/bundle.cjs.js +1516 -71
- package/dist/bundle.esm.js +1511 -73
- package/dist/domain/index.d.ts +6 -2
- package/dist/domain/index.js +2 -0
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/pool-tvl.d.ts +62 -0
- package/dist/domain/pool-tvl.js +22 -0
- package/dist/domain/pool-tvl.js.map +1 -0
- package/dist/domain/yield-history.d.ts +122 -0
- package/dist/domain/yield-history.js +95 -0
- package/dist/domain/yield-history.js.map +1 -0
- package/dist/facade/chain-configs.js +24 -0
- package/dist/facade/chain-configs.js.map +1 -1
- package/dist/facade/kasu.d.ts +2 -0
- package/dist/facade/kasu.js +13 -5
- package/dist/facade/kasu.js.map +1 -1
- package/dist/facade/strategies.d.ts +20 -0
- package/dist/facade/strategies.js +22 -0
- package/dist/facade/strategies.js.map +1 -1
- package/dist/facade/types.d.ts +20 -0
- package/dist/facade/user-portfolio.d.ts +32 -0
- package/dist/facade/user-portfolio.js +34 -0
- package/dist/facade/user-portfolio.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kasu-sdk.d.ts +9 -1
- package/dist/kasu-sdk.js +2 -2
- package/dist/kasu-sdk.js.map +1 -1
- package/dist/sdk-config.d.ts +20 -0
- package/dist/sdk-config.js +3 -1
- package/dist/sdk-config.js.map +1 -1
- package/dist/services/DataService/data-service.d.ts +81 -1
- package/dist/services/DataService/data-service.js +211 -6
- package/dist/services/DataService/data-service.js.map +1 -1
- package/dist/services/DataService/tvl-history.d.ts +296 -0
- package/dist/services/DataService/tvl-history.js +558 -0
- package/dist/services/DataService/tvl-history.js.map +1 -0
- package/dist/services/Portfolio/portfolio.d.ts +37 -0
- package/dist/services/Portfolio/portfolio.js +136 -56
- package/dist/services/Portfolio/portfolio.js.map +1 -1
- package/dist/services/Portfolio/queries.js +15 -3
- package/dist/services/Portfolio/queries.js.map +1 -1
- package/dist/services/Portfolio/types.d.ts +8 -0
- package/dist/services/Portfolio/yield-history.d.ts +162 -0
- package/dist/services/Portfolio/yield-history.js +378 -0
- package/dist/services/Portfolio/yield-history.js.map +1 -0
- package/dist/services/shared.d.ts +16 -0
- package/dist/services/shared.js +30 -0
- package/dist/services/shared.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/index.ts +15 -10
- package/src/domain/pool-tvl.ts +66 -0
- package/src/domain/yield-history.ts +194 -0
- package/src/facade/chain-configs.ts +26 -0
- package/src/facade/kasu.ts +20 -2
- package/src/facade/strategies.ts +26 -0
- package/src/facade/types.ts +20 -0
- package/src/facade/user-portfolio.ts +40 -3
- package/src/index.ts +11 -0
- package/src/kasu-sdk.ts +19 -2
- package/src/sdk-config.ts +22 -0
- package/src/services/DataService/data-service.ts +296 -6
- package/src/services/DataService/tvl-history.ts +853 -0
- package/src/services/Portfolio/portfolio.ts +263 -153
- package/src/services/Portfolio/queries.ts +15 -3
- package/src/services/Portfolio/types.ts +10 -0
- package/src/services/Portfolio/yield-history.ts +541 -0
- package/src/services/shared.ts +38 -1
|
@@ -0,0 +1,558 @@
|
|
|
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 { BigNumber } from 'ethers';
|
|
11
|
+
import { formatUnits, Interface } from 'ethers/lib/utils';
|
|
12
|
+
import { gql } from 'graphql-request';
|
|
13
|
+
import { KasuPoolExternalTVLAbi__factory } from '../../contracts';
|
|
14
|
+
import { poolTvl } from '../../domain/pool-tvl';
|
|
15
|
+
/** Clearings per subgraph page (the subgraph's own row cap). */
|
|
16
|
+
export const TVL_HISTORY_PAGE_SIZE = 1000;
|
|
17
|
+
/**
|
|
18
|
+
* A runaway guard on the clearings pagination, not a working limit: a pool
|
|
19
|
+
* clears once per epoch, so 20 pages would be twenty thousand cycles.
|
|
20
|
+
*/
|
|
21
|
+
export const TVL_HISTORY_MAX_PAGES = 20;
|
|
22
|
+
/**
|
|
23
|
+
* How many past blocks one time-travel request reads, as GraphQL aliases. A
|
|
24
|
+
* pool with ~120 clearings costs two such requests.
|
|
25
|
+
*/
|
|
26
|
+
export const TVL_HISTORY_BLOCKS_PER_REQUEST = 100;
|
|
27
|
+
/** At most this many past-state RPC reads are in flight at once. */
|
|
28
|
+
export const TVL_HISTORY_RPC_CONCURRENCY = 8;
|
|
29
|
+
/** Attempts per past-state RPC read (each over every history RPC in turn). */
|
|
30
|
+
export const TVL_HISTORY_RPC_ATTEMPTS = 3;
|
|
31
|
+
/** Back-off before the second attempt; doubled for each one after. */
|
|
32
|
+
export const TVL_HISTORY_RPC_RETRY_DELAY_MS = 500;
|
|
33
|
+
/** Per-call timeout of the history providers the SDK builds itself. */
|
|
34
|
+
export const TVL_HISTORY_RPC_TIMEOUT_MS = 10000;
|
|
35
|
+
/** Default `timeoutMs` of a whole `getPoolTvlHistory` call. */
|
|
36
|
+
export const TVL_HISTORY_DEFAULT_TIMEOUT_MS = 30000;
|
|
37
|
+
/**
|
|
38
|
+
* Blocks at least this far below the subgraph's head are treated as final
|
|
39
|
+
* and their reads are cached; nearer ones are read again every time.
|
|
40
|
+
*/
|
|
41
|
+
export const TVL_HISTORY_CACHE_DEPTH = 64;
|
|
42
|
+
/** Entries per SDK instance before the cache starts again from empty. */
|
|
43
|
+
export const TVL_HISTORY_CACHE_LIMIT = 20000;
|
|
44
|
+
/** `getPoolTvlHistory` took longer than its `timeoutMs`. */
|
|
45
|
+
export class PoolTvlHistoryTimeoutError extends Error {
|
|
46
|
+
constructor(timeoutMs) {
|
|
47
|
+
super(`getPoolTvlHistory: timed out after ${String(timeoutMs)} ms`);
|
|
48
|
+
this.timeoutMs = timeoutMs;
|
|
49
|
+
this.name = 'PoolTvlHistoryTimeoutError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** `getPoolTvlHistory` was abandoned through its `signal`. */
|
|
53
|
+
export class PoolTvlHistoryAbortedError extends Error {
|
|
54
|
+
constructor() {
|
|
55
|
+
super('getPoolTvlHistory: aborted');
|
|
56
|
+
this.name = 'PoolTvlHistoryAbortedError';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A history provider answered a past block as if nothing were deployed — no
|
|
61
|
+
* code even for the pool, which cleared in that very block. A pruned node
|
|
62
|
+
* does that; trusting it would draw the off-chain TVL as 0.
|
|
63
|
+
*/
|
|
64
|
+
export class PastStateUnavailableError extends Error {
|
|
65
|
+
constructor(block) {
|
|
66
|
+
super(`getPoolTvlHistory: history provider does not serve past state (no code for the pool at block ${String(block)}, where it cleared)`);
|
|
67
|
+
this.block = block;
|
|
68
|
+
this.name = 'PastStateUnavailableError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Throws `RangeError` / `TypeError` on a malformed option.
|
|
73
|
+
* `getPoolTvlHistory` calls it ONCE, BEFORE any network read;
|
|
74
|
+
* `resolvePoolTvlHistoryWindow` assumes it has run.
|
|
75
|
+
*/
|
|
76
|
+
export function validatePoolTvlHistoryOptions(options) {
|
|
77
|
+
const { fromEpoch, count, timeoutMs, signal } = options;
|
|
78
|
+
if (fromEpoch !== undefined &&
|
|
79
|
+
(!Number.isSafeInteger(fromEpoch) || fromEpoch < 0)) {
|
|
80
|
+
throw new RangeError(`getPoolTvlHistory: fromEpoch must be a non-negative integer, got ${String(fromEpoch)}`);
|
|
81
|
+
}
|
|
82
|
+
if (count !== undefined && (!Number.isSafeInteger(count) || count < 1)) {
|
|
83
|
+
throw new RangeError(`getPoolTvlHistory: count must be a positive integer, got ${String(count)}`);
|
|
84
|
+
}
|
|
85
|
+
if (timeoutMs !== undefined &&
|
|
86
|
+
(typeof timeoutMs !== 'number' ||
|
|
87
|
+
!Number.isFinite(timeoutMs) ||
|
|
88
|
+
timeoutMs <= 0)) {
|
|
89
|
+
throw new RangeError(`getPoolTvlHistory: timeoutMs must be a positive number, got ${String(timeoutMs)}`);
|
|
90
|
+
}
|
|
91
|
+
if (signal !== undefined &&
|
|
92
|
+
(typeof signal !== 'object' ||
|
|
93
|
+
typeof signal.aborted !== 'boolean')) {
|
|
94
|
+
throw new TypeError('getPoolTvlHistory: signal must be an AbortSignal');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** The epoch window. Options must already have passed validation. */
|
|
98
|
+
export function resolvePoolTvlHistoryWindow(options, currentEpoch) {
|
|
99
|
+
const { fromEpoch, count } = options;
|
|
100
|
+
let from;
|
|
101
|
+
let to = currentEpoch;
|
|
102
|
+
if (fromEpoch !== undefined) {
|
|
103
|
+
from = fromEpoch;
|
|
104
|
+
if (count !== undefined) {
|
|
105
|
+
to = Math.min(currentEpoch, fromEpoch + count - 1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
from = count !== undefined ? Math.max(0, currentEpoch - count + 1) : 0;
|
|
110
|
+
}
|
|
111
|
+
return from > to ? null : { fromEpoch: from, toEpoch: to };
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Runs `work` under a deadline and an optional caller signal. Whichever comes
|
|
115
|
+
* first rejects the returned promise with its typed error at once, aborts
|
|
116
|
+
* `cancellation.signal` (cancelling in-flight subgraph requests) and makes
|
|
117
|
+
* every later `throwIfCancelled()` throw, so no new read starts. An RPC call
|
|
118
|
+
* already sent cannot be recalled; its answer is dropped.
|
|
119
|
+
*/
|
|
120
|
+
export function runCancellable(timeoutMs, external, work) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
if (external === null || external === void 0 ? void 0 : external.aborted)
|
|
123
|
+
throw new PoolTvlHistoryAbortedError();
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
let reason;
|
|
126
|
+
let rejectCancelled = () => undefined;
|
|
127
|
+
const cancelled = new Promise((_, reject) => {
|
|
128
|
+
rejectCancelled = reject;
|
|
129
|
+
});
|
|
130
|
+
const cancel = (error) => {
|
|
131
|
+
if (reason)
|
|
132
|
+
return;
|
|
133
|
+
reason = error;
|
|
134
|
+
controller.abort();
|
|
135
|
+
rejectCancelled(error);
|
|
136
|
+
};
|
|
137
|
+
const timer = setTimeout(() => {
|
|
138
|
+
cancel(new PoolTvlHistoryTimeoutError(timeoutMs));
|
|
139
|
+
}, timeoutMs);
|
|
140
|
+
const onAbort = () => {
|
|
141
|
+
cancel(new PoolTvlHistoryAbortedError());
|
|
142
|
+
};
|
|
143
|
+
external === null || external === void 0 ? void 0 : external.addEventListener('abort', onAbort);
|
|
144
|
+
const cancellation = {
|
|
145
|
+
signal: controller.signal,
|
|
146
|
+
throwIfCancelled: () => {
|
|
147
|
+
if (reason)
|
|
148
|
+
throw reason;
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
const running = work(cancellation);
|
|
153
|
+
// The losing side must never surface as an unhandled rejection.
|
|
154
|
+
running.catch(() => undefined);
|
|
155
|
+
return yield Promise.race([running, cancelled]);
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
external === null || external === void 0 ? void 0 : external.removeEventListener('abort', onAbort);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Subgraph reads
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
/** Above any epoch number: "no upper bound" for the clearings query. */
|
|
167
|
+
const NO_EPOCH_BOUND = '1000000000000';
|
|
168
|
+
/**
|
|
169
|
+
* The pool's FINISHED clearings, plus — on the first page only — its balance
|
|
170
|
+
* now and the subgraph's latest block.
|
|
171
|
+
*
|
|
172
|
+
* Two modes over one document: ascending from `$epochGte` (a `fromEpoch`
|
|
173
|
+
* window, or everything), or descending below `$epochLt` (the newest N, for
|
|
174
|
+
* a `count`-only window, so it never pages through the whole history).
|
|
175
|
+
*/
|
|
176
|
+
export const poolTvlClearingsQuery = gql `
|
|
177
|
+
query PoolTvlClearings(
|
|
178
|
+
$poolId: ID!
|
|
179
|
+
$pool: String!
|
|
180
|
+
$epochGte: BigInt!
|
|
181
|
+
$epochLt: BigInt!
|
|
182
|
+
$direction: OrderDirection!
|
|
183
|
+
$first: Int!
|
|
184
|
+
$withSnapshot: Boolean!
|
|
185
|
+
) {
|
|
186
|
+
clearings: lendingPoolClearings(
|
|
187
|
+
first: $first
|
|
188
|
+
orderBy: epochId
|
|
189
|
+
orderDirection: $direction
|
|
190
|
+
where: {
|
|
191
|
+
lendingPool: $pool
|
|
192
|
+
isFinished: true
|
|
193
|
+
epochId_gte: $epochGte
|
|
194
|
+
epochId_lt: $epochLt
|
|
195
|
+
}
|
|
196
|
+
) {
|
|
197
|
+
epochId
|
|
198
|
+
endBlockNumber
|
|
199
|
+
endTimestamp
|
|
200
|
+
}
|
|
201
|
+
pool: lendingPool(id: $poolId) @include(if: $withSnapshot) {
|
|
202
|
+
balance
|
|
203
|
+
}
|
|
204
|
+
meta: _meta @include(if: $withSnapshot) {
|
|
205
|
+
block {
|
|
206
|
+
number
|
|
207
|
+
timestamp
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
`;
|
|
212
|
+
/** The time-travel alias for one block: `b<block>`. */
|
|
213
|
+
export function blockAlias(block) {
|
|
214
|
+
return `b${String(block)}`;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* One time-travel request: the pool's balance at the END of each block, one
|
|
218
|
+
* alias per block. Block numbers are written into the document, so each must
|
|
219
|
+
* be a positive safe integer — anything else throws rather than reaching the
|
|
220
|
+
* query text. The pool id travels as a variable.
|
|
221
|
+
*/
|
|
222
|
+
export function poolBalancesAtBlocksQuery(blocks) {
|
|
223
|
+
const fields = blocks.map((block) => {
|
|
224
|
+
if (!Number.isSafeInteger(block) || block <= 0) {
|
|
225
|
+
throw new Error(`getPoolTvlHistory: refusing block number ${String(block)}`);
|
|
226
|
+
}
|
|
227
|
+
return `${blockAlias(block)}: lendingPool(id: $poolId, block: { number: ${String(block)} }) { balance }`;
|
|
228
|
+
});
|
|
229
|
+
return `query PoolTvlAtBlocks($poolId: ID!) { ${fields.join(' ')} }`;
|
|
230
|
+
}
|
|
231
|
+
function parseClearing(row) {
|
|
232
|
+
const clearing = {
|
|
233
|
+
epochId: Number(row.epochId),
|
|
234
|
+
block: Number(row.endBlockNumber),
|
|
235
|
+
timestamp: Number(row.endTimestamp),
|
|
236
|
+
};
|
|
237
|
+
if (!Number.isSafeInteger(clearing.epochId) ||
|
|
238
|
+
clearing.epochId < 0 ||
|
|
239
|
+
!Number.isSafeInteger(clearing.block) ||
|
|
240
|
+
clearing.block <= 0 ||
|
|
241
|
+
!Number.isSafeInteger(clearing.timestamp) ||
|
|
242
|
+
clearing.timestamp <= 0) {
|
|
243
|
+
throw new Error(`getPoolTvlHistory: malformed clearing row ${JSON.stringify(row)}`);
|
|
244
|
+
}
|
|
245
|
+
return clearing;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The scope's finished clearings, ascending by epoch, and the snapshot from
|
|
249
|
+
* the first page. Normally ONE request.
|
|
250
|
+
*/
|
|
251
|
+
export function fetchPoolClearings(request, poolId, scope, cancellation) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
const clearings = [];
|
|
254
|
+
let snapshot = {};
|
|
255
|
+
let gte = scope.kind === 'from' ? scope.fromEpoch : 0;
|
|
256
|
+
let lt;
|
|
257
|
+
let requests = 0;
|
|
258
|
+
for (;;) {
|
|
259
|
+
cancellation.throwIfCancelled();
|
|
260
|
+
if (requests >= TVL_HISTORY_MAX_PAGES) {
|
|
261
|
+
throw new Error(`getPoolTvlHistory: more than ${String(TVL_HISTORY_MAX_PAGES)} pages of clearings for one pool`);
|
|
262
|
+
}
|
|
263
|
+
const first = requests === 0;
|
|
264
|
+
const remaining = scope.kind === 'newest'
|
|
265
|
+
? scope.count - clearings.length
|
|
266
|
+
: TVL_HISTORY_PAGE_SIZE;
|
|
267
|
+
const pageSize = Math.min(TVL_HISTORY_PAGE_SIZE, remaining);
|
|
268
|
+
const page = yield request(poolTvlClearingsQuery, {
|
|
269
|
+
poolId,
|
|
270
|
+
pool: poolId,
|
|
271
|
+
epochGte: String(gte),
|
|
272
|
+
epochLt: lt === undefined ? NO_EPOCH_BOUND : String(lt),
|
|
273
|
+
direction: scope.kind === 'newest' ? 'desc' : 'asc',
|
|
274
|
+
first: pageSize,
|
|
275
|
+
withSnapshot: first,
|
|
276
|
+
}, cancellation.signal);
|
|
277
|
+
requests += 1;
|
|
278
|
+
if (first)
|
|
279
|
+
snapshot = { pool: page.pool, meta: page.meta };
|
|
280
|
+
const rows = page.clearings.map(parseClearing);
|
|
281
|
+
clearings.push(...rows);
|
|
282
|
+
const last = rows.at(-1);
|
|
283
|
+
if (rows.length < pageSize || last === undefined)
|
|
284
|
+
break;
|
|
285
|
+
if (scope.kind === 'newest') {
|
|
286
|
+
if (clearings.length >= scope.count)
|
|
287
|
+
break;
|
|
288
|
+
if (lt !== undefined && last.epochId >= lt) {
|
|
289
|
+
throw new Error('getPoolTvlHistory: the clearings cursor did not advance');
|
|
290
|
+
}
|
|
291
|
+
lt = last.epochId;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
if (last.epochId < gte) {
|
|
295
|
+
throw new Error('getPoolTvlHistory: the clearings cursor did not advance');
|
|
296
|
+
}
|
|
297
|
+
gte = last.epochId + 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
clearings.sort((a, b) => a.epochId - b.epochId);
|
|
301
|
+
return { clearings, snapshot, requests };
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The pool's balance (display units, the subgraph's decimal string) at the end
|
|
306
|
+
* of each block, `TVL_HISTORY_BLOCKS_PER_REQUEST` blocks per request. A block
|
|
307
|
+
* at which the subgraph has no such pool THROWS: a finished clearing of the
|
|
308
|
+
* pool happened in it, so a missing pool means a broken read, not a zero.
|
|
309
|
+
*/
|
|
310
|
+
export function fetchPoolBalancesAtBlocks(request, poolId, blocks, cancellation) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
const chunks = [];
|
|
313
|
+
for (let i = 0; i < blocks.length; i += TVL_HISTORY_BLOCKS_PER_REQUEST) {
|
|
314
|
+
chunks.push(blocks.slice(i, i + TVL_HISTORY_BLOCKS_PER_REQUEST));
|
|
315
|
+
}
|
|
316
|
+
cancellation.throwIfCancelled();
|
|
317
|
+
const pages = yield Promise.all(chunks.map((chunk) => request(poolBalancesAtBlocksQuery(chunk), { poolId }, cancellation.signal).then((page) => ({ chunk, page }))));
|
|
318
|
+
const balances = new Map();
|
|
319
|
+
for (const { chunk, page } of pages) {
|
|
320
|
+
for (const block of chunk) {
|
|
321
|
+
const state = page[blockAlias(block)];
|
|
322
|
+
if (!state) {
|
|
323
|
+
throw new Error(`getPoolTvlHistory: the subgraph has no state for the pool at block ${String(block)}`);
|
|
324
|
+
}
|
|
325
|
+
balances.set(block, state.balance);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return { balances, requests: chunks.length };
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
const EXTERNAL_TVL_INTERFACE = new Interface(KasuPoolExternalTVLAbi__factory.abi);
|
|
332
|
+
function hasCode(code) {
|
|
333
|
+
if (typeof code !== 'string' || !/^0x[0-9a-fA-F]*$/.test(code)) {
|
|
334
|
+
throw new Error(`getPoolTvlHistory: getCode returned ${String(code)}, not hex`);
|
|
335
|
+
}
|
|
336
|
+
return code !== '0x';
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The real reader: each read goes to the history RPCs IN ORDER until one
|
|
340
|
+
* answers, and the whole chain is retried `attempts` times with back-off.
|
|
341
|
+
* After the last attempt the last error propagates — never a value. Each
|
|
342
|
+
* attempt first checks the cancellation, so a timed-out call stops here.
|
|
343
|
+
*/
|
|
344
|
+
export function createOffChainTvlReader({ externalTvl, pool, rpcs, cancellation, attempts = TVL_HISTORY_RPC_ATTEMPTS, delayMs = TVL_HISTORY_RPC_RETRY_DELAY_MS, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), }) {
|
|
345
|
+
if (rpcs.length === 0) {
|
|
346
|
+
throw new Error('getPoolTvlHistory: no history RPC to read from');
|
|
347
|
+
}
|
|
348
|
+
const data = EXTERNAL_TVL_INTERFACE.encodeFunctionData('externalTVLOfPool', [pool]);
|
|
349
|
+
const read = (op) => __awaiter(this, void 0, void 0, function* () {
|
|
350
|
+
let lastError;
|
|
351
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
352
|
+
for (const rpc of rpcs) {
|
|
353
|
+
cancellation.throwIfCancelled();
|
|
354
|
+
try {
|
|
355
|
+
return yield op(rpc);
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
lastError = error;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (attempt < attempts) {
|
|
362
|
+
yield sleep(delayMs * Math.pow(2, (attempt - 1)));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
cancellation.throwIfCancelled();
|
|
366
|
+
throw lastError;
|
|
367
|
+
});
|
|
368
|
+
return {
|
|
369
|
+
readAt: (block) => read((rpc) => __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
const result = yield rpc.call({ to: externalTvl, data }, block);
|
|
371
|
+
const [value] = EXTERNAL_TVL_INTERFACE.decodeFunctionResult('externalTVLOfPool', result);
|
|
372
|
+
return value;
|
|
373
|
+
})),
|
|
374
|
+
hasCodeAt: (block) => read((rpc) => __awaiter(this, void 0, void 0, function* () { return hasCode(yield rpc.getCode(externalTvl, block)); })),
|
|
375
|
+
poolHasCodeAt: (block) => read((rpc) => __awaiter(this, void 0, void 0, function* () { return hasCode(yield rpc.getCode(pool, block)); })),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Index of the first block (of `blocks`, ascending) at which the contract has
|
|
380
|
+
* code; `blocks.length` when it has code at none. A deployed contract keeps
|
|
381
|
+
* its code (it is a proxy, never self-destructed), so the answer is a single
|
|
382
|
+
* boundary and a binary search finds it: ONE `getCode` when the contract
|
|
383
|
+
* already existed at the oldest clearing, about log2(n) otherwise.
|
|
384
|
+
*/
|
|
385
|
+
export function firstBlockWithCode(blocks, hasCodeAt) {
|
|
386
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
if (blocks.length === 0)
|
|
388
|
+
return 0;
|
|
389
|
+
if (yield hasCodeAt(blocks[0]))
|
|
390
|
+
return 0;
|
|
391
|
+
const last = blocks.length - 1;
|
|
392
|
+
if (!(yield hasCodeAt(blocks[last])))
|
|
393
|
+
return blocks.length;
|
|
394
|
+
let lo = 0; // no code
|
|
395
|
+
let hi = last; // code
|
|
396
|
+
while (hi - lo > 1) {
|
|
397
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
398
|
+
if (yield hasCodeAt(blocks[mid]))
|
|
399
|
+
hi = mid;
|
|
400
|
+
else
|
|
401
|
+
lo = mid;
|
|
402
|
+
}
|
|
403
|
+
return hi;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* `fn` over `items`, at most `limit` in flight; rejects on the first failure
|
|
408
|
+
* and starts nothing after it (or after `beforeEach` throws).
|
|
409
|
+
*/
|
|
410
|
+
export function mapWithConcurrency(items_1, limit_1, fn_1) {
|
|
411
|
+
return __awaiter(this, arguments, void 0, function* (items, limit, fn, beforeEach = () => undefined) {
|
|
412
|
+
const results = new Array(items.length);
|
|
413
|
+
let next = 0;
|
|
414
|
+
let failed = false;
|
|
415
|
+
const worker = () => __awaiter(this, void 0, void 0, function* () {
|
|
416
|
+
while (!failed && next < items.length) {
|
|
417
|
+
const index = next++;
|
|
418
|
+
try {
|
|
419
|
+
beforeEach();
|
|
420
|
+
results[index] = yield fn(items[index]);
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
failed = true;
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
yield Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
429
|
+
return results;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Immutable past-block reads, per SDK instance. Keys carry the contract (or
|
|
434
|
+
* subgraph), the pool and the block, so two deployments never collide.
|
|
435
|
+
*/
|
|
436
|
+
export class PastBlockCache {
|
|
437
|
+
constructor() {
|
|
438
|
+
this._entries = new Map();
|
|
439
|
+
}
|
|
440
|
+
get(key) {
|
|
441
|
+
return this._entries.get(key);
|
|
442
|
+
}
|
|
443
|
+
set(key, value) {
|
|
444
|
+
if (this._entries.size >= TVL_HISTORY_CACHE_LIMIT) {
|
|
445
|
+
this._entries.clear();
|
|
446
|
+
}
|
|
447
|
+
this._entries.set(key, value);
|
|
448
|
+
}
|
|
449
|
+
get size() {
|
|
450
|
+
return this._entries.size;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* The off-chain TVL (BASE units) at each block, and — with `withLatest` — at
|
|
455
|
+
* the latest block, all inside ONE bounded pool of reads.
|
|
456
|
+
*
|
|
457
|
+
* Before the contract existed there was nothing to record, so those blocks
|
|
458
|
+
* are 0 — decided by `getCode`, never by catching a revert: an RPC that
|
|
459
|
+
* refuses past state can surface that refusal as a "call exception". And a
|
|
460
|
+
* "no code" answer is believed only if the same provider DOES show code for
|
|
461
|
+
* the pool at the oldest and newest such block (it cleared there); otherwise
|
|
462
|
+
* `PastStateUnavailableError`. Every other failed read throws.
|
|
463
|
+
*
|
|
464
|
+
* `cached` blocks (final, below the head) are answered from `cache` and
|
|
465
|
+
* stored there after a successful read.
|
|
466
|
+
*/
|
|
467
|
+
export function fetchOffChainTvlAtBlocks(reader_1, blocks_1, _a) {
|
|
468
|
+
return __awaiter(this, arguments, void 0, function* (reader, blocks, { withLatest = false, cancellation, cache, cacheKey, cacheable = () => false, }) {
|
|
469
|
+
let rpcReads = 0;
|
|
470
|
+
const cached = (kind, block, load) => {
|
|
471
|
+
const key = cache && cacheKey && cacheable(block)
|
|
472
|
+
? cacheKey(kind, block)
|
|
473
|
+
: undefined;
|
|
474
|
+
const hit = key === undefined ? undefined : cache === null || cache === void 0 ? void 0 : cache.get(key);
|
|
475
|
+
if (hit !== undefined)
|
|
476
|
+
return Promise.resolve(hit);
|
|
477
|
+
cancellation.throwIfCancelled();
|
|
478
|
+
rpcReads += 1;
|
|
479
|
+
return load().then((value) => {
|
|
480
|
+
if (key !== undefined)
|
|
481
|
+
cache === null || cache === void 0 ? void 0 : cache.set(key, value);
|
|
482
|
+
return value;
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
const deployedFrom = yield firstBlockWithCode(blocks, (block) => cached('code', block, () => reader.hasCodeAt(block)));
|
|
486
|
+
if (deployedFrom > 0) {
|
|
487
|
+
for (const block of new Set([blocks[0], blocks[deployedFrom - 1]])) {
|
|
488
|
+
const poolDeployed = yield cached('pool', block, () => reader.poolHasCodeAt(block));
|
|
489
|
+
if (!poolDeployed)
|
|
490
|
+
throw new PastStateUnavailableError(block);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const offChain = new Map();
|
|
494
|
+
for (const block of blocks.slice(0, deployedFrom)) {
|
|
495
|
+
offChain.set(block, BigNumber.from(0));
|
|
496
|
+
}
|
|
497
|
+
const targets = [...blocks.slice(deployedFrom)];
|
|
498
|
+
if (withLatest)
|
|
499
|
+
targets.push('latest');
|
|
500
|
+
const values = yield mapWithConcurrency(targets, TVL_HISTORY_RPC_CONCURRENCY, (block) => {
|
|
501
|
+
if (block !== 'latest') {
|
|
502
|
+
return cached('tvl', block, () => reader.readAt(block));
|
|
503
|
+
}
|
|
504
|
+
// Never cached: "latest" moves.
|
|
505
|
+
rpcReads += 1;
|
|
506
|
+
return reader.readAt('latest');
|
|
507
|
+
}, () => {
|
|
508
|
+
cancellation.throwIfCancelled();
|
|
509
|
+
});
|
|
510
|
+
let latest = null;
|
|
511
|
+
targets.forEach((block, i) => {
|
|
512
|
+
if (block === 'latest')
|
|
513
|
+
latest = values[i];
|
|
514
|
+
else
|
|
515
|
+
offChain.set(block, values[i]);
|
|
516
|
+
});
|
|
517
|
+
return { offChain, latest, rpcReads };
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Pure: the reads → the history. One `clearing` point per clearing, ordered by
|
|
522
|
+
* the block it finished in (then by epoch, for clearings that shared a block),
|
|
523
|
+
* so the series is ascending in TIME even where epoch numbers jump; then the
|
|
524
|
+
* `current` point. Each point is `poolTvl(onChain, offChain)` — the same
|
|
525
|
+
* function `getPoolOverview` uses for `totalValueLocked.total`.
|
|
526
|
+
*/
|
|
527
|
+
export function buildPoolTvlHistory(read) {
|
|
528
|
+
const offChainDisplay = (value) => formatUnits(value, read.decimals);
|
|
529
|
+
const entries = [...read.clearings]
|
|
530
|
+
.sort((a, b) => a.block - b.block || a.epochId - b.epochId)
|
|
531
|
+
.map((clearing) => {
|
|
532
|
+
const balance = read.balances.get(clearing.block);
|
|
533
|
+
const offChain = read.offChain.get(clearing.block);
|
|
534
|
+
if (balance === undefined || offChain === undefined) {
|
|
535
|
+
throw new Error(`getPoolTvlHistory: no reading at block ${String(clearing.block)}`);
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
epochId: clearing.epochId,
|
|
539
|
+
timestamp: clearing.timestamp,
|
|
540
|
+
tvl: poolTvl(balance, offChainDisplay(offChain)),
|
|
541
|
+
kind: 'clearing',
|
|
542
|
+
};
|
|
543
|
+
});
|
|
544
|
+
if (read.current) {
|
|
545
|
+
entries.push({
|
|
546
|
+
epochId: read.current.epochId,
|
|
547
|
+
timestamp: read.current.timestamp,
|
|
548
|
+
tvl: poolTvl(read.current.balance, offChainDisplay(read.current.offChain)),
|
|
549
|
+
kind: 'current',
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return entries;
|
|
553
|
+
}
|
|
554
|
+
/** Ascending, de-duplicated clearing blocks: each past block is read ONCE. */
|
|
555
|
+
export function distinctBlocks(clearings) {
|
|
556
|
+
return [...new Set(clearings.map((c) => c.block))].sort((a, b) => a - b);
|
|
557
|
+
}
|
|
558
|
+
//# sourceMappingURL=tvl-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tvl-history.js","sourceRoot":"","sources":["../../../src/services/DataService/tvl-history.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAuB,MAAM,uBAAuB,CAAC;AAwCrE,gEAAgE;AAChE,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAElD,oEAAoE;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAA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AAU,cAAc,CAAC,SAA8B;IACzD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Provider } from '@ethersproject/providers';
|
|
2
2
|
import { BigNumber, Signer } from 'ethers';
|
|
3
|
+
import { YieldHistoryEntry } from '../../domain/yield-history';
|
|
3
4
|
import { SdkConfig } from '../../sdk-config';
|
|
4
5
|
import { TrancheConfigurationSubgraphResult, TrancheSubgraphResult } from '../DataService/subgraph-types';
|
|
5
6
|
import { PoolOverview } from '../DataService/types';
|
|
6
7
|
import { LockingSummarySubgraphResult, SystemVariables } from '../Locking/types';
|
|
7
8
|
import { PortfolioLendingPool, PortfolioRewards, PortfolioSummary, UserLendingPoolTrancheFixedTermDepositLock } from './types';
|
|
9
|
+
import { YieldHistoryOptions } from './yield-history';
|
|
8
10
|
export declare class Portfolio {
|
|
9
11
|
private _kasuConfig;
|
|
10
12
|
private _lockingService;
|
|
@@ -56,6 +58,41 @@ export declare class Portfolio {
|
|
|
56
58
|
getUserNfts(userAddress: string): Promise<number[]>;
|
|
57
59
|
getPortfolioSummary(userAddress: string, portfolioLendingPools: PortfolioLendingPool[], currentEpoch: string): Promise<PortfolioSummary>;
|
|
58
60
|
getPortfolioLendingData(userAddress: string, poolOverviews: PoolOverview[], currentEpoch: string, provider?: Provider): Promise<PortfolioLendingPool[]>;
|
|
61
|
+
/**
|
|
62
|
+
* The lender's settled yield per cycle (epoch), per pool and tranche —
|
|
63
|
+
* what the chain credited at each close, NET of the performance fee
|
|
64
|
+
* (`domain/yield-history.ts`), in the deployment's own stable token. Each
|
|
65
|
+
* entry runs the same `epochTrancheYield` as `getPortfolioLendingData`'s
|
|
66
|
+
* last-epoch figures: a tranche's `yieldEarnings.lastEpoch` plus its
|
|
67
|
+
* locks' equals its entry for the epoch of the tranche's most recently
|
|
68
|
+
* APPLIED interest (older than the last cycle for a pool that has not
|
|
69
|
+
* cleared since; no entry, and a figure of 0, when the lender held
|
|
70
|
+
* nothing at that epoch).
|
|
71
|
+
*
|
|
72
|
+
* Sum entries with `aggregateYieldHistory` (all strategies, or one with
|
|
73
|
+
* `{ poolId }`). Only epochs in which the lender held shares appear — a
|
|
74
|
+
* new lender gets `[]`. Pools in `UNUSED_LENDING_POOL_IDS` are left out,
|
|
75
|
+
* as in `lendingPortfolioQuery`; Directus enablement is NOT applied.
|
|
76
|
+
*
|
|
77
|
+
* Cost: three parallel `SystemVariables` reads and the positions query in
|
|
78
|
+
* one round, then one subgraph request per page of the longest series
|
|
79
|
+
* (1000 rows a page) — normally two subgraph round trips in all, never one
|
|
80
|
+
* per epoch.
|
|
81
|
+
*
|
|
82
|
+
* On a LITE deployment, a subgraph that lacks the entities (a validation
|
|
83
|
+
* error naming them) yields `[]`; on a full deployment that error throws,
|
|
84
|
+
* like every other failure (`isEmptyHistoryError`).
|
|
85
|
+
*
|
|
86
|
+
* @throws RangeError on a malformed `fromEpoch` / `count`, before any
|
|
87
|
+
* network read.
|
|
88
|
+
*/
|
|
89
|
+
getYieldHistory(userAddress: string, options?: YieldHistoryOptions): Promise<YieldHistoryEntry[]>;
|
|
90
|
+
/**
|
|
91
|
+
* A money figure as a plain decimal string. Below a millionth of a token
|
|
92
|
+
* (the stable asset's own precision) is float noise, never money, so it
|
|
93
|
+
* is `'0'` — not `'1e-7'`, which `parseUnits` rejects, nor `'-3e-12'`. A
|
|
94
|
+
* small negative remainder (above −0.0001) is `'0'` as well.
|
|
95
|
+
*/
|
|
59
96
|
precisionToString(val: number): string;
|
|
60
97
|
calculateFixedTermDepositEarnings(fixedTermDepositLock: UserLendingPoolTrancheFixedTermDepositLock, totalTrancheBalance: string, totalTrancheShares: string): number;
|
|
61
98
|
}
|