@gearbox-protocol/sdk 15.1.0-next.4 → 15.1.0-next.6

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 (35) hide show
  1. package/dist/cjs/dev/compareOpportunities.js +218 -0
  2. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -2
  3. package/dist/cjs/sdk/index.js +9 -5
  4. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
  5. package/dist/cjs/sdk/market/credit/CreditSuite.js +18 -27
  6. package/dist/cjs/sdk/market/credit/index.js +3 -0
  7. package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
  8. package/dist/cjs/sdk/market/index.js +17 -0
  9. package/dist/cjs/sdk/market/math.js +57 -44
  10. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +1 -1
  11. package/dist/cjs/sdk/opportunities/index.js +0 -13
  12. package/dist/esm/dev/compareOpportunities.js +216 -0
  13. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +3 -3
  14. package/dist/esm/sdk/index.js +3 -2
  15. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
  16. package/dist/esm/sdk/market/credit/CreditSuite.js +19 -28
  17. package/dist/esm/sdk/market/credit/index.js +2 -1
  18. package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
  19. package/dist/esm/sdk/market/index.js +3 -1
  20. package/dist/esm/sdk/market/math.js +52 -40
  21. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -2
  22. package/dist/esm/sdk/opportunities/index.js +1 -2
  23. package/dist/types/dev/compareOpportunities.d.ts +153 -0
  24. package/dist/types/model/opportunities.d.ts +9 -9
  25. package/dist/types/model/positions.d.ts +3 -3
  26. package/dist/types/sdk/index.d.ts +3 -2
  27. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
  28. package/dist/types/sdk/market/credit/CreditSuite.d.ts +2 -16
  29. package/dist/types/sdk/market/credit/index.d.ts +2 -1
  30. package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
  31. package/dist/types/sdk/market/credit/types.d.ts +2 -9
  32. package/dist/types/sdk/market/index.d.ts +3 -1
  33. package/dist/types/sdk/market/math.d.ts +44 -34
  34. package/dist/types/sdk/opportunities/index.d.ts +1 -2
  35. package/package.json +1 -1
@@ -0,0 +1,218 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_opportunities = require("../model/opportunities.js");
3
+ require("../model/index.js");
4
+ //#region src/dev/compareOpportunities.ts
5
+ /**
6
+ * Matches two opportunity listings by {@link opportunityId} and reports every
7
+ * field the two sources disagree on.
8
+ *
9
+ * Nothing is filtered out: a diff that is expected — a field only the backend
10
+ * can fill, a formula the two sides define differently, a USD value smoothed on
11
+ * one side — is reported like any other, tagged by {@link DiffKind} so that a
12
+ * reader can bucket it afterwards.
13
+ **/
14
+ function compareOpportunities(input) {
15
+ const onchainRows = indexById(input.onchain.data);
16
+ const offchainRows = indexById(input.offchain.data);
17
+ const onlyOnchain = [];
18
+ const onlyOffchain = [];
19
+ const matched = [];
20
+ for (const [id, row] of onchainRows) {
21
+ const counterpart = offchainRows.get(id);
22
+ if (!counterpart) {
23
+ onlyOnchain.push(toRef(row));
24
+ continue;
25
+ }
26
+ const diffs = diffOpportunity(row, counterpart);
27
+ matched.push({
28
+ id,
29
+ kind: row.kind,
30
+ chainId: row.chainId,
31
+ onchainName: row.name,
32
+ offchainName: counterpart.name,
33
+ identical: diffs.length === 0,
34
+ diffs
35
+ });
36
+ }
37
+ for (const [id, row] of offchainRows) if (!onchainRows.has(id)) onlyOffchain.push(toRef(row));
38
+ byId(onlyOnchain);
39
+ byId(onlyOffchain);
40
+ matched.sort((a, b) => a.id.localeCompare(b.id));
41
+ return {
42
+ generatedAt: input.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
43
+ backendUrl: input.backendUrl,
44
+ networks: [...input.networks],
45
+ onchainChains: input.onchain.meta.chains,
46
+ offchainChains: input.offchain.meta.chains,
47
+ summary: summarize(input.onchain.data, input.offchain.data, onlyOnchain, onlyOffchain, matched),
48
+ onlyOnchain,
49
+ onlyOffchain,
50
+ matched
51
+ };
52
+ }
53
+ function indexById(rows) {
54
+ return new Map(rows.map((row) => [require_model_opportunities.opportunityId(row), row]));
55
+ }
56
+ function byId(refs) {
57
+ refs.sort((a, b) => a.id.localeCompare(b.id));
58
+ }
59
+ function toRef(row) {
60
+ const base = {
61
+ id: require_model_opportunities.opportunityId(row),
62
+ kind: row.kind,
63
+ chainId: row.chainId,
64
+ name: row.name
65
+ };
66
+ return row.kind === "pool" ? {
67
+ ...base,
68
+ pool: row.pool
69
+ } : {
70
+ ...base,
71
+ creditManager: row.creditManager,
72
+ targetCollateral: row.targetCollateral.address
73
+ };
74
+ }
75
+ /**
76
+ * Every field two versions of one opportunity disagree on.
77
+ **/
78
+ function diffOpportunity(onchain, offchain) {
79
+ const diffs = [];
80
+ diffValue("", onchain, offchain, diffs);
81
+ return diffs;
82
+ }
83
+ function diffValue(path, onchain, offchain, out) {
84
+ if (isAbsent(onchain) && isAbsent(offchain)) return;
85
+ if (isAbsent(onchain) || isAbsent(offchain)) {
86
+ out.push({
87
+ path,
88
+ onchain,
89
+ offchain,
90
+ kind: "presence"
91
+ });
92
+ return;
93
+ }
94
+ if (Array.isArray(onchain) && Array.isArray(offchain)) {
95
+ diffArray(path, onchain, offchain, out);
96
+ return;
97
+ }
98
+ if (isRecord(onchain) && isRecord(offchain)) {
99
+ for (const key of union(Object.keys(onchain), Object.keys(offchain))) diffValue(join(path, key), onchain[key], offchain[key], out);
100
+ return;
101
+ }
102
+ if (!sameScalar(onchain, offchain)) out.push({
103
+ path,
104
+ onchain,
105
+ offchain,
106
+ kind: scalarKind(path, onchain)
107
+ });
108
+ }
109
+ /**
110
+ * Arrays whose elements identify themselves — collateral tokens, points
111
+ * programs — are matched by that identity, so a token present on one side only
112
+ * is reported as such rather than shifting every later element into a diff.
113
+ **/
114
+ function diffArray(path, onchain, offchain, out) {
115
+ const onchainKeyed = keyElements(onchain);
116
+ const offchainKeyed = keyElements(offchain);
117
+ if (!onchainKeyed || !offchainKeyed) {
118
+ if (onchain.length !== offchain.length) {
119
+ out.push({
120
+ path,
121
+ onchain,
122
+ offchain,
123
+ kind: "other"
124
+ });
125
+ return;
126
+ }
127
+ onchain.forEach((element, index) => {
128
+ diffValue(`${path}[${index}]`, element, offchain[index], out);
129
+ });
130
+ return;
131
+ }
132
+ for (const key of union([...onchainKeyed.keys()], [...offchainKeyed.keys()])) diffValue(`${path}[${key}]`, onchainKeyed.get(key), offchainKeyed.get(key), out);
133
+ }
134
+ /**
135
+ * The array indexed by each element's own identity, or `undefined` when its
136
+ * elements have none and order is all there is to go by.
137
+ **/
138
+ function keyElements(values) {
139
+ const keyed = /* @__PURE__ */ new Map();
140
+ for (const value of values) {
141
+ if (!isRecord(value)) return;
142
+ const identity = value.address ?? value.id ?? value.token;
143
+ if (typeof identity !== "string") return;
144
+ keyed.set(identity.toLowerCase(), value);
145
+ }
146
+ return keyed.size === values.length ? keyed : void 0;
147
+ }
148
+ const ADDRESS = /^0x[0-9a-f]{40}$/i;
149
+ /**
150
+ * Only addresses are compared case-insensitively: the backend lowercases them
151
+ * while the chain hands out checksummed ones, which is not a disagreement. A
152
+ * symbol or a name spelled differently is.
153
+ **/
154
+ function sameScalar(onchain, offchain) {
155
+ if (typeof onchain === "string" && typeof offchain === "string" && ADDRESS.test(onchain) && ADDRESS.test(offchain)) return onchain.toLowerCase() === offchain.toLowerCase();
156
+ return onchain === offchain;
157
+ }
158
+ function scalarKind(path, onchain) {
159
+ if (path.endsWith("valueUsd")) return "usd";
160
+ return typeof onchain === "number" || typeof onchain === "bigint" ? "numeric" : "other";
161
+ }
162
+ function summarize(onchain, offchain, onlyOnchain, onlyOffchain, matched) {
163
+ const byChain = union(onchain.map((row) => String(row.chainId)), offchain.map((row) => String(row.chainId))).map((chainId) => ({
164
+ chainId: Number(chainId),
165
+ ...count(onchain.filter((row) => String(row.chainId) === chainId), offchain.filter((row) => String(row.chainId) === chainId), onlyOnchain.filter((ref) => String(ref.chainId) === chainId), onlyOffchain.filter((ref) => String(ref.chainId) === chainId), matched.filter((match) => String(match.chainId) === chainId))
166
+ })).sort((a, b) => a.chainId - b.chainId);
167
+ return {
168
+ ...count(onchain, offchain, onlyOnchain, onlyOffchain, matched),
169
+ byChain,
170
+ diffsByPath: countPaths(matched)
171
+ };
172
+ }
173
+ function count(onchain, offchain, onlyOnchain, onlyOffchain, matched) {
174
+ const identical = matched.filter((match) => match.identical).length;
175
+ return {
176
+ onchainRows: onchain.length,
177
+ offchainRows: offchain.length,
178
+ matched: matched.length,
179
+ identical,
180
+ differing: matched.length - identical,
181
+ onlyOnchain: onlyOnchain.length,
182
+ onlyOffchain: onlyOffchain.length
183
+ };
184
+ }
185
+ /**
186
+ * How often each field differed, with array keys collapsed so that the same
187
+ * field of a hundred collateral tokens counts as one path.
188
+ **/
189
+ function countPaths(matched) {
190
+ const counts = /* @__PURE__ */ new Map();
191
+ for (const match of matched) for (const diff of match.diffs) {
192
+ const path = diff.path.replace(/\[[^\]]*\]/g, "[]");
193
+ const entry = counts.get(path) ?? {
194
+ path,
195
+ kinds: [],
196
+ count: 0
197
+ };
198
+ entry.count += 1;
199
+ if (!entry.kinds.includes(diff.kind)) entry.kinds.push(diff.kind);
200
+ counts.set(path, entry);
201
+ }
202
+ return [...counts.values()].sort((a, b) => b.count - a.count || a.path.localeCompare(b.path));
203
+ }
204
+ function isAbsent(value) {
205
+ return value === void 0 || value === null;
206
+ }
207
+ function isRecord(value) {
208
+ return typeof value === "object" && value !== null && !Array.isArray(value);
209
+ }
210
+ function union(left, right) {
211
+ return [.../* @__PURE__ */ new Set([...left, ...right])];
212
+ }
213
+ function join(path, key) {
214
+ return path ? `${path}.${key}` : key;
215
+ }
216
+ //#endregion
217
+ exports.compareOpportunities = compareOpportunities;
218
+ exports.diffOpportunity = diffOpportunity;
@@ -209,8 +209,8 @@ var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKCon
209
209
  creditAccount: ca.creditAccount,
