@gearbox-protocol/sdk 14.12.0-next.45 → 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
|
-
|
|
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"
|
|
42
|
-
|
|
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 = {
|
|
@@ -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
|
-
|
|
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"
|
|
18
|
-
|
|
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,
|
|
@@ -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
|
|
15
|
-
*
|
|
16
|
-
* (
|
|
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
|
|
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` (
|
|
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>;
|