@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,9 +1,13 @@
1
- import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, StrategyOpportunityDetail, StrategyOpportunityKey } from "../../model/opportunities.js";
2
- import { HistoryMetric, HistorySeries, OpportunityHistoryQuery } from "../../model/history.js";
1
+ import { ChartBundle, ChartRange, PoolOpportunityChartMetric, StrategyOpportunityChartMetric } from "../../model/charts.js";
2
+ import { Opportunity, OpportunityFilter, OpportunityKey, PoolOpportunityDetail, PoolOpportunityKey, StrategyOpportunityDetail, StrategyOpportunityKey } from "../../model/opportunities.js";
3
3
  import { DataResponse } from "../../model/response.js";
4
4
  import { GearboxAPIOptions } from "../types.js";
5
5
  import { AbstractOffchainNamespace } from "../AbstractOffchainNamespace.js";
6
6
  //#region src/offchain/opportunities/OffchainOpportunities.d.ts
7
+ type OpportunityChartMetricFor<K extends OpportunityKey> = {
8
+ pool: PoolOpportunityChartMetric;
9
+ strategy: StrategyOpportunityChartMetric;
10
+ }[K["kind"]];
7
11
  /**
8
12
  * Backend counterpart of the `opportunities` namespace.
9
13
  **/
@@ -24,9 +28,9 @@ declare class OffchainOpportunities extends AbstractOffchainNamespace {
24
28
  **/
25
29
  getStrategy(key: StrategyOpportunityKey): Promise<DataResponse<StrategyOpportunityDetail>>;
26
30
  /**
27
- * One historical series of one opportunity
31
+ * Charts of one opportunity: one series per metric, on a shared grid.
28
32
  **/
29
- getHistory<M extends HistoryMetric>(query: OpportunityHistoryQuery<M>): Promise<DataResponse<HistorySeries<M>>>;
33
+ getCharts<K extends OpportunityKey, const Metrics extends readonly OpportunityChartMetricFor<K>[]>(key: K, metrics: Metrics, range: ChartRange): Promise<DataResponse<ChartBundle<Metrics>>>;
30
34
  }
31
35
  //#endregion
32
36
  export { OffchainOpportunities };
@@ -1,10 +1,14 @@
1
- import { Position } from "../../model/positions.js";
2
- import { HistorySeries, PositionHistoryMetric, PositionHistoryQuery } from "../../model/history.js";
1
+ import { ChartBundle, ChartRange, PoolPositionChartMetric, StrategyPositionChartMetric } from "../../model/charts.js";
2
+ import { Position, PositionKey } from "../../model/positions.js";
3
3
  import { DataResponse } from "../../model/response.js";
4
4
  import { ListPositionsPropsBase } from "../../sdk/positions/types.js";
5
5
  import { GearboxAPIOptions } from "../types.js";
6
6
  import { AbstractOffchainNamespace } from "../AbstractOffchainNamespace.js";
7
7
  //#region src/offchain/positions/OffchainPositions.d.ts
8
+ type PositionChartMetricFor<K extends PositionKey> = {
9
+ pool: PoolPositionChartMetric;
10
+ strategy: StrategyPositionChartMetric;
11
+ }[K["kind"]];
8
12
  /**
9
13
  * Backend counterpart of the `positions` namespace.
10
14
  **/
@@ -16,11 +20,13 @@ declare class OffchainPositions extends AbstractOffchainNamespace {
16
20
  **/
17
21
  list(props: ListPositionsPropsBase): Promise<DataResponse<Position[]>>;
18
22
  /**
19
- * One historical series of one position.
23
+ * Charts of one position: one series per metric, on a shared grid.
20
24
  *
21
- * @returns An empty series until the backend client is implemented.
25
+ * @throws {OffchainNotImplementedError} Until the backend serves it. An empty
26
+ * bundle would be the one answer this model exists to rule out: a chart that
27
+ * could not be read is not a chart with no points.
22
28
  **/
23
- getHistory<M extends PositionHistoryMetric>(query: PositionHistoryQuery<M>): Promise<DataResponse<HistorySeries<M>>>;
29
+ getCharts<K extends PositionKey, const Metrics extends readonly PositionChartMetricFor<K>[]>(key: K, _metrics: Metrics, _range: ChartRange): Promise<DataResponse<ChartBundle<Metrics>>>;
24
30
  }
25
31
  //#endregion
26
32
  export { OffchainPositions };
@@ -49,4 +49,4 @@ declare function assetBalance(assets: Array<{
49
49
  balance: bigint;
50
50
  }>, token: Address): bigint;
51
51
  //#endregion
52
- export { ExpectedFlowOp, assetBalance, expectAdjustResumePreview, expectCallsArrayExact, expectOpsArrayExact, withOnchainOpCalls };
52
+ export { ExpectedFlowOp };
@@ -81,4 +81,4 @@ declare function buildClaimResumeProps<T extends DelayedIntent>(args: {
81
81
  slippage: undefined;
82
82
  };
83
83
  //#endregion
84
- export { ANY, ANY2, CREDIT_ACCOUNT, CREDIT_FACADE, CREDIT_MANAGER, RESUME_FIXTURE_PHANTOM, RWA_ASSET, ResumeCase, TOK_DECIMALS, UND, UND_DECIMALS, buildClaimResumeProps, buildOffchainOptions, buildOnchainOptions, buildResumeSdk, claimedValueInUnd };
84
+ export { ANY, CREDIT_ACCOUNT, RWA_ASSET, ResumeCase, UND, buildOffchainOptions, buildOnchainOptions, buildResumeSdk };
@@ -3,12 +3,13 @@ import "../../model/index.js";
3
3
  //#region src/sdk/positions/calcTimeToLiquidationMs.d.ts
4
4
  /**
5
5
  * Estimated milliseconds until `healthFactorBps` decays to `10000` (1.0)
6
- * while the debt grows at `totalBorrowRateOnDebt` (basis points relative to
7
- * the debt, as {@link BorrowRateBreakdown.totalOnDebt} reports it).
6
+ * while the debt grows at `totalBorrowRateOnDebt`, in the same `Bps` scale
7
+ * (`10000` = 100%) as {@link BorrowRateBreakdown.totalOnDebt} reports it —
8
+ * not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` = 100%) scale the
9
+ * pre-rewrite frontend fed into its own `getTimeToLiquidation`.
8
10
  *
9
11
  * `null` when the account is already at or under the liquidation threshold,
10
- * or when the debt carries no borrow rate at all. Formula is in parity with
11
- * the legacy `getTimeToLiquidation`.
12
+ * or when the debt carries no borrow rate at all.
12
13
  **/
13
14
  declare function calcTimeToLiquidationMs(healthFactorBps: Bps, totalBorrowRateOnDebt: bigint): bigint | null;
14
15
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "15.1.0-next.7",
3
+ "version": "15.1.0-next.9",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,53 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/model/history.ts
3
- /**
4
- * Every {@link PoolHistoryMetric}, for callers that enumerate them.
5
- **/
6
- const POOL_HISTORY_METRICS = [
7
- "depositApy",
8
- "borrowApy",
9
- "dieselRate",
10
- "supplied",
11
- "borrowed",
12
- "availableLiquidity"
13
- ];
14
- /**
15
- * Every {@link StrategyHistoryMetric}, for callers that enumerate them.
16
- **/
17
- const STRATEGY_HISTORY_METRICS = [
18
- "netApy",
19
- "borrowApy",
20
- "collateralApy",
21
- "tvl",
22
- "collateralPrice",
23
- "collateralUsdPrice",
24
- "underlyingUsdPrice"
25
- ];
26
- /**
27
- * Every {@link PoolPositionHistoryMetric}, for callers that enumerate them.
28
- **/
29
- const POOL_POSITION_HISTORY_METRICS = [
30
- "depositApy",
31
- "borrowApy",
32
- "dieselRate",
33
- "supplied",
34
- "borrowed",
35
- "availableLiquidity"
36
- ];
37
- /**
38
- * Every {@link StrategyPositionHistoryMetric}, for callers that enumerate them.
39
- **/
40
- const STRATEGY_POSITION_HISTORY_METRICS = [
41
- "netApy",
42
- "borrowApy",
43
- "collateralApy",
44
- "tvl",
45
- "collateralPrice",
46
- "collateralUsdPrice",
47
- "underlyingUsdPrice"
48
- ];
49
- //#endregion
50
- exports.POOL_HISTORY_METRICS = POOL_HISTORY_METRICS;
51
- exports.POOL_POSITION_HISTORY_METRICS = POOL_POSITION_HISTORY_METRICS;
52
- exports.STRATEGY_HISTORY_METRICS = STRATEGY_HISTORY_METRICS;
53
- exports.STRATEGY_POSITION_HISTORY_METRICS = STRATEGY_POSITION_HISTORY_METRICS;
@@ -1,128 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_model_primitives_schema = require("./primitives.schema.js");
3
- const require_model_opportunities_schema = require("./opportunities.schema.js");
4
- const require_model_positions_schema = require("./positions.schema.js");
5
- let zod_v4 = require("zod/v4");
6
- //#region src/model/history.schema.ts
7
- /**
8
- * Runtime schemas for {@link ./history.js}, see the note in
9
- * `primitives.schema.ts` on why they are written by hand.
10
- **/
11
- /**
12
- * {@link HistoryRange}
13
- **/
14
- const historyRangeSchema = zod_v4.z.union([
15
- zod_v4.z.literal("1d"),
16
- zod_v4.z.literal("1w"),
17
- zod_v4.z.literal("1m"),
18
- zod_v4.z.literal("1y"),
19
- zod_v4.z.literal("max")
20
- ]);
21
- /**
22
- * {@link PoolHistoryMetric}
23
- **/
24
- const poolHistoryMetricSchema = zod_v4.z.union([
25
- zod_v4.z.literal("depositApy"),
26
- zod_v4.z.literal("borrowApy"),
27
- zod_v4.z.literal("dieselRate"),
28
- zod_v4.z.literal("supplied"),
29
- zod_v4.z.literal("borrowed"),
30
- zod_v4.z.literal("availableLiquidity")
31
- ]);
32
- /**
33
- * {@link StrategyHistoryMetric}
34
- **/
35
- const strategyHistoryMetricSchema = zod_v4.z.union([
36
- zod_v4.z.literal("netApy"),
37
- zod_v4.z.literal("borrowApy"),
38
- zod_v4.z.literal("collateralApy"),
39
- zod_v4.z.literal("tvl"),
40
- zod_v4.z.literal("collateralPrice"),
41
- zod_v4.z.literal("collateralUsdPrice"),
42
- zod_v4.z.literal("underlyingUsdPrice")
43
- ]);
44
- /**
45
- * {@link PoolPositionHistoryMetric}
46
- **/
47
- const poolPositionHistoryMetricSchema = zod_v4.z.union([
48
- zod_v4.z.literal("depositApy"),
49
- zod_v4.z.literal("borrowApy"),
50
- zod_v4.z.literal("dieselRate"),
51
- zod_v4.z.literal("supplied"),
52
- zod_v4.z.literal("borrowed"),
53
- zod_v4.z.literal("availableLiquidity")
54
- ]);
55
- /**
56
- * {@link StrategyPositionHistoryMetric}
57
- **/
58
- const strategyPositionHistoryMetricSchema = zod_v4.z.union([
59
- zod_v4.z.literal("netApy"),
60
- zod_v4.z.literal("borrowApy"),
61
- zod_v4.z.literal("collateralApy"),
62
- zod_v4.z.literal("tvl"),
63
- zod_v4.z.literal("collateralPrice"),
64
- zod_v4.z.literal("collateralUsdPrice"),
65
- zod_v4.z.literal("underlyingUsdPrice")
66
- ]);
67
- /**
68
- * {@link PositionHistoryMetric}
69
- **/
70
- const positionHistoryMetricSchema = zod_v4.z.union([poolPositionHistoryMetricSchema, strategyPositionHistoryMetricSchema]);
71
- /**
72
- * {@link HistoryMetric}
73
- **/
74
- const historyMetricSchema = zod_v4.z.union([
75
- poolHistoryMetricSchema,
76
- strategyHistoryMetricSchema,
77
- positionHistoryMetricSchema
78
- ]);
79
- /**
80
- * {@link HistoryPoint}
81
- **/
82
- const historyPointSchema = zod_v4.z.object({
83
- timestamp: require_model_primitives_schema.timestampSchema,
84
- value: zod_v4.z.number()
85
- });
86
- /**
87
- * {@link HistoryChartMetadata}
88
- *
89
- * TODO: empty until the backend specifies the payload.
90
- **/
91
- const historyChartMetadataSchema = zod_v4.z.object({});
92
- /**
93
- * {@link HistorySeries}
94
- **/
95
- const historySeriesSchema = zod_v4.z.object({
96
- metric: historyMetricSchema,
97
- points: zod_v4.z.array(historyPointSchema),
98
- metadata: historyChartMetadataSchema
99
- });
100
- /**
101
- * {@link OpportunityHistoryQuery}
102
- **/
103
- const opportunityHistoryQuerySchema = zod_v4.z.object({
104
- opportunity: require_model_opportunities_schema.opportunityKeySchema,
105
- range: historyRangeSchema,
106
- metric: historyMetricSchema
107
- });
108
- /**
109
- * {@link PositionHistoryQuery}
110
- **/
111
- const positionHistoryQuerySchema = zod_v4.z.object({
112
- position: require_model_positions_schema.positionKeySchema,
113
- range: historyRangeSchema,
114
- metric: positionHistoryMetricSchema
115
- });
116
- //#endregion
117
- exports.historyChartMetadataSchema = historyChartMetadataSchema;
118
- exports.historyMetricSchema = historyMetricSchema;
119
- exports.historyPointSchema = historyPointSchema;
120
- exports.historyRangeSchema = historyRangeSchema;
121
- exports.historySeriesSchema = historySeriesSchema;
122
- exports.opportunityHistoryQuerySchema = opportunityHistoryQuerySchema;
123
- exports.poolHistoryMetricSchema = poolHistoryMetricSchema;
124
- exports.poolPositionHistoryMetricSchema = poolPositionHistoryMetricSchema;
125
- exports.positionHistoryMetricSchema = positionHistoryMetricSchema;
126
- exports.positionHistoryQuerySchema = positionHistoryQuerySchema;
127
- exports.strategyHistoryMetricSchema = strategyHistoryMetricSchema;
128
- exports.strategyPositionHistoryMetricSchema = strategyPositionHistoryMetricSchema;
@@ -1 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -1,167 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk_accounts_intents_testing_sdk_mock = require("./sdk-mock.js");
3
- let vitest = require("vitest");
4
- //#region src/sdk/accounts/intents/testing/expect.ts
5
- function expectedCalls(expected) {
6
- return expected.calls ?? [];
7
- }
8
- /**
9
- * Fills sentinel `calls` for onchain resume expectations. Shared fixtures keep
10
- * `calls: []` for offchain; onchain tests map through this helper.
11
- */
12
- function withOnchainOpCalls(ops) {
13
- return ops.map((op) => {
14
- switch (op.type) {
15
- case "claimDelayedWithdrawal": return {
16
- ...op,
17
- calls: [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLAIM_CALL]
18
- };
19
- case "changeQuota": return {
20
- ...op,
21
- calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.changeQuota]
22
- };
23
- case "decreaseDebt": return {
24
- ...op,
25
- calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.decreaseDebt]
26
- };
27
- case "withdrawCollateral": return {
28
- ...op,
29
- calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.withdrawCollateral]
30
- };
31
- case "swap": return {
32
- ...op,
33
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_ROUTER_CALL]
34
- };
35
- case "wrapRwaCollateral": return {
36
- ...op,
37
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_RWA_WRAP_CALL]
38
- };
39
- case "unwrapRwaCollateral": return {
40
- ...op,
41
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_RWA_UNWRAP_CALL]
42
- };
43
- case "closeCreditAccount": return {
44
- ...op,
45
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLOSE_CALL]
46
- };
47
- default: return op;
48
- }
49
- });
50
- }
51
- function matchOp(actual, expected, index) {
52
- (0, vitest.expect)(actual.type, `op[${index}].type`).toBe(expected.type);
53
- switch (expected.type) {
54
- case "claimDelayedWithdrawal":
55
- if (actual.type !== "claimDelayedWithdrawal") return;
56
- (0, vitest.expect)(actual.token, `op[${index}].token`).toBe(expected.token);
57
- (0, vitest.expect)(actual.withdrawalPhantomToken, `op[${index}].withdrawalPhantomToken`).toBe(expected.withdrawalPhantomToken);
58
- (0, vitest.expect)(actual.withdrawalTokenSpent, `op[${index}].withdrawalTokenSpent`).toBe(expected.withdrawalTokenSpent);
59
- (0, vitest.expect)(actual.outputs, `op[${index}].outputs`).toEqual(expected.outputs);
60
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
61
- break;
62
- case "changeQuota":
63
- if (actual.type !== "changeQuota") return;
64
- (0, vitest.expect)(actual.quotaIncrease, `op[${index}].quotaIncrease`).toEqual(expected.quotaIncrease);
65
- (0, vitest.expect)(actual.quotaDecrease, `op[${index}].quotaDecrease`).toEqual(expected.quotaDecrease);
66
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
67
- break;
68
- case "closeCreditAccount":
69
- if (actual.type !== "closeCreditAccount") return;
70
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
71
- (0, vitest.expect)(actual.minAmount, `op[${index}].minAmount`).toBe(expected.minAmount);
72
- (0, vitest.expect)(actual.underlyingBalance, `op[${index}].underlyingBalance`).toBe(expected.underlyingBalance);
73
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
74
- break;
75
- case "swap":
76
- if (actual.type !== "swap") return;
77
- (0, vitest.expect)(actual.from, `op[${index}].from`).toEqual(expected.from);
78
- (0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
79
- (0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
80
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
81
- break;
82
- case "decreaseDebt":
83
- if (actual.type !== "decreaseDebt") return;
84
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
85
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
86
- break;
87
- case "withdrawCollateral":
88
- if (actual.type !== "withdrawCollateral") return;
89
- (0, vitest.expect)(actual.token, `op[${index}].token`).toBe(expected.token);
90
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
91
- (0, vitest.expect)(actual.to, `op[${index}].to`).toBe(expected.to);
92
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
93
- break;
94
- case "unwrapRwaCollateral":
95
- if (actual.type !== "unwrapRwaCollateral") return;
96
- (0, vitest.expect)(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
97
- (0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
98
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
99
- (0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
100
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
101
- break;
102
- case "wrapRwaCollateral":
103
- if (actual.type !== "wrapRwaCollateral") return;
104
- (0, vitest.expect)(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
105
- (0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
106
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
107
- (0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
108
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
109
- }
110
- }
111
- /** Asserts exact operations on a raw op array (type + tokens + amounts). */
112
- function expectOpsArrayExact(ops, expected) {
113
- (0, vitest.expect)(ops.length, "operations.length").toBe(expected.length);
114
- for (let i = 0; i < expected.length; i++) {
115
- const actual = ops[i];
116
- const exp = expected[i];
117
- if (actual === void 0 || exp === void 0) {
118
- vitest.expect.fail(`missing op at index ${i}`);
119
- return;
120
- }
121
- matchOp(actual, exp, i);
122
- }
123
- }
124
- /** Asserts exact calls on a raw MultiCall array (target + callData). */
125
- function expectCallsArrayExact(calls, expected, label = "calls") {
126
- (0, vitest.expect)(calls.length, `${label}.length`).toBe(expected.length);
127
- for (let i = 0; i < expected.length; i++) {
128
- const actual = calls[i];
129
- const exp = expected[i];
130
- if (actual === void 0 || exp === void 0) {
131
- vitest.expect.fail(`missing call at index ${i}`);
132
- return;
133
- }
134
- (0, vitest.expect)(actual.target, `${label}[${i}].target`).toBe(exp.target);
135
- (0, vitest.expect)(actual.callData, `${label}[${i}].callData`).toBe(exp.callData);
136
- }
137
- }
138
- /**
139
- * Asserts a successful adjust-style resume preview: ok, instant branch present,
140
- * exact calls (empty unless `expectedCalls` is provided), metrics from the
141
- * post-claim CA, and exact operations (incl. changeQuota).
142
- * Returns the adjust preview state for further asset/quota assertions.
143
- */
144
- function expectAdjustResumePreview(result, args) {
145
- (0, vitest.expect)(result.ok).toBe(true);
146
- if (!result.ok) throw new Error("expected ok resume preview");
147
- (0, vitest.expect)(result.instant, "instant branch").toBeDefined();
148
- if (!result.instant) throw new Error("expected instant branch");
149
- if (args.expectedCalls) expectCallsArrayExact(result.instant.calls, args.expectedCalls);
150
- else (0, vitest.expect)(result.instant.calls).toEqual([]);
151
- const state = result.instant.preview.min;
152
- (0, vitest.expect)(state.kind).toBe("adjust");
153
- if (state.kind !== "adjust") throw new Error("expected adjust preview state");
154
- (0, vitest.expect)(state.totalValue).toBe(args.totalValue);
155
- (0, vitest.expect)(state.accountDebt).toBe(args.accountDebt);
156
- expectOpsArrayExact(result.instant.operations, args.expectedOps);
157
- return state;
158
- }
159
- function assetBalance(assets, token) {
160
- return assets.find((a) => a.token === token)?.balance ?? 0n;
161
- }
162
- //#endregion
163
- exports.assetBalance = assetBalance;
164
- exports.expectAdjustResumePreview = expectAdjustResumePreview;
165
- exports.expectCallsArrayExact = expectCallsArrayExact;
166
- exports.expectOpsArrayExact = expectOpsArrayExact;
167
- exports.withOnchainOpCalls = withOnchainOpCalls;
@@ -1,49 +0,0 @@
1
- //#region src/model/history.ts
2
- /**
3
- * Every {@link PoolHistoryMetric}, for callers that enumerate them.
4
- **/
5
- const POOL_HISTORY_METRICS = [
6
- "depositApy",
7
- "borrowApy",
8
- "dieselRate",
9
- "supplied",
10
- "borrowed",
11
- "availableLiquidity"
12
- ];
13
- /**
14
- * Every {@link StrategyHistoryMetric}, for callers that enumerate them.
15
- **/
16
- const STRATEGY_HISTORY_METRICS = [
17
- "netApy",
18
- "borrowApy",
19
- "collateralApy",
20
- "tvl",
21
- "collateralPrice",
22
- "collateralUsdPrice",
23
- "underlyingUsdPrice"
24
- ];
25
- /**
26
- * Every {@link PoolPositionHistoryMetric}, for callers that enumerate them.
27
- **/
28
- const POOL_POSITION_HISTORY_METRICS = [
29
- "depositApy",
30
- "borrowApy",
31
- "dieselRate",
32
- "supplied",
33
- "borrowed",
34
- "availableLiquidity"
35
- ];
36
- /**
37
- * Every {@link StrategyPositionHistoryMetric}, for callers that enumerate them.
38
- **/
39
- const STRATEGY_POSITION_HISTORY_METRICS = [
40
- "netApy",
41
- "borrowApy",
42
- "collateralApy",
43
- "tvl",
44
- "collateralPrice",
45
- "collateralUsdPrice",
46
- "underlyingUsdPrice"
47
- ];
48
- //#endregion
49
- export { POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS };
@@ -1,116 +0,0 @@
1
- import { timestampSchema } from "./primitives.schema.js";
2
- import { opportunityKeySchema } from "./opportunities.schema.js";
3
- import { positionKeySchema } from "./positions.schema.js";
4
- import { z } from "zod/v4";
5
- //#region src/model/history.schema.ts
6
- /**
7
- * Runtime schemas for {@link ./history.js}, see the note in
8
- * `primitives.schema.ts` on why they are written by hand.
9
- **/
10
- /**
11
- * {@link HistoryRange}
12
- **/
13
- const historyRangeSchema = z.union([
14
- z.literal("1d"),
15
- z.literal("1w"),
16
- z.literal("1m"),
17
- z.literal("1y"),
18
- z.literal("max")
19
- ]);
20
- /**
21
- * {@link PoolHistoryMetric}
22
- **/
23
- const poolHistoryMetricSchema = z.union([
24
- z.literal("depositApy"),
25
- z.literal("borrowApy"),
26
- z.literal("dieselRate"),
27
- z.literal("supplied"),
28
- z.literal("borrowed"),
29
- z.literal("availableLiquidity")
30
- ]);
31
- /**
32
- * {@link StrategyHistoryMetric}
33
- **/
34
- const strategyHistoryMetricSchema = z.union([
35
- z.literal("netApy"),
36
- z.literal("borrowApy"),
37
- z.literal("collateralApy"),
38
- z.literal("tvl"),
39
- z.literal("collateralPrice"),
40
- z.literal("collateralUsdPrice"),
41
- z.literal("underlyingUsdPrice")
42
- ]);
43
- /**
44
- * {@link PoolPositionHistoryMetric}
45
- **/
46
- const poolPositionHistoryMetricSchema = z.union([
47
- z.literal("depositApy"),
48
- z.literal("borrowApy"),
49
- z.literal("dieselRate"),
50
- z.literal("supplied"),
51
- z.literal("borrowed"),
52
- z.literal("availableLiquidity")
53
- ]);
54
- /**
55
- * {@link StrategyPositionHistoryMetric}
56
- **/
57
- const strategyPositionHistoryMetricSchema = z.union([
58
- z.literal("netApy"),
59
- z.literal("borrowApy"),
60
- z.literal("collateralApy"),
61
- z.literal("tvl"),
62
- z.literal("collateralPrice"),
63
- z.literal("collateralUsdPrice"),
64
- z.literal("underlyingUsdPrice")
65
- ]);
66
- /**
67
- * {@link PositionHistoryMetric}
68
- **/
69
- const positionHistoryMetricSchema = z.union([poolPositionHistoryMetricSchema, strategyPositionHistoryMetricSchema]);
70
- /**
71
- * {@link HistoryMetric}
72
- **/
73
- const historyMetricSchema = z.union([
74
- poolHistoryMetricSchema,
75
- strategyHistoryMetricSchema,
76
- positionHistoryMetricSchema
77
- ]);
78
- /**
79
- * {@link HistoryPoint}
80
- **/
81
- const historyPointSchema = z.object({
82
- timestamp: timestampSchema,
83
- value: z.number()
84
- });
85
- /**
86
- * {@link HistoryChartMetadata}
87
- *
88
- * TODO: empty until the backend specifies the payload.
89
- **/
90
- const historyChartMetadataSchema = z.object({});
91
- /**
92
- * {@link HistorySeries}
93
- **/
94
- const historySeriesSchema = z.object({
95
- metric: historyMetricSchema,
96
- points: z.array(historyPointSchema),
97
- metadata: historyChartMetadataSchema
98
- });
99
- /**
100
- * {@link OpportunityHistoryQuery}
101
- **/
102
- const opportunityHistoryQuerySchema = z.object({
103
- opportunity: opportunityKeySchema,
104
- range: historyRangeSchema,
105
- metric: historyMetricSchema
106
- });
107
- /**
108
- * {@link PositionHistoryQuery}
109
- **/
110
- const positionHistoryQuerySchema = z.object({
111
- position: positionKeySchema,
112
- range: historyRangeSchema,
113
- metric: positionHistoryMetricSchema
114
- });
115
- //#endregion
116
- export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema };
@@ -1 +0,0 @@
1
- export {};