@gearbox-protocol/sdk 14.12.0-next.81 → 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.
- 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 +21 -0
- package/dist/cjs/new-sdk/utils/index.js +6 -0
- package/dist/cjs/new-sdk/utils/mergeChains.js +81 -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 +20 -0
- package/dist/esm/new-sdk/utils/index.js +3 -1
- package/dist/esm/new-sdk/utils/mergeChains.js +78 -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 +19 -40
- package/dist/types/new-sdk/opportunities/index.d.ts +2 -2
- package/dist/types/new-sdk/opportunities/types.d.ts +80 -26
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +17 -38
- package/dist/types/new-sdk/positions/index.d.ts +2 -2
- package/dist/types/new-sdk/positions/types.d.ts +74 -24
- package/dist/types/new-sdk/types.d.ts +24 -77
- package/dist/types/new-sdk/utils/filterResponse.d.ts +16 -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 +20 -0
- package/dist/types/new-sdk/utils/types.d.ts +11 -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,10 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/model/filters.ts
|
|
3
3
|
/**
|
|
4
|
-
* The vocabulary every read-model filter is written in: how a single condition
|
|
5
|
-
* says "do not narrow", and how a predicate asks whether it narrows at all.
|
|
6
|
-
**/
|
|
7
|
-
/**
|
|
8
4
|
* Sentinel a filter condition can be set to instead of being omitted.
|
|
9
5
|
**/
|
|
10
6
|
const FILTER_ALL = "all";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./filters.js");
|
|
2
|
+
const require_model_filters = require("./filters.js");
|
|
3
3
|
let zod_v4 = require("zod/v4");
|
|
4
4
|
//#region src/model/filters.schema.ts
|
|
5
5
|
/**
|
|
@@ -17,7 +17,16 @@ function filterable(schema) {
|
|
|
17
17
|
return zod_v4.z.union([schema, filterAllSchema]);
|
|
18
18
|
}
|
|
19
19
|
const booleanParamSchema = zod_v4.z.enum(["true", "false"]);
|
|
20
|
+
/**
|
|
21
|
+
* A boolean condition as a URL can carry it: a condition that does not narrow
|
|
22
|
+
* is absent rather than spelled out, see {@link booleanParamSchema}.
|
|
23
|
+
**/
|
|
24
|
+
function encodeFlag(condition) {
|
|
25
|
+
if (!require_model_filters.isFilterSet(condition)) return;
|
|
26
|
+
return condition ? "true" : "false";
|
|
27
|
+
}
|
|
20
28
|
//#endregion
|
|
21
29
|
exports.booleanParamSchema = booleanParamSchema;
|
|
30
|
+
exports.encodeFlag = encodeFlag;
|
|
22
31
|
exports.filterAllSchema = filterAllSchema;
|
|
23
32
|
exports.filterable = filterable;
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -33,6 +33,7 @@ exports.curatorNameSchema = require_model_curators_schema.curatorNameSchema;
|
|
|
33
33
|
exports.curatorSchema = require_model_curators_schema.curatorSchema;
|
|
34
34
|
exports.dataSourceSchema = require_model_response_schema.dataSourceSchema;
|
|
35
35
|
exports.delayedReceivedAssetSchema = require_model_liquidations_schema.delayedReceivedAssetSchema;
|
|
36
|
+
exports.encodeFlag = require_model_filters_schema.encodeFlag;
|
|
36
37
|
exports.filterAllSchema = require_model_filters_schema.filterAllSchema;
|
|
37
38
|
exports.filterable = require_model_filters_schema.filterable;
|
|
38
39
|
exports.historyChartMetadataSchema = require_model_history_schema.historyChartMetadataSchema;
|
|
@@ -77,6 +78,8 @@ exports.poolPositionId = require_model_positions.poolPositionId;
|
|
|
77
78
|
exports.poolPositionKeySchema = require_model_positions_schema.poolPositionKeySchema;
|
|
78
79
|
exports.poolPositionSchema = require_model_positions_schema.poolPositionSchema;
|
|
79
80
|
exports.positionCollateralSchema = require_model_positions_schema.positionCollateralSchema;
|
|
81
|
+
exports.positionFilterQueryParamsSchema = require_model_positions_schema.positionFilterQueryParamsSchema;
|
|
82
|
+
exports.positionFilterQuerySchema = require_model_positions_schema.positionFilterQuerySchema;
|
|
80
83
|
exports.positionFilterSchema = require_model_positions_schema.positionFilterSchema;
|
|
81
84
|
exports.positionHistoryMetricSchema = require_model_history_schema.positionHistoryMetricSchema;
|
|
82
85
|
exports.positionHistoryQuerySchema = require_model_history_schema.positionHistoryQuerySchema;
|
|
@@ -14,7 +14,7 @@ const require_model_filters = require("./filters.js");
|
|
|
14
14
|
**/
|
|
15
15
|
function matchesLiquidatableAccountFilter(account, filter) {
|
|
16
16
|
if (!filter) return true;
|
|
17
|
-
if (
|
|
17
|
+
if (filter.chainIds && !filter.chainIds.includes(account.chainId)) return false;
|
|
18
18
|
if (require_model_filters.isFilterSet(filter.underlyingType) && account.totalValue.token.assetType !== filter.underlyingType) return false;
|
|
19
19
|
if (require_model_filters.isFilterSet(filter.paused) && account.paused !== filter.paused) return false;
|
|
20
20
|
if (require_model_filters.isFilterSet(filter.rwa) && account.rwa !== filter.rwa) return false;
|
|
@@ -12,7 +12,7 @@ let zod_v4 = require("zod/v4");
|
|
|
12
12
|
* {@link LiquidatableAccountFilter}
|
|
13
13
|
**/
|
|
14
14
|
const liquidatableAccountFilterSchema = zod_v4.z.object({
|
|
15
|
-
chainIds:
|
|
15
|
+
chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
|
|
16
16
|
underlyingType: require_model_filters_schema.filterable(require_model_primitives_schema.assetTypeSchema).optional(),
|
|
17
17
|
paused: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
|
|
18
18
|
rwa: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
|
|
@@ -43,7 +43,7 @@ function opportunityId(opportunity) {
|
|
|
43
43
|
function matchesOpportunityFilter(opportunity, filter) {
|
|
44
44
|
if (!filter) return true;
|
|
45
45
|
if (require_model_filters.isFilterSet(filter.kind) && opportunity.kind !== filter.kind) return false;
|
|
46
|
-
if (
|
|
46
|
+
if (filter.chainIds && !filter.chainIds.includes(opportunity.chainId)) return false;
|
|
47
47
|
if (require_model_filters.isFilterSet(filter.underlyingType) && opportunity.underlyingToken.assetType !== filter.underlyingType) return false;
|
|
48
48
|
if (require_model_filters.isFilterSet(filter.paused) && opportunity.paused !== filter.paused) return false;
|
|
49
49
|
if (require_model_filters.isFilterSet(filter.sunset) && opportunity.sunset !== filter.sunset) return false;
|
|
@@ -106,7 +106,7 @@ const opportunitySchema = zod_v4.z.discriminatedUnion("kind", [poolOpportunitySc
|
|
|
106
106
|
**/
|
|
107
107
|
const opportunityFilterSchema = zod_v4.z.object({
|
|
108
108
|
kind: require_model_filters_schema.filterable(opportunityKindSchema).optional(),
|
|
109
|
-
chainIds:
|
|
109
|
+
chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
|
|
110
110
|
underlyingType: require_model_filters_schema.filterable(require_model_primitives_schema.assetTypeSchema).optional(),
|
|
111
111
|
paused: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
|
|
112
112
|
sunset: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
|
|
@@ -131,7 +131,7 @@ const opportunityFilterQuerySchema = zod_v4.z.codec(opportunityFilterQueryParams
|
|
|
131
131
|
decode: (params) => {
|
|
132
132
|
const filter = {};
|
|
133
133
|
if (params.kind !== void 0) filter.kind = params.kind;
|
|
134
|
-
if (params.chainIds !== void 0) filter.chainIds =
|
|
134
|
+
if (params.chainIds !== void 0) filter.chainIds = params.chainIds === "" ? [] : params.chainIds.split(",").map(Number);
|
|
135
135
|
if (params.underlyingType !== void 0) filter.underlyingType = params.underlyingType;
|
|
136
136
|
if (params.paused !== void 0) filter.paused = params.paused === "true";
|
|
137
137
|
if (params.sunset !== void 0) filter.sunset = params.sunset === "true";
|
|
@@ -140,20 +140,13 @@ const opportunityFilterQuerySchema = zod_v4.z.codec(opportunityFilterQueryParams
|
|
|
140
140
|
},
|
|
141
141
|
encode: (filter) => ({
|
|
142
142
|
kind: require_model_filters.isFilterSet(filter.kind) ? filter.kind : void 0,
|
|
143
|
-
chainIds:
|
|
143
|
+
chainIds: filter.chainIds?.join(","),
|
|
144
144
|
underlyingType: require_model_filters.isFilterSet(filter.underlyingType) ? filter.underlyingType : void 0,
|
|
145
|
-
paused: encodeFlag(filter.paused),
|
|
146
|
-
sunset: encodeFlag(filter.sunset),
|
|
147
|
-
rwa: encodeFlag(filter.rwa)
|
|
145
|
+
paused: require_model_filters_schema.encodeFlag(filter.paused),
|
|
146
|
+
sunset: require_model_filters_schema.encodeFlag(filter.sunset),
|
|
147
|
+
rwa: require_model_filters_schema.encodeFlag(filter.rwa)
|
|
148
148
|
})
|
|
149
149
|
});
|
|
150
|
-
function decodeChainIds(param) {
|
|
151
|
-
return param === "" ? [] : param.split(",").map(Number);
|
|
152
|
-
}
|
|
153
|
-
function encodeFlag(condition) {
|
|
154
|
-
if (!require_model_filters.isFilterSet(condition)) return;
|
|
155
|
-
return condition ? "true" : "false";
|
|
156
|
-
}
|
|
157
150
|
/**
|
|
158
151
|
* {@link RateCurvePoint}
|
|
159
152
|
**/
|
|
@@ -65,7 +65,7 @@ function positionId(position) {
|
|
|
65
65
|
function matchesPositionFilter(position, filter) {
|
|
66
66
|
if (!filter) return true;
|
|
67
67
|
if (require_model_filters.isFilterSet(filter.kind) && position.kind !== filter.kind) return false;
|
|
68
|
-
if (
|
|
68
|
+
if (filter.chainIds && !filter.chainIds.includes(position.chainId)) return false;
|
|
69
69
|
if (require_model_filters.isFilterSet(filter.isZeroDebt) && position.kind === "strategy" && position.totalDebt.value === 0n !== filter.isZeroDebt) return false;
|
|
70
70
|
if (require_model_filters.isFilterSet(filter.underlyingType)) {
|
|
71
71
|
const underlying = positionUnderlying(position);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_zod = require("../sdk/utils/zod.js");
|
|
3
|
+
const require_model_filters = require("./filters.js");
|
|
3
4
|
const require_model_filters_schema = require("./filters.schema.js");
|
|
4
5
|
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
5
6
|
const require_model_opportunities_schema = require("./opportunities.schema.js");
|
|
@@ -104,10 +105,39 @@ const positionSchema = zod_v4.z.discriminatedUnion("kind", [
|
|
|
104
105
|
const positionFilterSchema = zod_v4.z.object({
|
|
105
106
|
kind: require_model_filters_schema.filterable(positionKindSchema).optional(),
|
|
106
107
|
isZeroDebt: require_model_filters_schema.filterable(zod_v4.z.boolean()).optional(),
|
|
107
|
-
chainIds:
|
|
108
|
+
chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
|
|
108
109
|
underlyingType: require_model_filters_schema.filterable(require_model_primitives_schema.assetTypeSchema).optional()
|
|
109
110
|
});
|
|
110
111
|
/**
|
|
112
|
+
* {@link PositionFilter} as a URL can carry it: every condition is a string,
|
|
113
|
+
* and a condition that does not narrow is absent rather than empty.
|
|
114
|
+
**/
|
|
115
|
+
const positionFilterQueryParamsSchema = zod_v4.z.object({
|
|
116
|
+
kind: positionKindSchema.optional(),
|
|
117
|
+
isZeroDebt: require_model_filters_schema.booleanParamSchema.optional(),
|
|
118
|
+
chainIds: zod_v4.z.string().regex(/^$|^\d+(,\d+)*$/).optional(),
|
|
119
|
+
underlyingType: require_model_primitives_schema.assetTypeSchema.optional()
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Code for {@link PositionFilter} to encode/decode to/from url query parameters.
|
|
123
|
+
**/
|
|
124
|
+
const positionFilterQuerySchema = zod_v4.z.codec(positionFilterQueryParamsSchema, positionFilterSchema, {
|
|
125
|
+
decode: (params) => {
|
|
126
|
+
const filter = {};
|
|
127
|
+
if (params.kind !== void 0) filter.kind = params.kind;
|
|
128
|
+
if (params.isZeroDebt !== void 0) filter.isZeroDebt = params.isZeroDebt === "true";
|
|
129
|
+
if (params.chainIds !== void 0) filter.chainIds = params.chainIds === "" ? [] : params.chainIds.split(",").map(Number);
|
|
130
|
+
if (params.underlyingType !== void 0) filter.underlyingType = params.underlyingType;
|
|
131
|
+
return filter;
|
|
132
|
+
},
|
|
133
|
+
encode: (filter) => ({
|
|
134
|
+
kind: require_model_filters.isFilterSet(filter.kind) ? filter.kind : void 0,
|
|
135
|
+
isZeroDebt: require_model_filters_schema.encodeFlag(filter.isZeroDebt),
|
|
136
|
+
chainIds: filter.chainIds?.join(","),
|
|
137
|
+
underlyingType: require_model_filters.isFilterSet(filter.underlyingType) ? filter.underlyingType : void 0
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
/**
|
|
111
141
|
* {@link PoolPositionKey}
|
|
112
142
|
**/
|
|
113
143
|
const poolPositionKeySchema = zod_v4.z.object({
|
|
@@ -139,6 +169,8 @@ exports.pointsRewardsPnLSchema = pointsRewardsPnLSchema;
|
|
|
139
169
|
exports.poolPositionKeySchema = poolPositionKeySchema;
|
|
140
170
|
exports.poolPositionSchema = poolPositionSchema;
|
|
141
171
|
exports.positionCollateralSchema = positionCollateralSchema;
|
|
172
|
+
exports.positionFilterQueryParamsSchema = positionFilterQueryParamsSchema;
|
|
173
|
+
exports.positionFilterQuerySchema = positionFilterQuerySchema;
|
|
142
174
|
exports.positionFilterSchema = positionFilterSchema;
|
|
143
175
|
exports.positionKeySchema = positionKeySchema;
|
|
144
176
|
exports.positionKindSchema = positionKindSchema;
|
|
@@ -12,22 +12,25 @@ let zod_v4 = require("zod/v4");
|
|
|
12
12
|
/**
|
|
13
13
|
* {@link DataSource}
|
|
14
14
|
**/
|
|
15
|
-
const dataSourceSchema = zod_v4.z.
|
|
15
|
+
const dataSourceSchema = zod_v4.z.enum(["onchain", "offchain"]);
|
|
16
16
|
/**
|
|
17
17
|
* {@link ChainSucceeded}
|
|
18
|
+
*
|
|
19
|
+
* `source` may be omitted by the backend and decodes to `"offchain"`. The block
|
|
20
|
+
* has no such default: a success that omits it fails validation.
|
|
18
21
|
**/
|
|
19
22
|
const chainSucceededSchema = zod_v4.z.object({
|
|
20
23
|
chainId: require_model_primitives_schema.chainIdSchema,
|
|
21
24
|
status: zod_v4.z.literal("success"),
|
|
22
|
-
source: dataSourceSchema,
|
|
23
|
-
blockNumber: zod_v4.z.number().int().nonnegative()
|
|
24
|
-
timestamp: require_model_primitives_schema.timestampSchema
|
|
25
|
+
source: dataSourceSchema.default("offchain"),
|
|
26
|
+
blockNumber: zod_v4.z.number().int().nonnegative(),
|
|
27
|
+
timestamp: require_model_primitives_schema.timestampSchema
|
|
25
28
|
});
|
|
26
29
|
/**
|
|
27
30
|
* {@link ChainFailed}
|
|
28
31
|
*
|
|
29
|
-
* `error` is a `string`
|
|
30
|
-
* codec also validates a locally produced envelope
|
|
32
|
+
* `error` is a `string` in a JSON body. The schema accepts `unknown` so the
|
|
33
|
+
* same codec also validates a locally produced envelope carrying an `Error`.
|
|
31
34
|
**/
|
|
32
35
|
const chainFailedSchema = zod_v4.z.object({
|
|
33
36
|
chainId: require_model_primitives_schema.chainIdSchema,
|
|
@@ -1,158 +1,76 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_new_sdk_errors_AllSourcesFailedError = require("./errors/AllSourcesFailedError.js");
|
|
3
|
+
const require_new_sdk_errors_everyChainFailed = require("./errors/everyChainFailed.js");
|
|
4
|
+
const require_new_sdk_errors_SourceUnavailableError = require("./errors/SourceUnavailableError.js");
|
|
5
|
+
require("./errors/index.js");
|
|
4
6
|
//#region src/new-sdk/AbstractNamespace.ts
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Base class of every {@link GearboxSDK} namespace: holds the two source
|
|
9
|
+
* namespaces, exposes each on its own, and runs merged reads over both.
|
|
7
10
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* envelope and the all-sources-failed rule — so a namespace holds nothing but
|
|
12
|
-
* its reads and its merge policy.
|
|
13
|
-
*
|
|
14
|
-
* The sources are whatever it was handed, and their readiness is their owner's
|
|
15
|
-
* business: a source that is not ready to answer fails the read it was given,
|
|
16
|
-
* and that failure is reported like any other.
|
|
17
|
-
*
|
|
18
|
-
* All protocol knowledge lives in the sources: `MultichainSDK` for the chain,
|
|
19
|
-
* `GearboxAPI` for the backend. None of it is repeated here or in a subclass.
|
|
20
|
-
*
|
|
21
|
-
* @typeParam ListRow - Row type of the namespace's list read.
|
|
11
|
+
* @typeParam Onchain - On-chain source namespace, e.g.
|
|
12
|
+
* `MultichainOpportunitiesService`.
|
|
13
|
+
* @typeParam Offchain - Backend source namespace, e.g. `OffchainOpportunities`.
|
|
22
14
|
**/
|
|
23
15
|
var AbstractNamespace = class {
|
|
16
|
+
/**
|
|
17
|
+
* How far the backend may lag the chain and still serve a chain.
|
|
18
|
+
**/
|
|
19
|
+
maxOffchainLagSeconds;
|
|
24
20
|
logger;
|
|
21
|
+
#name;
|
|
25
22
|
#onchain;
|
|
26
23
|
#offchain;
|
|
27
|
-
constructor(name, onchain, offchain,
|
|
24
|
+
constructor(name, onchain, offchain, options) {
|
|
25
|
+
this.#name = name;
|
|
28
26
|
this.#onchain = onchain;
|
|
29
27
|
this.#offchain = offchain;
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Asks both sources in parallel and combines whatever answered.
|
|
34
|
-
*
|
|
35
|
-
* The action name is only used in diagnostics and in the error raised when
|
|
36
|
-
* every source the read had failed.
|
|
37
|
-
**/
|
|
38
|
-
async read(action, fromChain, fromBackend, combine) {
|
|
39
|
-
const [onchain, offchain] = await Promise.all([this.fromChain(fromChain), this.fromBackend(fromBackend)]);
|
|
40
|
-
const meta = toMeta(onchain, offchain);
|
|
41
|
-
this.assertAnySourceSucceeded(action, meta);
|
|
42
|
-
return {
|
|
43
|
-
result: combine(onchain.value, offchain.value),
|
|
44
|
-
meta
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Reads the namespace's list from both sources, unioned by
|
|
49
|
-
* {@link AbstractNamespace.mergeList}.
|
|
50
|
-
**/
|
|
51
|
-
async readList(action, fromChain, fromBackend) {
|
|
52
|
-
return this.read(action, fromChain, fromBackend, (onchain, offchain) => this.mergeList(onchain ?? [], offchain ?? []));
|
|
28
|
+
this.maxOffchainLagSeconds = options.maxOffchainLagSeconds;
|
|
29
|
+
this.logger = options.logger?.child?.({ name }) ?? options.logger;
|
|
53
30
|
}
|
|
54
31
|
/**
|
|
55
|
-
*
|
|
56
|
-
* {@link
|
|
57
|
-
* on-chain leg queries exactly one.
|
|
32
|
+
* The on-chain source namespace on its own. Throws
|
|
33
|
+
* {@link SourceUnavailableError} in `offchain` mode.
|
|
58
34
|
**/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!network) return { chains: [] };
|
|
63
|
-
return this.onOneChain(action, network, () => fromChain(sdk));
|
|
64
|
-
}, fromBackend, (onchain, offchain) => {
|
|
65
|
-
if (onchain && offchain) return this.mergeOne(onchain, offchain);
|
|
66
|
-
return onchain ?? offchain;
|
|
67
|
-
});
|
|
35
|
+
get onchain() {
|
|
36
|
+
if (!this.#onchain) throw new require_new_sdk_errors_SourceUnavailableError.SourceUnavailableError(this.#name, "onchain");
|
|
37
|
+
return this.#onchain;
|
|
68
38
|
}
|
|
69
39
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* The fallback stands in for a backend that answered with nothing, which is
|
|
73
|
-
* a different thing from a backend that failed and was dropped.
|
|
40
|
+
* The backend source namespace on its own. Throws
|
|
41
|
+
* {@link SourceUnavailableError} in `onchain` mode.
|
|
74
42
|
**/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.assertAnySourceSucceeded(action, meta);
|
|
79
|
-
return {
|
|
80
|
-
result: offchain.value ?? fallback,
|
|
81
|
-
meta
|
|
82
|
-
};
|
|
43
|
+
get offchain() {
|
|
44
|
+
if (!this.#offchain) throw new require_new_sdk_errors_SourceUnavailableError.SourceUnavailableError(this.#name, "offchain");
|
|
45
|
+
return this.#offchain;
|
|
83
46
|
}
|
|
84
47
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
48
|
+
* Asks both sources at once and merges what came back, failing only when no
|
|
49
|
+
* chain was served at all.
|
|
87
50
|
**/
|
|
88
|
-
async
|
|
89
|
-
|
|
51
|
+
async merged(action, query) {
|
|
52
|
+
const onchain = this.#onchain;
|
|
53
|
+
const offchain = this.#offchain;
|
|
54
|
+
const [fromChain, fromBackend] = await Promise.all([this.#ask(action, "onchain", onchain, query.fromChain), this.#ask(action, "offchain", offchain, query.fromBackend)]);
|
|
55
|
+
const merged = query.merge(fromChain.response, fromBackend.response);
|
|
56
|
+
if (merged && !require_new_sdk_errors_everyChainFailed.everyChainFailed(merged.meta)) return merged;
|
|
57
|
+
const sole = onchain && offchain ? void 0 : fromChain.error ?? fromBackend.error;
|
|
58
|
+
if (sole !== void 0) throw sole;
|
|
59
|
+
throw new require_new_sdk_errors_AllSourcesFailedError.AllSourcesFailedError(action, [fromChain.error, fromBackend.error], merged?.meta);
|
|
90
60
|
}
|
|
91
61
|
/**
|
|
92
|
-
* Runs a read
|
|
93
|
-
*
|
|
62
|
+
* Runs one source's leg of a read, skipping a source this mode does not have
|
|
63
|
+
* and turning a rejection into an outcome.
|
|
94
64
|
**/
|
|
95
|
-
async
|
|
96
|
-
if (
|
|
65
|
+
async #ask(action, label, source, run) {
|
|
66
|
+
if (source === void 0) return {};
|
|
97
67
|
try {
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
value: meta.status === "success" ? result : void 0,
|
|
101
|
-
status: meta
|
|
102
|
-
};
|
|
68
|
+
return { response: await run(source) };
|
|
103
69
|
} catch (error) {
|
|
104
|
-
this.logger?.warn(error,
|
|
105
|
-
return {
|
|
106
|
-
status: "error",
|
|
107
|
-
error
|
|
108
|
-
} };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Runs a read against one chain, turning a rejection into that chain's
|
|
113
|
-
* metadata entry.
|
|
114
|
-
**/
|
|
115
|
-
async onOneChain(action, network, run) {
|
|
116
|
-
try {
|
|
117
|
-
return {
|
|
118
|
-
value: await run(),
|
|
119
|
-
chains: [{
|
|
120
|
-
network,
|
|
121
|
-
status: "success"
|
|
122
|
-
}]
|
|
123
|
-
};
|
|
124
|
-
} catch (error) {
|
|
125
|
-
this.logger?.warn(error, `failed to ${action} on ${network}`);
|
|
126
|
-
return { chains: [{
|
|
127
|
-
network,
|
|
128
|
-
status: "error",
|
|
129
|
-
error
|
|
130
|
-
}] };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* A read that reached at least one source returns what it has; a read where
|
|
135
|
-
* every source it had failed throws, because an empty result would otherwise
|
|
136
|
-
* be indistinguishable from "there is nothing here".
|
|
137
|
-
**/
|
|
138
|
-
assertAnySourceSucceeded(action, meta) {
|
|
139
|
-
const asked = meta.chains.length > 0 || meta.offchain !== void 0;
|
|
140
|
-
const answered = meta.chains.some((c) => c.status === "success") || meta.offchain?.status === "success";
|
|
141
|
-
if (asked && !answered) throw new require_new_sdk_types.AllSourcesFailedError(action, meta);
|
|
142
|
-
}
|
|
143
|
-
networkOf(chainId) {
|
|
144
|
-
try {
|
|
145
|
-
return require_sdk_chain_chains.getNetworkType(chainId);
|
|
146
|
-
} catch {
|
|
147
|
-
this.logger?.debug(`chain ${chainId} is not a Gearbox network, skipping the onchain source`);
|
|
148
|
-
return;
|
|
70
|
+
this.logger?.warn(error, `failed to ${action} from the ${label} source`);
|
|
71
|
+
return { error };
|
|
149
72
|
}
|
|
150
73
|
}
|
|
151
74
|
};
|
|
152
|
-
function toMeta(onchain, offchain) {
|
|
153
|
-
const meta = { chains: onchain.chains };
|
|
154
|
-
if (offchain.status) meta.offchain = offchain.status;
|
|
155
|
-
return meta;
|
|
156
|
-
}
|
|
157
75
|
//#endregion
|
|
158
76
|
exports.AbstractNamespace = AbstractNamespace;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_chain_chains = require("../sdk/chain/chains.js");
|
|
2
3
|
const require_sdk_MultichainSDK = require("../sdk/MultichainSDK.js");
|
|
3
4
|
require("../sdk/index.js");
|
|
5
|
+
const require_new_sdk_errors_assertSameChains = require("./errors/assertSameChains.js");
|
|
6
|
+
const require_new_sdk_errors_MissingSourceError = require("./errors/MissingSourceError.js");
|
|
7
|
+
require("./errors/index.js");
|
|
4
8
|
const require_offchain_GearboxAPI = require("../offchain/GearboxAPI.js");
|
|
5
9
|
require("../offchain/index.js");
|
|
10
|
+
require("./utils/mergeChains.js");
|
|
11
|
+
require("./utils/index.js");
|
|
6
12
|
const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
|
|
7
13
|
require("./opportunities/index.js");
|
|
8
14
|
const require_new_sdk_positions_PositionsNamespace = require("./positions/PositionsNamespace.js");
|
|
9
15
|
require("./positions/index.js");
|
|
10
16
|
//#region src/new-sdk/GearboxSDK.ts
|
|
11
17
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* The {@link Mode} is fixed at construction and decides which methods exist,
|
|
16
|
-
* not what they return, so a screen written against `both` cannot silently
|
|
17
|
-
* degrade to a subset when someone reconfigures the SDK:
|
|
18
|
+
* Entry point over both sources of Gearbox data: the chain and the Gearbox
|
|
19
|
+
* backend. The {@link Mode} is fixed at construction and decides which methods
|
|
20
|
+
* exist.
|
|
18
21
|
*
|
|
19
22
|
* ```ts
|
|
20
23
|
* const sdk = new GearboxSDK({
|
|
@@ -25,13 +28,9 @@ require("./positions/index.js");
|
|
|
25
28
|
* });
|
|
26
29
|
* await sdk.attach();
|
|
27
30
|
*
|
|
28
|
-
* const {
|
|
31
|
+
* const { data, meta } = await sdk.opportunities.list({ kind: "strategy" });
|
|
29
32
|
* ```
|
|
30
33
|
*
|
|
31
|
-
* Every read answers with `{ result, meta }`: `meta` says which chains and
|
|
32
|
-
* which backend answered, because a partial answer is the normal case for a
|
|
33
|
-
* multi-chain read.
|
|
34
|
-
*
|
|
35
34
|
* @typeParam M - Mode the instance was built in.
|
|
36
35
|
**/
|
|
37
36
|
var GearboxSDK = class {
|
|
@@ -40,8 +39,7 @@ var GearboxSDK = class {
|
|
|
40
39
|
**/
|
|
41
40
|
mode;
|
|
42
41
|
/**
|
|
43
|
-
* Chains this instance covers
|
|
44
|
-
* SDK covers a different set.
|
|
42
|
+
* Chains this instance covers, which every read is scoped to.
|
|
45
43
|
**/
|
|
46
44
|
networks;
|
|
47
45
|
/**
|
|
@@ -55,46 +53,51 @@ var GearboxSDK = class {
|
|
|
55
53
|
#attachOptions;
|
|
56
54
|
#onchain;
|
|
57
55
|
#offchain;
|
|
58
|
-
/**
|
|
59
|
-
* Whether this instance built the on-chain SDK, and therefore attaches it.
|
|
60
|
-
**/
|
|
61
56
|
#ownsOnchain = false;
|
|
62
57
|
#attached;
|
|
63
58
|
constructor(options) {
|
|
64
|
-
const { mode, networks, onchain, offchain, attach, logger } = options;
|
|
59
|
+
const { mode, networks, onchain, offchain, attach, logger, maxOffchainLagSeconds = 120 } = options;
|
|
65
60
|
this.mode = mode;
|
|
66
61
|
this.networks = [...networks];
|
|
67
62
|
this.#attachOptions = attach;
|
|
68
63
|
const needsOnchain = mode === "onchain" || mode === "both";
|
|
69
64
|
const needsOffchain = mode === "offchain" || mode === "both";
|
|
70
|
-
if (needsOnchain && !onchain) throw new
|
|
71
|
-
if (needsOffchain && !offchain) throw new
|
|
65
|
+
if (needsOnchain && !onchain) throw new require_new_sdk_errors_MissingSourceError.MissingSourceError(mode, "onchain");
|
|
66
|
+
if (needsOffchain && !offchain) throw new require_new_sdk_errors_MissingSourceError.MissingSourceError(mode, "offchain");
|
|
72
67
|
if (!needsOnchain && onchain) logger?.warn(`GearboxSDK in ${mode} mode ignores the onchain source it was given`);
|
|
73
68
|
if (!needsOffchain && offchain) logger?.warn(`GearboxSDK in ${mode} mode ignores the offchain source it was given`);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.#onchain =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
const chainIds = require_sdk_chain_chains.toChainIds(networks);
|
|
70
|
+
if (needsOnchain && onchain) {
|
|
71
|
+
if (onchain instanceof require_sdk_MultichainSDK.MultichainSDK) this.#onchain = onchain;
|
|
72
|
+
else {
|
|
73
|
+
this.#onchain = new require_sdk_MultichainSDK.MultichainSDK({
|
|
74
|
+
logger,
|
|
75
|
+
...onchain,
|
|
76
|
+
chains: chainsOf(onchain.chains, networks)
|
|
77
|
+
});
|
|
78
|
+
this.#ownsOnchain = true;
|
|
79
|
+
}
|
|
80
|
+
require_new_sdk_errors_assertSameChains.assertSameChains("onchain", networks, [...this.#onchain.chains.keys()]);
|
|
81
81
|
}
|
|
82
|
-
if (needsOffchain && offchain)
|
|
82
|
+
if (needsOffchain && offchain) if (offchain instanceof require_offchain_GearboxAPI.GearboxAPI) {
|
|
83
|
+
require_new_sdk_errors_assertSameChains.assertSameChains("offchain", chainIds, offchain.chainIds);
|
|
84
|
+
this.#offchain = offchain;
|
|
85
|
+
} else this.#offchain = new require_offchain_GearboxAPI.GearboxAPI({
|
|
83
86
|
logger,
|
|
84
|
-
...offchain
|
|
87
|
+
...offchain,
|
|
88
|
+
chainIds
|
|
85
89
|
});
|
|
86
90
|
this.#attached = !this.#ownsOnchain;
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
const namespaceOptions = {
|
|
92
|
+
maxOffchainLagSeconds,
|
|
93
|
+
logger
|
|
94
|
+
};
|
|
95
|
+
this.opportunities = new require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace(this.#onchain, this.#offchain, namespaceOptions);
|
|
96
|
+
this.positions = new require_new_sdk_positions_PositionsNamespace.PositionsNamespace(this.#onchain, this.#offchain, namespaceOptions);
|
|
89
97
|
}
|
|
90
98
|
/**
|
|
91
|
-
* Attaches the on-chain SDK when this instance owns one
|
|
92
|
-
*
|
|
93
|
-
* Reads issued before this resolves still reach the chain and fail there, so
|
|
94
|
-
* in `both` mode they are served from the backend alone and report the chain
|
|
95
|
-
* as failed in their meta, rather than blocking.
|
|
96
|
-
*
|
|
97
|
-
* A no-op in `offchain` mode and when an already-attached SDK was injected.
|
|
99
|
+
* Attaches the on-chain SDK when this instance owns one; a no-op in `offchain`
|
|
100
|
+
* mode and when an already-attached SDK was injected.
|
|
98
101
|
**/
|
|
99
102
|
async attach() {
|
|
100
103
|
if (this.#attached || !this.#ownsOnchain || !this.#onchain) return;
|
|
@@ -103,17 +106,15 @@ var GearboxSDK = class {
|
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
108
|
* Whether the on-chain source is ready to be read from. Always `true` in
|
|
106
|
-
* `offchain` mode
|
|
109
|
+
* `offchain` mode.
|
|
107
110
|
**/
|
|
108
111
|
get attached() {
|
|
109
112
|
return this.mode === "offchain" ? true : this.#attached;
|
|
110
113
|
}
|
|
111
114
|
/**
|
|
112
115
|
* The underlying on-chain SDK, for everything this facade does not expose
|
|
113
|
-
* yet: markets, credit accounts, transaction building.
|
|
114
|
-
*
|
|
115
|
-
* `undefined` in `offchain` mode. Otherwise it exists from construction on,
|
|
116
|
-
* but only answers reads once {@link attach} has resolved.
|
|
116
|
+
* yet: markets, credit accounts, transaction building. `undefined` in
|
|
117
|
+
* `offchain` mode, and only answers reads once {@link attach} has resolved.
|
|
117
118
|
**/
|
|
118
119
|
get onchain() {
|
|
119
120
|
return this.#onchain;
|
|
@@ -125,5 +126,17 @@ var GearboxSDK = class {
|
|
|
125
126
|
return this.#offchain;
|
|
126
127
|
}
|
|
127
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Per-chain configuration of exactly the networks the SDK covers.
|
|
131
|
+
**/
|
|
132
|
+
function chainsOf(configured, networks) {
|
|
133
|
+
const chains = {};
|
|
134
|
+
for (const network of networks) {
|
|
135
|
+
const chain = configured[network];
|
|
136
|
+
if (!chain) throw new Error(`GearboxSDK covers ${network}, but its onchain source has no configuration for it`);
|
|
137
|
+
chains[network] = chain;
|
|
138
|
+
}
|
|
139
|
+
return chains;
|
|
140
|
+
}
|
|
128
141
|
//#endregion
|
|
129
142
|
exports.GearboxSDK = GearboxSDK;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/new-sdk/errors/AllSourcesFailedError.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when a read had sources to ask and none of them served a single chain.
|
|
5
|
+
**/
|
|
6
|
+
var AllSourcesFailedError = class extends AggregateError {
|
|
7
|
+
constructor(action, sourceErrors, meta) {
|
|
8
|
+
const causes = [...sourceErrors, ...chainErrors(meta)].filter((reason) => reason !== void 0);
|
|
9
|
+
super(causes, `cannot ${action}, every source failed (${causes.join("; ")})`);
|
|
10
|
+
this.name = "AllSourcesFailedError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Why each chain a merged envelope did report failed.
|
|
15
|
+
**/
|
|
16
|
+
function chainErrors(meta) {
|
|
17
|
+
return (meta?.chains ?? []).map((chain) => chain.status === "error" ? chain.error : void 0);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.AllSourcesFailedError = AllSourcesFailedError;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
//#region src/new-sdk/errors/MissingSourceError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown at construction when a {@link GearboxSDK} was not given a source its
|
|
6
|
+
* {@link Mode} reads from.
|
|
7
|
+
**/
|
|
8
|
+
var MissingSourceError = class extends viem.BaseError {
|
|
9
|
+
name = "MissingSourceError";
|
|
10
|
+
/**
|
|
11
|
+
* Mode the SDK was built in.
|
|
12
|
+
**/
|
|
13
|
+
mode;
|
|
14
|
+
/**
|
|
15
|
+
* Source that mode needs and did not get.
|
|
16
|
+
**/
|
|
17
|
+
source;
|
|
18
|
+
constructor(mode, source) {
|
|
19
|
+
super(`A GearboxSDK in ${mode} mode needs an ${source} source.`);
|
|
20
|
+
this.mode = mode;
|
|
21
|
+
this.source = source;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.MissingSourceError = MissingSourceError;
|