@gearbox-protocol/sdk 15.1.0-next.19 → 15.1.0-next.20
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/charts/credit-session.js +1 -1
- package/dist/cjs/model/opportunities.js +4 -4
- package/dist/cjs/model/opportunities.schema.js +1 -2
- package/dist/cjs/new-sdk/prepare/PrepareApi.js +14 -10
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/cjs/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/cjs/sdk/OnchainSDK.js +2 -2
- package/dist/cjs/sdk/accounts/intents/testing/market.js +2 -1
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +2 -2
- package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +1 -1
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +2 -2
- package/dist/cjs/sdk/chain/chains.js +140 -51
- package/dist/cjs/sdk/chain/index.js +3 -0
- package/dist/cjs/sdk/constants/networks.js +1 -1
- package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +1 -1
- package/dist/cjs/sdk/index.js +11 -7
- package/dist/cjs/sdk/market/MarketSuite.js +8 -39
- package/dist/cjs/sdk/market/credit/CreditSuite.js +61 -37
- package/dist/cjs/sdk/market/credit/{isStrategyCollateral.js → collateralUtils.js} +52 -5
- package/dist/cjs/sdk/market/credit/index.js +5 -6
- package/dist/cjs/sdk/market/index.js +7 -6
- package/dist/cjs/sdk/market/strategyName.js +19 -0
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +5 -3
- package/dist/cjs/sdk/positions/PositionsService.js +5 -10
- package/dist/cjs/sdk/utils/index.js +1 -1
- package/dist/esm/common-utils/charts/credit-session.js +1 -1
- package/dist/esm/model/opportunities.js +4 -4
- package/dist/esm/model/opportunities.schema.js +1 -2
- package/dist/esm/new-sdk/prepare/PrepareApi.js +14 -10
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/esm/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/esm/sdk/OnchainSDK.js +2 -2
- package/dist/esm/sdk/accounts/intents/testing/market.js +2 -1
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/esm/sdk/accounts/intents/utils/pick-token.js +1 -1
- package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +1 -1
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/sdk/chain/chains.js +139 -53
- package/dist/esm/sdk/chain/index.js +2 -2
- package/dist/esm/sdk/constants/networks.js +1 -1
- package/dist/esm/sdk/core/AbstractAddressProviderContract.js +1 -1
- package/dist/esm/sdk/index.js +5 -5
- package/dist/esm/sdk/market/MarketSuite.js +8 -39
- package/dist/esm/sdk/market/credit/CreditSuite.js +62 -38
- package/dist/esm/sdk/market/credit/{isStrategyCollateral.js → collateralUtils.js} +51 -6
- package/dist/esm/sdk/market/credit/index.js +2 -3
- package/dist/esm/sdk/market/index.js +3 -3
- package/dist/esm/sdk/market/strategyName.js +18 -0
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +5 -3
- package/dist/esm/sdk/positions/PositionsService.js +5 -10
- package/dist/esm/sdk/utils/index.js +1 -1
- package/dist/types/model/index.d.ts +1 -1
- package/dist/types/model/opportunities.d.ts +8 -15
- package/dist/types/model/opportunities.schema.d.ts +0 -2
- package/dist/types/model/positions.d.ts +2 -10
- package/dist/types/new-sdk/errors/SourceChainMismatchError.d.ts +1 -1
- package/dist/types/new-sdk/positions/mergePositionList.d.ts +3 -2
- package/dist/types/new-sdk/types.d.ts +1 -1
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +5 -0
- package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
- package/dist/types/sdk/base/MultichainConstruct.d.ts +1 -1
- package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
- package/dist/types/sdk/chain/chains.d.ts +51 -7
- package/dist/types/sdk/chain/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +7 -7
- package/dist/types/sdk/market/MarketRegister.d.ts +1 -1
- package/dist/types/sdk/market/MarketSuite.d.ts +4 -34
- package/dist/types/sdk/market/ZapperRegister.d.ts +1 -1
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +23 -14
- package/dist/types/sdk/market/credit/{isStrategyCollateral.d.ts → collateralUtils.d.ts} +36 -8
- package/dist/types/sdk/market/credit/index.d.ts +2 -3
- package/dist/types/sdk/market/index.d.ts +4 -4
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +1 -1
- package/dist/types/sdk/market/oracle/types.d.ts +1 -1
- package/dist/types/sdk/market/strategyName.d.ts +18 -0
- package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +2 -2
- package/dist/types/sdk/positions/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/sdk/market/credit/dominantCollateral.js +0 -47
- package/dist/esm/sdk/market/credit/dominantCollateral.js +0 -45
- package/dist/types/sdk/market/credit/dominantCollateral.d.ts +0 -29
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -8,7 +8,6 @@ const require_sdk_utils_bigint_math = require("./utils/bigint-math.js");
|
|
|
8
8
|
const require_sdk_utils_bytes32ToString = require("./utils/bytes32ToString.js");
|
|
9
9
|
const require_sdk_utils_childLogger = require("./utils/childLogger.js");
|
|
10
10
|
const require_sdk_utils_createRawTx = require("./utils/createRawTx.js");
|
|
11
|
-
const require_sdk_utils_mappers = require("./utils/mappers.js");
|
|
12
11
|
const require_sdk_chain_chains = require("./chain/chains.js");
|
|
13
12
|
const require_sdk_chain_detectNetwork = require("./chain/detectNetwork.js");
|
|
14
13
|
require("./chain/index.js");
|
|
@@ -17,6 +16,7 @@ const require_sdk_constants_address_provider = require("./constants/address-prov
|
|
|
17
16
|
const require_sdk_constants_addresses = require("./constants/addresses.js");
|
|
18
17
|
const require_sdk_constants_bot_permissions = require("./constants/bot-permissions.js");
|
|
19
18
|
const require_sdk_constants_math = require("./constants/math.js");
|
|
19
|
+
const require_sdk_utils_mappers = require("./utils/mappers.js");
|
|
20
20
|
const require_sdk_constants_networks = require("./constants/networks.js");
|
|
21
21
|
const require_sdk_constants_periphery = require("./constants/periphery.js");
|
|
22
22
|
const require_sdk_constants_versions = require("./constants/versions.js");
|
|
@@ -134,8 +134,8 @@ const require_sdk_market_credit_CreditFacadeV310BaseContract = require("./market
|
|
|
134
134
|
const require_sdk_market_credit_CreditFacadeV310Contract = require("./market/credit/CreditFacadeV310Contract.js");
|
|
135
135
|
const require_sdk_market_math = require("./market/math.js");
|
|
136
136
|
const require_sdk_market_credit_CreditManagerV310Contract = require("./market/credit/CreditManagerV310Contract.js");
|
|
137
|
-
const
|
|
138
|
-
const
|
|
137
|
+
const require_sdk_market_strategyName = require("./market/strategyName.js");
|
|
138
|
+
const require_sdk_market_credit_collateralUtils = require("./market/credit/collateralUtils.js");
|
|
139
139
|
const require_sdk_market_credit_CreditSuite = require("./market/credit/CreditSuite.js");
|
|
140
140
|
const require_sdk_market_credit_expectedBalanceDeltas = require("./market/credit/expectedBalanceDeltas.js");
|
|
141
141
|
const require_sdk_utils_viem_simulateMulticall = require("./utils/viem/simulateMulticall.js");
|
|
@@ -370,7 +370,7 @@ exports.MultichainOpportunitiesService = require_sdk_opportunities_MultichainOpp
|
|
|
370
370
|
exports.MultichainPositionsService = require_sdk_positions_MultichainPositionsService.MultichainPositionsService;
|
|
371
371
|
exports.MultichainSDK = require_sdk_MultichainSDK.MultichainSDK;
|
|
372
372
|
exports.NATIVE_ADDRESS = require_sdk_constants_addresses.NATIVE_ADDRESS;
|
|
373
|
-
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES =
|
|
373
|
+
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_collateralUtils.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
|
|
374
374
|
exports.NOT_DEPLOYED = require_sdk_constants_addresses.NOT_DEPLOYED;
|
|
375
375
|
exports.NO_VERSION = require_sdk_constants_address_provider.NO_VERSION;
|
|
376
376
|
exports.NetworkType = require_sdk_chain_chains.NetworkType;
|
|
@@ -495,7 +495,7 @@ exports.curveAddLiquidityFromTransfers = require_sdk_market_adapters_transferHel
|
|
|
495
495
|
exports.curveRemoveLiquidityFromTransfers = require_sdk_market_adapters_transferHelpers.curveRemoveLiquidityFromTransfers;
|
|
496
496
|
exports.decodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.decodeDelayedIntent;
|
|
497
497
|
exports.detectNetwork = require_sdk_chain_detectNetwork.detectNetwork;
|
|
498
|
-
exports.dominantCollateral =
|
|
498
|
+
exports.dominantCollateral = require_sdk_market_credit_collateralUtils.dominantCollateral;
|
|
499
499
|
exports.encodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.encodeDelayedIntent;
|
|
500
500
|
exports.erc4626ReferralAdapterAbi = require_sdk_market_adapters_abi_adapters_erc4626ReferralAdapter.erc4626ReferralAdapterAbi;
|
|
501
501
|
exports.estimateRawTxGas = require_sdk_utils_viem_sendRawTx.estimateRawTxGas;
|
|
@@ -521,6 +521,7 @@ exports.formatTimestamp = require_sdk_utils_formatter.formatTimestamp;
|
|
|
521
521
|
exports.functionArgsToMap = require_sdk_utils_abi_decode.functionArgsToMap;
|
|
522
522
|
exports.functionArgsToRecord = require_sdk_utils_abi_decode.functionArgsToRecord;
|
|
523
523
|
exports.generateCastTraceCall = require_sdk_utils_viem_cast.generateCastTraceCall;
|
|
524
|
+
exports.getAccountTargetCollateral = require_sdk_chain_chains.getAccountTargetCollateral;
|
|
524
525
|
exports.getAdapterActionAbi = require_sdk_market_adapters_abi_utils.getAdapterActionAbi;
|
|
525
526
|
exports.getAdapterDeployParamsAbi = require_sdk_market_adapters_abi_utils.getAdapterDeployParamsAbi;
|
|
526
527
|
exports.getAdapterType = require_sdk_market_adapters_abi_utils.getAdapterType;
|
|
@@ -529,9 +530,11 @@ exports.getCastTraceArgs = require_sdk_utils_viem_cast.getCastTraceArgs;
|
|
|
529
530
|
exports.getChain = require_sdk_chain_chains.getChain;
|
|
530
531
|
exports.getCuratorName = require_sdk_chain_chains.getCuratorName;
|
|
531
532
|
exports.getFunctionSignature = require_sdk_utils_abi_decode.getFunctionSignature;
|
|
533
|
+
exports.getLegacyStrategyTarget = require_sdk_chain_chains.getLegacyStrategyTarget;
|
|
532
534
|
exports.getNetworkType = require_sdk_chain_chains.getNetworkType;
|
|
533
535
|
exports.getRawPriceUpdates = require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates;
|
|
534
536
|
exports.getSimulateWithPriceUpdatesError = require_sdk_utils_viem_simulateWithPriceUpdates.getSimulateWithPriceUpdatesError;
|
|
537
|
+
exports.getTokenPrettyName = require_sdk_chain_chains.getTokenPrettyName;
|
|
535
538
|
exports.getWithdrawalCompressorAddress = require_sdk_accounts_withdrawal_compressor_addresses.getWithdrawalCompressorAddress;
|
|
536
539
|
exports.halfRAY = require_sdk_constants_math.halfRAY;
|
|
537
540
|
exports.hasAdapterDeployParamsAbi = require_sdk_market_adapters_abi_utils.hasAdapterDeployParamsAbi;
|
|
@@ -612,7 +615,7 @@ exports.isLPPriceFeed = require_sdk_market_pricefeeds_AbstractLPPriceFeed.isLPPr
|
|
|
612
615
|
exports.isPublicNetwork = require_sdk_chain_chains.isPublicNetwork;
|
|
613
616
|
exports.isRWAFactory = require_sdk_market_rwa_types.isRWAFactory;
|
|
614
617
|
exports.isRWAToken = require_sdk_chain_chains.isRWAToken;
|
|
615
|
-
exports.isStrategyCollateral =
|
|
618
|
+
exports.isStrategyCollateral = require_sdk_market_credit_collateralUtils.isStrategyCollateral;
|
|
616
619
|
exports.isSunsetPool = require_sdk_chain_chains.isSunsetPool;
|
|
617
620
|
exports.isSunsetStrategy = require_sdk_chain_chains.isSunsetStrategy;
|
|
618
621
|
exports.isSupportedNetwork = require_sdk_chain_chains.isSupportedNetwork;
|
|
@@ -626,7 +629,6 @@ exports.json_stringify = require_sdk_utils_json.json_stringify;
|
|
|
626
629
|
exports.lidoV1_WETHGatewayAbi = require_sdk_market_adapters_abi_targetContractAbi.lidoV1_WETHGatewayAbi;
|
|
627
630
|
exports.mellowDvvAdapterAbi = require_sdk_market_adapters_abi_adapters_mellowDvvAdapter.mellowDvvAdapterAbi;
|
|
628
631
|
exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
|
|
629
|
-
exports.mustGetDominantCollateral = require_sdk_market_credit_dominantCollateral.mustGetDominantCollateral;
|
|
630
632
|
exports.numberWithCommas = require_sdk_utils_formatter.numberWithCommas;
|
|
631
633
|
exports.onchainSDKOptionsSchema = require_sdk_options.onchainSDKOptionsSchema;
|
|
632
634
|
exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
|
|
@@ -635,6 +637,7 @@ exports.parseAdapterAction = require_sdk_market_adapters_abi_utils.parseAdapterA
|
|
|
635
637
|
exports.parseAdapterDeployParams = require_sdk_market_adapters_abi_utils.parseAdapterDeployParams;
|
|
636
638
|
exports.parsePosNegAmount = require_sdk_market_adapters_transferHelpers.parsePosNegAmount;
|
|
637
639
|
exports.percentFmt = require_sdk_utils_formatter.percentFmt;
|
|
640
|
+
exports.pickStrategyTargetCollateral = require_sdk_market_credit_collateralUtils.pickStrategyTargetCollateral;
|
|
638
641
|
exports.rayToBps = require_sdk_market_math.rayToBps;
|
|
639
642
|
exports.rayToNumber = require_sdk_utils_formatter.rayToNumber;
|
|
640
643
|
exports.retry = require_sdk_utils_retry.retry;
|
|
@@ -645,6 +648,7 @@ exports.shortHash = require_sdk_utils_formatter.shortHash;
|
|
|
645
648
|
exports.simulateCall = require_sdk_utils_viem_simulateCall.simulateCall;
|
|
646
649
|
exports.simulateMulticall = require_sdk_utils_viem_simulateMulticall.simulateMulticall;
|
|
647
650
|
exports.simulateWithPriceUpdates = require_sdk_utils_viem_simulateWithPriceUpdates.simulateWithPriceUpdates;
|
|
651
|
+
exports.strategyName = require_sdk_market_strategyName.strategyName;
|
|
648
652
|
exports.swapFromTransfers = require_sdk_market_adapters_transferHelpers.swapFromTransfers;
|
|
649
653
|
exports.toAddress = require_sdk_utils_toAddress.toAddress;
|
|
650
654
|
exports.toBN = require_sdk_utils_formatter.toBN;
|
|
@@ -17,7 +17,6 @@ const require_sdk_market_oracle_createPriceOracle = require("./oracle/createPric
|
|
|
17
17
|
require("./oracle/index.js");
|
|
18
18
|
const require_sdk_market_pool_PoolSuite = require("./pool/PoolSuite.js");
|
|
19
19
|
require("./pool/index.js");
|
|
20
|
-
let viem = require("viem");
|
|
21
20
|
//#region src/sdk/market/MarketSuite.ts
|
|
22
21
|
/**
|
|
23
22
|
* Aggregates all SDK wrappers that make up one Gearbox market.
|
|
@@ -137,22 +136,12 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
137
136
|
return this.configurator.curator;
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
140
|
-
* Every `(credit suite, collateral)` pair of this market that qualifies as a
|
|
141
|
-
* leveraged position.
|
|
142
|
-
*/
|
|
143
|
-
get strategies() {
|
|
144
|
-
return this.creditManagers.flatMap((suite) => suite.strategyCollaterals.map((collateral) => ({
|
|
145
|
-
suite,
|
|
146
|
-
collateral
|
|
147
|
-
})));
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
139
|
* Tokens a position can actually be built on in this market, deduplicated
|
|
151
140
|
* across its credit suites.
|
|
152
141
|
*/
|
|
153
142
|
get collateralTokens() {
|
|
154
143
|
const seen = new require_sdk_utils_AddressMap.AddressMap(void 0, "collateralTokens");
|
|
155
|
-
for (const
|
|
144
|
+
for (const suite of this.creditManagers) for (const collateral of suite.strategyCollaterals) seen.upsert(collateral, this.tokensMeta.mustGetToken(collateral));
|
|
156
145
|
return seen.values();
|
|
157
146
|
}
|
|
158
147
|
/**
|
|
@@ -160,7 +149,7 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
160
149
|
* token. Read from a hardcoded per-chain list rather than from the chain.
|
|
161
150
|
*/
|
|
162
151
|
get rwa() {
|
|
163
|
-
return this.
|
|
152
|
+
return this.collateralTokens.some((token) => require_sdk_chain_chains.isRWAToken(token.address, this.sdk.networkType));
|
|
164
153
|
}
|
|
165
154
|
/**
|
|
166
155
|
* Whether this market's pool is being wound down and should no longer be
|
|
@@ -195,8 +184,8 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
195
184
|
return this.priceOracle.priceFeedSummary(this.underlying, collateral);
|
|
196
185
|
}
|
|
197
186
|
/**
|
|
198
|
-
* Every opportunity this market offers: its pool, plus one row per
|
|
199
|
-
*
|
|
187
|
+
* Every opportunity this market offers: its pool, plus one row per credit
|
|
188
|
+
* manager that qualifies as a strategy.
|
|
200
189
|
*
|
|
201
190
|
* @param filter - Optional narrowing. A filter naming a kind skips building
|
|
202
191
|
* the other kind entirely; every built row is then checked in full by
|
|
@@ -207,7 +196,10 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
207
196
|
const rows = [];
|
|
208
197
|
const kind = filter?.kind;
|
|
209
198
|
if (!require_model_filters.isFilterSet(kind) || kind === "pool") rows.push(this.poolOpportunity());
|
|
210
|
-
if (!require_model_filters.isFilterSet(kind) || kind === "strategy") for (const
|
|
199
|
+
if (!require_model_filters.isFilterSet(kind) || kind === "strategy") for (const suite of this.creditManagers) {
|
|
200
|
+
const opportunity = suite.strategyOpportunity();
|
|
201
|
+
if (opportunity) rows.push(opportunity);
|
|
202
|
+
}
|
|
211
203
|
return rows.filter((row) => require_model_opportunities.matchesOpportunityFilter(row, filter));
|
|
212
204
|
}
|
|
213
205
|
/**
|
|
@@ -246,29 +238,6 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
246
238
|
};
|
|
247
239
|
}
|
|
248
240
|
/**
|
|
249
|
-
* Resolves a strategy of this market by its two halves.
|
|
250
|
-
*
|
|
251
|
-
* @param creditManager - Credit manager the position is opened in.
|
|
252
|
-
* @param collateral - Target collateral of the position.
|
|
253
|
-
* @throws If this market has no such credit manager, or if that manager does
|
|
254
|
-
* not accept the collateral as a strategy.
|
|
255
|
-
*/
|
|
256
|
-
mustFindStrategy(creditManager, collateral) {
|
|
257
|
-
const strategy = this.strategies.find((s) => (0, viem.isAddressEqual)(s.suite.creditManager.address, creditManager) && (0, viem.isAddressEqual)(s.collateral, collateral));
|
|
258
|
-
if (!strategy) throw new Error(`${this.labelAddress(collateral)} is not a strategy collateral of credit manager ${this.labelAddress(creditManager)}`);
|
|
259
|
-
return strategy;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Detailed view of one leveraged position of this market.
|
|
263
|
-
*
|
|
264
|
-
* @param creditManager - Credit manager the position is opened in.
|
|
265
|
-
* @param collateral - Target collateral of the position.
|
|
266
|
-
* @throws If this market has no such strategy, see {@link mustFindStrategy}.
|
|
267
|
-
*/
|
|
268
|
-
strategyOpportunityDetail(creditManager, collateral) {
|
|
269
|
-
return this.mustFindStrategy(creditManager, collateral).suite.strategyOpportunityDetail(collateral);
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
241
|
* Whether any child contract wrapper has observed events that require a
|
|
273
242
|
* market resync.
|
|
274
243
|
*/
|
|
@@ -8,11 +8,11 @@ require("../../utils/index.js");
|
|
|
8
8
|
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
9
9
|
require("../../base/index.js");
|
|
10
10
|
const require_sdk_market_math = require("../math.js");
|
|
11
|
+
const require_sdk_market_strategyName = require("../strategyName.js");
|
|
12
|
+
const require_sdk_market_credit_collateralUtils = require("./collateralUtils.js");
|
|
11
13
|
const require_sdk_market_credit_createCreditConfigurator = require("./createCreditConfigurator.js");
|
|
12
14
|
const require_sdk_market_credit_createCreditFacade = require("./createCreditFacade.js");
|
|
13
15
|
const require_sdk_market_credit_createCreditManager = require("./createCreditManager.js");
|
|
14
|
-
const require_sdk_market_credit_dominantCollateral = require("./dominantCollateral.js");
|
|
15
|
-
const require_sdk_market_credit_isStrategyCollateral = require("./isStrategyCollateral.js");
|
|
16
16
|
//#region src/sdk/market/credit/CreditSuite.ts
|
|
17
17
|
/**
|
|
18
18
|
* SDK aggregate for one credit-manager branch inside a market.
|
|
@@ -181,22 +181,26 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
181
181
|
*/
|
|
182
182
|
get strategyCollaterals() {
|
|
183
183
|
if (this.maxBorrowAmount === 0n) return [];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
184
|
+
return this.creditManager.collateralTokens.filter((token) => require_sdk_market_credit_collateralUtils.isStrategyCollateral(this.#strategyCollateralProps(token), true));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The single target collateral of this suite's strategy, or `undefined` when
|
|
188
|
+
* none can be resolved.
|
|
189
|
+
*
|
|
190
|
+
* Resolution, in order:
|
|
191
|
+
* 1. a hardcoded legacy mapping for this credit manager, when that token is
|
|
192
|
+
* still a collateral of the manager (it may be absent on an older
|
|
193
|
+
* snapshot, or after it was delisted);
|
|
194
|
+
* 2. the collateral with the biggest index in
|
|
195
|
+
* {@link ICreditManagerContract.collateralTokens} that
|
|
196
|
+
* {@link isStrategyCollateral} accepts with quota required;
|
|
197
|
+
* 3. the biggest-index collateral that {@link isStrategyCollateral} accepts
|
|
198
|
+
* without quota.
|
|
199
|
+
*/
|
|
200
|
+
get strategyTargetCollateral() {
|
|
201
|
+
const legacy = require_sdk_chain_chains.getLegacyStrategyTarget(this.creditManager.address, this.chainId);
|
|
202
|
+
if (legacy && this.creditManager.liquidationThresholds.has(legacy)) return legacy;
|
|
203
|
+
return require_sdk_market_credit_collateralUtils.pickStrategyTargetCollateral(this.creditManager.collateralTokens.map((token) => this.#strategyCollateralProps(token)));
|
|
200
204
|
}
|
|
201
205
|
/**
|
|
202
206
|
* Largest debt a single new position can take on right now: the tightest of
|
|
@@ -209,22 +213,23 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
209
213
|
return require_sdk_utils_bigint_math.BigIntMath.min(debtParams?.available ?? 115792089237316195423570985008687907853269984665640564039457584007913129639935n, pool.availableLiquidity, this.creditFacade.maxDebt);
|
|
210
214
|
}
|
|
211
215
|
/**
|
|
212
|
-
* Display name of
|
|
213
|
-
* `
|
|
214
|
-
*
|
|
215
|
-
* @param collateral - Target collateral of the position.
|
|
216
|
+
* Display name of this suite's leveraged strategy, e.g. `"wstETH / WETH"`,
|
|
217
|
+
* or `undefined` when {@link strategyTargetCollateral} cannot be resolved.
|
|
216
218
|
*/
|
|
217
|
-
strategyName(
|
|
218
|
-
|
|
219
|
+
get strategyName() {
|
|
220
|
+
const collateral = this.strategyTargetCollateral;
|
|
221
|
+
if (!collateral) return;
|
|
222
|
+
return require_sdk_market_strategyName.strategyName(this.tokensMeta.mustGetToken(collateral), this.market.underlyingToken, this.chainId);
|
|
219
223
|
}
|
|
220
224
|
/**
|
|
221
|
-
* Describes
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @param collateral - Target collateral of the position.
|
|
225
|
-
* @throws If the credit manager does not value the collateral.
|
|
225
|
+
* Describes this suite's leveraged strategy as the shared read model does,
|
|
226
|
+
* or `undefined` when {@link strategyTargetCollateral} cannot be resolved or
|
|
227
|
+
* {@link maxBorrowAmount} is `0`.
|
|
226
228
|
*/
|
|
227
|
-
strategyOpportunity(
|
|
229
|
+
strategyOpportunity() {
|
|
230
|
+
if (this.maxBorrowAmount === 0n) return;
|
|
231
|
+
const collateral = this.strategyTargetCollateral;
|
|
232
|
+
if (!collateral) return;
|
|
228
233
|
const { market, creditManager: cm } = this;
|
|
229
234
|
const { pool } = market.pool;
|
|
230
235
|
const oracle = market.priceOracle;
|
|
@@ -237,7 +242,7 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
237
242
|
chainId: this.chainId,
|
|
238
243
|
creditManager: cm.address,
|
|
239
244
|
targetCollateral: this.tokensMeta.mustGetToken(collateral),
|
|
240
|
-
name: this.strategyName
|
|
245
|
+
name: this.strategyName ?? this.market.underlyingToken.symbol,
|
|
241
246
|
curator: market.curator,
|
|
242
247
|
underlyingToken: market.underlyingToken,
|
|
243
248
|
totalBorrow: oracle.toAmount(pool.underlying, borrowed),
|
|
@@ -260,14 +265,14 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
260
265
|
}
|
|
261
266
|
/**
|
|
262
267
|
* {@link strategyOpportunity} plus the data only its detail screen needs.
|
|
263
|
-
*
|
|
264
|
-
* @param collateral - Target collateral of the position.
|
|
265
268
|
*/
|
|
266
|
-
strategyOpportunityDetail(
|
|
269
|
+
strategyOpportunityDetail() {
|
|
270
|
+
const opportunity = this.strategyOpportunity();
|
|
271
|
+
if (!opportunity) return;
|
|
267
272
|
return {
|
|
268
|
-
...
|
|
273
|
+
...opportunity,
|
|
269
274
|
rateCurve: this.market.pool.rateCurve,
|
|
270
|
-
priceFeeds: this.market.priceFeedSummary(
|
|
275
|
+
priceFeeds: this.market.priceFeedSummary(opportunity.targetCollateral.address)
|
|
271
276
|
};
|
|
272
277
|
}
|
|
273
278
|
/**
|
|
@@ -305,7 +310,26 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
305
310
|
* https://github.com/Gearbox-protocol/router-v3/blob/main/contracts/liquidation/AbstractLiquidator.sol#L270
|
|
306
311
|
*/
|
|
307
312
|
#bestTokenOut(ca) {
|
|
308
|
-
|
|
313
|
+
const collateral = require_sdk_market_credit_collateralUtils.dominantCollateral(ca, this.market);
|
|
314
|
+
if (!collateral) throw new Error(`cannot determine tokenOut for partial liquidation of ${this.labelAddress(ca.creditAccount)}: no enabled non-underlying collateral with value`);
|
|
315
|
+
return collateral;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Shared inputs of {@link isStrategyCollateral} for one of this suite's
|
|
319
|
+
* collateral tokens.
|
|
320
|
+
*/
|
|
321
|
+
#strategyCollateralProps(token) {
|
|
322
|
+
const meta = this.tokensMeta.mustGet(token);
|
|
323
|
+
return {
|
|
324
|
+
token,
|
|
325
|
+
underlying: this.creditManager.underlying,
|
|
326
|
+
unwrappedUnderlying: this.market.pool.unwrappedUnderlying,
|
|
327
|
+
liquidationThreshold: this.creditManager.liquidationThresholds.mustGet(token),
|
|
328
|
+
contractType: meta.contractType,
|
|
329
|
+
isExpired: meta.isExpired,
|
|
330
|
+
mainPrice: this.market.priceOracle.mainPrices.get(token)?.price,
|
|
331
|
+
hasActiveQuota: this.market.pool.pqk.hasActiveQuota(token)
|
|
332
|
+
};
|
|
309
333
|
}
|
|
310
334
|
/**
|
|
311
335
|
* Minimum amount of `token` that must be seized when repaying `repaidAmount`
|
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
require("../../constants/math.js");
|
|
3
3
|
require("../../constants/index.js");
|
|
4
4
|
let viem = require("viem");
|
|
5
|
-
//#region src/sdk/market/credit/
|
|
5
|
+
//#region src/sdk/market/credit/collateralUtils.ts
|
|
6
6
|
/**
|
|
7
7
|
* Withdrawal and redemption phantom tokens that can never be acquired as a
|
|
8
8
|
* strategy target. Other `PHANTOM_TOKEN::*` types (Convex, Infrared, staking
|
|
@@ -34,17 +34,64 @@ const RWA_UNDERLYING_PREFIX = "RWA_UNDERLYING::";
|
|
|
34
34
|
* - is not an expired token, e.g. a matured Pendle PT;
|
|
35
35
|
* - has a non-zero main price in the market's oracle — a zero or missing
|
|
36
36
|
* answer (e.g. a failed or zero price feed) means the position cannot be
|
|
37
|
-
* valued
|
|
38
|
-
*
|
|
37
|
+
* valued.
|
|
38
|
+
*
|
|
39
|
+
* Pass `requireQuota` as `true` to also require that the market still accepts
|
|
40
|
+
* quota for the token.
|
|
39
41
|
*/
|
|
40
|
-
function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }) {
|
|
42
|
+
function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }, requireQuota = false) {
|
|
41
43
|
if ((0, viem.isAddressEqual)(token, underlying) || (0, viem.isAddressEqual)(token, unwrappedUnderlying)) return false;
|
|
42
44
|
if (liquidationThreshold <= 0 || liquidationThreshold >= Number(10000n)) return false;
|
|
43
45
|
if (contractType && (NON_STRATEGY_PHANTOM_TOKEN_TYPE_SET.has(contractType) || contractType.startsWith(RWA_UNDERLYING_PREFIX))) return false;
|
|
44
46
|
if (isExpired) return false;
|
|
45
47
|
if (!mainPrice) return false;
|
|
46
|
-
return hasActiveQuota;
|
|
48
|
+
return !requireQuota || hasActiveQuota;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Picks the single strategy target from a credit manager's collateral list.
|
|
52
|
+
*
|
|
53
|
+
* Walks {@link tokens} from the end (biggest index first) and returns the
|
|
54
|
+
* first token that {@link isStrategyCollateral} accepts with quota required.
|
|
55
|
+
* If none has an active quota, returns the biggest-index candidate that
|
|
56
|
+
* qualifies without quota. `undefined` when nothing qualifies. A hardcoded
|
|
57
|
+
* legacy mapping, when present, is applied by the caller before this function.
|
|
58
|
+
**/
|
|
59
|
+
function pickStrategyTargetCollateral(tokens) {
|
|
60
|
+
let quotaless;
|
|
61
|
+
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
62
|
+
const props = tokens[i];
|
|
63
|
+
if (!isStrategyCollateral(props)) continue;
|
|
64
|
+
if (isStrategyCollateral(props, true)) return props.token;
|
|
65
|
+
quotaless ??= props.token;
|
|
66
|
+
}
|
|
67
|
+
return quotaless;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The account's dominant collateral: the most valuable enabled non-underlying
|
|
71
|
+
* token it holds above dust, by USD value.
|
|
72
|
+
*
|
|
73
|
+
* Used to pick the collateral a partial liquidation seizes by default.
|
|
74
|
+
*
|
|
75
|
+
* @param account - Account to inspect.
|
|
76
|
+
* @param market - Market of the account, whose oracle prices the candidates.
|
|
77
|
+
* @returns The dominant collateral, or `undefined` when the account holds
|
|
78
|
+
* nothing but its underlying, or nothing the oracle can price.
|
|
79
|
+
**/
|
|
80
|
+
function dominantCollateral(account, market) {
|
|
81
|
+
let bestValue = 0;
|
|
82
|
+
let dominant;
|
|
83
|
+
for (const t of account.tokens) {
|
|
84
|
+
if ((0, viem.isAddressEqual)(t.token, account.underlying) || (t.mask & account.enabledTokensMask) === 0n || t.balance <= 10n) continue;
|
|
85
|
+
const value = market.priceOracle.safeUsdValue(t.token, t.balance) ?? 0;
|
|
86
|
+
if (value > bestValue) {
|
|
87
|
+
bestValue = value;
|
|
88
|
+
dominant = t.token;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return dominant;
|
|
47
92
|
}
|
|
48
93
|
//#endregion
|
|
49
94
|
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = NON_STRATEGY_PHANTOM_TOKEN_TYPES;
|
|
95
|
+
exports.dominantCollateral = dominantCollateral;
|
|
50
96
|
exports.isStrategyCollateral = isStrategyCollateral;
|
|
97
|
+
exports.pickStrategyTargetCollateral = pickStrategyTargetCollateral;
|
|
@@ -3,8 +3,7 @@ const require_sdk_market_credit_CreditConfiguratorV310Contract = require("./Cred
|
|
|
3
3
|
const require_sdk_market_credit_CreditFacadeV310BaseContract = require("./CreditFacadeV310BaseContract.js");
|
|
4
4
|
const require_sdk_market_credit_CreditFacadeV310Contract = require("./CreditFacadeV310Contract.js");
|
|
5
5
|
const require_sdk_market_credit_CreditManagerV310Contract = require("./CreditManagerV310Contract.js");
|
|
6
|
-
const
|
|
7
|
-
const require_sdk_market_credit_isStrategyCollateral = require("./isStrategyCollateral.js");
|
|
6
|
+
const require_sdk_market_credit_collateralUtils = require("./collateralUtils.js");
|
|
8
7
|
const require_sdk_market_credit_CreditSuite = require("./CreditSuite.js");
|
|
9
8
|
const require_sdk_market_credit_expectedBalanceDeltas = require("./expectedBalanceDeltas.js");
|
|
10
9
|
require("./types.js");
|
|
@@ -13,9 +12,9 @@ exports.CreditFacadeV310BaseContract = require_sdk_market_credit_CreditFacadeV31
|
|
|
13
12
|
exports.CreditFacadeV310Contract = require_sdk_market_credit_CreditFacadeV310Contract.CreditFacadeV310Contract;
|
|
14
13
|
exports.CreditManagerV310Contract = require_sdk_market_credit_CreditManagerV310Contract.CreditManagerV310Contract;
|
|
15
14
|
exports.CreditSuite = require_sdk_market_credit_CreditSuite.CreditSuite;
|
|
16
|
-
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES =
|
|
15
|
+
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_collateralUtils.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
|
|
17
16
|
exports.creditFacadeV310Abi = require_sdk_market_credit_CreditFacadeV310BaseContract.creditFacadeV310Abi;
|
|
18
|
-
exports.dominantCollateral =
|
|
17
|
+
exports.dominantCollateral = require_sdk_market_credit_collateralUtils.dominantCollateral;
|
|
19
18
|
exports.expectedBalanceDeltas = require_sdk_market_credit_expectedBalanceDeltas.expectedBalanceDeltas;
|
|
20
|
-
exports.isStrategyCollateral =
|
|
21
|
-
exports.
|
|
19
|
+
exports.isStrategyCollateral = require_sdk_market_credit_collateralUtils.isStrategyCollateral;
|
|
20
|
+
exports.pickStrategyTargetCollateral = require_sdk_market_credit_collateralUtils.pickStrategyTargetCollateral;
|
|
@@ -90,8 +90,8 @@ const require_sdk_market_credit_CreditFacadeV310BaseContract = require("./credit
|
|
|
90
90
|
const require_sdk_market_credit_CreditFacadeV310Contract = require("./credit/CreditFacadeV310Contract.js");
|
|
91
91
|
const require_sdk_market_math = require("./math.js");
|
|
92
92
|
const require_sdk_market_credit_CreditManagerV310Contract = require("./credit/CreditManagerV310Contract.js");
|
|
93
|
-
const
|
|
94
|
-
const
|
|
93
|
+
const require_sdk_market_strategyName = require("./strategyName.js");
|
|
94
|
+
const require_sdk_market_credit_collateralUtils = require("./credit/collateralUtils.js");
|
|
95
95
|
const require_sdk_market_credit_CreditSuite = require("./credit/CreditSuite.js");
|
|
96
96
|
const require_sdk_market_credit_expectedBalanceDeltas = require("./credit/expectedBalanceDeltas.js");
|
|
97
97
|
require("./credit/index.js");
|
|
@@ -200,7 +200,7 @@ exports.MidasGatewayAdapterContract = require_sdk_market_adapters_contracts_Mida
|
|
|
200
200
|
exports.MidasIssuanceVaultAdapterContract = require_sdk_market_adapters_contracts_MidasIssuanceVaultAdapterContract.MidasIssuanceVaultAdapterContract;
|
|
201
201
|
exports.MidasLiquidatorContract = require_sdk_market_rwa_midas_MidasLiquidatorContract.MidasLiquidatorContract;
|
|
202
202
|
exports.MidasRedemptionVaultAdapterContract = require_sdk_market_adapters_contracts_MidasRedemptionVaultAdapterContract.MidasRedemptionVaultAdapterContract;
|
|
203
|
-
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES =
|
|
203
|
+
exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_collateralUtils.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
|
|
204
204
|
exports.PARTIAL_LIQUIDATION_BUFFER_BPS = require_sdk_market_math.PARTIAL_LIQUIDATION_BUFFER_BPS;
|
|
205
205
|
exports.PHANTOM_TOKEN_MIDAS_REDEMPTION = require_sdk_market_rwa_midas_constants.PHANTOM_TOKEN_MIDAS_REDEMPTION;
|
|
206
206
|
exports.PHANTOM_TOKEN_SECURITIZE_REDEMPTION = require_sdk_market_rwa_securitize_constants.PHANTOM_TOKEN_SECURITIZE_REDEMPTION;
|
|
@@ -257,7 +257,7 @@ exports.createZapper = require_sdk_market_zapper_createZapper.createZapper;
|
|
|
257
257
|
exports.creditFacadeV310Abi = require_sdk_market_credit_CreditFacadeV310BaseContract.creditFacadeV310Abi;
|
|
258
258
|
exports.curveAddLiquidityFromTransfers = require_sdk_market_adapters_transferHelpers.curveAddLiquidityFromTransfers;
|
|
259
259
|
exports.curveRemoveLiquidityFromTransfers = require_sdk_market_adapters_transferHelpers.curveRemoveLiquidityFromTransfers;
|
|
260
|
-
exports.dominantCollateral =
|
|
260
|
+
exports.dominantCollateral = require_sdk_market_credit_collateralUtils.dominantCollateral;
|
|
261
261
|
exports.erc4626ReferralAdapterAbi = require_sdk_market_adapters_abi_adapters_erc4626ReferralAdapter.erc4626ReferralAdapterAbi;
|
|
262
262
|
exports.expectedBalanceDeltas = require_sdk_market_credit_expectedBalanceDeltas.expectedBalanceDeltas;
|
|
263
263
|
exports.fetchRedstonePayloads = require_sdk_market_pricefeeds_updates_fetchRedstonePayloads.fetchRedstonePayloads;
|
|
@@ -338,21 +338,22 @@ exports.iVelodromeV2RouterAbi = require_sdk_market_adapters_abi_targetContractAb
|
|
|
338
338
|
exports.iVelodromeV2RouterAdapterAbi = require_sdk_market_adapters_abi_adapters_iVelodromeV2RouterAdapter.iVelodromeV2RouterAdapterAbi;
|
|
339
339
|
exports.isLPPriceFeed = require_sdk_market_pricefeeds_AbstractLPPriceFeed.isLPPriceFeed;
|
|
340
340
|
exports.isRWAFactory = require_sdk_market_rwa_types.isRWAFactory;
|
|
341
|
-
exports.isStrategyCollateral =
|
|
341
|
+
exports.isStrategyCollateral = require_sdk_market_credit_collateralUtils.isStrategyCollateral;
|
|
342
342
|
exports.isUpdatablePriceFeed = require_sdk_market_pricefeeds_isUpdatablePriceFeed.isUpdatablePriceFeed;
|
|
343
343
|
exports.iwstETHAbi = require_sdk_market_adapters_abi_targetContractAbi.iwstETHAbi;
|
|
344
344
|
exports.iwstEthv1AdapterAbi = require_sdk_market_adapters_abi_adapters_iwstEthv1Adapter.iwstEthv1AdapterAbi;
|
|
345
345
|
exports.lidoV1_WETHGatewayAbi = require_sdk_market_adapters_abi_targetContractAbi.lidoV1_WETHGatewayAbi;
|
|
346
346
|
exports.mellowDvvAdapterAbi = require_sdk_market_adapters_abi_adapters_mellowDvvAdapter.mellowDvvAdapterAbi;
|
|
347
347
|
exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
|
|
348
|
-
exports.mustGetDominantCollateral = require_sdk_market_credit_dominantCollateral.mustGetDominantCollateral;
|
|
349
348
|
exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
|
|
350
349
|
exports.optimalRepaidAmount = require_sdk_market_math.optimalRepaidAmount;
|
|
351
350
|
exports.parseAdapterAction = require_sdk_market_adapters_abi_utils.parseAdapterAction;
|
|
352
351
|
exports.parseAdapterDeployParams = require_sdk_market_adapters_abi_utils.parseAdapterDeployParams;
|
|
353
352
|
exports.parsePosNegAmount = require_sdk_market_adapters_transferHelpers.parsePosNegAmount;
|
|
353
|
+
exports.pickStrategyTargetCollateral = require_sdk_market_credit_collateralUtils.pickStrategyTargetCollateral;
|
|
354
354
|
exports.rayToBps = require_sdk_market_math.rayToBps;
|
|
355
355
|
exports.rewardsFromTransfers = require_sdk_market_adapters_transferHelpers.rewardsFromTransfers;
|
|
356
|
+
exports.strategyName = require_sdk_market_strategyName.strategyName;
|
|
356
357
|
exports.swapFromTransfers = require_sdk_market_adapters_transferHelpers.swapFromTransfers;
|
|
357
358
|
exports.toNetTransfers = require_sdk_market_adapters_transferHelpers.toNetTransfers;
|
|
358
359
|
exports.usdToNumber = require_sdk_market_math.usdToNumber;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_chain_chains = require("../chain/chains.js");
|
|
3
|
+
//#region src/sdk/market/strategyName.ts
|
|
4
|
+
/**
|
|
5
|
+
* Display name of a leveraged strategy: the target collateral over the
|
|
6
|
+
* borrowed underlying, e.g. `"wstETH / WETH"`.
|
|
7
|
+
*
|
|
8
|
+
* A curated pretty name from {@link getTokenPrettyName} wins over the target's
|
|
9
|
+
* ticker when one is configured.
|
|
10
|
+
*
|
|
11
|
+
* @param target - Collateral the position is built around.
|
|
12
|
+
* @param underlying - Token the position borrows.
|
|
13
|
+
* @param network - Chain id or network type label of the market.
|
|
14
|
+
**/
|
|
15
|
+
function strategyName(target, underlying, network) {
|
|
16
|
+
return `${require_sdk_chain_chains.getTokenPrettyName(target.address, network) ?? target.symbol} / ${underlying.symbol}`;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.strategyName = strategyName;
|
|
@@ -37,11 +37,13 @@ var OpportunitiesService = class extends require_sdk_base_SDKConstruct.SDKConstr
|
|
|
37
37
|
* A single strategy opportunity plus the rate curve of the pool it borrows
|
|
38
38
|
* from and the price feeds its liquidation price depends on.
|
|
39
39
|
*
|
|
40
|
-
* @throws If the credit manager is unknown, or does not
|
|
41
|
-
*
|
|
40
|
+
* @throws If the credit manager is unknown, or does not currently offer a
|
|
41
|
+
* strategy.
|
|
42
42
|
**/
|
|
43
43
|
async getStrategy(key) {
|
|
44
|
-
|
|
44
|
+
const detail = this.sdk.marketRegister.findCreditManager(key.creditManager).strategyOpportunityDetail();
|
|
45
|
+
if (!detail) throw new Error(`credit manager ${key.creditManager} does not currently offer a strategy`);
|
|
46
|
+
return detail;
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
//#endregion
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
|
|
3
|
+
const require_sdk_chain_chains = require("../chain/chains.js");
|
|
3
4
|
require("../constants/math.js");
|
|
4
5
|
require("../constants/index.js");
|
|
5
|
-
const require_sdk_utils_hex = require("../utils/hex.js");
|
|
6
6
|
require("../utils/index.js");
|
|
7
7
|
const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
8
8
|
require("../base/index.js");
|
|
9
9
|
const require_sdk_market_math = require("../market/math.js");
|
|
10
|
-
const
|
|
10
|
+
const require_sdk_market_strategyName = require("../market/strategyName.js");
|
|
11
11
|
const require_model_filters = require("../../model/filters.js");
|
|
12
12
|
const require_model_positions = require("../../model/positions.js");
|
|
13
13
|
require("../../model/index.js");
|
|
14
|
-
require("../market/index.js");
|
|
15
14
|
const require_sdk_positions_calcBorrowRate = require("./calcBorrowRate.js");
|
|
16
15
|
const require_sdk_positions_calcHealthFactor = require("./calcHealthFactor.js");
|
|
17
16
|
const require_sdk_positions_calcLiquidationPrice = require("./calcLiquidationPrice.js");
|
|
@@ -150,11 +149,7 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
|
|
|
150
149
|
const { pool } = market.pool;
|
|
151
150
|
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
152
151
|
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
153
|
-
|
|
154
|
-
if (collateral) {
|
|
155
|
-
const source = this.sdk.withdrawalCompressor?.getWithdrawalSourceToken(collateral);
|
|
156
|
-
if (source) collateral = require_sdk_utils_hex.hexEq(source, market.underlying) ? void 0 : source;
|
|
157
|
-
}
|
|
152
|
+
const target = require_sdk_chain_chains.getAccountTargetCollateral(ca.creditAccount, this.sdk.chainId) ?? suite.strategyTargetCollateral;
|
|
158
153
|
const snapshot = require_sdk_positions_types.accountSnapshotFromCreditAccountData(ca);
|
|
159
154
|
const borrowRate = this.borrowRate(snapshot);
|
|
160
155
|
const timeToLiquidation = this.timeToLiquidation(snapshot);
|
|
@@ -164,8 +159,8 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
|
|
|
164
159
|
chainId: this.sdk.chainId,
|
|
165
160
|
creditManager: ca.creditManager,
|
|
166
161
|
creditAccount: ca.creditAccount,
|
|
167
|
-
name:
|
|
168
|
-
targetCollateral:
|
|
162
|
+
name: target ? require_sdk_market_strategyName.strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
|
|
163
|
+
targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
|
|
169
164
|
leverage: require_sdk_market_math.calcPositionLeverage(ca.totalValue, totalDebtValue),
|
|
170
165
|
borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
171
166
|
totalDebt: {
|
|
@@ -8,8 +8,8 @@ const require_sdk_utils_bigint_math = require("./bigint-math.js");
|
|
|
8
8
|
const require_sdk_utils_bytes32ToString = require("./bytes32ToString.js");
|
|
9
9
|
const require_sdk_utils_childLogger = require("./childLogger.js");
|
|
10
10
|
const require_sdk_utils_createRawTx = require("./createRawTx.js");
|
|
11
|
-
const require_sdk_utils_mappers = require("./mappers.js");
|
|
12
11
|
const require_sdk_utils_etherscan = require("./etherscan.js");
|
|
12
|
+
const require_sdk_utils_mappers = require("./mappers.js");
|
|
13
13
|
const require_sdk_utils_isDust = require("./isDust.js");
|
|
14
14
|
const require_sdk_utils_filterDust = require("./filterDust.js");
|
|
15
15
|
const require_sdk_utils_formatter = require("./formatter.js");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TypedObjectUtils } from "../../sdk/utils/mappers.js";
|
|
2
1
|
import { PERCENTAGE_DECIMALS } from "../../sdk/constants/math.js";
|
|
2
|
+
import { TypedObjectUtils } from "../../sdk/utils/mappers.js";
|
|
3
3
|
import { toBigInt } from "../../sdk/utils/formatter.js";
|
|
4
4
|
//#region src/common-utils/charts/credit-session.ts
|
|
5
5
|
const CREDIT_SESSION_STATUS_BY_ID = {
|
|
@@ -16,17 +16,17 @@ function poolOpportunityId(chainId, pool) {
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
|
-
* strategyOpportunityId(1, "0x3eb9..."
|
|
19
|
+
* strategyOpportunityId(1, "0x3eb9...") // "1:0x3eb9..."
|
|
20
20
|
* ```
|
|
21
21
|
**/
|
|
22
|
-
function strategyOpportunityId(chainId, creditManager
|
|
23
|
-
return `${chainId}:${creditManager.toLowerCase()}
|
|
22
|
+
function strategyOpportunityId(chainId, creditManager) {
|
|
23
|
+
return `${chainId}:${creditManager.toLowerCase()}`;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Canonical id of any opportunity, dispatching on {@link Opportunity.kind}.
|
|
27
27
|
**/
|
|
28
28
|
function opportunityId(opportunity) {
|
|
29
|
-
return opportunity.kind === "pool" ? poolOpportunityId(opportunity.chainId, opportunity.pool) : strategyOpportunityId(opportunity.chainId, opportunity.creditManager
|
|
29
|
+
return opportunity.kind === "pool" ? poolOpportunityId(opportunity.chainId, opportunity.pool) : strategyOpportunityId(opportunity.chainId, opportunity.creditManager);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Whether an opportunity satisfies every condition of a filter.
|
|
@@ -232,8 +232,7 @@ const poolOpportunityKeySchema = z.object({
|
|
|
232
232
|
**/
|
|
233
233
|
const strategyOpportunityKeySchema = z.object({
|
|
234
234
|
chainId: chainIdSchema,
|
|
235
|
-
creditManager: ZodAddress()
|
|
236
|
-
targetCollateral: ZodAddress()
|
|
235
|
+
creditManager: ZodAddress()
|
|
237
236
|
});
|
|
238
237
|
/**
|
|
239
238
|
* {@link OpportunityKey}
|