@gearbox-protocol/sdk 14.12.0-next.45 → 14.12.0-next.47
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.
- package/dist/cjs/dev/withdrawalUtils.js +8 -1
- package/dist/cjs/preview/preview/detectCloseOrRepay.js +11 -8
- package/dist/esm/dev/withdrawalUtils.js +8 -1
- package/dist/esm/preview/preview/detectCloseOrRepay.js +11 -8
- package/dist/types/preview/preview/detectCloseOrRepay.d.ts +7 -5
- package/dist/types/preview/preview/previewCloseOrRepayCreditAccount.d.ts +1 -1
- package/package.json +1 -1
|
@@ -197,7 +197,7 @@ async function fulfillMidasWithdrawal(anvil, creditAccount, withdrawalPhantomTok
|
|
|
197
197
|
address: MIDAS_VAULT_ADMIN,
|
|
198
198
|
value: (0, import_viem.parseEther)("100")
|
|
199
199
|
});
|
|
200
|
-
await anvil.writeContract({
|
|
200
|
+
const hash = await anvil.writeContract({
|
|
201
201
|
chain: anvil.chain,
|
|
202
202
|
address: midasRedemptionVault,
|
|
203
203
|
account: MIDAS_VAULT_ADMIN,
|
|
@@ -205,6 +205,13 @@ async function fulfillMidasWithdrawal(anvil, creditAccount, withdrawalPhantomTok
|
|
|
205
205
|
functionName: "safeApproveRequest",
|
|
206
206
|
args: [requestId, mTokenRate]
|
|
207
207
|
});
|
|
208
|
+
const receipt = await anvil.waitForTransactionReceipt({
|
|
209
|
+
hash,
|
|
210
|
+
pollingInterval: 100
|
|
211
|
+
});
|
|
212
|
+
if (receipt.status !== "success") {
|
|
213
|
+
throw new Error(`midas: safeApproveRequest tx ${hash} reverted`);
|
|
214
|
+
}
|
|
208
215
|
await anvil.stopImpersonatingAccount({ address: MIDAS_VAULT_ADMIN });
|
|
209
216
|
}
|
|
210
217
|
}
|
|
@@ -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 = {
|
|
@@ -186,7 +186,7 @@ async function fulfillMidasWithdrawal(anvil, creditAccount, withdrawalPhantomTok
|
|
|
186
186
|
address: MIDAS_VAULT_ADMIN,
|
|
187
187
|
value: parseEther("100")
|
|
188
188
|
});
|
|
189
|
-
await anvil.writeContract({
|
|
189
|
+
const hash = await anvil.writeContract({
|
|
190
190
|
chain: anvil.chain,
|
|
191
191
|
address: midasRedemptionVault,
|
|
192
192
|
account: MIDAS_VAULT_ADMIN,
|
|
@@ -194,6 +194,13 @@ async function fulfillMidasWithdrawal(anvil, creditAccount, withdrawalPhantomTok
|
|
|
194
194
|
functionName: "safeApproveRequest",
|
|
195
195
|
args: [requestId, mTokenRate]
|
|
196
196
|
});
|
|
197
|
+
const receipt = await anvil.waitForTransactionReceipt({
|
|
198
|
+
hash,
|
|
199
|
+
pollingInterval: 100
|
|
200
|
+
});
|
|
201
|
+
if (receipt.status !== "success") {
|
|
202
|
+
throw new Error(`midas: safeApproveRequest tx ${hash} reverted`);
|
|
203
|
+
}
|
|
197
204
|
await anvil.stopImpersonatingAccount({ address: MIDAS_VAULT_ADMIN });
|
|
198
205
|
}
|
|
199
206
|
}
|
|
@@ -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>;
|