@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.
Files changed (82) hide show
  1. package/dist/cjs/common-utils/charts/credit-session.js +1 -1
  2. package/dist/cjs/model/opportunities.js +4 -4
  3. package/dist/cjs/model/opportunities.schema.js +1 -2
  4. package/dist/cjs/new-sdk/prepare/PrepareApi.js +14 -10
  5. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
  6. package/dist/cjs/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
  7. package/dist/cjs/sdk/OnchainSDK.js +2 -2
  8. package/dist/cjs/sdk/accounts/intents/testing/market.js +2 -1
  9. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +1 -0
  10. package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +2 -2
  11. package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +1 -1
  12. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +2 -2
  13. package/dist/cjs/sdk/chain/chains.js +140 -51
  14. package/dist/cjs/sdk/chain/index.js +3 -0
  15. package/dist/cjs/sdk/constants/networks.js +1 -1
  16. package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +1 -1
  17. package/dist/cjs/sdk/index.js +11 -7
  18. package/dist/cjs/sdk/market/MarketSuite.js +8 -39
  19. package/dist/cjs/sdk/market/credit/CreditSuite.js +61 -37
  20. package/dist/cjs/sdk/market/credit/{isStrategyCollateral.js → collateralUtils.js} +52 -5
  21. package/dist/cjs/sdk/market/credit/index.js +5 -6
  22. package/dist/cjs/sdk/market/index.js +7 -6
  23. package/dist/cjs/sdk/market/strategyName.js +19 -0
  24. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +5 -3
  25. package/dist/cjs/sdk/positions/PositionsService.js +5 -10
  26. package/dist/cjs/sdk/utils/index.js +1 -1
  27. package/dist/esm/common-utils/charts/credit-session.js +1 -1
  28. package/dist/esm/model/opportunities.js +4 -4
  29. package/dist/esm/model/opportunities.schema.js +1 -2
  30. package/dist/esm/new-sdk/prepare/PrepareApi.js +14 -10
  31. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
  32. package/dist/esm/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
  33. package/dist/esm/sdk/OnchainSDK.js +2 -2
  34. package/dist/esm/sdk/accounts/intents/testing/market.js +2 -1
  35. package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +1 -0
  36. package/dist/esm/sdk/accounts/intents/utils/pick-token.js +1 -1
  37. package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +1 -1
  38. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  39. package/dist/esm/sdk/chain/chains.js +139 -53
  40. package/dist/esm/sdk/chain/index.js +2 -2
  41. package/dist/esm/sdk/constants/networks.js +1 -1
  42. package/dist/esm/sdk/core/AbstractAddressProviderContract.js +1 -1
  43. package/dist/esm/sdk/index.js +5 -5
  44. package/dist/esm/sdk/market/MarketSuite.js +8 -39
  45. package/dist/esm/sdk/market/credit/CreditSuite.js +62 -38
  46. package/dist/esm/sdk/market/credit/{isStrategyCollateral.js → collateralUtils.js} +51 -6
  47. package/dist/esm/sdk/market/credit/index.js +2 -3
  48. package/dist/esm/sdk/market/index.js +3 -3
  49. package/dist/esm/sdk/market/strategyName.js +18 -0
  50. package/dist/esm/sdk/opportunities/OpportunitiesService.js +5 -3
  51. package/dist/esm/sdk/positions/PositionsService.js +5 -10
  52. package/dist/esm/sdk/utils/index.js +1 -1
  53. package/dist/types/model/index.d.ts +1 -1
  54. package/dist/types/model/opportunities.d.ts +8 -15
  55. package/dist/types/model/opportunities.schema.d.ts +0 -2
  56. package/dist/types/model/positions.d.ts +2 -10
  57. package/dist/types/new-sdk/errors/SourceChainMismatchError.d.ts +1 -1
  58. package/dist/types/new-sdk/positions/mergePositionList.d.ts +3 -2
  59. package/dist/types/new-sdk/types.d.ts +1 -1
  60. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +5 -0
  61. package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
  62. package/dist/types/sdk/base/MultichainConstruct.d.ts +1 -1
  63. package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
  64. package/dist/types/sdk/chain/chains.d.ts +51 -7
  65. package/dist/types/sdk/chain/index.d.ts +2 -2
  66. package/dist/types/sdk/index.d.ts +7 -7
  67. package/dist/types/sdk/market/MarketRegister.d.ts +1 -1
  68. package/dist/types/sdk/market/MarketSuite.d.ts +4 -34
  69. package/dist/types/sdk/market/ZapperRegister.d.ts +1 -1
  70. package/dist/types/sdk/market/credit/CreditSuite.d.ts +23 -14
  71. package/dist/types/sdk/market/credit/{isStrategyCollateral.d.ts → collateralUtils.d.ts} +36 -8
  72. package/dist/types/sdk/market/credit/index.d.ts +2 -3
  73. package/dist/types/sdk/market/index.d.ts +4 -4
  74. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +1 -1
  75. package/dist/types/sdk/market/oracle/types.d.ts +1 -1
  76. package/dist/types/sdk/market/strategyName.d.ts +18 -0
  77. package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +2 -2
  78. package/dist/types/sdk/positions/types.d.ts +1 -1
  79. package/package.json +1 -1
  80. package/dist/cjs/sdk/market/credit/dominantCollateral.js +0 -47
  81. package/dist/esm/sdk/market/credit/dominantCollateral.js +0 -45
  82. package/dist/types/sdk/market/credit/dominantCollateral.d.ts +0 -29
@@ -16,7 +16,6 @@ import { createPriceOracle } from "./oracle/createPriceOracle.js";
16
16
  import "./oracle/index.js";
17
17
  import { PoolSuite } from "./pool/PoolSuite.js";
18
18
  import "./pool/index.js";
19
- import { isAddressEqual } from "viem";
20
19
  //#region src/sdk/market/MarketSuite.ts
21
20
  /**
22
21
  * Aggregates all SDK wrappers that make up one Gearbox market.
@@ -136,22 +135,12 @@ var MarketSuite = class extends SDKConstruct {
136
135
  return this.configurator.curator;
137
136
  }
138
137
  /**
139
- * Every `(credit suite, collateral)` pair of this market that qualifies as a
140
- * leveraged position.
141
- */
142
- get strategies() {
143
- return this.creditManagers.flatMap((suite) => suite.strategyCollaterals.map((collateral) => ({
144
- suite,
145
- collateral
146
- })));
147
- }
148
- /**
149
138
  * Tokens a position can actually be built on in this market, deduplicated
150
139
  * across its credit suites.
151
140
  */
152
141
  get collateralTokens() {
153
142
  const seen = new AddressMap(void 0, "collateralTokens");
154
- for (const { collateral } of this.strategies) seen.upsert(collateral, this.tokensMeta.mustGetToken(collateral));
143
+ for (const suite of this.creditManagers) for (const collateral of suite.strategyCollaterals) seen.upsert(collateral, this.tokensMeta.mustGetToken(collateral));
155
144
  return seen.values();
156
145
  }
157
146
  /**
@@ -159,7 +148,7 @@ var MarketSuite = class extends SDKConstruct {
159
148
  * token. Read from a hardcoded per-chain list rather than from the chain.
160
149
  */
161
150
  get rwa() {
162
- return this.strategies.some(({ collateral }) => isRWAToken(collateral, this.sdk.networkType));
151
+ return this.collateralTokens.some((token) => isRWAToken(token.address, this.sdk.networkType));
163
152
  }
164
153
  /**
165
154
  * Whether this market's pool is being wound down and should no longer be
@@ -194,8 +183,8 @@ var MarketSuite = class extends SDKConstruct {
194
183
  return this.priceOracle.priceFeedSummary(this.underlying, collateral);
195
184
  }
196
185
  /**
197
- * Every opportunity this market offers: its pool, plus one row per
198
- * `(credit manager, target collateral)` pair.
186
+ * Every opportunity this market offers: its pool, plus one row per credit
187
+ * manager that qualifies as a strategy.
199
188
  *
200
189
  * @param filter - Optional narrowing. A filter naming a kind skips building
201
190
  * the other kind entirely; every built row is then checked in full by
@@ -206,7 +195,10 @@ var MarketSuite = class extends SDKConstruct {
206
195
  const rows = [];
207
196
  const kind = filter?.kind;
208
197
  if (!isFilterSet(kind) || kind === "pool") rows.push(this.poolOpportunity());
209
- if (!isFilterSet(kind) || kind === "strategy") for (const { suite, collateral } of this.strategies) rows.push(suite.strategyOpportunity(collateral));
198
+ if (!isFilterSet(kind) || kind === "strategy") for (const suite of this.creditManagers) {
199
+ const opportunity = suite.strategyOpportunity();
200
+ if (opportunity) rows.push(opportunity);
201
+ }
210
202
  return rows.filter((row) => matchesOpportunityFilter(row, filter));
211
203
  }
212
204
  /**
@@ -245,29 +237,6 @@ var MarketSuite = class extends SDKConstruct {
245
237
  };
246
238
  }
247
239
  /**
248
- * Resolves a strategy of this market by its two halves.
249
- *
250
- * @param creditManager - Credit manager the position is opened in.
251
- * @param collateral - Target collateral of the position.
252
- * @throws If this market has no such credit manager, or if that manager does
253
- * not accept the collateral as a strategy.
254
- */
255
- mustFindStrategy(creditManager, collateral) {
256
- const strategy = this.strategies.find((s) => isAddressEqual(s.suite.creditManager.address, creditManager) && isAddressEqual(s.collateral, collateral));
257
- if (!strategy) throw new Error(`${this.labelAddress(collateral)} is not a strategy collateral of credit manager ${this.labelAddress(creditManager)}`);
258
- return strategy;
259
- }
260
- /**
261
- * Detailed view of one leveraged position of this market.
262
- *
263
- * @param creditManager - Credit manager the position is opened in.
264
- * @param collateral - Target collateral of the position.
265
- * @throws If this market has no such strategy, see {@link mustFindStrategy}.
266
- */
267
- strategyOpportunityDetail(creditManager, collateral) {
268
- return this.mustFindStrategy(creditManager, collateral).suite.strategyOpportunityDetail(collateral);
269
- }
270
- /**
271
240
  * Whether any child contract wrapper has observed events that require a
272
241
  * market resync.
273
242
  */
@@ -1,17 +1,17 @@
1
1
  import { AddressMap } from "../../utils/AddressMap.js";
2
2
  import { BigIntMath } from "../../utils/bigint-math.js";
3
- import { isSunsetStrategy } from "../../chain/chains.js";
3
+ import { getLegacyStrategyTarget, isSunsetStrategy } from "../../chain/chains.js";
4
4
  import { PERCENTAGE_FACTOR, RAY } from "../../constants/math.js";
5
5
  import "../../constants/index.js";
6
6
  import "../../utils/index.js";
7
7
  import { SDKConstruct } from "../../base/SDKConstruct.js";
8
8
  import "../../base/index.js";
9
9
  import { calcAdditionalBorrowApy, calcBorrowApy, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount } from "../math.js";
10
+ import { strategyName } from "../strategyName.js";
11
+ import { dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral } from "./collateralUtils.js";
10
12
  import createCreditConfigurator from "./createCreditConfigurator.js";
11
13
  import createCreditFacade from "./createCreditFacade.js";
12
14
  import createCreditManager from "./createCreditManager.js";
13
- import { mustGetDominantCollateral } from "./dominantCollateral.js";
14
- import { isStrategyCollateral } from "./isStrategyCollateral.js";
15
15
  //#region src/sdk/market/credit/CreditSuite.ts
16
16
  /**
17
17
  * SDK aggregate for one credit-manager branch inside a market.
@@ -180,22 +180,26 @@ var CreditSuite = class extends SDKConstruct {
180
180
  */
181
181
  get strategyCollaterals() {
182
182
  if (this.maxBorrowAmount === 0n) return [];
183
- const { pqk, unwrappedUnderlying } = this.market.pool;
184
- const { mainPrices } = this.market.priceOracle;
185
- const { tokensMeta, creditManager } = this;
186
- return creditManager.collateralTokens.filter((token) => {
187
- const meta = tokensMeta.mustGet(token);
188
- return isStrategyCollateral({
189
- token,
190
- underlying: creditManager.underlying,
191
- unwrappedUnderlying,
192
- liquidationThreshold: creditManager.liquidationThresholds.mustGet(token),
193
- contractType: meta.contractType,
194
- isExpired: meta.isExpired,
195
- mainPrice: mainPrices.get(token)?.price,
196
- hasActiveQuota: pqk.hasActiveQuota(token)
197
- });
198
- });
183
+ return this.creditManager.collateralTokens.filter((token) => isStrategyCollateral(this.#strategyCollateralProps(token), true));
184
+ }
185
+ /**
186
+ * The single target collateral of this suite's strategy, or `undefined` when
187
+ * none can be resolved.
188
+ *
189
+ * Resolution, in order:
190
+ * 1. a hardcoded legacy mapping for this credit manager, when that token is
191
+ * still a collateral of the manager (it may be absent on an older
192
+ * snapshot, or after it was delisted);
193
+ * 2. the collateral with the biggest index in
194
+ * {@link ICreditManagerContract.collateralTokens} that
195
+ * {@link isStrategyCollateral} accepts with quota required;
196
+ * 3. the biggest-index collateral that {@link isStrategyCollateral} accepts
197
+ * without quota.
198
+ */
199
+ get strategyTargetCollateral() {
200
+ const legacy = getLegacyStrategyTarget(this.creditManager.address, this.chainId);
201
+ if (legacy && this.creditManager.liquidationThresholds.has(legacy)) return legacy;
202
+ return pickStrategyTargetCollateral(this.creditManager.collateralTokens.map((token) => this.#strategyCollateralProps(token)));
199
203
  }
200
204
  /**
201
205
  * Largest debt a single new position can take on right now: the tightest of
@@ -208,22 +212,23 @@ var CreditSuite = class extends SDKConstruct {
208
212
  return BigIntMath.min(debtParams?.available ?? 115792089237316195423570985008687907853269984665640564039457584007913129639935n, pool.availableLiquidity, this.creditFacade.maxDebt);
209
213
  }
210
214
  /**
211
- * Display name of a leveraged position built on one collateral token, e.g.
212
- * `"wstETH / WETH"`.
213
- *
214
- * @param collateral - Target collateral of the position.
215
+ * Display name of this suite's leveraged strategy, e.g. `"wstETH / WETH"`,
216
+ * or `undefined` when {@link strategyTargetCollateral} cannot be resolved.
215
217
  */
216
- strategyName(collateral) {
217
- return `${this.tokensMeta.symbol(collateral)} / ${this.market.underlyingToken.symbol}`;
218
+ get strategyName() {
219
+ const collateral = this.strategyTargetCollateral;
220
+ if (!collateral) return;
221
+ return strategyName(this.tokensMeta.mustGetToken(collateral), this.market.underlyingToken, this.chainId);
218
222
  }
219
223
  /**
220
- * Describes a leveraged position built on one collateral token as the shared
221
- * read model does.
222
- *
223
- * @param collateral - Target collateral of the position.
224
- * @throws If the credit manager does not value the collateral.
224
+ * Describes this suite's leveraged strategy as the shared read model does,
225
+ * or `undefined` when {@link strategyTargetCollateral} cannot be resolved or
226
+ * {@link maxBorrowAmount} is `0`.
225
227
  */
226
- strategyOpportunity(collateral) {
228
+ strategyOpportunity() {
229
+ if (this.maxBorrowAmount === 0n) return;
230
+ const collateral = this.strategyTargetCollateral;
231
+ if (!collateral) return;
227
232
  const { market, creditManager: cm } = this;
228
233
  const { pool } = market.pool;
229
234
  const oracle = market.priceOracle;
@@ -236,7 +241,7 @@ var CreditSuite = class extends SDKConstruct {
236
241
  chainId: this.chainId,
237
242
  creditManager: cm.address,
238
243
  targetCollateral: this.tokensMeta.mustGetToken(collateral),
239
- name: this.strategyName(collateral),
244
+ name: this.strategyName ?? this.market.underlyingToken.symbol,
240
245
  curator: market.curator,
241
246
  underlyingToken: market.underlyingToken,
242
247
  totalBorrow: oracle.toAmount(pool.underlying, borrowed),
@@ -259,14 +264,14 @@ var CreditSuite = class extends SDKConstruct {
259
264
  }
260
265
  /**
261
266
  * {@link strategyOpportunity} plus the data only its detail screen needs.
262
- *
263
- * @param collateral - Target collateral of the position.
264
267
  */
265
- strategyOpportunityDetail(collateral) {
268
+ strategyOpportunityDetail() {
269
+ const opportunity = this.strategyOpportunity();
270
+ if (!opportunity) return;
266
271
  return {
267
- ...this.strategyOpportunity(collateral),
272
+ ...opportunity,
268
273
  rateCurve: this.market.pool.rateCurve,
269
- priceFeeds: this.market.priceFeedSummary(collateral)
274
+ priceFeeds: this.market.priceFeedSummary(opportunity.targetCollateral.address)
270
275
  };
271
276
  }
272
277
  /**
@@ -304,7 +309,26 @@ var CreditSuite = class extends SDKConstruct {
304
309
  * https://github.com/Gearbox-protocol/router-v3/blob/main/contracts/liquidation/AbstractLiquidator.sol#L270
305
310
  */
306
311
  #bestTokenOut(ca) {
307
- return mustGetDominantCollateral(ca, this.market);
312
+ const collateral = dominantCollateral(ca, this.market);
313
+ if (!collateral) throw new Error(`cannot determine tokenOut for partial liquidation of ${this.labelAddress(ca.creditAccount)}: no enabled non-underlying collateral with value`);
314
+ return collateral;
315
+ }
316
+ /**
317
+ * Shared inputs of {@link isStrategyCollateral} for one of this suite's
318
+ * collateral tokens.
319
+ */
320
+ #strategyCollateralProps(token) {
321
+ const meta = this.tokensMeta.mustGet(token);
322
+ return {
323
+ token,
324
+ underlying: this.creditManager.underlying,
325
+ unwrappedUnderlying: this.market.pool.unwrappedUnderlying,
326
+ liquidationThreshold: this.creditManager.liquidationThresholds.mustGet(token),
327
+ contractType: meta.contractType,
328
+ isExpired: meta.isExpired,
329
+ mainPrice: this.market.priceOracle.mainPrices.get(token)?.price,
330
+ hasActiveQuota: this.market.pool.pqk.hasActiveQuota(token)
331
+ };
308
332
  }
309
333
  /**
310
334
  * Minimum amount of `token` that must be seized when repaying `repaidAmount`
@@ -1,7 +1,7 @@
1
1
  import "../../constants/math.js";
2
2
  import "../../constants/index.js";
3
3
  import { isAddressEqual } from "viem";
4
- //#region src/sdk/market/credit/isStrategyCollateral.ts
4
+ //#region src/sdk/market/credit/collateralUtils.ts
5
5
  /**
6
6
  * Withdrawal and redemption phantom tokens that can never be acquired as a
7
7
  * strategy target. Other `PHANTOM_TOKEN::*` types (Convex, Infrared, staking
@@ -33,16 +33,61 @@ const RWA_UNDERLYING_PREFIX = "RWA_UNDERLYING::";
33
33
  * - is not an expired token, e.g. a matured Pendle PT;
34
34
  * - has a non-zero main price in the market's oracle — a zero or missing
35
35
  * answer (e.g. a failed or zero price feed) means the position cannot be
36
- * valued;
37
- * - the market still accepts quota for.
36
+ * valued.
37
+ *
38
+ * Pass `requireQuota` as `true` to also require that the market still accepts
39
+ * quota for the token.
38
40
  */
39
- function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }) {
41
+ function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }, requireQuota = false) {
40
42
  if (isAddressEqual(token, underlying) || isAddressEqual(token, unwrappedUnderlying)) return false;
41
43
  if (liquidationThreshold <= 0 || liquidationThreshold >= Number(10000n)) return false;
42
44
  if (contractType && (NON_STRATEGY_PHANTOM_TOKEN_TYPE_SET.has(contractType) || contractType.startsWith(RWA_UNDERLYING_PREFIX))) return false;
43
45
  if (isExpired) return false;
44
46
  if (!mainPrice) return false;
45
- return hasActiveQuota;
47
+ return !requireQuota || hasActiveQuota;
48
+ }
49
+ /**
50
+ * Picks the single strategy target from a credit manager's collateral list.
51
+ *
52
+ * Walks {@link tokens} from the end (biggest index first) and returns the
53
+ * first token that {@link isStrategyCollateral} accepts with quota required.
54
+ * If none has an active quota, returns the biggest-index candidate that
55
+ * qualifies without quota. `undefined` when nothing qualifies. A hardcoded
56
+ * legacy mapping, when present, is applied by the caller before this function.
57
+ **/
58
+ function pickStrategyTargetCollateral(tokens) {
59
+ let quotaless;
60
+ for (let i = tokens.length - 1; i >= 0; i--) {
61
+ const props = tokens[i];
62
+ if (!isStrategyCollateral(props)) continue;
63
+ if (isStrategyCollateral(props, true)) return props.token;
64
+ quotaless ??= props.token;
65
+ }
66
+ return quotaless;
67
+ }
68
+ /**
69
+ * The account's dominant collateral: the most valuable enabled non-underlying
70
+ * token it holds above dust, by USD value.
71
+ *
72
+ * Used to pick the collateral a partial liquidation seizes by default.
73
+ *
74
+ * @param account - Account to inspect.
75
+ * @param market - Market of the account, whose oracle prices the candidates.
76
+ * @returns The dominant collateral, or `undefined` when the account holds
77
+ * nothing but its underlying, or nothing the oracle can price.
78
+ **/
79
+ function dominantCollateral(account, market) {
80
+ let bestValue = 0;
81
+ let dominant;
82
+ for (const t of account.tokens) {
83
+ if (isAddressEqual(t.token, account.underlying) || (t.mask & account.enabledTokensMask) === 0n || t.balance <= 10n) continue;
84
+ const value = market.priceOracle.safeUsdValue(t.token, t.balance) ?? 0;
85
+ if (value > bestValue) {
86
+ bestValue = value;
87
+ dominant = t.token;
88
+ }
89
+ }
90
+ return dominant;
46
91
  }
47
92
  //#endregion
48
- export { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral };
93
+ export { NON_STRATEGY_PHANTOM_TOKEN_TYPES, dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral };
@@ -2,9 +2,8 @@ import { CreditConfiguratorV310Contract } from "./CreditConfiguratorV310Contract
2
2
  import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./CreditFacadeV310BaseContract.js";
3
3
  import { CreditFacadeV310Contract } from "./CreditFacadeV310Contract.js";
4
4
  import { CreditManagerV310Contract } from "./CreditManagerV310Contract.js";
5
- import { dominantCollateral, mustGetDominantCollateral } from "./dominantCollateral.js";
6
- import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./isStrategyCollateral.js";
5
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral } from "./collateralUtils.js";
7
6
  import { CreditSuite } from "./CreditSuite.js";
8
7
  import { expectedBalanceDeltas } from "./expectedBalanceDeltas.js";
9
8
  import "./types.js";
10
- export { CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, NON_STRATEGY_PHANTOM_TOKEN_TYPES, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, isStrategyCollateral, mustGetDominantCollateral };
9
+ export { CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, NON_STRATEGY_PHANTOM_TOKEN_TYPES, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, isStrategyCollateral, pickStrategyTargetCollateral };
@@ -89,8 +89,8 @@ import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./cred
89
89
  import { CreditFacadeV310Contract } from "./credit/CreditFacadeV310Contract.js";
90
90
  import { MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./math.js";
91
91
  import { CreditManagerV310Contract } from "./credit/CreditManagerV310Contract.js";
92
- import { dominantCollateral, mustGetDominantCollateral } from "./credit/dominantCollateral.js";
93
- import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./credit/isStrategyCollateral.js";
92
+ import { strategyName } from "./strategyName.js";
93
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral } from "./credit/collateralUtils.js";
94
94
  import { CreditSuite } from "./credit/CreditSuite.js";
95
95
  import { expectedBalanceDeltas } from "./credit/expectedBalanceDeltas.js";
96
96
  import "./credit/index.js";
@@ -144,4 +144,4 @@ import { RWARegistry } from "./rwa/RWARegistry.js";
144
144
  import { RWA_FACTORY_TYPES, isRWAFactory } from "./rwa/types.js";
145
145
  import "./rwa/index.js";
146
146
  import "./types.js";
147
- export { AbstractAdapterContract, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AccountMigratorAdapterContract, AdapterType, BalancerStablePriceFeedContract, BalancerV3PoolStatus, BalancerV3RouterAdapterContract, BalancerV3WrapperAdapterContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CamelotV3AdapterContract, CompositePriceFeedContract, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1StableNGAdapterContract, DaiUsdsAdapterContract, ERC4626AdapterContract, ERC4626ReferralAdapterContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, FluidDexAdapterContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InfinifiGatewayAdapterContract, InfinifiUnwindingGatewayAdapterContract, KelpLRTDepositPoolAdapterContract, KelpLRTWithdrawalManagerAdapterContract, LidoV1AdapterContract, LinearInterestRateModelContract, MAX_LEVERAGE_BUFFER_BPS, MarketRegister, MarketSuite, MellowClaimerAdapterContract, MellowDVVAdapterContract, MellowERC4626VaultAdapterContract, MellowLRTPriceFeedContract, MellowWrapperAdapterContract, MidasGatewayAdapterContract, MidasIssuanceVaultAdapterContract, MidasLiquidatorContract, MidasRedemptionVaultAdapterContract, NON_STRATEGY_PHANTOM_TOKEN_TYPES, PARTIAL_LIQUIDATION_BUFFER_BPS, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PartialPriceFeedInitError, PendlePairStatus, PendleRouterAdapterContract, PendleTWAPPTPriceFeed, PendleTokenType, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeLiquidatorContract, SecuritizeOnRampAdapterContract, SecuritizeRWAFactory, SecuritizeRedemptionGatewayAdapterContract, StakingRewardsAdapterContract, TraderJoePoolVersion, TraderJoeRouterAdapterContract, UniswapV2AdapterContract, UniswapV3AdapterContract, UniswapV4AdapterContract, UnsupportedZapperFunctionError, UpshiftVaultAdapterContract, VelodromeV2RouterAdapterContract, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, adapterActionAbi, adapterActionSelectors, adapterActionSignatures, adapterConstructorAbi, allTransfersAsTokenAmounts, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, classifyCurveOperation, createAdapter, createPriceOracle, createZapper, abi as creditFacadeV310Abi, curveAddLiquidityFromTransfers, curveRemoveLiquidityFromTransfers, dominantCollateral, erc4626ReferralAdapterAbi, expectedBalanceDeltas, fetchRedstonePayloads, fnSigToName, getAdapterActionAbi, getAdapterDeployParamsAbi, getAdapterType, getRawPriceUpdates, hasAdapterDeployParamsAbi, healthFactorBps, iBalancerV3RouterAbi, iBalancerV3RouterAdapterAbi, iBalancerV3WrapperAbi, iBalancerV3WrapperAdapterAbi, iBaseOnRampAbi, iBaseRewardPoolAbi, iBoosterAbi, iCamelotV3AdapterAbi, iCamelotV3RouterAbi, iConvexV1BaseRewardPoolAdapterAbi, iConvexV1BoosterAdapterAbi, iCurvePoolAbi, iCurvePoolStableNGAbi, iCurvePool_2Abi, iCurvePool_3Abi, iCurvePool_4Abi, iCurveV1StableNgAdapterAbi, iCurveV1_2AssetsAdapterAbi, iCurveV1_3AssetsAdapterAbi, iCurveV1_4AssetsAdapterAbi, iDaiUsdsAbi, iDaiUsdsAdapterAbi, iERC4626Abi, iERC4626ReferralAbi, iFluidDexAbi, iFluidDexAdapterAbi, iInfinifiGatewayAbi, iInfinifiGatewayAdapterAbi, iInfinifiUnwindingGatewayAbi, iInfinifiUnwindingGatewayAdapterAbi, iKelpLRTDepositPoolGatewayAbi, iKelpLRTWithdrawalManagerGatewayAbi, iKelpLrtDepositPoolAdapterAbi, iKelpLrtDepositPoolGatewayAbi, iKelpLrtWithdrawalManagerAdapterAbi, iKelpLrtWithdrawalManagerGatewayAbi, iLidoV1AdapterAbi, iMellow4626VaultAdapterAbi, iMellowClaimerAbi, iMellowClaimerAdapterAbi, iMellowWrapperAbi, iMellowWrapperAdapterAbi, iMidasGatewayAdapterV311Abi, iMidasGatewayV311Abi, iMidasIssuanceVaultAdapterV310Abi, iMidasIssuanceVaultV310Abi, iMidasRedemptionVaultAdapterV310Abi, iMidasRedemptionVaultGatewayV310Abi, iPendleRouterAbi, iPendleRouterAdapterAbi, iSecuritizeOnRampAbi, iSecuritizeOnRampAdapterV310Abi, iSecuritizeRedemptionGatewayAdapterV311Abi, iSecuritizeRedemptionGatewayV311Abi, iStakingRewardsAbi, iStakingRewardsAdapterAbi, iTraderJoeRouterAbi, iTraderJoeRouterAdapterAbi, iUniswapV2AdapterAbi, iUniswapV2Router02Abi, iUniswapV3Abi, iUniswapV3AdapterAbi, iUniswapV4AdapterAbi, iUniswapV4GatewayAbi, iUpshiftVaultAdapterAbi, iUpshiftVaultGatewayAbi, iVelodromeV2RouterAbi, iVelodromeV2RouterAdapterAbi, isLPPriceFeed, isRWAFactory, isStrategyCollateral, isUpdatablePriceFeed, iwstETHAbi, iwstEthv1AdapterAbi, lidoV1_WETHGatewayAbi, mellowDvvAdapterAbi, minSeizedAmount, mustGetDominantCollateral, optimalHFForPartialLiquidation, optimalRepaidAmount, parseAdapterAction, parseAdapterDeployParams, parsePosNegAmount, rayToBps, rewardsFromTransfers, swapFromTransfers, toNetTransfers, usdToNumber };
147
+ export { AbstractAdapterContract, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AccountMigratorAdapterContract, AdapterType, BalancerStablePriceFeedContract, BalancerV3PoolStatus, BalancerV3RouterAdapterContract, BalancerV3WrapperAdapterContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CamelotV3AdapterContract, CompositePriceFeedContract, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1StableNGAdapterContract, DaiUsdsAdapterContract, ERC4626AdapterContract, ERC4626ReferralAdapterContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, FluidDexAdapterContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InfinifiGatewayAdapterContract, InfinifiUnwindingGatewayAdapterContract, KelpLRTDepositPoolAdapterContract, KelpLRTWithdrawalManagerAdapterContract, LidoV1AdapterContract, LinearInterestRateModelContract, MAX_LEVERAGE_BUFFER_BPS, MarketRegister, MarketSuite, MellowClaimerAdapterContract, MellowDVVAdapterContract, MellowERC4626VaultAdapterContract, MellowLRTPriceFeedContract, MellowWrapperAdapterContract, MidasGatewayAdapterContract, MidasIssuanceVaultAdapterContract, MidasLiquidatorContract, MidasRedemptionVaultAdapterContract, NON_STRATEGY_PHANTOM_TOKEN_TYPES, PARTIAL_LIQUIDATION_BUFFER_BPS, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PartialPriceFeedInitError, PendlePairStatus, PendleRouterAdapterContract, PendleTWAPPTPriceFeed, PendleTokenType, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeLiquidatorContract, SecuritizeOnRampAdapterContract, SecuritizeRWAFactory, SecuritizeRedemptionGatewayAdapterContract, StakingRewardsAdapterContract, TraderJoePoolVersion, TraderJoeRouterAdapterContract, UniswapV2AdapterContract, UniswapV3AdapterContract, UniswapV4AdapterContract, UnsupportedZapperFunctionError, UpshiftVaultAdapterContract, VelodromeV2RouterAdapterContract, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, adapterActionAbi, adapterActionSelectors, adapterActionSignatures, adapterConstructorAbi, allTransfersAsTokenAmounts, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, classifyCurveOperation, createAdapter, createPriceOracle, createZapper, abi as creditFacadeV310Abi, curveAddLiquidityFromTransfers, curveRemoveLiquidityFromTransfers, dominantCollateral, erc4626ReferralAdapterAbi, expectedBalanceDeltas, fetchRedstonePayloads, fnSigToName, getAdapterActionAbi, getAdapterDeployParamsAbi, getAdapterType, getRawPriceUpdates, hasAdapterDeployParamsAbi, healthFactorBps, iBalancerV3RouterAbi, iBalancerV3RouterAdapterAbi, iBalancerV3WrapperAbi, iBalancerV3WrapperAdapterAbi, iBaseOnRampAbi, iBaseRewardPoolAbi, iBoosterAbi, iCamelotV3AdapterAbi, iCamelotV3RouterAbi, iConvexV1BaseRewardPoolAdapterAbi, iConvexV1BoosterAdapterAbi, iCurvePoolAbi, iCurvePoolStableNGAbi, iCurvePool_2Abi, iCurvePool_3Abi, iCurvePool_4Abi, iCurveV1StableNgAdapterAbi, iCurveV1_2AssetsAdapterAbi, iCurveV1_3AssetsAdapterAbi, iCurveV1_4AssetsAdapterAbi, iDaiUsdsAbi, iDaiUsdsAdapterAbi, iERC4626Abi, iERC4626ReferralAbi, iFluidDexAbi, iFluidDexAdapterAbi, iInfinifiGatewayAbi, iInfinifiGatewayAdapterAbi, iInfinifiUnwindingGatewayAbi, iInfinifiUnwindingGatewayAdapterAbi, iKelpLRTDepositPoolGatewayAbi, iKelpLRTWithdrawalManagerGatewayAbi, iKelpLrtDepositPoolAdapterAbi, iKelpLrtDepositPoolGatewayAbi, iKelpLrtWithdrawalManagerAdapterAbi, iKelpLrtWithdrawalManagerGatewayAbi, iLidoV1AdapterAbi, iMellow4626VaultAdapterAbi, iMellowClaimerAbi, iMellowClaimerAdapterAbi, iMellowWrapperAbi, iMellowWrapperAdapterAbi, iMidasGatewayAdapterV311Abi, iMidasGatewayV311Abi, iMidasIssuanceVaultAdapterV310Abi, iMidasIssuanceVaultV310Abi, iMidasRedemptionVaultAdapterV310Abi, iMidasRedemptionVaultGatewayV310Abi, iPendleRouterAbi, iPendleRouterAdapterAbi, iSecuritizeOnRampAbi, iSecuritizeOnRampAdapterV310Abi, iSecuritizeRedemptionGatewayAdapterV311Abi, iSecuritizeRedemptionGatewayV311Abi, iStakingRewardsAbi, iStakingRewardsAdapterAbi, iTraderJoeRouterAbi, iTraderJoeRouterAdapterAbi, iUniswapV2AdapterAbi, iUniswapV2Router02Abi, iUniswapV3Abi, iUniswapV3AdapterAbi, iUniswapV4AdapterAbi, iUniswapV4GatewayAbi, iUpshiftVaultAdapterAbi, iUpshiftVaultGatewayAbi, iVelodromeV2RouterAbi, iVelodromeV2RouterAdapterAbi, isLPPriceFeed, isRWAFactory, isStrategyCollateral, isUpdatablePriceFeed, iwstETHAbi, iwstEthv1AdapterAbi, lidoV1_WETHGatewayAbi, mellowDvvAdapterAbi, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, parseAdapterAction, parseAdapterDeployParams, parsePosNegAmount, pickStrategyTargetCollateral, rayToBps, rewardsFromTransfers, strategyName, swapFromTransfers, toNetTransfers, usdToNumber };
@@ -0,0 +1,18 @@
1
+ import { getTokenPrettyName } from "../chain/chains.js";
2
+ //#region src/sdk/market/strategyName.ts
3
+ /**
4
+ * Display name of a leveraged strategy: the target collateral over the
5
+ * borrowed underlying, e.g. `"wstETH / WETH"`.
6
+ *
7
+ * A curated pretty name from {@link getTokenPrettyName} wins over the target's
8
+ * ticker when one is configured.
9
+ *
10
+ * @param target - Collateral the position is built around.
11
+ * @param underlying - Token the position borrows.
12
+ * @param network - Chain id or network type label of the market.
13
+ **/
14
+ function strategyName(target, underlying, network) {
15
+ return `${getTokenPrettyName(target.address, network) ?? target.symbol} / ${underlying.symbol}`;
16
+ }
17
+ //#endregion
18
+ export { strategyName };
@@ -36,11 +36,13 @@ var OpportunitiesService = class extends SDKConstruct {
36
36
  * A single strategy opportunity plus the rate curve of the pool it borrows
37
37
  * from and the price feeds its liquidation price depends on.
38
38
  *
39
- * @throws If the credit manager is unknown, or does not accept the requested
40
- * collateral as a strategy.
39
+ * @throws If the credit manager is unknown, or does not currently offer a
40
+ * strategy.
41
41
  **/
42
42
  async getStrategy(key) {
43
- return this.sdk.marketRegister.findByCreditManager(key.creditManager).strategyOpportunityDetail(key.creditManager, key.targetCollateral);
43
+ const detail = this.sdk.marketRegister.findCreditManager(key.creditManager).strategyOpportunityDetail();
44
+ if (!detail) throw new Error(`credit manager ${key.creditManager} does not currently offer a strategy`);
45
+ return detail;
44
46
  }
45
47
  };
46
48
  //#endregion
@@ -1,16 +1,15 @@
1
1
  import { AddressMap } from "../utils/AddressMap.js";
2
+ import { getAccountTargetCollateral } from "../chain/chains.js";
2
3
  import "../constants/math.js";
3
4
  import "../constants/index.js";
4
- import { hexEq } from "../utils/hex.js";
5
5
  import "../utils/index.js";
6
6
  import { SDKConstruct } from "../base/SDKConstruct.js";
7
7
  import "../base/index.js";
8
8
  import { calcBorrowApy, calcPositionLeverage, healthFactorBps, usdToNumber } from "../market/math.js";
9
- import { dominantCollateral } from "../market/credit/dominantCollateral.js";
9
+ import { strategyName } from "../market/strategyName.js";
10
10
  import { isFilterSet } from "../../model/filters.js";
11
11
  import { matchesPositionFilter } from "../../model/positions.js";
12
12
  import "../../model/index.js";
13
- import "../market/index.js";
14
13
  import { calcBorrowRate } from "./calcBorrowRate.js";
15
14
  import { calcHealthFactor } from "./calcHealthFactor.js";
16
15
  import { calcLiquidationPrice } from "./calcLiquidationPrice.js";
@@ -149,11 +148,7 @@ var PositionsService = class extends SDKConstruct {
149
148
  const { pool } = market.pool;
150
149
  const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
151
150
  const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
152
- let collateral = dominantCollateral(ca, market);
153
- if (collateral) {
154
- const source = this.sdk.withdrawalCompressor?.getWithdrawalSourceToken(collateral);
155
- if (source) collateral = hexEq(source, market.underlying) ? void 0 : source;
156
- }
151
+ const target = getAccountTargetCollateral(ca.creditAccount, this.sdk.chainId) ?? suite.strategyTargetCollateral;
157
152
  const snapshot = accountSnapshotFromCreditAccountData(ca);
158
153
  const borrowRate = this.borrowRate(snapshot);
159
154
  const timeToLiquidation = this.timeToLiquidation(snapshot);
@@ -163,8 +158,8 @@ var PositionsService = class extends SDKConstruct {
163
158
  chainId: this.sdk.chainId,
164
159
  creditManager: ca.creditManager,
165
160
  creditAccount: ca.creditAccount,
166
- name: collateral ? suite.strategyName(collateral) : token.symbol,
167
- targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
161
+ name: target ? strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
162
+ targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
168
163
  leverage: calcPositionLeverage(ca.totalValue, totalDebtValue),
169
164
  borrowApy: calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
170
165
  totalDebt: {
@@ -7,8 +7,8 @@ import { BigIntMath } from "./bigint-math.js";
7
7
  import { bytes32ToString } from "./bytes32ToString.js";
8
8
  import { childLogger } from "./childLogger.js";
9
9
  import { createRawTx } from "./createRawTx.js";
10
- import { TypedObjectUtils } from "./mappers.js";
11
10
  import { etherscanApiUrl, etherscanUrl } from "./etherscan.js";
11
+ import { TypedObjectUtils } from "./mappers.js";
12
12
  import { isDust } from "./isDust.js";
13
13
  import { filterDust, filterDustUSD } from "./filterDust.js";
14
14
  import { fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, numberWithCommas, percentFmt, rayToNumber, shortAddress, shortHash, toBN, toBigInt, toSignificant } from "./formatter.js";
@@ -1,8 +1,8 @@
1
1
  import { Amount, Asset, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
2
- import { Curator, CuratorName } from "./curators.js";
3
2
  import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, GridSampling, OpportunityChartMetric, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PoolOpportunityChartMetric, PoolPositionChartMetric, PositionChartMetric, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, StrategyOpportunityChartMetric, StrategyPositionChartMetric } from "./charts.js";
4
3
  import { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, poolOpportunityChartMetricSchema, poolPositionChartMetricSchema, strategyOpportunityChartMetricSchema, strategyPositionChartMetricSchema } from "./charts.schema.js";
5
4
  import { CompareTag, CompareTolerance, ToleranceCompareTag, compareTagOf, offchainOnly, onchainOnly, tolerance } from "./compare.schema.js";
5
+ import { Curator, CuratorName } from "./curators.js";
6
6
  import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
7
7
  import { DelayedAddCollateralIntent, DelayedCloseAccountIntent, DelayedDecreaseLeverageIntent, DelayedDepositAndIncreaseLeverageIntent, DelayedDepositIntent, DelayedIncreaseLeverageIntent, DelayedIntent, DelayedWithdrawCollateralIntent } from "./delayed-intents.js";
8
8
  import { ChainScopedFilter, FILTER_ALL, FilterAll, Filterable, isFilterSet } from "./filters.js";
@@ -208,12 +208,9 @@ interface PoolOpportunity extends OpportunityBase {
208
208
  supplyApyAvg7D?: ApyBreakdown;
209
209
  }
210
210
  /**
211
- * A leveraged position: one credit manager plus one target collateral token.
212
- * A credit manager that accepts five collateral tokens therefore produces five
213
- * strategies.
214
- *
215
- * Identified by `(chainId, creditManager, targetCollateral.address)`,
216
- * see {@link strategyOpportunityId}.
211
+ * A leveraged position: one credit manager plus the single target collateral
212
+ * token that manager is configured around. Identified by
213
+ * `(chainId, creditManager)`, see {@link strategyOpportunityId}.
217
214
  **/
218
215
  interface StrategyOpportunity extends OpportunityBase {
219
216
  kind: "strategy";
@@ -316,8 +313,7 @@ interface StrategyOpportunity extends OpportunityBase {
316
313
  additionalBorrowApyAvg7D?: Bps;
317
314
  /**
318
315
  * Size of the strategy: the summed total value of the credit accounts
319
- * holding {@link targetCollateral}. An account that holds several strategy
320
- * collaterals counts in full towards each of them.
316
+ * opened in this credit manager.
321
317
  *
322
318
  * Absent in `onchain` mode.
323
319
  *
@@ -390,10 +386,10 @@ declare function poolOpportunityId(chainId: ChainId, pool: Address): Opportunity
390
386
  *
391
387
  * @example
392
388
  * ```ts
393
- * strategyOpportunityId(1, "0x3eb9...", "0x7f39...") // "1:0x3eb9...:0x7f39..."
389
+ * strategyOpportunityId(1, "0x3eb9...") // "1:0x3eb9..."
394
390
  * ```
395
391
  **/
396
- declare function strategyOpportunityId(chainId: ChainId, creditManager: Address, targetCollateral: Address): OpportunityId;
392
+ declare function strategyOpportunityId(chainId: ChainId, creditManager: Address): OpportunityId;
397
393
  /**
398
394
  * Canonical id of any opportunity, dispatching on {@link Opportunity.kind}.
399
395
  **/
@@ -610,15 +606,12 @@ interface PoolOpportunityKey {
610
606
  pool: Address;
611
607
  }
612
608
  /**
613
- * Identifies a strategy opportunity in a detail request.
609
+ * Identifies a strategy opportunity in a detail request. The credit manager
610
+ * identifies it on its own: each manager has exactly one target collateral.
614
611
  **/
615
612
  interface StrategyOpportunityKey {
616
613
  chainId: ChainId;
617
614
  creditManager: Address;
618
- /**
619
- * Address of the target collateral token.
620
- **/
621
- targetCollateral: Address;
622
615
  }
623
616
  /**
624
617
  * {@link PoolOpportunityKey} tagged with its kind, for requests that accept
@@ -1561,7 +1561,6 @@ declare const poolOpportunityKeySchema: z.ZodObject<{
1561
1561
  declare const strategyOpportunityKeySchema: z.ZodObject<{
1562
1562
  chainId: z.ZodNumber;
1563
1563
  creditManager: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1564
- targetCollateral: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1565
1564
  }, z.core.$strip>;
1566
1565
  /**
1567
1566
  * {@link OpportunityKey}
@@ -1573,7 +1572,6 @@ declare const opportunityKeySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1573
1572
  }, z.core.$strip>, z.ZodObject<{
1574
1573
  chainId: z.ZodNumber;
1575
1574
  creditManager: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1576
- targetCollateral: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1577
1575
  kind: z.ZodLiteral<"strategy">;
1578
1576
  }, z.core.$strip>], "kind">;
1579
1577
  //#endregion
@@ -184,8 +184,7 @@ interface StrategyPosition {
184
184
  kind: "strategy";
185
185
  /**
186
186
  * Human-readable strategy name, e.g. `"wstETH / WETH"`. Derived from
187
- * {@link targetCollateral}, so in `both` mode it follows the same backend
188
- * override as that field.
187
+ * {@link targetCollateral}.
189
188
  **/
190
189
  name: string;
191
190
  /**
@@ -201,14 +200,7 @@ interface StrategyPosition {
201
200
  **/
202
201
  creditAccount: Address;
203
202
  /**
204
- * The account's dominant non-underlying collateral at the session's opening
205
- * block (greatest opening-block USD value) — the asset the position was
206
- * initially leveraged into. `null` when the opening snapshot holds only the
207
- * underlying.
208
- *
209
- * In `both` mode the backend's value is always preferred when it has the
210
- * row, even if the chain wins the freshness race: the chain can only guess
211
- * from current holdings.
203
+ * Collateral token this position is a strategy in.
212
204
  **/
213
205
  targetCollateral: Token | null;
214
206
  /**
@@ -1,7 +1,7 @@
1
1
  import { ChainId } from "../../model/primitives.js";
2
- import { NetworkType } from "../../sdk/chain/chains.js";
3
2
  import { DataSource } from "../../model/response.js";
4
3
  import "../../model/index.js";
4
+ import { NetworkType } from "../../sdk/chain/chains.js";
5
5
  import "../../sdk/index.js";
6
6
  import { BaseError } from "viem";
7
7
  //#region src/new-sdk/errors/SourceChainMismatchError.d.ts
@@ -9,8 +9,9 @@ import { MergeListResult } from "../utils/types.js";
9
9
  * `name` onto every strategy row the backend has — even when that chain was
10
10
  * served from on-chain data because the backend was stale.
11
11
  *
12
- * The backend records the collateral the strategy was opened into; the chain
13
- * can only guess from current holdings. `name` is derived from that collateral,
12
+ * The chain resolves `targetCollateral` from a per-account override or the
13
+ * credit manager's single target token. The backend's historical value is
14
+ * still preferred when it has the row. `name` is derived from that collateral,
14
15
  * so it follows the same override.
15
16
  **/
16
17
  declare function mergePositionList<Onchain extends DataResponse<Position[]> | undefined, Offchain extends DataResponse<Position[]> | undefined>(onchain: Onchain, offchain: Offchain, maxLagSeconds?: number): MergeListResult<Onchain, Offchain, Position[]>;
@@ -1,9 +1,9 @@
1
1
  import { ILogger } from "../sdk/types/logger.js";
2
2
  import { ChainId } from "../model/primitives.js";
3
- import { NetworkType } from "../sdk/chain/chains.js";
4
3
  import { Notice, NoticeSubject } from "../model/notices.js";
5
4
  import { DataResponse } from "../model/response.js";
6
5
  import "../model/index.js";
6
+ import { NetworkType } from "../sdk/chain/chains.js";
7
7
  import { MultichainAttachOptions, MultichainSDK, MultichainSDKOptions } from "../sdk/MultichainSDK.js";
8
8
  import "../sdk/index.js";
9
9
  import { GearboxAPIOptions } from "../offchain/types.js";
@@ -97,6 +97,11 @@ interface BuildMockSdkArgs {
97
97
  maxDebtPerBlockMultiplier?: number;
98
98
  /** Tokens the facade forbids, which the mock turns into its mask. */
99
99
  forbiddenTokens?: Address[];
100
+ /**
101
+ * Single strategy target of this mock credit manager. Defaults to the first
102
+ * non-underlying collateral so the 1-to-1 CM rule has something to read.
103
+ */
104
+ strategyTargetCollateral?: Address;
100
105
  /**
101
106
  * Redemption venues the mock compressor reports, keyed by source token. An
102
107
  * empty array stands for "this token has no delayed route"; several entries