@gearbox-protocol/sdk 17.10.1-next.2 → 17.10.1-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.
@@ -93,7 +93,7 @@ async function buildWrapRwaCollateralOperation(input) {
93
93
  }
94
94
  /** Unwraps the market underlying back into its RWA asset. */
95
95
  async function buildUnwrapRwaCollateralOperation(input) {
96
- const calls = await input.sdk.accounts.assembleRWAUnwrapCalls(input.amountIn, input.creditAccount.creditManager);
96
+ const calls = input.all ? await input.sdk.accounts.assembleRedeemDiffCalls(1n, input.creditAccount.creditManager) : await input.sdk.accounts.assembleRWAUnwrapCalls(input.amountIn, input.creditAccount.creditManager);
97
97
  if (!calls) throw new Error("unwrapRwaCollateral: no unwrap calls found");
98
98
  return {
99
99
  type: "unwrapRwaCollateral",
@@ -309,6 +309,7 @@ async function realize(steps, props) {
309
309
  const wrapped = ledger.balanceOf(underlying);
310
310
  if (rwaAsset && wrapped > 0n) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
311
311
  tokenIn: underlying,
312
+ all: true,
312
313
  amountIn: wrapped,
313
314
  tokenOut: rwaAsset,
314
315
  amountOut: require_onchain_accounts_intents_utils_common.toTargetDecimals(wrapped, underlying, rwaAsset, sdk),
@@ -357,6 +357,7 @@ function buildMockSdk(args) {
357
357
  prepareUpdateQuotas: vitest.vi.fn(() => [CA_OP_CALLS.changeQuota]),
358
358
  assembleRWAWrapCalls: vitest.vi.fn(async () => [MOCK_RWA_WRAP_CALL]),
359
359
  assembleRWAUnwrapCalls: vitest.vi.fn(async () => [MOCK_RWA_UNWRAP_CALL]),
360
+ assembleRedeemDiffCalls: vitest.vi.fn(async () => [MOCK_RWA_UNWRAP_CALL]),
360
361
  previewDelayedWithdrawal,
361
362
  assembleStartDelayedWithdrawalCalls: vitest.vi.fn(({ preview }) => [...preview.requestCalls]),
362
363
  assembleClaimDelayedCalls: vitest.vi.fn(({ claimableNow }) => [...claimableNow.claimCalls])
@@ -1,6 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
3
3
  require("../../../model/index.js");
4
+ require("../helpers/health-factor-limits.js");
5
+ require("../helpers/index.js");
4
6
  //#region src/onchain/validation/checks/checkCollateralised.ts
5
7
  /**
6
8
  * The account against its debt, at whichever threshold the caller holds it to.
@@ -15,7 +17,7 @@ function checkCollateralised(args) {
15
17
  healthFactorThreshold,
16
18
  safePrices
17
19
  })];
18
- if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor > improvesFrom) return [];
20
+ if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor >= 1e4 && healthFactor > improvesFrom) return [];
19
21
  return [require_model_errors_operation_errors.insufficientCollateral({
20
22
  healthFactor,
21
23
  healthFactorThreshold,
@@ -92,7 +92,7 @@ async function buildWrapRwaCollateralOperation(input) {
92
92
  }
93
93
  /** Unwraps the market underlying back into its RWA asset. */
94
94
  async function buildUnwrapRwaCollateralOperation(input) {
95
- const calls = await input.sdk.accounts.assembleRWAUnwrapCalls(input.amountIn, input.creditAccount.creditManager);
95
+ const calls = input.all ? await input.sdk.accounts.assembleRedeemDiffCalls(1n, input.creditAccount.creditManager) : await input.sdk.accounts.assembleRWAUnwrapCalls(input.amountIn, input.creditAccount.creditManager);
96
96
  if (!calls) throw new Error("unwrapRwaCollateral: no unwrap calls found");
97
97
  return {
98
98
  type: "unwrapRwaCollateral",
@@ -308,6 +308,7 @@ async function realize(steps, props) {
308
308
  const wrapped = ledger.balanceOf(underlying);
309
309
  if (rwaAsset && wrapped > 0n) push(await buildUnwrapRwaCollateralOperation({
310
310
  tokenIn: underlying,
311
+ all: true,
311
312
  amountIn: wrapped,
312
313
  tokenOut: rwaAsset,
313
314
  amountOut: toTargetDecimals(wrapped, underlying, rwaAsset, sdk),
@@ -357,6 +357,7 @@ function buildMockSdk(args) {
357
357
  prepareUpdateQuotas: vi.fn(() => [CA_OP_CALLS.changeQuota]),
358
358
  assembleRWAWrapCalls: vi.fn(async () => [MOCK_RWA_WRAP_CALL]),
359
359
  assembleRWAUnwrapCalls: vi.fn(async () => [MOCK_RWA_UNWRAP_CALL]),
360
+ assembleRedeemDiffCalls: vi.fn(async () => [MOCK_RWA_UNWRAP_CALL]),
360
361
  previewDelayedWithdrawal,
361
362
  assembleStartDelayedWithdrawalCalls: vi.fn(({ preview }) => [...preview.requestCalls]),
362
363
  assembleClaimDelayedCalls: vi.fn(({ claimableNow }) => [...claimableNow.claimCalls])
@@ -1,5 +1,7 @@
1
1
  import { insufficientCollateral } from "../../../model/errors/operation-errors.js";
2
2
  import "../../../model/index.js";
3
+ import "../helpers/health-factor-limits.js";
4
+ import "../helpers/index.js";
3
5
  //#region src/onchain/validation/checks/checkCollateralised.ts
4
6
  /**
5
7
  * The account against its debt, at whichever threshold the caller holds it to.
@@ -14,7 +16,7 @@ function checkCollateralised(args) {
14
16
  healthFactorThreshold,
15
17
  safePrices
16
18
  })];
17
- if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor > improvesFrom) return [];
19
+ if (healthFactor >= healthFactorThreshold || improvesFrom !== void 0 && healthFactor >= 1e4 && healthFactor > improvesFrom) return [];
18
20
  return [insufficientCollateral({
19
21
  healthFactor,
20
22
  healthFactorThreshold,
@@ -162,7 +162,9 @@ interface RwaLegInput {
162
162
  /** Wraps an RWA asset into the market underlying. */
163
163
  declare function buildWrapRwaCollateralOperation(input: RwaLegInput): Promise<WrapRwaCollateralOperation>;
164
164
  /** Unwraps the market underlying back into its RWA asset. */
165
- declare function buildUnwrapRwaCollateralOperation(input: RwaLegInput): Promise<UnwrapRwaCollateralOperation>;
165
+ declare function buildUnwrapRwaCollateralOperation(input: RwaLegInput & {
166
+ all?: boolean;
167
+ }): Promise<UnwrapRwaCollateralOperation>;
166
168
  /**
167
169
  * The request that starts a redemption: spends the source token and receives
168
170
  * the phantom token standing in for the claim until it matures.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "17.10.1-next.2",
3
+ "version": "17.10.1-next.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {