@gearbox-protocol/sdk 14.12.0-next.80 → 14.12.0-next.82

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 (221) hide show
  1. package/dist/cjs/model/filters.js +0 -4
  2. package/dist/cjs/model/filters.schema.js +10 -1
  3. package/dist/cjs/model/index.js +11 -0
  4. package/dist/cjs/model/liquidations.js +1 -1
  5. package/dist/cjs/model/liquidations.schema.js +1 -1
  6. package/dist/cjs/model/opportunities.js +1 -1
  7. package/dist/cjs/model/opportunities.schema.js +6 -13
  8. package/dist/cjs/model/positions.js +1 -1
  9. package/dist/cjs/model/positions.schema.js +33 -1
  10. package/dist/cjs/model/response.js +1 -0
  11. package/dist/cjs/model/response.schema.js +64 -0
  12. package/dist/cjs/new-sdk/AbstractNamespace.js +46 -128
  13. package/dist/cjs/new-sdk/GearboxSDK.js +55 -42
  14. package/dist/cjs/new-sdk/errors/AllSourcesFailedError.js +20 -0
  15. package/dist/cjs/new-sdk/errors/MissingSourceError.js +25 -0
  16. package/dist/cjs/new-sdk/errors/NoSourceServedError.js +20 -0
  17. package/dist/cjs/new-sdk/errors/SourceChainMismatchError.js +34 -0
  18. package/dist/cjs/new-sdk/errors/SourceUnavailableError.js +25 -0
  19. package/dist/cjs/new-sdk/errors/assertSameChains.js +12 -0
  20. package/dist/cjs/new-sdk/errors/everyChainFailed.js +11 -0
  21. package/dist/cjs/new-sdk/errors/index.js +15 -0
  22. package/dist/cjs/new-sdk/index.js +23 -3
  23. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +37 -89
  24. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +27 -94
  25. package/dist/cjs/new-sdk/types.js +0 -21
  26. package/dist/cjs/new-sdk/utils/filterResponse.js +21 -0
  27. package/dist/cjs/new-sdk/utils/index.js +6 -0
  28. package/dist/cjs/new-sdk/utils/mergeChains.js +81 -0
  29. package/dist/cjs/new-sdk/utils/types.js +1 -0
  30. package/dist/cjs/offchain/AbstractOffchainNamespace.js +42 -65
  31. package/dist/cjs/offchain/GearboxAPI.js +12 -8
  32. package/dist/cjs/offchain/errors/OffchainInvalidJsonError.js +19 -0
  33. package/dist/cjs/offchain/errors/OffchainNotConfiguredError.js +20 -0
  34. package/dist/cjs/offchain/errors/OffchainNotImplementedError.js +19 -0
  35. package/dist/cjs/offchain/errors/OffchainRequestFailedError.js +24 -0
  36. package/dist/cjs/offchain/errors/OffchainStatusError.js +20 -0
  37. package/dist/cjs/offchain/errors/OffchainTransportError.js +31 -0
  38. package/dist/cjs/offchain/errors/OffchainValidationError.js +26 -0
  39. package/dist/cjs/offchain/errors/backendMessage.js +28 -0
  40. package/dist/cjs/offchain/errors/errorCause.js +12 -0
  41. package/dist/cjs/offchain/errors/index.js +21 -0
  42. package/dist/cjs/offchain/errors/readResponseBody.js +15 -0
  43. package/dist/cjs/offchain/index.js +22 -5
  44. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +6 -3
  45. package/dist/cjs/offchain/positions/OffchainPositions.js +15 -21
  46. package/dist/cjs/offchain/types.js +0 -75
  47. package/dist/cjs/sdk/MultichainSDK.js +1 -1
  48. package/dist/cjs/sdk/OnchainSDK.js +1 -1
  49. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +6 -6
  50. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +26 -20
  51. package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
  52. package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +7 -5
  53. package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +3 -2
  54. package/dist/cjs/sdk/base/MultichainConstruct.js +73 -34
  55. package/dist/cjs/sdk/chain/chains.js +11 -0
  56. package/dist/cjs/sdk/chain/index.js +1 -0
  57. package/dist/cjs/sdk/core/index.js +1 -1
  58. package/dist/cjs/sdk/index.js +2 -1
  59. package/dist/cjs/sdk/market/rwa/RWARegistry.js +4 -2
  60. package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
  61. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +1 -4
  62. package/dist/cjs/sdk/pools/PoolService.js +2 -1
  63. package/dist/cjs/sdk/positions/MultichainPositionsService.js +6 -29
  64. package/dist/cjs/sdk/positions/PositionsService.js +12 -6
  65. package/dist/esm/dev/AccountOpener.js +1 -1
  66. package/dist/esm/dev/withdrawalUtils.js +1 -1
  67. package/dist/esm/model/filters.js +0 -4
  68. package/dist/esm/model/filters.schema.js +10 -2
  69. package/dist/esm/model/index.js +5 -3
  70. package/dist/esm/model/liquidations.js +1 -1
  71. package/dist/esm/model/liquidations.schema.js +1 -1
  72. package/dist/esm/model/opportunities.js +1 -1
  73. package/dist/esm/model/opportunities.schema.js +4 -11
  74. package/dist/esm/model/positions.js +1 -1
  75. package/dist/esm/model/positions.schema.js +33 -3
  76. package/dist/esm/model/response.js +1 -0
  77. package/dist/esm/model/response.schema.js +58 -0
  78. package/dist/esm/new-sdk/AbstractNamespace.js +46 -128
  79. package/dist/esm/new-sdk/GearboxSDK.js +55 -42
  80. package/dist/esm/new-sdk/errors/AllSourcesFailedError.js +19 -0
  81. package/dist/esm/new-sdk/errors/MissingSourceError.js +24 -0
  82. package/dist/esm/new-sdk/errors/NoSourceServedError.js +19 -0
  83. package/dist/esm/new-sdk/errors/SourceChainMismatchError.js +33 -0
  84. package/dist/esm/new-sdk/errors/SourceUnavailableError.js +24 -0
  85. package/dist/esm/new-sdk/errors/assertSameChains.js +11 -0
  86. package/dist/esm/new-sdk/errors/everyChainFailed.js +10 -0
  87. package/dist/esm/new-sdk/errors/index.js +8 -0
  88. package/dist/esm/new-sdk/index.js +13 -3
  89. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +38 -90
  90. package/dist/esm/new-sdk/positions/PositionsNamespace.js +28 -95
  91. package/dist/esm/new-sdk/types.js +1 -21
  92. package/dist/esm/new-sdk/utils/filterResponse.js +20 -0
  93. package/dist/esm/new-sdk/utils/index.js +3 -1
  94. package/dist/esm/new-sdk/utils/mergeChains.js +78 -0
  95. package/dist/esm/new-sdk/utils/types.js +1 -0
  96. package/dist/esm/offchain/AbstractOffchainNamespace.js +41 -64
  97. package/dist/esm/offchain/GearboxAPI.js +12 -8
  98. package/dist/esm/offchain/errors/OffchainInvalidJsonError.js +18 -0
  99. package/dist/esm/offchain/errors/OffchainNotConfiguredError.js +19 -0
  100. package/dist/esm/offchain/errors/OffchainNotImplementedError.js +18 -0
  101. package/dist/esm/offchain/errors/OffchainRequestFailedError.js +23 -0
  102. package/dist/esm/offchain/errors/OffchainStatusError.js +19 -0
  103. package/dist/esm/offchain/errors/OffchainTransportError.js +30 -0
  104. package/dist/esm/offchain/errors/OffchainValidationError.js +25 -0
  105. package/dist/esm/offchain/errors/backendMessage.js +27 -0
  106. package/dist/esm/offchain/errors/errorCause.js +11 -0
  107. package/dist/esm/offchain/errors/index.js +11 -0
  108. package/dist/esm/offchain/errors/readResponseBody.js +14 -0
  109. package/dist/esm/offchain/index.js +13 -2
  110. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +6 -3
  111. package/dist/esm/offchain/positions/OffchainPositions.js +15 -21
  112. package/dist/esm/offchain/types.js +1 -72
  113. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  114. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  115. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  116. package/dist/esm/sdk/MultichainSDK.js +1 -1
  117. package/dist/esm/sdk/OnchainSDK.js +1 -1
  118. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  119. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +6 -6
  120. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +27 -21
  121. package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
  122. package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +7 -5
  123. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  124. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  125. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  126. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +4 -3
  127. package/dist/esm/sdk/base/MultichainConstruct.js +73 -34
  128. package/dist/esm/sdk/base/TokensMeta.js +2 -2
  129. package/dist/esm/sdk/chain/chains.js +11 -1
  130. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  131. package/dist/esm/sdk/chain/index.js +2 -2
  132. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  133. package/dist/esm/sdk/core/index.js +1 -1
  134. package/dist/esm/sdk/index.js +3 -3
  135. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  136. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  137. package/dist/esm/sdk/market/rwa/RWARegistry.js +4 -2
  138. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  139. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  140. package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
  141. package/dist/esm/sdk/opportunities/OpportunitiesService.js +1 -4
  142. package/dist/esm/sdk/pools/PoolService.js +3 -2
  143. package/dist/esm/sdk/positions/MultichainPositionsService.js +6 -29
  144. package/dist/esm/sdk/positions/PositionsService.js +12 -6
  145. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  146. package/dist/types/model/filters.d.ts +9 -3
  147. package/dist/types/model/filters.schema.d.ts +7 -1
  148. package/dist/types/model/index.d.ts +7 -5
  149. package/dist/types/model/liquidations.d.ts +2 -6
  150. package/dist/types/model/liquidations.schema.d.ts +1 -1
  151. package/dist/types/model/opportunities.d.ts +3 -7
  152. package/dist/types/model/opportunities.schema.d.ts +2 -2
  153. package/dist/types/model/positions.d.ts +2 -6
  154. package/dist/types/model/positions.schema.d.ts +32 -2
  155. package/dist/types/model/response.d.ts +105 -0
  156. package/dist/types/model/response.schema.d.ts +98 -0
  157. package/dist/types/new-sdk/AbstractNamespace.d.ts +33 -98
  158. package/dist/types/new-sdk/GearboxSDK.d.ts +10 -25
  159. package/dist/types/new-sdk/errors/AllSourcesFailedError.d.ts +11 -0
  160. package/dist/types/new-sdk/errors/MissingSourceError.d.ts +23 -0
  161. package/dist/types/new-sdk/errors/NoSourceServedError.d.ts +17 -0
  162. package/dist/types/new-sdk/errors/SourceChainMismatchError.d.ts +35 -0
  163. package/dist/types/new-sdk/errors/SourceUnavailableError.d.ts +22 -0
  164. package/dist/types/new-sdk/errors/assertSameChains.d.ts +11 -0
  165. package/dist/types/new-sdk/errors/everyChainFailed.d.ts +10 -0
  166. package/dist/types/new-sdk/errors/index.d.ts +8 -0
  167. package/dist/types/new-sdk/index.d.ts +17 -6
  168. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -40
  169. package/dist/types/new-sdk/opportunities/index.d.ts +2 -2
  170. package/dist/types/new-sdk/opportunities/types.d.ts +80 -26
  171. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +17 -38
  172. package/dist/types/new-sdk/positions/index.d.ts +2 -2
  173. package/dist/types/new-sdk/positions/types.d.ts +74 -24
  174. package/dist/types/new-sdk/types.d.ts +24 -77
  175. package/dist/types/new-sdk/utils/filterResponse.d.ts +16 -0
  176. package/dist/types/new-sdk/utils/history.d.ts +6 -36
  177. package/dist/types/new-sdk/utils/index.d.ts +5 -2
  178. package/dist/types/new-sdk/utils/mergeChains.d.ts +20 -0
  179. package/dist/types/new-sdk/utils/types.d.ts +11 -0
  180. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +21 -28
  181. package/dist/types/offchain/GearboxAPI.d.ts +13 -9
  182. package/dist/types/offchain/errors/OffchainInvalidJsonError.d.ts +16 -0
  183. package/dist/types/offchain/errors/OffchainNotConfiguredError.d.ts +16 -0
  184. package/dist/types/offchain/errors/OffchainNotImplementedError.d.ts +15 -0
  185. package/dist/types/offchain/errors/OffchainRequestFailedError.d.ts +12 -0
  186. package/dist/types/offchain/errors/OffchainStatusError.d.ts +16 -0
  187. package/dist/types/offchain/errors/OffchainTransportError.d.ts +43 -0
  188. package/dist/types/offchain/errors/OffchainValidationError.d.ts +21 -0
  189. package/dist/types/offchain/errors/backendMessage.d.ts +9 -0
  190. package/dist/types/offchain/errors/errorCause.d.ts +22 -0
  191. package/dist/types/offchain/errors/index.d.ts +11 -0
  192. package/dist/types/offchain/errors/readResponseBody.d.ts +8 -0
  193. package/dist/types/offchain/index.d.ts +13 -2
  194. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +9 -8
  195. package/dist/types/offchain/positions/OffchainPositions.d.ts +9 -15
  196. package/dist/types/offchain/types.d.ts +7 -88
  197. package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +4 -0
  198. package/dist/types/sdk/accounts/index.d.ts +3 -3
  199. package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +2 -2
  200. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +15 -14
  201. package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -2
  202. package/dist/types/sdk/accounts/liquidations/types.d.ts +32 -16
  203. package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +4 -4
  204. package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +2 -2
  205. package/dist/types/sdk/accounts/withdrawal-compressor/index.d.ts +2 -2
  206. package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +26 -4
  207. package/dist/types/sdk/base/MultichainConstruct.d.ts +63 -14
  208. package/dist/types/sdk/base/index.d.ts +2 -2
  209. package/dist/types/sdk/chain/chains.d.ts +10 -2
  210. package/dist/types/sdk/chain/index.d.ts +2 -2
  211. package/dist/types/sdk/index.d.ts +7 -7
  212. package/dist/types/sdk/market/MarketSuite.d.ts +1 -1
  213. package/dist/types/sdk/market/rwa/RWARegistry.d.ts +2 -1
  214. package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +13 -16
  215. package/dist/types/sdk/pools/types.d.ts +4 -0
  216. package/dist/types/sdk/positions/MultichainPositionsService.d.ts +2 -12
  217. package/dist/types/sdk/positions/index.d.ts +2 -2
  218. package/dist/types/sdk/positions/types.d.ts +14 -5
  219. package/dist/types/sdk/types/index.d.ts +2 -2
  220. package/dist/types/sdk/types/multichain.d.ts +16 -36
  221. package/package.json +1 -1
