@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,28 +1,54 @@
1
1
  import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
2
2
  import { PoolHistoryMetric, StrategyHistoryMetric } from "../../model/history.js";
3
+ import { DataResponse } from "../../model/response.js";
3
4
  import "../../model/index.js";
4
- import { Mode, ReadResult } from "../types.js";
5
+ import { MultichainOpportunitiesService } from "../../sdk/opportunities/MultichainOpportunitiesService.js";
6
+ import "../../sdk/index.js";
7
+ import { OffchainOpportunities } from "../../offchain/opportunities/OffchainOpportunities.js";
8
+ import "../../offchain/index.js";
9
+ import { Mode } from "../types.js";
5
10
  import { HistoryReader } from "../utils/history.js";
11
+ import { SourceMerger } from "../utils/types.js";
12
+ import "../utils/index.js";
6
13
  //#region src/new-sdk/opportunities/types.d.ts
7
14
  /**
8
- * Reads every mode supports, because either source alone can answer them.
15
+ * What the `opportunities` namespace offers in every mode.
9
16
  **/
10
17
  interface OpportunitiesBase {
11
18
  /**
12
- * All pool and strategy opportunities, optionally narrowed.
13
- *
14
- * In `both` mode the two lists are unioned by canonical opportunity id and
15
- * merged field-wise, with the chain winning any field both sources fill.
19
+ * All pool and strategy opportunities, optionally narrowed. In `both` mode
20
+ * each chain is served by whichever source is fresh enough, see
21
+ * {@link OpportunityMergers}.
16
22
  **/
17
- list(filter?: OpportunityFilter): Promise<ReadResult<Opportunity[]>>;
23
+ list(filter?: OpportunityFilter): Promise<DataResponse<Opportunity[]>>;
18
24
  /**
19
25
  * Detailed view of one pool opportunity.
20
26
  **/
21
- getPool(key: PoolOpportunityKey): Promise<ReadResult<PoolOpportunityDetail>>;
27
+ getPool(key: PoolOpportunityKey): Promise<DataResponse<PoolOpportunityDetail>>;
22
28
  /**
23
29
  * Detailed view of one strategy opportunity.
24
30
  **/
25
- getStrategy(key: StrategyOpportunityKey): Promise<ReadResult<StrategyOpportunityDetail>>;
31
+ getStrategy(key: StrategyOpportunityKey): Promise<DataResponse<StrategyOpportunityDetail>>;
32
+ /**
33
+ * Narrows an already-read list, rows and metadata alike. `undefined` passes
34
+ * through, so a read still in flight stays that way.
35
+ **/
36
+ filter(response: DataResponse<Opportunity[]> | undefined, filter?: OpportunityFilter): DataResponse<Opportunity[]> | undefined;
37
+ /**
38
+ * The chain on its own, for a consumer that shows each source as it arrives.
39
+ * Throws in `offchain` mode.
40
+ **/
41
+ readonly onchain: MultichainOpportunitiesService;
42
+ /**
43
+ * The backend on its own, see {@link OpportunitiesBase.onchain}. Throws in
44
+ * `onchain` mode.
45
+ **/
46
+ readonly offchain: OffchainOpportunities;
47
+ /**
48
+ * Merge policy of each read, for a consumer combining the two branches
49
+ * itself, see {@link OpportunityMergers}.
50
+ **/
51
+ readonly merge: OpportunityMergers;
26
52
  }
27
53
  /**
28
54
  * Reads only a backend can answer.
@@ -30,37 +56,65 @@ interface OpportunitiesBase {
30
56
  interface OpportunitiesOffchainOnly {
31
57
  /**
32
58
  * Historical charts of one opportunity, one metric and one range at a time:
33
- * `history(key).chart("depositApy", "1m")`.
34
- *
35
- * The key's kind decides which metrics exist, so asking a pool for a
36
- * strategy series does not compile.
37
- *
38
- * Absent in `onchain` mode: the chain serves the present, and rebuilding a
39
- * series from it would mean an archive read per point.
59
+ * `history(key).chart("depositApy", "1m")`. The key's kind decides which
60
+ * metrics exist, so asking a pool for a strategy series does not compile.
40
61
  **/
41
62
  history(key: PoolOpportunityRef): HistoryReader<PoolHistoryMetric>;
42
63
  history(key: StrategyOpportunityRef): HistoryReader<StrategyHistoryMetric>;
43
64
  }
44
65
  /**
45
- * Reads only the chain can answer. Empty for now — every on-chain read the
46
- * namespace exposes has a backend counterpart.
66
+ * Reads only the chain can answer. Empty for now.
47
67
  **/
48
68
  interface OpportunitiesOnchainOnly {}
69
+ /**
70
+ * How each read combines what the two sources returned: a chain is served by
71
+ * the backend when it is fresh enough, and by the chain otherwise.
72
+ **/
73
+ interface OpportunityMergers {
74
+ list: SourceMerger<Opportunity[]>;
75
+ pool: SourceMerger<PoolOpportunityDetail>;
76
+ strategy: SourceMerger<StrategyOpportunityDetail>;
77
+ }
78
+ /**
79
+ * Which reads the `opportunities` namespace has in each mode. A widened mode
80
+ * offers what every mode has, i.e. {@link OpportunitiesBase} alone.
81
+ **/
82
+ interface OpportunitiesOnchainBranch {
83
+ readonly onchain: MultichainOpportunitiesService;
84
+ }
85
+ /**
86
+ * The backend on its own, see {@link OpportunitiesOnchainBranch}.
87
+ **/
88
+ interface OpportunitiesOffchainBranch {
89
+ readonly offchain: OffchainOpportunities;
90
+ }
91
+ /**
92
+ * Merge policy of each read, exposed so that a consumer reading the two
93
+ * branches itself combines them exactly as `both` mode would: a chain is served
94
+ * by the backend when it is fresh enough, and by the chain otherwise.
95
+ **/
96
+ interface OpportunityMergers {
97
+ list: SourceMerger<Opportunity[]>;
98
+ pool: SourceMerger<PoolOpportunityDetail>;
99
+ strategy: SourceMerger<StrategyOpportunityDetail>;
100
+ }
101
+ /**
102
+ * Merging, which only exists where there are two sources to merge.
103
+ **/
104
+ interface OpportunitiesMerged {
105
+ readonly merge: OpportunityMergers;
106
+ }
49
107
  /**
50
108
  * Which methods the `opportunities` namespace has in each mode.
51
- *
52
- * A lookup map rather than a conditional type: `both` is spelled out instead of
53
- * being inferred, and a widened mode degrades to the intersection of what all
54
- * modes offer rather than silently distributing into a union of everything.
55
109
  **/
56
110
  interface OpportunitiesByMode {
57
- onchain: OpportunitiesBase & OpportunitiesOnchainOnly;
58
- offchain: OpportunitiesBase & OpportunitiesOffchainOnly;
59
- both: OpportunitiesBase & OpportunitiesOffchainOnly & OpportunitiesOnchainOnly;
111
+ onchain: OpportunitiesBase & OpportunitiesOnchainOnly & OpportunitiesOnchainBranch;
112
+ offchain: OpportunitiesBase & OpportunitiesOffchainOnly & OpportunitiesOffchainBranch;
113
+ both: OpportunitiesBase & OpportunitiesOnchainOnly & OpportunitiesOffchainOnly;
60
114
  }
61
115
  /**
62
116
  * The `opportunities` namespace of a {@link GearboxSDK} in mode `M`.
63
117
  **/
64
118
  type Opportunities<M extends Mode = Mode> = OpportunitiesByMode[M];
65
119
  //#endregion
66
- export { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly };
120
+ export { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesMerged, OpportunitiesOffchainBranch, OpportunitiesOffchainOnly, OpportunitiesOnchainBranch, OpportunitiesOnchainOnly, OpportunityMergers };
@@ -1,62 +1,41 @@
1
- import { ILogger } from "../../sdk/types/logger.js";
2
1
  import { PoolPositionRef, Position, PositionFilter, StrategyPositionRef } from "../../model/positions.js";
3
2
  import { PoolPositionHistoryMetric, StrategyPositionHistoryMetric } from "../../model/history.js";
3
+ import { DataResponse } from "../../model/response.js";
4
4
  import "../../model/index.js";
5
5
  import { MultichainSDK } from "../../sdk/MultichainSDK.js";
6
6
  import "../../sdk/index.js";
7
7
  import { GearboxAPI } from "../../offchain/GearboxAPI.js";
8
8
  import "../../offchain/index.js";
9
- import { ReadResult } from "../types.js";
10
- import { AbstractNamespace } from "../AbstractNamespace.js";
9
+ import { NamespaceOptions } from "../types.js";
11
10
  import { HistoryReader } from "../utils/history.js";
12
11
  import "../utils/index.js";
13
- import { PositionsBase, PositionsOffchainOnly } from "./types.js";
12
+ import { AbstractNamespace } from "../AbstractNamespace.js";
13
+ import { PositionMergers, PositionsBase, PositionsOffchainOnly } from "./types.js";
14
14
  import { Address } from "viem";
15
15
  //#region src/new-sdk/positions/PositionsNamespace.d.ts
16
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.
17
+ * The `positions` namespace of a {@link GearboxSDK}, see
18
+ * {@link PositionsByMode} for what each mode offers.
26
19
  **/
27
- declare class PositionsNamespace extends AbstractNamespace<Position> implements PositionsBase, PositionsOffchainOnly {
28
- #private;
29
- constructor(onchain: MultichainSDK | undefined, offchain: GearboxAPI | undefined, logger?: ILogger);
20
+ declare class PositionsNamespace extends AbstractNamespace<MultichainSDK["positions"], GearboxAPI["positions"]> implements PositionsBase, PositionsOffchainOnly {
30
21
  /**
31
- * {@inheritDoc PositionsBase.list}
22
+ * {@inheritDoc PositionsBase.merge}
32
23
  **/
33
- list(wallet: Address, filter?: PositionFilter): Promise<ReadResult<Position[]>>;
24
+ readonly merge: PositionMergers;
25
+ constructor(onchain: MultichainSDK | undefined, offchain: GearboxAPI | undefined, options: NamespaceOptions);
34
26
  /**
35
- * {@inheritDoc PositionsOffchainOnly.history}
27
+ * {@inheritDoc PositionsBase.list}
36
28
  **/
37
- history(key: PoolPositionRef): HistoryReader<PoolPositionHistoryMetric>;
38
- history(key: StrategyPositionRef): HistoryReader<StrategyPositionHistoryMetric>;
29
+ list(wallet: Address, filter?: PositionFilter): Promise<DataResponse<Position[]>>;
39
30
  /**
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.
31
+ * {@inheritDoc PositionsBase.filter}
49
32
  **/
50
- protected mergeOne<T extends object>(onchain: T, offchain: T): T;
33
+ filter(response: DataResponse<Position[]> | undefined, filter?: PositionFilter): DataResponse<Position[]> | undefined;
51
34
  /**
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.
35
+ * {@inheritDoc PositionsOffchainOnly.history}
58
36
  **/
59
- protected mergeList(onchain: Position[], offchain: Position[]): Position[];
37
+ history(key: PoolPositionRef): HistoryReader<PoolPositionHistoryMetric>;
38
+ history(key: StrategyPositionRef): HistoryReader<StrategyPositionHistoryMetric>;
60
39
  }
61
40
  //#endregion
62
41
  export { PositionsNamespace };
@@ -1,3 +1,3 @@
1
- import { Positions, PositionsBase, PositionsByMode, PositionsOffchainOnly, PositionsOnchainOnly } from "./types.js";
1
+ import { PositionMergers, Positions, PositionsBase, PositionsByMode, PositionsMerged, PositionsOffchainBranch, PositionsOffchainOnly, PositionsOnchainBranch, PositionsOnchainOnly } from "./types.js";
2
2
  import { PositionsNamespace } from "./PositionsNamespace.js";
3
- export { Positions, PositionsBase, PositionsByMode, PositionsNamespace, PositionsOffchainOnly, PositionsOnchainOnly };
3
+ export { PositionMergers, Positions, PositionsBase, PositionsByMode, PositionsMerged, PositionsNamespace, PositionsOffchainBranch, PositionsOffchainOnly, PositionsOnchainBranch, PositionsOnchainOnly };
@@ -1,22 +1,48 @@
1
1
  import { PoolPositionRef, Position, PositionFilter, StrategyPositionRef } from "../../model/positions.js";
2
2
  import { PoolPositionHistoryMetric, StrategyPositionHistoryMetric } from "../../model/history.js";
3
+ import { DataResponse } from "../../model/response.js";
3
4
  import "../../model/index.js";
4
- import { Mode, ReadResult } from "../types.js";
5
+ import { MultichainPositionsService } from "../../sdk/positions/MultichainPositionsService.js";
6
+ import "../../sdk/index.js";
7
+ import { OffchainPositions } from "../../offchain/positions/OffchainPositions.js";
8
+ import "../../offchain/index.js";
9
+ import { Mode } from "../types.js";
5
10
  import { HistoryReader } from "../utils/history.js";
11
+ import { SourceMerger } from "../utils/types.js";
12
+ import "../utils/index.js";
6
13
  import { Address } from "viem";
7
14
  //#region src/new-sdk/positions/types.d.ts
8
15
  /**
9
- * Reads every mode supports, because either source alone can answer them.
16
+ * What the `positions` namespace offers in every mode.
10
17
  **/
11
18
  interface PositionsBase {
12
19
  /**
13
20
  * 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.
21
+ * delayed withdrawals it took over by liquidating, optionally narrowed. In
22
+ * `both` mode each chain is served by whichever source is fresh enough, see
23
+ * {@link PositionMergers}.
18
24
  **/
19
- list(wallet: Address, filter?: PositionFilter): Promise<ReadResult<Position[]>>;
25
+ list(wallet: Address, filter?: PositionFilter): Promise<DataResponse<Position[]>>;
26
+ /**
27
+ * Narrows an already-read list, rows and metadata alike. `undefined` passes
28
+ * through, so a read still in flight stays that way.
29
+ **/
30
+ filter(response: DataResponse<Position[]> | undefined, filter?: PositionFilter): DataResponse<Position[]> | undefined;
31
+ /**
32
+ * The chain on its own, for a consumer that shows each source as it arrives.
33
+ * Throws in `offchain` mode.
34
+ **/
35
+ readonly onchain: MultichainPositionsService;
36
+ /**
37
+ * The backend on its own, see {@link PositionsBase.onchain}. Throws in
38
+ * `onchain` mode.
39
+ **/
40
+ readonly offchain: OffchainPositions;
41
+ /**
42
+ * Merge policy of each read, for a consumer combining the two branches
43
+ * itself, see {@link PositionMergers}.
44
+ **/
45
+ readonly merge: PositionMergers;
20
46
  }
21
47
  /**
22
48
  * Reads only a backend can answer.
@@ -24,39 +50,63 @@ interface PositionsBase {
24
50
  interface PositionsOffchainOnly {
25
51
  /**
26
52
  * 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.
53
+ * `history(key).chart("netApy", "1m")`. The key's kind decides which metrics
54
+ * exist, so asking a pool position for a strategy series does not compile.
55
+ * Liquidation positions have no charts: a delayed withdrawal is a single
56
+ * event rather than a series.
36
57
  **/
37
58
  history(key: PoolPositionRef): HistoryReader<PoolPositionHistoryMetric>;
38
59
  history(key: StrategyPositionRef): HistoryReader<StrategyPositionHistoryMetric>;
39
60
  }
40
61
  /**
41
- * Reads only the chain can answer. Empty for now — every on-chain read the
42
- * namespace exposes has a backend counterpart.
62
+ * Reads only the chain can answer. Empty for now.
43
63
  **/
44
64
  interface PositionsOnchainOnly {}
65
+ /**
66
+ * How each read combines what the two sources returned: a chain is served by
67
+ * the backend when it is fresh enough, and by the chain otherwise.
68
+ **/
69
+ interface PositionMergers {
70
+ list: SourceMerger<Position[]>;
71
+ }
72
+ /**
73
+ * Which reads the `positions` namespace has in each mode. A widened mode offers
74
+ * what every mode has, i.e. {@link PositionsBase} alone.
75
+ **/
76
+ interface PositionsOnchainBranch {
77
+ readonly onchain: MultichainPositionsService;
78
+ }
79
+ /**
80
+ * The backend on its own, see {@link PositionsOnchainBranch}.
81
+ **/
82
+ interface PositionsOffchainBranch {
83
+ readonly offchain: OffchainPositions;
84
+ }
85
+ /**
86
+ * Merge policy of each read, exposed so that a consumer reading the two
87
+ * branches itself combines them exactly as `both` mode would: a chain is served
88
+ * by the backend when it is fresh enough, and by the chain otherwise.
89
+ **/
90
+ interface PositionMergers {
91
+ list: SourceMerger<Position[]>;
92
+ }
93
+ /**
94
+ * Merging, which only exists where there are two sources to merge.
95
+ **/
96
+ interface PositionsMerged {
97
+ readonly merge: PositionMergers;
98
+ }
45
99
  /**
46
100
  * 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
101
  **/
52
102
  interface PositionsByMode {
53
103
  onchain: PositionsBase & PositionsOnchainOnly;
54
104
  offchain: PositionsBase & PositionsOffchainOnly;
55
- both: PositionsBase & PositionsOffchainOnly & PositionsOnchainOnly;
105
+ both: PositionsBase & PositionsOnchainOnly & PositionsOffchainOnly;
56
106
  }
57
107
  /**
58
108
  * The `positions` namespace of a {@link GearboxSDK} in mode `M`.
59
109
  **/
60
110
  type Positions<M extends Mode = Mode> = PositionsByMode[M];
61
111
  //#endregion
62
- export { Positions, PositionsBase, PositionsByMode, PositionsOffchainOnly, PositionsOnchainOnly };
112
+ export { PositionMergers, Positions, PositionsBase, PositionsByMode, PositionsMerged, PositionsOffchainBranch, PositionsOffchainOnly, PositionsOnchainBranch, PositionsOnchainOnly };
@@ -1,6 +1,5 @@
1
1
  import { ILogger } from "../sdk/types/logger.js";
2
2
  import { NetworkType } from "../sdk/chain/chains.js";
3
- import { MultichainNetworkMeta } from "../sdk/types/multichain.js";
4
3
  import { MultichainAttachOptions, MultichainSDK, MultichainSDKOptions } from "../sdk/MultichainSDK.js";
5
4
  import "../sdk/index.js";
6
5
  import { GearboxAPIOptions } from "../offchain/types.js";
@@ -8,89 +7,25 @@ import { GearboxAPI } from "../offchain/GearboxAPI.js";
8
7
  import "../offchain/index.js";
9
8
  //#region src/new-sdk/types.d.ts
10
9
  /**
11
- * Which sources a {@link GearboxSDK} reads from. Fixed at construction: a
12
- * running instance never changes mode, and the mode decides which methods
13
- * exist at all rather than what they return.
10
+ * Which sources a {@link GearboxSDK} reads from, and therefore which of its
11
+ * methods exist.
14
12
  **/
15
13
  type Mode = "onchain" | "offchain" | "both";
16
14
  /**
17
- * Outcome of the off-chain read behind a response.
18
- **/
19
- interface OffchainSourceStatus {
20
- /**
21
- * Whether the backend served the request.
22
- **/
23
- status: "success" | "error";
24
- /**
25
- * Rejection reason. Only set when {@link status} is `"error"`.
26
- **/
27
- error?: unknown;
28
- }
29
- /**
30
- * Which sources produced a response and which of them failed.
31
- *
32
- * Meta is always present, in every mode. A partial answer is the normal case
33
- * for a multi-chain read, so a caller that ignores this block is choosing to
34
- * treat "one chain is down" as "these opportunities do not exist".
35
- **/
36
- interface SourceMeta {
37
- /**
38
- * Outcome per queried chain. Empty when the read touched no chain, either
39
- * because the SDK is off-chain or because a filter selected no chain.
40
- **/
41
- chains: MultichainNetworkMeta[];
42
- /**
43
- * Outcome of the off-chain read, absent when the SDK has no backend source.
44
- **/
45
- offchain?: OffchainSourceStatus;
46
- }
47
- /**
48
- * What every {@link GearboxSDK} read returns.
49
- *
50
- * @typeParam T - Payload type.
51
- **/
52
- interface ReadResult<T> {
53
- /**
54
- * Requested payload, built from every source that answered.
55
- **/
56
- result: T;
57
- /**
58
- * Which sources produced it, see {@link SourceMeta}.
59
- **/
60
- meta: SourceMeta;
61
- }
62
- /**
63
- * Thrown when a read had sources to ask and none of them answered.
64
- *
65
- * A read that partially succeeded never throws: it returns what it has and
66
- * reports the rest in {@link SourceMeta}.
67
- **/
68
- declare class AllSourcesFailedError extends Error {
69
- /**
70
- * Outcome of every source the failed read asked.
71
- **/
72
- readonly meta: SourceMeta;
73
- constructor(action: string, meta: SourceMeta);
74
- }
75
- /**
76
- * On-chain source of a {@link GearboxSDK}: either an already-attached SDK to
77
- * reuse, or the options to build one with.
78
- *
79
- * An injected instance is never re-attached — its owner decides when it syncs.
15
+ * On-chain source of a {@link GearboxSDK}: either an SDK to reuse, which its
16
+ * owner keeps attaching itself, or the options to build one with.
80
17
  **/
81
18
  type OnchainSource = MultichainSDK | PlainMultichainSDKOptions;
82
19
  /**
83
20
  * {@link MultichainSDKOptions} without plugin typing.
84
- *
85
- * The facade exposes the on-chain SDK as a plain `MultichainSDK`; a consumer
86
- * that injects a plugin-typed instance keeps its own typed reference to it.
87
21
  **/
88
22
  type PlainMultichainSDKOptions = MultichainSDKOptions<{}>;
89
23
  /**
90
24
  * Off-chain source of a {@link GearboxSDK}: either a client to reuse or the
91
- * options to build one with.
25
+ * options to build one with. The chains come from
26
+ * {@link GearboxSDKOptions.networks} either way.
92
27
  **/
93
- type OffchainSource = GearboxAPI | GearboxAPIOptions;
28
+ type OffchainSource = GearboxAPI | Omit<GearboxAPIOptions, "chainIds">;
94
29
  /**
95
30
  * Options for creating a {@link GearboxSDK}.
96
31
  *
@@ -102,9 +37,8 @@ interface GearboxSDKOptions<M extends Mode = Mode> {
102
37
  **/
103
38
  mode: M;
104
39
  /**
105
- * Chains the SDK covers. This list is authoritative: when {@link onchain} is
106
- * an already-attached instance covering a different set of chains, the
107
- * mismatch is logged and this list still decides what is read.
40
+ * Chains the SDK covers, which every read of every source is scoped to. An
41
+ * injected source covering a different set is rejected at construction.
108
42
  **/
109
43
  networks: NetworkType[];
110
44
  /**
@@ -115,14 +49,27 @@ interface GearboxSDKOptions<M extends Mode = Mode> {
115
49
  * Off-chain source. Required in `offchain` and `both` mode.
116
50
  **/
117
51
  offchain?: OffchainSource;
52
+ /**
53
+ * How many seconds the backend may lag the chain and still serve a chain in
54
+ * `both` mode, see {@link DEFAULT_MAX_OFFCHAIN_LAG}.
55
+ **/
56
+ maxOffchainLagSeconds?: number;
118
57
  /**
119
58
  * Options passed to {@link MultichainSDK.attach}, used only when the SDK
120
59
  * builds the on-chain source itself.
121
60
  **/
122
61
  attach?: MultichainAttachOptions;
62
+ logger?: ILogger;
63
+ }
64
+ /**
65
+ * What a {@link GearboxSDK} hands every namespace it builds.
66
+ **/
67
+ interface NamespaceOptions {
123
68
  /**
124
- * Logger for source selection and degradation diagnostics.
69
+ * How far the backend may lag the chain, see
70
+ * {@link GearboxSDKOptions.maxOffchainLagSeconds}.
125
71
  **/
72
+ maxOffchainLagSeconds: number;
126
73
  logger?: ILogger;
127
74
  }
128
75
  /**
@@ -146,4 +93,4 @@ interface OffchainByMode {
146
93
  both: GearboxAPI;
147
94
  }
148
95
  //#endregion
149
- export { AllSourcesFailedError, GearboxSDKOptions, Mode, OffchainByMode, OffchainSource, OffchainSourceStatus, OnchainByMode, OnchainSource, PlainMultichainSDKOptions, ReadResult, SourceMeta };
96
+ export { GearboxSDKOptions, Mode, NamespaceOptions, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, PlainMultichainSDKOptions };
@@ -0,0 +1,16 @@
1
+ import { ChainScopedFilter } from "../../model/filters.js";
2
+ import { DataResponse } from "../../model/response.js";
3
+ import "../../model/index.js";
4
+ //#region src/new-sdk/utils/filterResponse.d.ts
5
+ /**
6
+ * Narrows an already-read list, rows and metadata alike. `undefined` passes
7
+ * through, so a read still in flight stays that way.
8
+ *
9
+ * @typeParam T - Row type.
10
+ * @typeParam F - Filter type.
11
+ * @param matches - Whether one row satisfies the filter, e.g.
12
+ * `matchesOpportunityFilter`.
13
+ **/
14
+ declare function filterResponse<T, F extends ChainScopedFilter>(response: DataResponse<T[]> | undefined, filter: F | undefined, matches: (row: T, filter?: F) => boolean): DataResponse<T[]> | undefined;
15
+ //#endregion
16
+ export { filterResponse };
@@ -1,48 +1,18 @@
1
- import { HistoryChartMetadata, HistoryPoint, HistoryRange } from "../../model/history.js";
1
+ import { HistoryRange, HistorySeries } from "../../model/history.js";
2
+ import { DataResponse } from "../../model/response.js";
2
3
  import "../../model/index.js";
3
- import { SourceMeta } from "../types.js";
4
4
  //#region src/new-sdk/utils/history.d.ts
5
- /**
6
- * Everything that annotates a chart: what the backend said about the series,
7
- * plus which sources produced it.
8
- **/
9
- interface ChartMetadata extends HistoryChartMetadata {
10
- /**
11
- * Which sources answered, see {@link SourceMeta}. A chart is backend-only,
12
- * so this reports the backend alone.
13
- **/
14
- source: SourceMeta;
15
- }
16
- /**
17
- * One chart: the points to draw and everything that annotates them.
18
- **/
19
- interface Chart {
20
- /**
21
- * Samples, oldest first.
22
- **/
23
- data: HistoryPoint[];
24
- /**
25
- * Annotations of the series, see {@link ChartMetadata}.
26
- **/
27
- metadata: ChartMetadata;
28
- }
29
5
  /**
30
6
  * Reads the charts of one subject, one metric and one range at a time.
31
7
  *
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
- *
36
8
  * @typeParam Metric - Metrics the subject has.
37
9
  **/
38
10
  interface HistoryReader<Metric extends string> {
39
11
  /**
40
- * Historical chart of one metric over one window.
41
- *
42
- * A metric the subject does not have is a compile error rather than an empty
43
- * chart.
12
+ * Historical chart of one metric over one window. A metric the subject does
13
+ * not have is a compile error.
44
14
  **/
45
- chart(metric: Metric, range: HistoryRange): Promise<Chart>;
15
+ chart(metric: Metric, range: HistoryRange): Promise<DataResponse<HistorySeries<Metric>>>;
46
16
  }
47
17
  //#endregion
48
- export { Chart, ChartMetadata, HistoryReader };
18
+ export { HistoryReader };
@@ -1,2 +1,5 @@
1
- import { Chart, ChartMetadata, HistoryReader } from "./history.js";
2
- export { Chart, ChartMetadata, HistoryReader };
1
+ import { filterResponse } from "./filterResponse.js";
2
+ import { HistoryReader } from "./history.js";
3
+ import { DEFAULT_MAX_OFFCHAIN_LAG, mergeChainList, mergeChainOne } from "./mergeChains.js";
4
+ import { SourceMerger } from "./types.js";
5
+ export { DEFAULT_MAX_OFFCHAIN_LAG, HistoryReader, type SourceMerger, filterResponse, mergeChainList, mergeChainOne };
@@ -0,0 +1,20 @@
1
+ import { ChainScoped, DataResponse } from "../../model/response.js";
2
+ import "../../model/index.js";
3
+ //#region src/new-sdk/utils/mergeChains.d.ts
4
+ /**
5
+ * How many seconds the backend may lag the chain and still be used.
6
+ **/
7
+ declare const DEFAULT_MAX_OFFCHAIN_LAG = 120;
8
+ /**
9
+ * Merges two lists chain by chain: a chain is served by the backend when it is
10
+ * within `maxLagSeconds` of the chain, by the chain otherwise, and reported as
11
+ * an error when neither source succeeded.
12
+ **/
13
+ declare function mergeChainList<T extends ChainScoped>(onchain: DataResponse<T[]> | undefined, offchain: DataResponse<T[]> | undefined, maxLagSeconds?: number): DataResponse<T[]> | undefined;
14
+ /**
15
+ * Merges two versions of one entity under the same freshness rule as
16
+ * {@link mergeChainList}, returning the winning response whole.
17
+ **/
18
+ declare function mergeChainOne<T>(onchain: DataResponse<T> | undefined, offchain: DataResponse<T> | undefined, maxLagSeconds?: number): DataResponse<T> | undefined;
19
+ //#endregion
20
+ export { DEFAULT_MAX_OFFCHAIN_LAG, mergeChainList, mergeChainOne };
@@ -0,0 +1,11 @@
1
+ import { DataResponse } from "../../model/response.js";
2
+ import "../../model/index.js";
3
+ //#region src/new-sdk/utils/types.d.ts
4
+ /**
5
+ * How one read combines what the two sources returned.
6
+ *
7
+ * @typeParam T - Payload type of the read.
8
+ **/
9
+ type SourceMerger<T> = (onchain: DataResponse<T> | undefined, offchain: DataResponse<T> | undefined) => DataResponse<T> | undefined;
10
+ //#endregion
11
+ export { SourceMerger };