@gearbox-protocol/sdk 16.3.2 → 16.4.0-next.2

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 (70) hide show
  1. package/dist/cjs/dev/midasUtils.js +11 -46
  2. package/dist/cjs/model/errors/index.js +1 -0
  3. package/dist/cjs/model/errors/operation-errors.js +9 -0
  4. package/dist/cjs/model/index.js +1 -0
  5. package/dist/cjs/onchain/accounts/intents/collateral-money.js +41 -0
  6. package/dist/cjs/onchain/accounts/intents/guards.js +15 -3
  7. package/dist/cjs/onchain/accounts/intents/index.js +21 -18
  8. package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +12 -38
  9. package/dist/cjs/onchain/accounts/intents/realize.js +10 -2
  10. package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
  11. package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +97 -0
  12. package/dist/cjs/onchain/index.js +2 -0
  13. package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +1 -1
  14. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +10 -16
  15. package/dist/cjs/onchain/preview/preview/previewOperation.js +19 -11
  16. package/dist/cjs/onchain/preview/preview/replayMulticall.js +4 -3
  17. package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  18. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +4 -3
  19. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +1 -2
  20. package/dist/cjs/onchain/validation/checkOperation.js +0 -1
  21. package/dist/cjs/onchain/validation/checks/checkReservePriceLimited.js +30 -0
  22. package/dist/cjs/onchain/validation/checks/index.js +2 -0
  23. package/dist/cjs/onchain/validation/index.js +2 -0
  24. package/dist/cjs/sdk/prepare/PrepareApi.js +3 -2
  25. package/dist/esm/dev/midasUtils.js +12 -47
  26. package/dist/esm/model/errors/index.js +2 -2
  27. package/dist/esm/model/errors/operation-errors.js +9 -1
  28. package/dist/esm/model/index.js +2 -2
  29. package/dist/esm/onchain/accounts/intents/collateral-money.js +40 -0
  30. package/dist/esm/onchain/accounts/intents/guards.js +15 -3
  31. package/dist/esm/onchain/accounts/intents/index.js +21 -18
  32. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +12 -38
  33. package/dist/esm/onchain/accounts/intents/realize.js +10 -2
  34. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  35. package/dist/esm/onchain/accounts/intents/withdraw-limits.js +95 -0
  36. package/dist/esm/onchain/index.js +2 -1
  37. package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +1 -1
  38. package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +11 -17
  39. package/dist/esm/onchain/preview/preview/previewOperation.js +19 -11
  40. package/dist/esm/onchain/preview/preview/replayMulticall.js +4 -3
  41. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  42. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +4 -3
  43. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +1 -2
  44. package/dist/esm/onchain/validation/checkOperation.js +0 -1
  45. package/dist/esm/onchain/validation/checks/checkReservePriceLimited.js +29 -0
  46. package/dist/esm/onchain/validation/checks/index.js +2 -1
  47. package/dist/esm/onchain/validation/index.js +2 -1
  48. package/dist/esm/sdk/prepare/PrepareApi.js +3 -2
  49. package/dist/types/dev/midasUtils.d.ts +3 -4
  50. package/dist/types/model/errors/index.d.ts +2 -2
  51. package/dist/types/model/errors/operation-errors.d.ts +41 -1
  52. package/dist/types/model/index.d.ts +3 -3
  53. package/dist/types/model/previews.d.ts +11 -20
  54. package/dist/types/onchain/accounts/intents/collateral-money.d.ts +42 -0
  55. package/dist/types/onchain/accounts/intents/guards.d.ts +18 -2
  56. package/dist/types/onchain/accounts/intents/index.d.ts +23 -14
  57. package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -8
  58. package/dist/types/onchain/accounts/intents/types.d.ts +26 -4
  59. package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +80 -0
  60. package/dist/types/onchain/index.d.ts +2 -1
  61. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +5 -3
  62. package/dist/types/onchain/preview/preview/replayMulticall.d.ts +8 -7
  63. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +2 -2
  64. package/dist/types/onchain/validation/checks/checkReservePriceLimited.d.ts +31 -0
  65. package/dist/types/onchain/validation/checks/index.d.ts +2 -1
  66. package/dist/types/onchain/validation/index.d.ts +2 -1
  67. package/dist/types/onchain/validation/raise.d.ts +2 -2
  68. package/dist/types/sdk/prepare/PrepareApi.d.ts +1 -1
  69. package/dist/types/sdk/prepare/types.d.ts +23 -16
  70. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import { Bps, TokenAmount } from "../../../model/primitives.js";
2
+ import { ReservePriceLimitedError } from "../../../model/errors/operation-errors.js";
3
+ import "../../../model/index.js";
4
+ //#region src/onchain/validation/checks/checkReservePriceLimited.d.ts
5
+ interface ReservePriceLimitedArgs {
6
+ /** The safe-price factor, the one the collateral check compared. */
7
+ healthFactor: Bps;
8
+ /** The same account at the main feed. */
9
+ atMainPrices: Bps;
10
+ /** The lowest acceptable factor — a factor equal to it passes. */
11
+ healthFactorThreshold: Bps;
12
+ /** What the account can still take out, in the market's underlying. */
13
+ withdrawable: TokenAmount;
14
+ }
15
+ /**
16
+ * Whether a failed collateral check is the reserve price feed's doing.
17
+ *
18
+ * A call that hands funds over is weighed at safe prices — `min` of a token's
19
+ * two feeds, and nothing at all where governance registered no reserve feed —
20
+ * so an account that covers its debt at the main feed can still be refused.
21
+ * The two are worth telling apart: a position that is genuinely too small is
22
+ * fixed by adding collateral or requesting less, while this one is a valuation
23
+ * the account does not control, and requesting less only helps as far as
24
+ * `withdrawable` says it does.
25
+ *
26
+ * Runs after `checkCollateralised` and answers only when that one refused, so
27
+ * the caller keeps its own threshold rather than restating it here.
28
+ */
29
+ declare function checkReservePriceLimited(args: ReservePriceLimitedArgs): ReservePriceLimitedError[];
30
+ //#endregion
31
+ export { ReservePriceLimitedArgs, checkReservePriceLimited };
@@ -13,4 +13,5 @@ import { PoolPausedArgs, checkPoolPaused } from "./checkPoolPaused.js";
13
13
  import { PoolSunsetArgs, checkPoolSunset } from "./checkPoolSunset.js";
14
14
  import { QuotaCountArgs, checkQuotaCount } from "./checkQuotaCount.js";
15
15
  import { QuotaLimitArgs, checkQuotaLimit } from "./checkQuotaLimit.js";
16
- export { BorrowLimitArgs, CollateralisedArgs, CreditAccountFrozenArgs, CreditManagerPausedArgs, DebtLimitsArgs, EmergencyLiquidatorArgs, ForbiddenTokenArgs, LeverageArgs, LiquidatorEligibleArgs, MarketExpiredArgs, PoolLiquidityArgs, PoolPausedArgs, PoolSunsetArgs, QuotaCountArgs, QuotaLimitArgs, checkBorrowLimit, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkLeverage, checkLiquidatorEligible, checkMarketExpired, checkPoolLiquidity, checkPoolPaused, checkPoolSunset, checkQuotaCount, checkQuotaLimit };
16
+ import { ReservePriceLimitedArgs, checkReservePriceLimited } from "./checkReservePriceLimited.js";
17
+ export { BorrowLimitArgs, CollateralisedArgs, CreditAccountFrozenArgs, CreditManagerPausedArgs, DebtLimitsArgs, EmergencyLiquidatorArgs, ForbiddenTokenArgs, LeverageArgs, LiquidatorEligibleArgs, MarketExpiredArgs, PoolLiquidityArgs, PoolPausedArgs, PoolSunsetArgs, QuotaCountArgs, QuotaLimitArgs, ReservePriceLimitedArgs, checkBorrowLimit, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkLeverage, checkLiquidatorEligible, checkMarketExpired, checkPoolLiquidity, checkPoolPaused, checkPoolSunset, checkQuotaCount, checkQuotaLimit, checkReservePriceLimited };
@@ -35,9 +35,10 @@ import { PoolPausedArgs, checkPoolPaused } from "./checks/checkPoolPaused.js";
35
35
  import { PoolSunsetArgs, checkPoolSunset } from "./checks/checkPoolSunset.js";
36
36
  import { QuotaCountArgs, checkQuotaCount } from "./checks/checkQuotaCount.js";
37
37
  import { QuotaLimitArgs, checkQuotaLimit } from "./checks/checkQuotaLimit.js";
38
+ import { ReservePriceLimitedArgs, checkReservePriceLimited } from "./checks/checkReservePriceLimited.js";
38
39
  import "./checks/index.js";
39
40
  import { amountOf } from "./helpers/amount.js";
40
41
  import { MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM } from "./helpers/health-factor-limits.js";
41
42
  import { toToken, toTokenAmount } from "./helpers/token.js";
42
43
  import "./helpers/index.js";
43
- export { BorrowLimitArgs, CheckCollateralFundingInput, CheckLiquidationEligibilityInput, CheckLiquidationFundingInput, CheckLiquidationInput, CheckLiquidationOptions, CheckOperationInput, CheckOperationOptions, CheckPoolFundingInput, CheckRWAOpenRequirementsInput, CheckRWAOpeningInput, CheckSimulationInput, CheckWalletAllowanceInput, CheckWalletBalanceInput, CheckWalletInput, CollateralFundingPreview, CollateralisedArgs, CreditAccountFrozenArgs, CreditManagerPausedArgs, CreditOperationArgs, CreditOperationError, CreditOperationPreview, CreditSimulationInput, DebtLimitsArgs, EmergencyLiquidatorArgs, ForbiddenTokenArgs, HealthFactorThresholds, type IntentValidationError, LeverageArgs, LiquidationEligibilityError, LiquidationValidationError, LiquidatorEligibleArgs, MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, MarketExpiredArgs, MarketStateError, OperationValidationError, PoolLiquidityArgs, PoolOperationArgs, PoolOperationError, PoolPausedArgs, PoolSunsetArgs, QuotaCountArgs, QuotaLimitArgs, SimulationValidationError, WalletFundingError, WeighedFactors, amountOf, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkObtained, checkOperation, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaCount, checkQuotaLimit, checkRWAOpenRequirements, checkRWAOpening, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, raise, toToken, toTokenAmount };
44
+ export { BorrowLimitArgs, CheckCollateralFundingInput, CheckLiquidationEligibilityInput, CheckLiquidationFundingInput, CheckLiquidationInput, CheckLiquidationOptions, CheckOperationInput, CheckOperationOptions, CheckPoolFundingInput, CheckRWAOpenRequirementsInput, CheckRWAOpeningInput, CheckSimulationInput, CheckWalletAllowanceInput, CheckWalletBalanceInput, CheckWalletInput, CollateralFundingPreview, CollateralisedArgs, CreditAccountFrozenArgs, CreditManagerPausedArgs, CreditOperationArgs, CreditOperationError, CreditOperationPreview, CreditSimulationInput, DebtLimitsArgs, EmergencyLiquidatorArgs, ForbiddenTokenArgs, HealthFactorThresholds, type IntentValidationError, LeverageArgs, LiquidationEligibilityError, LiquidationValidationError, LiquidatorEligibleArgs, MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, MarketExpiredArgs, MarketStateError, OperationValidationError, PoolLiquidityArgs, PoolOperationArgs, PoolOperationError, PoolPausedArgs, PoolSunsetArgs, QuotaCountArgs, QuotaLimitArgs, ReservePriceLimitedArgs, SimulationValidationError, WalletFundingError, WeighedFactors, amountOf, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkIncreaseDebt, checkIncreaseQuota, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkObtained, checkOperation, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaCount, checkQuotaLimit, checkRWAOpenRequirements, checkRWAOpening, checkReservePriceLimited, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, raise, toToken, toTokenAmount };
@@ -1,4 +1,4 @@
1
- import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError } from "../../model/errors/operation-errors.js";
1
+ import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError, ReservePriceLimitedError } from "../../model/errors/operation-errors.js";
2
2
  import { MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
3
3
  import "../../model/index.js";
4
4
  //#region src/onchain/validation/raise.d.ts
@@ -9,7 +9,7 @@ import "../../model/index.js";
9
9
  * Not a catch-all of every SDK error — pool paused/sunset is `checkOperation`'s,
10
10
  * a malformed transaction is `previewOperation`'s, not the engine's.
11
11
  **/
12
- type IntentValidationError = CreditManagerPausedError | MarketExpiredError | InsufficientPoolLiquidityError | DebtOutOfRangeError | LeverageOutOfRangeError | InsufficientCollateralError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientBalanceError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | NoRecordedIntentError;
12
+ type IntentValidationError = CreditManagerPausedError | MarketExpiredError | InsufficientPoolLiquidityError | DebtOutOfRangeError | LeverageOutOfRangeError | InsufficientCollateralError | ReservePriceLimitedError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientBalanceError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | NoRecordedIntentError;
13
13
  /**
14
14
  * Engine-internal throw: planners and guards raise one error object, and the
15
15
  * service boundary turns it into {@link SDKError}.
@@ -79,7 +79,7 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
79
79
  /**
80
80
  * {@inheritDoc IOpportunitiesPrepare.maxWithdraw}
81
81
  **/
82
- maxWithdraw(position: PositionInput): Promise<WithdrawCeilings>;
82
+ maxWithdraw(position: PositionInput, sourceToken?: Address): Promise<WithdrawCeilings>;
83
83
  /**
84
84
  * {@inheritDoc IOpportunitiesPrepare.repayStrategy}
85
85
  **/
@@ -1,6 +1,6 @@
1
1
  import { Bps, Timestamp, TokenAmount } from "../../model/primitives.js";
2
2
  import { Curator } from "../../model/curators.js";
3
- import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError } from "../../model/errors/operation-errors.js";
3
+ import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError, ReservePriceLimitedError } from "../../model/errors/operation-errors.js";
4
4
  import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
5
5
  import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
6
6
  import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
@@ -22,7 +22,7 @@ import { Address } from "viem";
22
22
  * What any operation on an existing account can answer with: the engine's
23
23
  * shared guards, the missing account, and a wrapped crash.
24
24
  **/
25
- type AccountFlowError = CreditManagerPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientBalanceError | CreditAccountNotFoundError | UnexpectedFailureError;
25
+ type AccountFlowError = CreditManagerPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | ReservePriceLimitedError | InsufficientBalanceError | CreditAccountNotFoundError | UnexpectedFailureError;
26
26
  /** Same guards for the account-less open flow. */
27
27
  type OpenFlowError = CreditManagerPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientBalanceError | UnexpectedFailureError;
28
28
  /**
@@ -541,26 +541,33 @@ interface IOpportunitiesPrepare {
541
541
  **/
542
542
  withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteErrors>>;
543
543
  /**
544
- * How much {@link withdrawStrategy} can take out, both ends of it, in
545
- * underlying units: `partial` is the largest withdrawal that keeps leverage
546
- * and leaves the debt at the credit manager's `minDebt`, `exit` is the net
547
- * value leaving entirely hands over.
548
- *
549
- * Two numbers rather than one because the range has a hole in it: between
550
- * them the flow refuses with `debtOutOfRange`, since the leftover loan would
551
- * sit below the floor. A form driving a slider off `partial` and a Max
552
- * button off `exit` describes what the account can actually do; a form using
553
- * either alone will misstate one of them — see {@link WithdrawCeilings},
554
- * which spells out how far apart they can be.
555
- *
556
- * Taking everything out needs neither figure: send `MAX_UINT256` to
544
+ * How much {@link withdrawStrategy} can take out, every end of it, in
545
+ * underlying units: `safePartial` is the largest partial withdrawal the flow
546
+ * accepts, `partial` the same figure before the safe-price collateral check
547
+ * has had its say, and `exit` the net value leaving entirely hands over.
548
+ *
549
+ * More than one number because the range has a hole in it: between the
550
+ * largest partial and `exit` the flow refuses with `debtOutOfRange`, since
551
+ * the leftover loan would sit below the floor. A form driving a slider off
552
+ * `safePartial` and a Max button off `exit` describes what the account can
553
+ * actually do; a form using either alone will misstate one of them — see
554
+ * {@link WithdrawCeilings}, which spells out how far apart they can be and
555
+ * why the two partial figures differ.
556
+ *
557
+ * `sourceToken` is the collateral the withdrawal would be funded from, the
558
+ * same argument {@link withdrawStrategy} takes. It matters because selling
559
+ * one collateral and selling another cost the safe-price check different
560
+ * amounts; omitted, both this and the flow itself reach for the account's
561
+ * largest non-phantom balance.
562
+ *
563
+ * Taking everything out needs none of the figures: send `MAX_UINT256` to
557
564
  * {@link withdrawStrategy} and the exit is what runs, named rather than
558
565
  * priced.
559
566
  *
560
567
  * A bare read: it answers its numbers, and throws on an account or a chain
561
568
  * the SDK does not hold.
562
569
  **/
563
- maxWithdraw(position: PositionInput): Promise<WithdrawCeilings>;
570
+ maxWithdraw(position: PositionInput, sourceToken?: Address): Promise<WithdrawCeilings>;
564
571
  /**
565
572
  * Paying debt down with funds from the wallet: collateral stays where it is,
566
573
  * so net value grows by what was repaid, leverage falls and the health factor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.3.2",
3
+ "version": "16.4.0-next.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {