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