@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.
Files changed (48) hide show
  1. package/dist/cjs/model/charts.js +147 -0
  2. package/dist/cjs/model/charts.schema.js +240 -0
  3. package/dist/cjs/model/index.js +27 -22
  4. package/dist/cjs/model/liquidations.schema.js +1 -1
  5. package/dist/cjs/model/opportunities.schema.js +1 -1
  6. package/dist/cjs/model/positions.schema.js +2 -2
  7. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
  8. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +2 -6
  9. package/dist/cjs/new-sdk/utils/index.js +0 -1
  10. package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
  11. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
  12. package/dist/cjs/offchain/positions/OffchainPositions.js +8 -11
  13. package/dist/esm/model/charts.js +140 -0
  14. package/dist/esm/model/charts.schema.js +226 -0
  15. package/dist/esm/model/index.js +7 -7
  16. package/dist/esm/model/liquidations.schema.js +1 -1
  17. package/dist/esm/model/opportunities.schema.js +1 -1
  18. package/dist/esm/model/positions.schema.js +2 -2
  19. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
  20. package/dist/esm/new-sdk/positions/PositionsNamespace.js +2 -6
  21. package/dist/esm/new-sdk/utils/index.js +0 -1
  22. package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
  23. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
  24. package/dist/esm/offchain/positions/OffchainPositions.js +8 -11
  25. package/dist/types/model/charts.d.ts +349 -0
  26. package/dist/types/model/charts.schema.d.ts +364 -0
  27. package/dist/types/model/index.d.ts +5 -5
  28. package/dist/types/model/positions.d.ts +1 -1
  29. package/dist/types/new-sdk/index.d.ts +1 -2
  30. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +4 -5
  31. package/dist/types/new-sdk/opportunities/types.d.ts +9 -7
  32. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
  33. package/dist/types/new-sdk/positions/types.d.ts +9 -9
  34. package/dist/types/new-sdk/utils/index.d.ts +1 -2
  35. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
  36. package/dist/types/offchain/index.d.ts +2 -2
  37. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
  38. package/dist/types/offchain/positions/OffchainPositions.d.ts +11 -5
  39. package/package.json +1 -1
  40. package/dist/cjs/model/history.js +0 -53
  41. package/dist/cjs/model/history.schema.js +0 -128
  42. package/dist/cjs/new-sdk/utils/history.js +0 -1
  43. package/dist/esm/model/history.js +0 -49
  44. package/dist/esm/model/history.schema.js +0 -116
  45. package/dist/esm/new-sdk/utils/history.js +0 -1
  46. package/dist/types/model/history.d.ts +0 -153
  47. package/dist/types/model/history.schema.d.ts +0 -95
  48. package/dist/types/new-sdk/utils/history.d.ts +0 -18
@@ -0,0 +1,147 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/model/charts.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
+ const CHART_RANGES = [
21
+ "1d",
22
+ "1w",
23
+ "1m",
24
+ "1y",
25
+ "max"
26
+ ];
27
+ /**
28
+ * Every metric a pool opportunity can chart.
29
+ **/
30
+ const POOL_OPPORTUNITY_CHART_METRICS = [
31
+ "depositApy",
32
+ "borrowApy",
33
+ "dieselRate",
34
+ "supplied",
35
+ "borrowed",
36
+ "availableLiquidity"
37
+ ];
38
+ /**
39
+ * Every metric a strategy opportunity can chart.
40
+ *
41
+ * `collateralPrice` is the collateral/underlying series a liquidation-price
42
+ * chart draws; the two USD series are the same prices quoted in dollars.
43
+ **/
44
+ const STRATEGY_OPPORTUNITY_CHART_METRICS = [
45
+ "netApy",
46
+ "borrowApy",
47
+ "collateralApy",
48
+ "tvl",
49
+ "collateralPrice",
50
+ "collateralUsdPrice",
51
+ "underlyingUsdPrice"
52
+ ];
53
+ /**
54
+ * Every metric a pool position can chart.
55
+ *
56
+ * Nothing to do with {@link POOL_OPPORTUNITY_CHART_METRICS}: an opportunity charts what the
57
+ * pool did, a position charts what one wallet's deposit did in it. `mwr` and
58
+ * `twr` are cumulative returns since the position opened — money-weighted, so
59
+ * sensitive to when deposits and withdrawals landed, and time-weighted, which
60
+ * strips that timing out. Both are anchored at inception, so a narrow `range`
61
+ * only zooms the visible slice and its first point is rarely zero.
62
+ **/
63
+ const POOL_POSITION_CHART_METRICS = [
64
+ "value",
65
+ "apy",
66
+ "pnl",
67
+ "mwr",
68
+ "twr",
69
+ "underlyingPrice"
70
+ ];
71
+ /**
72
+ * Every metric a strategy position can chart.
73
+ *
74
+ * `twrApy` annualizes `twr` over the position's whole life; the two trailing
75
+ * APYs annualize it over a fixed window instead, so they track the current pace
76
+ * rather than the lifetime rate and are comparable across positions of
77
+ * different ages.
78
+ **/
79
+ const STRATEGY_POSITION_CHART_METRICS = [
80
+ "totalValueUsd",
81
+ "totalValueUnderlying",
82
+ "debt",
83
+ "healthFactor",
84
+ "leverage",
85
+ "borrowApy",
86
+ "underlyingPrice",
87
+ "pnl",
88
+ "mwr",
89
+ "twr",
90
+ "twrApy",
91
+ "trailingApy7d",
92
+ "trailingApy30d"
93
+ ];
94
+ /**
95
+ * Unit of every metric, the one place either side decides it.
96
+ *
97
+ * A metric added to a union above fails to compile here until its unit is
98
+ * named, and the wire schema rejects a series whose `unit` disagrees with this
99
+ * table, so the backend cannot drift from it silently.
100
+ **/
101
+ const CHART_METRIC_UNITS = {
102
+ depositApy: "bps",
103
+ borrowApy: "bps",
104
+ netApy: "bps",
105
+ collateralApy: "bps",
106
+ supplied: "token",
107
+ borrowed: "token",
108
+ availableLiquidity: "token",
109
+ tvl: "token",
110
+ dieselRate: "ratio",
111
+ collateralPrice: "ratio",
112
+ collateralUsdPrice: "usd",
113
+ underlyingUsdPrice: "usd",
114
+ value: "token",
115
+ apy: "bps",
116
+ pnl: "token",
117
+ mwr: "bps",
118
+ twr: "bps",
119
+ underlyingPrice: "usd",
120
+ totalValueUsd: "usd",
121
+ totalValueUnderlying: "token",
122
+ debt: "token",
123
+ healthFactor: "bps",
124
+ leverage: "scalar",
125
+ twrApy: "bps",
126
+ trailingApy7d: "bps",
127
+ trailingApy30d: "bps"
128
+ };
129
+ /**
130
+ * Reason a series could not be produced at all, which is not the same as a
131
+ * series that has no points in the window.
132
+ **/
133
+ const CHART_UNAVAILABLE_CODES = [
134
+ "unknown_subject",
135
+ "unsupported_metric",
136
+ "no_price_feed",
137
+ "not_indexed",
138
+ "internal"
139
+ ];
140
+ //#endregion
141
+ exports.CHART_METRIC_UNITS = CHART_METRIC_UNITS;
142
+ exports.CHART_RANGES = CHART_RANGES;
143
+ exports.CHART_UNAVAILABLE_CODES = CHART_UNAVAILABLE_CODES;
144
+ exports.POOL_OPPORTUNITY_CHART_METRICS = POOL_OPPORTUNITY_CHART_METRICS;
145
+ exports.POOL_POSITION_CHART_METRICS = POOL_POSITION_CHART_METRICS;
146
+ exports.STRATEGY_OPPORTUNITY_CHART_METRICS = STRATEGY_OPPORTUNITY_CHART_METRICS;
147
+ exports.STRATEGY_POSITION_CHART_METRICS = STRATEGY_POSITION_CHART_METRICS;
@@ -0,0 +1,240 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_charts = require("./charts.js");
3
+ const require_model_primitives_schema = require("./primitives.schema.js");
4
+ let zod_v4 = require("zod/v4");
5
+ //#region src/model/charts.schema.ts
6
+ /**
7
+ * Runtime schemas for {@link ./charts.js}, see the note in
8
+ * `primitives.schema.ts` on why they are written by hand.
9
+ *
10
+ * Metric schemas are shared with the backend, while
11
+ * {@link chartBundleSchemaFor} builds the response schema for one concrete
12
+ * request. Component schemas remain available for consumers that validate
13
+ * model fragments.
14
+ **/
15
+ /**
16
+ * {@link ChartRange}
17
+ **/
18
+ const chartRangeSchema = zod_v4.z.enum(require_model_charts.CHART_RANGES);
19
+ /**
20
+ * {@link PoolOpportunityChartMetric}
21
+ **/
22
+ const poolOpportunityChartMetricSchema = zod_v4.z.enum(require_model_charts.POOL_OPPORTUNITY_CHART_METRICS);
23
+ /**
24
+ * {@link StrategyOpportunityChartMetric}
25
+ **/
26
+ const strategyOpportunityChartMetricSchema = zod_v4.z.enum(require_model_charts.STRATEGY_OPPORTUNITY_CHART_METRICS);
27
+ /**
28
+ * {@link PoolPositionChartMetric}
29
+ **/
30
+ const poolPositionChartMetricSchema = zod_v4.z.enum(require_model_charts.POOL_POSITION_CHART_METRICS);
31
+ /**
32
+ * {@link StrategyPositionChartMetric}
33
+ **/
34
+ const strategyPositionChartMetricSchema = zod_v4.z.enum(require_model_charts.STRATEGY_POSITION_CHART_METRICS);
35
+ /**
36
+ * {@link ChartMetric}, every metric either kind of subject can chart.
37
+ **/
38
+ const chartMetricSchema = zod_v4.z.union([
39
+ poolOpportunityChartMetricSchema,
40
+ strategyOpportunityChartMetricSchema,
41
+ poolPositionChartMetricSchema,
42
+ strategyPositionChartMetricSchema
43
+ ]);
44
+ /**
45
+ * {@link ChartQuery}
46
+ **/
47
+ const chartQuerySchema = zod_v4.z.object({
48
+ metrics: zod_v4.z.array(chartMetricSchema).readonly().refine((metrics) => metrics.length > 0, { error: "a chart read needs at least one metric" }).refine((metrics) => new Set(metrics).size === metrics.length, { error: "a chart read needs distinct metrics" }),
49
+ range: chartRangeSchema
50
+ });
51
+ /**
52
+ * {@link ChartQuery} as a URL can carry it: the metrics comma-joined, since
53
+ * repeated `?metrics=` entries would order differently between clients and give
54
+ * one request two cache keys.
55
+ **/
56
+ const chartQueryParamsSchema = zod_v4.z.object({
57
+ metrics: zod_v4.z.string().regex(/^\w+(,\w+)*$/),
58
+ range: chartRangeSchema
59
+ });
60
+ /**
61
+ * Codec for {@link ChartQuery} to encode/decode to/from url query parameters.
62
+ *
63
+ * The one place the wire form of a chart request is decided. The SDK encodes
64
+ * with it, the backend decodes with it, and the checks that a read names at
65
+ * least one metric and names none of them twice ride along in both directions —
66
+ * so a bad request fails before it is issued, not after a round trip.
67
+ **/
68
+ const chartQueryCodec = zod_v4.z.codec(chartQueryParamsSchema, chartQuerySchema, {
69
+ decode: (params) => ({
70
+ metrics: params.metrics.split(","),
71
+ range: params.range
72
+ }),
73
+ encode: (query) => ({
74
+ metrics: query.metrics.join(","),
75
+ range: query.range
76
+ })
77
+ });
78
+ /**
79
+ * {@link ChartDenomination}
80
+ **/
81
+ const chartDenominationSchema = zod_v4.z.discriminatedUnion("unit", [
82
+ zod_v4.z.object({ unit: zod_v4.z.literal("bps") }),
83
+ zod_v4.z.object({ unit: zod_v4.z.literal("usd") }),
84
+ zod_v4.z.object({ unit: zod_v4.z.literal("scalar") }),
85
+ zod_v4.z.object({
86
+ unit: zod_v4.z.literal("token"),
87
+ base: require_model_primitives_schema.tokenSchema
88
+ }),
89
+ zod_v4.z.object({
90
+ unit: zod_v4.z.literal("ratio"),
91
+ base: require_model_primitives_schema.tokenSchema,
92
+ quote: require_model_primitives_schema.tokenSchema
93
+ })
94
+ ]);
95
+ /**
96
+ * {@link ChartValue}. `null` is a gap, never a zero.
97
+ **/
98
+ const chartValueSchema = zod_v4.z.number().nullable();
99
+ /**
100
+ * {@link ChartSeries}
101
+ **/
102
+ const chartSeriesSchema = zod_v4.z.union([zod_v4.z.intersection(zod_v4.z.object({
103
+ status: zod_v4.z.literal("ok"),
104
+ values: zod_v4.z.array(chartValueSchema)
105
+ }), chartDenominationSchema), zod_v4.z.object({
106
+ status: zod_v4.z.literal("unavailable"),
107
+ reason: zod_v4.z.object({
108
+ code: zod_v4.z.enum(require_model_charts.CHART_UNAVAILABLE_CODES),
109
+ message: zod_v4.z.string().optional()
110
+ })
111
+ })]);
112
+ /**
113
+ * {@link ChartWindow}
114
+ **/
115
+ const chartWindowSchema = zod_v4.z.object({
116
+ range: chartRangeSchema,
117
+ from: require_model_primitives_schema.timestampSchema,
118
+ to: require_model_primitives_schema.timestampSchema
119
+ });
120
+ const gridSamplingSchema = zod_v4.z.object({
121
+ kind: zod_v4.z.literal("grid"),
122
+ intervalSeconds: zod_v4.z.number().int().positive()
123
+ });
124
+ /**
125
+ * A bundle whose series are keyed by `keys`.
126
+ *
127
+ * `z.record` over a literal union is what enforces the metric set: a key that
128
+ * was not asked for is rejected, and one that was but is missing fails as an
129
+ * absent value. Exactly-once therefore needs no counting — an object cannot
130
+ * hold the same key twice.
131
+ **/
132
+ function chartBundleSchemaWith(keys, expectedRange) {
133
+ return zod_v4.z.object({
134
+ window: chartWindowSchema,
135
+ sampling: gridSamplingSchema,
136
+ timestamps: zod_v4.z.array(require_model_primitives_schema.timestampSchema),
137
+ series: zod_v4.z.record(keys, chartSeriesSchema)
138
+ }).superRefine((bundle, ctx) => checkChartBundle(bundle, ctx, expectedRange));
139
+ }
140
+ /**
141
+ * The invariants a bundle upholds beyond its shape, checked on every read so a
142
+ * backend that breaks one is rejected rather than plotted:
143
+ *
144
+ * - each available series holds exactly one value per timestamp, which is what
145
+ * makes two series of a bundle comparable at an index;
146
+ * - a series' unit is the one {@link CHART_METRIC_UNITS} gives the metric it is
147
+ * keyed by, so a consumer can format from either without them disagreeing;
148
+ * - the window's bounds are the axis' own, so a chart drawn from `window` and a
149
+ * chart drawn from `timestamps` cover the same span;
150
+ * - timestamps lie on the declared grid and are exactly one interval apart;
151
+ * - when validating a read, the response names the range that was requested.
152
+ **/
153
+ function checkChartBundle(bundle, ctx, expectedRange) {
154
+ const { sampling, timestamps, window, series } = bundle;
155
+ const entries = Object.entries(series);
156
+ for (const [metric, chart] of entries) {
157
+ if (chart.status !== "ok") continue;
158
+ if (chart.values.length !== timestamps.length) ctx.addIssue({
159
+ code: "custom",
160
+ path: [
161
+ "series",
162
+ metric,
163
+ "values"
164
+ ],
165
+ message: `series "${metric}" holds ${chart.values.length} values for ${timestamps.length} timestamps`
166
+ });
167
+ if (require_model_charts.CHART_METRIC_UNITS[metric] !== chart.unit) ctx.addIssue({
168
+ code: "custom",
169
+ path: [
170
+ "series",
171
+ metric,
172
+ "unit"
173
+ ],
174
+ message: `metric "${metric}" is ${require_model_charts.CHART_METRIC_UNITS[metric]}, not ${chart.unit}`
175
+ });
176
+ }
177
+ const first = timestamps.at(0);
178
+ const last = timestamps.at(-1);
179
+ if (first !== void 0 && first !== window.from) ctx.addIssue({
180
+ code: "custom",
181
+ path: ["window", "from"],
182
+ message: `window starts at ${window.from} but the axis starts at ${first}`
183
+ });
184
+ if (last !== void 0 && last !== window.to) ctx.addIssue({
185
+ code: "custom",
186
+ path: ["window", "to"],
187
+ message: `window ends at ${window.to} but the axis ends at ${last}`
188
+ });
189
+ if (expectedRange !== void 0 && window.range !== expectedRange) ctx.addIssue({
190
+ code: "custom",
191
+ path: ["window", "range"],
192
+ message: `requested range ${expectedRange}, received ${window.range}`
193
+ });
194
+ for (let i = 0; i < timestamps.length; i += 1) {
195
+ const timestamp = timestamps[i];
196
+ if (timestamp % sampling.intervalSeconds !== 0) ctx.addIssue({
197
+ code: "custom",
198
+ path: ["timestamps", i],
199
+ message: `timestamp ${timestamp} is not on the ${sampling.intervalSeconds}-second grid`
200
+ });
201
+ const previous = timestamps[i - 1];
202
+ if (previous !== void 0 && timestamp - previous !== sampling.intervalSeconds) ctx.addIssue({
203
+ code: "custom",
204
+ path: ["timestamps", i],
205
+ message: `timestamps are not ${sampling.intervalSeconds} seconds apart`
206
+ });
207
+ }
208
+ }
209
+ /**
210
+ * The schema one chart read is decoded with: a {@link ChartBundle} keyed by the
211
+ * requested distinct metrics, all of them and nothing else, for the requested
212
+ * range.
213
+ *
214
+ * Pinning the metrics is what upholds the `ChartBundle<Metrics>` a caller gets
215
+ * back — a response that answers a different question fails validation rather
216
+ * than being cast into the requested shape. The declared return type is the one
217
+ * the key schema actually enforces, which the compiler cannot see through a
218
+ * schema built from a runtime list.
219
+ **/
220
+ function chartBundleSchemaFor(metrics, range) {
221
+ if (metrics.length === 0) throw new RangeError("a chart read needs at least one metric");
222
+ if (new Set(metrics).size !== metrics.length) throw new RangeError("a chart read needs distinct metrics");
223
+ const literals = metrics.map((metric) => zod_v4.z.literal(metric));
224
+ return chartBundleSchemaWith(zod_v4.z.union(literals), range);
225
+ }
226
+ //#endregion
227
+ exports.chartBundleSchemaFor = chartBundleSchemaFor;
228
+ exports.chartDenominationSchema = chartDenominationSchema;
229
+ exports.chartMetricSchema = chartMetricSchema;
230
+ exports.chartQueryCodec = chartQueryCodec;
231
+ exports.chartQueryParamsSchema = chartQueryParamsSchema;
232
+ exports.chartQuerySchema = chartQuerySchema;
233
+ exports.chartRangeSchema = chartRangeSchema;
234
+ exports.chartSeriesSchema = chartSeriesSchema;
235
+ exports.chartValueSchema = chartValueSchema;
236
+ exports.chartWindowSchema = chartWindowSchema;
237
+ exports.poolOpportunityChartMetricSchema = poolOpportunityChartMetricSchema;
238
+ exports.poolPositionChartMetricSchema = poolPositionChartMetricSchema;
239
+ exports.strategyOpportunityChartMetricSchema = strategyOpportunityChartMetricSchema;
240
+ exports.strategyPositionChartMetricSchema = strategyPositionChartMetricSchema;
@@ -1,25 +1,28 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_charts = require("./charts.js");
3
+ const require_model_primitives_schema = require("./primitives.schema.js");
4
+ const require_model_charts_schema = require("./charts.schema.js");
2
5
  require("./curators.js");
3
6
  const require_model_curators_schema = require("./curators.schema.js");
4
7
  const require_model_filters = require("./filters.js");
5
8
  const require_model_filters_schema = require("./filters.schema.js");
6
- const require_model_history = require("./history.js");
7
- const require_model_primitives_schema = require("./primitives.schema.js");
8
- const require_model_opportunities_schema = require("./opportunities.schema.js");
9
- const require_model_liquidations_schema = require("./liquidations.schema.js");
10
- const require_model_positions_schema = require("./positions.schema.js");
11
- const require_model_history_schema = require("./history.schema.js");
12
9
  const require_model_liquidations = require("./liquidations.js");
10
+ const require_model_liquidations_schema = require("./liquidations.schema.js");
13
11
  const require_model_opportunities = require("./opportunities.js");
12
+ const require_model_opportunities_schema = require("./opportunities.schema.js");
14
13
  const require_model_positions = require("./positions.js");
14
+ const require_model_positions_schema = require("./positions.schema.js");
15
15
  require("./primitives.js");
16
16
  require("./response.js");
17
17
  const require_model_response_schema = require("./response.schema.js");
18
+ exports.CHART_METRIC_UNITS = require_model_charts.CHART_METRIC_UNITS;
19
+ exports.CHART_RANGES = require_model_charts.CHART_RANGES;
20
+ exports.CHART_UNAVAILABLE_CODES = require_model_charts.CHART_UNAVAILABLE_CODES;
18
21
  exports.FILTER_ALL = require_model_filters.FILTER_ALL;
19
- exports.POOL_HISTORY_METRICS = require_model_history.POOL_HISTORY_METRICS;
20
- exports.POOL_POSITION_HISTORY_METRICS = require_model_history.POOL_POSITION_HISTORY_METRICS;
21
- exports.STRATEGY_HISTORY_METRICS = require_model_history.STRATEGY_HISTORY_METRICS;
22
- exports.STRATEGY_POSITION_HISTORY_METRICS = require_model_history.STRATEGY_POSITION_HISTORY_METRICS;
22
+ exports.POOL_OPPORTUNITY_CHART_METRICS = require_model_charts.POOL_OPPORTUNITY_CHART_METRICS;
23
+ exports.POOL_POSITION_CHART_METRICS = require_model_charts.POOL_POSITION_CHART_METRICS;
24
+ exports.STRATEGY_OPPORTUNITY_CHART_METRICS = require_model_charts.STRATEGY_OPPORTUNITY_CHART_METRICS;
25
+ exports.STRATEGY_POSITION_CHART_METRICS = require_model_charts.STRATEGY_POSITION_CHART_METRICS;
23
26
  exports.amountSchema = require_model_primitives_schema.amountSchema;
24
27
  exports.apyBreakdownSchema = require_model_opportunities_schema.apyBreakdownSchema;
