@gearbox-protocol/sdk 14.12.0-next.71 → 14.12.0-next.72
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/history.js +25 -0
- package/dist/cjs/model/history.schema.js +45 -1
- package/dist/cjs/model/index.js +17 -3
- package/dist/cjs/model/positions.js +89 -0
- package/dist/cjs/model/positions.schema.js +28 -0
- package/dist/cjs/new-sdk/GearboxSDK.js +7 -0
- package/dist/cjs/new-sdk/index.js +3 -0
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +119 -0
- package/dist/cjs/new-sdk/positions/index.js +4 -0
- package/dist/cjs/new-sdk/positions/types.js +1 -0
- package/dist/cjs/offchain/GearboxAPI.js +9 -2
- package/dist/cjs/offchain/index.js +5 -2
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +3 -14
- package/dist/cjs/offchain/opportunities/index.js +0 -1
- package/dist/cjs/offchain/positions/OffchainPositions.js +69 -0
- package/dist/cjs/offchain/positions/index.js +3 -0
- package/dist/cjs/offchain/types.js +17 -0
- package/dist/cjs/sdk/MultichainSDK.js +7 -0
- package/dist/cjs/sdk/OnchainSDK.js +7 -0
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +84 -0
- package/dist/cjs/sdk/accounts/constants.js +12 -0
- package/dist/cjs/sdk/accounts/dominantCollateral.js +33 -0
- package/dist/cjs/sdk/accounts/index.js +4 -1
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +3 -10
- package/dist/cjs/sdk/accounts/liquidations/constants.js +2 -6
- package/dist/cjs/sdk/accounts/liquidations/index.js +2 -1
- package/dist/cjs/sdk/index.js +11 -1
- package/dist/cjs/sdk/market/MarketSuite.js +7 -1
- package/dist/cjs/sdk/market/credit/CreditSuite.js +10 -1
- package/dist/cjs/sdk/market/math.js +37 -0
- package/dist/cjs/sdk/opportunities/index.js +2 -0
- package/dist/cjs/sdk/pools/PoolService.js +37 -0
- package/dist/cjs/sdk/positions/MultichainPositionsService.js +48 -0
- package/dist/cjs/sdk/positions/PositionsService.js +39 -0
- package/dist/cjs/sdk/positions/index.js +6 -0
- package/dist/cjs/sdk/positions/types.js +1 -0
- package/dist/esm/model/history.js +24 -1
- package/dist/esm/model/history.schema.js +42 -2
- package/dist/esm/model/index.js +6 -6
- package/dist/esm/model/positions.js +85 -1
- package/dist/esm/model/positions.schema.js +26 -1
- package/dist/esm/new-sdk/GearboxSDK.js +7 -0
- package/dist/esm/new-sdk/index.js +3 -1
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +118 -0
- package/dist/esm/new-sdk/positions/index.js +3 -0
- package/dist/esm/new-sdk/positions/types.js +1 -0
- package/dist/esm/offchain/GearboxAPI.js +9 -2
- package/dist/esm/offchain/index.js +5 -3
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +2 -12
- package/dist/esm/offchain/opportunities/index.js +2 -2
- package/dist/esm/offchain/positions/OffchainPositions.js +68 -0
- package/dist/esm/offchain/positions/index.js +2 -0
- package/dist/esm/offchain/types.js +17 -1
- package/dist/esm/sdk/MultichainSDK.js +7 -0
- package/dist/esm/sdk/OnchainSDK.js +7 -0
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +84 -0
- package/dist/esm/sdk/accounts/constants.js +11 -0
- package/dist/esm/sdk/accounts/dominantCollateral.js +32 -0
- package/dist/esm/sdk/accounts/index.js +4 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +3 -10
- package/dist/esm/sdk/accounts/liquidations/constants.js +1 -5
- package/dist/esm/sdk/accounts/liquidations/index.js +2 -1
- package/dist/esm/sdk/index.js +8 -3
- package/dist/esm/sdk/market/MarketSuite.js +7 -1
- package/dist/esm/sdk/market/credit/CreditSuite.js +10 -1
- package/dist/esm/sdk/market/math.js +37 -2
- package/dist/esm/sdk/opportunities/index.js +2 -2
- package/dist/esm/sdk/pools/PoolService.js +37 -0
- package/dist/esm/sdk/positions/MultichainPositionsService.js +47 -0
- package/dist/esm/sdk/positions/PositionsService.js +38 -0
- package/dist/esm/sdk/positions/index.js +4 -0
- package/dist/esm/sdk/positions/types.js +1 -0
- package/dist/types/model/history.d.ts +50 -2
- package/dist/types/model/history.schema.d.ts +32 -3
- package/dist/types/model/index.d.ts +5 -5
- package/dist/types/model/positions.d.ts +100 -1
- package/dist/types/model/positions.schema.d.ts +29 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +2 -2
- package/dist/types/new-sdk/GearboxSDK.d.ts +6 -0
- package/dist/types/new-sdk/index.d.ts +4 -1
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +1 -1
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +62 -0
- package/dist/types/new-sdk/positions/index.d.ts +3 -0
- package/dist/types/new-sdk/positions/types.d.ts +62 -0
- package/dist/types/new-sdk/utils/history.d.ts +6 -2
- package/dist/types/offchain/GearboxAPI.d.ts +8 -2
- package/dist/types/offchain/index.d.ts +5 -3
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -9
- package/dist/types/offchain/opportunities/index.d.ts +2 -2
- package/dist/types/offchain/positions/OffchainPositions.d.ts +47 -0
- package/dist/types/offchain/positions/index.d.ts +2 -0
- package/dist/types/offchain/types.d.ts +12 -1
- package/dist/types/sdk/MultichainSDK.d.ts +6 -0
- package/dist/types/sdk/OnchainSDK.d.ts +6 -0
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +7 -1
- package/dist/types/sdk/accounts/constants.d.ts +11 -0
- package/dist/types/sdk/accounts/dominantCollateral.d.ts +22 -0
- package/dist/types/sdk/accounts/index.d.ts +5 -3
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/constants.d.ts +1 -5
- package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -1
- package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +26 -1
- package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
- package/dist/types/sdk/index.d.ts +11 -5
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +1 -1
- package/dist/types/sdk/market/MarketSuite.d.ts +5 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +8 -1
- package/dist/types/sdk/market/credit/types.d.ts +1 -1
- package/dist/types/sdk/market/math.d.ts +29 -1
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -2
- package/dist/types/sdk/market/oracle/types.d.ts +2 -2
- package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/pool/types.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/types.d.ts +1 -1
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +2 -2
- package/dist/types/sdk/opportunities/index.d.ts +2 -2
- package/dist/types/sdk/pools/PoolService.d.ts +7 -1
- package/dist/types/sdk/pools/index.d.ts +2 -2
- package/dist/types/sdk/pools/types.d.ts +18 -1
- package/dist/types/sdk/positions/MultichainPositionsService.d.ts +33 -0
- package/dist/types/sdk/positions/PositionsService.d.ts +22 -0
- package/dist/types/sdk/positions/index.d.ts +4 -0
- package/dist/types/sdk/positions/types.d.ts +25 -0
- package/package.json +1 -1
|
@@ -23,6 +23,31 @@ const STRATEGY_HISTORY_METRICS = [
|
|
|
23
23
|
"collateralUsdPrice",
|
|
24
24
|
"underlyingUsdPrice"
|
|
25
25
|
];
|
|
26
|
+
/**
|
|
27
|
+
* Every {@link PoolPositionHistoryMetric}, for callers that enumerate them.
|
|
28
|
+
**/
|
|
29
|
+
const POOL_POSITION_HISTORY_METRICS = [
|
|
30
|
+
"depositApy",
|
|
31
|
+
"borrowApy",
|
|
32
|
+
"dieselRate",
|
|
33
|
+
"supplied",
|
|
34
|
+
"borrowed",
|
|
35
|
+
"availableLiquidity"
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Every {@link StrategyPositionHistoryMetric}, for callers that enumerate them.
|
|
39
|
+
**/
|
|
40
|
+
const STRATEGY_POSITION_HISTORY_METRICS = [
|
|
41
|
+
"netApy",
|
|
42
|
+
"borrowApy",
|
|
43
|
+
"collateralApy",
|
|
44
|
+
"tvl",
|
|
45
|
+
"collateralPrice",
|
|
46
|
+
"collateralUsdPrice",
|
|
47
|
+
"underlyingUsdPrice"
|
|
48
|
+
];
|
|
26
49
|
//#endregion
|
|
27
50
|
exports.POOL_HISTORY_METRICS = POOL_HISTORY_METRICS;
|
|
51
|
+
exports.POOL_POSITION_HISTORY_METRICS = POOL_POSITION_HISTORY_METRICS;
|
|
28
52
|
exports.STRATEGY_HISTORY_METRICS = STRATEGY_HISTORY_METRICS;
|
|
53
|
+
exports.STRATEGY_POSITION_HISTORY_METRICS = STRATEGY_POSITION_HISTORY_METRICS;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
3
3
|
const require_model_opportunities_schema = require("./opportunities.schema.js");
|
|
4
|
+
const require_model_positions_schema = require("./positions.schema.js");
|
|
4
5
|
let zod_v4 = require("zod/v4");
|
|
5
6
|
//#region src/model/history.schema.ts
|
|
6
7
|
/**
|
|
@@ -41,9 +42,40 @@ const strategyHistoryMetricSchema = zod_v4.z.union([
|
|
|
41
42
|
zod_v4.z.literal("underlyingUsdPrice")
|
|
42
43
|
]);
|
|
43
44
|
/**
|
|
45
|
+
* {@link PoolPositionHistoryMetric}
|
|
46
|
+
**/
|
|
47
|
+
const poolPositionHistoryMetricSchema = zod_v4.z.union([
|
|
48
|
+
zod_v4.z.literal("depositApy"),
|
|
49
|
+
zod_v4.z.literal("borrowApy"),
|
|
50
|
+
zod_v4.z.literal("dieselRate"),
|
|
51
|
+
zod_v4.z.literal("supplied"),
|
|
52
|
+
zod_v4.z.literal("borrowed"),
|
|
53
|
+
zod_v4.z.literal("availableLiquidity")
|
|
54
|
+
]);
|
|
55
|
+
/**
|
|
56
|
+
* {@link StrategyPositionHistoryMetric}
|
|
57
|
+
**/
|
|
58
|
+
const strategyPositionHistoryMetricSchema = zod_v4.z.union([
|
|
59
|
+
zod_v4.z.literal("netApy"),
|
|
60
|
+
zod_v4.z.literal("borrowApy"),
|
|
61
|
+
zod_v4.z.literal("collateralApy"),
|
|
62
|
+
zod_v4.z.literal("tvl"),
|
|
63
|
+
zod_v4.z.literal("collateralPrice"),
|
|
64
|
+
zod_v4.z.literal("collateralUsdPrice"),
|
|
65
|
+
zod_v4.z.literal("underlyingUsdPrice")
|
|
66
|
+
]);
|
|
67
|
+
/**
|
|
68
|
+
* {@link PositionHistoryMetric}
|
|
69
|
+
**/
|
|
70
|
+
const positionHistoryMetricSchema = zod_v4.z.union([poolPositionHistoryMetricSchema, strategyPositionHistoryMetricSchema]);
|
|
71
|
+
/**
|
|
44
72
|
* {@link HistoryMetric}
|
|
45
73
|
**/
|
|
46
|
-
const historyMetricSchema = zod_v4.z.union([
|
|
74
|
+
const historyMetricSchema = zod_v4.z.union([
|
|
75
|
+
poolHistoryMetricSchema,
|
|
76
|
+
strategyHistoryMetricSchema,
|
|
77
|
+
positionHistoryMetricSchema
|
|
78
|
+
]);
|
|
47
79
|
/**
|
|
48
80
|
* {@link HistoryPoint}
|
|
49
81
|
**/
|
|
@@ -73,6 +105,14 @@ const opportunityHistoryQuerySchema = zod_v4.z.object({
|
|
|
73
105
|
range: historyRangeSchema,
|
|
74
106
|
metric: historyMetricSchema
|
|
75
107
|
});
|
|
108
|
+
/**
|
|
109
|
+
* {@link PositionHistoryQuery}
|
|
110
|
+
**/
|
|
111
|
+
const positionHistoryQuerySchema = zod_v4.z.object({
|
|
112
|
+
position: require_model_positions_schema.positionKeySchema,
|
|
113
|
+
range: historyRangeSchema,
|
|
114
|
+
metric: positionHistoryMetricSchema
|
|
115
|
+
});
|
|
76
116
|
//#endregion
|
|
77
117
|
exports.historyChartMetadataSchema = historyChartMetadataSchema;
|
|
78
118
|
exports.historyMetricSchema = historyMetricSchema;
|
|
@@ -81,4 +121,8 @@ exports.historyRangeSchema = historyRangeSchema;
|
|
|
81
121
|
exports.historySeriesSchema = historySeriesSchema;
|
|
82
122
|
exports.opportunityHistoryQuerySchema = opportunityHistoryQuerySchema;
|
|
83
123
|
exports.poolHistoryMetricSchema = poolHistoryMetricSchema;
|
|
124
|
+
exports.poolPositionHistoryMetricSchema = poolPositionHistoryMetricSchema;
|
|
125
|
+
exports.positionHistoryMetricSchema = positionHistoryMetricSchema;
|
|
126
|
+
exports.positionHistoryQuerySchema = positionHistoryQuerySchema;
|
|
84
127
|
exports.strategyHistoryMetricSchema = strategyHistoryMetricSchema;
|
|
128
|
+
exports.strategyPositionHistoryMetricSchema = strategyPositionHistoryMetricSchema;
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -2,15 +2,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_model_history = require("./history.js");
|
|
3
3
|
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
4
4
|
const require_model_opportunities_schema = require("./opportunities.schema.js");
|
|
5
|
+
const require_model_liquidations_schema = require("./liquidations.schema.js");
|
|
6
|
+
const require_model_positions_schema = require("./positions.schema.js");
|
|
5
7
|
const require_model_history_schema = require("./history.schema.js");
|
|
6
8
|
const require_model_liquidations = require("./liquidations.js");
|
|
7
|
-
const require_model_liquidations_schema = require("./liquidations.schema.js");
|
|
8
9
|
const require_model_opportunities = require("./opportunities.js");
|
|
9
|
-
require("./positions.js");
|
|
10
|
-
const require_model_positions_schema = require("./positions.schema.js");
|
|
10
|
+
const require_model_positions = require("./positions.js");
|
|
11
11
|
require("./primitives.js");
|
|
12
12
|
exports.POOL_HISTORY_METRICS = require_model_history.POOL_HISTORY_METRICS;
|
|
13
|
+
exports.POOL_POSITION_HISTORY_METRICS = require_model_history.POOL_POSITION_HISTORY_METRICS;
|
|
13
14
|
exports.STRATEGY_HISTORY_METRICS = require_model_history.STRATEGY_HISTORY_METRICS;
|
|
15
|
+
exports.STRATEGY_POSITION_HISTORY_METRICS = require_model_history.STRATEGY_POSITION_HISTORY_METRICS;
|
|
14
16
|
exports.amountSchema = require_model_primitives_schema.amountSchema;
|
|
15
17
|
exports.apyBreakdownSchema = require_model_opportunities_schema.apyBreakdownSchema;
|
|
16
18
|
exports.assetTypeSchema = require_model_primitives_schema.assetTypeSchema;
|
|
@@ -29,9 +31,11 @@ exports.liquidatableAccountFilterSchema = require_model_liquidations_schema.liqu
|
|
|
29
31
|
exports.liquidatableAccountSchema = require_model_liquidations_schema.liquidatableAccountSchema;
|
|
30
32
|
exports.liquidationApprovalSchema = require_model_liquidations_schema.liquidationApprovalSchema;
|
|
31
33
|
exports.liquidationDetailsSchema = require_model_liquidations_schema.liquidationDetailsSchema;
|
|
34
|
+
exports.liquidationPositionId = require_model_positions.liquidationPositionId;
|
|
32
35
|
exports.liquidationPositionSchema = require_model_liquidations_schema.liquidationPositionSchema;
|
|
33
36
|
exports.matchesLiquidatableAccountFilter = require_model_liquidations.matchesLiquidatableAccountFilter;
|
|
34
37
|
exports.matchesOpportunityFilter = require_model_opportunities.matchesOpportunityFilter;
|
|
38
|
+
exports.matchesPositionFilter = require_model_positions.matchesPositionFilter;
|
|
35
39
|
exports.opportunityBaseSchema = require_model_opportunities_schema.opportunityBaseSchema;
|
|
36
40
|
exports.opportunityDetailSchema = require_model_opportunities_schema.opportunityDetailSchema;
|
|
37
41
|
exports.opportunityFilterSchema = require_model_opportunities_schema.opportunityFilterSchema;
|
|
@@ -50,9 +54,16 @@ exports.poolOpportunityDetailSchema = require_model_opportunities_schema.poolOpp
|
|
|
50
54
|
exports.poolOpportunityId = require_model_opportunities.poolOpportunityId;
|
|
51
55
|
exports.poolOpportunityKeySchema = require_model_opportunities_schema.poolOpportunityKeySchema;
|
|
52
56
|
exports.poolOpportunitySchema = require_model_opportunities_schema.poolOpportunitySchema;
|
|
57
|
+
exports.poolPositionHistoryMetricSchema = require_model_history_schema.poolPositionHistoryMetricSchema;
|
|
58
|
+
exports.poolPositionId = require_model_positions.poolPositionId;
|
|
59
|
+
exports.poolPositionKeySchema = require_model_positions_schema.poolPositionKeySchema;
|
|
53
60
|
exports.poolPositionSchema = require_model_positions_schema.poolPositionSchema;
|
|
54
61
|
exports.positionCollateralSchema = require_model_positions_schema.positionCollateralSchema;
|
|
55
62
|
exports.positionFilterSchema = require_model_positions_schema.positionFilterSchema;
|
|
63
|
+
exports.positionHistoryMetricSchema = require_model_history_schema.positionHistoryMetricSchema;
|
|
64
|
+
exports.positionHistoryQuerySchema = require_model_history_schema.positionHistoryQuerySchema;
|
|
65
|
+
exports.positionId = require_model_positions.positionId;
|
|
66
|
+
exports.positionKeySchema = require_model_positions_schema.positionKeySchema;
|
|
56
67
|
exports.positionKindSchema = require_model_positions_schema.positionKindSchema;
|
|
57
68
|
exports.positionSchema = require_model_positions_schema.positionSchema;
|
|
58
69
|
exports.priceFeedDataSchema = require_model_opportunities_schema.priceFeedDataSchema;
|
|
@@ -68,6 +79,9 @@ exports.strategyOpportunityDetailSchema = require_model_opportunities_schema.str
|
|
|
68
79
|
exports.strategyOpportunityId = require_model_opportunities.strategyOpportunityId;
|
|
69
80
|
exports.strategyOpportunityKeySchema = require_model_opportunities_schema.strategyOpportunityKeySchema;
|
|
70
81
|
exports.strategyOpportunitySchema = require_model_opportunities_schema.strategyOpportunitySchema;
|
|
82
|
+
exports.strategyPositionHistoryMetricSchema = require_model_history_schema.strategyPositionHistoryMetricSchema;
|
|
83
|
+
exports.strategyPositionId = require_model_positions.strategyPositionId;
|
|
84
|
+
exports.strategyPositionKeySchema = require_model_positions_schema.strategyPositionKeySchema;
|
|
71
85
|
exports.strategyPositionSchema = require_model_positions_schema.strategyPositionSchema;
|
|
72
86
|
exports.timestampSchema = require_model_primitives_schema.timestampSchema;
|
|
73
87
|
exports.tokenAmountSchema = require_model_primitives_schema.tokenAmountSchema;
|
|
@@ -1 +1,90 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model/positions.ts
|
|
3
|
+
/**
|
|
4
|
+
* Builds the canonical id of a pool position.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* poolPositionId(1, "0xda00...") // "1:pool:0xda00..."
|
|
9
|
+
* ```
|
|
10
|
+
**/
|
|
11
|
+
function poolPositionId(chainId, pool) {
|
|
12
|
+
return `${chainId}:pool:${pool.toLowerCase()}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the canonical id of a strategy position. The credit account address
|
|
16
|
+
* identifies it on its own, the credit manager is not part of the id.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* strategyPositionId(1, "0x9c4c...") // "1:strategy:0x9c4c..."
|
|
21
|
+
* ```
|
|
22
|
+
**/
|
|
23
|
+
function strategyPositionId(chainId, creditAccount) {
|
|
24
|
+
return `${chainId}:strategy:${creditAccount.toLowerCase()}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds the canonical id of a liquidation position.
|
|
28
|
+
*
|
|
29
|
+
* The redeemer is the withdrawal's own contract and therefore identifies it,
|
|
30
|
+
* but compressor versions below 313 do not report one; those fall back to the
|
|
31
|
+
* source token plus the moment the withdrawal becomes claimable, which is what
|
|
32
|
+
* distinguishes two withdrawals of the same asset.
|
|
33
|
+
**/
|
|
34
|
+
function liquidationPositionId(chainId, position) {
|
|
35
|
+
const { redeemer, sourceToken, claimableAt } = position;
|
|
36
|
+
return `${chainId}:liquidation:${redeemer ? redeemer.toLowerCase() : `${sourceToken.address.toLowerCase()}:${claimableAt ?? "claimable"}`}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Canonical id of any position, dispatching on {@link Position.kind}.
|
|
40
|
+
**/
|
|
41
|
+
function positionId(position) {
|
|
42
|
+
switch (position.kind) {
|
|
43
|
+
case "pool": return poolPositionId(position.chainId, position.pool);
|
|
44
|
+
case "strategy": return strategyPositionId(position.chainId, position.creditAccount);
|
|
45
|
+
case "liquidation": return liquidationPositionId(position.chainId, position);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether a position satisfies every criterion of a filter.
|
|
50
|
+
*
|
|
51
|
+
* This is the single definition of what each criterion means: every source
|
|
52
|
+
* builds its rows first and runs them through here, so the chain and the
|
|
53
|
+
* backend cannot disagree on what a filter selects.
|
|
54
|
+
*
|
|
55
|
+
* A criterion that does not apply to a position's kind keeps the row rather
|
|
56
|
+
* than dropping it: `isZeroDebt` says nothing about a pool position, and
|
|
57
|
+
* `underlyingType` says nothing about a liquidation position, which is
|
|
58
|
+
* denominated in whatever its withdrawal pays out.
|
|
59
|
+
*
|
|
60
|
+
* @param position - Row to test.
|
|
61
|
+
* @param filter - Criteria to test against. An absent filter matches anything.
|
|
62
|
+
**/
|
|
63
|
+
function matchesPositionFilter(position, filter) {
|
|
64
|
+
if (!filter) return true;
|
|
65
|
+
if (filter.kind && position.kind !== filter.kind) return false;
|
|
66
|
+
if (filter.chainIds && !filter.chainIds.includes(position.chainId)) return false;
|
|
67
|
+
if (filter.isZeroDebt !== void 0 && position.kind === "strategy" && position.totalDebt.value === 0n !== filter.isZeroDebt) return false;
|
|
68
|
+
if (filter.underlyingType) {
|
|
69
|
+
const underlying = positionUnderlying(position);
|
|
70
|
+
if (underlying && underlying.assetType !== filter.underlyingType) return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Token a position's headline amount is denominated in, or `undefined` for a
|
|
76
|
+
* kind that has no single underlying.
|
|
77
|
+
**/
|
|
78
|
+
function positionUnderlying(position) {
|
|
79
|
+
switch (position.kind) {
|
|
80
|
+
case "pool": return position.netValue.token;
|
|
81
|
+
case "strategy": return position.totalValue.token;
|
|
82
|
+
case "liquidation": return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
exports.liquidationPositionId = liquidationPositionId;
|
|
87
|
+
exports.matchesPositionFilter = matchesPositionFilter;
|
|
88
|
+
exports.poolPositionId = poolPositionId;
|
|
89
|
+
exports.positionId = positionId;
|
|
90
|
+
exports.strategyPositionId = strategyPositionId;
|
|
@@ -106,15 +106,43 @@ const positionFilterSchema = zod_v4.z.object({
|
|
|
106
106
|
chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
|
|
107
107
|
underlyingType: require_model_primitives_schema.assetTypeSchema.optional()
|
|
108
108
|
});
|
|
109
|
+
/**
|
|
110
|
+
* {@link PoolPositionKey}
|
|
111
|
+
**/
|
|
112
|
+
const poolPositionKeySchema = zod_v4.z.object({
|
|
113
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
114
|
+
pool: require_sdk_utils_zod.ZodAddress(),
|
|
115
|
+
wallet: require_sdk_utils_zod.ZodAddress()
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* {@link StrategyPositionKey}
|
|
119
|
+
**/
|
|
120
|
+
const strategyPositionKeySchema = zod_v4.z.object({
|
|
121
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
122
|
+
creditAccount: require_sdk_utils_zod.ZodAddress()
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* {@link PositionKey}
|
|
126
|
+
**/
|
|
127
|
+
const positionKeySchema = zod_v4.z.discriminatedUnion("kind", [zod_v4.z.object({
|
|
128
|
+
kind: zod_v4.z.literal("pool"),
|
|
129
|
+
...poolPositionKeySchema.shape
|
|
130
|
+
}), zod_v4.z.object({
|
|
131
|
+
kind: zod_v4.z.literal("strategy"),
|
|
132
|
+
...strategyPositionKeySchema.shape
|
|
133
|
+
})]);
|
|
109
134
|
//#endregion
|
|
110
135
|
exports.pnlBreakdownSchema = pnlBreakdownSchema;
|
|
111
136
|
exports.pointsProgramPnLSchema = pointsProgramPnLSchema;
|
|
112
137
|
exports.pointsRewardsPnLSchema = pointsRewardsPnLSchema;
|
|
138
|
+
exports.poolPositionKeySchema = poolPositionKeySchema;
|
|
113
139
|
exports.poolPositionSchema = poolPositionSchema;
|
|
114
140
|
exports.positionCollateralSchema = positionCollateralSchema;
|
|
115
141
|
exports.positionFilterSchema = positionFilterSchema;
|
|
142
|
+
exports.positionKeySchema = positionKeySchema;
|
|
116
143
|
exports.positionKindSchema = positionKindSchema;
|
|
117
144
|
exports.positionSchema = positionSchema;
|
|
118
145
|
exports.rewardsPnLSchema = rewardsPnLSchema;
|
|
146
|
+
exports.strategyPositionKeySchema = strategyPositionKeySchema;
|
|
119
147
|
exports.strategyPositionSchema = strategyPositionSchema;
|
|
120
148
|
exports.tokenRewardsPnLSchema = tokenRewardsPnLSchema;
|
|
@@ -5,6 +5,8 @@ const require_offchain_GearboxAPI = require("../offchain/GearboxAPI.js");
|
|
|
5
5
|
require("../offchain/index.js");
|
|
6
6
|
const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
|
|
7
7
|
require("./opportunities/index.js");
|
|
8
|
+
const require_new_sdk_positions_PositionsNamespace = require("./positions/PositionsNamespace.js");
|
|
9
|
+
require("./positions/index.js");
|
|
8
10
|
//#region src/new-sdk/GearboxSDK.ts
|
|
9
11
|
/**
|
|
10
12
|
* Combined entry point over both sources of Gearbox data: the chain and the
|
|
@@ -46,6 +48,10 @@ var GearboxSDK = class {
|
|
|
46
48
|
* Namespace for pool and strategy opportunities.
|
|
47
49
|
**/
|
|
48
50
|
opportunities;
|
|
51
|
+
/**
|
|
52
|
+
* Namespace for the positions a wallet holds.
|
|
53
|
+
**/
|
|
54
|
+
positions;
|
|
49
55
|
#attachOptions;
|
|
50
56
|
#onchain;
|
|
51
57
|
#offchain;
|
|
@@ -79,6 +85,7 @@ var GearboxSDK = class {
|
|
|
79
85
|
});
|
|
80
86
|
this.#attached = !this.#ownsOnchain;
|
|
81
87
|
this.opportunities = new require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace(this.#onchain, this.#offchain, logger);
|
|
88
|
+
this.positions = new require_new_sdk_positions_PositionsNamespace.PositionsNamespace(this.#onchain, this.#offchain, logger);
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
84
91
|
* Attaches the on-chain SDK when this instance owns one.
|
|
@@ -3,9 +3,12 @@ const require_new_sdk_types = require("./types.js");
|
|
|
3
3
|
const require_new_sdk_AbstractNamespace = require("./AbstractNamespace.js");
|
|
4
4
|
const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
|
|
5
5
|
require("./opportunities/index.js");
|
|
6
|
+
const require_new_sdk_positions_PositionsNamespace = require("./positions/PositionsNamespace.js");
|
|
7
|
+
require("./positions/index.js");
|
|
6
8
|
const require_new_sdk_GearboxSDK = require("./GearboxSDK.js");
|
|
7
9
|
require("./utils/index.js");
|
|
8
10
|
exports.AbstractNamespace = require_new_sdk_AbstractNamespace.AbstractNamespace;
|
|
9
11
|
exports.AllSourcesFailedError = require_new_sdk_types.AllSourcesFailedError;
|
|
10
12
|
exports.GearboxSDK = require_new_sdk_GearboxSDK.GearboxSDK;
|
|
11
13
|
exports.OpportunitiesNamespace = require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace;
|
|
14
|
+
exports.PositionsNamespace = require_new_sdk_positions_PositionsNamespace.PositionsNamespace;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_positions = require("../../model/positions.js");
|
|
3
|
+
require("../../model/index.js");
|
|
4
|
+
const require_new_sdk_AbstractNamespace = require("../AbstractNamespace.js");
|
|
5
|
+
//#region src/new-sdk/positions/PositionsNamespace.ts
|
|
6
|
+
/**
|
|
7
|
+
* Fields the backend owns even when the chain also fills them.
|
|
8
|
+
*
|
|
9
|
+
* The yield and PnL groups are derived from a position's history and from
|
|
10
|
+
* incentive programs, neither of which the chain has. `targetCollateral` is
|
|
11
|
+
* there for a subtler reason: the read model defines it as the collateral the
|
|
12
|
+
* position was opened into, which only the backend can know, while the chain
|
|
13
|
+
* approximates it with the dominant collateral held right now.
|
|
14
|
+
**/
|
|
15
|
+
const OFFCHAIN_OWNED_FIELDS = /* @__PURE__ */ new Set([
|
|
16
|
+
"apy",
|
|
17
|
+
"netApy",
|
|
18
|
+
"pnl",
|
|
19
|
+
"targetCollateral"
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
22
|
+
* The `positions` namespace of the combined SDK.
|
|
23
|
+
*
|
|
24
|
+
* A stateless router over the two sources, see {@link AbstractNamespace} for the
|
|
25
|
+
* routing itself. What is specific to positions is the reads below and the merge
|
|
26
|
+
* policy at the bottom of the class.
|
|
27
|
+
*
|
|
28
|
+
* The class implements the methods of every mode; {@link GearboxSDK} exposes it
|
|
29
|
+
* as its mode's slice of {@link PositionsByMode}, so calling a method the mode
|
|
30
|
+
* does not have is a compile error rather than a runtime one.
|
|
31
|
+
**/
|
|
32
|
+
var PositionsNamespace = class extends require_new_sdk_AbstractNamespace.AbstractNamespace {
|
|
33
|
+
constructor(onchain, offchain, logger) {
|
|
34
|
+
super("Positions", onchain, offchain, logger);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc PositionsBase.list}
|
|
38
|
+
**/
|
|
39
|
+
async list(wallet, filter) {
|
|
40
|
+
return this.readList("list positions", async (sdk) => {
|
|
41
|
+
const { result, meta } = await sdk.positions.list({
|
|
42
|
+
wallet,
|
|
43
|
+
filter
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
value: result,
|
|
47
|
+
chains: meta
|
|
48
|
+
};
|
|
49
|
+
}, (api) => api.positions.list(wallet, filter));
|
|
50
|
+
}
|
|
51
|
+
history(key) {
|
|
52
|
+
return { chart: (metric, range) => this.#chart(key, metric, range) };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads one chart of one position from the backend.
|
|
56
|
+
*
|
|
57
|
+
* The metric a caller may name is gated by the reader's type, so the kind of
|
|
58
|
+
* the key is not re-checked here.
|
|
59
|
+
**/
|
|
60
|
+
async #chart(key, metric, range) {
|
|
61
|
+
const { result, meta } = await this.readOffchain(`get ${metric} history`, (api) => api.positions.getHistory({
|
|
62
|
+
position: key,
|
|
63
|
+
range,
|
|
64
|
+
metric
|
|
65
|
+
}), {
|
|
66
|
+
metric,
|
|
67
|
+
points: [],
|
|
68
|
+
metadata: {}
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
data: result.points,
|
|
72
|
+
metadata: {
|
|
73
|
+
...result.metadata,
|
|
74
|
+
source: meta
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Merges the two versions of one position.
|
|
80
|
+
*
|
|
81
|
+
* The chain wins every field it fills; the backend fills the rest and owns
|
|
82
|
+
* {@link OFFCHAIN_OWNED_FIELDS}.
|
|
83
|
+
*
|
|
84
|
+
* The rule is onchain-first, field-wise, and never deeper than one level: a
|
|
85
|
+
* group like `totalValue` or `apy` is taken whole from one source, so a row
|
|
86
|
+
* never mixes an on-chain token amount with a backend dollar value derived
|
|
87
|
+
* from a different block.
|
|
88
|
+
**/
|
|
89
|
+
mergeOne(onchain, offchain) {
|
|
90
|
+
const merged = { ...onchain };
|
|
91
|
+
for (const [field, value] of Object.entries(offchain)) {
|
|
92
|
+
if (value === void 0) continue;
|
|
93
|
+
if (OFFCHAIN_OWNED_FIELDS.has(field) || merged[field] === void 0) merged[field] = value;
|
|
94
|
+
}
|
|
95
|
+
return merged;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Unions the two lists by canonical position id.
|
|
99
|
+
*
|
|
100
|
+
* Rows present in both are merged by {@link PositionsNamespace.mergeOne}.
|
|
101
|
+
* Rows only the backend knows are appended: a chain the SDK does not cover,
|
|
102
|
+
* or a market it has not loaded, must not hide a position the wallet actually
|
|
103
|
+
* holds.
|
|
104
|
+
**/
|
|
105
|
+
mergeList(onchain, offchain) {
|
|
106
|
+
const byId = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const row of onchain) byId.set(require_model_positions.positionId(row), row);
|
|
108
|
+
const extra = [];
|
|
109
|
+
for (const row of offchain) {
|
|
110
|
+
const id = require_model_positions.positionId(row);
|
|
111
|
+
const existing = byId.get(id);
|
|
112
|
+
if (existing) byId.set(id, this.mergeOne(existing, row));
|
|
113
|
+
else extra.push(row);
|
|
114
|
+
}
|
|
115
|
+
return [...byId.values(), ...extra];
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
exports.PositionsNamespace = PositionsNamespace;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_new_sdk_positions_PositionsNamespace = require("./PositionsNamespace.js");
|
|
3
|
+
require("./types.js");
|
|
4
|
+
exports.PositionsNamespace = require_new_sdk_positions_PositionsNamespace.PositionsNamespace;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
|
|
3
3
|
require("./opportunities/index.js");
|
|
4
|
+
const require_offchain_positions_OffchainPositions = require("./positions/OffchainPositions.js");
|
|
5
|
+
require("./positions/index.js");
|
|
4
6
|
//#region src/offchain/GearboxAPI.ts
|
|
5
7
|
/**
|
|
6
8
|
* Client for the Gearbox backend, the off-chain source of the read model.
|
|
@@ -17,16 +19,21 @@ require("./opportunities/index.js");
|
|
|
17
19
|
* return those types directly, so there is no wire DTO layer here — only
|
|
18
20
|
* transport and schema validation.
|
|
19
21
|
*
|
|
20
|
-
* The transport is not implemented yet; see {@link OffchainOpportunities}
|
|
21
|
-
* what each stubbed endpoint currently answers.
|
|
22
|
+
* The transport is not implemented yet; see {@link OffchainOpportunities} and
|
|
23
|
+
* {@link OffchainPositions} for what each stubbed endpoint currently answers.
|
|
22
24
|
**/
|
|
23
25
|
var GearboxAPI = class {
|
|
24
26
|
/**
|
|
25
27
|
* Namespace for pool and strategy opportunities.
|
|
26
28
|
**/
|
|
27
29
|
opportunities;
|
|
30
|
+
/**
|
|
31
|
+
* Namespace for the positions a wallet holds.
|
|
32
|
+
**/
|
|
33
|
+
positions;
|
|
28
34
|
constructor(options) {
|
|
29
35
|
this.opportunities = new require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities(options);
|
|
36
|
+
this.positions = new require_offchain_positions_OffchainPositions.OffchainPositions(options);
|
|
30
37
|
}
|
|
31
38
|
};
|
|
32
39
|
//#endregion
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_types = require("./types.js");
|
|
2
3
|
const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
|
|
3
4
|
require("./opportunities/index.js");
|
|
5
|
+
const require_offchain_positions_OffchainPositions = require("./positions/OffchainPositions.js");
|
|
6
|
+
require("./positions/index.js");
|
|
4
7
|
const require_offchain_GearboxAPI = require("./GearboxAPI.js");
|
|
5
|
-
require("./types.js");
|
|
6
8
|
exports.GearboxAPI = require_offchain_GearboxAPI.GearboxAPI;
|
|
7
|
-
exports.OffchainNotImplementedError =
|
|
9
|
+
exports.OffchainNotImplementedError = require_offchain_types.OffchainNotImplementedError;
|
|
8
10
|
exports.OffchainOpportunities = require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities;
|
|
11
|
+
exports.OffchainPositions = require_offchain_positions_OffchainPositions.OffchainPositions;
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_offchain_types = require("../types.js");
|
|
2
3
|
//#region src/offchain/opportunities/OffchainOpportunities.ts
|
|
3
4
|
/**
|
|
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 opportunity.
|
|
7
|
-
**/
|
|
8
|
-
var OffchainNotImplementedError = class extends Error {
|
|
9
|
-
constructor(endpoint) {
|
|
10
|
-
super(`GearboxAPI: ${endpoint} is not implemented yet`);
|
|
11
|
-
this.name = "OffchainNotImplementedError";
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
5
|
* Backend counterpart of the `opportunities` namespace.
|
|
16
6
|
*
|
|
17
7
|
* This is a stub: the HTTP client is not written yet, so list reads answer with
|
|
@@ -58,7 +48,7 @@ var OffchainOpportunities = class {
|
|
|
58
48
|
* implemented.
|
|
59
49
|
**/
|
|
60
50
|
async getPool(key) {
|
|
61
|
-
throw new OffchainNotImplementedError("opportunities.getPool");
|
|
51
|
+
throw new require_offchain_types.OffchainNotImplementedError("opportunities.getPool");
|
|
62
52
|
}
|
|
63
53
|
/**
|
|
64
54
|
* Detailed view of one strategy opportunity.
|
|
@@ -67,7 +57,7 @@ var OffchainOpportunities = class {
|
|
|
67
57
|
* implemented.
|
|
68
58
|
**/
|
|
69
59
|
async getStrategy(key) {
|
|
70
|
-
throw new OffchainNotImplementedError("opportunities.getStrategy");
|
|
60
|
+
throw new require_offchain_types.OffchainNotImplementedError("opportunities.getStrategy");
|
|
71
61
|
}
|
|
72
62
|
/**
|
|
73
63
|
* One historical series of one opportunity. History exists only here:
|
|
@@ -93,5 +83,4 @@ var OffchainOpportunities = class {
|
|
|
93
83
|
}
|
|
94
84
|
};
|
|
95
85
|
//#endregion
|
|
96
|
-
exports.OffchainNotImplementedError = OffchainNotImplementedError;
|
|
97
86
|
exports.OffchainOpportunities = OffchainOpportunities;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_offchain_opportunities_OffchainOpportunities = require("./OffchainOpportunities.js");
|
|
3
|
-
exports.OffchainNotImplementedError = require_offchain_opportunities_OffchainOpportunities.OffchainNotImplementedError;
|
|
4
3
|
exports.OffchainOpportunities = require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/offchain/positions/OffchainPositions.ts
|
|
3
|
+
/**
|
|
4
|
+
* Backend counterpart of the `positions` namespace.
|
|
5
|
+
*
|
|
6
|
+
* This is a stub: the HTTP client is not written yet, so reads answer with an
|
|
7
|
+
* empty payload. Every signature is already the final one, because the backend
|
|
8
|
+
* returns the read model types directly — there is no wire DTO and no mapper
|
|
9
|
+
* between the two.
|
|
10
|
+
*
|
|
11
|
+
* When the transport lands, each method will validate the response against the
|
|
12
|
+
* matching schema from `src/model` before returning it. A validation failure is
|
|
13
|
+
* a version-skew error and is handled exactly like a transport error: the
|
|
14
|
+
* combined SDK drops the backend's contribution in `both` mode and rethrows in
|
|
15
|
+
* `offchain` mode.
|
|
16
|
+
**/
|
|
17
|
+
var OffchainPositions = class {
|
|
18
|
+
#baseUrl;
|
|
19
|
+
#logger;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.#baseUrl = options?.baseUrl;
|
|
22
|
+
this.#logger = options?.logger?.child?.({ name: "OffchainPositions" });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Base URL the client will call once the transport is implemented.
|
|
26
|
+
**/
|
|
27
|
+
get baseUrl() {
|
|
28
|
+
return this.#baseUrl;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Everything a wallet holds, optionally narrowed by {@link PositionFilter}.
|
|
32
|
+
*
|
|
33
|
+
* @returns An empty list until the backend client is implemented.
|
|
34
|
+
**/
|
|
35
|
+
async list(wallet, filter) {
|
|
36
|
+
this.#logger?.debug({
|
|
37
|
+
wallet,
|
|
38
|
+
filter
|
|
39
|
+
}, "offchain positions list is not implemented, serving empty list");
|
|
40
|
+
return {
|
|
41
|
+
result: [],
|
|
42
|
+
meta: { status: "success" }
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One historical series of one position. History exists only here: rebuilding
|
|
47
|
+
* it from the chain would mean an archive read per point.
|
|
48
|
+
*
|
|
49
|
+
* The requested metric types the response, so a caller asking for one metric
|
|
50
|
+
* does not have to narrow the union back down. When the transport lands,
|
|
51
|
+
* validation is what upholds it: a response carrying a different metric than
|
|
52
|
+
* the one asked for is a version-skew error like any other.
|
|
53
|
+
*
|
|
54
|
+
* @returns An empty series until the backend client is implemented.
|
|
55
|
+
**/
|
|
56
|
+
async getHistory(query) {
|
|
57
|
+
this.#logger?.debug({ query }, "offchain positions history is not implemented, serving empty series");
|
|
58
|
+
return {
|
|
59
|
+
result: {
|
|
60
|
+
metric: query.metric,
|
|
61
|
+
points: [],
|
|
62
|
+
metadata: {}
|
|
63
|
+
},
|
|
64
|
+
meta: { status: "success" }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.OffchainPositions = OffchainPositions;
|
|
@@ -1 +1,18 @@
|
|
|
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
|
+
//#endregion
|
|
18
|
+
exports.OffchainNotImplementedError = OffchainNotImplementedError;
|