@gearbox-protocol/sdk 14.12.0-next.71 → 14.12.0-next.72

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 (130) hide show
  1. package/dist/cjs/model/history.js +25 -0
  2. package/dist/cjs/model/history.schema.js +45 -1
  3. package/dist/cjs/model/index.js +17 -3
  4. package/dist/cjs/model/positions.js +89 -0
  5. package/dist/cjs/model/positions.schema.js +28 -0
  6. package/dist/cjs/new-sdk/GearboxSDK.js +7 -0
  7. package/dist/cjs/new-sdk/index.js +3 -0
  8. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +119 -0
  9. package/dist/cjs/new-sdk/positions/index.js +4 -0
  10. package/dist/cjs/new-sdk/positions/types.js +1 -0
  11. package/dist/cjs/offchain/GearboxAPI.js +9 -2
  12. package/dist/cjs/offchain/index.js +5 -2
  13. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +3 -14
  14. package/dist/cjs/offchain/opportunities/index.js +0 -1
  15. package/dist/cjs/offchain/positions/OffchainPositions.js +69 -0
  16. package/dist/cjs/offchain/positions/index.js +3 -0
  17. package/dist/cjs/offchain/types.js +17 -0
  18. package/dist/cjs/sdk/MultichainSDK.js +7 -0
  19. package/dist/cjs/sdk/OnchainSDK.js +7 -0
  20. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +84 -0
  21. package/dist/cjs/sdk/accounts/constants.js +12 -0
  22. package/dist/cjs/sdk/accounts/dominantCollateral.js +33 -0
  23. package/dist/cjs/sdk/accounts/index.js +4 -1
  24. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +3 -10
  25. package/dist/cjs/sdk/accounts/liquidations/constants.js +2 -6
  26. package/dist/cjs/sdk/accounts/liquidations/index.js +2 -1
  27. package/dist/cjs/sdk/index.js +11 -1
  28. package/dist/cjs/sdk/market/MarketSuite.js +7 -1
  29. package/dist/cjs/sdk/market/credit/CreditSuite.js +10 -1
  30. package/dist/cjs/sdk/market/math.js +37 -0
  31. package/dist/cjs/sdk/opportunities/index.js +2 -0
  32. package/dist/cjs/sdk/pools/PoolService.js +37 -0
  33. package/dist/cjs/sdk/positions/MultichainPositionsService.js +48 -0
  34. package/dist/cjs/sdk/positions/PositionsService.js +39 -0
  35. package/dist/cjs/sdk/positions/index.js +6 -0
  36. package/dist/cjs/sdk/positions/types.js +1 -0
  37. package/dist/esm/model/history.js +24 -1
  38. package/dist/esm/model/history.schema.js +42 -2
  39. package/dist/esm/model/index.js +6 -6
  40. package/dist/esm/model/positions.js +85 -1
  41. package/dist/esm/model/positions.schema.js +26 -1
  42. package/dist/esm/new-sdk/GearboxSDK.js +7 -0
  43. package/dist/esm/new-sdk/index.js +3 -1
  44. package/dist/esm/new-sdk/positions/PositionsNamespace.js +118 -0
  45. package/dist/esm/new-sdk/positions/index.js +3 -0
  46. package/dist/esm/new-sdk/positions/types.js +1 -0
  47. package/dist/esm/offchain/GearboxAPI.js +9 -2
  48. package/dist/esm/offchain/index.js +5 -3
  49. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +2 -12
  50. package/dist/esm/offchain/opportunities/index.js +2 -2
  51. package/dist/esm/offchain/positions/OffchainPositions.js +68 -0
  52. package/dist/esm/offchain/positions/index.js +2 -0
  53. package/dist/esm/offchain/types.js +17 -1
  54. package/dist/esm/sdk/MultichainSDK.js +7 -0
  55. package/dist/esm/sdk/OnchainSDK.js +7 -0
  56. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +84 -0
  57. package/dist/esm/sdk/accounts/constants.js +11 -0
  58. package/dist/esm/sdk/accounts/dominantCollateral.js +32 -0
  59. package/dist/esm/sdk/accounts/index.js +4 -2
  60. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +3 -10
  61. package/dist/esm/sdk/accounts/liquidations/constants.js +1 -5
  62. package/dist/esm/sdk/accounts/liquidations/index.js +2 -1
  63. package/dist/esm/sdk/index.js +8 -3
  64. package/dist/esm/sdk/market/MarketSuite.js +7 -1
  65. package/dist/esm/sdk/market/credit/CreditSuite.js +10 -1
  66. package/dist/esm/sdk/market/math.js +37 -2
  67. package/dist/esm/sdk/opportunities/index.js +2 -2
  68. package/dist/esm/sdk/pools/PoolService.js +37 -0
  69. package/dist/esm/sdk/positions/MultichainPositionsService.js +47 -0
  70. package/dist/esm/sdk/positions/PositionsService.js +38 -0
  71. package/dist/esm/sdk/positions/index.js +4 -0
  72. package/dist/esm/sdk/positions/types.js +1 -0
  73. package/dist/types/model/history.d.ts +50 -2
  74. package/dist/types/model/history.schema.d.ts +32 -3
  75. package/dist/types/model/index.d.ts +5 -5
  76. package/dist/types/model/positions.d.ts +100 -1
  77. package/dist/types/model/positions.schema.d.ts +29 -1
  78. package/dist/types/new-sdk/AbstractNamespace.d.ts +2 -2
  79. package/dist/types/new-sdk/GearboxSDK.d.ts +6 -0
  80. package/dist/types/new-sdk/index.d.ts +4 -1
  81. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +1 -1
  82. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +62 -0
  83. package/dist/types/new-sdk/positions/index.d.ts +3 -0
  84. package/dist/types/new-sdk/positions/types.d.ts +62 -0
  85. package/dist/types/new-sdk/utils/history.d.ts +6 -2
  86. package/dist/types/offchain/GearboxAPI.d.ts +8 -2
  87. package/dist/types/offchain/index.d.ts +5 -3
  88. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -9
  89. package/dist/types/offchain/opportunities/index.d.ts +2 -2
  90. package/dist/types/offchain/positions/OffchainPositions.d.ts +47 -0
  91. package/dist/types/offchain/positions/index.d.ts +2 -0
  92. package/dist/types/offchain/types.d.ts +12 -1
  93. package/dist/types/sdk/MultichainSDK.d.ts +6 -0
  94. package/dist/types/sdk/OnchainSDK.d.ts +6 -0
  95. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +7 -1
  96. package/dist/types/sdk/accounts/constants.d.ts +11 -0
  97. package/dist/types/sdk/accounts/dominantCollateral.d.ts +22 -0
  98. package/dist/types/sdk/accounts/index.d.ts +5 -3
  99. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +2 -2
  100. package/dist/types/sdk/accounts/liquidations/constants.d.ts +1 -5
  101. package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -1
  102. package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
  103. package/dist/types/sdk/accounts/types.d.ts +26 -1
  104. package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
  105. package/dist/types/sdk/index.d.ts +11 -5
  106. package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +1 -1
  107. package/dist/types/sdk/market/MarketSuite.d.ts +5 -1
  108. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +1 -1
  109. package/dist/types/sdk/market/credit/CreditSuite.d.ts +8 -1
  110. package/dist/types/sdk/market/credit/types.d.ts +1 -1
  111. package/dist/types/sdk/market/math.d.ts +29 -1
  112. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -2
  113. package/dist/types/sdk/market/oracle/types.d.ts +2 -2
  114. package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +1 -1
  115. package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +1 -1
  116. package/dist/types/sdk/market/pool/PoolSuite.d.ts +1 -1
  117. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +1 -1
  118. package/dist/types/sdk/market/pool/types.d.ts +1 -1
  119. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +1 -1
  120. package/dist/types/sdk/market/pricefeeds/types.d.ts +1 -1
  121. package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +2 -2
  122. package/dist/types/sdk/opportunities/index.d.ts +2 -2
  123. package/dist/types/sdk/pools/PoolService.d.ts +7 -1
  124. package/dist/types/sdk/pools/index.d.ts +2 -2
  125. package/dist/types/sdk/pools/types.d.ts +18 -1
  126. package/dist/types/sdk/positions/MultichainPositionsService.d.ts +33 -0
  127. package/dist/types/sdk/positions/PositionsService.d.ts +22 -0
  128. package/dist/types/sdk/positions/index.d.ts +4 -0
  129. package/dist/types/sdk/positions/types.d.ts +25 -0
  130. package/package.json +1 -1
@@ -17,10 +17,22 @@ declare const poolHistoryMetricSchema: z.ZodUnion<readonly [z.ZodLiteral<"deposi
17
17
  * {@link StrategyHistoryMetric}
18
18
  **/
19
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">]>]>;
20
32
  /**
21
33
  * {@link HistoryMetric}
22
34
  **/
23
- 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">]>]>;
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">]>]>]>;
24
36
  /**
25
37
  * {@link HistoryPoint}
26
38
  **/
@@ -38,7 +50,7 @@ declare const historyChartMetadataSchema: z.ZodType<HistoryChartMetadata>;
38
50
  * {@link HistorySeries}
39
51
  **/
40
52
  declare const historySeriesSchema: z.ZodObject<{
41
- 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">]>]>;
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">]>]>]>;
42
54
  points: z.ZodArray<z.ZodObject<{
43
55
  timestamp: z.ZodNumber;
44
56
  value: z.ZodNumber;
@@ -60,7 +72,24 @@ declare const opportunityHistoryQuerySchema: z.ZodObject<{
60
72
  kind: z.ZodLiteral<"strategy">;
61
73
  }, z.core.$strip>], "kind">;
62
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.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
84
+ wallet: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
85
+ kind: z.ZodLiteral<"pool">;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ chainId: z.ZodNumber;
88
+ creditAccount: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, 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">]>;
63
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">]>]>;
64
93
  }, z.core.$strip>;
65
94
  //#endregion
66
- export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, strategyHistoryMetricSchema };
95
+ export { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema };
@@ -1,11 +1,11 @@
1
1
  import { Amount, AssetType, Bps, ChainId, Curator, Leverage, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
2
2
  import { ApyBreakdown, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, PointRewards, PointsProgram, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, Rewards, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, TokenRewards, matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
3
- import { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, OpportunityHistoryQuery, POOL_HISTORY_METRICS, PoolHistoryMetric, STRATEGY_HISTORY_METRICS, StrategyHistoryMetric } from "./history.js";
4
- import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, strategyHistoryMetricSchema } from "./history.schema.js";
5
3
  import { DelayedReceivedAsset, InstantReceivedAsset, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, ReceivedAsset, matchesLiquidatableAccountFilter } from "./liquidations.js";
4
+ import { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, RewardsPnL, StrategyPosition, StrategyPositionKey, StrategyPositionRef, TokenRewardsPnL, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
5
+ import { 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 } from "./history.js";
6
+ import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema } from "./history.schema.js";
6
7
  import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
7
8
  import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, 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 { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, Position, PositionCollateral, PositionFilter, PositionKind, RewardsPnL, StrategyPosition, TokenRewardsPnL } from "./positions.js";
9
- import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
9
+ import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
10
10
  import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
11
- export { Amount, ApyBreakdown, AssetType, Bps, ChainId, Curator, DelayedReceivedAsset, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, Position, PositionCollateral, PositionFilter, PositionKind, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, Rewards, RewardsPnL, STRATEGY_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, Timestamp, Token, TokenAmount, TokenRewards, TokenRewardsPnL, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, delayedReceivedAssetSchema, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
11
+ export { Amount, ApyBreakdown, AssetType, Bps, ChainId, Curator, DelayedReceivedAsset, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionHistoryMetric, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionHistoryMetric, PositionHistoryQuery, PositionId, PositionKey, PositionKind, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, Rewards, RewardsPnL, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionHistoryMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenRewards, TokenRewardsPnL, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorSchema, delayedReceivedAssetSchema, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionHistoryMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, positionId, positionKeySchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionHistoryMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
@@ -215,6 +215,46 @@ interface StrategyPosition {
215
215
  * A row of the positions list: anything a wallet holds in the protocol.
216
216
  **/
217
217
  type Position = PoolPosition | StrategyPosition | LiquidationPosition;
218
+ /**
219
+ * Canonical id of a position: the string used to match a row read from the
220
+ * chain with the same row served by the backend.
221
+ *
222
+ * A position list is always scoped to one wallet, so the wallet is not part of
223
+ * the id.
224
+ **/
225
+ type PositionId = string;
226
+ /**
227
+ * Builds the canonical id of a pool position.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * poolPositionId(1, "0xda00...") // "1:pool:0xda00..."
232
+ * ```
233
+ **/
234
+ declare function poolPositionId(chainId: ChainId, pool: Address): PositionId;
235
+ /**
236
+ * Builds the canonical id of a strategy position. The credit account address
237
+ * identifies it on its own, the credit manager is not part of the id.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * strategyPositionId(1, "0x9c4c...") // "1:strategy:0x9c4c..."
242
+ * ```
243
+ **/
244
+ declare function strategyPositionId(chainId: ChainId, creditAccount: Address): PositionId;
245
+ /**
246
+ * Builds the canonical id of a liquidation position.
247
+ *
248
+ * The redeemer is the withdrawal's own contract and therefore identifies it,
249
+ * but compressor versions below 313 do not report one; those fall back to the
250
+ * source token plus the moment the withdrawal becomes claimable, which is what
251
+ * distinguishes two withdrawals of the same asset.
252
+ **/
253
+ declare function liquidationPositionId(chainId: ChainId, position: Pick<LiquidationPosition, "redeemer" | "sourceToken" | "claimableAt">): PositionId;
254
+ /**
255
+ * Canonical id of any position, dispatching on {@link Position.kind}.
256
+ **/
257
+ declare function positionId(position: Position): PositionId;
218
258
  /**
219
259
  * Optional narrowing of a positions list.
220
260
  *
@@ -243,5 +283,64 @@ interface PositionFilter {
243
283
  **/
244
284
  underlyingType?: AssetType;
245
285
  }
286
+ /**
287
+ * Whether a position satisfies every criterion of a filter.
288
+ *
289
+ * This is the single definition of what each criterion means: every source
290
+ * builds its rows first and runs them through here, so the chain and the
291
+ * backend cannot disagree on what a filter selects.
292
+ *
293
+ * A criterion that does not apply to a position's kind keeps the row rather
294
+ * than dropping it: `isZeroDebt` says nothing about a pool position, and
295
+ * `underlyingType` says nothing about a liquidation position, which is
296
+ * denominated in whatever its withdrawal pays out.
297
+ *
298
+ * @param position - Row to test.
299
+ * @param filter - Criteria to test against. An absent filter matches anything.
300
+ **/
301
+ declare function matchesPositionFilter(position: Position, filter?: PositionFilter): boolean;
302
+ /**
303
+ * Identifies a pool position in a detail or history request.
304
+ **/
305
+ interface PoolPositionKey {
306
+ chainId: ChainId;
307
+ /**
308
+ * Address of the ERC-4626 pool contract.
309
+ **/
310
+ pool: Address;
311
+ /**
312
+ * Wallet holding the shares. Unlike an opportunity, a position exists only
313
+ * relative to its holder.
314
+ **/
315
+ wallet: Address;
316
+ }
317
+ /**
318
+ * Identifies a strategy position in a detail or history request. The credit
319
+ * account address identifies it on its own.
320
+ **/
321
+ interface StrategyPositionKey {
322
+ chainId: ChainId;
323
+ creditAccount: Address;
324
+ }
325
+ /**
326
+ * {@link PoolPositionKey} tagged with its kind, for requests that accept both
327
+ * kinds.
328
+ **/
329
+ interface PoolPositionRef extends PoolPositionKey {
330
+ kind: "pool";
331
+ }
332
+ /**
333
+ * {@link StrategyPositionKey} tagged with its kind, for requests that accept
334
+ * both kinds.
335
+ **/
336
+ interface StrategyPositionRef extends StrategyPositionKey {
337
+ kind: "strategy";
338
+ }
339
+ /**
340
+ * Identifies any position that has a history, for requests that accept both
341
+ * kinds. Liquidation positions have none: a delayed withdrawal is a single
342
+ * event rather than a series.
343
+ **/
344
+ type PositionKey = PoolPositionRef | StrategyPositionRef;
246
345
  //#endregion
247
- export { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, Position, PositionCollateral, PositionFilter, PositionKind, RewardsPnL, StrategyPosition, TokenRewardsPnL };
346
+ export { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, RewardsPnL, StrategyPosition, StrategyPositionKey, StrategyPositionRef, TokenRewardsPnL, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId };
@@ -697,5 +697,33 @@ declare const positionFilterSchema: z.ZodObject<{
697
697
  chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
698
698
  underlyingType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
699
699
  }, z.core.$strip>;
700
+ /**
701
+ * {@link PoolPositionKey}
702
+ **/
703
+ declare const poolPositionKeySchema: z.ZodObject<{
704
+ chainId: z.ZodNumber;
705
+ pool: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
706
+ wallet: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
707
+ }, z.core.$strip>;
708
+ /**
709
+ * {@link StrategyPositionKey}
710
+ **/
711
+ declare const strategyPositionKeySchema: z.ZodObject<{
712
+ chainId: z.ZodNumber;
713
+ creditAccount: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
714
+ }, z.core.$strip>;
715
+ /**
716
+ * {@link PositionKey}
717
+ **/
718
+ declare const positionKeySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
719
+ chainId: z.ZodNumber;
720
+ pool: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
721
+ wallet: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
722
+ kind: z.ZodLiteral<"pool">;
723
+ }, z.core.$strip>, z.ZodObject<{
724
+ chainId: z.ZodNumber;
725
+ creditAccount: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
726
+ kind: z.ZodLiteral<"strategy">;
727
+ }, z.core.$strip>], "kind">;
700
728
  //#endregion
701
- export { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionSchema, tokenRewardsPnLSchema };
729
+ export { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
@@ -1,8 +1,8 @@
1
- import { ILogger } from "../sdk/types/logger.js";
2
1
  import { ChainId } from "../model/primitives.js";
2
+ import "../model/index.js";
3
+ import { ILogger } from "../sdk/types/logger.js";
3
4
  import { NetworkType } from "../sdk/chain/chains.js";
4
5
  import { MultichainNetworkMeta } from "../sdk/types/multichain.js";
5
- import "../model/index.js";
6
6
  import { MultichainSDK } from "../sdk/MultichainSDK.js";
7
7
  import "../sdk/index.js";
8
8
  import { OffchainResult } from "../offchain/types.js";
@@ -3,6 +3,8 @@ import "../sdk/index.js";
3
3
  import { GearboxSDKOptions, Mode, OffchainByMode, OnchainByMode } from "./types.js";
4
4
  import { Opportunities } from "./opportunities/types.js";
5
5
  import "./opportunities/index.js";
6
+ import { Positions } from "./positions/types.js";
7
+ import "./positions/index.js";
6
8
  //#region src/new-sdk/GearboxSDK.d.ts
7
9
  /**
8
10
  * Combined entry point over both sources of Gearbox data: the chain and the
@@ -45,6 +47,10 @@ declare class GearboxSDK<const M extends Mode = Mode> {
45
47
  * Namespace for pool and strategy opportunities.
46
48
  **/
47
49
  readonly opportunities: Opportunities<M>;
50
+ /**
51
+ * Namespace for the positions a wallet holds.
52
+ **/
53
+ readonly positions: Positions<M>;
48
54
  constructor(options: GearboxSDKOptions<M>);
49
55
  /**
50
56
  * Attaches the on-chain SDK when this instance owns one.
@@ -5,5 +5,8 @@ import "./utils/index.js";
5
5
  import { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly } from "./opportunities/types.js";
6
6
  import { OpportunitiesNamespace } from "./opportunities/OpportunitiesNamespace.js";
7
7
  import "./opportunities/index.js";
8
+ import { Positions, PositionsBase, PositionsByMode, PositionsOffchainOnly, PositionsOnchainOnly } from "./positions/types.js";
9
+ import { PositionsNamespace } from "./positions/PositionsNamespace.js";
10
+ import "./positions/index.js";
8
11
  import { GearboxSDK } from "./GearboxSDK.js";
9
- export { AbstractNamespace, AllSourcesFailedError, Chart, ChartMetadata, CombineSources, GearboxSDK, GearboxSDKOptions, HistoryReader, Mode, OffchainByMode, OffchainContribution, OffchainSource, OffchainSourceStatus, OnchainByMode, OnchainContribution, OnchainSource, Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesNamespace, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly, PlainMultichainSDKOptions, ReadResult, SourceMeta };
12
+ export { AbstractNamespace, AllSourcesFailedError, Chart, ChartMetadata, CombineSources, GearboxSDK, GearboxSDKOptions, HistoryReader, Mode, OffchainByMode, OffchainContribution, OffchainSource, OffchainSourceStatus, OnchainByMode, OnchainContribution, OnchainSource, Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesNamespace, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly, PlainMultichainSDKOptions, Positions, PositionsBase, PositionsByMode, PositionsNamespace, PositionsOffchainOnly, PositionsOnchainOnly, ReadResult, SourceMeta };
@@ -1,7 +1,7 @@
1
- import { ILogger } from "../../sdk/types/logger.js";
2
1
  import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
3
2
  import { PoolHistoryMetric, StrategyHistoryMetric } from "../../model/history.js";
4
3
  import "../../model/index.js";
4
+ import { ILogger } from "../../sdk/types/logger.js";
5
5
  import { MultichainSDK } from "../../sdk/MultichainSDK.js";
6
6
  import "../../sdk/index.js";
7
7
  import { GearboxAPI } from "../../offchain/GearboxAPI.js";
@@ -0,0 +1,62 @@
1
+ import { PoolPositionRef, Position, PositionFilter, StrategyPositionRef } from "../../model/positions.js";
2
+ import { PoolPositionHistoryMetric, StrategyPositionHistoryMetric } from "../../model/history.js";
3
+ import "../../model/index.js";
4
+ import { ILogger } from "../../sdk/types/logger.js";
5
+ import { MultichainSDK } from "../../sdk/MultichainSDK.js";
6
+ import "../../sdk/index.js";
7
+ import { GearboxAPI } from "../../offchain/GearboxAPI.js";
8
+ import "../../offchain/index.js";
9
+ import { ReadResult } from "../types.js";
10
+ import { AbstractNamespace } from "../AbstractNamespace.js";
11
+ import { HistoryReader } from "../utils/history.js";
12
+ import "../utils/index.js";
13
+ import { PositionsBase, PositionsOffchainOnly } from "./types.js";
14
+ import { Address } from "viem";
15
+ //#region src/new-sdk/positions/PositionsNamespace.d.ts
16
+ /**
17
+ * The `positions` namespace of the combined SDK.
18
+ *
19
+ * A stateless router over the two sources, see {@link AbstractNamespace} for the
20
+ * routing itself. What is specific to positions is the reads below and the merge
21
+ * policy at the bottom of the class.
22
+ *
23
+ * The class implements the methods of every mode; {@link GearboxSDK} exposes it
24
+ * as its mode's slice of {@link PositionsByMode}, so calling a method the mode
25
+ * does not have is a compile error rather than a runtime one.
26
+ **/
27
+ declare class PositionsNamespace extends AbstractNamespace<Position> implements PositionsBase, PositionsOffchainOnly {
28
+ #private;
29
+ constructor(onchain: MultichainSDK | undefined, offchain: GearboxAPI | undefined, logger?: ILogger);
30
+ /**
31
+ * {@inheritDoc PositionsBase.list}
32
+ **/
33
+ list(wallet: Address, filter?: PositionFilter): Promise<ReadResult<Position[]>>;
34
+ /**
35
+ * {@inheritDoc PositionsOffchainOnly.history}
36
+ **/
37
+ history(key: PoolPositionRef): HistoryReader<PoolPositionHistoryMetric>;
38
+ history(key: StrategyPositionRef): HistoryReader<StrategyPositionHistoryMetric>;
39
+ /**
40
+ * Merges the two versions of one position.
41
+ *
42
+ * The chain wins every field it fills; the backend fills the rest and owns
43
+ * {@link OFFCHAIN_OWNED_FIELDS}.
44
+ *
45
+ * The rule is onchain-first, field-wise, and never deeper than one level: a
46
+ * group like `totalValue` or `apy` is taken whole from one source, so a row
47
+ * never mixes an on-chain token amount with a backend dollar value derived
48
+ * from a different block.
49
+ **/
50
+ protected mergeOne<T extends object>(onchain: T, offchain: T): T;
51
+ /**
52
+ * Unions the two lists by canonical position id.
53
+ *
54
+ * Rows present in both are merged by {@link PositionsNamespace.mergeOne}.
55
+ * Rows only the backend knows are appended: a chain the SDK does not cover,
56
+ * or a market it has not loaded, must not hide a position the wallet actually
57
+ * holds.
58
+ **/
59
+ protected mergeList(onchain: Position[], offchain: Position[]): Position[];
60
+ }
61
+ //#endregion
62
+ export { PositionsNamespace };
@@ -0,0 +1,3 @@
1
+ import { Positions, PositionsBase, PositionsByMode, PositionsOffchainOnly, PositionsOnchainOnly } from "./types.js";
2
+ import { PositionsNamespace } from "./PositionsNamespace.js";
3
+ export { Positions, PositionsBase, PositionsByMode, PositionsNamespace, PositionsOffchainOnly, PositionsOnchainOnly };
@@ -0,0 +1,62 @@
1
+ import { PoolPositionRef, Position, PositionFilter, StrategyPositionRef } from "../../model/positions.js";
2
+ import { PoolPositionHistoryMetric, StrategyPositionHistoryMetric } from "../../model/history.js";
3
+ import "../../model/index.js";
4
+ import { Mode, ReadResult } from "../types.js";
5
+ import { HistoryReader } from "../utils/history.js";
6
+ import { Address } from "viem";
7
+ //#region src/new-sdk/positions/types.d.ts
8
+ /**
9
+ * Reads every mode supports, because either source alone can answer them.
10
+ **/
11
+ interface PositionsBase {
12
+ /**
13
+ * Everything a wallet holds: its pool shares, its credit accounts and the
14
+ * delayed withdrawals it took over by liquidating, optionally narrowed.
15
+ *
16
+ * In `both` mode the two lists are unioned by canonical position id and
17
+ * merged field-wise, with the chain winning any field both sources fill.
18
+ **/
19
+ list(wallet: Address, filter?: PositionFilter): Promise<ReadResult<Position[]>>;
20
+ }
21
+ /**
22
+ * Reads only a backend can answer.
23
+ **/
24
+ interface PositionsOffchainOnly {
25
+ /**
26
+ * Historical charts of one position, one metric and one range at a time:
27
+ * `history(key).chart("netApy", "1m")`.
28
+ *
29
+ * The key's kind decides which metrics exist, so asking a pool position for a
30
+ * strategy series does not compile. Liquidation positions have no history at
31
+ * all: a delayed withdrawal is a single event rather than a series, which is
32
+ * why no key names one.
33
+ *
34
+ * Absent in `onchain` mode: the chain serves the present, and rebuilding a
35
+ * series from it would mean an archive read per point.
36
+ **/
37
+ history(key: PoolPositionRef): HistoryReader<PoolPositionHistoryMetric>;
38
+ history(key: StrategyPositionRef): HistoryReader<StrategyPositionHistoryMetric>;
39
+ }
40
+ /**
41
+ * Reads only the chain can answer. Empty for now — every on-chain read the
42
+ * namespace exposes has a backend counterpart.
43
+ **/
44
+ interface PositionsOnchainOnly {}
45
+ /**
46
+ * Which methods the `positions` namespace has in each mode.
47
+ *
48
+ * A lookup map rather than a conditional type: `both` is spelled out instead of
49
+ * being inferred, and a widened mode degrades to the intersection of what all
50
+ * modes offer rather than silently distributing into a union of everything.
51
+ **/
52
+ interface PositionsByMode {
53
+ onchain: PositionsBase & PositionsOnchainOnly;
54
+ offchain: PositionsBase & PositionsOffchainOnly;
55
+ both: PositionsBase & PositionsOffchainOnly & PositionsOnchainOnly;
56
+ }
57
+ /**
58
+ * The `positions` namespace of a {@link GearboxSDK} in mode `M`.
59
+ **/
60
+ type Positions<M extends Mode = Mode> = PositionsByMode[M];
61
+ //#endregion
62
+ export { Positions, PositionsBase, PositionsByMode, PositionsOffchainOnly, PositionsOnchainOnly };
@@ -1,4 +1,4 @@
1
- import { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange } from "../../model/history.js";
1
+ import { HistoryChartMetadata, HistoryPoint, HistoryRange } from "../../model/history.js";
2
2
  import "../../model/index.js";
3
3
  import { SourceMeta } from "../types.js";
4
4
  //#region src/new-sdk/utils/history.d.ts
@@ -29,9 +29,13 @@ interface Chart {
29
29
  /**
30
30
  * Reads the charts of one subject, one metric and one range at a time.
31
31
  *
32
+ * The constraint is `string` rather than {@link HistoryMetric}, matching
33
+ * {@link HistorySeries}: opportunities and positions carry their own metric
34
+ * unions, and those are free to drift apart.
35
+ *
32
36
  * @typeParam Metric - Metrics the subject has.
33
37
  **/
34
- interface HistoryReader<Metric extends HistoryMetric> {
38
+ interface HistoryReader<Metric extends string> {
35
39
  /**
36
40
  * Historical chart of one metric over one window.
37
41
  *
@@ -1,6 +1,8 @@
1
1
  import { GearboxAPIOptions } from "./types.js";
2
2
  import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
3
3
  import "./opportunities/index.js";
4
+ import { OffchainPositions } from "./positions/OffchainPositions.js";
5
+ import "./positions/index.js";
4
6
  //#region src/offchain/GearboxAPI.d.ts
5
7
  /**
6
8
  * Client for the Gearbox backend, the off-chain source of the read model.
@@ -17,14 +19,18 @@ import "./opportunities/index.js";
17
19
  * return those types directly, so there is no wire DTO layer here — only
18
20
  * transport and schema validation.
19
21
  *
20
- * The transport is not implemented yet; see {@link OffchainOpportunities} for
21
- * what each stubbed endpoint currently answers.
22
+ * The transport is not implemented yet; see {@link OffchainOpportunities} and
23
+ * {@link OffchainPositions} for what each stubbed endpoint currently answers.
22
24
  **/
23
25
  declare class GearboxAPI {
24
26
  /**
25
27
  * Namespace for pool and strategy opportunities.
26
28
  **/
27
29
  readonly opportunities: OffchainOpportunities;
30
+ /**
31
+ * Namespace for the positions a wallet holds.
32
+ **/
33
+ readonly positions: OffchainPositions;
28
34
  constructor(options?: GearboxAPIOptions);
29
35
  }
30
36
  //#endregion
@@ -1,5 +1,7 @@
1
- import { GearboxAPIOptions, OffchainResult, OffchainSourceMeta } from "./types.js";
2
- import { OffchainNotImplementedError, OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
1
+ import { GearboxAPIOptions, OffchainNotImplementedError, OffchainResult, OffchainSourceMeta } from "./types.js";
2
+ import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
3
3
  import "./opportunities/index.js";
4
+ import { OffchainPositions } from "./positions/OffchainPositions.js";
5
+ import "./positions/index.js";
4
6
  import { GearboxAPI } from "./GearboxAPI.js";
5
- export { GearboxAPI, GearboxAPIOptions, OffchainNotImplementedError, OffchainOpportunities, OffchainResult, OffchainSourceMeta };
7
+ export { GearboxAPI, GearboxAPIOptions, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainResult, OffchainSourceMeta };
@@ -2,14 +2,6 @@ import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityK
2
2
  import { HistoryMetric, HistorySeries, OpportunityHistoryQuery } from "../../model/history.js";
3
3
  import { GearboxAPIOptions, OffchainResult } from "../types.js";
4
4
  //#region src/offchain/opportunities/OffchainOpportunities.d.ts
5
- /**
6
- * Thrown by the endpoints that have no stub answer, so that a caller in
7
- * `offchain` mode fails loudly instead of reading an empty detail page as a
8
- * missing opportunity.
9
- **/
10
- declare class OffchainNotImplementedError extends Error {
11
- constructor(endpoint: string);
12
- }
13
5
  /**
14
6
  * Backend counterpart of the `opportunities` namespace.
15
7
  *
@@ -66,4 +58,4 @@ declare class OffchainOpportunities {
66
58
  getHistory<M extends HistoryMetric>(query: OpportunityHistoryQuery<M>): Promise<OffchainResult<HistorySeries<M>>>;
67
59
  }
68
60
  //#endregion
69
- export { OffchainNotImplementedError, OffchainOpportunities };
61
+ export { OffchainOpportunities };
@@ -1,2 +1,2 @@
1
- import { OffchainNotImplementedError, OffchainOpportunities } from "./OffchainOpportunities.js";
2
- export { OffchainNotImplementedError, OffchainOpportunities };
1
+ import { OffchainOpportunities } from "./OffchainOpportunities.js";
2
+ export { OffchainOpportunities };
@@ -0,0 +1,47 @@
1
+ import { Position, PositionFilter } from "../../model/positions.js";
2
+ import { HistorySeries, PositionHistoryMetric, PositionHistoryQuery } from "../../model/history.js";
3
+ import { GearboxAPIOptions, OffchainResult } from "../types.js";
4
+ import { Address } from "viem";
5
+ //#region src/offchain/positions/OffchainPositions.d.ts
6
+ /**
7
+ * Backend counterpart of the `positions` namespace.
8
+ *
9
+ * This is a stub: the HTTP client is not written yet, so reads answer with an
10
+ * empty payload. Every signature is already the final one, because the backend
11
+ * returns the read model types directly — there is no wire DTO and no mapper
12
+ * between the two.
13
+ *
14
+ * When the transport lands, each method will validate the response against the
15
+ * matching schema from `src/model` before returning it. A validation failure is
16
+ * a version-skew error and is handled exactly like a transport error: the
17
+ * combined SDK drops the backend's contribution in `both` mode and rethrows in
18
+ * `offchain` mode.
19
+ **/
20
+ declare class OffchainPositions {
21
+ #private;
22
+ constructor(options?: GearboxAPIOptions);
23
+ /**
24
+ * Base URL the client will call once the transport is implemented.
25
+ **/
26
+ get baseUrl(): string | undefined;
27
+ /**
28
+ * Everything a wallet holds, optionally narrowed by {@link PositionFilter}.
29
+ *
30
+ * @returns An empty list until the backend client is implemented.
31
+ **/
32
+ list(wallet: Address, filter?: PositionFilter): Promise<OffchainResult<Position[]>>;
33
+ /**
34
+ * One historical series of one position. History exists only here: rebuilding
35
+ * it from the chain would mean an archive read per point.
36
+ *
37
+ * The requested metric types the response, so a caller asking for one metric
38
+ * does not have to narrow the union back down. When the transport lands,
39
+ * validation is what upholds it: a response carrying a different metric than
40
+ * the one asked for is a version-skew error like any other.
41
+ *
42
+ * @returns An empty series until the backend client is implemented.
43
+ **/
44
+ getHistory<M extends PositionHistoryMetric>(query: PositionHistoryQuery<M>): Promise<OffchainResult<HistorySeries<M>>>;
45
+ }
46
+ //#endregion
47
+ export { OffchainPositions };
@@ -0,0 +1,2 @@
1
+ import { OffchainPositions } from "./OffchainPositions.js";
2
+ export { OffchainPositions };
@@ -31,6 +31,17 @@ interface OffchainResult<T> {
31
31
  **/
32
32
  meta: OffchainSourceMeta;
33
33
  }
34
+ /**
35
+ * Thrown by the endpoints that have no stub answer, so that a caller in
36
+ * `offchain` mode fails loudly instead of reading an empty detail page as a
37
+ * missing entity.
38
+ *
39
+ * Lives here rather than in one namespace because every stubbed namespace
40
+ * throws it.
41
+ **/
42
+ declare class OffchainNotImplementedError extends Error {
43
+ constructor(endpoint: string);
44
+ }
34
45
  /**
35
46
  * Options for creating a {@link GearboxAPI} instance.
36
47
  **/
@@ -47,4 +58,4 @@ interface GearboxAPIOptions {
47
58
  logger?: ILogger;
48
59
  }
49
60
  //#endregion
50
- export { GearboxAPIOptions, OffchainResult, OffchainSourceMeta };
61
+ export { GearboxAPIOptions, OffchainNotImplementedError, OffchainResult, OffchainSourceMeta };
@@ -8,6 +8,8 @@ import { RedstoneOptions } from "./market/pricefeeds/updates/RedstoneUpdater.js"
8
8
  import "./market/pricefeeds/updates/index.js";
9
9
  import { MultichainOpportunitiesService } from "./opportunities/MultichainOpportunitiesService.js";
10
10
  import "./opportunities/index.js";
11
+ import { MultichainPositionsService } from "./positions/MultichainPositionsService.js";
12
+ import "./positions/index.js";
11
13
  import { AttachOptions, ClientOptions, HydrateOptions, OnchainSDK } from "./OnchainSDK.js";
12
14
  import { MultichainState } from "./types/state.js";
13
15
  import "./types/index.js";
@@ -123,6 +125,10 @@ declare class MultichainSDK<const Plugins extends PluginsMap = {}> {
123
125
  * chains.
124
126
  */
125
127
  readonly opportunities: MultichainOpportunitiesService<Plugins>;
128
+ /**
129
+ * Namespace for the positions a wallet holds on all configured chains.
130
+ */
131
+ readonly positions: MultichainPositionsService<Plugins>;
126
132
  constructor(options: MultichainSDKOptions<Plugins>);
127
133
  /**
128
134
  * Attach all configured chains in parallel.