25
28
  exports.assetTypeSchema = require_model_primitives_schema.assetTypeSchema;
@@ -30,6 +33,16 @@ exports.chainFailedSchema = require_model_response_schema.chainFailedSchema;
30
33
  exports.chainIdSchema = require_model_primitives_schema.chainIdSchema;
31
34
  exports.chainMetadataSchema = require_model_response_schema.chainMetadataSchema;
32
35
  exports.chainSucceededSchema = require_model_response_schema.chainSucceededSchema;
36
+ exports.chartBundleSchemaFor = require_model_charts_schema.chartBundleSchemaFor;
37
+ exports.chartDenominationSchema = require_model_charts_schema.chartDenominationSchema;
38
+ exports.chartMetricSchema = require_model_charts_schema.chartMetricSchema;
39
+ exports.chartQueryCodec = require_model_charts_schema.chartQueryCodec;
40
+ exports.chartQueryParamsSchema = require_model_charts_schema.chartQueryParamsSchema;
41
+ exports.chartQuerySchema = require_model_charts_schema.chartQuerySchema;
42
+ exports.chartRangeSchema = require_model_charts_schema.chartRangeSchema;
43
+ exports.chartSeriesSchema = require_model_charts_schema.chartSeriesSchema;
44
+ exports.chartValueSchema = require_model_charts_schema.chartValueSchema;
45
+ exports.chartWindowSchema = require_model_charts_schema.chartWindowSchema;
33
46
  exports.curatorNameSchema = require_model_curators_schema.curatorNameSchema;
