@gearbox-protocol/sdk 16.0.0-next.2 → 16.0.0-next.4

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 (55) hide show
  1. package/dist/cjs/dev/mode-parity/fieldDiff.js +1 -1
  2. package/dist/cjs/model/opportunities.schema.js +5 -5
  3. package/dist/cjs/sdk/chain/chains.js +1 -0
  4. package/dist/cjs/sdk/index.js +1 -0
  5. package/dist/cjs/sdk/market/MarketSuite.js +22 -20
  6. package/dist/cjs/sdk/market/credit/CreditSuite.js +24 -13
  7. package/dist/cjs/sdk/market/index.js +1 -0
  8. package/dist/cjs/sdk/market/math.js +10 -2
  9. package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -6
  10. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +0 -7
  11. package/dist/cjs/sdk/market/pool/math.js +1 -1
  12. package/dist/esm/dev/AccountOpener.js +1 -1
  13. package/dist/esm/dev/mode-parity/fieldDiff.js +1 -1
  14. package/dist/esm/dev/withdrawalUtils.js +1 -1
  15. package/dist/esm/model/opportunities.schema.js +5 -5
  16. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  17. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  18. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  19. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  20. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  21. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  22. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  23. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  24. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  25. package/dist/esm/sdk/chain/chains.js +1 -0
  26. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  27. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  28. package/dist/esm/sdk/index.js +2 -2
  29. package/dist/esm/sdk/market/MarketSuite.js +22 -20
  30. package/dist/esm/sdk/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  31. package/dist/esm/sdk/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  32. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  33. package/dist/esm/sdk/market/credit/CreditSuite.js +25 -14
  34. package/dist/esm/sdk/market/index.js +2 -2
  35. package/dist/esm/sdk/market/math.js +10 -3
  36. package/dist/esm/sdk/market/pool/PoolSuite.js +0 -6
  37. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -8
  38. package/dist/esm/sdk/market/pool/math.js +2 -2
  39. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  40. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  41. package/dist/esm/sdk/pools/PoolService.js +1 -1
  42. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  43. package/dist/types/dev/mode-parity/fieldDiff.d.ts +3 -3
  44. package/dist/types/model/opportunities.d.ts +27 -30
  45. package/dist/types/model/opportunities.schema.d.ts +56 -64
  46. package/dist/types/model/primitives.d.ts +1 -1
  47. package/dist/types/sdk/index.d.ts +2 -2
  48. package/dist/types/sdk/market/MarketSuite.d.ts +8 -5
  49. package/dist/types/sdk/market/credit/CreditSuite.d.ts +0 -7
  50. package/dist/types/sdk/market/index.d.ts +2 -2
  51. package/dist/types/sdk/market/math.d.ts +9 -4
  52. package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -5
  53. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +0 -6
  54. package/dist/types/sdk/market/pool/types.d.ts +0 -6
  55. package/package.json +1 -1
@@ -1,6 +1,5 @@
1
1
  import { AddressMap } from "../utils/AddressMap.js";
2
2
  import { isRWAToken, isSunsetPool } from "../chain/chains.js";
3
- import { PERCENTAGE_FACTOR } from "../constants/math.js";
4
3
  import "../utils/index.js";
5
4
  import { SDKConstruct } from "../base/SDKConstruct.js";
6
5
  import "../base/index.js";
@@ -17,6 +16,7 @@ import { createPriceOracle } from "./oracle/createPriceOracle.js";
17
16
  import "./oracle/index.js";
18
17
  import { PoolSuite } from "./pool/PoolSuite.js";
19
18
  import "./pool/index.js";
19
+ import { isAddressEqual } from "viem";
20
20
  //#region src/sdk/market/MarketSuite.ts
21
21
  /**
22
22
  * Aggregates all SDK wrappers that make up one Gearbox market.
@@ -136,20 +136,28 @@ var MarketSuite = class extends SDKConstruct {
136
136
  return this.configurator.curator;
137
137
  }
138
138
  /**
139
- * Tokens a position can actually be built on in this market, deduplicated
140
- * across its credit suites.
139
+ * Tokens a user can transfer from their wallet to deposit into this pool.
140
+ *
141
+ * 1. unwrapped underlying
142
+ * 2. tokenIn of every zapper (order does not matter), skipping the wrapped
143
+ * and unwrapped underlying
141
144
  */
142
- get collateralTokens() {
143
- const seen = new AddressMap(void 0, "collateralTokens");
144
- for (const suite of this.creditManagers) for (const collateral of suite.strategyCollaterals) seen.upsert(collateral, this.tokensMeta.mustGetToken(collateral));
145
+ get allowedDepositTokens() {
146
+ const seen = new AddressMap(void 0, "allowedDepositTokens");
147
+ seen.upsert(this.unwrappedUnderlying, this.underlyingToken);
148
+ for (const zapper of this.sdk.marketRegister.poolZappers(this.pool.pool.address)) {
149
+ const tokenIn = zapper.tokenIn.addr;
150
+ if (isAddressEqual(tokenIn, this.pool.underlying) || isAddressEqual(tokenIn, this.unwrappedUnderlying)) continue;
151
+ seen.upsert(tokenIn, this.tokensMeta.mustGetToken(tokenIn));
152
+ }
145
153
  return seen.values();
146
154
  }
147
155
  /**
148
- * Whether at least one of {@link collateralTokens} is a real-world-asset
149
- * token. Read from a hardcoded per-chain list rather than from the chain.
156
+ * Whether one of the market's quoted tokens is a real-world-asset token.
157
+ * Read from a hardcoded per-chain list rather than from the chain.
150
158
  */
151
159
  get rwa() {
152
- return this.collateralTokens.some((token) => isRWAToken(token.address, this.sdk.networkType));
160
+ return this.pool.pqk.quotas.keys().some((token) => isRWAToken(token, this.sdk.networkType));
153
161
  }
154
162
  /**
155
163
  * Whether this market's pool is being wound down and should no longer be
@@ -165,16 +173,11 @@ var MarketSuite = class extends SDKConstruct {
165
173
  quotaAssets() {
166
174
  const oracle = this.priceOracle;
167
175
  const { underlying } = this;
168
- const quotas = this.pool.pqk.quotas.entries();
169
- const sumUsed = quotas.reduce((sum, [, quota]) => sum + quota.totalQuoted, 0n);
170
- const { totalBorrowed } = this.pool.pool;
171
- return quotas.map(([token, quota]) => ({
176
+ return this.pool.pqk.quotas.entries().map(([token, quota]) => ({
172
177
  token: this.tokensMeta.mustGetToken(token),
173
178
  quotaRate: quota.rate,
174
179
  limit: oracle.toAmount(underlying, quota.limit),
175
- used: oracle.toAmount(underlying, quota.totalQuoted),
176
- allocationShare: sumUsed === 0n ? 0 : Number(quota.totalQuoted * PERCENTAGE_FACTOR / sumUsed),
177
- allocatedDebt: oracle.toAmount(underlying, sumUsed === 0n ? 0n : totalBorrowed * quota.totalQuoted / sumUsed)
180
+ used: oracle.toAmount(underlying, quota.totalQuoted)
178
181
  }));
179
182
  }
180
183
  /**
@@ -221,12 +224,11 @@ var MarketSuite = class extends SDKConstruct {
221
224
  name: this.poolName,
222
225
  curator: this.curator,
223
226
  underlyingToken: this.underlyingToken,
224
- totalSupply: oracle.toAmount(pool.underlying, pool.totalAssets),
227
+ totalSupply: oracle.toAmount(pool.underlying, pool.expectedLiquidity),
225
228
  availableLiquidity: oracle.toAmount(pool.underlying, pool.availableLiquidity),
226
- totalBorrow: oracle.toAmount(pool.underlying, pool.totalBorrowed),
227
- utilization: pool.utilization,
229
+ totalBorrowedWithInterest: oracle.toAmount(pool.underlying, pool.borrowed),
228
230
  supplyApy: { organicApy: rayToBps(pool.supplyRate) },
229
- collateralTokens: this.collateralTokens,
231
+ allowedDepositTokens: this.allowedDepositTokens,
230
232
  paused: pool.isPaused,
231
233
  rwa: this.rwa,
232
234
  sunset: this.sunset,
@@ -1,5 +1,5 @@
1
- import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
2
1
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
2
+ import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
3
3
  //#region src/sdk/market/adapters/contracts/AccountMigratorAdapterContract.ts
4
4
  const abi = accountMigratorAbi;
5
5
  const protocolAbi = accountMigratorAbi;
@@ -1,6 +1,6 @@
1
- import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
2
1
  import { MissingSerializedParamsError } from "../../../base/errors.js";
3
2
  import "../../../base/index.js";
3
+ import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
4
4
  import { iERC4626Abi } from "../abi/targetContractAbi.js";
5
5
  import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
6
6
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
@@ -1,7 +1,7 @@
1
- import { iPausableAbi } from "../../../abi/iPausable.js";
2
1
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
3
2
  import { BaseContract } from "../../base/BaseContract.js";
4
3
  import "../../base/index.js";
4
+ import { iPausableAbi } from "../../../abi/iPausable.js";
5
5
  //#region src/sdk/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -8,10 +8,11 @@ import { SDKConstruct } from "../../base/SDKConstruct.js";
8
8
  import "../../base/index.js";
9
9
  import { calcBorrowApy, calcQuotaRate, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount } from "../math.js";
10
10
  import { strategyName } from "../strategyName.js";
11
- import { dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral } from "./collateralUtils.js";
11
+ import { dominantCollateral, pickStrategyTargetCollateral } from "./collateralUtils.js";
12
12
  import createCreditConfigurator from "./createCreditConfigurator.js";
13
13
  import createCreditFacade from "./createCreditFacade.js";
14
14
  import createCreditManager from "./createCreditManager.js";
15
+ import { isAddressEqual } from "viem";
15
16
  //#region src/sdk/market/credit/CreditSuite.ts
16
17
  /**
17
18
  * Amount of underlying seeded into each pool at market creation to protect
@@ -177,17 +178,6 @@ var CreditSuite = class extends SDKConstruct {
177
178
  return this.creditFacade.isPaused || this.market.pool.isPaused;
178
179
  }
179
180
  /**
180
- * Collateral tokens a leveraged position can be built around in this suite,
181
- * see {@link isStrategyCollateral} for the per-token criteria. Tokens the
182
- * facade has forbidden are excluded — they cannot be taken on — even when
183
- * they still pass the shared eligibility rule used for target selection.
184
- */
185
- get strategyCollaterals() {
186
- if (this.maxBorrowAmount <= MIN_STRATEGY_BORROW_AMOUNT) return [];
187
- const forbidden = new Set(this.forbiddenTokens);
188
- return this.creditManager.collateralTokens.filter((token) => !forbidden.has(token) && isStrategyCollateral(this.#strategyCollateralProps(token), true));
189
- }
190
- /**
191
181
  * Tokens forbidden by the facade.
192
182
  */
193
183
  get forbiddenTokens() {
@@ -257,8 +247,8 @@ var CreditSuite = class extends SDKConstruct {
257
247
  name: this.strategyName ?? this.market.underlyingToken.symbol,
258
248
  curator: market.curator,
259
249
  underlyingToken: market.underlyingToken,
260
- totalBorrow: oracle.toAmount(pool.underlying, borrowed),
261
- collateralTokens: this.strategyCollaterals.map((t) => this.tokensMeta.mustGetToken(t)),
250
+ totalBorrowed: oracle.toAmount(pool.underlying, borrowed),
251
+ allowedDepositTokens: this.#allowedDepositTokens(collateral),
262
252
  paused: this.isPaused,
263
253
  rwa: market.rwa,
264
254
  sunset: market.sunset || isSunsetStrategy(cm.address, this.sdk.networkType),
@@ -327,6 +317,27 @@ var CreditSuite = class extends SDKConstruct {
327
317
  return collateral;
328
318
  }
329
319
  /**
320
+ * Tokens a user can transfer from their wallet when opening an account in
321
+ * this suite:
322
+ *
323
+ * 1. unwrapped underlying (USDC, never dcUSDC)
324
+ * 2. target collateral
325
+ * 3. remaining CM collaterals in manager order, no phantoms
326
+ */
327
+ #allowedDepositTokens(targetCollateral) {
328
+ const unwrappedUnderlying = this.market.unwrappedUnderlying;
329
+ const contractUnderlying = this.underlying;
330
+ const skip = (token) => isAddressEqual(token, unwrappedUnderlying) || isAddressEqual(token, contractUnderlying) || isAddressEqual(token, targetCollateral);
331
+ return [
332
+ unwrappedUnderlying,
333
+ targetCollateral,
334
+ ...this.creditManager.collateralTokens.filter((token) => {
335
+ const contractType = this.tokensMeta.mustGet(token).contractType;
336
+ return !skip(token) && !contractType?.startsWith("PHANTOM_TOKEN::");
337
+ })
338
+ ].map((token) => this.tokensMeta.mustGetToken(token));
339
+ }
340
+ /**
330
341
  * Shared inputs of {@link isStrategyCollateral} for one of this suite's
331
342
  * collateral tokens.
332
343
  */
@@ -87,7 +87,7 @@ import "./adapters/index.js";
87
87
  import { CreditConfiguratorV310Contract } from "./credit/CreditConfiguratorV310Contract.js";
88
88
  import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./credit/CreditFacadeV310BaseContract.js";
89
89
  import { CreditFacadeV310Contract } from "./credit/CreditFacadeV310Contract.js";
90
- import { DEFAULT_QUOTA_BUFFER_BPS, MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, bpsToRay, calcBorrowApy, calcEffectiveBorrowApy, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./math.js";
90
+ import { DEFAULT_QUOTA_BUFFER_BPS, MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, bpsToRay, calcBorrowApy, calcEffectiveBorrowApy, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcUtilization, calcUtilizationRaw, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./math.js";
91
91
  import { CreditManagerV310Contract } from "./credit/CreditManagerV310Contract.js";
92
92
  import { strategyName } from "./strategyName.js";
93
93
  import { dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral } from "./credit/collateralUtils.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, DEFAULT_QUOTA_BUFFER_BPS, 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, 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, bpsToRay, calcBorrowApy, calcEffectiveBorrowApy, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, 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 };
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, DEFAULT_QUOTA_BUFFER_BPS, 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, 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, bpsToRay, calcBorrowApy, calcEffectiveBorrowApy, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcUtilization, calcUtilizationRaw, 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 };
@@ -60,15 +60,22 @@ function usdToNumber(usd) {
60
60
  * @example
61
61
  * ```ts
62
62
  * // borrowed: 750, total: 1000
63
- * calcUtilization(750n, 1000n) // 750 / 1000 = 7500 bps = 75%
63
+ * calcUtilizationRaw(750n, 1000n) // 750 / 1000 = 7500 bps = 75%
64
64
  * ```
65
65
  **/
66
- function calcUtilization(borrowed, total) {
66
+ function calcUtilizationRaw(borrowed, total) {
67
67
  if (total <= 0n || borrowed <= 0n) return 0;
68
68
  const utilization = Number(borrowed * PERCENTAGE_FACTOR / total);
69
69
  return Math.min(utilization, FULL);
70
70
  }
71
71
  /**
72
+ * Pool utilization: {@link PoolOpportunity.totalBorrowedWithInterest} as a
73
+ * share of {@link PoolOpportunity.totalSupply}, in basis points.
74
+ **/
75
+ function calcUtilization(poolOpportunity) {
76
+ return calcUtilizationRaw(poolOpportunity.totalBorrowedWithInterest.value, poolOpportunity.totalSupply.value);
77
+ }
78
+ /**
72
79
  * Annual cost of debt for a credit manager, in basis points:
73
80
  * `baseInterestRate × (1 + feeInterest)` — the pool's base rate plus the
74
81
  * protocol's cut of the accrued interest.
@@ -267,4 +274,4 @@ function optimalHFForPartialLiquidation(borrowRate) {
267
274
  return PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
268
275
  }
269
276
  //#endregion
270
- export { DEFAULT_QUOTA_BUFFER_BPS, MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, bpsToRay, calcBorrowApy, calcEffectiveBorrowApy, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber };
277
+ export { DEFAULT_QUOTA_BUFFER_BPS, MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, bpsToRay, calcBorrowApy, calcEffectiveBorrowApy, calcMaxLeverage, calcNetStrategyApy, calcPositionLeverage, calcQuotaRate, calcUtilization, calcUtilizationRaw, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber };
@@ -105,12 +105,6 @@ var PoolSuite = class extends SDKConstruct {
105
105
  return this.pool.unwrappedUnderlying;
106
106
  }
107
107
  /**
108
- * {@inheritDoc IPoolContract.utilization}
109
- */
110
- get utilization() {
111
- return this.pool.utilization;
112
- }
113
- /**
114
108
  * Whether the pool is paused, which blocks borrowing across every connected
115
109
  * credit suite.
116
110
  */
@@ -1,4 +1,3 @@
1
- import { iPausableAbi } from "../../../abi/iPausable.js";
2
1
  import { iPoolV310Abi } from "../../../abi/310/generated.js";
3
2
  import { AddressMap } from "../../utils/AddressMap.js";
4
3
  import { RAY } from "../../constants/math.js";
@@ -7,7 +6,7 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
7
6
  import "../../utils/index.js";
8
7
  import { BaseContract } from "../../base/BaseContract.js";
9
8
  import "../../base/index.js";
10
- import { calcUtilization } from "../math.js";
9
+ import { iPausableAbi } from "../../../abi/iPausable.js";
11
10
  //#region src/sdk/market/pool/PoolV310Contract.ts
12
11
  const abi = [...iPoolV310Abi, ...iPausableAbi];
13
12
  var PoolV310Contract = class extends BaseContract {
@@ -47,12 +46,6 @@ var PoolV310Contract = class extends BaseContract {
47
46
  return this.totalSupply * this.dieselRate / RAY;
48
47
  }
49
48
  /**
50
- * {@inheritDoc IPoolContract.utilization}
51
- */
52
- get utilization() {
53
- return calcUtilization(this.borrowed, this.expectedLiquidity);
54
- }
55
- /**
56
49
  * {@inheritDoc IPoolContract.unwrappedUnderlying}
57
50
  */
58
51
  get unwrappedUnderlying() {
@@ -1,5 +1,5 @@
1
1
  import { PERCENTAGE_FACTOR } from "../../constants/math.js";
2
- import { calcUtilization } from "../math.js";
2
+ import { calcUtilizationRaw } from "../math.js";
3
3
  //#region src/sdk/market/pool/math.ts
4
4
  const FULL = Number(PERCENTAGE_FACTOR);
5
5
  /**
@@ -28,7 +28,7 @@ function borrowRateAtUtilization(utilization, params) {
28
28
  **/
29
29
  function utilizationAfterLiquidityChange(expectedLiquidity, availableLiquidity, availableLiquidityChange) {
30
30
  const borrowed = expectedLiquidity - (availableLiquidity + availableLiquidityChange);
31
- return calcUtilization(borrowed, expectedLiquidity);
31
+ return calcUtilizationRaw(borrowed, expectedLiquidity);
32
32
  }
33
33
  /**
34
34
  * Rate depositors earn at a given utilization, in basis points: the interest
@@ -1,5 +1,5 @@
1
- import { iethZapperAbi } from "../../../abi/iETHZapper.js";
2
1
  import { ZapperContract } from "./ZapperContract.js";
2
+ import { iethZapperAbi } from "../../../abi/iETHZapper.js";
3
3
  //#region src/sdk/market/zapper/IETHZapperContract.ts
4
4
  const abi = iethZapperAbi;
5
5
  var IETHZapperContract = class extends ZapperContract {
@@ -1,6 +1,6 @@
1
- import { iZapperAbi } from "../../../abi/iZapper.js";
2
1
  import { BaseContract } from "../../base/BaseContract.js";
3
2
  import "../../base/index.js";
3
+ import { iZapperAbi } from "../../../abi/iZapper.js";
4
4
  import { UnsupportedZapperFunctionError } from "./errors.js";
5
5
  //#region src/sdk/market/zapper/ZapperContract.ts
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { ierc20Abi } from "../../abi/iERC20.js";
2
1
  import { AddressSet } from "../utils/AddressSet.js";
2
+ import { ierc20Abi } from "../../abi/iERC20.js";
3
3
  import "../constants/addresses.js";
4
4
  import { PERCENTAGE_FACTOR, RAY } from "../constants/math.js";
5
5
  import "../constants/index.js";
@@ -1,6 +1,6 @@
1
1
  import { errorAbis } from "../../../abi/errors.js";
2
- import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
3
2
  import { generateCastTraceCall } from "./cast.js";
3
+ import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
4
4
  import { simulateMulticall } from "./simulateMulticall.js";
5
5
  import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
6
6
  import { getAction, parseAccount } from "viem/utils";
@@ -26,7 +26,7 @@ type ExpectedDiffReason = "mode-scoped" | "tolerance";
26
26
  interface FieldDiff {
27
27
  /**
28
28
  * Dotted path into the row, with array elements keyed by their own identity
29
- * rather than by index, e.g. `collateralTokens[0xa0b8...].symbol`.
29
+ * rather than by index, e.g. `allowedDepositTokens[0xa0b8...].symbol`.
30
30
  **/
31
31
  path: string;
32
32
  /**
@@ -74,7 +74,7 @@ interface EntityFieldDiff {
74
74
  }
75
75
  /**
76
76
  * How often one field disagreed across all matched rows, with array keys
77
- * collapsed, e.g. `collateralTokens[].symbol`.
77
+ * collapsed, e.g. `allowedDepositTokens[].symbol`.
78
78
  **/
79
79
  interface DiffPathCount {
80
80
  path: string;
@@ -165,7 +165,7 @@ declare function withExpected(diff: FieldDiff, reason: ExpectedDiffReason): Fiel
165
165
  **/
166
166
  declare function countPaths(diffs: Iterable<EntityFieldDiff>): DiffPathCount[];
167
167
  /**
168
- * Collapse `collateralTokens[0xa0b8...].symbol` to `collateralTokens[].symbol`.
168
+ * Collapse `allowedDepositTokens[0xa0b8...].symbol` to `allowedDepositTokens[].symbol`.
169
169
  **/
170
170
  declare function collapseArrayKeys(path: string): string;
171
171
  /**
@@ -132,17 +132,11 @@ interface OpportunityBase {
132
132
  **/
133
133
  underlyingToken: Token;
134
134
  /**
135
- * Debt principal drawn against the opportunity: everything the pool has lent
136
- * out for a {@link PoolOpportunity} (`pool.totalBorrowed()`), only what the
137
- * strategy's credit manager has drawn for a {@link StrategyOpportunity}
138
- * (`pool.creditManagerBorrowed(creditManager)`).
135
+ * Tokens a user can transfer from their wallet to deposit into a pool
136
+ * position or to use when opening a credit account. They are not necessarily
137
+ * the pool underlying or credit-account collateral tokens.
139
138
  **/
140
- totalBorrow: Amount;
141
- /**
142
- * Tokens accepted as collateral, i.e. the tokens that have both a non-zero
143
- * liquidation threshold and a non-zero quota limit.
144
- **/
145
- collateralTokens: Token[];
139
+ allowedDepositTokens: Token[];
146
140
  /**
147
141
  * The contract's own pause flag: the pool for a {@link PoolOpportunity}, the
148
142
  * credit facade or the pool it borrows from for a
@@ -150,8 +144,8 @@ interface OpportunityBase {
150
144
  **/
151
145
  paused: boolean;
152
146
  /**
153
- * Whether at least one of {@link collateralTokens} is a real-world-asset
154
- * token. Read from a hardcoded per-chain list rather than from the chain.
147
+ * Whether one of the market's quoted tokens is a real-world-asset token.
148
+ * Read from a hardcoded per-chain list rather than from the chain.
155
149
  **/
156
150
  rwa: boolean;
157
151
  /**
@@ -174,10 +168,9 @@ interface PoolOpportunity extends OpportunityBase {
174
168
  **/
175
169
  pool: Address;
176
170
  /**
177
- * Size of the pool: the underlying its shares are worth, converted at the
178
- * current share rate, i.e. `pool.totalAssets()`. Denominated in the
179
- * underlying rather than in shares, so it is comparable with
180
- * {@link OpportunityBase.totalBorrow}.
171
+ * Size of the pool: deposits plus accrued interest, i.e.
172
+ * `pool.expectedLiquidity`. Denominated in the underlying rather than in
173
+ * shares, so it is comparable with {@link totalBorrowedWithInterest}.
181
174
  **/
182
175
  totalSupply: Amount;
183
176
  /**
@@ -185,11 +178,11 @@ interface PoolOpportunity extends OpportunityBase {
185
178
  **/
186
179
  availableLiquidity: Amount;
187
180
  /**
188
- * How much of the pool's capital is currently borrowed, in basis points.
189
- *
190
- * @example `7500` for 75% utilization
181
+ * Everything the pool has lent out plus accrued interest:
182
+ * `pool.expectedLiquidity - pool.availableLiquidity`. Denominated in the
183
+ * underlying.
191
184
  **/
192
- utilization: Bps;
185
+ totalBorrowedWithInterest: Amount;
193
186
  /**
194
187
  * Yield earned by supplying to the pool.
195
188
  *
@@ -226,6 +219,12 @@ interface StrategyOpportunity extends OpportunityBase {
226
219
  * Collateral token the position is built around.
227
220
  **/
228
221
  targetCollateral: Token;
222
+ /**
223
+ * Debt principal this credit manager has drawn from the pool
224
+ * (`pool.creditManagerBorrowed(creditManager)`). Denominated in the
225
+ * underlying.
226
+ **/
227
+ totalBorrowed: Amount;
229
228
  /**
230
229
  * Liquidation threshold of {@link targetCollateral} in this credit manager,
231
230
  * in basis points: the share of the collateral value that counts towards
@@ -310,7 +309,7 @@ interface StrategyOpportunity extends OpportunityBase {
310
309
  totalValue?: Amount;
311
310
  /**
312
311
  * Share of {@link totalValue} that is borrowed, in basis points:
313
- * `totalBorrow / totalValue`.
312
+ * `totalBorrowed / totalValue`.
314
313
  *
315
314
  * Absent in `onchain` mode, because its denominator is, see
316
315
  * {@link totalValue}.
@@ -499,19 +498,17 @@ interface QuotaAsset {
499
498
  **/
500
499
  used: Amount;
501
500
  /**
502
- * This token's share of the pool's used quota, in basis points:
503
- * `used / Σ used` over every quota asset of the pool. Zero when nothing is
504
- * quoted.
501
+ * TODO: add description
505
502
  *
506
- * @example `2500` for 25% of the quoted amount
503
+ * @mode offchain
507
504
  **/
508
- allocationShare: Bps;
505
+ allocationShare?: Bps;
509
506
  /**
510
- * Estimate of how much of the pool's {@link OpportunityBase.totalBorrow}
511
- * backs this collateral: {@link allocationShare} applied to the pool's
512
- * total borrowed amount, denominated in the underlying.
507
+ * TODO: add description
508
+ *
509
+ * @mode offchain
513
510
  **/
514
- allocatedDebt: Amount;
511
+ allocatedDebt?: Amount;
515
512
  }
516
513
  /**
517
514
  * A price feed and the feeds it is composed of.