@gearbox-protocol/sdk 17.0.0-next.2 → 17.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 (37) hide show
  1. package/dist/cjs/onchain/accounts/intents/guards.js +4 -4
  2. package/dist/cjs/onchain/market/credit/CreditSuite.js +7 -3
  3. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +1 -1
  4. package/dist/cjs/onchain/validation/bundles/checkDraw.js +3 -3
  5. package/dist/cjs/onchain/validation/checkSimulation.js +10 -4
  6. package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +2 -5
  7. package/dist/esm/dev/AccountOpener.js +1 -1
  8. package/dist/esm/dev/withdrawalUtils.js +1 -1
  9. package/dist/esm/history/trace/extractTransfers.js +1 -1
  10. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  11. package/dist/esm/onchain/accounts/intents/guards.js +4 -4
  12. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  13. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  14. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  15. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  16. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  17. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  18. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  19. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  20. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  21. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  22. package/dist/esm/onchain/market/credit/CreditSuite.js +7 -3
  23. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  24. package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
  25. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  26. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  27. package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +2 -2
  28. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  29. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +1 -1
  30. package/dist/esm/onchain/validation/bundles/checkDraw.js +3 -3
  31. package/dist/esm/onchain/validation/checkSimulation.js +10 -4
  32. package/dist/esm/onchain/validation/checks/checkDebtLimits.js +2 -5
  33. package/dist/types/model/errors/operation-errors.d.ts +3 -4
  34. package/dist/types/onchain/market/credit/types.d.ts +2 -2
  35. package/dist/types/onchain/validation/checkSimulation.d.ts +6 -3
  36. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +1 -1
  37. package/package.json +1 -1
@@ -44,13 +44,13 @@ function assertMarketOperable(suite) {
44
44
  }
45
45
  /** The pool has to be able to lend what the plan means to draw. */
46
46
  function assertCanBorrow(sdk, suite, amount) {
47
- const { value, limit } = suite.maxBorrowAmount();
47
+ const maxBorrowAmount = suite.maxBorrowAmount();
48
48
  require_onchain_validation_raise.raise(require_onchain_validation_checks_checkBorrowLimit.checkBorrowLimit({
49
49
  requested: amount,
50
- available: value,
51
- limit,
50
+ available: maxBorrowAmount.amount.value,
51
+ limit: maxBorrowAmount.limit,
52
52
  underlying: require_onchain_validation_helpers_token.toToken(sdk, suite.market.pool.underlying)
53
- }), `borrow: ${amount} exceeds what the pool can lend now (${value})`);
53
+ }), `borrow: ${amount} exceeds what the pool can lend now (${maxBorrowAmount.amount.value})`);
54
54
  }
55
55
  /**
56
56
  * What the account is allowed to end up holding more of than it started with.
@@ -279,11 +279,11 @@ var CreditSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
279
279
  const { pool } = this.market.pool;
280
280
  const { maxDebtPerBlockMultiplier, maxDebt } = this.creditFacade;
281
281
  if (maxDebtPerBlockMultiplier === 0) return {
282
- value: 0n,
282
+ amount: this.market.toUnderlyingAmount(0n),
283
283
  limit: "debtPerBlockLimit"
284
284
  };
285
285
  const available = pool.creditManagerDebtParams.get(this.creditManager.address)?.available;
286
- return [
286
+ const { value, limit } = [
287
287
  {
288
288
  value: pool.availableLiquidity,
289
289
  limit: "poolAvailableLiquidity"
@@ -297,6 +297,10 @@ var CreditSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
297
297
  limit: "maxDebt"
298
298
  }
299
299
  ].reduce((a, b) => b.value < a.value ? b : a);
300
+ return {
301
+ amount: this.market.toUnderlyingAmount(value),
302
+ limit
303
+ };
300
304
  }
301
305
  /**
302
306
  * The single target collateral of this suite's strategy, or `undefined` when
@@ -355,7 +359,7 @@ var CreditSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
355
359
  * or `undefined` when credit suite does not offer a strategy opportunity.
356
360
  */
357
361
  strategyOpportunity() {
358
- const maxBorrowAmount = this.maxBorrowAmount().value;
362
+ const maxBorrowAmount = this.maxBorrowAmount().amount.value;
359
363
  if (maxBorrowAmount <= MIN_STRATEGY_BORROW_AMOUNT) return;
360
364
  const collateral = this.strategyTargetCollateral;
361
365
  if (!collateral) return;
@@ -34,7 +34,7 @@ async function checkCreditOperation(args) {
34
34
  maxDebt: suite.creditFacade.maxDebt,
35
35
  underlying,
36
36
  allowZero: !isOpening,
37
- ceiling: suite.maxBorrowAmount()
37
+ maxBorrowAmount: suite.maxBorrowAmount()
38
38
  }),
39
39
  ...require_onchain_validation_bundles_checkDraw.checkDraw(suite, preview, underlying),
40
40
  ...require_onchain_validation_bundles_checkObtained.checkObtained(suite, preview),
@@ -16,11 +16,11 @@ require("../checks/index.js");
16
16
  function checkDraw(suite, preview, underlying) {
17
17
  const drawn = preview.operation === "AdjustCreditAccount" ? preview.totalDebtChange.value : preview.totalDebt.value;
18
18
  if (drawn <= 0n) return [];
19
- const { value, limit } = suite.maxBorrowAmount();
19
+ const maxBorrowAmount = suite.maxBorrowAmount();
20
20
  return require_onchain_validation_checks_checkBorrowLimit.checkBorrowLimit({
21
21
  requested: drawn,
22
- available: value,
23
- limit,
22
+ available: maxBorrowAmount.amount.value,
23
+ limit: maxBorrowAmount.limit,
24
24
  underlying
25
25
  });
26
26
  }
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_onchain_validation_helpers_token = require("./helpers/token.js");
3
3
  require("./helpers/index.js");
4
4
  const require_onchain_validation_checks_checkDebtLimits = require("./checks/checkDebtLimits.js");
5
+ const require_onchain_validation_checks_checkQuotaCount = require("./checks/checkQuotaCount.js");
5
6
  require("./checks/index.js");
6
7
  const require_onchain_validation_bundles_checkAccountQuotas = require("./bundles/checkAccountQuotas.js");
7
8
  const require_onchain_validation_bundles_checkHealthFactors = require("./bundles/checkHealthFactors.js");
@@ -27,8 +28,10 @@ const require_onchain_validation_bundles_checkMarket = require("./bundles/checkM
27
28
  * touched. The engine performed all three during the walk, so a simulation that
28
29
  * came back `ok` has already passed them.
29
30
  *
30
- * A credit account only: a pool operation has no account to weigh, and the
31
- * three things its own state decides are read by `prepare` before it answers.
31
+ * A credit account only, opened or adjusted: a pool operation has no account
32
+ * to weigh, and the three things its own state decides are read by `prepare`
33
+ * before it answers. An opening names its quotas `averageQuota` — the branch
34
+ * the planner already weighed it as.
32
35
  */
33
36
  function checkSimulation(sdk, input, options = {}) {
34
37
  const { state } = input;
@@ -41,9 +44,12 @@ function checkSimulation(sdk, input, options = {}) {
41
44
  maxDebt: suite.creditFacade.maxDebt,
42
45
  underlying: require_onchain_validation_helpers_token.toToken(sdk, suite.market.pool.underlying),
43
46
  allowZero: true,
44
- ceiling: suite.maxBorrowAmount()
47
+ maxBorrowAmount: suite.maxBorrowAmount()
45
48
  }),
46
- ...require_onchain_validation_bundles_checkAccountQuotas.checkAccountQuotas(suite, state),
49
+ ..."averageQuota" in state ? require_onchain_validation_checks_checkQuotaCount.checkQuotaCount({
50
+ count: state.averageQuota.filter((q) => q.balance > 0n).length,
51
+ max: suite.creditManager.maxEnabledTokens
52
+ }) : require_onchain_validation_bundles_checkAccountQuotas.checkAccountQuotas(suite, state),
47
53
  ...require_onchain_validation_bundles_checkHealthFactors.checkHealthFactors(state, options)
48
54
  ];
49
55
  }
@@ -6,16 +6,13 @@ require("../helpers/index.js");
6
6
  //#region src/onchain/validation/checks/checkDebtLimits.ts
7
7
  /** A debt the facade would revert on. */
8
8
  function checkDebtLimits(args) {
9
- const { debt, minDebt, maxDebt, underlying, allowZero, ceiling } = args;
9
+ const { debt, minDebt, maxDebt, underlying, allowZero, maxBorrowAmount } = args;
10
10
  if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
11
11
  return [require_model_errors_operation_errors.debtOutOfRange({
12
12
  requested: require_onchain_validation_helpers_amount.amountOf(underlying, debt),
13
13
  minDebt: require_onchain_validation_helpers_amount.amountOf(underlying, minDebt),
14
14
  maxDebt: require_onchain_validation_helpers_amount.amountOf(underlying, maxDebt),
15
- ceiling: ceiling && {
16
- amount: require_onchain_validation_helpers_amount.amountOf(underlying, ceiling.value),
17
- limit: ceiling.limit
18
- }
15
+ maxBorrowAmount
19
16
  })];
20
17
  }
21
18
  //#endregion
@@ -1,5 +1,5 @@
1
- import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
2
1
  import { ierc20Abi } from "../abi/iERC20.js";
2
+ import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
3
3
  import { AddressMap } from "../onchain/utils/AddressMap.js";
4
4
  import { AddressSet } from "../onchain/utils/AddressSet.js";
5
5
  import { AssetsMap } from "../onchain/utils/AssetsMap.js";
@@ -1,6 +1,6 @@
1
+ import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
1
2
  import { getNetworkType } from "../onchain/chain/chains.js";
2
3
  import { getWithdrawalCompressorAddress } from "../onchain/accounts/withdrawal-compressor/addresses.js";
3
- import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
4
4
  import "../onchain/index.js";
5
5
  import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
6
6
  import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
@@ -1,5 +1,5 @@
1
- import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
2
1
  import { ierc20Abi } from "../../abi/iERC20.js";
2
+ import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
3
3
  import { AddressMap } from "../../onchain/utils/AddressMap.js";
4
4
  import "../../onchain/index.js";
5
5
  import { UnexpectedFacadeEventOrderError } from "./errors.js";
@@ -1,3 +1,5 @@
1
+ import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
+ import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
1
3
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
2
4
  import { ADDRESS_0X0 } from "../constants/addresses.js";
3
5
  import { MAX_UINT256 } from "../constants/math.js";
@@ -8,8 +10,6 @@ import "../base/index.js";
8
10
  import { AccountBotsService } from "./bots/AccountBotsService.js";
9
11
  import "./bots/index.js";
10
12
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
11
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
12
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
13
13
  import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
14
14
  import "../market/index.js";
15
15
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
@@ -43,13 +43,13 @@ function assertMarketOperable(suite) {
43
43
  }
44
44
  /** The pool has to be able to lend what the plan means to draw. */
45
45
  function assertCanBorrow(sdk, suite, amount) {
46
- const { value, limit } = suite.maxBorrowAmount();
46
+ const maxBorrowAmount = suite.maxBorrowAmount();
47
47
  raise(checkBorrowLimit({
48
48
  requested: amount,
49
- available: value,
50
- limit,
49
+ available: maxBorrowAmount.amount.value,
50
+ limit: maxBorrowAmount.limit,
51
51
  underlying: toToken(sdk, suite.market.pool.underlying)
52
- }), `borrow: ${amount} exceeds what the pool can lend now (${value})`);
52
+ }), `borrow: ${amount} exceeds what the pool can lend now (${maxBorrowAmount.amount.value})`);
53
53
  }
54
54
  /**
55
55
  * What the account is allowed to end up holding more of than it started with.
@@ -1,3 +1,4 @@
1
+ import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
1
2
  import { AddressSet } from "../../utils/AddressSet.js";
2
3
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
3
4
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -19,7 +20,6 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
19
20
  import "../../market/rwa/securitize/index.js";
20
21
  import "../../market/index.js";
21
22
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
22
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
23
23
  import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
24
24
  //#region src/onchain/accounts/liquidations/LiquidationsService.ts
25
25
  /**
@@ -1,9 +1,9 @@
1
+ import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
6
  import { decodeDelayedIntent } from "./intent-codec.js";
6
- import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
7
7
  //#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
8
8
  const abi = iRedemptionLoggerV310Abi;
9
9
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
4
4
  const abi = iWithdrawalCompressorV311Abi;
5
5
  /**
@@ -1,6 +1,6 @@
1
+ import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
1
2
  import { encodeDelayedIntent } from "./intent-codec.js";
2
3
  import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
3
- import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
4
4
  import { toWithdrawalStatus } from "./types.js";
5
5
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
6
6
  const abi = iWithdrawalCompressorV313Abi;
@@ -1,12 +1,12 @@
1
+ import { iExpirableAbi } from "../../abi/iExpirable.js";
2
+ import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
3
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
4
  import { AddressMap } from "../utils/AddressMap.js";
2
5
  import { AddressSet } from "../utils/AddressSet.js";
3
6
  import { bytes32ToString } from "../utils/bytes32ToString.js";
4
7
  import { getAssetType } from "../chain/chains.js";
5
8
  import { formatBN } from "../utils/formatter.js";
6
9
  import "../utils/index.js";
7
- import { iExpirableAbi } from "../../abi/iExpirable.js";
8
- import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
9
- import { iVersionAbi } from "../../abi/iVersion.js";
10
10
  import { SdkRWADataNotLoadedError } from "../core/errors.js";
11
11
  import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
12
12
  //#region src/onchain/base/TokensMeta.ts
@@ -1,8 +1,8 @@
1
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
2
  import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
2
3
  import { isV310 } from "../constants/versions.js";
3
4
  import "../constants/index.js";
4
5
  import { hexEq } from "../utils/hex.js";
5
- import { iVersionAbi } from "../../abi/iVersion.js";
6
6
  import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
7
7
  //#region src/onchain/core/createAddressProvider.ts
8
8
  const OVERRIDE_ADDRESSES = { Mainnet: {
@@ -1,5 +1,5 @@
1
- import { AbstractAdapterContract } from "./AbstractAdapter.js";
2
1
  import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
2
+ import { AbstractAdapterContract } from "./AbstractAdapter.js";
3
3
  //#region src/onchain/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";
1
2
  import { MissingSerializedParamsError } from "../../../base/errors.js";
2
3
  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";
1
2
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
2
3
  import { BaseContract } from "../../base/BaseContract.js";
3
4
  import "../../base/index.js";
4
- import { iPausableAbi } from "../../../abi/iPausable.js";
5
5
  //#region src/onchain/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -278,11 +278,11 @@ var CreditSuite = class extends SDKConstruct {
278
278
  const { pool } = this.market.pool;
279
279
  const { maxDebtPerBlockMultiplier, maxDebt } = this.creditFacade;
280
280
  if (maxDebtPerBlockMultiplier === 0) return {
281
- value: 0n,
281
+ amount: this.market.toUnderlyingAmount(0n),
282
282
  limit: "debtPerBlockLimit"
283
283
  };
284
284
  const available = pool.creditManagerDebtParams.get(this.creditManager.address)?.available;
285
- return [
285
+ const { value, limit } = [
286
286
  {
287
287
  value: pool.availableLiquidity,
288
288
  limit: "poolAvailableLiquidity"
@@ -296,6 +296,10 @@ var CreditSuite = class extends SDKConstruct {
296
296
  limit: "maxDebt"
297
297
  }
298
298
  ].reduce((a, b) => b.value < a.value ? b : a);
299
+ return {
300
+ amount: this.market.toUnderlyingAmount(value),
301
+ limit
302
+ };
299
303
  }
300
304
  /**
301
305
  * The single target collateral of this suite's strategy, or `undefined` when
@@ -354,7 +358,7 @@ var CreditSuite = class extends SDKConstruct {
354
358
  * or `undefined` when credit suite does not offer a strategy opportunity.
355
359
  */
356
360
  strategyOpportunity() {
357
- const maxBorrowAmount = this.maxBorrowAmount().value;
361
+ const maxBorrowAmount = this.maxBorrowAmount().amount.value;
358
362
  if (maxBorrowAmount <= MIN_STRATEGY_BORROW_AMOUNT) return;
359
363
  const collateral = this.strategyTargetCollateral;
360
364
  if (!collateral) return;
@@ -1,3 +1,4 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iPoolV310Abi } from "../../../abi/310/generated.js";
2
3
  import { AddressMap } from "../../utils/AddressMap.js";
3
4
  import { RAY } from "../../constants/math.js";
@@ -7,7 +8,6 @@ import "../../utils/index.js";
7
8
  import { SdkRWADataNotLoadedError } from "../../core/errors.js";
8
9
  import { BaseContract } from "../../base/BaseContract.js";
9
10
  import "../../base/index.js";
10
- import { iPausableAbi } from "../../../abi/iPausable.js";
11
11
  //#region src/onchain/market/pool/PoolV310Contract.ts
12
12
  const abi = [...iPoolV310Abi, ...iPausableAbi];
13
13
  var PoolV310Contract = class extends BaseContract {
@@ -1,6 +1,6 @@
1
+ import { iVersionAbi } from "../../../abi/iVersion.js";
1
2
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
2
3
  import "../../utils/index.js";
3
- import { iVersionAbi } from "../../../abi/iVersion.js";
4
4
  import { iMidasDegenNFTAbi } from "../../../abi/rwa/iMidasDegenNFT.js";
5
5
  import { DEGEN_NFT_MIDAS } from "./midas/constants.js";
6
6
  import { MidasDegenNFT } from "./midas/MidasDegenNFT.js";
@@ -1,5 +1,5 @@
1
- import { ZapperContract } from "./ZapperContract.js";
2
1
  import { iethZapperAbi } from "../../../abi/iETHZapper.js";
2
+ import { ZapperContract } from "./ZapperContract.js";
3
3
  //#region src/onchain/market/zapper/IETHZapperContract.ts
4
4
  const abi = iethZapperAbi;
5
5
  var IETHZapperContract = class extends ZapperContract {
@@ -1,8 +1,8 @@
1
+ import { iZapperAbi } from "../../../abi/iZapper.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
- import { iZapperAbi } from "../../../abi/iZapper.js";
6
6
  //#region src/onchain/market/zapper/ZapperContract.ts
7
7
  /**
8
8
  * Base contract for every Gearbox zapper. Specialized zappers (e.g.
@@ -1,8 +1,8 @@
1
- import { iPoolV310Abi } from "../../../abi/310/generated.js";
2
1
  import { ierc20Abi } from "../../../abi/iERC20.js";
2
+ import { iZapperAbi } from "../../../abi/iZapper.js";
3
+ import { iPoolV310Abi } from "../../../abi/310/generated.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
- import { iZapperAbi } from "../../../abi/iZapper.js";
6
6
  //#region src/onchain/preview/preview/previewPoolPositionOperation.ts
7
7
  function previewRead(operation) {
8
8
  switch (operation.operation) {
@@ -1,6 +1,6 @@
1
1
  import { errorAbis } from "../../../abi/errors.js";
2
- import { generateCastTraceCall } from "./cast.js";
3
2
  import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
3
+ import { generateCastTraceCall } from "./cast.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";
@@ -33,7 +33,7 @@ async function checkCreditOperation(args) {
33
33
  maxDebt: suite.creditFacade.maxDebt,
34
34
  underlying,
35
35
  allowZero: !isOpening,
36
- ceiling: suite.maxBorrowAmount()
36
+ maxBorrowAmount: suite.maxBorrowAmount()
37
37
  }),
38
38
  ...checkDraw(suite, preview, underlying),
39
39
  ...checkObtained(suite, preview),
@@ -15,11 +15,11 @@ import "../checks/index.js";
15
15
  function checkDraw(suite, preview, underlying) {
16
16
  const drawn = preview.operation === "AdjustCreditAccount" ? preview.totalDebtChange.value : preview.totalDebt.value;
17
17
  if (drawn <= 0n) return [];
18
- const { value, limit } = suite.maxBorrowAmount();
18
+ const maxBorrowAmount = suite.maxBorrowAmount();
19
19
  return checkBorrowLimit({
20
20
  requested: drawn,
21
- available: value,
22
- limit,
21
+ available: maxBorrowAmount.amount.value,
22
+ limit: maxBorrowAmount.limit,
23
23
  underlying
24
24
  });
25
25
  }
@@ -1,6 +1,7 @@
1
1
  import { toToken } from "./helpers/token.js";
2
2
  import "./helpers/index.js";
3
3
  import { checkDebtLimits } from "./checks/checkDebtLimits.js";
4
+ import { checkQuotaCount } from "./checks/checkQuotaCount.js";
4
5
  import "./checks/index.js";
5
6
  import { checkAccountQuotas } from "./bundles/checkAccountQuotas.js";
6
7
  import { checkHealthFactors } from "./bundles/checkHealthFactors.js";
@@ -26,8 +27,10 @@ import { checkMarket } from "./bundles/checkMarket.js";
26
27
  * touched. The engine performed all three during the walk, so a simulation that
27
28
  * came back `ok` has already passed them.
28
29
  *
29
- * A credit account only: a pool operation has no account to weigh, and the
30
- * three things its own state decides are read by `prepare` before it answers.
30
+ * A credit account only, opened or adjusted: a pool operation has no account
31
+ * to weigh, and the three things its own state decides are read by `prepare`
32
+ * before it answers. An opening names its quotas `averageQuota` — the branch
33
+ * the planner already weighed it as.
31
34
  */
32
35
  function checkSimulation(sdk, input, options = {}) {
33
36
  const { state } = input;
@@ -40,9 +43,12 @@ function checkSimulation(sdk, input, options = {}) {
40
43
  maxDebt: suite.creditFacade.maxDebt,
41
44
  underlying: toToken(sdk, suite.market.pool.underlying),
42
45
  allowZero: true,
43
- ceiling: suite.maxBorrowAmount()
46
+ maxBorrowAmount: suite.maxBorrowAmount()
44
47
  }),
45
- ...checkAccountQuotas(suite, state),
48
+ ..."averageQuota" in state ? checkQuotaCount({
49
+ count: state.averageQuota.filter((q) => q.balance > 0n).length,
50
+ max: suite.creditManager.maxEnabledTokens
51
+ }) : checkAccountQuotas(suite, state),
46
52
  ...checkHealthFactors(state, options)
47
53
  ];
48
54
  }
@@ -5,16 +5,13 @@ import "../helpers/index.js";
5
5
  //#region src/onchain/validation/checks/checkDebtLimits.ts
6
6
  /** A debt the facade would revert on. */
7
7
  function checkDebtLimits(args) {
8
- const { debt, minDebt, maxDebt, underlying, allowZero, ceiling } = args;
8
+ const { debt, minDebt, maxDebt, underlying, allowZero, maxBorrowAmount } = args;
9
9
  if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
10
10
  return [debtOutOfRange({
11
11
  requested: amountOf(underlying, debt),
12
12
  minDebt: amountOf(underlying, minDebt),
13
13
  maxDebt: amountOf(underlying, maxDebt),
14
- ceiling: ceiling && {
15
- amount: amountOf(underlying, ceiling.value),
16
- limit: ceiling.limit
17
- }
14
+ maxBorrowAmount
18
15
  })];
19
16
  }
20
17
  //#endregion
@@ -1,6 +1,8 @@
1
1
  import { Bps, Token, TokenAmount } from "../primitives.js";
2
2
  import { IGearboxError } from "./base.js";
3
3
  import { RWAMissingOpenAccountRequirements, RWAOpenAccountRequirements } from "../rwa.js";
4
+ import { MaxBorrowAmount } from "../../onchain/market/credit/types.js";
5
+ import "../../onchain/index.js";
4
6
  import { Address } from "viem";
5
7
  //#region src/model/errors/operation-errors.d.ts
6
8
  /**
@@ -83,10 +85,7 @@ interface DebtOutOfRangeError extends IGearboxError {
83
85
  minDebt: TokenAmount;
84
86
  maxDebt: TokenAmount;
85
87
  /** What the market will really lend; absent where the raiser only throws. */
86
- ceiling?: {
87
- amount: TokenAmount;
88
- limit: BorrowLimitCause;
89
- };
88
+ maxBorrowAmount?: MaxBorrowAmount;
90
89
  }
91
90
  /** {@inheritDoc DebtOutOfRangeError} */
92
91
  declare function debtOutOfRange(args: Omit<DebtOutOfRangeError, "code" | "message">): DebtOutOfRangeError;
@@ -1,4 +1,4 @@
1
- import { Bps, Leverage } from "../../../model/primitives.js";
1
+ import { Bps, Leverage, TokenAmount } from "../../../model/primitives.js";
2
2
  import { BorrowLimitCause } from "../../../model/errors/operation-errors.js";
3
3
  import "../../../model/index.js";
4
4
  import { AddressMap } from "../../utils/AddressMap.js";
@@ -25,7 +25,7 @@ interface ICreditConfiguratorContract extends IBaseContract {
25
25
  **/
26
26
  interface MaxBorrowAmount {
27
27
  /** In the pool's underlying. */
28
- value: bigint;
28
+ amount: TokenAmount;
29
29
  /** The limit {@link value} ran into; see {@link BorrowLimitCause}. */
30
30
  limit: BorrowLimitCause;
31
31
  }
@@ -3,13 +3,14 @@ import { DebtOutOfRangeError, InsufficientCollateralError, QuotaCountExceededErr
3
3
  import "../../model/index.js";
4
4
  import { OnchainSDK } from "../OnchainSDK.js";
5
5
  import { OperationState } from "../accounts/intents/types.js";
6
+ import { OpenStrategyState } from "../accounts/intents/open-strategy.js";
6
7
  import { HealthFactorThresholds } from "./bundles/checkHealthFactors.js";
7
8
  import { MarketStateError } from "./bundles/checkMarket.js";
8
9
  //#region src/onchain/validation/checkSimulation.d.ts
9
10
  /** A simulated credit operation, as the intents engine reports one. */
10
11
  interface CreditSimulationInput {
11
12
  chainId: ChainId;
12
- state: OperationState;
13
+ state: OperationState | OpenStrategyState;
13
14
  }
14
15
  type CheckSimulationInput = CreditSimulationInput;
15
16
  /** {@inheritDoc checkSimulation} */
@@ -34,8 +35,10 @@ type SimulationValidationError = MarketStateError | DebtOutOfRangeError | QuotaC
34
35
  * touched. The engine performed all three during the walk, so a simulation that
35
36
  * came back `ok` has already passed them.
36
37
  *
37
- * A credit account only: a pool operation has no account to weigh, and the
38
- * three things its own state decides are read by `prepare` before it answers.
38
+ * A credit account only, opened or adjusted: a pool operation has no account
39
+ * to weigh, and the three things its own state decides are read by `prepare`
40
+ * before it answers. An opening names its quotas `averageQuota` — the branch
41
+ * the planner already weighed it as.
39
42
  */
40
43
  declare function checkSimulation(sdk: OnchainSDK, input: CheckSimulationInput, options?: HealthFactorThresholds): SimulationValidationError[];
41
44
  //#endregion
@@ -17,7 +17,7 @@ interface DebtLimitsArgs {
17
17
  */
18
18
  allowZero: boolean;
19
19
  /** From the caller's suite; a caller that raises to throw advises nobody. */
20
- ceiling?: MaxBorrowAmount;
20
+ maxBorrowAmount?: MaxBorrowAmount;
21
21
  }
22
22
  /** A debt the facade would revert on. */
23
23
  declare function checkDebtLimits(args: DebtLimitsArgs): DebtOutOfRangeError[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "17.0.0-next.2",
3
+ "version": "17.0.0-next.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {