@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
@@ -0,0 +1,19 @@
1
+ import { BaseError } from "viem";
2
+ //#region src/offchain/errors/OffchainNotConfiguredError.ts
3
+ /**
4
+ * Thrown when a read is issued against a client that was never told where the
5
+ * backend is.
6
+ **/
7
+ var OffchainNotConfiguredError = class extends BaseError {
8
+ name = "OffchainNotConfiguredError";
9
+ /**
10
+ * Path that was read, below the base URL that is missing.
11
+ **/
12
+ path;
13
+ constructor(path) {
14
+ super("No baseUrl was configured for the Gearbox backend.", { metaMessages: [`Path: ${path}`] });
15
+ this.path = path;
16
+ }
17
+ };
18
+ //#endregion
19
+ export { OffchainNotConfiguredError };
@@ -0,0 +1,18 @@
1
+ import { BaseError } from "viem";
2
+ //#region src/offchain/errors/OffchainNotImplementedError.ts
3
+ /**
4
+ * Thrown by the endpoints that are not implemented yet.
5
+ **/
6
+ var OffchainNotImplementedError = class extends BaseError {
7
+ name = "OffchainNotImplementedError";
8
+ /**
9
+ * Endpoint that was asked for.
10
+ **/
11
+ endpoint;
12
+ constructor(endpoint) {
13
+ super("This Gearbox backend endpoint is not implemented yet.", { metaMessages: [`Endpoint: ${endpoint}`] });
14
+ this.endpoint = endpoint;
15
+ }
16
+ };
17
+ //#endregion
18
+ export { OffchainNotImplementedError };
@@ -0,0 +1,23 @@
1
+ import { OffchainTransportError } from "./OffchainTransportError.js";
2
+ //#region src/offchain/errors/OffchainRequestFailedError.ts
3
+ /**
4
+ * Thrown when a request to the backend never completed: the network was down,
5
+ * or it took longer than {@link GearboxAPIOptions.timeout}.
6
+ **/
7
+ var OffchainRequestFailedError = class extends OffchainTransportError {
8
+ name = "OffchainRequestFailedError";
9
+ constructor(url, cause) {
10
+ super(timedOut(cause) ? "The request to the Gearbox backend timed out." : "The request to the Gearbox backend failed.", {
11
+ url,
12
+ cause
13
+ });
14
+ }
15
+ };
16
+ /**
17
+ * Whether a caught value is the rejection `AbortSignal.timeout` produces.
18
+ **/
19
+ function timedOut(error) {
20
+ return error instanceof Error && error.name === "TimeoutError";
21
+ }
22
+ //#endregion
23
+ export { OffchainRequestFailedError };
@@ -0,0 +1,19 @@
1
+ import { backendMessage } from "./backendMessage.js";
2
+ import { OffchainTransportError } from "./OffchainTransportError.js";
3
+ //#region src/offchain/errors/OffchainStatusError.ts
4
+ /**
5
+ * Thrown when the backend answered with a status outside the 2xx range. What it
6
+ * said about it, when it said anything, is the `details` of the error.
7
+ **/
8
+ var OffchainStatusError = class extends OffchainTransportError {
9
+ name = "OffchainStatusError";
10
+ constructor(url, status, body) {
11
+ super(`The Gearbox backend answered ${status}.`, {
12
+ url,
13
+ status,
14
+ details: backendMessage(body)
15
+ });
16
+ }
17
+ };
18
+ //#endregion
19
+ export { OffchainStatusError };
@@ -0,0 +1,30 @@
1
+ import { errorCause } from "./errorCause.js";
2
+ import { BaseError } from "viem";
3
+ //#region src/offchain/errors/OffchainTransportError.ts
4
+ /**
5
+ * Thrown when the backend could not be reached, or answered with something
6
+ * other than a JSON body in the 2xx range. Its subclasses say which of the
7
+ * three it was; catch this one to catch all of them.
8
+ **/
9
+ var OffchainTransportError = class extends BaseError {
10
+ /**
11
+ * URL that was requested, query included.
12
+ **/
13
+ url;
14
+ /**
15
+ * Status the backend answered with, absent when the request never completed.
16
+ **/
17
+ status;
18
+ constructor(shortMessage, params) {
19
+ const caught = errorCause(params.cause);
20
+ super(shortMessage, {
21
+ cause: caught.cause,
22
+ details: caught.details ?? params.details,
23
+ metaMessages: [`URL: ${params.url}`, ...params.status === void 0 ? [] : [`Status: ${params.status}`]]
24
+ });
25
+ this.url = params.url;
26
+ this.status = params.status;
27
+ }
28
+ };
29
+ //#endregion
30
+ export { OffchainTransportError };
@@ -0,0 +1,25 @@
1
+ import { BaseError } from "viem";
2
+ import { z } from "zod/v4";
3
+ //#region src/offchain/errors/OffchainValidationError.ts
4
+ /**
5
+ * Thrown when the backend answered, but with a payload the read model does not
6
+ * describe, i.e. the two are of different versions.
7
+ **/
8
+ var OffchainValidationError = class extends BaseError {
9
+ name = "OffchainValidationError";
10
+ /**
11
+ * URL whose payload failed to validate.
12
+ **/
13
+ url;
14
+ /**
15
+ * The zod failure itself, e.g. for `z.treeifyError(error.zodError)`.
16
+ **/
17
+ zodError;
18
+ constructor(url, zodError) {
19
+ super("The Gearbox backend response does not match the read model.", { metaMessages: [`URL: ${url}`, ...z.prettifyError(zodError).split("\n")] });
20
+ this.url = url;
21
+ this.zodError = zodError;
22
+ }
23
+ };
24
+ //#endregion
25
+ export { OffchainValidationError };
@@ -0,0 +1,27 @@
1
+ //#region src/offchain/errors/backendMessage.ts
2
+ const MAX_LENGTH = 200;
3
+ /**
4
+ * Why a non-2xx response failed, in the backend's own words: the `message` of a
5
+ * Gearbox backend error body, the whole body when it is not one, and nothing
6
+ * when it said nothing at all.
7
+ **/
8
+ function backendMessage(body) {
9
+ if (!body) return;
10
+ const message = parsedMessage(body) ?? body.trim();
11
+ return message ? truncate(message) : void 0;
12
+ }
13
+ /**
14
+ * The `message` of a Gearbox backend error body, or nothing when the body is
15
+ * not one.
16
+ **/
17
+ function parsedMessage(body) {
18
+ try {
19
+ const parsed = JSON.parse(body);
20
+ if (typeof parsed === "object" && parsed !== null && "message" in parsed && typeof parsed.message === "string") return parsed.message;
21
+ } catch {}
22
+ }
23
+ function truncate(text) {
24
+ return text.length > MAX_LENGTH ? `${text.slice(0, MAX_LENGTH)}…` : text;
25
+ }
26
+ //#endregion
27
+ export { backendMessage };
@@ -0,0 +1,11 @@
1
+ //#region src/offchain/errors/errorCause.ts
2
+ /**
3
+ * Turns a caught `unknown` into what viem's `BaseError` takes: it types `cause`
4
+ * as an `Error`, so anything else can only be reported as `details`.
5
+ **/
6
+ function errorCause(error) {
7
+ if (error === void 0) return {};
8
+ return error instanceof Error ? { cause: error } : { details: String(error) };
9
+ }
10
+ //#endregion
11
+ export { errorCause };
@@ -0,0 +1,11 @@
1
+ import { backendMessage } from "./backendMessage.js";
2
+ import { errorCause } from "./errorCause.js";
3
+ import { OffchainTransportError } from "./OffchainTransportError.js";
4
+ import { OffchainInvalidJsonError } from "./OffchainInvalidJsonError.js";
5
+ import { OffchainNotConfiguredError } from "./OffchainNotConfiguredError.js";
6
+ import { OffchainNotImplementedError } from "./OffchainNotImplementedError.js";
7
+ import { OffchainRequestFailedError } from "./OffchainRequestFailedError.js";
8
+ import { OffchainStatusError } from "./OffchainStatusError.js";
9
+ import { OffchainValidationError } from "./OffchainValidationError.js";
10
+ import { readResponseBody } from "./readResponseBody.js";
11
+ export { OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
@@ -0,0 +1,14 @@
1
+ //#region src/offchain/errors/readResponseBody.ts
2
+ /**
3
+ * Body of a failed response as text, or nothing when it cannot be read: a
4
+ * failure explaining a failure is not itself worth throwing.
5
+ **/
6
+ async function readResponseBody(response) {
7
+ try {
8
+ return await response.text();
9
+ } catch {
10
+ return;
11
+ }
12
+ }
13
+ //#endregion
14
+ export { readResponseBody };
@@ -1,8 +1,19 @@
1
- import { OffchainNotConfiguredError, OffchainNotImplementedError, OffchainTransportError, OffchainValidationError } from "./types.js";
1
+ import { backendMessage } from "./errors/backendMessage.js";
2
+ import { errorCause } from "./errors/errorCause.js";
3
+ import { OffchainTransportError } from "./errors/OffchainTransportError.js";
4
+ import { OffchainInvalidJsonError } from "./errors/OffchainInvalidJsonError.js";
5
+ import { OffchainNotConfiguredError } from "./errors/OffchainNotConfiguredError.js";
6
+ import { OffchainNotImplementedError } from "./errors/OffchainNotImplementedError.js";
7
+ import { OffchainRequestFailedError } from "./errors/OffchainRequestFailedError.js";
8
+ import { OffchainStatusError } from "./errors/OffchainStatusError.js";
9
+ import { OffchainValidationError } from "./errors/OffchainValidationError.js";
10
+ import { readResponseBody } from "./errors/readResponseBody.js";
11
+ import "./errors/index.js";
2
12
  import { AbstractOffchainNamespace } from "./AbstractOffchainNamespace.js";
3
13
  import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
4
14
  import "./opportunities/index.js";
5
15
  import { OffchainPositions } from "./positions/OffchainPositions.js";
6
16
  import "./positions/index.js";
7
17
  import { GearboxAPI } from "./GearboxAPI.js";
8
- export { AbstractOffchainNamespace, GearboxAPI, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainTransportError, OffchainValidationError };
18
+ import "./types.js";
19
+ export { AbstractOffchainNamespace, GearboxAPI, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
@@ -11,13 +11,16 @@ var OffchainOpportunities = class extends AbstractOffchainNamespace {
11
11
  super("OffchainOpportunities", options);
12
12
  }
13
13
  /**
14
- * All opportunities the backend knows about, optionally narrowed by
15
- * {@link OpportunityFilter}.
14
+ * Opportunities of the chains this client covers, optionally narrowed further
15
+ * by {@link OpportunityFilter}.
16
16
  **/
17
17
  async list(filter) {
18
18
  return this.get({
19
19
  path: this.#root,
20
- query: filter ? z.encode(opportunityFilterQuerySchema, filter) : void 0,
20
+ query: z.encode(opportunityFilterQuerySchema, {
21
+ ...filter,
22
+ chainIds: this.scopedChainIds(filter)
23
+ }),
21
24
  schema: z.array(opportunitySchema)
22
25
  });
23
26
  }
@@ -1,47 +1,41 @@
1
+ import { positionFilterQuerySchema, positionSchema } from "../../model/positions.schema.js";
1
2
  import { AbstractOffchainNamespace } from "../AbstractOffchainNamespace.js";
3
+ import { z } from "zod/v4";
2
4
  //#region src/offchain/positions/OffchainPositions.ts
3
5
  /**
4
6
  * Backend counterpart of the `positions` namespace.
5
7
  **/
6
8
  var OffchainPositions = class extends AbstractOffchainNamespace {
9
+ #root = "/v2/positions";
7
10
  constructor(options) {
8
11
  super("OffchainPositions", options);
9
12
  }
10
13
  /**
11
14
  * Everything a wallet holds, optionally narrowed by {@link PositionFilter}.
12
- *
13
- * @returns An empty list until the backend client is implemented.
14
15
  **/
15
- async list(wallet, filter) {
16
- this.logger?.debug({
17
- wallet,
18
- filter
19
- }, "offchain positions list is not implemented, serving empty list");
20
- return {
21
- result: [],
22
- meta: { status: "success" }
23
- };
16
+ async list(props) {
17
+ return this.get({
18
+ path: `${this.#root}/${props.wallet}`,
19
+ query: z.encode(positionFilterQuerySchema, {
20
+ ...props.filter,
21
+ chainIds: this.scopedChainIds(props.filter)
22
+ }),
23
+ schema: z.array(positionSchema)
24
+ });
24
25
  }
25
26
  /**
26
- * One historical series of one position. History exists only here: rebuilding
27
- * it from the chain would mean an archive read per point.
28
- *
29
- * The requested metric types the response, so a caller asking for one metric
30
- * does not have to narrow the union back down. When the transport lands,
31
- * validation is what upholds it: a response carrying a different metric than
32
- * the one asked for is a version-skew error like any other.
27
+ * One historical series of one position.
33
28
  *
34
29
  * @returns An empty series until the backend client is implemented.
35
30
  **/
36
31
  async getHistory(query) {
37
- this.logger?.debug({ query }, "offchain positions history is not implemented, serving empty series");
38
32
  return {
39
- result: {
33
+ data: {
40
34
  metric: query.metric,
41
35
  points: [],
42
36
  metadata: {}
43
37
  },
44
- meta: { status: "success" }
38
+ meta: { chains: [] }
45
39
  };
46
40
  }
47
41
  };
@@ -1,72 +1 @@
1
- //#region src/offchain/types.ts
2
- /**
3
- * Thrown by the endpoints that have no stub answer, so that a caller in
4
- * `offchain` mode fails loudly instead of reading an empty detail page as a
5
- * missing entity.
6
- *
7
- * Lives here rather than in one namespace because every stubbed namespace
8
- * throws it.
9
- **/
10
- var OffchainNotImplementedError = class extends Error {
11
- constructor(endpoint) {
12
- super(`GearboxAPI: ${endpoint} is not implemented yet`);
13
- this.name = "OffchainNotImplementedError";
14
- }
15
- };
16
- /**
17
- * Thrown when a read is issued against a client that was never told where the
18
- * backend is.
19
- **/
20
- var OffchainNotConfiguredError = class extends Error {
21
- constructor(path) {
22
- super(`GearboxAPI: cannot read ${path}, no baseUrl was configured`);
23
- this.name = "OffchainNotConfiguredError";
24
- }
25
- };
26
- /**
27
- * Thrown when the backend could not be reached, or answered with a status
28
- * outside the 2xx range.
29
- **/
30
- var OffchainTransportError = class extends Error {
31
- /**
32
- * URL that was requested, query included.
33
- **/
34
- url;
35
- /**
36
- * Status the backend answered with, absent when the request never completed.
37
- **/
38
- status;
39
- constructor(url, reason, status) {
40
- super(`GearboxAPI: request to ${url} failed, ${reason}`);
41
- this.name = "OffchainTransportError";
42
- this.url = url;
43
- this.status = status;
44
- }
45
- };
46
- /**
47
- * Thrown when the backend answered, but with a payload the read model does not
48
- * describe.
49
- *
50
- * This is version skew rather than a bad request, and it is deliberately
51
- * handled like a transport error: the combined SDK drops the backend's
52
- * contribution in `both` mode and fails the read in `offchain` mode.
53
- **/
54
- var OffchainValidationError = class extends Error {
55
- /**
56
- * URL whose payload failed to validate.
57
- **/
58
- url;
59
- /**
60
- * What did not match, in the order zod reported it.
61
- **/
62
- issues;
63
- constructor(url, issues) {
64
- const summary = issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ");
65
- super(`GearboxAPI: response from ${url} does not match the model, ${summary}`);
66
- this.name = "OffchainValidationError";
67
- this.url = url;
68
- this.issues = issues;
69
- }
70
- };
71
- //#endregion
72
- export { OffchainNotConfiguredError, OffchainNotImplementedError, OffchainTransportError, OffchainValidationError };
1
+ export {};
@@ -1,5 +1,5 @@
1
- import { ierc4626AdapterAbi } from "../../../abi/ierc4626Adapter.js";
2
1
  import { MissingSerializedParamsError } from "../../../sdk/base/errors.js";
2
+ import { ierc4626AdapterAbi } from "../../../abi/ierc4626Adapter.js";
3
3
  import "../../../sdk/index.js";
4
4
  import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
5
5
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
@@ -1,5 +1,5 @@
1
- import { iZapperAbi } from "../../abi/iZapper.js";
2
1
  import { iPoolV310Abi } from "../../abi/310/generated.js";
2
+ import { iZapperAbi } from "../../abi/iZapper.js";
3
3
  import { asPreviewSimulationError } from "./errors.js";
4
4
  //#region src/preview/simulate/simulatePoolOperation.ts
5
5
  function previewRead(operation) {
@@ -1,6 +1,6 @@
1
- import { ierc20Abi } from "../../abi/iERC20.js";
2
1
  import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
3
2
  import { AddressMap } from "../../sdk/utils/AddressMap.js";
3
+ import { ierc20Abi } from "../../abi/iERC20.js";
4
4
  import "../../sdk/index.js";
5
5
  import { UnexpectedFacadeEventOrderError } from "./errors.js";
6
6
  import { getAddress, isAddressEqual, parseEventLogs } from "viem";
@@ -1,9 +1,9 @@
1
1
  import { getNetworkType } from "./chain/chains.js";
2
- import { ChainNotConfiguredError, SdkMissingChainStateError, SdkStateVersionMismatchError, SdkSyncFailedError } from "./core/errors.js";
3
2
  import { PriceUpdatesCache } from "./market/pricefeeds/updates/PriceUpdatesCache.js";
4
3
  import "./market/pricefeeds/updates/index.js";
5
4
  import { MultichainLiquidationsService } from "./accounts/liquidations/MultichainLiquidationsService.js";
6
5
  import "./accounts/index.js";
6
+ import { ChainNotConfiguredError, SdkMissingChainStateError, SdkStateVersionMismatchError, SdkSyncFailedError } from "./core/errors.js";
7
7
  import "./core/index.js";
8
8
  import { MultichainOpportunitiesService } from "./opportunities/MultichainOpportunitiesService.js";
9
9
  import "./opportunities/index.js";
@@ -8,7 +8,6 @@ import { formatTimestamp } from "./utils/formatter.js";
8
8
  import { toAddress } from "./utils/toAddress.js";
9
9
  import "./utils/index.js";
10
10
  import { ChainContractsRegister } from "./base/ChainContractsRegister.js";
11
- import { SdkAlreadyAttachedError, SdkChainMismatchError, SdkNotAttachedError, SdkStateVersionMismatchError } from "./core/errors.js";
12
11
  import "./base/index.js";
13
12
  import { executeDelegatedMulticalls } from "./utils/viem/executeDelegatedMulticalls.js";
14
13
  import "./utils/viem/index.js";
@@ -23,6 +22,7 @@ import { createRedemptionLogger } from "./accounts/withdrawal-compressor/createR
23
22
  import { createWithdrawalCompressor } from "./accounts/withdrawal-compressor/createWithdrawalCompressor.js";
24
23
  import "./accounts/index.js";
25
24
  import { createAddressProvider, hydrateAddressProvider } from "./core/createAddressProvider.js";
25
+ import { SdkAlreadyAttachedError, SdkChainMismatchError, SdkNotAttachedError, SdkStateVersionMismatchError } from "./core/errors.js";
26
26
  import "./core/index.js";
27
27
  import { OpportunitiesService } from "./opportunities/OpportunitiesService.js";
28
28
  import "./opportunities/index.js";
@@ -1,5 +1,3 @@
1
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
3
1
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
4
2
  import { ADDRESS_0X0 } from "../constants/addresses.js";
5
3
  import { MAX_UINT256 } from "../constants/math.js";
@@ -10,6 +8,8 @@ import "../base/index.js";
10
8
  import { AccountBotsService } from "./bots/AccountBotsService.js";
11
9
  import "./bots/index.js";
12
10
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
11
+ import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
12
+ import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
13
13
  import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
14
14
  import "../market/index.js";
15
15
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
@@ -108,7 +108,7 @@ var CreditAccountCompressor = class extends SDKConstruct {
108
108
  async getBorrowerCreditAccounts(borrower, options, blockNumber) {
109
109
  const { creditManager, includeZeroDebt = false, maxHealthFactor = MAX_UINT256, minHealthFactor = 0n, ignoreReservePrices = false } = options ?? {};
110
110
  const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
111
- const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
111
+ const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower, void 0, blockNumber)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
112
112
  const cmFilter = creditManager ? {
113
113
  configurators: [],
114
114
  creditManagers: [creditManager],
@@ -178,13 +178,13 @@ var CreditAccountCompressor = class extends SDKConstruct {
178
178
  * @param props - {@link ListStrategyPositionsProps}
179
179
  **/
180
180
  async listPositions(props) {
181
- const { owner, includeZeroDebt } = props;
182
- const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
181
+ const { owner, includeZeroDebt, blockNumber } = props;
182
+ const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber), this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber)]);
183
183
  const describable = accounts.filter((ca) => {
184
184
  if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
185
185
  return ca.success;
186
186
  });
187
- const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
187
+ const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
188
188
  return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new AddressMap()));
189
189
  }
190
190
  /**
@@ -235,13 +235,13 @@ var CreditAccountCompressor = class extends SDKConstruct {
235
235
  * Delayed withdrawals of one account, keyed by the phantom token that
236
236
  * represents them on it, so that each collateral row can pick up its own.
237
237
  **/
238
- async #accountWithdrawals(ca) {
238
+ async #accountWithdrawals(ca, blockNumber) {
239
239
  const compressor = this.sdk.withdrawalCompressor;
240
240
  const byPhantomToken = new AddressMap(void 0, "accountWithdrawals");
241
241
  const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
242
242
  if (!compressor || !holdsPhantomToken) return byPhantomToken;
243
243
  const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
244
- const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
244
+ const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
245
245
  const add = (w, outputs, claimableAt) => {
246
246
  const assets = outputs.map((o) => ({
247
247
  isDelayed: true,
@@ -1,4 +1,3 @@
1
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
2
1
  import { AddressSet } from "../../utils/AddressSet.js";
3
2
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
4
3
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -20,6 +19,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
20
19
  import "../../market/rwa/securitize/index.js";
21
20
  import "../../market/index.js";
22
21
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
22
+ import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
23
23
  //#region src/sdk/accounts/liquidations/LiquidationsService.ts
24
24
  /**
25
25
  * Service for discovering liquidatable credit accounts and previewing manual
@@ -32,13 +32,13 @@ var LiquidationsService = class extends SDKConstruct {
32
32
  * Accounts whose collateral computation failed are excluded.
33
33
  **/
34
34
  async getLiquidatableAccounts(props) {
35
- await this.sdk.withdrawalCompressor?.loadWithdrawableAssets();
35
+ await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, props?.blockNumber);
36
36
  const unhealthy = await this.sdk.accounts.getCreditAccounts({
37
37
  maxHealthFactor: WAD - 1n,
38
38
  includeZeroDebt: false
39
- });
39
+ }, props?.blockNumber);
40
40
  const seen = new AddressSet(unhealthy.map((ca) => ca.creditAccount));
41
- let expired = await this.#getExpiredCreditAccounts();
41
+ let expired = await this.#getExpiredCreditAccounts(props?.blockNumber);
42
42
  expired = expired.filter((ca) => !seen.has(ca.creditAccount));
43
43
  return [...unhealthy, ...expired].flatMap((ca) => {
44
44
  if (!ca.success) {
@@ -55,13 +55,13 @@ var LiquidationsService = class extends SDKConstruct {
55
55
  * @throws When the account is not found or its collateral computation fails.
56
56
  **/
57
57
  async getLiquidationDetails(props) {
58
- const { creditAccount, liquidator, ignoreReservePrices } = props;
59
- const ca = await this.#getCreditAccountData(creditAccount);
58
+ const { creditAccount, liquidator, ignoreReservePrices, blockNumber } = props;
59
+ const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
60
60
  const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
61
61
  const { priceOracle } = suite.market;
62
- await this.sdk.withdrawalCompressor?.loadWithdrawableAssets();
62
+ await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber);
63
63
  const account = this.#buildAccount(ca, suite);
64
- const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices);
64
+ const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices, blockNumber);
65
65
  return {
66
66
  ...account,
67
67
  repaymentAmount: priceOracle.toTokenAmount(hexEq(data.requiredToken, "0x0000000000000000000000000000000000000000") ? account.totalValue.token.address : data.requiredToken, data.requiredAmount),
@@ -79,9 +79,9 @@ var LiquidationsService = class extends SDKConstruct {
79
79
  * the debt from own funds and receiving the collateral from the credit account.
80
80
  **/
81
81
  async buildLiquidationTx(props) {
82
- const { creditAccount, liquidator, ignoreReservePrices } = props;
83
- const ca = await this.#getCreditAccountData(creditAccount);
84
- const { liquidationCall } = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices);
82
+ const { creditAccount, liquidator, ignoreReservePrices, blockNumber } = props;
83
+ const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
84
+ const { liquidationCall } = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices, blockNumber);
85
85
  this.logger?.debug(`built tx to liquidate credit account ${this.labelAddress(creditAccount)} to ${this.labelAddress(liquidator)}`);
86
86
  return {
87
87
  to: liquidationCall.target,
@@ -96,9 +96,13 @@ var LiquidationsService = class extends SDKConstruct {
96
96
  async getLiquidationPositions(props) {
97
97
  const compressor = this.sdk.withdrawalCompressor;
98
98
  if (!compressor) return [];
99
- await compressor.loadWithdrawableAssets();
99
+ await compressor.loadWithdrawableAssets(void 0, props.blockNumber);
100
100
  const phantomTokens = new AddressSet(compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken));
101
- const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals(props.liquidator, ...phantomTokens.asArray());
101
+ const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals({
102
+ account: props.liquidator,
103
+ withdrawalTokens: phantomTokens.asArray(),
104
+ blockNumber: props.blockNumber
105
+ });
102
106
  return [...claimable.map((w) => ({
103
107
  ...this.#liquidationPosition(w.token, w.outputs),
104
108
  claimTx: this.#claimTx(w.claimCalls, w.token),
@@ -114,7 +118,7 @@ var LiquidationsService = class extends SDKConstruct {
114
118
  * deployed for the markets of the chain and registers them in the SDK
115
119
  * contracts register.
116
120
  **/
117
- async loadRWALiquidators() {
121
+ async loadRWALiquidators(props) {
118
122
  const configurators = this.sdk.marketRegister.marketConfigurators;
119
123
  if (configurators.length === 0) return;
120
124
  const resp = await this.client.multicall({
@@ -125,7 +129,8 @@ var LiquidationsService = class extends SDKConstruct {
125
129
  args: [mc.address]
126
130
  })),
127
131
  allowFailure: false,
128
- batchSize: 0
132
+ batchSize: 0,
133
+ blockNumber: props?.blockNumber
129
134
  });
130
135
  for (const info of resp.flat()) this.#createRWALiquidator(info);
131
136
  }
@@ -211,13 +216,13 @@ var LiquidationsService = class extends SDKConstruct {
211
216
  ...priceOracle.toTokenAmount(requiredToken, requiredAmount * (PERCENTAGE_FACTOR + LIQUIDATION_APPROVAL_BUFFER) / PERCENTAGE_FACTOR)
212
217
  };
213
218
  }
214
- async #getCreditAccountData(creditAccount) {
215
- const ca = await this.sdk.accounts.getCreditAccountData(creditAccount);
219
+ async #getCreditAccountData(creditAccount, blockNumber) {
220
+ const ca = await this.sdk.accounts.getCreditAccountData(creditAccount, blockNumber);
216
221
  if (!ca) throw new Error(`credit account ${creditAccount} not found`);
217
222
  if (!ca.success) throw new Error(`cannot compute liquidation details for ${creditAccount}: collateral computation failed`);
218
223
  return ca;
219
224
  }
220
- async #getLiquidationData(ca, liquidator = ADDRESS_0X0, ignoreReservePrices) {
225
+ async #getLiquidationData(ca, liquidator = ADDRESS_0X0, ignoreReservePrices, blockNumber) {
221
226
  const priceUpdates = await this.sdk.accounts.getOnDemandPriceUpdates(ca, ignoreReservePrices);
222
227
  const { result } = await this.client.simulateContract({
223
228
  address: LIQUIDATION_COMPRESSOR_V313_ADDRESS,
@@ -227,11 +232,12 @@ var LiquidationsService = class extends SDKConstruct {
227
232
  liquidator,
228
233
  ca.creditAccount,
229
234
  priceUpdates
230
- ]
235
+ ],
236
+ blockNumber
231
237
  });
232
238
  return result;
233
239
  }
234
- async #getExpiredCreditAccounts() {
240
+ async #getExpiredCreditAccounts(blockNumber) {
235
241
  const expiredCMs = [];
236
242
  for (const market of this.sdk.marketRegister.markets) {
237
243
  if (market.pool.pool.totalBorrowed === 0n) continue;
@@ -245,7 +251,7 @@ var LiquidationsService = class extends SDKConstruct {
245
251
  return (await Promise.all(expiredCMs.map((creditManager) => this.sdk.accounts.getCreditAccounts({
246
252
  creditManager,
247
253
  includeZeroDebt: false
248
- })))).flat();
254
+ }, blockNumber)))).flat();
249
255
  }
250
256
  #buildAccount(ca, suite = this.sdk.marketRegister.findCreditManager(ca.creditManager)) {
251
257
  const market = suite.market;