@gearbox-protocol/sdk 14.12.0-next.44 → 14.12.0-next.46

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.
@@ -25,24 +25,27 @@ module.exports = __toCommonJS(detectCloseOrRepay_exports);
25
25
  var import_viem = require("viem");
26
26
  var import_sdk = require("../../sdk/index.js");
27
27
  function isCloseOrRepay(multicall) {
28
- const repaysFullDebt = multicall.some(
28
+ return multicall.some(
29
29
  (op) => op.operation === "DecreaseBorrowedAmount" && op.amount === import_sdk.MAX_UINT256
30
30
  );
31
- const withdrawsEverything = multicall.some(
32
- (op) => op.operation === "WithdrawCollateral" && op.amount === import_sdk.MAX_UINT256
33
- );
34
- return repaysFullDebt && withdrawsEverything;
35
31
  }
36
32
  function classifyCloseOrRepay(multicall, exitTokens) {
33
+ let hasExitWithdrawal = false;
37
34
  for (const op of multicall) {
38
35
  if (op.operation === "AddCollateral") {
39
36
  return "repay";
40
37
  }
41
- if (op.operation === "WithdrawCollateral" && !exitTokens.some((token) => (0, import_viem.isAddressEqual)(op.token, token))) {
42
- return "repay";
38
+ if (op.operation === "WithdrawCollateral") {
39
+ const isExit = exitTokens.some((token) => (0, import_viem.isAddressEqual)(op.token, token));
40
+ if (!isExit) {
41
+ return "repay";
42
+ }
43
+ if (op.amount === import_sdk.MAX_UINT256) {
44
+ hasExitWithdrawal = true;
45
+ }
43
46
  }
44
47
  }
45
- return "close";
48
+ return hasExitWithdrawal ? "close" : "repay";
46
49
  }
47
50
  // Annotate the CommonJS export names for ESM import in node:
48
51
  0 && (module.exports = {
@@ -76,7 +76,10 @@ function encodeDelayedIntent(intent) {
76
76
  }
77
77
  }
78
78
  function decodeDelayedIntent(data) {
79
- const [_version, intentType] = (0, import_viem.decodeAbiParameters)(HEADER_PARAMS, data);
79
+ const [version, intentType] = (0, import_viem.decodeAbiParameters)(HEADER_PARAMS, data);
80
+ if (version !== DELAYED_INTENT_VERSION) {
81
+ throw new Error(`unsupported delayed intent version: ${version}`);
82
+ }
80
83
  switch (intentType) {
81
84
  case DELAYED_INTENT_TYPES.INCREASE_LEVERAGE:
82
85
  return { type: "INCREASE_LEVERAGE" };
@@ -1,24 +1,27 @@
1
1
  import { isAddressEqual } from "viem";
2
2
  import { MAX_UINT256 } from "../../sdk/index.js";
3
3
  function isCloseOrRepay(multicall) {
4
- const repaysFullDebt = multicall.some(
4
+ return multicall.some(
5
5
  (op) => op.operation === "DecreaseBorrowedAmount" && op.amount === MAX_UINT256
6
6
  );
7
- const withdrawsEverything = multicall.some(
8
- (op) => op.operation === "WithdrawCollateral" && op.amount === MAX_UINT256
9
- );
10
- return repaysFullDebt && withdrawsEverything;
11
7
  }
12
8
  function classifyCloseOrRepay(multicall, exitTokens) {
9
+ let hasExitWithdrawal = false;
13
10
  for (const op of multicall) {
14
11
  if (op.operation === "AddCollateral") {
15
12
  return "repay";
16
13
  }
17
- if (op.operation === "WithdrawCollateral" && !exitTokens.some((token) => isAddressEqual(op.token, token))) {
18
- return "repay";
14
+ if (op.operation === "WithdrawCollateral") {
15
+ const isExit = exitTokens.some((token) => isAddressEqual(op.token, token));
16
+ if (!isExit) {
17
+ return "repay";
18
+ }
19
+ if (op.amount === MAX_UINT256) {
20
+ hasExitWithdrawal = true;
21
+ }
19
22
  }
20
23
  }
21
- return "close";
24
+ return hasExitWithdrawal ? "close" : "repay";
22
25
  }
23
26
  export {
24
27
  classifyCloseOrRepay,
@@ -50,7 +50,10 @@ function encodeDelayedIntent(intent) {
50
50
  }
51
51
  }
52
52
  function decodeDelayedIntent(data) {
53
- const [_version, intentType] = decodeAbiParameters(HEADER_PARAMS, data);
53
+ const [version, intentType] = decodeAbiParameters(HEADER_PARAMS, data);
54
+ if (version !== DELAYED_INTENT_VERSION) {
55
+ throw new Error(`unsupported delayed intent version: ${version}`);
56
+ }
54
57
  switch (intentType) {
55
58
  case DELAYED_INTENT_TYPES.INCREASE_LEVERAGE:
56
59
  return { type: "INCREASE_LEVERAGE" };
@@ -2,7 +2,7 @@ import type { Address } from "viem";
2
2
  import type { InnerOperation } from "../parse/index.js";
3
3
  /**
4
4
  * Detects whether a credit-facade multicall fully closes or repays the
5
- * account.
5
+ * account: any multicall that calls `decreaseDebt(MAX_UINT256)`.
6
6
  *
7
7
  * Note that closing/repaying an account whose debt is already zero emits no
8
8
  * `decreaseDebt` call at all and is not detected (previews as an adjustment).
@@ -11,10 +11,12 @@ export declare function isCloseOrRepay(multicall: InnerOperation[]): boolean;
11
11
  /**
12
12
  * Distinguishes a closure from a repayment by how collateral leaves the
13
13
  * account:
14
- * - close swaps all assets into an exit token and withdraws only exit
15
- * tokens: the underlying or, on RWA markets, the unwrapped RWA underlying
16
- * (the ERC4626 vault asset)
14
+ * - close swaps all assets into the market underlying and withdraws only
15
+ * that token or, on RWA markets, its unwrapped version.
16
+ * Requires at least one `withdrawCollateral(MAX)` for one of those tokens.
17
17
  * - repay returns collateral in-kind: it adds collateral from the wallet to
18
- * cover the debt and/or withdraws non-exit tokens.
18
+ * cover the debt, withdraws tokens other than the market underlying (or
19
+ * its unwrapped RWA asset), and/or leaves collateral on the account with
20
+ * no withdrawals at all.
19
21
  */
20
22
  export declare function classifyCloseOrRepay(multicall: InnerOperation[], exitTokens: Address[]): "close" | "repay";
@@ -5,7 +5,7 @@ import type { CloseCreditAccountPreview, RepayCreditAccountPreview } from "./typ
5
5
  /**
6
6
  * Any parsed operation that fully closes or repays a credit account: the
7
7
  * facade `closeCreditAccount` entry point (permanent closure) or a plain
8
- * multicall detected by `isCloseOrRepay` (zero-debt closure/repay).
8
+ * multicall detected by `isCloseOrRepay` (`decreaseDebt(MAX)`).
9
9
  */
10
10
  export type CloseOrRepayOperation = CloseCreditAccountOperation | MulticallOperation | RWAMulticallOperation;
11
11
  export declare function previewCloseOrRepayCreditAccount<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: CloseOrRepayOperation, permanent: boolean, options: PreviewOperationOptions<true>): Promise<CloseCreditAccountPreview | RepayCreditAccountPreview>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.12.0-next.44",
3
+ "version": "14.12.0-next.46",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -73,7 +73,9 @@
73
73
  "test:e2e": "vitest run --project e2e",
74
74
  "test:all": "vitest run",
75
75
  "test": "vitest run",
76
- "generate:e2e": "NODE_OPTIONS='--max-old-space-size=8192' tsx scripts/generate-e2e-fixtures.ts",
76
+ "generate:e2e": "NODE_OPTIONS='--max-old-space-size=8192' tsx dev/scripts/generate-e2e-fixtures.ts",
77
+ "tx:decode": "tsx dev/txdiff/cli.ts decode",
78
+ "tx:diff": "tsx dev/txdiff/cli.ts diff",
77
79
  "prepare": "husky",
78
80
  "check": "biome check --write",
79
81
  "check:ci": "biome check --diagnostic-level=error",