@gearbox-protocol/sdk 14.12.0-next.81 → 14.12.0-next.83

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 (200) 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 +3 -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.schema.js +9 -6
  11. package/dist/cjs/new-sdk/AbstractNamespace.js +46 -128
  12. package/dist/cjs/new-sdk/GearboxSDK.js +55 -42
  13. package/dist/cjs/new-sdk/errors/AllSourcesFailedError.js +20 -0
  14. package/dist/cjs/new-sdk/errors/MissingSourceError.js +25 -0
  15. package/dist/cjs/new-sdk/errors/NoSourceServedError.js +20 -0
  16. package/dist/cjs/new-sdk/errors/SourceChainMismatchError.js +34 -0
  17. package/dist/cjs/new-sdk/errors/SourceUnavailableError.js +25 -0
  18. package/dist/cjs/new-sdk/errors/assertSameChains.js +12 -0
  19. package/dist/cjs/new-sdk/errors/everyChainFailed.js +11 -0
  20. package/dist/cjs/new-sdk/errors/index.js +15 -0
  21. package/dist/cjs/new-sdk/index.js +23 -3
  22. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +37 -89
  23. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +27 -94
  24. package/dist/cjs/new-sdk/types.js +0 -21
  25. package/dist/cjs/new-sdk/utils/filterResponse.js +12 -0
  26. package/dist/cjs/new-sdk/utils/index.js +6 -0
  27. package/dist/cjs/new-sdk/utils/mergeChains.js +76 -0
  28. package/dist/cjs/new-sdk/utils/types.js +1 -0
  29. package/dist/cjs/offchain/AbstractOffchainNamespace.js +42 -65
  30. package/dist/cjs/offchain/GearboxAPI.js +12 -8
  31. package/dist/cjs/offchain/errors/OffchainInvalidJsonError.js +19 -0
  32. package/dist/cjs/offchain/errors/OffchainNotConfiguredError.js +20 -0
  33. package/dist/cjs/offchain/errors/OffchainNotImplementedError.js +19 -0
  34. package/dist/cjs/offchain/errors/OffchainRequestFailedError.js +24 -0
  35. package/dist/cjs/offchain/errors/OffchainStatusError.js +20 -0
  36. package/dist/cjs/offchain/errors/OffchainTransportError.js +31 -0
  37. package/dist/cjs/offchain/errors/OffchainValidationError.js +26 -0
  38. package/dist/cjs/offchain/errors/backendMessage.js +28 -0
  39. package/dist/cjs/offchain/errors/errorCause.js +12 -0
  40. package/dist/cjs/offchain/errors/index.js +21 -0
  41. package/dist/cjs/offchain/errors/readResponseBody.js +15 -0
  42. package/dist/cjs/offchain/index.js +22 -5
  43. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +6 -3
  44. package/dist/cjs/offchain/positions/OffchainPositions.js +15 -21
  45. package/dist/cjs/offchain/types.js +0 -75
  46. package/dist/cjs/sdk/MultichainSDK.js +1 -1
  47. package/dist/cjs/sdk/OnchainSDK.js +1 -1
  48. package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
  49. package/dist/cjs/sdk/base/MultichainConstruct.js +73 -34
  50. package/dist/cjs/sdk/chain/chains.js +11 -0
  51. package/dist/cjs/sdk/chain/index.js +1 -0
  52. package/dist/cjs/sdk/core/index.js +1 -1
  53. package/dist/cjs/sdk/index.js +2 -1
  54. package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
  55. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +1 -4
  56. package/dist/cjs/sdk/positions/MultichainPositionsService.js +6 -29
  57. package/dist/cjs/sdk/positions/PositionsService.js +1 -2
  58. package/dist/esm/dev/AccountOpener.js +1 -1
  59. package/dist/esm/dev/withdrawalUtils.js +1 -1
  60. package/dist/esm/model/filters.js +0 -4
  61. package/dist/esm/model/filters.schema.js +10 -2
  62. package/dist/esm/model/index.js +3 -3
  63. package/dist/esm/model/liquidations.js +1 -1
  64. package/dist/esm/model/liquidations.schema.js +1 -1
  65. package/dist/esm/model/opportunities.js +1 -1
  66. package/dist/esm/model/opportunities.schema.js +4 -11
  67. package/dist/esm/model/positions.js +1 -1
  68. package/dist/esm/model/positions.schema.js +33 -3
  69. package/dist/esm/model/response.schema.js +9 -6
  70. package/dist/esm/new-sdk/AbstractNamespace.js +46 -128
  71. package/dist/esm/new-sdk/GearboxSDK.js +55 -42
  72. package/dist/esm/new-sdk/errors/AllSourcesFailedError.js +19 -0
  73. package/dist/esm/new-sdk/errors/MissingSourceError.js +24 -0
  74. package/dist/esm/new-sdk/errors/NoSourceServedError.js +19 -0
  75. package/dist/esm/new-sdk/errors/SourceChainMismatchError.js +33 -0
  76. package/dist/esm/new-sdk/errors/SourceUnavailableError.js +24 -0
  77. package/dist/esm/new-sdk/errors/assertSameChains.js +11 -0
  78. package/dist/esm/new-sdk/errors/everyChainFailed.js +10 -0
  79. package/dist/esm/new-sdk/errors/index.js +8 -0
  80. package/dist/esm/new-sdk/index.js +13 -3
  81. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +38 -90
  82. package/dist/esm/new-sdk/positions/PositionsNamespace.js +28 -95
  83. package/dist/esm/new-sdk/types.js +1 -21
  84. package/dist/esm/new-sdk/utils/filterResponse.js +11 -0
  85. package/dist/esm/new-sdk/utils/index.js +3 -1
  86. package/dist/esm/new-sdk/utils/mergeChains.js +73 -0
  87. package/dist/esm/new-sdk/utils/types.js +1 -0
  88. package/dist/esm/offchain/AbstractOffchainNamespace.js +41 -64
  89. package/dist/esm/offchain/GearboxAPI.js +12 -8
  90. package/dist/esm/offchain/errors/OffchainInvalidJsonError.js +18 -0
  91. package/dist/esm/offchain/errors/OffchainNotConfiguredError.js +19 -0
  92. package/dist/esm/offchain/errors/OffchainNotImplementedError.js +18 -0
  93. package/dist/esm/offchain/errors/OffchainRequestFailedError.js +23 -0
  94. package/dist/esm/offchain/errors/OffchainStatusError.js +19 -0
  95. package/dist/esm/offchain/errors/OffchainTransportError.js +30 -0
  96. package/dist/esm/offchain/errors/OffchainValidationError.js +25 -0
  97. package/dist/esm/offchain/errors/backendMessage.js +27 -0
  98. package/dist/esm/offchain/errors/errorCause.js +11 -0
  99. package/dist/esm/offchain/errors/index.js +11 -0
  100. package/dist/esm/offchain/errors/readResponseBody.js +14 -0
  101. package/dist/esm/offchain/index.js +13 -2
  102. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +6 -3
  103. package/dist/esm/offchain/positions/OffchainPositions.js +15 -21
  104. package/dist/esm/offchain/types.js +1 -72
  105. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  106. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  107. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  108. package/dist/esm/sdk/MultichainSDK.js +1 -1
  109. package/dist/esm/sdk/OnchainSDK.js +1 -1
  110. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  111. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  112. package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
  113. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  114. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  115. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  116. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  117. package/dist/esm/sdk/base/MultichainConstruct.js +73 -34
  118. package/dist/esm/sdk/base/TokensMeta.js +2 -2
  119. package/dist/esm/sdk/chain/chains.js +11 -1
  120. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  121. package/dist/esm/sdk/chain/index.js +2 -2
  122. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  123. package/dist/esm/sdk/core/index.js +1 -1
  124. package/dist/esm/sdk/index.js +3 -3
  125. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  126. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  127. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  128. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  129. package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
  130. package/dist/esm/sdk/opportunities/OpportunitiesService.js +1 -4
  131. package/dist/esm/sdk/pools/PoolService.js +1 -1
  132. package/dist/esm/sdk/positions/MultichainPositionsService.js +6 -29
  133. package/dist/esm/sdk/positions/PositionsService.js +1 -2
  134. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  135. package/dist/types/model/filters.d.ts +9 -3
  136. package/dist/types/model/filters.schema.d.ts +7 -1
  137. package/dist/types/model/index.d.ts +5 -5
  138. package/dist/types/model/liquidations.d.ts +2 -6
  139. package/dist/types/model/liquidations.schema.d.ts +1 -1
  140. package/dist/types/model/opportunities.d.ts +3 -7
  141. package/dist/types/model/opportunities.schema.d.ts +2 -2
  142. package/dist/types/model/positions.d.ts +2 -6
  143. package/dist/types/model/positions.schema.d.ts +32 -2
  144. package/dist/types/model/response.d.ts +7 -6
  145. package/dist/types/model/response.schema.d.ts +41 -32
  146. package/dist/types/new-sdk/AbstractNamespace.d.ts +33 -98
  147. package/dist/types/new-sdk/GearboxSDK.d.ts +10 -25
  148. package/dist/types/new-sdk/errors/AllSourcesFailedError.d.ts +11 -0
  149. package/dist/types/new-sdk/errors/MissingSourceError.d.ts +23 -0
  150. package/dist/types/new-sdk/errors/NoSourceServedError.d.ts +17 -0
  151. package/dist/types/new-sdk/errors/SourceChainMismatchError.d.ts +35 -0
  152. package/dist/types/new-sdk/errors/SourceUnavailableError.d.ts +22 -0
  153. package/dist/types/new-sdk/errors/assertSameChains.d.ts +11 -0
  154. package/dist/types/new-sdk/errors/everyChainFailed.d.ts +10 -0
  155. package/dist/types/new-sdk/errors/index.d.ts +8 -0
  156. package/dist/types/new-sdk/index.d.ts +17 -6
  157. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +20 -40
  158. package/dist/types/new-sdk/opportunities/index.d.ts +2 -2
  159. package/dist/types/new-sdk/opportunities/types.d.ts +72 -26
  160. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +18 -38
  161. package/dist/types/new-sdk/positions/index.d.ts +2 -2
  162. package/dist/types/new-sdk/positions/types.d.ts +68 -24
  163. package/dist/types/new-sdk/types.d.ts +24 -77
  164. package/dist/types/new-sdk/utils/filterResponse.d.ts +19 -0
  165. package/dist/types/new-sdk/utils/history.d.ts +6 -36
  166. package/dist/types/new-sdk/utils/index.d.ts +5 -2
  167. package/dist/types/new-sdk/utils/mergeChains.d.ts +22 -0
  168. package/dist/types/new-sdk/utils/types.d.ts +43 -0
  169. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +21 -28
  170. package/dist/types/offchain/GearboxAPI.d.ts +13 -9
  171. package/dist/types/offchain/errors/OffchainInvalidJsonError.d.ts +16 -0
  172. package/dist/types/offchain/errors/OffchainNotConfiguredError.d.ts +16 -0
  173. package/dist/types/offchain/errors/OffchainNotImplementedError.d.ts +15 -0
  174. package/dist/types/offchain/errors/OffchainRequestFailedError.d.ts +12 -0
  175. package/dist/types/offchain/errors/OffchainStatusError.d.ts +16 -0
  176. package/dist/types/offchain/errors/OffchainTransportError.d.ts +43 -0
  177. package/dist/types/offchain/errors/OffchainValidationError.d.ts +21 -0
  178. package/dist/types/offchain/errors/backendMessage.d.ts +9 -0
  179. package/dist/types/offchain/errors/errorCause.d.ts +22 -0
  180. package/dist/types/offchain/errors/index.d.ts +11 -0
  181. package/dist/types/offchain/errors/readResponseBody.d.ts +8 -0
  182. package/dist/types/offchain/index.d.ts +13 -2
  183. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +9 -8
  184. package/dist/types/offchain/positions/OffchainPositions.d.ts +9 -15
  185. package/dist/types/offchain/types.d.ts +7 -88
  186. package/dist/types/sdk/accounts/index.d.ts +2 -2
  187. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +15 -14
  188. package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -2
  189. package/dist/types/sdk/accounts/liquidations/types.d.ts +9 -15
  190. package/dist/types/sdk/base/MultichainConstruct.d.ts +63 -14
  191. package/dist/types/sdk/base/index.d.ts +2 -2
  192. package/dist/types/sdk/chain/chains.d.ts +10 -2
  193. package/dist/types/sdk/chain/index.d.ts +2 -2
  194. package/dist/types/sdk/index.d.ts +5 -5
  195. package/dist/types/sdk/market/MarketSuite.d.ts +1 -1
  196. package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +13 -16
  197. package/dist/types/sdk/positions/MultichainPositionsService.d.ts +2 -12
  198. package/dist/types/sdk/types/index.d.ts +2 -2
  199. package/dist/types/sdk/types/multichain.d.ts +8 -43
  200. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ import { OffchainTransportError } from "./OffchainTransportError.js";
2
+ //#region src/offchain/errors/OffchainInvalidJsonError.ts
3
+ /**
4
+ * Thrown when the backend answered in the 2xx range with a body that is not
5
+ * JSON, so there is nothing to validate against the read model.
6
+ **/
7
+ var OffchainInvalidJsonError = class extends OffchainTransportError {
8
+ name = "OffchainInvalidJsonError";
9
+ constructor(url, status, cause) {
10
+ super("The Gearbox backend answered with a body that is not JSON.", {
11
+ url,
12
+ status,
13
+ cause
14
+ });
15
+ }
16
+ };
17
+ //#endregion
18
+ export { OffchainInvalidJsonError };
@@ -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";
@@ -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
@@ -2,13 +2,8 @@ import { MultichainConstruct } from "../../base/MultichainConstruct.js";
2
2
  import "../../base/index.js";
3
3
  //#region src/sdk/accounts/liquidations/MultichainLiquidationsService.ts
4
4
  /**
5
- * Cross-chain counterpart of {@link LiquidationsService}.
6
- *
7
- * Fans out over all chains configured in {@link MultichainSDK} (optionally
8
- * restricted via {@link MultichainNetworksProps.networks}). A failed chain is
9
- * logged as a warning and skipped, so one dead RPC does not empty the whole
10
- * list; its failure is reported in {@link MultichainResult.meta}. Networks that
11
- * are not configured in the SDK are reported there the same way.
5
+ * Cross-chain counterpart of {@link LiquidationsService}. These reads are live,
6
+ * so each chain is pinned to its own freshly fetched head.
12
7
  **/
13
8
  var MultichainLiquidationsService = class extends MultichainConstruct {
14
9
  /**
@@ -17,22 +12,44 @@ var MultichainLiquidationsService = class extends MultichainConstruct {
17
12
  **/
18
13
  async getLiquidatableAccounts(props) {
19
14
  return this.queryChains({
20
- networks: props?.networks,
15
+ chainIds: props?.chainIds,
21
16
  label: "get liquidatable accounts",
22
- run: (sdk) => sdk.liquidations.getLiquidatableAccounts(props)
17
+ block: "latest",
18
+ run: (sdk, block) => sdk.liquidations.getLiquidatableAccounts({
19
+ ...props,
20
+ blockNumber: block.blockNumber
21
+ })
23
22
  });
24
23
  }
25
24
  /**
26
25
  * {@inheritDoc LiquidationsService.getLiquidationDetails}
26
+ *
27
+ * Throws when the chain cannot answer.
27
28
  **/
28
29
  async getLiquidationDetails(props) {
29
- return this.sdk.chain(props.network).liquidations.getLiquidationDetails(props);
30
+ return this.queryChain({
31
+ network: props.network,
32
+ block: props.blockNumber ?? "latest",
33
+ run: (sdk, block) => sdk.liquidations.getLiquidationDetails({
34
+ ...props,
35
+ blockNumber: block.blockNumber
36
+ })
37
+ });
30
38
  }
31
39
  /**
32
40
  * {@inheritDoc LiquidationsService.buildLiquidationTx}
41
+ *
42
+ * The reported block is the one the transaction was built against.
33
43
  **/
34
44
  async buildLiquidationTx(props) {
35
- return this.sdk.chain(props.network).liquidations.buildLiquidationTx(props);
45
+ return this.queryChain({
46
+ network: props.network,
47
+ block: props.blockNumber ?? "latest",
48
+ run: (sdk, block) => sdk.liquidations.buildLiquidationTx({
49
+ ...props,
50
+ blockNumber: block.blockNumber
51
+ })
52
+ });
36
53
  }
37
54
  /**
38
55
  * Liquidation positions of all queried chains, see
@@ -40,18 +57,25 @@ var MultichainLiquidationsService = class extends MultichainConstruct {
40
57
  **/
41
58
  async getLiquidationPositions(props) {
42
59
  return this.queryChains({
43
- networks: props.networks,
60
+ chainIds: props.chainIds,
44
61
  label: "get liquidation positions",
45
- run: (sdk) => sdk.liquidations.getLiquidationPositions(props)
62
+ block: "latest",
63
+ run: (sdk, block) => sdk.liquidations.getLiquidationPositions({
64
+ ...props,
65
+ blockNumber: block.blockNumber
66
+ })
46
67
  });
47
68
  }
48
69
  /**
49
70
  * Loads the liquidators of all queried chains, see
50
71
  * {@link LiquidationsService.loadRWALiquidators}.
72
+ *
73
+ * Nothing consumes the block of a cache warm-up, so this one is left on the
74
+ * loaded snapshot.
51
75
  **/
52
76
  async loadRWALiquidators(props) {
53
77
  return this.runChains({
54
- networks: props?.networks,
78
+ chainIds: props?.chainIds,
55
79
  label: "load RWA liquidators",
56
80
  run: (sdk) => sdk.liquidations.loadRWALiquidators()
57
81
  });
@@ -1,7 +1,7 @@
1
- import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
2
1
  import { BaseContract } from "../../base/BaseContract.js";
3
2
  import "../../base/index.js";
4
3
  import { decodeDelayedIntent } from "./intent-codec.js";
4
+ import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
5
5
  import { InvalidDelayedIntentError } from "./errors.js";
6
6
  //#region src/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
7
7
  const abi = iRedemptionLoggerV310Abi;
@@ -1,5 +1,5 @@
1
- import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
1
  import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
1
  import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
4
4
  const abi = iWithdrawalCompressorV311Abi;
5
5
  /**
@@ -1,6 +1,6 @@
1
- import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
2
1
  import { encodeDelayedIntent } from "./intent-codec.js";
3
2
  import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
3
+ import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
4
4
  import { toWithdrawalStatus } from "./types.js";
5
5
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
6
6
  const abi = iWithdrawalCompressorV313Abi;