34
47
  exports.curatorSchema = require_model_curators_schema.curatorSchema;
35
48
  exports.dataSourceSchema = require_model_response_schema.dataSourceSchema;
@@ -37,11 +50,6 @@ exports.delayedReceivedAssetSchema = require_model_liquidations_schema.delayedRe
37
50
  exports.encodeFlag = require_model_filters_schema.encodeFlag;
38
51
  exports.filterAllSchema = require_model_filters_schema.filterAllSchema;
39
52
  exports.filterable = require_model_filters_schema.filterable;
40
- exports.historyChartMetadataSchema = require_model_history_schema.historyChartMetadataSchema;
41
- exports.historyMetricSchema = require_model_history_schema.historyMetricSchema;
42
- exports.historyPointSchema = require_model_history_schema.historyPointSchema;
43
- exports.historyRangeSchema = require_model_history_schema.historyRangeSchema;
44
- exports.historySeriesSchema = require_model_history_schema.historySeriesSchema;
45
53
  exports.instantReceivedAssetSchema = require_model_liquidations_schema.instantReceivedAssetSchema;
46
54
  exports.isFilterSet = require_model_filters.isFilterSet;
47
55
  exports.leverageSchema = require_model_primitives_schema.leverageSchema;
@@ -59,7 +67,6 @@ exports.opportunityDetailSchema = require_model_opportunities_schema.opportunity
59
67
  exports.opportunityFilterQueryParamsSchema = require_model_opportunities_schema.opportunityFilterQueryParamsSchema;
60
68
  exports.opportunityFilterQuerySchema = require_model_opportunities_schema.opportunityFilterQuerySchema;
61
69
  exports.opportunityFilterSchema = require_model_opportunities_schema.opportunityFilterSchema;
62
- exports.opportunityHistoryQuerySchema = require_model_history_schema.opportunityHistoryQuerySchema;
63
70
  exports.opportunityId = require_model_opportunities.opportunityId;
64
71
  exports.opportunityKeySchema = require_model_opportunities_schema.opportunityKeySchema;
65
72
  exports.opportunityKindSchema = require_model_opportunities_schema.opportunityKindSchema;
@@ -69,12 +76,12 @@ exports.pointRewardsSchema = require_model_opportunities_schema.pointRewardsSche
69
76
  exports.pointsProgramPnLSchema = require_model_positions_schema.pointsProgramPnLSchema;
70
77
  exports.pointsProgramSchema = require_model_opportunities_schema.pointsProgramSchema;
71
78
  exports.pointsRewardsPnLSchema = require_model_positions_schema.pointsRewardsPnLSchema;
72
- exports.poolHistoryMetricSchema = require_model_history_schema.poolHistoryMetricSchema;
79
+ exports.poolOpportunityChartMetricSchema = require_model_charts_schema.poolOpportunityChartMetricSchema;
73
80
  exports.poolOpportunityDetailSchema = require_model_opportunities_schema.poolOpportunityDetailSchema;
74
81
  exports.poolOpportunityId = require_model_opportunities.poolOpportunityId;
75
82
  exports.poolOpportunityKeySchema = require_model_opportunities_schema.poolOpportunityKeySchema;
76
83
  exports.poolOpportunitySchema = require_model_opportunities_schema.poolOpportunitySchema;
77
- exports.poolPositionHistoryMetricSchema = require_model_history_schema.poolPositionHistoryMetricSchema;
84
+ exports.poolPositionChartMetricSchema = require_model_charts_schema.poolPositionChartMetricSchema;
78
85
  exports.poolPositionId = require_model_positions.poolPositionId;
79
86
  exports.poolPositionKeySchema = require_model_positions_schema.poolPositionKeySchema;
80
87
  exports.poolPositionSchema = require_model_positions_schema.poolPositionSchema;
@@ -82,8 +89,6 @@ exports.positionCollateralSchema = require_model_positions_schema.positionCollat
82
89
  exports.positionFilterQueryParamsSchema = require_model_positions_schema.positionFilterQueryParamsSchema;
83
90
  exports.positionFilterQuerySchema = require_model_positions_schema.positionFilterQuerySchema;
84
91
  exports.positionFilterSchema = require_model_positions_schema.positionFilterSchema;