210
210
  name: collateral ? suite.strategyName(collateral) : token.symbol,
211
211
  targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
212
- leverage: require_sdk_market_math.positionLeverage(totalDebtValue, ca.totalValue),
213
- borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
212
+ leverage: require_sdk_market_math.calcPositionLeverage(ca.totalValue, totalDebtValue),
213
+ borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
214
214
  totalDebt: {
215
215
  token,
216
216
  value: totalDebtValue,
@@ -53,6 +53,7 @@ const require_sdk_market_credit_CreditFacadeV310Contract = require("./market/cre
53
53
  const require_sdk_market_math = require("./market/math.js");
54
54
  const require_sdk_market_credit_CreditManagerV310Contract = require("./market/credit/CreditManagerV310Contract.js");
55
55
  const require_sdk_market_credit_dominantCollateral = require("./market/credit/dominantCollateral.js");
56
+ const require_sdk_market_credit_isStrategyCollateral = require("./market/credit/isStrategyCollateral.js");
56
57
  const require_sdk_market_credit_CreditSuite = require("./market/credit/CreditSuite.js");
57
58
  const require_sdk_market_credit_expectedBalanceDeltas = require("./market/credit/expectedBalanceDeltas.js");
58
59
  const require_sdk_utils_viem_simulateMulticall = require("./utils/viem/simulateMulticall.js");
@@ -233,6 +234,7 @@ exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = require_sdk_accounts_liquidations_
233
234
  exports.LinearInterestRateModelContract = require_sdk_market_pool_LinearInterestRateModelContract.LinearInterestRateModelContract;
234
235
  exports.LiquidationsService = require_sdk_accounts_liquidations_LiquidationsService.LiquidationsService;
235
236
  exports.MAX_INT = require_sdk_constants_math.MAX_INT;
237
+ exports.MAX_LEVERAGE_BUFFER_BPS = require_sdk_market_math.MAX_LEVERAGE_BUFFER_BPS;
236
238
  exports.MAX_UINT16 = require_sdk_constants_math.MAX_UINT16;
237
239
  exports.MAX_UINT256 = require_sdk_constants_math.MAX_UINT256;
238
240
  exports.MIN_INT96 = require_sdk_constants_math.MIN_INT96;
@@ -248,6 +250,7 @@ exports.MultichainOpportunitiesService = require_sdk_opportunities_MultichainOpp
248
250
  exports.MultichainPositionsService = require_sdk_positions_MultichainPositionsService.MultichainPositionsService;
249
251
  exports.MultichainSDK = require_sdk_MultichainSDK.MultichainSDK;
250
252
  exports.NATIVE_ADDRESS = require_sdk_constants_addresses.NATIVE_ADDRESS;
253
+ exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_isStrategyCollateral.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
251
254
  exports.NOT_DEPLOYED = require_sdk_constants_addresses.NOT_DEPLOYED;
252
255
  exports.NO_VERSION = require_sdk_constants_address_provider.NO_VERSION;
253
256
  exports.NetworkType = require_sdk_chain_chains.NetworkType;
@@ -324,12 +327,15 @@ exports.ZeroPriceFeedContract = require_sdk_market_pricefeeds_ZeroPriceFeed.Zero
324
327
  exports.ZodAddress = require_sdk_utils_zod.ZodAddress;
325
328
  exports.ZodBigInt = require_sdk_utils_zod.ZodBigInt;
326
329
  exports.ZodHex = require_sdk_utils_zod.ZodHex;
327
- exports.additionalBorrowApyBps = require_sdk_market_math.additionalBorrowApyBps;
328
330
  exports.assetsMap = require_sdk_router_helpers.assetsMap;
329
331
  exports.attachOptionsSchema = require_sdk_options.attachOptionsSchema;
330
- exports.borrowApyBps = require_sdk_market_math.borrowApyBps;
331
332
  exports.botPermissionsToString = require_sdk_constants_bot_permissions.botPermissionsToString;
332
333
  exports.bytes32ToString = require_sdk_utils_bytes32ToString.bytes32ToString;
334
+ exports.calcAdditionalBorrowApy = require_sdk_market_math.calcAdditionalBorrowApy;
335
+ exports.calcBorrowApy = require_sdk_market_math.calcBorrowApy;
336
+ exports.calcMaxLeverage = require_sdk_market_math.calcMaxLeverage;
337
+ exports.calcPositionLeverage = require_sdk_market_math.calcPositionLeverage;
338
+ exports.calcUtilization = require_sdk_market_math.calcUtilization;
333
339
  exports.chains = require_sdk_chain_chains.chains;
334
340
  exports.childLogger = require_sdk_utils_childLogger.childLogger;
335
341
  exports.createAdapter = require_sdk_market_adapters_createAdapter.createAdapter;
@@ -385,6 +391,7 @@ exports.isLPPriceFeed = require_sdk_market_pricefeeds_AbstractLPPriceFeed.isLPPr
385
391
  exports.isPublicNetwork = require_sdk_chain_chains.isPublicNetwork;
386
392
  exports.isRWAFactory = require_sdk_market_rwa_types.isRWAFactory;
387
393
  exports.isRWAToken = require_sdk_chain_chains.isRWAToken;
394
+ exports.isStrategyCollateral = require_sdk_market_credit_isStrategyCollateral.isStrategyCollateral;
388
395
  exports.isSunsetPool = require_sdk_chain_chains.isSunsetPool;
389
396
  exports.isSunsetStrategy = require_sdk_chain_chains.isSunsetStrategy;
390
397
  exports.isSupportedNetwork = require_sdk_chain_chains.isSupportedNetwork;
@@ -393,7 +400,6 @@ exports.isV310 = require_sdk_constants_versions.isV310;
393
400
  exports.isVersionRange = require_sdk_constants_versions.isVersionRange;
394
401
  exports.json_parse = require_sdk_utils_json.json_parse;
395
402
  exports.json_stringify = require_sdk_utils_json.json_stringify;
396
- exports.maxLeverage = require_sdk_market_math.maxLeverage;
397
403
  exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
398
404
  exports.mustGetDominantCollateral = require_sdk_market_credit_dominantCollateral.mustGetDominantCollateral;
399
405
  exports.numberWithCommas = require_sdk_utils_formatter.numberWithCommas;
@@ -401,7 +407,6 @@ exports.onchainSDKOptionsSchema = require_sdk_options.onchainSDKOptionsSchema;
401
407
  exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
402
408
  exports.optimalRepaidAmount = require_sdk_market_math.optimalRepaidAmount;
403
409
  exports.percentFmt = require_sdk_utils_formatter.percentFmt;
404
- exports.positionLeverage = require_sdk_market_math.positionLeverage;
405
410
  exports.primaryInstantOutput = require_sdk_accounts_intents_operations_claim_delayed_index.primaryInstantOutput;
406
411
  exports.rayToBps = require_sdk_market_math.rayToBps;
407
412
  exports.rayToNumber = require_sdk_utils_formatter.rayToNumber;
@@ -422,5 +427,4 @@ exports.toRequestableWithdrawal = require_sdk_accounts_withdrawal_compressor_Abs
422
427
  exports.toSignificant = require_sdk_utils_formatter.toSignificant;
423
428
  exports.toWithdrawalStatus = require_sdk_accounts_withdrawal_compressor_types.toWithdrawalStatus;
424
429
  exports.usdToNumber = require_sdk_market_math.usdToNumber;
425
- exports.utilizationBps = require_sdk_market_math.utilizationBps;
426
430
  exports.watchBlocksAsync = require_sdk_utils_viem_watchBlocksAsync.watchBlocksAsync;
@@ -10,7 +10,6 @@ require("../../base/index.js");
10
10
  const require_sdk_market_adapters_createAdapter = require("../adapters/createAdapter.js");
11
11
  require("../adapters/index.js");
12
12
  const require_sdk_market_math = require("../math.js");
13
- let viem = require("viem");
14
13
  //#region src/sdk/market/credit/CreditManagerV310Contract.ts
15
14
  const abi = require_abi_310_generated.iCreditManagerV310Abi;
16
15
  var CreditManagerV310Contract = class extends require_sdk_base_BaseContract.BaseContract {
@@ -65,20 +64,10 @@ var CreditManagerV310Contract = class extends require_sdk_base_BaseContract.Base
65
64
  return this.liquidationThresholds.keys();
66
65
  }
67
66
  /**
68
- * {@inheritDoc ICreditManagerContract.leverageableCollaterals}
69
- */
70
- get leverageableCollaterals() {
71
- return this.collateralTokens.filter((token) => {
72
- if ((0, viem.isAddressEqual)(token, this.underlying)) return false;
73
- const lt = this.liquidationThresholds.get(token);
74
- return !!lt && lt > 0 && lt < Number(10000n);
75
- });
76
- }
77
- /**
78
67
  * {@inheritDoc ICreditManagerContract.maxLeverage}
79
68
  */
80
69
  maxLeverage(collateral) {
81
- return require_sdk_market_math.maxLeverage(this.liquidationThresholds.mustGet(collateral));
70
+ return require_sdk_market_math.calcMaxLeverage(this.liquidationThresholds.mustGet(collateral));
82
71
  }
83
72
  /**
84
73
  * {@inheritDoc ICreditManagerContract.liquidationPremium}
@@ -12,7 +12,7 @@ const require_sdk_market_credit_createCreditConfigurator = require("./createCred
12
12
  const require_sdk_market_credit_createCreditFacade = require("./createCreditFacade.js");
13
13
  const require_sdk_market_credit_createCreditManager = require("./createCreditManager.js");
14
14
  const require_sdk_market_credit_dominantCollateral = require("./dominantCollateral.js");
15
- let viem = require("viem");
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.
@@ -172,22 +172,8 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
172
172
  return this.creditFacade.isPaused || this.market.pool.isPaused;
173
173
  }
174
174
  /**
175
- * Collateral tokens a leveraged position can be built around in this suite:
176
- * the ones the credit manager can lever up, narrowed to the tokens that can
177
- * still be entered. A token qualifies when it
178
- *
179
- * - has a liquidation threshold above `0` and below `100%`, and is not the
180
- * suite's underlying, see
181
- * {@link ICreditManagerContract.leverageableCollaterals};
182
- * - is not the token the market's underlying wraps, which for an RWA market
183
- * is the same exposure as the underlying itself;
184
- * - is not a phantom token, which only ever appears as the intermediate step
185
- * of a withdrawal and cannot be acquired;
186
- * - is not an expired token, e.g. a matured Pendle PT;
187
- * - has a non-zero main price in the market's oracle — a zero or failed
188
- * answer (e.g. a zero price feed) means the position cannot be valued;
189
- * - the market still accepts quota for, see
190
- * {@link PoolQuotaKeeperContract.hasActiveQuota}.
175
+ * Collateral tokens a leveraged position can be built around in this suite,
176
+ * see {@link isStrategyCollateral} for the per-token criteria.
191
177
  *
192
178
  * A suite where no debt can be drawn at all ({@link maxBorrowAmount} is `0`,
193
179
  * e.g. its debt limit is exhausted or zeroed out) offers no strategies,
@@ -197,14 +183,19 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
197
183
  if (this.maxBorrowAmount === 0n) return [];
198
184
  const { pqk, unwrappedUnderlying } = this.market.pool;
199
185
  const { mainPrices } = this.market.priceOracle;
200
- const { tokensMeta } = this;
201
- return this.creditManager.leverageableCollaterals.filter((token) => {
202
- if ((0, viem.isAddressEqual)(token, unwrappedUnderlying)) return false;
186
+ const { tokensMeta, creditManager } = this;
187
+ return creditManager.collateralTokens.filter((token) => {
203
188
  const meta = tokensMeta.mustGet(token);
204
- if (tokensMeta.isPhantomToken(meta) || meta.isExpired) return false;
205
- const mainPrice = mainPrices.get(token);
206
- if (!mainPrice?.success || mainPrice.price === 0n) return false;
207
- return pqk.hasActiveQuota(token);
189
+ return require_sdk_market_credit_isStrategyCollateral.isStrategyCollateral({
190
+ token,
191
+ underlying: creditManager.underlying,
192
+ unwrappedUnderlying,
193
+ liquidationThreshold: creditManager.liquidationThresholds.mustGet(token),
194
+ contractType: meta.contractType,
195
+ isExpired: meta.isExpired,
196
+ mainPrice: mainPrices.get(token)?.price,
197
+ hasActiveQuota: pqk.hasActiveQuota(token)
198
+ });
208
199
  });
209
200
  }
210
201
  /**
@@ -249,7 +240,7 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
249
240
  curator: market.curator,
250
241
  underlyingToken: market.underlyingToken,
251
242
  totalBorrow: oracle.toAmount(pool.underlying, borrowed),
252
- collateralTokens: market.collateralTokens,
243
+ collateralTokens: this.strategyCollaterals.map((t) => this.tokensMeta.mustGetToken(t)),
253
244
  paused: this.isPaused,
254
245
  rwa: market.rwa,
255
246
  sunset: market.sunset || require_sdk_chain_chains.isSunsetStrategy(cm.address, collateral, this.sdk.networkType),
@@ -257,8 +248,8 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
257
248
  liquidationPremium: cm.liquidationPremium,
258
249
  liquidationFee: cm.feeLiquidation,
259
250
  expirationDate: this.expirationDate,
260
- borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, cm.feeInterest),
261
- additionalBorrowApy: require_sdk_market_math.additionalBorrowApyBps(market.pool.pqk.quotaRate(collateral), maxLeverage),
251
+ borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, cm.feeInterest),
252
+ additionalBorrowApy: require_sdk_market_math.calcAdditionalBorrowApy(market.pool.pqk.quotaRate(collateral), cm.feeInterest, maxLeverage),
262
253
  maxBorrowAmount: oracle.toAmount(pool.underlying, this.maxBorrowAmount),
263
254
  maxLeverage
264
255
  };
@@ -4,6 +4,7 @@ const require_sdk_market_credit_CreditFacadeV310BaseContract = require("./Credit
4
4
  const require_sdk_market_credit_CreditFacadeV310Contract = require("./CreditFacadeV310Contract.js");
5
5
  const require_sdk_market_credit_CreditManagerV310Contract = require("./CreditManagerV310Contract.js");
6
6
  const require_sdk_market_credit_dominantCollateral = require("./dominantCollateral.js");
7
+ const require_sdk_market_credit_isStrategyCollateral = require("./isStrategyCollateral.js");
7
8
  const require_sdk_market_credit_CreditSuite = require("./CreditSuite.js");
8
9
  const require_sdk_market_credit_expectedBalanceDeltas = require("./expectedBalanceDeltas.js");
9
10
  require("./types.js");
@@ -12,7 +13,9 @@ exports.CreditFacadeV310BaseContract = require_sdk_market_credit_CreditFacadeV31
12
13
  exports.CreditFacadeV310Contract = require_sdk_market_credit_CreditFacadeV310Contract.CreditFacadeV310Contract;
13
14
  exports.CreditManagerV310Contract = require_sdk_market_credit_CreditManagerV310Contract.CreditManagerV310Contract;
14
15
  exports.CreditSuite = require_sdk_market_credit_CreditSuite.CreditSuite;
16
+ exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_isStrategyCollateral.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
15
17
  exports.creditFacadeV310Abi = require_sdk_market_credit_CreditFacadeV310BaseContract.creditFacadeV310Abi;
16
18
  exports.dominantCollateral = require_sdk_market_credit_dominantCollateral.dominantCollateral;
17
19
  exports.expectedBalanceDeltas = require_sdk_market_credit_expectedBalanceDeltas.expectedBalanceDeltas;
20
+ exports.isStrategyCollateral = require_sdk_market_credit_isStrategyCollateral.isStrategyCollateral;
18
21
  exports.mustGetDominantCollateral = require_sdk_market_credit_dominantCollateral.mustGetDominantCollateral;
@@ -0,0 +1,50 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../constants/math.js");
3
+ require("../../constants/index.js");
4
+ let viem = require("viem");
5
+ //#region src/sdk/market/credit/isStrategyCollateral.ts
6
+ /**
7
+ * Withdrawal and redemption phantom tokens that can never be acquired as a
8
+ * strategy target. Other `PHANTOM_TOKEN::*` types (Convex, Infrared, staking
9
+ * rewards) can.
10
+ */
11
+ const NON_STRATEGY_PHANTOM_TOKEN_TYPES = [
12
+ "PHANTOM_TOKEN::INFINIFI_UNWIND",
13
+ "PHANTOM_TOKEN::MELLOW_WITHDRAWAL",
14
+ "PHANTOM_TOKEN::MIDAS_REDEMPTION",
15
+ "PHANTOM_TOKEN::SECURITIZE_RD",
16
+ "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
17
+ ];
18
+ const NON_STRATEGY_PHANTOM_TOKEN_TYPE_SET = new Set(NON_STRATEGY_PHANTOM_TOKEN_TYPES);
19
+ const RWA_UNDERLYING_PREFIX = "RWA_UNDERLYING::";
20
+ /**
21
+ * Whether a collateral token can be the target of a leveraged strategy.
22
+ *
23
+ * A token qualifies when it
24
+ *
25
+ * - has a liquidation threshold above `0` and below `100%`, and is not the
26
+ * suite's underlying — borrowing an asset against itself is not a position,
27
+ * and an LT of `0` or at least `100%` would mean unbounded leverage;
28
+ * - is not the token the market's underlying wraps, which for an RWA market
29
+ * is the same exposure as the underlying itself (also rejected when
30
+ * `contractType` starts with `"RWA_UNDERLYING::"`);
31
+ * - is not a withdrawal or redemption phantom token listed in
32
+ * {@link NON_STRATEGY_PHANTOM_TOKEN_TYPES} — those only ever appear as the
33
+ * intermediate step of a withdrawal and cannot be acquired;
34
+ * - is not an expired token, e.g. a matured Pendle PT;
35
+ * - has a non-zero main price in the market's oracle — a zero or missing
36
+ * answer (e.g. a failed or zero price feed) means the position cannot be
37
+ * valued;
38
+ * - the market still accepts quota for.
39
+ */
40
+ function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }) {
41
+ if ((0, viem.isAddressEqual)(token, underlying) || (0, viem.isAddressEqual)(token, unwrappedUnderlying)) return false;
42
+ if (liquidationThreshold <= 0 || liquidationThreshold >= Number(10000n)) return false;
43
+ if (contractType && (NON_STRATEGY_PHANTOM_TOKEN_TYPE_SET.has(contractType) || contractType.startsWith(RWA_UNDERLYING_PREFIX))) return false;
44
+ if (isExpired) return false;
45
+ if (!mainPrice) return false;
46
+ return hasActiveQuota;
47
+ }
48
+ //#endregion
49
+ exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = NON_STRATEGY_PHANTOM_TOKEN_TYPES;
50
+ exports.isStrategyCollateral = isStrategyCollateral;
@@ -5,8 +5,10 @@ require("./adapters/index.js");
5
5
  const require_sdk_market_credit_CreditConfiguratorV310Contract = require("./credit/CreditConfiguratorV310Contract.js");
6
6
  const require_sdk_market_credit_CreditFacadeV310BaseContract = require("./credit/CreditFacadeV310BaseContract.js");
7
7
  const require_sdk_market_credit_CreditFacadeV310Contract = require("./credit/CreditFacadeV310Contract.js");
8
+ const require_sdk_market_math = require("./math.js");
8
9
  const require_sdk_market_credit_CreditManagerV310Contract = require("./credit/CreditManagerV310Contract.js");
9
10
  const require_sdk_market_credit_dominantCollateral = require("./credit/dominantCollateral.js");
11
+ const require_sdk_market_credit_isStrategyCollateral = require("./credit/isStrategyCollateral.js");
10
12
  const require_sdk_market_credit_CreditSuite = require("./credit/CreditSuite.js");
11
13
  const require_sdk_market_credit_expectedBalanceDeltas = require("./credit/expectedBalanceDeltas.js");
12
14
  require("./credit/index.js");
@@ -80,10 +82,13 @@ exports.GaugeContract = require_sdk_market_pool_GaugeContract.GaugeContract;
80
82
  exports.IERC20ZapperContract = require_sdk_market_zapper_IERC20ZapperContract.IERC20ZapperContract;
81
83
  exports.IETHZapperContract = require_sdk_market_zapper_IETHZapperContract.IETHZapperContract;
82
84
  exports.LinearInterestRateModelContract = require_sdk_market_pool_LinearInterestRateModelContract.LinearInterestRateModelContract;
85
+ exports.MAX_LEVERAGE_BUFFER_BPS = require_sdk_market_math.MAX_LEVERAGE_BUFFER_BPS;
83
86
  exports.MarketRegister = require_sdk_market_MarketRegister.MarketRegister;
84
87
  exports.MarketSuite = require_sdk_market_MarketSuite.MarketSuite;
85
88
  exports.MellowLRTPriceFeedContract = require_sdk_market_pricefeeds_MellowLRTPriceFeed.MellowLRTPriceFeedContract;
86
89
  exports.MidasLiquidatorContract = require_sdk_market_rwa_midas_MidasLiquidatorContract.MidasLiquidatorContract;
90
+ exports.NON_STRATEGY_PHANTOM_TOKEN_TYPES = require_sdk_market_credit_isStrategyCollateral.NON_STRATEGY_PHANTOM_TOKEN_TYPES;
91
+ exports.PARTIAL_LIQUIDATION_BUFFER_BPS = require_sdk_market_math.PARTIAL_LIQUIDATION_BUFFER_BPS;
87
92
  exports.PHANTOM_TOKEN_MIDAS_REDEMPTION = require_sdk_market_rwa_midas_constants.PHANTOM_TOKEN_MIDAS_REDEMPTION;
88
93
  exports.PHANTOM_TOKEN_SECURITIZE_REDEMPTION = require_sdk_market_rwa_securitize_constants.PHANTOM_TOKEN_SECURITIZE_REDEMPTION;
89
94
  exports.PartialPriceFeedInitError = require_sdk_market_pricefeeds_AbstractPriceFeed.PartialPriceFeedInitError;
@@ -109,6 +114,11 @@ exports.WstETHPriceFeedContract = require_sdk_market_pricefeeds_WstETHPriceFeed.
109
114
  exports.YearnPriceFeedContract = require_sdk_market_pricefeeds_YearnPriceFeed.YearnPriceFeedContract;
110
115
  exports.ZapperContract = require_sdk_market_zapper_ZapperContract.ZapperContract;
111
116
  exports.ZeroPriceFeedContract = require_sdk_market_pricefeeds_ZeroPriceFeed.ZeroPriceFeedContract;
117
+ exports.calcAdditionalBorrowApy = require_sdk_market_math.calcAdditionalBorrowApy;
118
+ exports.calcBorrowApy = require_sdk_market_math.calcBorrowApy;
119
+ exports.calcMaxLeverage = require_sdk_market_math.calcMaxLeverage;
120
+ exports.calcPositionLeverage = require_sdk_market_math.calcPositionLeverage;
121
+ exports.calcUtilization = require_sdk_market_math.calcUtilization;
112
122
  exports.createAdapter = require_sdk_market_adapters_createAdapter.createAdapter;
