@gearbox-protocol/sdk 14.12.0-next.66 → 14.12.0-next.67
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/common-utils/index.js +2 -2
- package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.js +3 -3
- package/dist/cjs/common-utils/utils/assets-math.js +7 -7
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +2 -2
- package/dist/cjs/common-utils/utils/creditAccount/debt.js +2 -2
- package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +5 -5
- package/dist/cjs/common-utils/utils/index.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +5 -5
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +2 -2
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +4 -4
- package/dist/cjs/model/history.js +28 -0
- package/dist/cjs/model/history.schema.js +84 -0
- package/dist/cjs/model/index.js +64 -0
- package/dist/cjs/model/liquidations.js +23 -0
- package/dist/cjs/model/liquidations.schema.js +91 -0
- package/dist/cjs/model/opportunities.js +55 -0
- package/dist/cjs/model/opportunities.schema.js +220 -0
- package/dist/cjs/model/package.json +1 -0
- package/dist/cjs/model/positions.js +1 -0
- package/dist/cjs/model/primitives.js +1 -0
- package/dist/cjs/model/primitives.schema.js +85 -0
- package/dist/cjs/new-sdk/AbstractNamespace.js +158 -0
- package/dist/cjs/new-sdk/GearboxSDK.js +122 -0
- package/dist/cjs/new-sdk/index.js +11 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +122 -0
- package/dist/cjs/new-sdk/opportunities/index.js +4 -0
- package/dist/cjs/new-sdk/opportunities/types.js +1 -0
- package/dist/cjs/new-sdk/package.json +1 -0
- package/dist/cjs/new-sdk/types.js +22 -0
- package/dist/cjs/new-sdk/utils/history.js +1 -0
- package/dist/cjs/new-sdk/utils/index.js +2 -0
- package/dist/cjs/offchain/GearboxAPI.js +33 -0
- package/dist/cjs/offchain/index.js +8 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +97 -0
- package/dist/cjs/offchain/opportunities/index.js +4 -0
- package/dist/cjs/offchain/package.json +1 -0
- package/dist/cjs/offchain/types.js +1 -0
- package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -5
- package/dist/cjs/rewards/rewards/api.js +2 -2
- package/dist/cjs/rewards/rewards/extra-apy.js +2 -2
- package/dist/cjs/sdk/MultichainSDK.js +18 -2
- package/dist/cjs/sdk/OnchainSDK.js +8 -1
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +150 -106
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
- package/dist/cjs/sdk/accounts/liquidations/constants.js +13 -0
- package/dist/cjs/sdk/accounts/liquidations/index.js +2 -0
- package/dist/cjs/sdk/base/MultichainConstruct.js +80 -0
- package/dist/cjs/sdk/base/TokensMeta.js +51 -0
- package/dist/cjs/sdk/base/index.js +2 -0
- package/dist/cjs/sdk/chain/chains.js +76 -0
- package/dist/cjs/sdk/chain/index.js +4 -0
- package/dist/cjs/sdk/core/errors.js +13 -0
- package/dist/cjs/sdk/core/index.js +2 -1
- package/dist/cjs/sdk/index.js +25 -1
- package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/cjs/sdk/market/MarketSuite.js +163 -0
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/cjs/sdk/market/credit/CreditSuite.js +102 -0
- package/dist/cjs/sdk/market/math.js +104 -0
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
- package/dist/cjs/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
- package/dist/cjs/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
- package/dist/cjs/sdk/market/pool/PoolSuite.js +28 -0
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +27 -0
- package/dist/cjs/sdk/market/pool/math.js +44 -0
- package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
- package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +60 -0
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +103 -0
- package/dist/cjs/sdk/opportunities/index.js +12 -0
- package/dist/cjs/sdk/types/multichain.js +1 -0
- package/dist/cjs/{common-utils → sdk}/utils/bigint-math.js +11 -11
- package/dist/cjs/sdk/utils/index.js +3 -0
- package/dist/cjs/sdk/utils/zod.js +12 -0
- package/dist/esm/common-utils/index.js +1 -1
- package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +1 -1
- package/dist/esm/common-utils/utils/assets-math.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/debt.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +1 -1
- package/dist/esm/common-utils/utils/index.js +1 -1
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +1 -1
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +1 -1
- package/dist/esm/model/history.js +26 -0
- package/dist/esm/model/history.schema.js +76 -0
- package/dist/esm/model/index.js +9 -0
- package/dist/esm/model/liquidations.js +22 -0
- package/dist/esm/model/liquidations.schema.js +83 -0
- package/dist/esm/model/opportunities.js +51 -0
- package/dist/esm/model/opportunities.schema.js +198 -0
- package/dist/esm/model/package.json +1 -0
- package/dist/esm/model/positions.js +1 -0
- package/dist/esm/model/primitives.js +1 -0
- package/dist/esm/model/primitives.schema.js +75 -0
- package/dist/esm/new-sdk/AbstractNamespace.js +157 -0
- package/dist/esm/new-sdk/GearboxSDK.js +121 -0
- package/dist/esm/new-sdk/index.js +7 -0
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +121 -0
- package/dist/esm/new-sdk/opportunities/index.js +3 -0
- package/dist/esm/new-sdk/opportunities/types.js +1 -0
- package/dist/esm/new-sdk/package.json +1 -0
- package/dist/esm/new-sdk/types.js +21 -0
- package/dist/esm/new-sdk/utils/history.js +1 -0
- package/dist/esm/new-sdk/utils/index.js +2 -0
- package/dist/esm/offchain/GearboxAPI.js +32 -0
- package/dist/esm/offchain/index.js +5 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +95 -0
- package/dist/esm/offchain/opportunities/index.js +2 -0
- package/dist/esm/offchain/package.json +1 -0
- package/dist/esm/offchain/types.js +1 -0
- package/dist/esm/preview/preview/buildDelayedPreview.js +1 -1
- package/dist/esm/rewards/rewards/api.js +1 -1
- package/dist/esm/rewards/rewards/extra-apy.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +18 -2
- package/dist/esm/sdk/OnchainSDK.js +8 -1
- package/dist/esm/sdk/accounts/index.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +152 -108
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
- package/dist/esm/sdk/accounts/liquidations/constants.js +12 -1
- package/dist/esm/sdk/accounts/liquidations/index.js +2 -2
- package/dist/esm/sdk/base/MultichainConstruct.js +79 -0
- package/dist/esm/sdk/base/TokensMeta.js +51 -0
- package/dist/esm/sdk/base/index.js +2 -1
- package/dist/esm/sdk/chain/chains.js +74 -2
- package/dist/esm/sdk/chain/index.js +2 -2
- package/dist/esm/sdk/core/errors.js +13 -1
- package/dist/esm/sdk/core/index.js +2 -2
- package/dist/esm/sdk/index.js +11 -5
- package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/esm/sdk/market/MarketSuite.js +163 -0
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/esm/sdk/market/credit/CreditSuite.js +102 -0
- package/dist/esm/sdk/market/math.js +98 -0
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
- package/dist/esm/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
- package/dist/esm/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
- package/dist/esm/sdk/market/pool/PoolSuite.js +28 -0
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +27 -0
- package/dist/esm/sdk/market/pool/math.js +41 -0
- package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
- package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +59 -0
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +102 -0
- package/dist/esm/sdk/opportunities/index.js +4 -0
- package/dist/esm/sdk/types/multichain.js +1 -0
- package/dist/esm/{common-utils → sdk}/utils/bigint-math.js +11 -11
- package/dist/esm/sdk/utils/index.js +3 -2
- package/dist/esm/sdk/utils/zod.js +13 -2
- package/dist/types/common-utils/index.d.ts +1 -1
- package/dist/types/common-utils/utils/index.d.ts +1 -1
- package/dist/types/model/history.d.ts +105 -0
- package/dist/types/model/history.schema.d.ts +66 -0
- package/dist/types/model/index.d.ts +9 -0
- package/dist/types/model/liquidations.d.ts +230 -0
- package/dist/types/model/liquidations.schema.d.ts +292 -0
- package/dist/types/model/opportunities.d.ts +543 -0
- package/dist/types/model/opportunities.schema.d.ts +1066 -0
- package/dist/types/model/positions.d.ts +11 -0
- package/dist/types/model/primitives.d.ts +193 -0
- package/dist/types/model/primitives.schema.d.ts +81 -0
- package/dist/types/new-sdk/AbstractNamespace.d.ts +119 -0
- package/dist/types/new-sdk/GearboxSDK.d.ts +78 -0
- package/dist/types/new-sdk/index.d.ts +9 -0
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +69 -0
- package/dist/types/new-sdk/opportunities/index.d.ts +3 -0
- package/dist/types/new-sdk/opportunities/types.d.ts +66 -0
- package/dist/types/new-sdk/types.d.ts +149 -0
- package/dist/types/new-sdk/utils/history.d.ts +44 -0
- package/dist/types/new-sdk/utils/index.d.ts +2 -0
- package/dist/types/offchain/GearboxAPI.d.ts +31 -0
- package/dist/types/offchain/index.d.ts +5 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +69 -0
- package/dist/types/offchain/opportunities/index.d.ts +2 -0
- package/dist/types/offchain/types.d.ts +50 -0
- package/dist/types/sdk/MultichainSDK.d.ts +15 -2
- package/dist/types/sdk/OnchainSDK.d.ts +9 -3
- package/dist/types/sdk/accounts/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +24 -16
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +26 -20
- package/dist/types/sdk/accounts/liquidations/constants.d.ts +12 -1
- package/dist/types/sdk/accounts/liquidations/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/types.d.ts +34 -309
- package/dist/types/sdk/base/MultichainConstruct.d.ts +57 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +26 -0
- package/dist/types/sdk/base/index.d.ts +2 -1
- package/dist/types/sdk/chain/chains.d.ts +68 -1
- package/dist/types/sdk/chain/index.d.ts +2 -2
- package/dist/types/sdk/core/errors.d.ts +10 -1
- package/dist/types/sdk/core/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +15 -8
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
- package/dist/types/sdk/market/MarketSuite.d.ts +109 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +47 -0
- package/dist/types/sdk/market/credit/types.d.ts +22 -0
- package/dist/types/sdk/market/index.d.ts +2 -2
- package/dist/types/sdk/market/math.d.ts +74 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +23 -0
- package/dist/types/sdk/market/oracle/types.d.ts +46 -0
- package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +12 -0
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +22 -1
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +23 -0
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +18 -0
- package/dist/types/sdk/market/pool/math.d.ts +57 -0
- package/dist/types/sdk/market/pool/types.d.ts +23 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +6 -0
- package/dist/types/sdk/market/pricefeeds/types.d.ts +10 -0
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +40 -0
- package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +47 -0
- package/dist/types/sdk/opportunities/index.d.ts +4 -0
- package/dist/types/sdk/types/index.d.ts +2 -1
- package/dist/types/sdk/types/multichain.d.ts +65 -0
- package/dist/types/sdk/types/state.d.ts +1 -1
- package/dist/types/sdk/types/transactions.d.ts +3 -0
- package/dist/types/{common-utils → sdk}/utils/bigint-math.d.ts +7 -11
- package/dist/types/sdk/utils/index.d.ts +3 -2
- package/dist/types/sdk/utils/zod.d.ts +6 -2
- package/package.json +16 -1
- package/dist/cjs/sdk/accounts/liquidations/helpers.js +0 -201
- package/dist/esm/sdk/accounts/liquidations/helpers.js +0 -192
- package/dist/types/sdk/accounts/liquidations/helpers.d.ts +0 -140
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model/opportunities.ts
|
|
3
|
+
/**
|
|
4
|
+
* Builds the canonical id of a pool opportunity.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* poolOpportunityId(1, "0xda00...") // "1:0xda00..."
|
|
9
|
+
* ```
|
|
10
|
+
**/
|
|
11
|
+
function poolOpportunityId(chainId, pool) {
|
|
12
|
+
return `${chainId}:${pool.toLowerCase()}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the canonical id of a strategy opportunity.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* strategyOpportunityId(1, "0x3eb9...", "0x7f39...") // "1:0x3eb9...:0x7f39..."
|
|
20
|
+
* ```
|
|
21
|
+
**/
|
|
22
|
+
function strategyOpportunityId(chainId, creditManager, targetCollateral) {
|
|
23
|
+
return `${chainId}:${creditManager.toLowerCase()}:${targetCollateral.toLowerCase()}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Canonical id of any opportunity, dispatching on {@link Opportunity.kind}.
|
|
27
|
+
**/
|
|
28
|
+
function opportunityId(opportunity) {
|
|
29
|
+
return opportunity.kind === "pool" ? poolOpportunityId(opportunity.chainId, opportunity.pool) : strategyOpportunityId(opportunity.chainId, opportunity.creditManager, opportunity.targetCollateral.address);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether an opportunity satisfies every criterion of a filter.
|
|
33
|
+
*
|
|
34
|
+
* This is the single definition of what each criterion means: every source
|
|
35
|
+
* builds its rows first and runs them through here, so the chain and the
|
|
36
|
+
* backend cannot disagree on what a filter selects.
|
|
37
|
+
*
|
|
38
|
+
* @param opportunity - Row to test.
|
|
39
|
+
* @param filter - Criteria to test against. An absent filter matches anything.
|
|
40
|
+
**/
|
|
41
|
+
function matchesOpportunityFilter(opportunity, filter) {
|
|
42
|
+
if (!filter) return true;
|
|
43
|
+
if (filter.kind && opportunity.kind !== filter.kind) return false;
|
|
44
|
+
if (filter.chainIds && !filter.chainIds.includes(opportunity.chainId)) return false;
|
|
45
|
+
if (filter.underlyingType && opportunity.underlyingToken.assetType !== filter.underlyingType) return false;
|
|
46
|
+
if (filter.paused !== void 0 && opportunity.paused !== filter.paused) return false;
|
|
47
|
+
if (filter.sunset !== void 0 && opportunity.sunset !== filter.sunset) return false;
|
|
48
|
+
if (filter.rwa !== void 0 && opportunity.rwa !== filter.rwa) return false;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.matchesOpportunityFilter = matchesOpportunityFilter;
|
|
53
|
+
exports.opportunityId = opportunityId;
|
|
54
|
+
exports.poolOpportunityId = poolOpportunityId;
|
|
55
|
+
exports.strategyOpportunityId = strategyOpportunityId;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_zod = require("../sdk/utils/zod.js");
|
|
3
|
+
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
4
|
+
let zod_v4 = require("zod/v4");
|
|
5
|
+
//#region src/model/opportunities.schema.ts
|
|
6
|
+
/**
|
|
7
|
+
* Runtime schemas for {@link ./opportunities.js}, see the note in
|
|
8
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
9
|
+
**/
|
|
10
|
+
/**
|
|
11
|
+
* {@link OpportunityKind}
|
|
12
|
+
**/
|
|
13
|
+
const opportunityKindSchema = zod_v4.z.union([zod_v4.z.literal("pool"), zod_v4.z.literal("strategy")]);
|
|
14
|
+
/**
|
|
15
|
+
* {@link PointsProgram}
|
|
16
|
+
**/
|
|
17
|
+
const pointsProgramSchema = zod_v4.z.object({
|
|
18
|
+
id: zod_v4.z.string(),
|
|
19
|
+
name: zod_v4.z.string(),
|
|
20
|
+
multiplier: zod_v4.z.number().nullable()
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* {@link TokenRewards}
|
|
24
|
+
**/
|
|
25
|
+
const tokenRewardsSchema = zod_v4.z.object({
|
|
26
|
+
kind: zod_v4.z.literal("token"),
|
|
27
|
+
token: require_model_primitives_schema.tokenSchema,
|
|
28
|
+
supplyApr: require_model_primitives_schema.bpsSchema.optional(),
|
|
29
|
+
borrowApr: require_model_primitives_schema.bpsSchema.optional()
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* {@link PointRewards}
|
|
33
|
+
**/
|
|
34
|
+
const pointRewardsSchema = zod_v4.z.object({
|
|
35
|
+
kind: zod_v4.z.literal("point"),
|
|
36
|
+
points: zod_v4.z.array(pointsProgramSchema)
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* {@link Rewards}
|
|
40
|
+
**/
|
|
41
|
+
const rewardsSchema = zod_v4.z.discriminatedUnion("kind", [tokenRewardsSchema, pointRewardsSchema]);
|
|
42
|
+
/**
|
|
43
|
+
* {@link ApyBreakdown}
|
|
44
|
+
**/
|
|
45
|
+
const apyBreakdownSchema = zod_v4.z.object({
|
|
46
|
+
totalApy: require_model_primitives_schema.bpsSchema,
|
|
47
|
+
organicApy: require_model_primitives_schema.bpsSchema,
|
|
48
|
+
rewards: zod_v4.z.array(rewardsSchema)
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* {@link OpportunityBase}
|
|
52
|
+
**/
|
|
53
|
+
const opportunityBaseSchema = zod_v4.z.object({
|
|
54
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
55
|
+
title: zod_v4.z.string(),
|
|
56
|
+
curator: require_model_primitives_schema.curatorSchema,
|
|
57
|
+
underlyingToken: require_model_primitives_schema.tokenSchema,
|
|
58
|
+
totalSupply: require_model_primitives_schema.amountSchema,
|
|
59
|
+
totalBorrow: require_model_primitives_schema.amountSchema,
|
|
60
|
+
utilization: require_model_primitives_schema.bpsSchema,
|
|
61
|
+
supplyApy: apyBreakdownSchema.optional(),
|
|
62
|
+
collateralTokens: zod_v4.z.array(require_model_primitives_schema.tokenSchema),
|
|
63
|
+
paused: zod_v4.z.boolean(),
|
|
64
|
+
rwa: zod_v4.z.boolean(),
|
|
65
|
+
sunset: zod_v4.z.boolean()
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* {@link PoolOpportunity}
|
|
69
|
+
**/
|
|
70
|
+
const poolOpportunitySchema = zod_v4.z.object({
|
|
71
|
+
...opportunityBaseSchema.shape,
|
|
72
|
+
kind: zod_v4.z.literal("pool"),
|
|
73
|
+
pool: require_sdk_utils_zod.ZodAddress()
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* {@link StrategyOpportunity}
|
|
77
|
+
**/
|
|
78
|
+
const strategyOpportunitySchema = zod_v4.z.object({
|
|
79
|
+
...opportunityBaseSchema.shape,
|
|
80
|
+
kind: zod_v4.z.literal("strategy"),
|
|
81
|
+
creditManager: require_sdk_utils_zod.ZodAddress(),
|
|
82
|
+
targetCollateral: require_model_primitives_schema.tokenSchema,
|
|
83
|
+
liquidationThreshold: require_model_primitives_schema.bpsSchema,
|
|
84
|
+
liquidationPremium: require_model_primitives_schema.bpsSchema,
|
|
85
|
+
liquidationFee: require_model_primitives_schema.bpsSchema,
|
|
86
|
+
expirationDate: require_model_primitives_schema.timestampSchema.nullable(),
|
|
87
|
+
collateralApy: apyBreakdownSchema.optional(),
|
|
88
|
+
borrowApy: require_model_primitives_schema.bpsSchema.optional(),
|
|
89
|
+
additionalBorrowApy: require_model_primitives_schema.bpsSchema.optional(),
|
|
90
|
+
maxBorrowAmount: require_model_primitives_schema.amountSchema,
|
|
91
|
+
maxLeverage: require_model_primitives_schema.leverageSchema
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* {@link Opportunity}
|
|
95
|
+
**/
|
|
96
|
+
const opportunitySchema = zod_v4.z.discriminatedUnion("kind", [poolOpportunitySchema, strategyOpportunitySchema]);
|
|
97
|
+
/**
|
|
98
|
+
* {@link OpportunityFilter}
|
|
99
|
+
**/
|
|
100
|
+
const opportunityFilterSchema = zod_v4.z.object({
|
|
101
|
+
kind: opportunityKindSchema.optional(),
|
|
102
|
+
chainIds: zod_v4.z.array(require_model_primitives_schema.chainIdSchema).optional(),
|
|
103
|
+
underlyingType: require_model_primitives_schema.assetTypeSchema.optional(),
|
|
104
|
+
paused: zod_v4.z.boolean().optional(),
|
|
105
|
+
sunset: zod_v4.z.boolean().optional(),
|
|
106
|
+
rwa: zod_v4.z.boolean().optional()
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* {@link RateCurvePoint}
|
|
110
|
+
**/
|
|
111
|
+
const rateCurvePointSchema = zod_v4.z.object({
|
|
112
|
+
utilization: require_model_primitives_schema.bpsSchema,
|
|
113
|
+
supplyApy: require_model_primitives_schema.bpsSchema,
|
|
114
|
+
borrowApy: require_model_primitives_schema.bpsSchema
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* {@link RateCurve}
|
|
118
|
+
**/
|
|
119
|
+
const rateCurveSchema = zod_v4.z.object({
|
|
120
|
+
points: zod_v4.z.array(rateCurvePointSchema),
|
|
121
|
+
borrowingLimitUtilization: require_model_primitives_schema.bpsSchema.nullable()
|
|
122
|
+
});
|
|
123
|
+
/**
|
|
124
|
+
* {@link QuotaAsset}
|
|
125
|
+
**/
|
|
126
|
+
const quotaAssetSchema = zod_v4.z.object({
|
|
127
|
+
token: require_model_primitives_schema.tokenSchema,
|
|
128
|
+
quotaRate: require_model_primitives_schema.bpsSchema,
|
|
129
|
+
limit: require_model_primitives_schema.amountSchema,
|
|
130
|
+
used: require_model_primitives_schema.amountSchema
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* {@link PriceFeedData}. Recursive: a composite feed lists the feeds it reads.
|
|
134
|
+
**/
|
|
135
|
+
const priceFeedDataSchema = zod_v4.z.object({
|
|
136
|
+
name: zod_v4.z.string(),
|
|
137
|
+
type: zod_v4.z.string(),
|
|
138
|
+
feedAddress: require_sdk_utils_zod.ZodAddress(),
|
|
139
|
+
get dependencies() {
|
|
140
|
+
return zod_v4.z.array(priceFeedDataSchema);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* {@link PriceFeedSummary}
|
|
145
|
+
**/
|
|
146
|
+
const priceFeedSummarySchema = zod_v4.z.object({
|
|
147
|
+
underlyingPriceInUsd: zod_v4.z.number(),
|
|
148
|
+
collateralPriceInUsd: zod_v4.z.number(),
|
|
149
|
+
collateralPriceInUnderlying: zod_v4.z.number(),
|
|
150
|
+
underlyingFeed: priceFeedDataSchema,
|
|
151
|
+
collateralFeed: priceFeedDataSchema
|
|
152
|
+
});
|
|
153
|
+
/**
|
|
154
|
+
* {@link PoolOpportunityDetail}
|
|
155
|
+
**/
|
|
156
|
+
const poolOpportunityDetailSchema = zod_v4.z.object({
|
|
157
|
+
...poolOpportunitySchema.shape,
|
|
158
|
+
rateCurve: rateCurveSchema,
|
|
159
|
+
quotaAssets: zod_v4.z.array(quotaAssetSchema)
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* {@link StrategyOpportunityDetail}
|
|
163
|
+
**/
|
|
164
|
+
const strategyOpportunityDetailSchema = zod_v4.z.object({
|
|
165
|
+
...strategyOpportunitySchema.shape,
|
|
166
|
+
rateCurve: rateCurveSchema,
|
|
167
|
+
priceFeeds: priceFeedSummarySchema
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* {@link OpportunityDetail}
|
|
171
|
+
**/
|
|
172
|
+
const opportunityDetailSchema = zod_v4.z.discriminatedUnion("kind", [poolOpportunityDetailSchema, strategyOpportunityDetailSchema]);
|
|
173
|
+
/**
|
|
174
|
+
* {@link PoolOpportunityKey}
|
|
175
|
+
**/
|
|
176
|
+
const poolOpportunityKeySchema = zod_v4.z.object({
|
|
177
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
178
|
+
pool: require_sdk_utils_zod.ZodAddress()
|
|
179
|
+
});
|
|
180
|
+
/**
|
|
181
|
+
* {@link StrategyOpportunityKey}
|
|
182
|
+
**/
|
|
183
|
+
const strategyOpportunityKeySchema = zod_v4.z.object({
|
|
184
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
185
|
+
creditManager: require_sdk_utils_zod.ZodAddress(),
|
|
186
|
+
targetCollateral: require_sdk_utils_zod.ZodAddress()
|
|
187
|
+
});
|
|
188
|
+
/**
|
|
189
|
+
* {@link OpportunityKey}
|
|
190
|
+
**/
|
|
191
|
+
const opportunityKeySchema = zod_v4.z.discriminatedUnion("kind", [zod_v4.z.object({
|
|
192
|
+
kind: zod_v4.z.literal("pool"),
|
|
193
|
+
...poolOpportunityKeySchema.shape
|
|
194
|
+
}), zod_v4.z.object({
|
|
195
|
+
kind: zod_v4.z.literal("strategy"),
|
|
196
|
+
...strategyOpportunityKeySchema.shape
|
|
197
|
+
})]);
|
|
198
|
+
//#endregion
|
|
199
|
+
exports.apyBreakdownSchema = apyBreakdownSchema;
|
|
200
|
+
exports.opportunityBaseSchema = opportunityBaseSchema;
|
|
201
|
+
exports.opportunityDetailSchema = opportunityDetailSchema;
|
|
202
|
+
exports.opportunityFilterSchema = opportunityFilterSchema;
|
|
203
|
+
exports.opportunityKeySchema = opportunityKeySchema;
|
|
204
|
+
exports.opportunityKindSchema = opportunityKindSchema;
|
|
205
|
+
exports.opportunitySchema = opportunitySchema;
|
|
206
|
+
exports.pointRewardsSchema = pointRewardsSchema;
|
|
207
|
+
exports.pointsProgramSchema = pointsProgramSchema;
|
|
208
|
+
exports.poolOpportunityDetailSchema = poolOpportunityDetailSchema;
|
|
209
|
+
exports.poolOpportunityKeySchema = poolOpportunityKeySchema;
|
|
210
|
+
exports.poolOpportunitySchema = poolOpportunitySchema;
|
|
211
|
+
exports.priceFeedDataSchema = priceFeedDataSchema;
|
|
212
|
+
exports.priceFeedSummarySchema = priceFeedSummarySchema;
|
|
213
|
+
exports.quotaAssetSchema = quotaAssetSchema;
|
|
214
|
+
exports.rateCurvePointSchema = rateCurvePointSchema;
|
|
215
|
+
exports.rateCurveSchema = rateCurveSchema;
|
|
216
|
+
exports.rewardsSchema = rewardsSchema;
|
|
217
|
+
exports.strategyOpportunityDetailSchema = strategyOpportunityDetailSchema;
|
|
218
|
+
exports.strategyOpportunityKeySchema = strategyOpportunityKeySchema;
|
|
219
|
+
exports.strategyOpportunitySchema = strategyOpportunitySchema;
|
|
220
|
+
exports.tokenRewardsSchema = tokenRewardsSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_zod = require("../sdk/utils/zod.js");
|
|
3
|
+
let zod_v4 = require("zod/v4");
|
|
4
|
+
//#region src/model/primitives.schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime schemas for {@link ./primitives.js}.
|
|
7
|
+
*
|
|
8
|
+
* The hand-written types are the contract; these schemas exist so the offchain
|
|
9
|
+
* client can reject a backend response that no longer matches it. The two are
|
|
10
|
+
* kept in sync by the type-level tests in `model.test-d.ts`, not by inferring
|
|
11
|
+
* one from the other.
|
|
12
|
+
**/
|
|
13
|
+
/**
|
|
14
|
+
* {@link ChainId}
|
|
15
|
+
**/
|
|
16
|
+
const chainIdSchema = zod_v4.z.number().int().positive();
|
|
17
|
+
/**
|
|
18
|
+
* {@link Timestamp}
|
|
19
|
+
**/
|
|
20
|
+
const timestampSchema = zod_v4.z.number().int().nonnegative();
|
|
21
|
+
/**
|
|
22
|
+
* {@link Bps}. Integer, not bounded to `0..10000`: rates may exceed 100%.
|
|
23
|
+
**/
|
|
24
|
+
const bpsSchema = zod_v4.z.number().int();
|
|
25
|
+
/**
|
|
26
|
+
* {@link AssetType}
|
|
27
|
+
**/
|
|
28
|
+
const assetTypeSchema = zod_v4.z.union([
|
|
29
|
+
zod_v4.z.literal("Stable"),
|
|
30
|
+
zod_v4.z.literal("ETH"),
|
|
31
|
+
zod_v4.z.literal("BTC")
|
|
32
|
+
]);
|
|
33
|
+
/**
|
|
34
|
+
* {@link Leverage}
|
|
35
|
+
**/
|
|
36
|
+
const leverageSchema = zod_v4.z.number().positive();
|
|
37
|
+
/**
|
|
38
|
+
* {@link Amount}
|
|
39
|
+
**/
|
|
40
|
+
const amountSchema = zod_v4.z.object({
|
|
41
|
+
value: zod_v4.z.bigint(),
|
|
42
|
+
valueUsd: zod_v4.z.number().nullable()
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* {@link Token}
|
|
46
|
+
**/
|
|
47
|
+
const tokenSchema = zod_v4.z.object({
|
|
48
|
+
chainId: chainIdSchema,
|
|
49
|
+
address: require_sdk_utils_zod.ZodAddress(),
|
|
50
|
+
symbol: zod_v4.z.string(),
|
|
51
|
+
name: zod_v4.z.string(),
|
|
52
|
+
decimals: zod_v4.z.number().int().nonnegative(),
|
|
53
|
+
assetType: assetTypeSchema.optional()
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* {@link TokenAmount}
|
|
57
|
+
**/
|
|
58
|
+
const tokenAmountSchema = amountSchema.extend({ token: tokenSchema });
|
|
59
|
+
/**
|
|
60
|
+
* {@link TxCall}
|
|
61
|
+
**/
|
|
62
|
+
const txCallSchema = zod_v4.z.object({
|
|
63
|
+
to: require_sdk_utils_zod.ZodAddress(),
|
|
64
|
+
callData: require_sdk_utils_zod.ZodHex(),
|
|
65
|
+
value: zod_v4.z.bigint().optional()
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* {@link Curator}
|
|
69
|
+
**/
|
|
70
|
+
const curatorSchema = zod_v4.z.object({
|
|
71
|
+
address: require_sdk_utils_zod.ZodAddress(),
|
|
72
|
+
name: zod_v4.z.string(),
|
|
73
|
+
url: zod_v4.z.string().nullable()
|
|
74
|
+
});
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.amountSchema = amountSchema;
|
|
77
|
+
exports.assetTypeSchema = assetTypeSchema;
|
|
78
|
+
exports.bpsSchema = bpsSchema;
|
|
79
|
+
exports.chainIdSchema = chainIdSchema;
|
|
80
|
+
exports.curatorSchema = curatorSchema;
|
|
81
|
+
exports.leverageSchema = leverageSchema;
|
|
82
|
+
exports.timestampSchema = timestampSchema;
|
|
83
|
+
exports.tokenAmountSchema = tokenAmountSchema;
|
|
84
|
+
exports.tokenSchema = tokenSchema;
|
|
85
|
+
exports.txCallSchema = txCallSchema;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_chain_chains = require("../sdk/chain/chains.js");
|
|
3
|
+
const require_new_sdk_types = require("./types.js");
|
|
4
|
+
//#region src/new-sdk/AbstractNamespace.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared machinery of every {@link GearboxSDK} namespace.
|
|
7
|
+
*
|
|
8
|
+
* A namespace is a stateless router: it asks the sources its mode allows, in
|
|
9
|
+
* parallel, merges what came back and reports what did not. This class owns
|
|
10
|
+
* that routing — per-chain failure capture, backend degradation, the response
|
|
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.
|
|
22
|
+
**/
|
|
23
|
+
var AbstractNamespace = class {
|
|
24
|
+
logger;
|
|
25
|
+
#onchain;
|
|
26
|
+
#offchain;
|
|
27
|
+
constructor(name, onchain, offchain, logger) {
|
|
28
|
+
this.#onchain = onchain;
|
|
29
|
+
this.#offchain = offchain;
|
|
30
|
+
this.logger = logger?.child?.({ name }) ?? logger;
|
|
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 ?? []));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads one row from both sources and merges them under
|
|
56
|
+
* {@link AbstractNamespace.mergeOne}. The key names the chain, so the
|
|
57
|
+
* on-chain leg queries exactly one.
|
|
58
|
+
**/
|
|
59
|
+
async readOne(action, chainId, fromChain, fromBackend) {
|
|
60
|
+
return this.read(action, async (sdk) => {
|
|
61
|
+
const network = this.networkOf(chainId);
|
|
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
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reads something only the backend can answer.
|
|
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.
|
|
74
|
+
**/
|
|
75
|
+
async readOffchain(action, fromBackend, fallback) {
|
|
76
|
+
const offchain = await this.fromBackend(fromBackend);
|
|
77
|
+
const meta = toMeta({ chains: [] }, offchain);
|
|
78
|
+
this.assertAnySourceSucceeded(action, meta);
|
|
79
|
+
return {
|
|
80
|
+
result: offchain.value ?? fallback,
|
|
81
|
+
meta
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Runs a read against the chain, or reports the chain as absent when the
|
|
86
|
+
* namespace has no on-chain source at all.
|
|
87
|
+
**/
|
|
88
|
+
async fromChain(run) {
|
|
89
|
+
return this.#onchain ? run(this.#onchain) : { chains: [] };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Runs a read against the backend, turning any rejection into metadata so
|
|
93
|
+
* that a dead backend degrades a `both`-mode read instead of failing it.
|
|
94
|
+
**/
|
|
95
|
+
async fromBackend(run) {
|
|
96
|
+
if (!this.#offchain) return {};
|
|
97
|
+
try {
|
|
98
|
+
const { result, meta } = await run(this.#offchain);
|
|
99
|
+
return {
|
|
100
|
+
value: meta.status === "success" ? result : void 0,
|
|
101
|
+
status: meta
|
|
102
|
+
};
|
|
103
|
+
} catch (error) {
|
|
104
|
+
this.logger?.warn(error, "offchain read failed");
|
|
105
|
+
return { status: {
|
|
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;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
function toMeta(onchain, offchain) {
|
|
153
|
+
const meta = { chains: onchain.chains };
|
|
154
|
+
if (offchain.status) meta.offchain = offchain.status;
|
|
155
|
+
return meta;
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
exports.AbstractNamespace = AbstractNamespace;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_MultichainSDK = require("../sdk/MultichainSDK.js");
|
|
3
|
+
require("../sdk/index.js");
|
|
4
|
+
const require_offchain_GearboxAPI = require("../offchain/GearboxAPI.js");
|
|
5
|
+
require("../offchain/index.js");
|
|
6
|
+
const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
|
|
7
|
+
require("./opportunities/index.js");
|
|
8
|
+
//#region src/new-sdk/GearboxSDK.ts
|
|
9
|
+
/**
|
|
10
|
+
* Combined entry point over both sources of Gearbox data: the chain and the
|
|
11
|
+
* Gearbox backend.
|
|
12
|
+
*
|
|
13
|
+
* The {@link Mode} is fixed at construction and decides which methods exist,
|
|
14
|
+
* not what they return, so a screen written against `both` cannot silently
|
|
15
|
+
* degrade to a subset when someone reconfigures the SDK:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const sdk = new GearboxSDK({
|
|
19
|
+
* mode: "both",
|
|
20
|
+
* networks: ["Mainnet"],
|
|
21
|
+
* onchain: { chains: { Mainnet: { rpcURLs } } },
|
|
22
|
+
* offchain: { baseUrl: "https://api.gearbox.fi" },
|
|
23
|
+
* });
|
|
24
|
+
* await sdk.attach();
|
|
25
|
+
*
|
|
26
|
+
* const { result, meta } = await sdk.opportunities.list({ kind: "strategy" });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Every read answers with `{ result, meta }`: `meta` says which chains and
|
|
30
|
+
* which backend answered, because a partial answer is the normal case for a
|
|
31
|
+
* multi-chain read.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam M - Mode the instance was built in.
|
|
34
|
+
**/
|
|
35
|
+
var GearboxSDK = class {
|
|
36
|
+
/**
|
|
37
|
+
* Sources this instance reads from.
|
|
38
|
+
**/
|
|
39
|
+
mode;
|
|
40
|
+
/**
|
|
41
|
+
* Chains this instance covers. Authoritative even when an injected on-chain
|
|
42
|
+
* SDK covers a different set.
|
|
43
|
+
**/
|
|
44
|
+
networks;
|
|
45
|
+
/**
|
|
46
|
+
* Namespace for pool and strategy opportunities.
|
|
47
|
+
**/
|
|
48
|
+
opportunities;
|
|
49
|
+
#attachOptions;
|
|
50
|
+
#onchain;
|
|
51
|
+
#offchain;
|
|
52
|
+
/**
|
|
53
|
+
* Whether this instance built the on-chain SDK, and therefore attaches it.
|
|
54
|
+
**/
|
|
55
|
+
#ownsOnchain = false;
|
|
56
|
+
#attached;
|
|
57
|
+
constructor(options) {
|
|
58
|
+
const { mode, networks, onchain, offchain, attach, logger } = options;
|
|
59
|
+
this.mode = mode;
|
|
60
|
+
this.networks = [...networks];
|
|
61
|
+
this.#attachOptions = attach;
|
|
62
|
+
const needsOnchain = mode === "onchain" || mode === "both";
|
|
63
|
+
const needsOffchain = mode === "offchain" || mode === "both";
|
|
64
|
+
if (needsOnchain && !onchain) throw new Error(`GearboxSDK in ${mode} mode needs an onchain source`);
|
|
65
|
+
if (needsOffchain && !offchain) throw new Error(`GearboxSDK in ${mode} mode needs an offchain source`);
|
|
66
|
+
if (!needsOnchain && onchain) logger?.warn(`GearboxSDK in ${mode} mode ignores the onchain source it was given`);
|
|
67
|
+
if (!needsOffchain && offchain) logger?.warn(`GearboxSDK in ${mode} mode ignores the offchain source it was given`);
|
|
68
|
+
if (needsOnchain && onchain) if (onchain instanceof require_sdk_MultichainSDK.MultichainSDK) this.#onchain = onchain;
|
|
69
|
+
else {
|
|
70
|
+
this.#onchain = new require_sdk_MultichainSDK.MultichainSDK({
|
|
71
|
+
logger,
|
|
72
|
+
...onchain
|
|
73
|
+
});
|
|
74
|
+
this.#ownsOnchain = true;
|
|
75
|
+
}
|
|
76
|
+
if (needsOffchain && offchain) this.#offchain = offchain instanceof require_offchain_GearboxAPI.GearboxAPI ? offchain : new require_offchain_GearboxAPI.GearboxAPI({
|
|
77
|
+
logger,
|
|
78
|
+
...offchain
|
|
79
|
+
});
|
|
80
|
+
this.#attached = !this.#ownsOnchain;
|
|
81
|
+
this.opportunities = new require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace(this.#onchain, this.#offchain, logger);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Attaches the on-chain SDK when this instance owns one.
|
|
85
|
+
*
|
|
86
|
+
* Reads issued before this resolves still reach the chain and fail there, so
|
|
87
|
+
* in `both` mode they are served from the backend alone and report the chain
|
|
88
|
+
* as failed in their meta, rather than blocking.
|
|
89
|
+
*
|
|
90
|
+
* A no-op in `offchain` mode and when an already-attached SDK was injected.
|
|
91
|
+
**/
|
|
92
|
+
async attach() {
|
|
93
|
+
if (this.#attached || !this.#ownsOnchain || !this.#onchain) return;
|
|
94
|
+
await this.#onchain.attach(this.#attachOptions);
|
|
95
|
+
this.#attached = true;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Whether the on-chain source is ready to be read from. Always `true` in
|
|
99
|
+
* `offchain` mode, where there is nothing to wait for.
|
|
100
|
+
**/
|
|
101
|
+
get attached() {
|
|
102
|
+
return this.mode === "offchain" ? true : this.#attached;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The underlying on-chain SDK, for everything this facade does not expose
|
|
106
|
+
* yet: markets, credit accounts, transaction building.
|
|
107
|
+
*
|
|
108
|
+
* `undefined` in `offchain` mode. Otherwise it exists from construction on,
|
|
109
|
+
* but only answers reads once {@link attach} has resolved.
|
|
110
|
+
**/
|
|
111
|
+
get onchain() {
|
|
112
|
+
return this.#onchain;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The underlying backend client. `undefined` in `onchain` mode.
|
|
116
|
+
**/
|
|
117
|
+
get offchain() {
|
|
118
|
+
return this.#offchain;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
//#endregion
|
|
122
|
+
exports.GearboxSDK = GearboxSDK;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_new_sdk_types = require("./types.js");
|
|
3
|
+
const require_new_sdk_AbstractNamespace = require("./AbstractNamespace.js");
|
|
4
|
+
const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
|
|
5
|
+
require("./opportunities/index.js");
|
|
6
|
+
const require_new_sdk_GearboxSDK = require("./GearboxSDK.js");
|
|
7
|
+
require("./utils/index.js");
|
|
8
|
+
exports.AbstractNamespace = require_new_sdk_AbstractNamespace.AbstractNamespace;
|
|
9
|
+
exports.AllSourcesFailedError = require_new_sdk_types.AllSourcesFailedError;
|
|
10
|
+
exports.GearboxSDK = require_new_sdk_GearboxSDK.GearboxSDK;
|
|
11
|
+
exports.OpportunitiesNamespace = require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace;
|