@gearbox-protocol/sdk 15.1.0-next.7 → 15.1.0-next.8
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/dist/cjs/model/charts.js +147 -0
- package/dist/cjs/model/charts.schema.js +240 -0
- package/dist/cjs/model/index.js +27 -22
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/opportunities.schema.js +1 -1
- package/dist/cjs/model/positions.schema.js +2 -2
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +2 -6
- package/dist/cjs/new-sdk/utils/index.js +0 -1
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/cjs/offchain/positions/OffchainPositions.js +8 -11
- package/dist/esm/model/charts.js +140 -0
- package/dist/esm/model/charts.schema.js +226 -0
- package/dist/esm/model/index.js +7 -7
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/opportunities.schema.js +1 -1
- package/dist/esm/model/positions.schema.js +2 -2
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +2 -6
- package/dist/esm/new-sdk/utils/index.js +0 -1
- package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/esm/offchain/positions/OffchainPositions.js +8 -11
- package/dist/types/model/charts.d.ts +349 -0
- package/dist/types/model/charts.schema.d.ts +364 -0
- package/dist/types/model/index.d.ts +5 -5
- package/dist/types/model/positions.d.ts +1 -1
- package/dist/types/new-sdk/index.d.ts +1 -2
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +4 -5
- package/dist/types/new-sdk/opportunities/types.d.ts +9 -7
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
- package/dist/types/new-sdk/positions/types.d.ts +9 -9
- package/dist/types/new-sdk/utils/index.d.ts +1 -2
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
- package/dist/types/offchain/index.d.ts +2 -2
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
- package/dist/types/offchain/positions/OffchainPositions.d.ts +11 -5
- package/package.json +1 -1
- package/dist/cjs/model/history.js +0 -53
- package/dist/cjs/model/history.schema.js +0 -128
- package/dist/cjs/new-sdk/utils/history.js +0 -1
- package/dist/esm/model/history.js +0 -49
- package/dist/esm/model/history.schema.js +0 -116
- package/dist/esm/new-sdk/utils/history.js +0 -1
- package/dist/types/model/history.d.ts +0 -153
- package/dist/types/model/history.schema.d.ts +0 -95
- package/dist/types/new-sdk/utils/history.d.ts +0 -18
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { Timestamp, Token } from "./primitives.js";
|
|
2
|
+
//#region src/model/charts.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Historical charts of an opportunity or a position.
|
|
5
|
+
*
|
|
6
|
+
* Charts are backend-only by construction: the chain serves the present, and
|
|
7
|
+
* reconstructing a series from it would mean archive-node reads per point.
|
|
8
|
+
*
|
|
9
|
+
* A chart is read as a {@link ChartBundle}: one shared x-axis plus one
|
|
10
|
+
* {@link ChartSeries} per metric, each holding values only. Alignment is
|
|
11
|
+
* therefore structural — series `i` and series `j` describe the same instant at
|
|
12
|
+
* the same index — rather than a property the backend promises and every
|
|
13
|
+
* consumer re-checks.
|
|
14
|
+
**/
|
|
15
|
+
/**
|
|
16
|
+
* Time window a chart covers, ending at the present.
|
|
17
|
+
*
|
|
18
|
+
* `"max"` is the full history the backend retains for the subject.
|
|
19
|
+
**/
|
|
20
|
+
declare const CHART_RANGES: readonly ["1d", "1w", "1m", "1y", "max"];
|
|
21
|
+
type ChartRange = (typeof CHART_RANGES)[number];
|
|
22
|
+
/**
|
|
23
|
+
* Every metric a pool opportunity can chart.
|
|
24
|
+
**/
|
|
25
|
+
declare const POOL_OPPORTUNITY_CHART_METRICS: readonly ["depositApy", "borrowApy", "dieselRate", "supplied", "borrowed", "availableLiquidity"];
|
|
26
|
+
/**
|
|
27
|
+
* Metric a pool opportunity can chart. Derived from the runtime list that also
|
|
28
|
+
* builds the backend's route enum, so the two cannot drift.
|
|
29
|
+
**/
|
|
30
|
+
type PoolOpportunityChartMetric = (typeof POOL_OPPORTUNITY_CHART_METRICS)[number];
|
|
31
|
+
/**
|
|
32
|
+
* Every metric a strategy opportunity can chart.
|
|
33
|
+
*
|
|
34
|
+
* `collateralPrice` is the collateral/underlying series a liquidation-price
|
|
35
|
+
* chart draws; the two USD series are the same prices quoted in dollars.
|
|
36
|
+
**/
|
|
37
|
+
declare const STRATEGY_OPPORTUNITY_CHART_METRICS: readonly ["netApy", "borrowApy", "collateralApy", "tvl", "collateralPrice", "collateralUsdPrice", "underlyingUsdPrice"];
|
|
38
|
+
/**
|
|
39
|
+
* Metric a strategy opportunity can chart, derived from
|
|
40
|
+
* {@link STRATEGY_OPPORTUNITY_CHART_METRICS}.
|
|
41
|
+
**/
|
|
42
|
+
type StrategyOpportunityChartMetric = (typeof STRATEGY_OPPORTUNITY_CHART_METRICS)[number];
|
|
43
|
+
/**
|
|
44
|
+
* Every metric a pool position can chart.
|
|
45
|
+
*
|
|
46
|
+
* Nothing to do with {@link POOL_OPPORTUNITY_CHART_METRICS}: an opportunity charts what the
|
|
47
|
+
* pool did, a position charts what one wallet's deposit did in it. `mwr` and
|
|
48
|
+
* `twr` are cumulative returns since the position opened — money-weighted, so
|
|
49
|
+
* sensitive to when deposits and withdrawals landed, and time-weighted, which
|
|
50
|
+
* strips that timing out. Both are anchored at inception, so a narrow `range`
|
|
51
|
+
* only zooms the visible slice and its first point is rarely zero.
|
|
52
|
+
**/
|
|
53
|
+
declare const POOL_POSITION_CHART_METRICS: readonly ["value", "apy", "pnl", "mwr", "twr", "underlyingPrice"];
|
|
54
|
+
/**
|
|
55
|
+
* Metric a pool position can chart, derived from
|
|
56
|
+
* {@link POOL_POSITION_CHART_METRICS}.
|
|
57
|
+
**/
|
|
58
|
+
type PoolPositionChartMetric = (typeof POOL_POSITION_CHART_METRICS)[number];
|
|
59
|
+
/**
|
|
60
|
+
* Every metric a strategy position can chart.
|
|
61
|
+
*
|
|
62
|
+
* `twrApy` annualizes `twr` over the position's whole life; the two trailing
|
|
63
|
+
* APYs annualize it over a fixed window instead, so they track the current pace
|
|
64
|
+
* rather than the lifetime rate and are comparable across positions of
|
|
65
|
+
* different ages.
|
|
66
|
+
**/
|
|
67
|
+
declare const STRATEGY_POSITION_CHART_METRICS: readonly ["totalValueUsd", "totalValueUnderlying", "debt", "healthFactor", "leverage", "borrowApy", "underlyingPrice", "pnl", "mwr", "twr", "twrApy", "trailingApy7d", "trailingApy30d"];
|
|
68
|
+
/**
|
|
69
|
+
* Metric a strategy position can chart, derived from
|
|
70
|
+
* {@link STRATEGY_POSITION_CHART_METRICS}.
|
|
71
|
+
*
|
|
72
|
+
* The backend also serves a `collateralPrice` series for a strategy position,
|
|
73
|
+
* which this model cannot name yet: a position holds several collaterals, so
|
|
74
|
+
* that read answers with one series per token, while a {@link ChartBundle}
|
|
75
|
+
* carries one series per metric. Charting it needs either a key that names the
|
|
76
|
+
* token or a token argument on the read.
|
|
77
|
+
**/
|
|
78
|
+
type StrategyPositionChartMetric = (typeof STRATEGY_POSITION_CHART_METRICS)[number];
|
|
79
|
+
/**
|
|
80
|
+
* Any metric an opportunity can chart.
|
|
81
|
+
**/
|
|
82
|
+
type OpportunityChartMetric = PoolOpportunityChartMetric | StrategyOpportunityChartMetric;
|
|
83
|
+
/**
|
|
84
|
+
* Any metric a position can chart.
|
|
85
|
+
**/
|
|
86
|
+
type PositionChartMetric = PoolPositionChartMetric | StrategyPositionChartMetric;
|
|
87
|
+
/**
|
|
88
|
+
* Any metric the read model can chart.
|
|
89
|
+
*
|
|
90
|
+
* The two sides overlap only where they mean the same thing — `borrowApy` is
|
|
91
|
+
* the same rate whether an opportunity or a position charts it — so one metric
|
|
92
|
+
* has one unit in {@link CHART_METRIC_UNITS} no matter who asks for it.
|
|
93
|
+
**/
|
|
94
|
+
type ChartMetric = OpportunityChartMetric | PositionChartMetric;
|
|
95
|
+
/**
|
|
96
|
+
* What one chart read asks for, beyond the subject its route names.
|
|
97
|
+
*
|
|
98
|
+
* The request side of a chart, mirroring how a list read carries its
|
|
99
|
+
* `OpportunityFilter`: the SDK encodes it into the query string and the backend
|
|
100
|
+
* decodes the same codec, so neither side has to restate how a metric list
|
|
101
|
+
* travels in a URL.
|
|
102
|
+
**/
|
|
103
|
+
interface ChartQuery {
|
|
104
|
+
/**
|
|
105
|
+
* Metrics to chart, at least one and each named once. They become the keys of
|
|
106
|
+
* {@link ChartBundle.series}.
|
|
107
|
+
**/
|
|
108
|
+
metrics: readonly ChartMetric[];
|
|
109
|
+
/**
|
|
110
|
+
* Window to cover, echoed back in {@link ChartWindow.range}.
|
|
111
|
+
**/
|
|
112
|
+
range: ChartRange;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Scale a chart's values are on.
|
|
116
|
+
*
|
|
117
|
+
* There is no `percent`: every percentage-like value of the read model is
|
|
118
|
+
* `Bps`, and a chart that quoted `5.2` where its own row quotes `520` would be
|
|
119
|
+
* plotted 100x off. Health factor is `bps` for the same reason — the model
|
|
120
|
+
* already carries it that way, `10000` being the liquidation boundary.
|
|
121
|
+
**/
|
|
122
|
+
type ChartUnit =
|
|
123
|
+
/**
|
|
124
|
+
* Integer basis points, `10000` = 100%.
|
|
125
|
+
**/
|
|
126
|
+
"bps" |
|
|
127
|
+
/**
|
|
128
|
+
* US dollars, a plain float.
|
|
129
|
+
**/
|
|
130
|
+
"usd" |
|
|
131
|
+
/**
|
|
132
|
+
* Whole tokens of the denomination's `base`, a plain float.
|
|
133
|
+
*
|
|
134
|
+
* Deliberately not an `Amount`: base units as `bigint` carry precision a
|
|
135
|
+
* chart cannot draw. A chart value is therefore *not* interchangeable with an
|
|
136
|
+
* `Amount.value`.
|
|
137
|
+
**/
|
|
138
|
+
"token" |
|
|
139
|
+
/**
|
|
140
|
+
* How many of the denomination's `quote` one whole `base` is worth, a plain
|
|
141
|
+
* float.
|
|
142
|
+
**/
|
|
143
|
+
"ratio" |
|
|
144
|
+
/**
|
|
145
|
+
* A plain number on no scale at all, plotted as it arrives: `5.5` is 5.5,
|
|
146
|
+
* which a leverage chart renders as `5.5x`.
|
|
147
|
+
*
|
|
148
|
+
* Only leverage is one. The model carries it as `Leverage`, explicitly
|
|
149
|
+
* neither a percentage nor basis points. Health factor is not — it is `bps`,
|
|
150
|
+
* `10000` being the liquidation boundary, which is how the position row
|
|
151
|
+
* quotes it, and naming this unit after a "factor" or a "multiplier" would
|
|
152
|
+
* read as though it were.
|
|
153
|
+
**/
|
|
154
|
+
"scalar";
|
|
155
|
+
/**
|
|
156
|
+
* Unit of every metric, the one place either side decides it.
|
|
157
|
+
*
|
|
158
|
+
* A metric added to a union above fails to compile here until its unit is
|
|
159
|
+
* named, and the wire schema rejects a series whose `unit` disagrees with this
|
|
160
|
+
* table, so the backend cannot drift from it silently.
|
|
161
|
+
**/
|
|
162
|
+
declare const CHART_METRIC_UNITS: {
|
|
163
|
+
readonly depositApy: "bps";
|
|
164
|
+
readonly borrowApy: "bps";
|
|
165
|
+
readonly netApy: "bps";
|
|
166
|
+
readonly collateralApy: "bps";
|
|
167
|
+
readonly supplied: "token";
|
|
168
|
+
readonly borrowed: "token";
|
|
169
|
+
readonly availableLiquidity: "token";
|
|
170
|
+
readonly tvl: "token";
|
|
171
|
+
readonly dieselRate: "ratio";
|
|
172
|
+
readonly collateralPrice: "ratio";
|
|
173
|
+
readonly collateralUsdPrice: "usd";
|
|
174
|
+
readonly underlyingUsdPrice: "usd";
|
|
175
|
+
readonly value: "token";
|
|
176
|
+
readonly apy: "bps";
|
|
177
|
+
readonly pnl: "token";
|
|
178
|
+
readonly mwr: "bps";
|
|
179
|
+
readonly twr: "bps";
|
|
180
|
+
readonly underlyingPrice: "usd";
|
|
181
|
+
readonly totalValueUsd: "usd";
|
|
182
|
+
readonly totalValueUnderlying: "token";
|
|
183
|
+
readonly debt: "token";
|
|
184
|
+
readonly healthFactor: "bps";
|
|
185
|
+
readonly leverage: "scalar";
|
|
186
|
+
readonly twrApy: "bps";
|
|
187
|
+
readonly trailingApy7d: "bps";
|
|
188
|
+
readonly trailingApy30d: "bps";
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* A unit together with what it is denominated in.
|
|
192
|
+
*
|
|
193
|
+
* Modelled as a union rather than an optional `denomination` field so that a
|
|
194
|
+
* `token` series without its token, or a `bps` series carrying one, does not
|
|
195
|
+
* typecheck. It is not narrowed by the metric: resolving it through `M` would
|
|
196
|
+
* make {@link ChartBundle} invariant in `M`, and a bundle of two metrics would
|
|
197
|
+
* stop being assignable to a `ChartBundle` parameter. That the two agree is
|
|
198
|
+
* enforced on every read instead, against {@link CHART_METRIC_UNITS}.
|
|
199
|
+
**/
|
|
200
|
+
type ChartDenomination = {
|
|
201
|
+
unit: "bps";
|
|
202
|
+
} | {
|
|
203
|
+
unit: "usd";
|
|
204
|
+
} | {
|
|
205
|
+
unit: "scalar";
|
|
206
|
+
} | {
|
|
207
|
+
unit: "token";
|
|
208
|
+
/**
|
|
209
|
+
* Token the values count whole units of.
|
|
210
|
+
**/
|
|
211
|
+
base: Token;
|
|
212
|
+
} | {
|
|
213
|
+
unit: "ratio";
|
|
214
|
+
/**
|
|
215
|
+
* Token one unit of which the value prices.
|
|
216
|
+
*
|
|
217
|
+
* @example wstETH, for a `collateralPrice` of wstETH in USDC
|
|
218
|
+
**/
|
|
219
|
+
base: Token;
|
|
220
|
+
/**
|
|
221
|
+
* Token the value is expressed in: `value` of these per one `base`.
|
|
222
|
+
*
|
|
223
|
+
* @example USDC, for a `collateralPrice` of wstETH in USDC
|
|
224
|
+
**/
|
|
225
|
+
quote: Token;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* One sampled value, or `null` where the series has no observation.
|
|
229
|
+
*
|
|
230
|
+
* `null` is a gap and breaks the line — it is never a zero. A rate that simply
|
|
231
|
+
* did not change is carried forward instead, see {@link GridSampling}.
|
|
232
|
+
**/
|
|
233
|
+
type ChartValue = number | null;
|
|
234
|
+
/**
|
|
235
|
+
* Reason a series could not be produced at all, which is not the same as a
|
|
236
|
+
* series that has no points in the window.
|
|
237
|
+
**/
|
|
238
|
+
declare const CHART_UNAVAILABLE_CODES: readonly ["unknown_subject", "unsupported_metric", "no_price_feed", "not_indexed", "internal"];
|
|
239
|
+
type ChartUnavailableCode = (typeof CHART_UNAVAILABLE_CODES)[number];
|
|
240
|
+
/**
|
|
241
|
+
* A series that was produced, holding one value per timestamp of its bundle.
|
|
242
|
+
*
|
|
243
|
+
* It does not name its own metric: it is reached through the key that does, see
|
|
244
|
+
* {@link ChartBundle}.
|
|
245
|
+
**/
|
|
246
|
+
type ChartSeriesOk = {
|
|
247
|
+
status: "ok";
|
|
248
|
+
/**
|
|
249
|
+
* Values aligned to the bundle's `timestamps`, index for index and of the
|
|
250
|
+
* same length, so two series of one bundle are directly comparable.
|
|
251
|
+
**/
|
|
252
|
+
values: ChartValue[];
|
|
253
|
+
} & ChartDenomination;
|
|
254
|
+
/**
|
|
255
|
+
* A series that could not be produced.
|
|
256
|
+
**/
|
|
257
|
+
interface ChartSeriesUnavailable {
|
|
258
|
+
status: "unavailable";
|
|
259
|
+
reason: {
|
|
260
|
+
/**
|
|
261
|
+
* Machine-readable cause, safe to `switch` on.
|
|
262
|
+
**/
|
|
263
|
+
code: ChartUnavailableCode;
|
|
264
|
+
/**
|
|
265
|
+
* English detail for logs. Not a translation key: what a screen shows is
|
|
266
|
+
* decided from {@link ChartUnavailableCode}, in the consumer's own
|
|
267
|
+
* catalogue.
|
|
268
|
+
**/
|
|
269
|
+
message?: string;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* One metric of one bundle, discriminated on `status`: an unavailable series
|
|
274
|
+
* has no values, and an available one has no reason.
|
|
275
|
+
**/
|
|
276
|
+
type ChartSeries = ChartSeriesOk | ChartSeriesUnavailable;
|
|
277
|
+
/**
|
|
278
|
+
* Window a bundle covers, resolved by the backend.
|
|
279
|
+
*
|
|
280
|
+
* Present even when every series is empty, so a chart still has an axis to draw
|
|
281
|
+
* and a range selector still has something to highlight.
|
|
282
|
+
**/
|
|
283
|
+
interface ChartWindow {
|
|
284
|
+
/**
|
|
285
|
+
* Window that was asked for.
|
|
286
|
+
**/
|
|
287
|
+
range: ChartRange;
|
|
288
|
+
/**
|
|
289
|
+
* Inclusive start, equal to the first timestamp of the bundle.
|
|
290
|
+
**/
|
|
291
|
+
from: Timestamp;
|
|
292
|
+
/**
|
|
293
|
+
* Inclusive end, equal to the last timestamp of the bundle.
|
|
294
|
+
**/
|
|
295
|
+
to: Timestamp;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Evenly spaced samples, which is what lets two series share an axis.
|
|
299
|
+
*
|
|
300
|
+
* A bucket in which a metric did not change carries the last known value; a
|
|
301
|
+
* bucket outside the series' lifetime — before its first observation or after
|
|
302
|
+
* its last — is `null`. Extrema inside a bucket are lost, which is the price of
|
|
303
|
+
* alignment.
|
|
304
|
+
**/
|
|
305
|
+
interface GridSampling {
|
|
306
|
+
/**
|
|
307
|
+
* The one sampling there is. Kept as a discriminant so a second one can be
|
|
308
|
+
* added later without breaking a consumer that already switches on it.
|
|
309
|
+
**/
|
|
310
|
+
kind: "grid";
|
|
311
|
+
/**
|
|
312
|
+
* Distance between consecutive timestamps, in seconds. Boundaries fall on
|
|
313
|
+
* multiples of it, so concurrent readers get the same grid — and so two reads
|
|
314
|
+
* of different subjects line up and can be drawn against each other.
|
|
315
|
+
**/
|
|
316
|
+
intervalSeconds: number;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* What a chart read answers with: one subject, one shared x-axis, and the
|
|
320
|
+
* series that were asked for.
|
|
321
|
+
*
|
|
322
|
+
* `Metrics` has no default. A bundle is always parameterized by the metric list
|
|
323
|
+
* one read received. A literal list gives exact required keys; a dynamically
|
|
324
|
+
* sized array gives optional keys because its runtime members are not known to
|
|
325
|
+
* TypeScript.
|
|
326
|
+
*
|
|
327
|
+
* @typeParam Metrics - Metric list the read received.
|
|
328
|
+
**/
|
|
329
|
+
interface ChartBundle<Metrics extends readonly ChartMetric[]> {
|
|
330
|
+
window: ChartWindow;
|
|
331
|
+
sampling: GridSampling;
|
|
332
|
+
/**
|
|
333
|
+
* The shared x-axis, ascending. Every available series holds exactly this
|
|
334
|
+
* many values.
|
|
335
|
+
**/
|
|
336
|
+
timestamps: Timestamp[];
|
|
337
|
+
/**
|
|
338
|
+
* One series per requested metric, keyed by it: `series.depositApy`.
|
|
339
|
+
*
|
|
340
|
+
* A literal metric tuple makes each requested key required. For a dynamic
|
|
341
|
+
* array the keys are optional: runtime validation still guarantees that every
|
|
342
|
+
* requested metric is present, but the compiler cannot know which metrics the
|
|
343
|
+
* array contains.
|
|
344
|
+
**/
|
|
345
|
+
series: ChartSeriesMap<Metrics>;
|
|
346
|
+
}
|
|
347
|
+
type ChartSeriesMap<Metrics extends readonly ChartMetric[]> = number extends Metrics["length"] ? Partial<Record<Metrics[number], ChartSeries>> : Record<Metrics[number], ChartSeries>;
|
|
348
|
+
//#endregion
|
|
349
|
+
export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, GridSampling, OpportunityChartMetric, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PoolOpportunityChartMetric, PoolPositionChartMetric, PositionChartMetric, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, StrategyOpportunityChartMetric, StrategyPositionChartMetric };
|