113
123
  exports.createPriceOracle = require_sdk_market_oracle_createPriceOracle.createPriceOracle;
114
124
  exports.createZapper = require_sdk_market_zapper_createZapper.createZapper;
@@ -117,7 +127,14 @@ exports.dominantCollateral = require_sdk_market_credit_dominantCollateral.domina
117
127
  exports.expectedBalanceDeltas = require_sdk_market_credit_expectedBalanceDeltas.expectedBalanceDeltas;
118
128
  exports.fetchRedstonePayloads = require_sdk_market_pricefeeds_updates_fetchRedstonePayloads.fetchRedstonePayloads;
119
129
  exports.getRawPriceUpdates = require_sdk_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates;
130
+ exports.healthFactorBps = require_sdk_market_math.healthFactorBps;
120
131
  exports.isLPPriceFeed = require_sdk_market_pricefeeds_AbstractLPPriceFeed.isLPPriceFeed;
121
132
  exports.isRWAFactory = require_sdk_market_rwa_types.isRWAFactory;
133
+ exports.isStrategyCollateral = require_sdk_market_credit_isStrategyCollateral.isStrategyCollateral;
122
134
  exports.isUpdatablePriceFeed = require_sdk_market_pricefeeds_isUpdatablePriceFeed.isUpdatablePriceFeed;
135
+ exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
123
136
  exports.mustGetDominantCollateral = require_sdk_market_credit_dominantCollateral.mustGetDominantCollateral;
137
+ exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
138
+ exports.optimalRepaidAmount = require_sdk_market_math.optimalRepaidAmount;
139
+ exports.rayToBps = require_sdk_market_math.rayToBps;
140
+ exports.usdToNumber = require_sdk_market_math.usdToNumber;