@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.
- package/dist/cjs/model/filters.js +0 -4
- package/dist/cjs/model/filters.schema.js +10 -1
- package/dist/cjs/model/index.js +3 -0
- package/dist/cjs/model/liquidations.js +1 -1
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/opportunities.js +1 -1
- package/dist/cjs/model/opportunities.schema.js +6 -13
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/positions.schema.js +33 -1
- package/dist/cjs/model/response.schema.js +9 -6
- package/dist/cjs/new-sdk/AbstractNamespace.js +46 -128
- package/dist/cjs/new-sdk/GearboxSDK.js +55 -42
- package/dist/cjs/new-sdk/errors/AllSourcesFailedError.js +20 -0
- package/dist/cjs/new-sdk/errors/MissingSourceError.js +25 -0
- package/dist/cjs/new-sdk/errors/NoSourceServedError.js +20 -0
- package/dist/cjs/new-sdk/errors/SourceChainMismatchError.js +34 -0
- package/dist/cjs/new-sdk/errors/SourceUnavailableError.js +25 -0
- package/dist/cjs/new-sdk/errors/assertSameChains.js +12 -0
- package/dist/cjs/new-sdk/errors/everyChainFailed.js +11 -0
- package/dist/cjs/new-sdk/errors/index.js +15 -0
- package/dist/cjs/new-sdk/index.js +23 -3
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +37 -89
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +27 -94
- package/dist/cjs/new-sdk/types.js +0 -21
- package/dist/cjs/new-sdk/utils/filterResponse.js +12 -0
- package/dist/cjs/new-sdk/utils/index.js +6 -0
- package/dist/cjs/new-sdk/utils/mergeChains.js +76 -0
- package/dist/cjs/new-sdk/utils/types.js +1 -0
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +42 -65
- package/dist/cjs/offchain/GearboxAPI.js +12 -8
- package/dist/cjs/offchain/errors/OffchainInvalidJsonError.js +19 -0
- package/dist/cjs/offchain/errors/OffchainNotConfiguredError.js +20 -0
- package/dist/cjs/offchain/errors/OffchainNotImplementedError.js +19 -0
- package/dist/cjs/offchain/errors/OffchainRequestFailedError.js +24 -0
- package/dist/cjs/offchain/errors/OffchainStatusError.js +20 -0
- package/dist/cjs/offchain/errors/OffchainTransportError.js +31 -0
- package/dist/cjs/offchain/errors/OffchainValidationError.js +26 -0
- package/dist/cjs/offchain/errors/backendMessage.js +28 -0
- package/dist/cjs/offchain/errors/errorCause.js +12 -0
- package/dist/cjs/offchain/errors/index.js +21 -0
- package/dist/cjs/offchain/errors/readResponseBody.js +15 -0
- package/dist/cjs/offchain/index.js +22 -5
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +6 -3
- package/dist/cjs/offchain/positions/OffchainPositions.js +15 -21
- package/dist/cjs/offchain/types.js +0 -75
- package/dist/cjs/sdk/MultichainSDK.js +1 -1
- package/dist/cjs/sdk/OnchainSDK.js +1 -1
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
- package/dist/cjs/sdk/base/MultichainConstruct.js +73 -34
- package/dist/cjs/sdk/chain/chains.js +11 -0
- package/dist/cjs/sdk/chain/index.js +1 -0
- package/dist/cjs/sdk/core/index.js +1 -1
- package/dist/cjs/sdk/index.js +2 -1
- package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +1 -4
- package/dist/cjs/sdk/positions/MultichainPositionsService.js +6 -29
- package/dist/cjs/sdk/positions/PositionsService.js +1 -2
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/filters.js +0 -4
- package/dist/esm/model/filters.schema.js +10 -2
- package/dist/esm/model/index.js +3 -3
- package/dist/esm/model/liquidations.js +1 -1
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/opportunities.js +1 -1
- package/dist/esm/model/opportunities.schema.js +4 -11
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/positions.schema.js +33 -3
- package/dist/esm/model/response.schema.js +9 -6
- package/dist/esm/new-sdk/AbstractNamespace.js +46 -128
- package/dist/esm/new-sdk/GearboxSDK.js +55 -42
- package/dist/esm/new-sdk/errors/AllSourcesFailedError.js +19 -0
- package/dist/esm/new-sdk/errors/MissingSourceError.js +24 -0
- package/dist/esm/new-sdk/errors/NoSourceServedError.js +19 -0
- package/dist/esm/new-sdk/errors/SourceChainMismatchError.js +33 -0
- package/dist/esm/new-sdk/errors/SourceUnavailableError.js +24 -0
- package/dist/esm/new-sdk/errors/assertSameChains.js +11 -0
- package/dist/esm/new-sdk/errors/everyChainFailed.js +10 -0
- package/dist/esm/new-sdk/errors/index.js +8 -0
- package/dist/esm/new-sdk/index.js +13 -3
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +38 -90
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +28 -95
- package/dist/esm/new-sdk/types.js +1 -21
- package/dist/esm/new-sdk/utils/filterResponse.js +11 -0
- package/dist/esm/new-sdk/utils/index.js +3 -1
- package/dist/esm/new-sdk/utils/mergeChains.js +73 -0
- package/dist/esm/new-sdk/utils/types.js +1 -0
- package/dist/esm/offchain/AbstractOffchainNamespace.js +41 -64
- package/dist/esm/offchain/GearboxAPI.js +12 -8
- package/dist/esm/offchain/errors/OffchainInvalidJsonError.js +18 -0
- package/dist/esm/offchain/errors/OffchainNotConfiguredError.js +19 -0
- package/dist/esm/offchain/errors/OffchainNotImplementedError.js +18 -0
- package/dist/esm/offchain/errors/OffchainRequestFailedError.js +23 -0
- package/dist/esm/offchain/errors/OffchainStatusError.js +19 -0
- package/dist/esm/offchain/errors/OffchainTransportError.js +30 -0
- package/dist/esm/offchain/errors/OffchainValidationError.js +25 -0
- package/dist/esm/offchain/errors/backendMessage.js +27 -0
- package/dist/esm/offchain/errors/errorCause.js +11 -0
- package/dist/esm/offchain/errors/index.js +11 -0
- package/dist/esm/offchain/errors/readResponseBody.js +14 -0
- package/dist/esm/offchain/index.js +13 -2
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +6 -3
- package/dist/esm/offchain/positions/OffchainPositions.js +15 -21
- package/dist/esm/offchain/types.js +1 -72
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +1 -1
- package/dist/esm/sdk/OnchainSDK.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/MultichainConstruct.js +73 -34
- package/dist/esm/sdk/base/TokensMeta.js +2 -2
- package/dist/esm/sdk/chain/chains.js +11 -1
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/chain/index.js +2 -2
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/core/index.js +1 -1
- package/dist/esm/sdk/index.js +3 -3
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +1 -4
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/positions/MultichainPositionsService.js +6 -29
- package/dist/esm/sdk/positions/PositionsService.js +1 -2
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/model/filters.d.ts +9 -3
- package/dist/types/model/filters.schema.d.ts +7 -1
- package/dist/types/model/index.d.ts +5 -5
- package/dist/types/model/liquidations.d.ts +2 -6
- package/dist/types/model/liquidations.schema.d.ts +1 -1
- package/dist/types/model/opportunities.d.ts +3 -7
- package/dist/types/model/opportunities.schema.d.ts +2 -2
- package/dist/types/model/positions.d.ts +2 -6
- package/dist/types/model/positions.schema.d.ts +32 -2
- package/dist/types/model/response.d.ts +7 -6
- package/dist/types/model/response.schema.d.ts +41 -32
- package/dist/types/new-sdk/AbstractNamespace.d.ts +33 -98
- package/dist/types/new-sdk/GearboxSDK.d.ts +10 -25
- package/dist/types/new-sdk/errors/AllSourcesFailedError.d.ts +11 -0
- package/dist/types/new-sdk/errors/MissingSourceError.d.ts +23 -0
- package/dist/types/new-sdk/errors/NoSourceServedError.d.ts +17 -0
- package/dist/types/new-sdk/errors/SourceChainMismatchError.d.ts +35 -0
- package/dist/types/new-sdk/errors/SourceUnavailableError.d.ts +22 -0
- package/dist/types/new-sdk/errors/assertSameChains.d.ts +11 -0
- package/dist/types/new-sdk/errors/everyChainFailed.d.ts +10 -0
- package/dist/types/new-sdk/errors/index.d.ts +8 -0
- package/dist/types/new-sdk/index.d.ts +17 -6
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +20 -40
- package/dist/types/new-sdk/opportunities/index.d.ts +2 -2
- package/dist/types/new-sdk/opportunities/types.d.ts +72 -26
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +18 -38
- package/dist/types/new-sdk/positions/index.d.ts +2 -2
- package/dist/types/new-sdk/positions/types.d.ts +68 -24
- package/dist/types/new-sdk/types.d.ts +24 -77
- package/dist/types/new-sdk/utils/filterResponse.d.ts +19 -0
- package/dist/types/new-sdk/utils/history.d.ts +6 -36
- package/dist/types/new-sdk/utils/index.d.ts +5 -2
- package/dist/types/new-sdk/utils/mergeChains.d.ts +22 -0
- package/dist/types/new-sdk/utils/types.d.ts +43 -0
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +21 -28
- package/dist/types/offchain/GearboxAPI.d.ts +13 -9
- package/dist/types/offchain/errors/OffchainInvalidJsonError.d.ts +16 -0
- package/dist/types/offchain/errors/OffchainNotConfiguredError.d.ts +16 -0
- package/dist/types/offchain/errors/OffchainNotImplementedError.d.ts +15 -0
- package/dist/types/offchain/errors/OffchainRequestFailedError.d.ts +12 -0
- package/dist/types/offchain/errors/OffchainStatusError.d.ts +16 -0
- package/dist/types/offchain/errors/OffchainTransportError.d.ts +43 -0
- package/dist/types/offchain/errors/OffchainValidationError.d.ts +21 -0
- package/dist/types/offchain/errors/backendMessage.d.ts +9 -0
- package/dist/types/offchain/errors/errorCause.d.ts +22 -0
- package/dist/types/offchain/errors/index.d.ts +11 -0
- package/dist/types/offchain/errors/readResponseBody.d.ts +8 -0
- package/dist/types/offchain/index.d.ts +13 -2
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +9 -8
- package/dist/types/offchain/positions/OffchainPositions.d.ts +9 -15
- package/dist/types/offchain/types.d.ts +7 -88
- package/dist/types/sdk/accounts/index.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +15 -14
- package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/types.d.ts +9 -15
- package/dist/types/sdk/base/MultichainConstruct.d.ts +63 -14
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/chain/chains.d.ts +10 -2
- package/dist/types/sdk/chain/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +5 -5
- package/dist/types/sdk/market/MarketSuite.d.ts +1 -1
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +13 -16
- package/dist/types/sdk/positions/MultichainPositionsService.d.ts +2 -12
- package/dist/types/sdk/types/index.d.ts +2 -2
- package/dist/types/sdk/types/multichain.d.ts +8 -43
- package/package.json +1 -1
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_history_schema = require("../model/history.schema.js");
|
|
3
|
-
const
|
|
3
|
+
const require_model_response_schema = require("../model/response.schema.js");
|
|
4
|
+
const require_offchain_errors_OffchainInvalidJsonError = require("./errors/OffchainInvalidJsonError.js");
|
|
5
|
+
const require_offchain_errors_OffchainNotConfiguredError = require("./errors/OffchainNotConfiguredError.js");
|
|
6
|
+
const require_offchain_errors_OffchainRequestFailedError = require("./errors/OffchainRequestFailedError.js");
|
|
7
|
+
const require_offchain_errors_OffchainStatusError = require("./errors/OffchainStatusError.js");
|
|
8
|
+
const require_offchain_errors_OffchainValidationError = require("./errors/OffchainValidationError.js");
|
|
9
|
+
const require_offchain_errors_readResponseBody = require("./errors/readResponseBody.js");
|
|
10
|
+
require("./errors/index.js");
|
|
4
11
|
let zod_v4 = require("zod/v4");
|
|
5
12
|
//#region src/offchain/AbstractOffchainNamespace.ts
|
|
6
13
|
const DEFAULT_TIMEOUT = 3e4;
|
|
7
14
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* A namespace is a set of routes: it knows which path answers which read and
|
|
11
|
-
* which schema describes the payload. Everything under that — where the
|
|
12
|
-
* backend is, how long a request may take, how a failure is reported and how a
|
|
13
|
-
* response becomes read model values — lives here, so a namespace holds
|
|
15
|
+
* Base class of every {@link GearboxAPI} namespace: issues the requests,
|
|
16
|
+
* decodes the responses and reports the failures, so that a namespace holds
|
|
14
17
|
* nothing but its routes.
|
|
15
18
|
**/
|
|
16
19
|
var AbstractOffchainNamespace = class {
|
|
17
20
|
logger;
|
|
18
21
|
#baseUrl;
|
|
22
|
+
#chainIds;
|
|
19
23
|
#timeout;
|
|
20
24
|
constructor(name, options) {
|
|
21
|
-
this.#baseUrl = options
|
|
22
|
-
this.#
|
|
23
|
-
this
|
|
25
|
+
this.#baseUrl = options.baseUrl?.replace(/\/+$/, "");
|
|
26
|
+
this.#chainIds = [...options.chainIds];
|
|
27
|
+
this.#timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
28
|
+
this.logger = options.logger?.child?.({ name }) ?? options.logger;
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Base URL every read of this namespace is issued against.
|
|
@@ -29,36 +34,39 @@ var AbstractOffchainNamespace = class {
|
|
|
29
34
|
return this.#baseUrl;
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
* Chains one read covers: the configured ones, narrowed by the filter when it
|
|
38
|
+
* names any. A filter naming a chain this client does not cover narrows
|
|
39
|
+
* nothing.
|
|
40
|
+
**/
|
|
41
|
+
scopedChainIds(filter) {
|
|
42
|
+
const wanted = filter?.chainIds;
|
|
43
|
+
return wanted ? this.#chainIds.filter((chainId) => wanted.includes(chainId)) : [...this.#chainIds];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reads one endpoint and decodes its payload. Timeouts, non-2xx answers and
|
|
47
|
+
* schema skew throw, since none of them is a {@link DataResponse}.
|
|
37
48
|
**/
|
|
38
49
|
async get(request) {
|
|
39
50
|
const url = this.#url(request.path, request.query);
|
|
40
|
-
this.logger?.debug(`reading ${url}`);
|
|
41
51
|
const payload = await this.#fetchJson(url);
|
|
42
|
-
const parsed = request.schema.safeParse(payload);
|
|
52
|
+
const parsed = require_model_response_schema.responseSchema(request.schema).safeParse(payload);
|
|
43
53
|
if (!parsed.success) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}, "offchain response does not match the read model");
|
|
48
|
-
throw new require_offchain_types.OffchainValidationError(url, parsed.error.issues);
|
|
54
|
+
const error = new require_offchain_errors_OffchainValidationError.OffchainValidationError(url, parsed.error);
|
|
55
|
+
this.logger?.error(error, "offchain response does not match the read model");
|
|
56
|
+
throw error;
|
|
49
57
|
}
|
|
58
|
+
const { data, meta } = parsed.data;
|
|
50
59
|
return {
|
|
51
|
-
|
|
52
|
-
meta: {
|
|
60
|
+
data,
|
|
61
|
+
meta: { chains: meta.chains.map((chain) => ({
|
|
62
|
+
...chain,
|
|
63
|
+
source: "offchain"
|
|
64
|
+
})) }
|
|
53
65
|
};
|
|
54
66
|
}
|
|
55
67
|
/**
|
|
56
|
-
* Reads one historical series.
|
|
57
|
-
*
|
|
58
|
-
* The requested metric is pinned in the schema, which is what upholds the
|
|
59
|
-
* `HistorySeries<M>` a caller gets back: a response carrying a different
|
|
60
|
-
* metric is version skew and fails validation like any other mismatch,
|
|
61
|
-
* rather than being cast into the requested shape.
|
|
68
|
+
* Reads one historical series. A response carrying a metric other than the
|
|
69
|
+
* requested one fails validation.
|
|
62
70
|
**/
|
|
63
71
|
async readHistory(request) {
|
|
64
72
|
return this.get({
|
|
@@ -71,7 +79,7 @@ var AbstractOffchainNamespace = class {
|
|
|
71
79
|
* Full URL of a read, with the conditions that do not narrow left out.
|
|
72
80
|
**/
|
|
73
81
|
#url(path, query) {
|
|
74
|
-
if (!this.#baseUrl) throw new
|
|
82
|
+
if (!this.#baseUrl) throw new require_offchain_errors_OffchainNotConfiguredError.OffchainNotConfiguredError(path);
|
|
75
83
|
const url = new URL(`${this.#baseUrl}${path}`);
|
|
76
84
|
for (const [key, value] of Object.entries(query ?? {})) if (value !== void 0) url.searchParams.set(key, value);
|
|
77
85
|
return url.toString();
|
|
@@ -87,46 +95,15 @@ var AbstractOffchainNamespace = class {
|
|
|
87
95
|
signal: AbortSignal.timeout(this.#timeout)
|
|
88
96
|
});
|
|
89
97
|
} catch (error) {
|
|
90
|
-
throw new
|
|
98
|
+
throw new require_offchain_errors_OffchainRequestFailedError.OffchainRequestFailedError(url, error);
|
|
91
99
|
}
|
|
92
|
-
if (!response.ok) throw new
|
|
100
|
+
if (!response.ok) throw new require_offchain_errors_OffchainStatusError.OffchainStatusError(url, response.status, await require_offchain_errors_readResponseBody.readResponseBody(response));
|
|
93
101
|
try {
|
|
94
102
|
return await response.json();
|
|
95
103
|
} catch (error) {
|
|
96
|
-
throw new
|
|
104
|
+
throw new require_offchain_errors_OffchainInvalidJsonError.OffchainInvalidJsonError(url, response.status, error);
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
};
|
|
100
|
-
/**
|
|
101
|
-
* Why a non-2xx response failed, in the backend's own words when it said.
|
|
102
|
-
**/
|
|
103
|
-
async function failureReason(response) {
|
|
104
|
-
const status = `the backend answered ${response.status}`;
|
|
105
|
-
let body;
|
|
106
|
-
try {
|
|
107
|
-
body = await response.text();
|
|
108
|
-
} catch {
|
|
109
|
-
return status;
|
|
110
|
-
}
|
|
111
|
-
const message = backendMessage(body) ?? body.trim();
|
|
112
|
-
return message ? `${status}: ${truncate(message)}` : status;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The `message` of a Gearbox backend error body, or nothing when the body is
|
|
116
|
-
* not one.
|
|
117
|
-
**/
|
|
118
|
-
function backendMessage(body) {
|
|
119
|
-
try {
|
|
120
|
-
const parsed = JSON.parse(body);
|
|
121
|
-
if (typeof parsed === "object" && parsed !== null && "message" in parsed && typeof parsed.message === "string") return parsed.message;
|
|
122
|
-
} catch {}
|
|
123
|
-
}
|
|
124
|
-
function describe(error) {
|
|
125
|
-
if (error instanceof Error) return error.name === "TimeoutError" ? "the request timed out" : error.message;
|
|
126
|
-
return String(error);
|
|
127
|
-
}
|
|
128
|
-
function truncate(text) {
|
|
129
|
-
return text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
|
130
|
-
}
|
|
131
108
|
//#endregion
|
|
132
109
|
exports.AbstractOffchainNamespace = AbstractOffchainNamespace;
|
|
@@ -11,18 +11,21 @@ require("./positions/index.js");
|
|
|
11
11
|
* call reads the same way against either source:
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
* const api = new GearboxAPI({
|
|
15
|
-
*
|
|
14
|
+
* const api = new GearboxAPI({
|
|
15
|
+
* baseUrl: "https://api.gearbox.fi",
|
|
16
|
+
* chainIds: [1, 42161],
|
|
17
|
+
* });
|
|
18
|
+
* const { data } = await api.opportunities.list({ kind: "strategy" });
|
|
16
19
|
* ```
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* transport and schema validation.
|
|
21
|
-
*
|
|
22
|
-
* The transport is not implemented yet; see {@link OffchainOpportunities} and
|
|
23
|
-
* {@link OffchainPositions} for what each stubbed endpoint currently answers.
|
|
21
|
+
* Every read is scoped to {@link GearboxAPIOptions.chainIds}, so a client only
|
|
22
|
+
* ever sees the chains it was built for even though the backend knows more.
|
|
24
23
|
**/
|
|
25
24
|
var GearboxAPI = class {
|
|
25
|
+
/**
|
|
26
|
+
* Chains every read of this client is scoped to.
|
|
27
|
+
**/
|
|
28
|
+
chainIds;
|
|
26
29
|
/**
|
|
27
30
|
* Namespace for pool and strategy opportunities.
|
|
28
31
|
**/
|
|
@@ -32,6 +35,7 @@ var GearboxAPI = class {
|
|
|
32
35
|
**/
|
|
33
36
|
positions;
|
|
34
37
|
constructor(options) {
|
|
38
|
+
this.chainIds = [...options.chainIds];
|
|
35
39
|
this.opportunities = new require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities(options);
|
|
36
40
|
this.positions = new require_offchain_positions_OffchainPositions.OffchainPositions(options);
|
|
37
41
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_errors_OffchainTransportError = require("./OffchainTransportError.js");
|
|
3
|
+
//#region src/offchain/errors/OffchainInvalidJsonError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when the backend answered in the 2xx range with a body that is not
|
|
6
|
+
* JSON, so there is nothing to validate against the read model.
|
|
7
|
+
**/
|
|
8
|
+
var OffchainInvalidJsonError = class extends require_offchain_errors_OffchainTransportError.OffchainTransportError {
|
|
9
|
+
name = "OffchainInvalidJsonError";
|
|
10
|
+
constructor(url, status, cause) {
|
|
11
|
+
super("The Gearbox backend answered with a body that is not JSON.", {
|
|
12
|
+
url,
|
|
13
|
+
status,
|
|
14
|
+
cause
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.OffchainInvalidJsonError = OffchainInvalidJsonError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
//#region src/offchain/errors/OffchainNotConfiguredError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a read is issued against a client that was never told where the
|
|
6
|
+
* backend is.
|
|
7
|
+
**/
|
|
8
|
+
var OffchainNotConfiguredError = class extends viem.BaseError {
|
|
9
|
+
name = "OffchainNotConfiguredError";
|
|
10
|
+
/**
|
|
11
|
+
* Path that was read, below the base URL that is missing.
|
|
12
|
+
**/
|
|
13
|
+
path;
|
|
14
|
+
constructor(path) {
|
|
15
|
+
super("No baseUrl was configured for the Gearbox backend.", { metaMessages: [`Path: ${path}`] });
|
|
16
|
+
this.path = path;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.OffchainNotConfiguredError = OffchainNotConfiguredError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
//#region src/offchain/errors/OffchainNotImplementedError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown by the endpoints that are not implemented yet.
|
|
6
|
+
**/
|
|
7
|
+
var OffchainNotImplementedError = class extends viem.BaseError {
|
|
8
|
+
name = "OffchainNotImplementedError";
|
|
9
|
+
/**
|
|
10
|
+
* Endpoint that was asked for.
|
|
11
|
+
**/
|
|
12
|
+
endpoint;
|
|
13
|
+
constructor(endpoint) {
|
|
14
|
+
super("This Gearbox backend endpoint is not implemented yet.", { metaMessages: [`Endpoint: ${endpoint}`] });
|
|
15
|
+
this.endpoint = endpoint;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.OffchainNotImplementedError = OffchainNotImplementedError;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_errors_OffchainTransportError = require("./OffchainTransportError.js");
|
|
3
|
+
//#region src/offchain/errors/OffchainRequestFailedError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a request to the backend never completed: the network was down,
|
|
6
|
+
* or it took longer than {@link GearboxAPIOptions.timeout}.
|
|
7
|
+
**/
|
|
8
|
+
var OffchainRequestFailedError = class extends require_offchain_errors_OffchainTransportError.OffchainTransportError {
|
|
9
|
+
name = "OffchainRequestFailedError";
|
|
10
|
+
constructor(url, cause) {
|
|
11
|
+
super(timedOut(cause) ? "The request to the Gearbox backend timed out." : "The request to the Gearbox backend failed.", {
|
|
12
|
+
url,
|
|
13
|
+
cause
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Whether a caught value is the rejection `AbortSignal.timeout` produces.
|
|
19
|
+
**/
|
|
20
|
+
function timedOut(error) {
|
|
21
|
+
return error instanceof Error && error.name === "TimeoutError";
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.OffchainRequestFailedError = OffchainRequestFailedError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_errors_backendMessage = require("./backendMessage.js");
|
|
3
|
+
const require_offchain_errors_OffchainTransportError = require("./OffchainTransportError.js");
|
|
4
|
+
//#region src/offchain/errors/OffchainStatusError.ts
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when the backend answered with a status outside the 2xx range. What it
|
|
7
|
+
* said about it, when it said anything, is the `details` of the error.
|
|
8
|
+
**/
|
|
9
|
+
var OffchainStatusError = class extends require_offchain_errors_OffchainTransportError.OffchainTransportError {
|
|
10
|
+
name = "OffchainStatusError";
|
|
11
|
+
constructor(url, status, body) {
|
|
12
|
+
super(`The Gearbox backend answered ${status}.`, {
|
|
13
|
+
url,
|
|
14
|
+
status,
|
|
15
|
+
details: require_offchain_errors_backendMessage.backendMessage(body)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.OffchainStatusError = OffchainStatusError;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_errors_errorCause = require("./errorCause.js");
|
|
3
|
+
let viem = require("viem");
|
|
4
|
+
//#region src/offchain/errors/OffchainTransportError.ts
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when the backend could not be reached, or answered with something
|
|
7
|
+
* other than a JSON body in the 2xx range. Its subclasses say which of the
|
|
8
|
+
* three it was; catch this one to catch all of them.
|
|
9
|
+
**/
|
|
10
|
+
var OffchainTransportError = class extends viem.BaseError {
|
|
11
|
+
/**
|
|
12
|
+
* URL that was requested, query included.
|
|
13
|
+
**/
|
|
14
|
+
url;
|
|
15
|
+
/**
|
|
16
|
+
* Status the backend answered with, absent when the request never completed.
|
|
17
|
+
**/
|
|
18
|
+
status;
|
|
19
|
+
constructor(shortMessage, params) {
|
|
20
|
+
const caught = require_offchain_errors_errorCause.errorCause(params.cause);
|
|
21
|
+
super(shortMessage, {
|
|
22
|
+
cause: caught.cause,
|
|
23
|
+
details: caught.details ?? params.details,
|
|
24
|
+
metaMessages: [`URL: ${params.url}`, ...params.status === void 0 ? [] : [`Status: ${params.status}`]]
|
|
25
|
+
});
|
|
26
|
+
this.url = params.url;
|
|
27
|
+
this.status = params.status;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.OffchainTransportError = OffchainTransportError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
let zod_v4 = require("zod/v4");
|
|
4
|
+
//#region src/offchain/errors/OffchainValidationError.ts
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when the backend answered, but with a payload the read model does not
|
|
7
|
+
* describe, i.e. the two are of different versions.
|
|
8
|
+
**/
|
|
9
|
+
var OffchainValidationError = class extends viem.BaseError {
|
|
10
|
+
name = "OffchainValidationError";
|
|
11
|
+
/**
|
|
12
|
+
* URL whose payload failed to validate.
|
|
13
|
+
**/
|
|
14
|
+
url;
|
|
15
|
+
/**
|
|
16
|
+
* The zod failure itself, e.g. for `z.treeifyError(error.zodError)`.
|
|
17
|
+
**/
|
|
18
|
+
zodError;
|
|
19
|
+
constructor(url, zodError) {
|
|
20
|
+
super("The Gearbox backend response does not match the read model.", { metaMessages: [`URL: ${url}`, ...zod_v4.z.prettifyError(zodError).split("\n")] });
|
|
21
|
+
this.url = url;
|
|
22
|
+
this.zodError = zodError;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.OffchainValidationError = OffchainValidationError;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/offchain/errors/backendMessage.ts
|
|
3
|
+
const MAX_LENGTH = 200;
|
|
4
|
+
/**
|
|
5
|
+
* Why a non-2xx response failed, in the backend's own words: the `message` of a
|
|
6
|
+
* Gearbox backend error body, the whole body when it is not one, and nothing
|
|
7
|
+
* when it said nothing at all.
|
|
8
|
+
**/
|
|
9
|
+
function backendMessage(body) {
|
|
10
|
+
if (!body) return;
|
|
11
|
+
const message = parsedMessage(body) ?? body.trim();
|
|
12
|
+
return message ? truncate(message) : void 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The `message` of a Gearbox backend error body, or nothing when the body is
|
|
16
|
+
* not one.
|
|
17
|
+
**/
|
|
18
|
+
function parsedMessage(body) {
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(body);
|
|
21
|
+
if (typeof parsed === "object" && parsed !== null && "message" in parsed && typeof parsed.message === "string") return parsed.message;
|
|
22
|
+
} catch {}
|
|
23
|
+
}
|
|
24
|
+
function truncate(text) {
|
|
25
|
+
return text.length > MAX_LENGTH ? `${text.slice(0, MAX_LENGTH)}…` : text;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.backendMessage = backendMessage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/offchain/errors/errorCause.ts
|
|
3
|
+
/**
|
|
4
|
+
* Turns a caught `unknown` into what viem's `BaseError` takes: it types `cause`
|
|
5
|
+
* as an `Error`, so anything else can only be reported as `details`.
|
|
6
|
+
**/
|
|
7
|
+
function errorCause(error) {
|
|
8
|
+
if (error === void 0) return {};
|
|
9
|
+
return error instanceof Error ? { cause: error } : { details: String(error) };
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.errorCause = errorCause;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_errors_backendMessage = require("./backendMessage.js");
|
|
3
|
+
const require_offchain_errors_errorCause = require("./errorCause.js");
|
|
4
|
+
const require_offchain_errors_OffchainTransportError = require("./OffchainTransportError.js");
|
|
5
|
+
const require_offchain_errors_OffchainInvalidJsonError = require("./OffchainInvalidJsonError.js");
|
|
6
|
+
const require_offchain_errors_OffchainNotConfiguredError = require("./OffchainNotConfiguredError.js");
|
|
7
|
+
const require_offchain_errors_OffchainNotImplementedError = require("./OffchainNotImplementedError.js");
|
|
8
|
+
const require_offchain_errors_OffchainRequestFailedError = require("./OffchainRequestFailedError.js");
|
|
9
|
+
const require_offchain_errors_OffchainStatusError = require("./OffchainStatusError.js");
|
|
10
|
+
const require_offchain_errors_OffchainValidationError = require("./OffchainValidationError.js");
|
|
11
|
+
const require_offchain_errors_readResponseBody = require("./readResponseBody.js");
|
|
12
|
+
exports.OffchainInvalidJsonError = require_offchain_errors_OffchainInvalidJsonError.OffchainInvalidJsonError;
|
|
13
|
+
exports.OffchainNotConfiguredError = require_offchain_errors_OffchainNotConfiguredError.OffchainNotConfiguredError;
|
|
14
|
+
exports.OffchainNotImplementedError = require_offchain_errors_OffchainNotImplementedError.OffchainNotImplementedError;
|
|
15
|
+
exports.OffchainRequestFailedError = require_offchain_errors_OffchainRequestFailedError.OffchainRequestFailedError;
|
|
16
|
+
exports.OffchainStatusError = require_offchain_errors_OffchainStatusError.OffchainStatusError;
|
|
17
|
+
exports.OffchainTransportError = require_offchain_errors_OffchainTransportError.OffchainTransportError;
|
|
18
|
+
exports.OffchainValidationError = require_offchain_errors_OffchainValidationError.OffchainValidationError;
|
|
19
|
+
exports.backendMessage = require_offchain_errors_backendMessage.backendMessage;
|
|
20
|
+
exports.errorCause = require_offchain_errors_errorCause.errorCause;
|
|
21
|
+
exports.readResponseBody = require_offchain_errors_readResponseBody.readResponseBody;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/offchain/errors/readResponseBody.ts
|
|
3
|
+
/**
|
|
4
|
+
* Body of a failed response as text, or nothing when it cannot be read: a
|
|
5
|
+
* failure explaining a failure is not itself worth throwing.
|
|
6
|
+
**/
|
|
7
|
+
async function readResponseBody(response) {
|
|
8
|
+
try {
|
|
9
|
+
return await response.text();
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.readResponseBody = readResponseBody;
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_offchain_errors_backendMessage = require("./errors/backendMessage.js");
|
|
3
|
+
const require_offchain_errors_errorCause = require("./errors/errorCause.js");
|
|
4
|
+
const require_offchain_errors_OffchainTransportError = require("./errors/OffchainTransportError.js");
|
|
5
|
+
const require_offchain_errors_OffchainInvalidJsonError = require("./errors/OffchainInvalidJsonError.js");
|
|
6
|
+
const require_offchain_errors_OffchainNotConfiguredError = require("./errors/OffchainNotConfiguredError.js");
|
|
7
|
+
const require_offchain_errors_OffchainNotImplementedError = require("./errors/OffchainNotImplementedError.js");
|
|
8
|
+
const require_offchain_errors_OffchainRequestFailedError = require("./errors/OffchainRequestFailedError.js");
|
|
9
|
+
const require_offchain_errors_OffchainStatusError = require("./errors/OffchainStatusError.js");
|
|
10
|
+
const require_offchain_errors_OffchainValidationError = require("./errors/OffchainValidationError.js");
|
|
11
|
+
const require_offchain_errors_readResponseBody = require("./errors/readResponseBody.js");
|
|
12
|
+
require("./errors/index.js");
|
|
3
13
|
const require_offchain_AbstractOffchainNamespace = require("./AbstractOffchainNamespace.js");
|
|
4
14
|
const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
|
|
5
15
|
require("./opportunities/index.js");
|
|
6
16
|
const require_offchain_positions_OffchainPositions = require("./positions/OffchainPositions.js");
|
|
7
17
|
require("./positions/index.js");
|
|
8
18
|
const require_offchain_GearboxAPI = require("./GearboxAPI.js");
|
|
19
|
+
require("./types.js");
|
|
9
20
|
exports.AbstractOffchainNamespace = require_offchain_AbstractOffchainNamespace.AbstractOffchainNamespace;
|
|
10
21
|
exports.GearboxAPI = require_offchain_GearboxAPI.GearboxAPI;
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
22
|
+
exports.OffchainInvalidJsonError = require_offchain_errors_OffchainInvalidJsonError.OffchainInvalidJsonError;
|
|
23
|
+
exports.OffchainNotConfiguredError = require_offchain_errors_OffchainNotConfiguredError.OffchainNotConfiguredError;
|
|
24
|
+
exports.OffchainNotImplementedError = require_offchain_errors_OffchainNotImplementedError.OffchainNotImplementedError;
|
|
13
25
|
exports.OffchainOpportunities = require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities;
|
|
14
26
|
exports.OffchainPositions = require_offchain_positions_OffchainPositions.OffchainPositions;
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
27
|
+
exports.OffchainRequestFailedError = require_offchain_errors_OffchainRequestFailedError.OffchainRequestFailedError;
|
|
28
|
+
exports.OffchainStatusError = require_offchain_errors_OffchainStatusError.OffchainStatusError;
|
|
29
|
+
exports.OffchainTransportError = require_offchain_errors_OffchainTransportError.OffchainTransportError;
|
|
30
|
+
exports.OffchainValidationError = require_offchain_errors_OffchainValidationError.OffchainValidationError;
|
|
31
|
+
exports.backendMessage = require_offchain_errors_backendMessage.backendMessage;
|
|
32
|
+
exports.errorCause = require_offchain_errors_errorCause.errorCause;
|
|
33
|
+
exports.readResponseBody = require_offchain_errors_readResponseBody.readResponseBody;
|
|
@@ -12,13 +12,16 @@ var OffchainOpportunities = class extends require_offchain_AbstractOffchainNames
|
|
|
12
12
|
super("OffchainOpportunities", options);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* {@link OpportunityFilter}.
|
|
15
|
+
* Opportunities of the chains this client covers, optionally narrowed further
|
|
16
|
+
* by {@link OpportunityFilter}.
|
|
17
17
|
**/
|
|
18
18
|
async list(filter) {
|
|
19
19
|
return this.get({
|
|
20
20
|
path: this.#root,
|
|
21
|
-
query:
|
|
21
|
+
query: zod_v4.z.encode(require_model_opportunities_schema.opportunityFilterQuerySchema, {
|
|
22
|
+
...filter,
|
|
23
|
+
chainIds: this.scopedChainIds(filter)
|
|
24
|
+
}),
|
|
22
25
|
schema: zod_v4.z.array(require_model_opportunities_schema.opportunitySchema)
|
|
23
26
|
});
|
|
24
27
|
}
|
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_positions_schema = require("../../model/positions.schema.js");
|
|
2
3
|
const require_offchain_AbstractOffchainNamespace = require("../AbstractOffchainNamespace.js");
|
|
4
|
+
let zod_v4 = require("zod/v4");
|
|
3
5
|
//#region src/offchain/positions/OffchainPositions.ts
|
|
4
6
|
/**
|
|
5
7
|
* Backend counterpart of the `positions` namespace.
|
|
6
8
|
**/
|
|
7
9
|
var OffchainPositions = class extends require_offchain_AbstractOffchainNamespace.AbstractOffchainNamespace {
|
|
10
|
+
#root = "/v2/positions";
|
|
8
11
|
constructor(options) {
|
|
9
12
|
super("OffchainPositions", options);
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* Everything a wallet holds, optionally narrowed by {@link PositionFilter}.
|
|
13
|
-
*
|
|
14
|
-
* @returns An empty list until the backend client is implemented.
|
|
15
16
|
**/
|
|
16
|
-
async list(
|
|
17
|
-
this.
|
|
18
|
-
wallet
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
17
|
+
async list(props) {
|
|
18
|
+
return this.get({
|
|
19
|
+
path: `${this.#root}/${props.wallet}`,
|
|
20
|
+
query: zod_v4.z.encode(require_model_positions_schema.positionFilterQuerySchema, {
|
|
21
|
+
...props.filter,
|
|
22
|
+
chainIds: this.scopedChainIds(props.filter)
|
|
23
|
+
}),
|
|
24
|
+
schema: zod_v4.z.array(require_model_positions_schema.positionSchema)
|
|
25
|
+
});
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
* One historical series of one position.
|
|
28
|
-
* it from the chain would mean an archive read per point.
|
|
29
|
-
*
|
|
30
|
-
* The requested metric types the response, so a caller asking for one metric
|
|
31
|
-
* does not have to narrow the union back down. When the transport lands,
|
|
32
|
-
* validation is what upholds it: a response carrying a different metric than
|
|
33
|
-
* the one asked for is a version-skew error like any other.
|
|
28
|
+
* One historical series of one position.
|
|
34
29
|
*
|
|
35
30
|
* @returns An empty series until the backend client is implemented.
|
|
36
31
|
**/
|
|
37
32
|
async getHistory(query) {
|
|
38
|
-
this.logger?.debug({ query }, "offchain positions history is not implemented, serving empty series");
|
|
39
33
|
return {
|
|
40
|
-
|
|
34
|
+
data: {
|
|
41
35
|
metric: query.metric,
|
|
42
36
|
points: [],
|
|
43
37
|
metadata: {}
|
|
44
38
|
},
|
|
45
|
-
meta: {
|
|
39
|
+
meta: { chains: [] }
|
|
46
40
|
};
|
|
47
41
|
}
|
|
48
42
|
};
|
|
@@ -1,76 +1 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/offchain/types.ts
|
|
3
|
-
/**
|
|
4
|
-
* Thrown by the endpoints that have no stub answer, so that a caller in
|
|
5
|
-
* `offchain` mode fails loudly instead of reading an empty detail page as a
|
|
6
|
-
* missing entity.
|
|
7
|
-
*
|
|
8
|
-
* Lives here rather than in one namespace because every stubbed namespace
|
|
9
|
-
* throws it.
|
|
10
|
-
**/
|
|
11
|
-
var OffchainNotImplementedError = class extends Error {
|
|
12
|
-
constructor(endpoint) {
|
|
13
|
-
super(`GearboxAPI: ${endpoint} is not implemented yet`);
|
|
14
|
-
this.name = "OffchainNotImplementedError";
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Thrown when a read is issued against a client that was never told where the
|
|
19
|
-
* backend is.
|
|
20
|
-
**/
|
|
21
|
-
var OffchainNotConfiguredError = class extends Error {
|
|
22
|
-
constructor(path) {
|
|
23
|
-
super(`GearboxAPI: cannot read ${path}, no baseUrl was configured`);
|
|
24
|
-
this.name = "OffchainNotConfiguredError";
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Thrown when the backend could not be reached, or answered with a status
|
|
29
|
-
* outside the 2xx range.
|
|
30
|
-
**/
|
|
31
|
-
var OffchainTransportError = class extends Error {
|
|
32
|
-
/**
|
|
33
|
-
* URL that was requested, query included.
|
|
34
|
-
**/
|
|
35
|
-
url;
|
|
36
|
-
/**
|
|
37
|
-
* Status the backend answered with, absent when the request never completed.
|
|
38
|
-
**/
|
|
39
|
-
status;
|
|
40
|
-
constructor(url, reason, status) {
|
|
41
|
-
super(`GearboxAPI: request to ${url} failed, ${reason}`);
|
|
42
|
-
this.name = "OffchainTransportError";
|
|
43
|
-
this.url = url;
|
|
44
|
-
this.status = status;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Thrown when the backend answered, but with a payload the read model does not
|
|
49
|
-
* describe.
|
|
50
|
-
*
|
|
51
|
-
* This is version skew rather than a bad request, and it is deliberately
|
|
52
|
-
* handled like a transport error: the combined SDK drops the backend's
|
|
53
|
-
* contribution in `both` mode and fails the read in `offchain` mode.
|
|
54
|
-
**/
|
|
55
|
-
var OffchainValidationError = class extends Error {
|
|
56
|
-
/**
|
|
57
|
-
* URL whose payload failed to validate.
|
|
58
|
-
**/
|
|
59
|
-
url;
|
|
60
|
-
/**
|
|
61
|
-
* What did not match, in the order zod reported it.
|
|
62
|
-
**/
|
|
63
|
-
issues;
|
|
64
|
-
constructor(url, issues) {
|
|
65
|
-
const summary = issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ");
|
|
66
|
-
super(`GearboxAPI: response from ${url} does not match the model, ${summary}`);
|
|
67
|
-
this.name = "OffchainValidationError";
|
|
68
|
-
this.url = url;
|
|
69
|
-
this.issues = issues;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
//#endregion
|
|
73
|
-
exports.OffchainNotConfiguredError = OffchainNotConfiguredError;
|
|
74
|
-
exports.OffchainNotImplementedError = OffchainNotImplementedError;
|
|
75
|
-
exports.OffchainTransportError = OffchainTransportError;
|
|
76
|
-
exports.OffchainValidationError = OffchainValidationError;
|