@gearbox-protocol/sdk 14.12.0-next.31 → 14.12.0-next.33
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/withdrawalAbi.js +64 -70
- package/dist/cjs/dev/withdrawalUtils.js +1 -1
- package/dist/cjs/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +40 -280
- package/dist/cjs/plugins/adapters/contracts/MidasGatewayAdapterContract.js +45 -44
- package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -1
- package/dist/cjs/preview/preview/detectCloseOrRepay.js +2 -2
- package/dist/cjs/preview/preview/previewCloseOrRepayCreditAccount.js +17 -2
- package/dist/cjs/rewards/rewards/extra-apy.js +8 -4
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -0
- package/dist/esm/dev/withdrawalAbi.js +64 -70
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +40 -280
- package/dist/esm/plugins/adapters/contracts/MidasGatewayAdapterContract.js +47 -45
- package/dist/esm/preview/preview/buildDelayedPreview.js +5 -1
- package/dist/esm/preview/preview/detectCloseOrRepay.js +2 -2
- package/dist/esm/preview/preview/previewCloseOrRepayCreditAccount.js +22 -3
- package/dist/esm/rewards/rewards/extra-apy.js +8 -4
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -0
- package/dist/types/dev/withdrawalAbi.d.ts +53 -57
- package/dist/types/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.d.ts +33 -219
- package/dist/types/plugins/adapters/contracts/MidasGatewayAdapterContract.d.ts +44 -232
- package/dist/types/preview/preview/detectCloseOrRepay.d.ts +5 -3
- package/dist/types/preview/preview/types.d.ts +6 -4
- package/dist/types/rewards/rewards/extra-apy.d.ts +3 -1
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AP_WETH_TOKEN,
|
|
3
|
+
MAX_UINT256,
|
|
4
|
+
NO_VERSION
|
|
5
|
+
} from "../../sdk/index.js";
|
|
2
6
|
import { classifyCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
3
7
|
import {
|
|
4
8
|
replayMulticall
|
|
@@ -9,8 +13,13 @@ async function previewCloseOrRepayCreditAccount(input, operation, permanent, opt
|
|
|
9
13
|
const market = sdk.marketRegister.findByCreditManager(
|
|
10
14
|
operation.creditManager
|
|
11
15
|
);
|
|
16
|
+
const exitTokens = [market.underlying];
|
|
17
|
+
const meta = sdk.tokensMeta.get(market.underlying);
|
|
18
|
+
if (meta && sdk.tokensMeta.isRWAUnderlying(meta)) {
|
|
19
|
+
exitTokens.push(meta.asset);
|
|
20
|
+
}
|
|
12
21
|
const replay = await replayMulticall(sdk, operation, options);
|
|
13
|
-
const kind = classifyCloseOrRepay(operation.multicall,
|
|
22
|
+
const kind = classifyCloseOrRepay(operation.multicall, exitTokens);
|
|
14
23
|
return kind === "close" ? previewCloseCreditAccount(input, operation, permanent, replay) : previewRepayCreditAccount(input, operation, permanent, replay);
|
|
15
24
|
}
|
|
16
25
|
function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
@@ -19,6 +28,13 @@ function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
|
19
28
|
operation.creditManager
|
|
20
29
|
);
|
|
21
30
|
const { after, error } = replay;
|
|
31
|
+
let receivedToken = market.underlying;
|
|
32
|
+
for (const m of operation.multicall) {
|
|
33
|
+
if (m.operation === "WithdrawCollateral" && m.amount === MAX_UINT256) {
|
|
34
|
+
receivedToken = m.token;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
22
38
|
return {
|
|
23
39
|
operation: "CloseCreditAccount",
|
|
24
40
|
permanent,
|
|
@@ -26,7 +42,10 @@ function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
|
26
42
|
creditAccount: operation.creditAccount,
|
|
27
43
|
// On a malformed multicall the withdrawn amount depends on best-effort
|
|
28
44
|
// replayed balances and may be unreliable
|
|
29
|
-
receivedAmount:
|
|
45
|
+
receivedAmount: {
|
|
46
|
+
token: receivedToken,
|
|
47
|
+
balance: after.collateralWithdrawn.getOrZero(receivedToken)
|
|
48
|
+
},
|
|
30
49
|
error
|
|
31
50
|
};
|
|
32
51
|
}
|
|
@@ -20,23 +20,27 @@ function getKeyForPoolPointsInfo(i) {
|
|
|
20
20
|
class PoolPointsAPI {
|
|
21
21
|
constructor() {
|
|
22
22
|
}
|
|
23
|
+
static defaultBackendUrl = "https://api.gearbox.foundation";
|
|
23
24
|
static async getTotalTokensOnProtocol({
|
|
24
25
|
tokensToCheck,
|
|
25
26
|
tokensList,
|
|
26
|
-
network
|
|
27
|
+
network,
|
|
28
|
+
backendUrl = PoolPointsAPI.defaultBackendUrl
|
|
27
29
|
}) {
|
|
28
30
|
const list = [...new Set(tokensToCheck)];
|
|
29
31
|
const res = await Promise.allSettled(
|
|
30
|
-
list.map(
|
|
32
|
+
list.map(
|
|
33
|
+
(t) => PoolPointsAPI.getTokenTotal(t, network, tokensList, backendUrl)
|
|
34
|
+
)
|
|
31
35
|
);
|
|
32
36
|
return res.map((r, i) => [
|
|
33
37
|
list[i],
|
|
34
38
|
r
|
|
35
39
|
]);
|
|
36
40
|
}
|
|
37
|
-
static async getTokenTotal(token, network, tokensList) {
|
|
41
|
+
static async getTokenTotal(token, network, tokensList, backendUrl) {
|
|
38
42
|
const chainId = chains[network]?.id;
|
|
39
|
-
const url =
|
|
43
|
+
const url = `${backendUrl}/v1/getBalanceAt?asset=${token}&chainId=${chainId}`;
|
|
40
44
|
const result = await axios.get(url);
|
|
41
45
|
const balance = result.data.result.reduce(
|
|
42
46
|
(sum, r) => r.effective_balance + sum,
|
|
@@ -616,10 +616,12 @@ class CreditAccountsServiceV310 extends SDKConstruct {
|
|
|
616
616
|
assetsToWithdraw,
|
|
617
617
|
to
|
|
618
618
|
}) {
|
|
619
|
+
const unwrapCalls = await this.getRedeemDiffCalls(1n, ca.creditManager) ?? [];
|
|
619
620
|
return [
|
|
620
621
|
...routerCalls,
|
|
621
622
|
...this.#prepareDisableQuotas(ca),
|
|
622
623
|
...this.#prepareDecreaseDebt(ca),
|
|
624
|
+
...unwrapCalls,
|
|
623
625
|
...assetsToWithdraw.map(
|
|
624
626
|
(t) => this.#prepareWithdrawToken(ca.creditFacade, t, MAX_UINT256, to)
|
|
625
627
|
)
|
|
@@ -9,13 +9,13 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
9
9
|
readonly type: "address";
|
|
10
10
|
readonly internalType: "address";
|
|
11
11
|
}, {
|
|
12
|
-
readonly name: "
|
|
12
|
+
readonly name: "_quoteToken";
|
|
13
13
|
readonly type: "address";
|
|
14
14
|
readonly internalType: "address";
|
|
15
15
|
}, {
|
|
16
|
-
readonly name: "
|
|
17
|
-
readonly type: "
|
|
18
|
-
readonly internalType: "
|
|
16
|
+
readonly name: "_isAccessControlled";
|
|
17
|
+
readonly type: "bool";
|
|
18
|
+
readonly internalType: "bool";
|
|
19
19
|
}, {
|
|
20
20
|
readonly name: "_allowedMarketConfigurator";
|
|
21
21
|
readonly type: "address";
|
|
@@ -32,6 +32,10 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
32
32
|
readonly name: "_redemptionLogger";
|
|
33
33
|
readonly type: "address";
|
|
34
34
|
readonly internalType: "address";
|
|
35
|
+
}, {
|
|
36
|
+
readonly name: "_withDelayedWithdrawals";
|
|
37
|
+
readonly type: "bool";
|
|
38
|
+
readonly internalType: "bool";
|
|
35
39
|
}];
|
|
36
40
|
readonly stateMutability: "nonpayable";
|
|
37
41
|
}, {
|
|
@@ -78,10 +82,6 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
78
82
|
readonly type: "function";
|
|
79
83
|
readonly name: "depositInstant";
|
|
80
84
|
readonly inputs: readonly [{
|
|
81
|
-
readonly name: "tokenIn";
|
|
82
|
-
readonly type: "address";
|
|
83
|
-
readonly internalType: "address";
|
|
84
|
-
}, {
|
|
85
85
|
readonly name: "amountToken";
|
|
86
86
|
readonly type: "uint256";
|
|
87
87
|
readonly internalType: "uint256";
|
|
@@ -153,10 +153,6 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
153
153
|
readonly name: "account";
|
|
154
154
|
readonly type: "address";
|
|
155
155
|
readonly internalType: "address";
|
|
156
|
-
}, {
|
|
157
|
-
readonly name: "tokenOut";
|
|
158
|
-
readonly type: "address";
|
|
159
|
-
readonly internalType: "address";
|
|
160
156
|
}];
|
|
161
157
|
readonly outputs: readonly [{
|
|
162
158
|
readonly name: "pendingAmount";
|
|
@@ -184,12 +180,28 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
184
180
|
readonly stateMutability: "view";
|
|
185
181
|
}, {
|
|
186
182
|
readonly type: "function";
|
|
187
|
-
readonly name: "
|
|
188
|
-
readonly inputs: readonly [
|
|
189
|
-
|
|
183
|
+
readonly name: "phantomToken";
|
|
184
|
+
readonly inputs: readonly [];
|
|
185
|
+
readonly outputs: readonly [{
|
|
186
|
+
readonly name: "";
|
|
190
187
|
readonly type: "address";
|
|
191
188
|
readonly internalType: "address";
|
|
192
|
-
}
|
|
189
|
+
}];
|
|
190
|
+
readonly stateMutability: "view";
|
|
191
|
+
}, {
|
|
192
|
+
readonly type: "function";
|
|
193
|
+
readonly name: "quoteToken";
|
|
194
|
+
readonly inputs: readonly [];
|
|
195
|
+
readonly outputs: readonly [{
|
|
196
|
+
readonly name: "";
|
|
197
|
+
readonly type: "address";
|
|
198
|
+
readonly internalType: "address";
|
|
199
|
+
}];
|
|
200
|
+
readonly stateMutability: "view";
|
|
201
|
+
}, {
|
|
202
|
+
readonly type: "function";
|
|
203
|
+
readonly name: "redeemInstant";
|
|
204
|
+
readonly inputs: readonly [{
|
|
193
205
|
readonly name: "amountMTokenIn";
|
|
194
206
|
readonly type: "uint256";
|
|
195
207
|
readonly internalType: "uint256";
|
|
@@ -214,10 +226,6 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
214
226
|
readonly type: "function";
|
|
215
227
|
readonly name: "requestRedeem";
|
|
216
228
|
readonly inputs: readonly [{
|
|
217
|
-
readonly name: "tokenOut";
|
|
218
|
-
readonly type: "address";
|
|
219
|
-
readonly internalType: "address";
|
|
220
|
-
}, {
|
|
221
229
|
readonly name: "amountMTokenIn";
|
|
222
230
|
readonly type: "uint256";
|
|
223
231
|
readonly internalType: "uint256";
|
|
@@ -266,10 +274,6 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
266
274
|
readonly type: "function";
|
|
267
275
|
readonly name: "withdraw";
|
|
268
276
|
readonly inputs: readonly [{
|
|
269
|
-
readonly name: "tokenOut";
|
|
270
|
-
readonly type: "address";
|
|
271
|
-
readonly internalType: "address";
|
|
272
|
-
}, {
|
|
273
277
|
readonly name: "amount";
|
|
274
278
|
readonly type: "uint256";
|
|
275
279
|
readonly internalType: "uint256";
|
|
@@ -283,10 +287,6 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
283
287
|
readonly name: "redeemer";
|
|
284
288
|
readonly type: "address";
|
|
285
289
|
readonly internalType: "address";
|
|
286
|
-
}, {
|
|
287
|
-
readonly name: "tokenOut";
|
|
288
|
-
readonly type: "address";
|
|
289
|
-
readonly internalType: "address";
|
|
290
290
|
}, {
|
|
291
291
|
readonly name: "amount";
|
|
292
292
|
readonly type: "uint256";
|
|
@@ -302,6 +302,10 @@ export declare const midasGatewayAbi: readonly [{
|
|
|
302
302
|
readonly type: "error";
|
|
303
303
|
readonly name: "CreditAccountNotEligibleException";
|
|
304
304
|
readonly inputs: readonly [];
|
|
305
|
+
}, {
|
|
306
|
+
readonly type: "error";
|
|
307
|
+
readonly name: "IncompatibleAccessControlsException";
|
|
308
|
+
readonly inputs: readonly [];
|
|
305
309
|
}, {
|
|
306
310
|
readonly type: "error";
|
|
307
311
|
readonly name: "IncompatibleIssuanceAndRedemptionVaultsException";
|
|
@@ -333,6 +337,10 @@ export declare const midasRedeemerAbi: readonly [{
|
|
|
333
337
|
readonly name: "_midasRedemptionVault";
|
|
334
338
|
readonly type: "address";
|
|
335
339
|
readonly internalType: "address";
|
|
340
|
+
}, {
|
|
341
|
+
readonly name: "_quoteToken";
|
|
342
|
+
readonly type: "address";
|
|
343
|
+
readonly internalType: "address";
|
|
336
344
|
}];
|
|
337
345
|
readonly stateMutability: "nonpayable";
|
|
338
346
|
}, {
|
|
@@ -358,11 +366,7 @@ export declare const midasRedeemerAbi: readonly [{
|
|
|
358
366
|
}, {
|
|
359
367
|
readonly type: "function";
|
|
360
368
|
readonly name: "claimableTokenOutAmount";
|
|
361
|
-
readonly inputs: readonly [
|
|
362
|
-
readonly name: "tokenOut";
|
|
363
|
-
readonly type: "address";
|
|
364
|
-
readonly internalType: "address";
|
|
365
|
-
}];
|
|
369
|
+
readonly inputs: readonly [];
|
|
366
370
|
readonly outputs: readonly [{
|
|
367
371
|
readonly name: "";
|
|
368
372
|
readonly type: "uint256";
|
|
@@ -432,17 +436,23 @@ export declare const midasRedeemerAbi: readonly [{
|
|
|
432
436
|
}, {
|
|
433
437
|
readonly type: "function";
|
|
434
438
|
readonly name: "pendingTokenOutAmount";
|
|
435
|
-
readonly inputs: readonly [
|
|
436
|
-
readonly name: "tokenOut";
|
|
437
|
-
readonly type: "address";
|
|
438
|
-
readonly internalType: "address";
|
|
439
|
-
}];
|
|
439
|
+
readonly inputs: readonly [];
|
|
440
440
|
readonly outputs: readonly [{
|
|
441
441
|
readonly name: "";
|
|
442
442
|
readonly type: "uint256";
|
|
443
443
|
readonly internalType: "uint256";
|
|
444
444
|
}];
|
|
445
445
|
readonly stateMutability: "view";
|
|
446
|
+
}, {
|
|
447
|
+
readonly type: "function";
|
|
448
|
+
readonly name: "quoteToken";
|
|
449
|
+
readonly inputs: readonly [];
|
|
450
|
+
readonly outputs: readonly [{
|
|
451
|
+
readonly name: "";
|
|
452
|
+
readonly type: "address";
|
|
453
|
+
readonly internalType: "address";
|
|
454
|
+
}];
|
|
455
|
+
readonly stateMutability: "view";
|
|
446
456
|
}, {
|
|
447
457
|
readonly type: "function";
|
|
448
458
|
readonly name: "redemptionStartTimestamp";
|
|
@@ -467,10 +477,6 @@ export declare const midasRedeemerAbi: readonly [{
|
|
|
467
477
|
readonly type: "function";
|
|
468
478
|
readonly name: "requestRedeem";
|
|
469
479
|
readonly inputs: readonly [{
|
|
470
|
-
readonly name: "tokenOut";
|
|
471
|
-
readonly type: "address";
|
|
472
|
-
readonly internalType: "address";
|
|
473
|
-
}, {
|
|
474
480
|
readonly name: "amountMTokenIn";
|
|
475
481
|
readonly type: "uint256";
|
|
476
482
|
readonly internalType: "uint256";
|
|
@@ -491,10 +497,6 @@ export declare const midasRedeemerAbi: readonly [{
|
|
|
491
497
|
readonly type: "function";
|
|
492
498
|
readonly name: "withdraw";
|
|
493
499
|
readonly inputs: readonly [{
|
|
494
|
-
readonly name: "tokenOut";
|
|
495
|
-
readonly type: "address";
|
|
496
|
-
readonly internalType: "address";
|
|
497
|
-
}, {
|
|
498
500
|
readonly name: "amount";
|
|
499
501
|
readonly type: "uint256";
|
|
500
502
|
readonly internalType: "uint256";
|
|
@@ -529,7 +531,11 @@ export declare const midasRedemptionVaultPhantomTokenAbi: readonly [{
|
|
|
529
531
|
readonly type: "address";
|
|
530
532
|
readonly internalType: "address";
|
|
531
533
|
}, {
|
|
532
|
-
readonly name: "
|
|
534
|
+
readonly name: "_mToken";
|
|
535
|
+
readonly type: "address";
|
|
536
|
+
readonly internalType: "address";
|
|
537
|
+
}, {
|
|
538
|
+
readonly name: "_quoteToken";
|
|
533
539
|
readonly type: "address";
|
|
534
540
|
readonly internalType: "address";
|
|
535
541
|
}];
|
|
@@ -658,16 +664,6 @@ export declare const midasRedemptionVaultPhantomTokenAbi: readonly [{
|
|
|
658
664
|
readonly internalType: "string";
|
|
659
665
|
}];
|
|
660
666
|
readonly stateMutability: "view";
|
|
661
|
-
}, {
|
|
662
|
-
readonly type: "function";
|
|
663
|
-
readonly name: "tokenOut";
|
|
664
|
-
readonly inputs: readonly [];
|
|
665
|
-
readonly outputs: readonly [{
|
|
666
|
-
readonly name: "";
|
|
667
|
-
readonly type: "address";
|
|
668
|
-
readonly internalType: "address";
|
|
669
|
-
}];
|
|
670
|
-
readonly stateMutability: "view";
|
|
671
667
|
}, {
|
|
672
668
|
readonly type: "function";
|
|
673
669
|
readonly name: "totalSupply";
|