@gearbox-protocol/sdk 15.1.0-next.5 → 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 (32) hide show
  1. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -2
  2. package/dist/cjs/sdk/index.js +9 -5
  3. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
  4. package/dist/cjs/sdk/market/credit/CreditSuite.js +17 -26
  5. package/dist/cjs/sdk/market/credit/index.js +3 -0
  6. package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
  7. package/dist/cjs/sdk/market/index.js +17 -0
  8. package/dist/cjs/sdk/market/math.js +57 -44
  9. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +1 -1
  10. package/dist/cjs/sdk/opportunities/index.js +0 -13
  11. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +3 -3
  12. package/dist/esm/sdk/index.js +3 -2
  13. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
  14. package/dist/esm/sdk/market/credit/CreditSuite.js +18 -27
  15. package/dist/esm/sdk/market/credit/index.js +2 -1
  16. package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
  17. package/dist/esm/sdk/market/index.js +3 -1
  18. package/dist/esm/sdk/market/math.js +52 -40
  19. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -2
  20. package/dist/esm/sdk/opportunities/index.js +1 -2
  21. package/dist/types/model/opportunities.d.ts +9 -9
  22. package/dist/types/model/positions.d.ts +3 -3
  23. package/dist/types/sdk/index.d.ts +3 -2
  24. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
  25. package/dist/types/sdk/market/credit/CreditSuite.d.ts +2 -16
  26. package/dist/types/sdk/market/credit/index.d.ts +2 -1
  27. package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
  28. package/dist/types/sdk/market/credit/types.d.ts +2 -9
  29. package/dist/types/sdk/market/index.d.ts +3 -1
  30. package/dist/types/sdk/market/math.d.ts +44 -34
  31. package/dist/types/sdk/opportunities/index.d.ts +1 -2
  32. package/package.json +1 -1
@@ -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
  /**
@@ -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;
@@ -16,7 +16,8 @@ const FULL = Number(require_sdk_constants_math.PERCENTAGE_FACTOR);
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
- * rayToBps(50_000_000_000_000_000_000_000_000n) // 500, i.e. 5%
19
+ * // ray: 5% (0.05 × 10²⁷)
20
+ * rayToBps(50_000_000_000_000_000_000_000_000n) // 500 bps = 5%
20
21
  * ```
21
22
  **/
22
23
  function rayToBps(ray) {
@@ -27,6 +28,7 @@ function rayToBps(ray) {
27
28
  *
28
29
  * @example
29
30
  * ```ts
31
+ * // usd: $1500.50 in 8-decimal fixed point
30
32
  * usdToNumber(150_050_000_000n) // 1500.5
31
33
  * ```
32
34
  **/
@@ -39,56 +41,66 @@ function usdToNumber(usd) {
39
41
  *
40
42
  * @example
41
43
  * ```ts
42
- * utilizationBps(750n, 1000n) // 7500, i.e. 75%
44
+ * // borrowed: 750, total: 1000
45
+ * calcUtilization(750n, 1000n) // 750 / 1000 = 7500 bps = 75%
43
46
  * ```
44
47
  **/
45
- function utilizationBps(borrowed, total) {
48
+ function calcUtilization(borrowed, total) {
46
49
  if (total <= 0n || borrowed <= 0n) return 0;
47
50
  const utilization = Number(borrowed * require_sdk_constants_math.PERCENTAGE_FACTOR / total);
48
51
  return Math.min(utilization, FULL);
49
52
  }
50
53
  /**
51
- * Annual cost of debt for a credit manager, in basis points: the pool's base
52
- * rate plus the protocol's cut of the accrued interest.
54
+ * Annual cost of debt for a credit manager, in basis points:
55
+ * `baseInterestRate × (1 + feeInterest)` — the pool's base rate plus the
56
+ * protocol's cut of the accrued interest.
53
57
  *
54
58
  * @param baseInterestRate - Pool base rate in ray.
55
59
  * @param feeInterest - Credit manager interest fee in basis points.
56
60
  *
57
61
  * @example
58
62
  * ```ts
59
- * // 5% base rate, 50% interest fee
60
- * borrowApyBps(50_000_000_000_000_000_000_000_000n, 5000) // 750, i.e. 7.5%
63
+ * // baseInterestRate: 5% in ray, feeInterest: 5000 bps = 50%
64
+ * calcBorrowApy(50_000_000_000_000_000_000_000_000n, 5000) // 5% × 1.5 = 750 bps = 7.5%
61
65
  * ```
62
66
  **/
63
- function borrowApyBps(baseInterestRate, feeInterest) {
67
+ function calcBorrowApy(baseInterestRate, feeInterest) {
64
68
  return rayToBps(baseInterestRate * (require_sdk_constants_math.PERCENTAGE_FACTOR + BigInt(feeInterest)) / require_sdk_constants_math.PERCENTAGE_FACTOR);
65
69
  }
66
70
  /**
67
- * Highest leverage a liquidation threshold allows: `1 / (1 - lt)`.
68
- *
69
- * A threshold of 100% or more would allow unbounded leverage; such tokens are
70
- * not strategies and are filtered out before this is called, so the guard here
71
- * only exists to keep the function total.
71
+ * 5% safety margin subtracted from 100% in {@link calcMaxLeverage}, so a
72
+ * maxed position opens with HF slightly above 1.
73
+ **/
74
+ const MAX_LEVERAGE_BUFFER_BPS = 500;
75
+ /**
76
+ * Highest total-value leverage a liquidation threshold allows:
77
+ * `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
78
+ * `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
79
+ * equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
80
+ * keeps the maxed position slightly away from that boundary.
72
81
  *
73
82
  * @example
74
83
  * ```ts
75
- * maxLeverage(9000) // 10
76
- * maxLeverage(8000) // 5
84
+ * // liquidationThreshold: 9000 bps = 90%
85
+ * calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
77
86
  * ```
78
87
  **/
79
- function maxLeverage(liquidationThreshold) {
80
- const equity = FULL - liquidationThreshold;
81
- return equity > 0 ? FULL / equity : Number.POSITIVE_INFINITY;
88
+ function calcMaxLeverage(liquidationThreshold) {
89
+ if (liquidationThreshold >= FULL) return 0;
90
+ const leverage = (FULL - 500) / (FULL - liquidationThreshold);
91
+ return Math.max(leverage, 1);
82
92
  }
83
93
  /**
84
94
  * Converts a credit account's health factor from the 18-decimal fixed point the
85
95
  * contracts store to basis points.
86
96
  *
87
- * An account with no debt return MAX_UINT256 from contract, here we return 0
97
+ * Accounts with no debt store `MAX_UINT256` on-chain; for those this
98
+ * returns `0`.
88
99
  *
89
100
  * @example
90
101
  * ```ts
91
- * healthFactorBps(1_250_000_000_000_000_000n) // 12500, i.e. 1.25
102
+ * // healthFactor: 1.25 in 18-decimal fixed point
103
+ * healthFactorBps(1_250_000_000_000_000_000n) // 12500 bps = 1.25
92
104
  * ```
93
105
  **/
94
106
  function healthFactorBps(healthFactor) {
@@ -96,39 +108,39 @@ function healthFactorBps(healthFactor) {
96
108
  return Number(healthFactor * require_sdk_constants_math.PERCENTAGE_FACTOR / require_sdk_constants_math.WAD);
97
109
  }
98
110
  /**
99
- * Leverage of an open position: `totalDebt / equity`, where equity is what is
100
- * left of the position's value once its debt is repaid.
101
- *
102
- * Returns `0` for a position that carries no debt and for one that is
103
- * underwater, where there is no equity to lever.
111
+ * Total-value leverage of an open position:
112
+ * `totalValue / (totalValue totalDebt)`. `1` when unleveraged, `0` when
113
+ * underwater.
104
114
  *
105
- * @param totalDebt - Debt principal plus accrued interest and fees.
106
- * @param totalValue - Total value of the position, in the same token.
115
+ * @param totalValue - Total value of the position.
116
+ * @param totalDebt - Debt principal plus accrued interest and fees, same token.
107
117
  *
108
118
  * @example
109
119
  * ```ts
110
- * positionLeverage(800n, 1000n) // 4, i.e. 4x debt per unit of equity
120
+ * // totalValue: 100k, totalDebt: 80k equity: 100k 80k = 20k
121
+ * calcPositionLeverage(100_000n, 80_000n) // 100k / 20k = 5x
111
122
  * ```
112
123
  **/
113
- function positionLeverage(totalDebt, totalValue) {
124
+ function calcPositionLeverage(totalValue, totalDebt) {
114
125
  const equity = totalValue - totalDebt;
115
- if (equity <= 0n || totalDebt <= 0n) return 0;
116
- return Number(totalDebt) / Number(equity);
126
+ if (totalValue <= 0n || equity <= 0n) return 0;
127
+ if (totalDebt <= 0n) return 1;
128
+ return Number(totalValue) / Number(equity);
117
129
  }
118
130
  /**
119
- * Annual quota cost scaled to the debt a maximally leveraged position carries,
120
- * in basis points. Every unit of own capital carries `maxLeverage - 1` units of
121
- * debt, and the quota is paid on the whole quoted position.
131
+ * Annual quota cost on equity, in basis points:
132
+ * `quotaRate × (1 + feeInterest) × leverage`. Quota accrues on the whole
133
+ * quoted position, and the DAO takes `feeInterest` of it as with base interest.
122
134
  *
123
135
  * @example
124
136
  * ```ts
125
- * // 2.5% quota rate at 5x leverage
126
- * additionalBorrowApyBps(250, 5) // 1000, i.e. 10%
137
+ * // quotaRate: 200 bps = 2%, feeInterest: 2500 bps = 25%, leverage: 9.5x
138
+ * calcAdditionalBorrowApy(200, 2500, 9.5) // 2% × 1.25 × 9.5 = 2375 bps = 23.75%
127
139
  * ```
128
140
  **/
129
- function additionalBorrowApyBps(quotaRate, leverage) {
130
- if (!Number.isFinite(leverage)) return 0;
131
- return Math.round(quotaRate * Math.max(leverage - 1, 0));
141
+ function calcAdditionalBorrowApy(quotaRate, feeInterest, leverage) {
142
+ if (!Number.isFinite(leverage) || leverage <= 0) return 0;
143
+ return Math.round(quotaRate * (1 + feeInterest / FULL) * leverage);
132
144
  }
133
145
  /**
134
146
  * {@link PERCENTAGE_FACTOR} less a 0.1% safety buffer.
@@ -186,15 +198,16 @@ function optimalHFForPartialLiquidation(borrowRate) {
186
198
  return require_sdk_constants_math.PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
187
199
  }
188
200
  //#endregion
201
+ exports.MAX_LEVERAGE_BUFFER_BPS = MAX_LEVERAGE_BUFFER_BPS;
189
202
  exports.PARTIAL_LIQUIDATION_BUFFER_BPS = PARTIAL_LIQUIDATION_BUFFER_BPS;
190
- exports.additionalBorrowApyBps = additionalBorrowApyBps;
191
- exports.borrowApyBps = borrowApyBps;
203
+ exports.calcAdditionalBorrowApy = calcAdditionalBorrowApy;
204
+ exports.calcBorrowApy = calcBorrowApy;
205
+ exports.calcMaxLeverage = calcMaxLeverage;
206
+ exports.calcPositionLeverage = calcPositionLeverage;
207
+ exports.calcUtilization = calcUtilization;
192
208
  exports.healthFactorBps = healthFactorBps;
193
- exports.maxLeverage = maxLeverage;
194
209
  exports.minSeizedAmount = minSeizedAmount;
195
210
  exports.optimalHFForPartialLiquidation = optimalHFForPartialLiquidation;
196
211
  exports.optimalRepaidAmount = optimalRepaidAmount;
197
- exports.positionLeverage = positionLeverage;
198
212
  exports.rayToBps = rayToBps;
199
213
  exports.usdToNumber = usdToNumber;
200
- exports.utilizationBps = utilizationBps;
@@ -51,7 +51,7 @@ var PoolV310Contract = class extends require_sdk_base_BaseContract.BaseContract
51
51
  * {@inheritDoc IPoolContract.utilization}
52
52
  */
53
53
  get utilization() {
54
- return require_sdk_market_math.utilizationBps(this.borrowed, this.expectedLiquidity);
54
+ return require_sdk_market_math.calcUtilization(this.borrowed, this.expectedLiquidity);
55
55
  }
56
56
  /**
57
57
  * {@inheritDoc IPoolContract.unwrappedUnderlying}
@@ -1,18 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk_market_math = require("../market/math.js");
3
2
  const require_sdk_opportunities_MultichainOpportunitiesService = require("./MultichainOpportunitiesService.js");
4
3
  const require_sdk_opportunities_OpportunitiesService = require("./OpportunitiesService.js");
5
4
  exports.MultichainOpportunitiesService = require_sdk_opportunities_MultichainOpportunitiesService.MultichainOpportunitiesService;
6
5
  exports.OpportunitiesService = require_sdk_opportunities_OpportunitiesService.OpportunitiesService;
7
- exports.PARTIAL_LIQUIDATION_BUFFER_BPS = require_sdk_market_math.PARTIAL_LIQUIDATION_BUFFER_BPS;
8
- exports.additionalBorrowApyBps = require_sdk_market_math.additionalBorrowApyBps;
9
- exports.borrowApyBps = require_sdk_market_math.borrowApyBps;
10
- exports.healthFactorBps = require_sdk_market_math.healthFactorBps;
11
- exports.maxLeverage = require_sdk_market_math.maxLeverage;
12
- exports.minSeizedAmount = require_sdk_market_math.minSeizedAmount;
13
- exports.optimalHFForPartialLiquidation = require_sdk_market_math.optimalHFForPartialLiquidation;
14
- exports.optimalRepaidAmount = require_sdk_market_math.optimalRepaidAmount;
15
- exports.positionLeverage = require_sdk_market_math.positionLeverage;
16
- exports.rayToBps = require_sdk_market_math.rayToBps;
17
- exports.usdToNumber = require_sdk_market_math.usdToNumber;
18
- exports.utilizationBps = require_sdk_market_math.utilizationBps;
@@ -9,7 +9,7 @@ import { hexEq } from "../../utils/hex.js";
9
9
  import "../../utils/index.js";
10
10
  import { SDKConstruct } from "../../base/SDKConstruct.js";
11
11
  import "../../base/index.js";
12
- import { borrowApyBps, healthFactorBps, positionLeverage, usdToNumber } from "../../market/math.js";
12
+ import { calcBorrowApy, calcPositionLeverage, healthFactorBps, usdToNumber } from "../../market/math.js";
13
13
  import { dominantCollateral } from "../../market/credit/dominantCollateral.js";
14
14
  import { simulateWithPriceUpdates } from "../../utils/viem/simulateWithPriceUpdates.js";
15
15
  import "../../utils/viem/index.js";
@@ -208,8 +208,8 @@ var CreditAccountCompressor = class extends SDKConstruct {
208
208
  creditAccount: ca.creditAccount,
209
209
  name: collateral ? suite.strategyName(collateral) : token.symbol,
210
210
  targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
211
- leverage: positionLeverage(totalDebtValue, ca.totalValue),
212
- borrowApy: borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
211
+ leverage: calcPositionLeverage(ca.totalValue, totalDebtValue),
212
+ borrowApy: calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
213
213
  totalDebt: {
214
214
  token,
215
215
  value: totalDebtValue,
@@ -49,9 +49,10 @@ import { createAdapter } from "./market/adapters/createAdapter.js";
49
49
  import { CreditConfiguratorV310Contract } from "./market/credit/CreditConfiguratorV310Contract.js";
50
50
  import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./market/credit/CreditFacadeV310BaseContract.js";
51
51
  import { CreditFacadeV310Contract } from "./market/credit/CreditFacadeV310Contract.js";
52
- import { PARTIAL_LIQUIDATION_BUFFER_BPS, additionalBorrowApyBps, borrowApyBps, healthFactorBps, maxLeverage, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, positionLeverage, rayToBps, usdToNumber, utilizationBps } from "./market/math.js";
52
+ import { MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./market/math.js";
53
53
  import { CreditManagerV310Contract } from "./market/credit/CreditManagerV310Contract.js";
54
54
  import { dominantCollateral, mustGetDominantCollateral } from "./market/credit/dominantCollateral.js";
55
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./market/credit/isStrategyCollateral.js";
55
56
  import { CreditSuite } from "./market/credit/CreditSuite.js";
56
57
  import { expectedBalanceDeltas } from "./market/credit/expectedBalanceDeltas.js";
57
58
  import { simulateMulticall } from "./utils/viem/simulateMulticall.js";
@@ -148,4 +149,4 @@ import { OnchainSDK, STATE_VERSION } from "./OnchainSDK.js";
148
149
  import { MultichainSDK } from "./MultichainSDK.js";
149
150
  import { attachOptionsSchema, onchainSDKOptionsSchema } from "./options.js";
150
151
  import "./types/index.js";
151
- export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PeripheryCompressorV310Contract, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex, additionalBorrowApyBps, assetsMap, attachOptionsSchema, borrowApyBps, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, executeMulticallBatches, expectedBalanceDeltas, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, maxLeverage, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, positionLeverage, primaryInstantOutput, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toChainIds, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, utilizationBps, watchBlocksAsync };
152
+ export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AccountBotsService, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_LEVERAGE_BUFFER_BPS, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainPositionsService, MultichainSDK, NATIVE_ADDRESS, NON_STRATEGY_PHANTOM_TOKEN_TYPES, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PeripheryCompressorV310Contract, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PositionsService, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodBigInt, ZodHex, assetsMap, attachOptionsSchema, botPermissionsToString, bytes32ToString, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, dominantCollateral, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, executeMulticallBatches, expectedBalanceDeltas, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, healthFactorBps, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isStrategyCollateral, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, minSeizedAmount, mustGetDominantCollateral, numberWithCommas, onchainSDKOptionsSchema, optimalHFForPartialLiquidation, optimalRepaidAmount, percentFmt, primaryInstantOutput, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toChainIds, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, watchBlocksAsync };
@@ -8,8 +8,7 @@ import { BaseContract } from "../../base/BaseContract.js";
8
8
  import "../../base/index.js";
9
9
  import { createAdapter } from "../adapters/createAdapter.js";
10
10
  import "../adapters/index.js";
11
- import { maxLeverage } from "../math.js";
12
- import { isAddressEqual } from "viem";
11
+ import { calcMaxLeverage } from "../math.js";
13
12
  //#region src/sdk/market/credit/CreditManagerV310Contract.ts
14
13
  const abi = iCreditManagerV310Abi;
15
14
  var CreditManagerV310Contract = class extends BaseContract {
@@ -64,20 +63,10 @@ var CreditManagerV310Contract = class extends BaseContract {
64
63
  return this.liquidationThresholds.keys();
65
64
  }
66
65
  /**
67
- * {@inheritDoc ICreditManagerContract.leverageableCollaterals}
68
- */
69
- get leverageableCollaterals() {
70
- return this.collateralTokens.filter((token) => {
71
- if (isAddressEqual(token, this.underlying)) return false;
72
- const lt = this.liquidationThresholds.get(token);
73
- return !!lt && lt > 0 && lt < Number(10000n);
74
- });
75
- }
76
- /**
77
66
  * {@inheritDoc ICreditManagerContract.maxLeverage}
78
67
  */
79
68
  maxLeverage(collateral) {
80
- return maxLeverage(this.liquidationThresholds.mustGet(collateral));
69
+ return calcMaxLeverage(this.liquidationThresholds.mustGet(collateral));
81
70
  }
82
71
  /**
83
72
  * {@inheritDoc ICreditManagerContract.liquidationPremium}