85
- exports.positionHistoryMetricSchema = require_model_history_schema.positionHistoryMetricSchema;
86
- exports.positionHistoryQuerySchema = require_model_history_schema.positionHistoryQuerySchema;
87
92
  exports.positionId = require_model_positions.positionId;
88
93
  exports.positionKeySchema = require_model_positions_schema.positionKeySchema;
89
94
  exports.positionKindSchema = require_model_positions_schema.positionKindSchema;
@@ -98,12 +103,12 @@ exports.responseMetadataSchema = require_model_response_schema.responseMetadataS
98
103
  exports.responseSchema = require_model_response_schema.responseSchema;
99
104
  exports.rewardsPnLSchema = require_model_positions_schema.rewardsPnLSchema;
100
105
  exports.rewardsSchema = require_model_opportunities_schema.rewardsSchema;
101
- exports.strategyHistoryMetricSchema = require_model_history_schema.strategyHistoryMetricSchema;
106
+ exports.strategyOpportunityChartMetricSchema = require_model_charts_schema.strategyOpportunityChartMetricSchema;
102
107
  exports.strategyOpportunityDetailSchema = require_model_opportunities_schema.strategyOpportunityDetailSchema;
103
108
  exports.strategyOpportunityId = require_model_opportunities.strategyOpportunityId;
104
109
  exports.strategyOpportunityKeySchema = require_model_opportunities_schema.strategyOpportunityKeySchema;
105
110
  exports.strategyOpportunitySchema = require_model_opportunities_schema.strategyOpportunitySchema;
106
- exports.strategyPositionHistoryMetricSchema = require_model_history_schema.strategyPositionHistoryMetricSchema;
111
+ exports.strategyPositionChartMetricSchema = require_model_charts_schema.strategyPositionChartMetricSchema;
107
112
  exports.strategyPositionId = require_model_positions.strategyPositionId;
108
113
  exports.strategyPositionKeySchema = require_model_positions_schema.strategyPositionKeySchema;
109
114
  exports.strategyPositionSchema = require_model_positions_schema.strategyPositionSchema;
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sdk_utils_zod = require("../sdk/utils/zod.js");
3
- const require_model_filters_schema = require("./filters.schema.js");
4
3
  const require_model_primitives_schema = require("./primitives.schema.js");
4
+ const require_model_filters_schema = require("./filters.schema.js");
5
5
  let zod_v4 = require("zod/v4");
6
6
  //#region src/model/liquidations.schema.ts
7
7
  /**
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sdk_utils_zod = require("../sdk/utils/zod.js");
3
+ const require_model_primitives_schema = require("./primitives.schema.js");
3
4
  const require_model_curators_schema = require("./curators.schema.js");
4
5
  const require_model_filters = require("./filters.js");
5
6
  const require_model_filters_schema = require("./filters.schema.js");
6
- const require_model_primitives_schema = require("./primitives.schema.js");
7
7
  let zod_v4 = require("zod/v4");
8
8
  //#region src/model/opportunities.schema.ts
9
9
  /**
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sdk_utils_zod = require("../sdk/utils/zod.js");
3
+ const require_model_primitives_schema = require("./primitives.schema.js");
3
4
  const require_model_filters = require("./filters.js");
4
5
  const require_model_filters_schema = require("./filters.schema.js");
5
- const require_model_primitives_schema = require("./primitives.schema.js");
6
- const require_model_opportunities_schema = require("./opportunities.schema.js");
7
6
  const require_model_liquidations_schema = require("./liquidations.schema.js");
7
+ const require_model_opportunities_schema = require("./opportunities.schema.js");
8
8
  let zod_v4 = require("zod/v4");
9
9
  //#region src/model/positions.schema.ts
10
10
  /**
@@ -58,12 +58,8 @@ var OpportunitiesNamespace = class extends require_new_sdk_AbstractNamespace.Abs
58
58
  filter(response, filter) {
59
59
  return require_new_sdk_utils_filterResponse.filterResponse(response, filter, require_model_opportunities.matchesOpportunityFilter);
60
60
  }
61
- history(key) {
62
- return { chart: (metric, range) => this.offchain.getHistory({
63
- opportunity: key,
64
- range,
65
- metric
66
- }) };
61
+ async charts(key, metrics, range) {
62
+ return this.offchain.getCharts(key, metrics, range);
67
63
  }
68
64
  };
69
65
  //#endregion
@@ -40,12 +40,8 @@ var PositionsNamespace = class extends require_new_sdk_AbstractNamespace.Abstrac
40
40
  filter(response, filter) {
41
41
  return require_new_sdk_utils_filterResponse.filterResponse(response, filter, require_model_positions.matchesPositionFilter);
42
42
  }
43
- history(key) {
44
- return { chart: (metric, range) => this.offchain.getHistory({
45
- position: key,
46
- range,
47
- metric
48
- }) };
43
+ async charts(key, metrics, range) {
44
+ return this.offchain.getCharts(key, metrics, range);
49
45
  }
50
46
  };
51
47
  //#endregion
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_new_sdk_utils_filterResponse = require("./filterResponse.js");
3
- require("./history.js");
4
3
  const require_new_sdk_utils_mergeChains = require("./mergeChains.js");
5
4
  exports.DEFAULT_MAX_OFFCHAIN_LAG = require_new_sdk_utils_mergeChains.DEFAULT_MAX_OFFCHAIN_LAG;
6
5
  exports.filterResponse = require_new_sdk_utils_filterResponse.filterResponse;
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_model_history_schema = require("../model/history.schema.js");
2
+ const require_model_charts_schema = require("../model/charts.schema.js");
3
3
  const require_model_response_schema = require("../model/response.schema.js");
4
4
  const require_offchain_errors_OffchainInvalidJsonError = require("./errors/OffchainInvalidJsonError.js");
5
5
  const require_offchain_errors_OffchainNotConfiguredError = require("./errors/OffchainNotConfiguredError.js");
@@ -65,14 +65,17 @@ var AbstractOffchainNamespace = class {
65
65
  };
66
66
  }
67
67
  /**
68
- * Reads one historical series. A response carrying a metric other than the
69
- * requested one fails validation.
68
+ * Reads the charts of one subject: one series per metric named, onto the one
69
+ * grid that lets them be compared at an index.
70
70
  **/
71
- async readHistory(request) {
71
+ async readCharts(path, metrics, range) {
72
72
  return this.get({
73
- path: request.path,
74
- query: { range: request.range },
75
- schema: require_model_history_schema.historySeriesSchema.extend({ metric: zod_v4.z.literal(request.metric) })
73
+ path,
74
+ query: zod_v4.z.encode(require_model_charts_schema.chartQueryCodec, {
75
+ metrics,
76
+ range
77
+ }),
78
+ schema: require_model_charts_schema.chartBundleSchemaFor(metrics, range)
76
79
  });
77
80
  }
78
81
  /**
@@ -44,14 +44,10 @@ var OffchainOpportunities = class extends require_offchain_AbstractOffchainNames
44
44
  });
45
45
  }
46
46
  /**
47
- * One historical series of one opportunity
47
+ * Charts of one opportunity: one series per metric, on a shared grid.
48
48
  **/
49
- async getHistory(query) {
50
- return this.readHistory({
51
- path: `${this.#historyRoot(query.opportunity)}/history/${query.metric}`,
52
- metric: query.metric,
53
- range: query.range
54
- });
49
+ async getCharts(key, metrics, range) {
50
+ return this.readCharts(`${this.#chartRoot(key)}/charts`, metrics, range);
55
51
  }
56
52
  #poolPath(key) {
57
53
  return `${this.#root}/pools/${key.chainId}/${key.pool}`;
@@ -59,7 +55,7 @@ var OffchainOpportunities = class extends require_offchain_AbstractOffchainNames
59
55
  #strategyPath(key) {
60
56
  return `${this.#root}/strategies/${key.chainId}/${key.creditManager}/${key.targetCollateral}`;
61
57
  }
62
- #historyRoot(key) {
58
+ #chartRoot(key) {
63
59
  return key.kind === "pool" ? this.#poolPath(key) : this.#strategyPath(key);
64
60
  }
65
61
  };
@@ -1,5 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_model_positions_schema = require("../../model/positions.schema.js");
3
+ const require_offchain_errors_OffchainNotImplementedError = require("../errors/OffchainNotImplementedError.js");
4
+ require("../errors/index.js");
3
5
  const require_offchain_AbstractOffchainNamespace = require("../AbstractOffchainNamespace.js");
4
6
  let zod_v4 = require("zod/v4");
5
7
  //#region src/offchain/positions/OffchainPositions.ts
@@ -25,19 +27,14 @@ var OffchainPositions = class extends require_offchain_AbstractOffchainNamespace
25
27
  });
26
28
  }
27
29
  /**
28
- * One historical series of one position.
30
+ * Charts of one position: one series per metric, on a shared grid.
29
31
  *
30
- * @returns An empty series until the backend client is implemented.
32
+ * @throws {OffchainNotImplementedError} Until the backend serves it. An empty
33
+ * bundle would be the one answer this model exists to rule out: a chart that
34
+ * could not be read is not a chart with no points.
31
35
  **/
32
- async getHistory(query) {
33
- return {
34
- data: {
35
- metric: query.metric,
36
- points: [],
37
- metadata: {}
38
- },
39
- meta: { chains: [] }
40
- };
36
+ async getCharts(key, _metrics, _range) {
37
+ throw new require_offchain_errors_OffchainNotImplementedError.OffchainNotImplementedError(`${this.#root}/${key.chainId}/charts`);
41
38
  }
42
39
  };
43
40
  //#endregion