@@ -1,10 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/model/filters.ts
3
3
  /**
4
- * The vocabulary every read-model filter is written in: how a single condition
5
- * says "do not narrow", and how a predicate asks whether it narrows at all.
6
- **/
7
- /**
8
4
  * Sentinel a filter condition can be set to instead of being omitted.
9
5
  **/
10
6
  const FILTER_ALL = "all";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("./filters.js");
2
+ const require_model_filters = require("./filters.js");
3
3
  let zod_v4 = require("zod/v4");
4
4
  //#region src/model/filters.schema.ts
5
5
  /**
@@ -17,7 +17,16 @@ function filterable(schema) {
17
17
  return zod_v4.z.union([schema, filterAllSchema]);
18
18
  }
19
19
  const booleanParamSchema = zod_v4.z.enum(["true", "false"]);
20
+ /**
21
+ * A boolean condition as a URL can carry it: a condition that does not narrow
22
+ * is absent rather than spelled out, see {@link booleanParamSchema}.
23
+ **/
24
+ function encodeFlag(condition) {
25
+ if (!require_model_filters.isFilterSet(condition)) return;
26
+ return condition ? "true" : "false";
27
+ }
20
28
  //#endregion
21
29
  exports.booleanParamSchema = booleanParamSchema;
30
+ exports.encodeFlag = encodeFlag;
22
31
  exports.filterAllSchema = filterAllSchema;
23
32
  exports.filterable = filterable;
@@ -13,6 +13,8 @@ const require_model_liquidations = require("./liquidations.js");
13
13
  const require_model_opportunities = require("./opportunities.js");
14
14
  const require_model_positions = require("./positions.js");
15
15
  require("./primitives.js");
16
+ require("./response.js");
17
+ const require_model_response_schema = require("./response.schema.js");
16
18
  exports.FILTER_ALL = require_model_filters.FILTER_ALL;
17
19
  exports.POOL_HISTORY_METRICS = require_model_history.POOL_HISTORY_METRICS;
18
20
  exports.POOL_POSITION_HISTORY_METRICS = require_model_history.POOL_POSITION_HISTORY_METRICS;
@@ -23,10 +25,15 @@ exports.apyBreakdownSchema = require_model_opportunities_schema.apyBreakdownSche
23
25
  exports.assetTypeSchema = require_model_primitives_schema.assetTypeSchema;
24
26
  exports.booleanParamSchema = require_model_filters_schema.booleanParamSchema;
25
27
  exports.bpsSchema = require_model_primitives_schema.bpsSchema;
28
+ exports.chainFailedSchema = require_model_response_schema.chainFailedSchema;
26
29
  exports.chainIdSchema = require_model_primitives_schema.chainIdSchema;
30
+ exports.chainMetadataSchema = require_model_response_schema.chainMetadataSchema;
31
+ exports.chainSucceededSchema = require_model_response_schema.chainSucceededSchema;
27
32
  exports.curatorNameSchema = require_model_curators_schema.curatorNameSchema;
28
33
  exports.curatorSchema = require_model_curators_schema.curatorSchema;
34
+ exports.dataSourceSchema = require_model_response_schema.dataSourceSchema;
29
35
  exports.delayedReceivedAssetSchema = require_model_liquidations_schema.delayedReceivedAssetSchema;
36
+ exports.encodeFlag = require_model_filters_schema.encodeFlag;
30
37
  exports.filterAllSchema = require_model_filters_schema.filterAllSchema;
31
38
  exports.filterable = require_model_filters_schema.filterable;
32
39
  exports.historyChartMetadataSchema = require_model_history_schema.historyChartMetadataSchema;
@@ -71,6 +78,8 @@ exports.poolPositionId = require_model_positions.poolPositionId;
71
78
  exports.poolPositionKeySchema = require_model_positions_schema.poolPositionKeySchema;
72
79
  exports.poolPositionSchema = require_model_positions_schema.poolPositionSchema;
73
80
  exports.positionCollateralSchema = require_model_positions_schema.positionCollateralSchema;
81
+ exports.positionFilterQueryParamsSchema = require_model_positions_schema.positionFilterQueryParamsSchema;
82
+ exports.positionFilterQuerySchema = require_model_positions_schema.positionFilterQuerySchema;
74
83
  exports.positionFilterSchema = require_model_positions_schema.positionFilterSchema;
75
84
  exports.positionHistoryMetricSchema = require_model_history_schema.positionHistoryMetricSchema;
76
85
  exports.positionHistoryQuerySchema = require_model_history_schema.positionHistoryQuerySchema;
@@ -84,6 +93,8 @@ exports.quotaAssetSchema = require_model_opportunities_schema.quotaAssetSchema;
84
93
  exports.rateCurvePointSchema = require_model_opportunities_schema.rateCurvePointSchema;
85
94
  exports.rateCurveSchema = require_model_opportunities_schema.rateCurveSchema;
86
95
  exports.receivedAssetSchema = require_model_liquidations_schema.receivedAssetSchema;
96
+ exports.responseMetadataSchema = require_model_response_schema.responseMetadataSchema;
97
+ exports.responseSchema = require_model_response_schema.responseSchema;
87
98
  exports.rewardsPnLSchema = require_model_positions_schema.rewardsPnLSchema;
88
99
  exports.rewardsSchema = require_model_opportunities_schema.rewardsSchema;
89
100
  exports.strategyHistoryMetricSchema = require_model_history_schema.strategyHistoryMetricSchema;
@@ -14,7 +14,7 @@ const require_model_filters = require("./filters.js");
14
14
  **/
15
15
  function matchesLiquidatableAccountFilter(account, filter) {
16
16
  if (!filter) return true;
17
- if (require_model_filters.isFilterSet(filter.chainIds) && !filter.chainIds.includes(account.chainId)) return false;
17
+ if (filter.chainIds && !filter.chainIds.includes(account.chainId)) return false;
18
18
  if (require_model_filters.isFilterSet(filter.underlyingType) && account.totalValue.token.assetType !== filter.underlyingType) return false;
19
19
  if (require_model_filters.isFilterSet(filter.paused) && account.paused !== filter.paused) return false;
20
20
  if (require_model_filters.isFilterSet(filter.rwa) && account.rwa !== filter.rwa) return false;
@@ -12,7 +12,7 @@ let zod_v4 = require("zod/v4");
12
12
  * {@link LiquidatableAccountFilter}
13
13
  **/
14
14
  const liquidatableAccountFilterSchema = zod_v4.z.object({
15
- chainIds: require_model_filters_schema.filterable(zod_v4.z.array(require_model_primitives_schema.chainIdSchema)).optional(),
15
+ chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
16
16
  underlyingType: require_model_filters_schema.filterable(require_model_primitives_schema.assetTypeSchema).optional(),
17
17
  paused: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
18
18
  rwa: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
@@ -43,7 +43,7 @@ function opportunityId(opportunity) {
43
43
  function matchesOpportunityFilter(opportunity, filter) {
44
44
  if (!filter) return true;
45
45
  if (require_model_filters.isFilterSet(filter.kind) && opportunity.kind !== filter.kind) return false;
46
- if (require_model_filters.isFilterSet(filter.chainIds) && !filter.chainIds.includes(opportunity.chainId)) return false;
46
+ if (filter.chainIds && !filter.chainIds.includes(opportunity.chainId)) return false;
47
47
  if (require_model_filters.isFilterSet(filter.underlyingType) && opportunity.underlyingToken.assetType !== filter.underlyingType) return false;
48
48
  if (require_model_filters.isFilterSet(filter.paused) && opportunity.paused !== filter.paused) return false;
49
49
  if (require_model_filters.isFilterSet(filter.sunset) && opportunity.sunset !== filter.sunset) return false;
@@ -106,7 +106,7 @@ const opportunitySchema = zod_v4.z.discriminatedUnion("kind", [poolOpportunitySc
106
106
  **/
107
107
  const opportunityFilterSchema = zod_v4.z.object({
108
108
  kind: require_model_filters_schema.filterable(opportunityKindSchema).optional(),
109
- chainIds: require_model_filters_schema.filterable(zod_v4.z.array(require_model_primitives_schema.chainIdSchema)).optional(),
109
+ chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
110
110
  underlyingType: require_model_filters_schema.filterable(require_model_primitives_schema.assetTypeSchema).optional(),
111
111
  paused: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
112
112
  sunset: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
@@ -131,7 +131,7 @@ const opportunityFilterQuerySchema = zod_v4.z.codec(opportunityFilterQueryParams
131
131
  decode: (params) => {
132
132
  const filter = {};
133
133
  if (params.kind !== void 0) filter.kind = params.kind;
134
- if (params.chainIds !== void 0) filter.chainIds = decodeChainIds(params.chainIds);
134
+ if (params.chainIds !== void 0) filter.chainIds = params.chainIds === "" ? [] : params.chainIds.split(",").map(Number);
135
135
  if (params.underlyingType !== void 0) filter.underlyingType = params.underlyingType;
136
136
  if (params.paused !== void 0) filter.paused = params.paused === "true";
137
137
  if (params.sunset !== void 0) filter.sunset = params.sunset === "true";
@@ -140,20 +140,13 @@ const opportunityFilterQuerySchema = zod_v4.z.codec(opportunityFilterQueryParams
140
140
  },
141
141
  encode: (filter) => ({
142
142
  kind: require_model_filters.isFilterSet(filter.kind) ? filter.kind : void 0,
143
- chainIds: require_model_filters.isFilterSet(filter.chainIds) ? filter.chainIds.join(",") : void 0,
143
+ chainIds: filter.chainIds?.join(","),
144
144
  underlyingType: require_model_filters.isFilterSet(filter.underlyingType) ? filter.underlyingType : void 0,
145
- paused: encodeFlag(filter.paused),
146
- sunset: encodeFlag(filter.sunset),
147
- rwa: encodeFlag(filter.rwa)
145
+ paused: require_model_filters_schema.encodeFlag(filter.paused),
146
+ sunset: require_model_filters_schema.encodeFlag(filter.sunset),
147
+ rwa: require_model_filters_schema.encodeFlag(filter.rwa)
148
148
  })
149
149
  });
150
- function decodeChainIds(param) {
151
- return param === "" ? [] : param.split(",").map(Number);
152
- }
153
- function encodeFlag(condition) {
154
- if (!require_model_filters.isFilterSet(condition)) return;
155
- return condition ? "true" : "false";
156
- }
157
150
  /**
158
151
  * {@link RateCurvePoint}
159
152
  **/
@@ -65,7 +65,7 @@ function positionId(position) {
65
65
  function matchesPositionFilter(position, filter) {
66
66
  if (!filter) return true;
67
67
  if (require_model_filters.isFilterSet(filter.kind) && position.kind !== filter.kind) return false;
68
- if (require_model_filters.isFilterSet(filter.chainIds) && !filter.chainIds.includes(position.chainId)) return false;
68
+ if (filter.chainIds && !filter.chainIds.includes(position.chainId)) return false;
69
69
  if (require_model_filters.isFilterSet(filter.isZeroDebt) && position.kind === "strategy" && position.totalDebt.value === 0n !== filter.isZeroDebt) return false;
70
70
  if (require_model_filters.isFilterSet(filter.underlyingType)) {
71
71
  const underlying = positionUnderlying(position);
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sdk_utils_zod = require("../sdk/utils/zod.js");
3
+ const require_model_filters = require("./filters.js");
3
4
  const require_model_filters_schema = require("./filters.schema.js");
4
5
  const require_model_primitives_schema = require("./primitives.schema.js");
5
6
  const require_model_opportunities_schema = require("./opportunities.schema.js");
@@ -104,10 +105,39 @@ const positionSchema = zod_v4.z.discriminatedUnion("kind", [
104
105
  const positionFilterSchema = zod_v4.z.object({
105
106
  kind: require_model_filters_schema.filterable(positionKindSchema).optional(),
106
107
  isZeroDebt: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
107
- chainIds: require_model_filters_schema.filterable(zod_v4.z.array(require_model_primitives_schema.chainIdSchema)).optional(),
108
+ chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
108
109
  underlyingType: require_model_filters_schema.filterable(require_model_primitives_schema.assetTypeSchema).optional()
109
110
  });
110
111
  /**
112
+ * {@link PositionFilter} as a URL can carry it: every condition is a string,
113
+ * and a condition that does not narrow is absent rather than empty.
114
+ **/
115
+ const positionFilterQueryParamsSchema = zod_v4.z.object({
116
+ kind: positionKindSchema.optional(),
117
+ isZeroDebt: require_model_filters_schema.booleanParamSchema.optional(),
118
+ chainIds: zod_v4.z.string().regex(/^$|^\d+(,\d+)*$/).optional(),
119
+ underlyingType: require_model_primitives_schema.assetTypeSchema.optional()
120
+ });
121
+ /**
122
+ * Code for {@link PositionFilter} to encode/decode to/from url query parameters.
123
+ **/
124
+ const positionFilterQuerySchema = zod_v4.z.codec(positionFilterQueryParamsSchema, positionFilterSchema, {
125
+ decode: (params) => {
126
+ const filter = {};
127
+ if (params.kind !== void 0) filter.kind = params.kind;
128
+ if (params.isZeroDebt !== void 0) filter.isZeroDebt = params.isZeroDebt === "true";
129
+ if (params.chainIds !== void 0) filter.chainIds = params.chainIds === "" ? [] : params.chainIds.split(",").map(Number);
130
+ if (params.underlyingType !== void 0) filter.underlyingType = params.underlyingType;
131
+ return filter;
132
+ },
133
+ encode: (filter) => ({
134
+ kind: require_model_filters.isFilterSet(filter.kind) ? filter.kind : void 0,
135
+ isZeroDebt: require_model_filters_schema.encodeFlag(filter.isZeroDebt),
136
+ chainIds: filter.chainIds?.join(","),
137
+ underlyingType: require_model_filters.isFilterSet(filter.underlyingType) ? filter.underlyingType : void 0
138
+ })
139
+ });
140
+ /**
111
141
  * {@link PoolPositionKey}
112
142
  **/
113
143
  const poolPositionKeySchema = zod_v4.z.object({
@@ -139,6 +169,8 @@ exports.pointsRewardsPnLSchema = pointsRewardsPnLSchema;
139
169
  exports.poolPositionKeySchema = poolPositionKeySchema;
140
170
  exports.poolPositionSchema = poolPositionSchema;
141
171
  exports.positionCollateralSchema = positionCollateralSchema;
172
+ exports.positionFilterQueryParamsSchema = positionFilterQueryParamsSchema;
173
+ exports.positionFilterQuerySchema = positionFilterQuerySchema;
142
174
  exports.positionFilterSchema = positionFilterSchema;
143
175
  exports.positionKeySchema = positionKeySchema;
144
176
  exports.positionKindSchema = positionKindSchema;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -0,0 +1,64 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_primitives_schema = require("./primitives.schema.js");
3
+ let zod_v4 = require("zod/v4");
4
+ //#region src/model/response.schema.ts
5
+ /**
6
+ * Runtime schemas for {@link ./response.js}, see the note in
7
+ * `primitives.schema.ts` on why they are written by hand.
8
+ *
9
+ * `responseSchema(payloadSchema)` validates a successful backend 2xx body.
10
+ * HTTP and transport errors never pass through it.
11
+ **/
12
+ /**
13
+ * {@link DataSource}
14
+ **/
15
+ const dataSourceSchema = zod_v4.z.enum(["onchain", "offchain"]);
16
+ /**
17
+ * {@link ChainSucceeded}
18
+ *
19
+ * `source` may be omitted by the backend and decodes to `"offchain"`. The block
20
+ * has no such default: a success that omits it fails validation.
21
+ **/
22
+ const chainSucceededSchema = zod_v4.z.object({
23
+ chainId: require_model_primitives_schema.chainIdSchema,
24
+ status: zod_v4.z.literal("success"),
25
+ source: dataSourceSchema.default("offchain"),
26
+ blockNumber: zod_v4.z.number().int().nonnegative(),
27
+ timestamp: require_model_primitives_schema.timestampSchema
28
+ });
29
+ /**
30
+ * {@link ChainFailed}
31
+ *
32
+ * `error` is a `string` in a JSON body. The schema accepts `unknown` so the
33
+ * same codec also validates a locally produced envelope carrying an `Error`.
34
+ **/
35
+ const chainFailedSchema = zod_v4.z.object({
36
+ chainId: require_model_primitives_schema.chainIdSchema,
37
+ status: zod_v4.z.literal("error"),
38
+ source: dataSourceSchema.optional(),
39
+ error: zod_v4.z.unknown().optional()
40
+ });
41
+ /**
42
+ * {@link ChainMetadata}
43
+ **/
44
+ const chainMetadataSchema = zod_v4.z.discriminatedUnion("status", [chainSucceededSchema, chainFailedSchema]);
45
+ /**
46
+ * {@link ResponseMetadata}
47
+ **/
48
+ const responseMetadataSchema = zod_v4.z.object({ chains: zod_v4.z.array(chainMetadataSchema) });
49
+ /**
50
+ * {@link DataResponse} parameterized by the payload schema.
51
+ **/
52
+ function responseSchema(payloadSchema) {
53
+ return zod_v4.z.object({
54
+ data: payloadSchema,
55
+ meta: responseMetadataSchema
56
+ });
57
+ }
58
+ //#endregion
59
+ exports.chainFailedSchema = chainFailedSchema;
60
+ exports.chainMetadataSchema = chainMetadataSchema;
61
+ exports.chainSucceededSchema = chainSucceededSchema;
62
+ exports.dataSourceSchema = dataSourceSchema;
63
+ exports.responseMetadataSchema = responseMetadataSchema;
64
+ exports.responseSchema = responseSchema;
@@ -1,158 +1,76 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk_chain_chains = require("../sdk/chain/chains.js");
3
- const require_new_sdk_types = require("./types.js");
2
+ const require_new_sdk_errors_AllSourcesFailedError = require("./errors/AllSourcesFailedError.js");
3
+ const require_new_sdk_errors_everyChainFailed = require("./errors/everyChainFailed.js");
4
+ const require_new_sdk_errors_SourceUnavailableError = require("./errors/SourceUnavailableError.js");
5
+ require("./errors/index.js");
4
6
  //#region src/new-sdk/AbstractNamespace.ts
5
7
  /**
6
- * Shared machinery of every {@link GearboxSDK} namespace.
8
+ * Base class of every {@link GearboxSDK} namespace: holds the two source
9
+ * namespaces, exposes each on its own, and runs merged reads over both.
7
10
  *
8
- * A namespace is a stateless router: it asks the sources its mode allows, in
9
- * parallel, merges what came back and reports what did not. This class owns
10
- * that routing — per-chain failure capture, backend degradation, the response
11
- * envelope and the all-sources-failed rule — so a namespace holds nothing but
12
- * its reads and its merge policy.
13
- *
14
- * The sources are whatever it was handed, and their readiness is their owner's
15
- * business: a source that is not ready to answer fails the read it was given,
16
- * and that failure is reported like any other.
17
- *
18
- * All protocol knowledge lives in the sources: `MultichainSDK` for the chain,
19
- * `GearboxAPI` for the backend. None of it is repeated here or in a subclass.
20
- *
21
- * @typeParam ListRow - Row type of the namespace's list read.
11
+ * @typeParam Onchain - On-chain source namespace, e.g.
12
+ * `MultichainOpportunitiesService`.
13
+ * @typeParam Offchain - Backend source namespace, e.g. `OffchainOpportunities`.
22
14
  **/
23
15
  var AbstractNamespace = class {
16
+ /**
17
+ * How far the backend may lag the chain and still serve a chain.
18
+ **/
19
+ maxOffchainLagSeconds;
24
20
  logger;
21
+ #name;
25
22
  #onchain;
26
23
  #offchain;
27
- constructor(name, onchain, offchain, logger) {
24
+ constructor(name, onchain, offchain, options) {
25
+ this.#name = name;
28
26
  this.#onchain = onchain;
29
27
  this.#offchain = offchain;
30
- this.logger = logger?.child?.({ name }) ?? logger;
31
- }
32
- /**
33
- * Asks both sources in parallel and combines whatever answered.
34
- *
35
- * The action name is only used in diagnostics and in the error raised when
36
- * every source the read had failed.
37
- **/
38
- async read(action, fromChain, fromBackend, combine) {
39
- const [onchain, offchain] = await Promise.all([this.fromChain(fromChain), this.fromBackend(fromBackend)]);
40
- const meta = toMeta(onchain, offchain);
41
- this.assertAnySourceSucceeded(action, meta);
42
- return {
43
- result: combine(onchain.value, offchain.value),
44
- meta
45
- };
46
- }
47
- /**
48
- * Reads the namespace's list from both sources, unioned by
49
- * {@link AbstractNamespace.mergeList}.
50
- **/
51
- async readList(action, fromChain, fromBackend) {
52
- return this.read(action, fromChain, fromBackend, (onchain, offchain) => this.mergeList(onchain ?? [], offchain ?? []));
28
+ this.maxOffchainLagSeconds = options.maxOffchainLagSeconds;
29
+ this.logger = options.logger?.child?.({ name }) ?? options.logger;
53
30
  }
54
31
  /**
55
- * Reads one row from both sources and merges them under
56
- * {@link AbstractNamespace.mergeOne}. The key names the chain, so the
57
- * on-chain leg queries exactly one.
32
+ * The on-chain source namespace on its own. Throws
33
+ * {@link SourceUnavailableError} in `offchain` mode.
58
34
  **/
59
- async readOne(action, chainId, fromChain, fromBackend) {
60
- return this.read(action, async (sdk) => {
61
- const network = this.networkOf(chainId);
62
- if (!network) return { chains: [] };
63
- return this.onOneChain(action, network, () => fromChain(sdk));
64
- }, fromBackend, (onchain, offchain) => {
65
- if (onchain && offchain) return this.mergeOne(onchain, offchain);
66
- return onchain ?? offchain;
67
- });
35
+ get onchain() {
36
+ if (!this.#onchain) throw new require_new_sdk_errors_SourceUnavailableError.SourceUnavailableError(this.#name, "onchain");
37
+ return this.#onchain;
68
38
  }
69
39
  /**
70
- * Reads something only the backend can answer.
71
- *
72
- * The fallback stands in for a backend that answered with nothing, which is
73
- * a different thing from a backend that failed and was dropped.
40
+ * The backend source namespace on its own. Throws
41
+ * {@link SourceUnavailableError} in `onchain` mode.
74
42
  **/
75
- async readOffchain(action, fromBackend, fallback) {
76
- const offchain = await this.fromBackend(fromBackend);
77
- const meta = toMeta({ chains: [] }, offchain);
78
- this.assertAnySourceSucceeded(action, meta);
79
- return {
80
- result: offchain.value ?? fallback,
81
- meta
82
- };
43
+ get offchain() {
44
+ if (!this.#offchain) throw new require_new_sdk_errors_SourceUnavailableError.SourceUnavailableError(this.#name, "offchain");
45
+ return this.#offchain;
83
46
  }
84
47
  /**
85
- * Runs a read against the chain, or reports the chain as absent when the
86
- * namespace has no on-chain source at all.
48
+ * Asks both sources at once and merges what came back, failing only when no
49
+ * chain was served at all.
87
50
  **/
88
- async fromChain(run) {
89
- return this.#onchain ? run(this.#onchain) : { chains: [] };
51
+ async merged(action, query) {
52
+ const onchain = this.#onchain;
53
+ const offchain = this.#offchain;
54
+ const [fromChain, fromBackend] = await Promise.all([this.#ask(action, "onchain", onchain, query.fromChain), this.#ask(action, "offchain", offchain, query.fromBackend)]);
55
+ const merged = query.merge(fromChain.response, fromBackend.response);
56
+ if (merged && !require_new_sdk_errors_everyChainFailed.everyChainFailed(merged.meta)) return merged;
57
+ const sole = onchain && offchain ? void 0 : fromChain.error ?? fromBackend.error;
58
+ if (sole !== void 0) throw sole;
59
+ throw new require_new_sdk_errors_AllSourcesFailedError.AllSourcesFailedError(action, [fromChain.error, fromBackend.error], merged?.meta);
90
60
  }
91
61
  /**
92
- * Runs a read against the backend, turning any rejection into metadata so
93
- * that a dead backend degrades a `both`-mode read instead of failing it.
62
+ * Runs one source's leg of a read, skipping a source this mode does not have
63
+ * and turning a rejection into an outcome.
94
64
  **/
95
- async fromBackend(run) {
96
- if (!this.#offchain) return {};
65
+ async #ask(action, label, source, run) {
66
+ if (source === void 0) return {};
97
67
  try {
98
- const { result, meta } = await run(this.#offchain);
99
- return {
100
- value: meta.status === "success" ? result : void 0,
101
- status: meta
102
- };
68
+ return { response: await run(source) };
103
69
  } catch (error) {
104
- this.logger?.warn(error, "offchain read failed");
105
- return { status: {
106
- status: "error",
107
- error
108
- } };
109
- }
110
- }
111
- /**
112
- * Runs a read against one chain, turning a rejection into that chain's
113
- * metadata entry.
114
- **/
115
- async onOneChain(action, network, run) {
116
- try {
117
- return {
118
- value: await run(),
119
- chains: [{
120
- network,
121
- status: "success"
122
- }]
123
- };
124
- } catch (error) {
125
- this.logger?.warn(error, `failed to ${action} on ${network}`);
126
- return { chains: [{
127
- network,
128
- status: "error",
129
- error
130
- }] };
131
- }
132
- }
133
- /**
134
- * A read that reached at least one source returns what it has; a read where
135
- * every source it had failed throws, because an empty result would otherwise
136
- * be indistinguishable from "there is nothing here".
137
- **/
138
- assertAnySourceSucceeded(action, meta) {
139
- const asked = meta.chains.length > 0 || meta.offchain !== void 0;
140
- const answered = meta.chains.some((c) => c.status === "success") || meta.offchain?.status === "success";
141
- if (asked && !answered) throw new require_new_sdk_types.AllSourcesFailedError(action, meta);
142
- }
143
- networkOf(chainId) {
144
- try {
145
- return require_sdk_chain_chains.getNetworkType(chainId);
146
- } catch {
147
- this.logger?.debug(`chain ${chainId} is not a Gearbox network, skipping the onchain source`);
148
- return;
70
+ this.logger?.warn(error, `failed to ${action} from the ${label} source`);
71
+ return { error };
149
72
  }
150
73
  }
151
74
  };
152
- function toMeta(onchain, offchain) {
153
- const meta = { chains: onchain.chains };
154
- if (offchain.status) meta.offchain = offchain.status;
155
- return meta;
156
- }
157
75
  //#endregion
158
76
  exports.AbstractNamespace = AbstractNamespace;