@gearbox-protocol/sdk 17.0.0-next.3 → 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.
@@ -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
  }
@@ -44,7 +44,7 @@ function checkSimulation(sdk, input, options = {}) {
44
44
  maxDebt: suite.creditFacade.maxDebt,
45
45
  underlying: require_onchain_validation_helpers_token.toToken(sdk, suite.market.pool.underlying),
46
46
  allowZero: true,
47
- ceiling: suite.maxBorrowAmount()
47
+ maxBorrowAmount: suite.maxBorrowAmount()
48
48
  }),
49
49
  ..."averageQuota" in state ? require_onchain_validation_checks_checkQuotaCount.checkQuotaCount({
50
50
  count: state.averageQuota.filter((q) => q.balance > 0n).length,
@@ -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
@@ -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.
@@ -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;
@@ -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
  }
@@ -43,7 +43,7 @@ function checkSimulation(sdk, input, options = {}) {
43
43
  maxDebt: suite.creditFacade.maxDebt,
44
44
  underlying: toToken(sdk, suite.market.pool.underlying),
45
45
  allowZero: true,
46
- ceiling: suite.maxBorrowAmount()
46
+ maxBorrowAmount: suite.maxBorrowAmount()
47
47
  }),
48
48
  ..."averageQuota" in state ? checkQuotaCount({
49
49
  count: state.averageQuota.filter((q) => q.balance > 0n).length,
@@ -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
  }
@@ -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.3",
3
+ "version": "17.0.0-next.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {