@gearbox-protocol/sdk 15.1.0-next.7 → 15.1.0-next.9

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 (88) hide show
  1. package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +3 -1
  2. package/dist/cjs/model/charts.js +147 -0
  3. package/dist/cjs/model/charts.schema.js +240 -0
  4. package/dist/cjs/model/index.js +27 -22
  5. package/dist/cjs/model/liquidations.schema.js +1 -1
  6. package/dist/cjs/model/opportunities.schema.js +1 -1
  7. package/dist/cjs/model/positions.schema.js +2 -2
  8. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
  9. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +2 -6
  10. package/dist/cjs/new-sdk/utils/index.js +0 -1
  11. package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
  12. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
  13. package/dist/cjs/offchain/positions/OffchainPositions.js +8 -11
  14. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +23 -23
  15. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +14 -14
  16. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +12 -12
  17. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +17 -17
  18. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +12 -12
  19. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +9 -9
  20. package/dist/cjs/sdk/accounts/intents/testing/resume.js +3 -18
  21. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +0 -1
  22. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +6 -5
  23. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +3 -1
  24. package/dist/esm/dev/AccountOpener.js +1 -1
  25. package/dist/esm/dev/withdrawalUtils.js +1 -1
  26. package/dist/esm/model/charts.js +140 -0
  27. package/dist/esm/model/charts.schema.js +226 -0
  28. package/dist/esm/model/index.js +7 -7
  29. package/dist/esm/model/liquidations.schema.js +1 -1
  30. package/dist/esm/model/opportunities.schema.js +1 -1
  31. package/dist/esm/model/positions.schema.js +2 -2
  32. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
  33. package/dist/esm/new-sdk/positions/PositionsNamespace.js +2 -6
  34. package/dist/esm/new-sdk/utils/index.js +0 -1
  35. package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
  36. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
  37. package/dist/esm/offchain/positions/OffchainPositions.js +8 -11
  38. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  39. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  40. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  41. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  42. package/dist/esm/sdk/accounts/intents/testing/resume.js +1 -13
  43. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  44. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  45. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  46. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  47. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  48. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  49. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  50. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  51. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  52. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  53. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  54. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  55. package/dist/esm/sdk/pools/PoolService.js +1 -1
  56. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +7 -6
  57. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  58. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +3 -1
  59. package/dist/types/model/charts.d.ts +349 -0
  60. package/dist/types/model/charts.schema.d.ts +364 -0
  61. package/dist/types/model/index.d.ts +5 -5
  62. package/dist/types/model/positions.d.ts +1 -1
  63. package/dist/types/new-sdk/index.d.ts +1 -2
  64. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +4 -5
  65. package/dist/types/new-sdk/opportunities/types.d.ts +9 -7
  66. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
  67. package/dist/types/new-sdk/positions/types.d.ts +9 -9
  68. package/dist/types/new-sdk/utils/index.d.ts +1 -2
  69. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
  70. package/dist/types/offchain/index.d.ts +2 -2
  71. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
  72. package/dist/types/offchain/positions/OffchainPositions.d.ts +11 -5
  73. package/dist/types/sdk/accounts/intents/testing/expect.d.ts +1 -1
  74. package/dist/types/sdk/accounts/intents/testing/resume.d.ts +1 -1
  75. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +5 -4
  76. package/package.json +1 -1
  77. package/dist/cjs/model/history.js +0 -53
  78. package/dist/cjs/model/history.schema.js +0 -128
  79. package/dist/cjs/new-sdk/utils/history.js +0 -1
  80. package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
  81. package/dist/esm/model/history.js +0 -49
  82. package/dist/esm/model/history.schema.js +0 -116
  83. package/dist/esm/new-sdk/utils/history.js +0 -1
  84. package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
  85. package/dist/types/model/history.d.ts +0 -153
  86. package/dist/types/model/history.schema.d.ts +0 -95
  87. package/dist/types/new-sdk/utils/history.d.ts +0 -18
  88. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +0 -96
@@ -1,162 +0,0 @@
1
- import { CA_OP_CALLS, MOCK_CLAIM_CALL, MOCK_CLOSE_CALL, MOCK_ROUTER_CALL, MOCK_RWA_UNWRAP_CALL, MOCK_RWA_WRAP_CALL } from "./sdk-mock.js";
2
- import { expect } from "vitest";
3
- //#region src/sdk/accounts/intents/testing/expect.ts
4
- function expectedCalls(expected) {
5
- return expected.calls ?? [];
6
- }
7
- /**
8
- * Fills sentinel `calls` for onchain resume expectations. Shared fixtures keep
9
- * `calls: []` for offchain; onchain tests map through this helper.
10
- */
11
- function withOnchainOpCalls(ops) {
12
- return ops.map((op) => {
13
- switch (op.type) {
14
- case "claimDelayedWithdrawal": return {
15
- ...op,
16
- calls: [MOCK_CLAIM_CALL]
17
- };
18
- case "changeQuota": return {
19
- ...op,
20
- calls: [CA_OP_CALLS.changeQuota]
21
- };
22
- case "decreaseDebt": return {
23
- ...op,
24
- calls: [CA_OP_CALLS.decreaseDebt]
25
- };
26
- case "withdrawCollateral": return {
27
- ...op,
28
- calls: [CA_OP_CALLS.withdrawCollateral]
29
- };
30
- case "swap": return {
31
- ...op,
32
- calls: op.calls?.length ? op.calls : [MOCK_ROUTER_CALL]
33
- };
34
- case "wrapRwaCollateral": return {
35
- ...op,
36
- calls: op.calls?.length ? op.calls : [MOCK_RWA_WRAP_CALL]
37
- };
38
- case "unwrapRwaCollateral": return {
39
- ...op,
40
- calls: op.calls?.length ? op.calls : [MOCK_RWA_UNWRAP_CALL]
41
- };
42
- case "closeCreditAccount": return {
43
- ...op,
44
- calls: op.calls?.length ? op.calls : [MOCK_CLOSE_CALL]
45
- };
46
- default: return op;
47
- }
48
- });
49
- }
50
- function matchOp(actual, expected, index) {
51
- expect(actual.type, `op[${index}].type`).toBe(expected.type);
52
- switch (expected.type) {
53
- case "claimDelayedWithdrawal":
54
- if (actual.type !== "claimDelayedWithdrawal") return;
55
- expect(actual.token, `op[${index}].token`).toBe(expected.token);
56
- expect(actual.withdrawalPhantomToken, `op[${index}].withdrawalPhantomToken`).toBe(expected.withdrawalPhantomToken);
57
- expect(actual.withdrawalTokenSpent, `op[${index}].withdrawalTokenSpent`).toBe(expected.withdrawalTokenSpent);
58
- expect(actual.outputs, `op[${index}].outputs`).toEqual(expected.outputs);
59
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
60
- break;
61
- case "changeQuota":
62
- if (actual.type !== "changeQuota") return;
63
- expect(actual.quotaIncrease, `op[${index}].quotaIncrease`).toEqual(expected.quotaIncrease);
64
- expect(actual.quotaDecrease, `op[${index}].quotaDecrease`).toEqual(expected.quotaDecrease);
65
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
66
- break;
67
- case "closeCreditAccount":
68
- if (actual.type !== "closeCreditAccount") return;
69
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
70
- expect(actual.minAmount, `op[${index}].minAmount`).toBe(expected.minAmount);
71
- expect(actual.underlyingBalance, `op[${index}].underlyingBalance`).toBe(expected.underlyingBalance);
72
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
73
- break;
74
- case "swap":
75
- if (actual.type !== "swap") return;
76
- expect(actual.from, `op[${index}].from`).toEqual(expected.from);
77
- expect(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
78
- expect(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
79
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
80
- break;
81
- case "decreaseDebt":
82
- if (actual.type !== "decreaseDebt") return;
83
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
84
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
85
- break;
86
- case "withdrawCollateral":
87
- if (actual.type !== "withdrawCollateral") return;
88
- expect(actual.token, `op[${index}].token`).toBe(expected.token);
89
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
90
- expect(actual.to, `op[${index}].to`).toBe(expected.to);
91
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
92
- break;
93
- case "unwrapRwaCollateral":
94
- if (actual.type !== "unwrapRwaCollateral") return;
95
- expect(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
96
- expect(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
97
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
98
- expect(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
99
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
100
- break;
101
- case "wrapRwaCollateral":
102
- if (actual.type !== "wrapRwaCollateral") return;
103
- expect(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
104
- expect(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
105
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
106
- expect(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
107
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
108
- }
109
- }
110
- /** Asserts exact operations on a raw op array (type + tokens + amounts). */
111
- function expectOpsArrayExact(ops, expected) {
112
- expect(ops.length, "operations.length").toBe(expected.length);
113
- for (let i = 0; i < expected.length; i++) {
114
- const actual = ops[i];
115
- const exp = expected[i];
116
- if (actual === void 0 || exp === void 0) {
117
- expect.fail(`missing op at index ${i}`);
118
- return;
119
- }
120
- matchOp(actual, exp, i);
121
- }
122
- }
123
- /** Asserts exact calls on a raw MultiCall array (target + callData). */
124
- function expectCallsArrayExact(calls, expected, label = "calls") {
125
- expect(calls.length, `${label}.length`).toBe(expected.length);
126
- for (let i = 0; i < expected.length; i++) {
127
- const actual = calls[i];
128
- const exp = expected[i];
129
- if (actual === void 0 || exp === void 0) {
130
- expect.fail(`missing call at index ${i}`);
131
- return;
132
- }
133
- expect(actual.target, `${label}[${i}].target`).toBe(exp.target);
134
- expect(actual.callData, `${label}[${i}].callData`).toBe(exp.callData);
135
- }
136
- }
137
- /**
138
- * Asserts a successful adjust-style resume preview: ok, instant branch present,
139
- * exact calls (empty unless `expectedCalls` is provided), metrics from the
140
- * post-claim CA, and exact operations (incl. changeQuota).
141
- * Returns the adjust preview state for further asset/quota assertions.
142
- */
143
- function expectAdjustResumePreview(result, args) {
144
- expect(result.ok).toBe(true);
145
- if (!result.ok) throw new Error("expected ok resume preview");
146
- expect(result.instant, "instant branch").toBeDefined();
147
- if (!result.instant) throw new Error("expected instant branch");
148
- if (args.expectedCalls) expectCallsArrayExact(result.instant.calls, args.expectedCalls);
149
- else expect(result.instant.calls).toEqual([]);
150
- const state = result.instant.preview.min;
151
- expect(state.kind).toBe("adjust");
152
- if (state.kind !== "adjust") throw new Error("expected adjust preview state");
153
- expect(state.totalValue).toBe(args.totalValue);
154
- expect(state.accountDebt).toBe(args.accountDebt);
155
- expectOpsArrayExact(result.instant.operations, args.expectedOps);
156
- return state;
157
- }
158
- function assetBalance(assets, token) {
159
- return assets.find((a) => a.token === token)?.balance ?? 0n;
160
- }
161
- //#endregion
162
- export { assetBalance, expectAdjustResumePreview, expectCallsArrayExact, expectOpsArrayExact, withOnchainOpCalls };
@@ -1,153 +0,0 @@
1
- import { Timestamp } from "./primitives.js";
2
- import { OpportunityKey } from "./opportunities.js";
3
- import { PositionKey } from "./positions.js";
4
- //#region src/model/history.d.ts
5
- /**
6
- * Historical time series of an opportunity.
7
- *
8
- * History is backend-only by construction: the chain serves the present, and
9
- * reconstructing a series from it would mean archive-node reads per point.
10
- **/
11
- /**
12
- * Time window a series covers, ending at the present.
13
- *
14
- * `"max"` is the full history the backend retains for the opportunity.
15
- **/
16
- type HistoryRange = "1d" | "1w" | "1m" | "1y" | "max";
17
- /**
18
- * Series available for a pool opportunity.
19
- **/
20
- type PoolHistoryMetric = "depositApy" | "borrowApy" | "dieselRate" | "supplied" | "borrowed" | "availableLiquidity";
21
- /**
22
- * Every {@link PoolHistoryMetric}, for callers that enumerate them.
23
- **/
24
- declare const POOL_HISTORY_METRICS: readonly ["depositApy", "borrowApy", "dieselRate", "supplied", "borrowed", "availableLiquidity"];
25
- /**
26
- * Series available for a strategy opportunity.
27
- *
28
- * `collateralPrice` is the collateral/underlying series a liquidation-price
29
- * chart draws; the two USD series are the same prices quoted in dollars.
30
- **/
31
- type StrategyHistoryMetric = "netApy" | "borrowApy" | "collateralApy" | "tvl" | "collateralPrice" | "collateralUsdPrice" | "underlyingUsdPrice";
32
- /**
33
- * Every {@link StrategyHistoryMetric}, for callers that enumerate them.
34
- **/
35
- declare const STRATEGY_HISTORY_METRICS: readonly ["netApy", "borrowApy", "collateralApy", "tvl", "collateralPrice", "collateralUsdPrice", "underlyingUsdPrice"];
36
- /**
37
- * Series available for a pool position.
38
- *
39
- * Spelled out rather than aliased to {@link PoolHistoryMetric}: an opportunity
40
- * and a position are separate contracts with the backend, and the position
41
- * series are expected to grow their own members (PnL above all) without that
42
- * change reaching the opportunity charts.
43
- **/
44
- type PoolPositionHistoryMetric = "depositApy" | "borrowApy" | "dieselRate" | "supplied" | "borrowed" | "availableLiquidity";
45
- /**
46
- * Every {@link PoolPositionHistoryMetric}, for callers that enumerate them.
47
- **/
48
- declare const POOL_POSITION_HISTORY_METRICS: readonly ["depositApy", "borrowApy", "dieselRate", "supplied", "borrowed", "availableLiquidity"];
49
- /**
50
- * Series available for a strategy position, see the note on
51
- * {@link PoolPositionHistoryMetric} for why these are spelled out separately
52
- * from {@link StrategyHistoryMetric}.
53
- **/
54
- type StrategyPositionHistoryMetric = "netApy" | "borrowApy" | "collateralApy" | "tvl" | "collateralPrice" | "collateralUsdPrice" | "underlyingUsdPrice";
55
- /**
56
- * Every {@link StrategyPositionHistoryMetric}, for callers that enumerate them.
57
- **/
58
- declare const STRATEGY_POSITION_HISTORY_METRICS: readonly ["netApy", "borrowApy", "collateralApy", "tvl", "collateralPrice", "collateralUsdPrice", "underlyingUsdPrice"];
59
- /**
60
- * Any series a position can return.
61
- **/
62
- type PositionHistoryMetric = PoolPositionHistoryMetric | StrategyPositionHistoryMetric;
63
- /**
64
- * Any series the read model can return.
65
- **/
66
- type HistoryMetric = PoolHistoryMetric | StrategyHistoryMetric | PositionHistoryMetric;
67
- /**
68
- * One sample of a series.
69
- **/
70
- interface HistoryPoint {
71
- /**
72
- * When the sample was taken.
73
- **/
74
- timestamp: Timestamp;
75
- /**
76
- * Sampled value. The unit follows from the metric: APY metrics are in basis
77
- * points, amount metrics are in the underlying's base units expressed as a
78
- * float, price metrics are plain prices.
79
- *
80
- * @example `842` for an 8.42% APY sample
81
- **/
82
- value: number;
83
- }
84
- /**
85
- * Annotations the backend ships alongside a series, e.g. what a chart drawn
86
- * from it should say beyond the points themselves.
87
- *
88
- * TODO: the backend has not specified this payload yet. It stays empty until
89
- * it does, so that filling it in later is additive rather than a rename.
90
- **/
91
- interface HistoryChartMetadata {}
92
- /**
93
- * A named series of samples ordered by ascending timestamp.
94
- *
95
- * @typeParam M - Metric the series carries.
96
- **/
97
- interface HistorySeries<M extends string = HistoryMetric> {
98
- /**
99
- * Metric the samples belong to; it also defines their unit, so no separate
100
- * unit field ships.
101
- **/
102
- metric: M;
103
- /**
104
- * Samples, oldest first.
105
- **/
106
- points: HistoryPoint[];
107
- /**
108
- * What the backend says about the series, see {@link HistoryChartMetadata}.
109
- **/
110
- metadata: HistoryChartMetadata;
111
- }
112
- /**
113
- * A request for one series of a single opportunity.
114
- *
115
- * @typeParam M - Metric requested.
116
- **/
117
- interface OpportunityHistoryQuery<M extends HistoryMetric = HistoryMetric> {
118
- /**
119
- * Opportunity the series belongs to.
120
- **/
121
- opportunity: OpportunityKey;
122
- /**
123
- * Window to cover.
124
- **/
125
- range: HistoryRange;
126
- /**
127
- * Metric to return. A metric that does not apply to the opportunity's kind
128
- * has no series.
129
- **/
130
- metric: M;
131
- }
132
- /**
133
- * A request for one series of a single position.
134
- *
135
- * @typeParam M - Metric requested.
136
- **/
137
- interface PositionHistoryQuery<M extends PositionHistoryMetric = PositionHistoryMetric> {
138
- /**
139
- * Position the series belongs to.
140
- **/
141
- position: PositionKey;
142
- /**
143
- * Window to cover.
144
- **/
145
- range: HistoryRange;
146
- /**
147
- * Metric to return. A metric that does not apply to the position's kind has
148
- * no series.
149
- **/
150
- metric: M;
151
- }
152
- //#endregion
153
- export { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, OpportunityHistoryQuery, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PoolHistoryMetric, PoolPositionHistoryMetric, PositionHistoryMetric, PositionHistoryQuery, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyPositionHistoryMetric };
@@ -1,95 +0,0 @@
1
- import { HistoryChartMetadata } from "./history.js";
2
- import { z } from "zod/v4";
3
- //#region src/model/history.schema.d.ts
4
- /**
5
- * Runtime schemas for {@link ./history.js}, see the note in
6
- * `primitives.schema.ts` on why they are written by hand.
7
- **/
8
- /**
9
- * {@link HistoryRange}
10
- **/
11
- declare const historyRangeSchema: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;
12
- /**
13
- * {@link PoolHistoryMetric}
14
- **/
15
- declare const poolHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>;
16
- /**
17
- * {@link StrategyHistoryMetric}
18
- **/
19
- declare const strategyHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>;
20
- /**
21
- * {@link PoolPositionHistoryMetric}
22
- **/
23
- declare const poolPositionHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>;
24
- /**
25
- * {@link StrategyPositionHistoryMetric}
26
- **/
27
- declare const strategyPositionHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>;
28
- /**
29
- * {@link PositionHistoryMetric}
30
- **/
31
- declare const positionHistoryMetricSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>;
32
- /**
33
- * {@link HistoryMetric}
34
- **/
35
- declare const historyMetricSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>]>;
36
- /**
37
- * {@link HistoryPoint}
38
- **/
39
- declare const historyPointSchema: z.ZodObject<{
40
- timestamp: z.ZodNumber;
41
- value: z.ZodNumber;
42
- }, z.core.$strip>;
43
- /**
44
- * {@link HistoryChartMetadata}
45
- *
46
- * TODO: empty until the backend specifies the payload.
47
- **/
48
- declare const historyChartMetadataSchema: z.ZodType<HistoryChartMetadata>;
49
- /**
50
- * {@link HistorySeries}
51
- **/
52
- declare const historySeriesSchema: z.ZodObject<{
53
- metric: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>]>;
54
- points: z.ZodArray<z.ZodObject<{
55
- timestamp: z.ZodNumber;
56
- value: z.ZodNumber;
57
- }, z.core.$strip>>;
58
- metadata: z.ZodType<HistoryChartMetadata, unknown, z.core.$ZodTypeInternals<HistoryChartMetadata, unknown>>;
59
- }, z.core.$strip>;
60
- /**
61
- * {@link OpportunityHistoryQuery}
62
- **/
63
- declare const opportunityHistoryQuerySchema: z.ZodObject<{
64
- opportunity: z.ZodDiscriminatedUnion<[z.ZodObject<{
65
- chainId: z.ZodNumber;
66
- pool: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
67
- kind: z.ZodLiteral<"pool">;
68
- }, z.core.$strip>, z.ZodObject<{
69
- chainId: z.ZodNumber;
70
- creditManager: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
71
- targetCollateral: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
72
- kind: z.ZodLiteral<"strategy">;
73
- }, z.core.$strip>], "kind">;
74
- range: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;
75
- metric: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>]>;
76
- }, z.core.$strip>;
77
- /**
78
- * {@link PositionHistoryQuery}
79
- **/
80
- declare const positionHistoryQuerySchema: z.ZodObject<{
81
- position: z.ZodDiscriminatedUnion<[z.ZodObject<{
82
- chainId: z.ZodNumber;
83
- pool: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
84
- wallet: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
85
- kind: z.ZodLiteral<"pool">;
86
- }, z.core.$strip>, z.ZodObject<{
87
- chainId: z.ZodNumber;
88
- creditAccount: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
89
- kind: z.ZodLiteral<"strategy">;
90
- }, z.core.$strip>], "kind">;
91
- range: z.ZodUnion<readonly [z.ZodLiteral<"1d">, z.ZodLiteral<"1w">, z.ZodLiteral<"1m">, z.ZodLiteral<"1y">, z.ZodLiteral<"max">]>;
92
- metric: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"depositApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"dieselRate">, z.ZodLiteral<"supplied">, z.ZodLiteral<"borrowed">, z.ZodLiteral<"availableLiquidity">]>, z.ZodUnion<readonly [z.ZodLiteral<"netApy">, z.ZodLiteral<"borrowApy">, z.ZodLiteral<"collateralApy">, z.ZodLiteral<"tvl">, z.ZodLiteral<"collateralPrice">, z.ZodLiteral<"collateralUsdPrice">, z.ZodLiteral<"underlyingUsdPrice">]>]>;
93
- }, z.core.$strip>;
94
- //#endregion
95
- export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema };
@@ -1,18 +0,0 @@
1
- import { HistoryRange, HistorySeries } from "../../model/history.js";
2
- import { DataResponse } from "../../model/response.js";
3
- import "../../model/index.js";
4
- //#region src/new-sdk/utils/history.d.ts
5
- /**
6
- * Reads the charts of one subject, one metric and one range at a time.
7
- *
8
- * @typeParam Metric - Metrics the subject has.
9
- **/
10
- interface HistoryReader<Metric extends string> {
11
- /**
12
- * Historical chart of one metric over one window. A metric the subject does
13
- * not have is a compile error.
14
- **/
15
- chart(metric: Metric, range: HistoryRange): Promise<DataResponse<HistorySeries<Metric>>>;
16
- }
17
- //#endregion
18
- export { HistoryReader };
@@ -1,96 +0,0 @@
1
- import { MultiCall } from "../../../types/transactions.js";
2
- import { OnchainSDK } from "../../../OnchainSDK.js";
3
- import "../../../index.js";
4
- import { Address } from "viem";
5
- //#region src/sdk/accounts/intents/testing/sdk-mock.d.ts
6
- /**
7
- * Test kit for intent-service specs.
8
- *
9
- * The service resolves all market data through `OnchainSDK`
10
- * (`marketRegister`, `tokensMeta`, `accounts`). `buildMockSdk` builds a mock
11
- * from plain records; assemble mocks ECHO recognizable sentinel calls derived
12
- * from their inputs, so `result.instant.calls` pins down which ops reached the
13
- * assembler and in which order.
14
- */
15
- /** Fixture `claimableWithdrawal.claimCalls` content; echoes through claim ops. */
16
- declare const MOCK_CLAIM_CALL: MultiCall;
17
- /** Recognizable router call embedded in close path results. */
18
- declare const MOCK_ROUTER_CALL: MultiCall;
19
- /** Returned by the `getRWAWrapCalls` mock; passes through per wrap op. */
20
- declare const MOCK_RWA_WRAP_CALL: MultiCall;
21
- /** Router-produced call for an RWA underlying → asset unwrap leg. */
22
- declare const MOCK_RWA_UNWRAP_CALL: MultiCall;
23
- /** Returned by the `assembleCloseCreditAccountCalls` mock. */
24
- declare const MOCK_CLOSE_CALL: MultiCall;
25
- /** One sentinel call per plain encodable op type. */
26
- declare const CA_OP_CALLS: {
27
- readonly addCollateral: {
28
- readonly target: Address;
29
- readonly callData: "0x";
30
- };
31
- readonly increaseDebt: {
32
- readonly target: Address;
33
- readonly callData: "0x";
34
- };
35
- readonly decreaseDebt: {
36
- readonly target: Address;
37
- readonly callData: "0x";
38
- };
39
- readonly withdrawCollateral: {
40
- readonly target: Address;
41
- readonly callData: "0x";
42
- };
43
- readonly changeQuota: {
44
- readonly target: Address;
45
- readonly callData: "0x";
46
- };
47
- };
48
- interface MockQuotaEntry {
49
- token: Address;
50
- rate: bigint;
51
- limit: bigint;
52
- totalQuoted?: bigint;
53
- quotaIncreaseFee?: bigint;
54
- isActive: boolean;
55
- }
56
- interface BuildMockSdkArgs {
57
- /** Price per token (PRICE_DECIMALS_POW-scaled), like legacy `prices`. */
58
- prices: Record<Address, bigint>;
59
- /** Token decimals; used by `tokensMeta` and the price conversion. */
60
- decimals: Record<Address, number>;
61
- /** Pool quota params (AddressMap values shape). */
62
- quotas: Record<Address, MockQuotaEntry>;
63
- liquidationThresholds: Record<Address, number>;
64
- maxDebt: bigint;
65
- /** Facade `minDebt`; defaults to 0n so debt-range checks stay opt-in. */
66
- minDebt?: bigint;
67
- /** Pool base rate in ray; feeds `calcBorrowApy` of position metrics. */
68
- baseInterestRate?: bigint;
69
- /** Credit manager interest fee in Bps; feeds position metrics. */
70
- feeInterest?: number;
71
- creditManager: Address;
72
- creditFacade: Address;
73
- /** Market underlying token (`market.pool.underlying`). */
74
- underlying: Address;
75
- /**
76
- * Close resume: router `findBestClosePath` result. When set, the mock
77
- * provides `routerFor` and `assembleCloseCreditAccountCalls`.
78
- */
79
- closePath?: {
80
- amount: bigint;
81
- minAmount: bigint;
82
- underlyingBalance: bigint;
83
- calls: MultiCall[];
84
- };
85
- /** RWA markets: underlying → rwa.asset (`tokensMeta.rwaUnderlyings`). */
86
- rwaAssets?: Record<Address, Address>;
87
- }
88
- /**
89
- * Mock `OnchainSDK` covering exactly what the intent-service touches:
90
- * price conversion, quota params, CM/facade lookup and call assembly.
91
- * Conversion mirrors the legacy price-based math:
92
- * `amount * price[from] * 10^dec(to) / (price[to] * 10^dec(from))`.
93
- */
94
- declare function buildMockSdk(args: BuildMockSdkArgs): OnchainSDK;
95
- //#endregion
96
- export { CA_OP_CALLS, MOCK_CLAIM_CALL, MOCK_CLOSE_CALL, MOCK_ROUTER_CALL, MOCK_RWA_UNWRAP_CALL, MOCK_RWA_WRAP_CALL, MockQuotaEntry, buildMockSdk };