@gearbox-protocol/sdk 8.31.2 → 9.0.1
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/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +4 -5
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +67 -70
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +16 -20
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +21 -25
- package/dist/esm/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +4 -5
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +67 -70
- package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +16 -20
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +21 -25
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +6 -8
- package/dist/types/sdk/accounts/types.d.ts +14 -8
- package/package.json +1 -1
|
@@ -116,11 +116,10 @@ class AbstractMigrateCreditAccountsService extends import_base.SDKConstruct {
|
|
|
116
116
|
return tx;
|
|
117
117
|
}
|
|
118
118
|
async getPriceUpdatesForMigration(targetCreditManager, expectedTargetQuota) {
|
|
119
|
-
const updatesPayload = await this.#service.getOnDemandPriceUpdates(
|
|
120
|
-
targetCreditManager,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
119
|
+
const updatesPayload = await this.#service.getOnDemandPriceUpdates({
|
|
120
|
+
creditManager: targetCreditManager,
|
|
121
|
+
desiredQuotas: expectedTargetQuota
|
|
122
|
+
});
|
|
124
123
|
const market = this.sdk.marketRegister.findByCreditManager(targetCreditManager);
|
|
125
124
|
const updates = updatesPayload.raw.length === 0 ? updatesPayload.raw : "priceFeed" in updatesPayload.raw[0] ? updatesPayload.raw : void 0;
|
|
126
125
|
if (!(0, import_versions.isV310)(market.priceOracle.version) || !updates)
|
|
@@ -74,11 +74,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
74
74
|
if (raw.success) {
|
|
75
75
|
return raw;
|
|
76
76
|
}
|
|
77
|
-
const { txs: priceUpdateTxs } = await this.getUpdateForAccount(
|
|
78
|
-
raw.creditManager,
|
|
79
|
-
raw
|
|
80
|
-
|
|
81
|
-
);
|
|
77
|
+
const { txs: priceUpdateTxs } = await this.getUpdateForAccount({
|
|
78
|
+
creditManager: raw.creditManager,
|
|
79
|
+
creditAccount: raw
|
|
80
|
+
});
|
|
82
81
|
const [cad] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
83
82
|
priceUpdates: priceUpdateTxs,
|
|
84
83
|
contracts: [
|
|
@@ -247,7 +246,14 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
247
246
|
* @returns
|
|
248
247
|
*/
|
|
249
248
|
async fullyLiquidate(props) {
|
|
250
|
-
const {
|
|
249
|
+
const {
|
|
250
|
+
account,
|
|
251
|
+
to,
|
|
252
|
+
slippage = 50n,
|
|
253
|
+
force = false,
|
|
254
|
+
keepAssets,
|
|
255
|
+
ignoreReservePrices
|
|
256
|
+
} = props;
|
|
251
257
|
const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
|
|
252
258
|
const routerCloseResult = await this.sdk.routerFor(account).findBestClosePath({
|
|
253
259
|
creditAccount: account,
|
|
@@ -256,11 +262,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
256
262
|
force,
|
|
257
263
|
keepAssets
|
|
258
264
|
});
|
|
259
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
260
|
-
account.creditManager,
|
|
261
|
-
account,
|
|
262
|
-
|
|
263
|
-
);
|
|
265
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
266
|
+
creditManager: account.creditManager,
|
|
267
|
+
creditAccount: account,
|
|
268
|
+
ignoreReservePrices
|
|
269
|
+
});
|
|
264
270
|
const calls = [...priceUpdates, ...routerCloseResult.calls];
|
|
265
271
|
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
266
272
|
account.creditAccount,
|
|
@@ -299,11 +305,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
299
305
|
creditManager: cm.creditManager,
|
|
300
306
|
slippage
|
|
301
307
|
});
|
|
302
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
303
|
-
ca.creditManager,
|
|
304
|
-
ca
|
|
305
|
-
|
|
306
|
-
);
|
|
308
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
309
|
+
creditManager: ca.creditManager,
|
|
310
|
+
creditAccount: ca
|
|
311
|
+
});
|
|
307
312
|
const calls = [
|
|
308
313
|
...operation === "close" ? [] : priceUpdates,
|
|
309
314
|
...routerCloseResult.calls,
|
|
@@ -333,11 +338,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
333
338
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
334
339
|
creditAccount.creditManager
|
|
335
340
|
);
|
|
336
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
337
|
-
creditAccount.creditManager,
|
|
338
|
-
creditAccount
|
|
339
|
-
|
|
340
|
-
);
|
|
341
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
342
|
+
creditManager: creditAccount.creditManager,
|
|
343
|
+
creditAccount
|
|
344
|
+
});
|
|
341
345
|
const calls = [
|
|
342
346
|
...priceUpdates,
|
|
343
347
|
...this.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
@@ -370,11 +374,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
370
374
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
371
375
|
creditAccount.creditManager
|
|
372
376
|
);
|
|
373
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
374
|
-
creditAccount.creditManager,
|
|
377
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
378
|
+
creditManager: creditAccount.creditManager,
|
|
375
379
|
creditAccount,
|
|
376
|
-
averageQuota
|
|
377
|
-
);
|
|
380
|
+
desiredQuotas: averageQuota
|
|
381
|
+
});
|
|
378
382
|
const calls = [
|
|
379
383
|
...priceUpdatesCalls,
|
|
380
384
|
...this.prepareAddCollateral(
|
|
@@ -413,11 +417,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
413
417
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
414
418
|
creditAccount.creditManager
|
|
415
419
|
);
|
|
416
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
417
|
-
creditAccount.creditManager,
|
|
418
|
-
creditAccount
|
|
419
|
-
|
|
420
|
-
);
|
|
420
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
421
|
+
creditManager: creditAccount.creditManager,
|
|
422
|
+
creditAccount
|
|
423
|
+
});
|
|
421
424
|
const underlyingEnabled = (creditAccount.enabledTokensMask & 1n) === 1n;
|
|
422
425
|
const shouldEnable = !isDecrease && !underlyingEnabled;
|
|
423
426
|
const calls = [
|
|
@@ -449,11 +452,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
449
452
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
450
453
|
creditAccount.creditManager
|
|
451
454
|
);
|
|
452
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
453
|
-
creditAccount.creditManager,
|
|
455
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
456
|
+
creditManager: creditAccount.creditManager,
|
|
454
457
|
creditAccount,
|
|
455
|
-
averageQuota
|
|
456
|
-
);
|
|
458
|
+
desiredQuotas: averageQuota
|
|
459
|
+
});
|
|
457
460
|
const calls = [
|
|
458
461
|
...priceUpdatesCalls,
|
|
459
462
|
...swapCalls,
|
|
@@ -504,11 +507,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
504
507
|
args: []
|
|
505
508
|
})
|
|
506
509
|
};
|
|
507
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
508
|
-
creditAccount.creditManager,
|
|
510
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
511
|
+
creditManager: creditAccount.creditManager,
|
|
509
512
|
creditAccount,
|
|
510
|
-
averageQuota
|
|
511
|
-
);
|
|
513
|
+
desiredQuotas: averageQuota
|
|
514
|
+
});
|
|
512
515
|
const mellowAdapter = cm.creditManager.adapters.mustGet(sourceToken);
|
|
513
516
|
const redeem = {
|
|
514
517
|
target: mellowAdapter.address,
|
|
@@ -585,11 +588,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
585
588
|
args: []
|
|
586
589
|
})
|
|
587
590
|
};
|
|
588
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
589
|
-
creditAccount.creditManager,
|
|
591
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
592
|
+
creditManager: creditAccount.creditManager,
|
|
590
593
|
creditAccount,
|
|
591
|
-
averageQuota
|
|
592
|
-
);
|
|
594
|
+
desiredQuotas: averageQuota
|
|
595
|
+
});
|
|
593
596
|
const CLAIMER = "0x25024a3017B8da7161d8c5DCcF768F8678fB5802";
|
|
594
597
|
const mellowClaimerAdapter = cm.creditManager.adapters.mustGet(CLAIMER);
|
|
595
598
|
const multiAcceptContract = (0, import_viem.getContract)({
|
|
@@ -635,11 +638,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
635
638
|
creditAccount: ca
|
|
636
639
|
}) {
|
|
637
640
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
638
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
639
|
-
ca.creditManager,
|
|
640
|
-
ca
|
|
641
|
-
|
|
642
|
-
);
|
|
641
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
642
|
+
creditManager: ca.creditManager,
|
|
643
|
+
creditAccount: ca
|
|
644
|
+
});
|
|
643
645
|
const calls = [
|
|
644
646
|
...priceUpdatesCalls,
|
|
645
647
|
...disabledTokens.map(
|
|
@@ -689,11 +691,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
689
691
|
}) {
|
|
690
692
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
691
693
|
const cm = cmSuite.creditManager;
|
|
692
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
693
|
-
cm.address,
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
);
|
|
694
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
695
|
+
creditManager: cm.address,
|
|
696
|
+
desiredQuotas: averageQuota
|
|
697
|
+
});
|
|
697
698
|
const calls = [
|
|
698
699
|
...priceUpdatesCalls,
|
|
699
700
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
@@ -824,7 +825,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
824
825
|
}
|
|
825
826
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
826
827
|
}
|
|
827
|
-
async getUpdateForAccount(
|
|
828
|
+
async getUpdateForAccount(options) {
|
|
829
|
+
const { creditManager, creditAccount, desiredQuotas, ignoreReservePrices } = options;
|
|
828
830
|
const quotaRecord = desiredQuotas ? (0, import_router.assetsMap)(desiredQuotas) : desiredQuotas;
|
|
829
831
|
const caBalancesRecord = creditAccount ? (0, import_router.assetsMap)(creditAccount.tokens) : creditAccount;
|
|
830
832
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
@@ -857,11 +859,15 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
857
859
|
}
|
|
858
860
|
}
|
|
859
861
|
}
|
|
860
|
-
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens)
|
|
862
|
+
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens), {
|
|
863
|
+
main: true,
|
|
864
|
+
reserve: !ignoreReservePrices
|
|
865
|
+
});
|
|
861
866
|
const tStr = Array.from(tokens).map((t) => this.labelAddress(t)).join(", ");
|
|
867
|
+
const remark = ignoreReservePrices ? " main" : "";
|
|
862
868
|
this.#logger?.debug(
|
|
863
869
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
864
|
-
`generating price feed updates for ${tStr} from ${priceFeeds.length} price feeds`
|
|
870
|
+
`generating price feed updates for ${tStr} from ${priceFeeds.length}${remark} price feeds`
|
|
865
871
|
);
|
|
866
872
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
867
873
|
priceFeeds,
|
|
@@ -870,19 +876,14 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
870
876
|
}
|
|
871
877
|
/**
|
|
872
878
|
* Returns account price updates that can be used in credit facade multicall or liquidator calls
|
|
873
|
-
* @param
|
|
874
|
-
* @param creditAccount
|
|
875
|
-
* @param desiredQuotas
|
|
879
|
+
* @param options
|
|
876
880
|
* @returns
|
|
877
881
|
*/
|
|
878
|
-
async getOnDemandPriceUpdates(
|
|
882
|
+
async getOnDemandPriceUpdates(options) {
|
|
883
|
+
const { creditManager, creditAccount } = options;
|
|
879
884
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
880
885
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
881
|
-
const update = await this.getUpdateForAccount(
|
|
882
|
-
creditManager,
|
|
883
|
-
creditAccount,
|
|
884
|
-
desiredQuotas
|
|
885
|
-
);
|
|
886
|
+
const update = await this.getUpdateForAccount(options);
|
|
886
887
|
this.#logger?.debug(
|
|
887
888
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
888
889
|
`getting on demand price updates from ${update.txs.length} txs`
|
|
@@ -900,12 +901,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
900
901
|
* @param acc
|
|
901
902
|
* @returns
|
|
902
903
|
*/
|
|
903
|
-
async getPriceUpdatesForFacade(
|
|
904
|
-
const updates = await this.getOnDemandPriceUpdates(
|
|
905
|
-
creditManager,
|
|
906
|
-
creditAccount,
|
|
907
|
-
desiredQuotas
|
|
908
|
-
);
|
|
904
|
+
async getPriceUpdatesForFacade(options) {
|
|
905
|
+
const updates = await this.getOnDemandPriceUpdates(options);
|
|
909
906
|
return updates.multicall;
|
|
910
907
|
}
|
|
911
908
|
prepareDisableQuotas(ca) {
|
|
@@ -49,11 +49,10 @@ class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.Abst
|
|
|
49
49
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
50
50
|
creditAccount.creditManager
|
|
51
51
|
);
|
|
52
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
53
|
-
creditAccount.creditManager,
|
|
54
|
-
creditAccount
|
|
55
|
-
|
|
56
|
-
);
|
|
52
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
53
|
+
creditManager: creditAccount.creditManager,
|
|
54
|
+
creditAccount
|
|
55
|
+
});
|
|
57
56
|
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
58
57
|
wrapped,
|
|
59
58
|
false,
|
|
@@ -92,11 +91,10 @@ class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.Abst
|
|
|
92
91
|
}) {
|
|
93
92
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
94
93
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
95
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
96
|
-
ca.creditManager,
|
|
97
|
-
ca
|
|
98
|
-
|
|
99
|
-
);
|
|
94
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
95
|
+
creditManager: ca.creditManager,
|
|
96
|
+
creditAccount: ca
|
|
97
|
+
});
|
|
100
98
|
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
101
99
|
wrapped,
|
|
102
100
|
true,
|
|
@@ -128,11 +126,10 @@ class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.Abst
|
|
|
128
126
|
to
|
|
129
127
|
}) {
|
|
130
128
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
131
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
132
|
-
ca.creditManager,
|
|
133
|
-
ca
|
|
134
|
-
|
|
135
|
-
);
|
|
129
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
130
|
+
creditManager: ca.creditManager,
|
|
131
|
+
creditAccount: ca
|
|
132
|
+
});
|
|
136
133
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
137
134
|
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
138
135
|
wrapped,
|
|
@@ -167,11 +164,10 @@ class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.Abst
|
|
|
167
164
|
}) {
|
|
168
165
|
if (claimCalls.length === 0) throw new Error("No path to execute");
|
|
169
166
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
170
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
171
|
-
ca.creditManager,
|
|
172
|
-
ca
|
|
173
|
-
|
|
174
|
-
);
|
|
167
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
168
|
+
creditManager: ca.creditManager,
|
|
169
|
+
creditAccount: ca
|
|
170
|
+
});
|
|
175
171
|
const calls = [
|
|
176
172
|
...priceUpdatesCalls,
|
|
177
173
|
...claimCalls,
|
|
@@ -37,11 +37,10 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
37
37
|
creditAccount: ca
|
|
38
38
|
}) {
|
|
39
39
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
40
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
41
|
-
ca.creditManager,
|
|
42
|
-
ca
|
|
43
|
-
|
|
44
|
-
);
|
|
40
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
41
|
+
creditManager: ca.creditManager,
|
|
42
|
+
creditAccount: ca
|
|
43
|
+
});
|
|
45
44
|
const addBotCall = {
|
|
46
45
|
target: ca.creditFacade,
|
|
47
46
|
callData: (0, import_viem.encodeFunctionData)({
|
|
@@ -67,11 +66,10 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
67
66
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
68
67
|
creditAccount.creditManager
|
|
69
68
|
);
|
|
70
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
71
|
-
creditAccount.creditManager,
|
|
72
|
-
creditAccount
|
|
73
|
-
|
|
74
|
-
);
|
|
69
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
70
|
+
creditManager: creditAccount.creditManager,
|
|
71
|
+
creditAccount
|
|
72
|
+
});
|
|
75
73
|
const calls = [
|
|
76
74
|
...priceUpdatesCalls,
|
|
77
75
|
...assetsToWithdraw.map(
|
|
@@ -108,11 +106,10 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
108
106
|
calls: [],
|
|
109
107
|
creditAccount: ca
|
|
110
108
|
});
|
|
111
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
112
|
-
ca.creditManager,
|
|
113
|
-
ca
|
|
114
|
-
|
|
115
|
-
);
|
|
109
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
110
|
+
creditManager: ca.creditManager,
|
|
111
|
+
creditAccount: ca
|
|
112
|
+
});
|
|
116
113
|
const calls = [
|
|
117
114
|
...operation === "close" ? [] : priceUpdates,
|
|
118
115
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
@@ -143,11 +140,10 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
143
140
|
calls: [],
|
|
144
141
|
creditAccount: ca
|
|
145
142
|
});
|
|
146
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
147
|
-
ca.creditManager,
|
|
148
|
-
ca
|
|
149
|
-
|
|
150
|
-
);
|
|
143
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
144
|
+
creditManager: ca.creditManager,
|
|
145
|
+
creditAccount: ca
|
|
146
|
+
});
|
|
151
147
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
152
148
|
const calls = [
|
|
153
149
|
...priceUpdates,
|
|
@@ -180,11 +176,11 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
180
176
|
creditAccount: ca
|
|
181
177
|
});
|
|
182
178
|
if (claimPath.calls.length === 0) throw new Error("No path to execute");
|
|
183
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
184
|
-
ca.creditManager,
|
|
185
|
-
ca,
|
|
186
|
-
averageQuota
|
|
187
|
-
);
|
|
179
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
180
|
+
creditManager: ca.creditManager,
|
|
181
|
+
creditAccount: ca,
|
|
182
|
+
desiredQuotas: averageQuota
|
|
183
|
+
});
|
|
188
184
|
const calls = [
|
|
189
185
|
...priceUpdatesCalls,
|
|
190
186
|
...claimPath.calls,
|
|
@@ -96,11 +96,10 @@ class AbstractMigrateCreditAccountsService extends SDKConstruct {
|
|
|
96
96
|
return tx;
|
|
97
97
|
}
|
|
98
98
|
async getPriceUpdatesForMigration(targetCreditManager, expectedTargetQuota) {
|
|
99
|
-
const updatesPayload = await this.#service.getOnDemandPriceUpdates(
|
|
100
|
-
targetCreditManager,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
99
|
+
const updatesPayload = await this.#service.getOnDemandPriceUpdates({
|
|
100
|
+
creditManager: targetCreditManager,
|
|
101
|
+
desiredQuotas: expectedTargetQuota
|
|
102
|
+
});
|
|
104
103
|
const market = this.sdk.marketRegister.findByCreditManager(targetCreditManager);
|
|
105
104
|
const updates = updatesPayload.raw.length === 0 ? updatesPayload.raw : "priceFeed" in updatesPayload.raw[0] ? updatesPayload.raw : void 0;
|
|
106
105
|
if (!isV310(market.priceOracle.version) || !updates)
|
|
@@ -71,11 +71,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
71
71
|
if (raw.success) {
|
|
72
72
|
return raw;
|
|
73
73
|
}
|
|
74
|
-
const { txs: priceUpdateTxs } = await this.getUpdateForAccount(
|
|
75
|
-
raw.creditManager,
|
|
76
|
-
raw
|
|
77
|
-
|
|
78
|
-
);
|
|
74
|
+
const { txs: priceUpdateTxs } = await this.getUpdateForAccount({
|
|
75
|
+
creditManager: raw.creditManager,
|
|
76
|
+
creditAccount: raw
|
|
77
|
+
});
|
|
79
78
|
const [cad] = await simulateWithPriceUpdates(this.client, {
|
|
80
79
|
priceUpdates: priceUpdateTxs,
|
|
81
80
|
contracts: [
|
|
@@ -244,7 +243,14 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
244
243
|
* @returns
|
|
245
244
|
*/
|
|
246
245
|
async fullyLiquidate(props) {
|
|
247
|
-
const {
|
|
246
|
+
const {
|
|
247
|
+
account,
|
|
248
|
+
to,
|
|
249
|
+
slippage = 50n,
|
|
250
|
+
force = false,
|
|
251
|
+
keepAssets,
|
|
252
|
+
ignoreReservePrices
|
|
253
|
+
} = props;
|
|
248
254
|
const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
|
|
249
255
|
const routerCloseResult = await this.sdk.routerFor(account).findBestClosePath({
|
|
250
256
|
creditAccount: account,
|
|
@@ -253,11 +259,11 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
253
259
|
force,
|
|
254
260
|
keepAssets
|
|
255
261
|
});
|
|
256
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
257
|
-
account.creditManager,
|
|
258
|
-
account,
|
|
259
|
-
|
|
260
|
-
);
|
|
262
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
263
|
+
creditManager: account.creditManager,
|
|
264
|
+
creditAccount: account,
|
|
265
|
+
ignoreReservePrices
|
|
266
|
+
});
|
|
261
267
|
const calls = [...priceUpdates, ...routerCloseResult.calls];
|
|
262
268
|
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
263
269
|
account.creditAccount,
|
|
@@ -296,11 +302,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
296
302
|
creditManager: cm.creditManager,
|
|
297
303
|
slippage
|
|
298
304
|
});
|
|
299
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
300
|
-
ca.creditManager,
|
|
301
|
-
ca
|
|
302
|
-
|
|
303
|
-
);
|
|
305
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
306
|
+
creditManager: ca.creditManager,
|
|
307
|
+
creditAccount: ca
|
|
308
|
+
});
|
|
304
309
|
const calls = [
|
|
305
310
|
...operation === "close" ? [] : priceUpdates,
|
|
306
311
|
...routerCloseResult.calls,
|
|
@@ -330,11 +335,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
330
335
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
331
336
|
creditAccount.creditManager
|
|
332
337
|
);
|
|
333
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
334
|
-
creditAccount.creditManager,
|
|
335
|
-
creditAccount
|
|
336
|
-
|
|
337
|
-
);
|
|
338
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
339
|
+
creditManager: creditAccount.creditManager,
|
|
340
|
+
creditAccount
|
|
341
|
+
});
|
|
338
342
|
const calls = [
|
|
339
343
|
...priceUpdates,
|
|
340
344
|
...this.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
@@ -367,11 +371,11 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
367
371
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
368
372
|
creditAccount.creditManager
|
|
369
373
|
);
|
|
370
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
371
|
-
creditAccount.creditManager,
|
|
374
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
375
|
+
creditManager: creditAccount.creditManager,
|
|
372
376
|
creditAccount,
|
|
373
|
-
averageQuota
|
|
374
|
-
);
|
|
377
|
+
desiredQuotas: averageQuota
|
|
378
|
+
});
|
|
375
379
|
const calls = [
|
|
376
380
|
...priceUpdatesCalls,
|
|
377
381
|
...this.prepareAddCollateral(
|
|
@@ -410,11 +414,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
410
414
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
411
415
|
creditAccount.creditManager
|
|
412
416
|
);
|
|
413
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
414
|
-
creditAccount.creditManager,
|
|
415
|
-
creditAccount
|
|
416
|
-
|
|
417
|
-
);
|
|
417
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
418
|
+
creditManager: creditAccount.creditManager,
|
|
419
|
+
creditAccount
|
|
420
|
+
});
|
|
418
421
|
const underlyingEnabled = (creditAccount.enabledTokensMask & 1n) === 1n;
|
|
419
422
|
const shouldEnable = !isDecrease && !underlyingEnabled;
|
|
420
423
|
const calls = [
|
|
@@ -446,11 +449,11 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
446
449
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
447
450
|
creditAccount.creditManager
|
|
448
451
|
);
|
|
449
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
450
|
-
creditAccount.creditManager,
|
|
452
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
453
|
+
creditManager: creditAccount.creditManager,
|
|
451
454
|
creditAccount,
|
|
452
|
-
averageQuota
|
|
453
|
-
);
|
|
455
|
+
desiredQuotas: averageQuota
|
|
456
|
+
});
|
|
454
457
|
const calls = [
|
|
455
458
|
...priceUpdatesCalls,
|
|
456
459
|
...swapCalls,
|
|
@@ -501,11 +504,11 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
501
504
|
args: []
|
|
502
505
|
})
|
|
503
506
|
};
|
|
504
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
505
|
-
creditAccount.creditManager,
|
|
507
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
508
|
+
creditManager: creditAccount.creditManager,
|
|
506
509
|
creditAccount,
|
|
507
|
-
averageQuota
|
|
508
|
-
);
|
|
510
|
+
desiredQuotas: averageQuota
|
|
511
|
+
});
|
|
509
512
|
const mellowAdapter = cm.creditManager.adapters.mustGet(sourceToken);
|
|
510
513
|
const redeem = {
|
|
511
514
|
target: mellowAdapter.address,
|
|
@@ -582,11 +585,11 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
582
585
|
args: []
|
|
583
586
|
})
|
|
584
587
|
};
|
|
585
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
586
|
-
creditAccount.creditManager,
|
|
588
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
589
|
+
creditManager: creditAccount.creditManager,
|
|
587
590
|
creditAccount,
|
|
588
|
-
averageQuota
|
|
589
|
-
);
|
|
591
|
+
desiredQuotas: averageQuota
|
|
592
|
+
});
|
|
590
593
|
const CLAIMER = "0x25024a3017B8da7161d8c5DCcF768F8678fB5802";
|
|
591
594
|
const mellowClaimerAdapter = cm.creditManager.adapters.mustGet(CLAIMER);
|
|
592
595
|
const multiAcceptContract = getContract({
|
|
@@ -632,11 +635,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
632
635
|
creditAccount: ca
|
|
633
636
|
}) {
|
|
634
637
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
635
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
636
|
-
ca.creditManager,
|
|
637
|
-
ca
|
|
638
|
-
|
|
639
|
-
);
|
|
638
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
639
|
+
creditManager: ca.creditManager,
|
|
640
|
+
creditAccount: ca
|
|
641
|
+
});
|
|
640
642
|
const calls = [
|
|
641
643
|
...priceUpdatesCalls,
|
|
642
644
|
...disabledTokens.map(
|
|
@@ -686,11 +688,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
686
688
|
}) {
|
|
687
689
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
688
690
|
const cm = cmSuite.creditManager;
|
|
689
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
690
|
-
cm.address,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
);
|
|
691
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
692
|
+
creditManager: cm.address,
|
|
693
|
+
desiredQuotas: averageQuota
|
|
694
|
+
});
|
|
694
695
|
const calls = [
|
|
695
696
|
...priceUpdatesCalls,
|
|
696
697
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
@@ -821,7 +822,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
821
822
|
}
|
|
822
823
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
823
824
|
}
|
|
824
|
-
async getUpdateForAccount(
|
|
825
|
+
async getUpdateForAccount(options) {
|
|
826
|
+
const { creditManager, creditAccount, desiredQuotas, ignoreReservePrices } = options;
|
|
825
827
|
const quotaRecord = desiredQuotas ? assetsMap(desiredQuotas) : desiredQuotas;
|
|
826
828
|
const caBalancesRecord = creditAccount ? assetsMap(creditAccount.tokens) : creditAccount;
|
|
827
829
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
@@ -854,11 +856,15 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
854
856
|
}
|
|
855
857
|
}
|
|
856
858
|
}
|
|
857
|
-
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens)
|
|
859
|
+
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens), {
|
|
860
|
+
main: true,
|
|
861
|
+
reserve: !ignoreReservePrices
|
|
862
|
+
});
|
|
858
863
|
const tStr = Array.from(tokens).map((t) => this.labelAddress(t)).join(", ");
|
|
864
|
+
const remark = ignoreReservePrices ? " main" : "";
|
|
859
865
|
this.#logger?.debug(
|
|
860
866
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
861
|
-
`generating price feed updates for ${tStr} from ${priceFeeds.length} price feeds`
|
|
867
|
+
`generating price feed updates for ${tStr} from ${priceFeeds.length}${remark} price feeds`
|
|
862
868
|
);
|
|
863
869
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
864
870
|
priceFeeds,
|
|
@@ -867,19 +873,14 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
867
873
|
}
|
|
868
874
|
/**
|
|
869
875
|
* Returns account price updates that can be used in credit facade multicall or liquidator calls
|
|
870
|
-
* @param
|
|
871
|
-
* @param creditAccount
|
|
872
|
-
* @param desiredQuotas
|
|
876
|
+
* @param options
|
|
873
877
|
* @returns
|
|
874
878
|
*/
|
|
875
|
-
async getOnDemandPriceUpdates(
|
|
879
|
+
async getOnDemandPriceUpdates(options) {
|
|
880
|
+
const { creditManager, creditAccount } = options;
|
|
876
881
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
877
882
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
878
|
-
const update = await this.getUpdateForAccount(
|
|
879
|
-
creditManager,
|
|
880
|
-
creditAccount,
|
|
881
|
-
desiredQuotas
|
|
882
|
-
);
|
|
883
|
+
const update = await this.getUpdateForAccount(options);
|
|
883
884
|
this.#logger?.debug(
|
|
884
885
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
885
886
|
`getting on demand price updates from ${update.txs.length} txs`
|
|
@@ -897,12 +898,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
897
898
|
* @param acc
|
|
898
899
|
* @returns
|
|
899
900
|
*/
|
|
900
|
-
async getPriceUpdatesForFacade(
|
|
901
|
-
const updates = await this.getOnDemandPriceUpdates(
|
|
902
|
-
creditManager,
|
|
903
|
-
creditAccount,
|
|
904
|
-
desiredQuotas
|
|
905
|
-
);
|
|
901
|
+
async getPriceUpdatesForFacade(options) {
|
|
902
|
+
const updates = await this.getOnDemandPriceUpdates(options);
|
|
906
903
|
return updates.multicall;
|
|
907
904
|
}
|
|
908
905
|
prepareDisableQuotas(ca) {
|
|
@@ -38,11 +38,10 @@ class CreditAccountServiceV300 extends AbstractCreditAccountService {
|
|
|
38
38
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
39
39
|
creditAccount.creditManager
|
|
40
40
|
);
|
|
41
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
42
|
-
creditAccount.creditManager,
|
|
43
|
-
creditAccount
|
|
44
|
-
|
|
45
|
-
);
|
|
41
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
42
|
+
creditManager: creditAccount.creditManager,
|
|
43
|
+
creditAccount
|
|
44
|
+
});
|
|
46
45
|
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
47
46
|
wrapped,
|
|
48
47
|
false,
|
|
@@ -81,11 +80,10 @@ class CreditAccountServiceV300 extends AbstractCreditAccountService {
|
|
|
81
80
|
}) {
|
|
82
81
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
83
82
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
84
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
85
|
-
ca.creditManager,
|
|
86
|
-
ca
|
|
87
|
-
|
|
88
|
-
);
|
|
83
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
84
|
+
creditManager: ca.creditManager,
|
|
85
|
+
creditAccount: ca
|
|
86
|
+
});
|
|
89
87
|
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
90
88
|
wrapped,
|
|
91
89
|
true,
|
|
@@ -117,11 +115,10 @@ class CreditAccountServiceV300 extends AbstractCreditAccountService {
|
|
|
117
115
|
to
|
|
118
116
|
}) {
|
|
119
117
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
120
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
121
|
-
ca.creditManager,
|
|
122
|
-
ca
|
|
123
|
-
|
|
124
|
-
);
|
|
118
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
119
|
+
creditManager: ca.creditManager,
|
|
120
|
+
creditAccount: ca
|
|
121
|
+
});
|
|
125
122
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
126
123
|
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
127
124
|
wrapped,
|
|
@@ -156,11 +153,10 @@ class CreditAccountServiceV300 extends AbstractCreditAccountService {
|
|
|
156
153
|
}) {
|
|
157
154
|
if (claimCalls.length === 0) throw new Error("No path to execute");
|
|
158
155
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
159
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
160
|
-
ca.creditManager,
|
|
161
|
-
ca
|
|
162
|
-
|
|
163
|
-
);
|
|
156
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
157
|
+
creditManager: ca.creditManager,
|
|
158
|
+
creditAccount: ca
|
|
159
|
+
});
|
|
164
160
|
const calls = [
|
|
165
161
|
...priceUpdatesCalls,
|
|
166
162
|
...claimCalls,
|
|
@@ -14,11 +14,10 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
14
14
|
creditAccount: ca
|
|
15
15
|
}) {
|
|
16
16
|
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
17
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
18
|
-
ca.creditManager,
|
|
19
|
-
ca
|
|
20
|
-
|
|
21
|
-
);
|
|
17
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
18
|
+
creditManager: ca.creditManager,
|
|
19
|
+
creditAccount: ca
|
|
20
|
+
});
|
|
22
21
|
const addBotCall = {
|
|
23
22
|
target: ca.creditFacade,
|
|
24
23
|
callData: encodeFunctionData({
|
|
@@ -44,11 +43,10 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
44
43
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
45
44
|
creditAccount.creditManager
|
|
46
45
|
);
|
|
47
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
48
|
-
creditAccount.creditManager,
|
|
49
|
-
creditAccount
|
|
50
|
-
|
|
51
|
-
);
|
|
46
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
47
|
+
creditManager: creditAccount.creditManager,
|
|
48
|
+
creditAccount
|
|
49
|
+
});
|
|
52
50
|
const calls = [
|
|
53
51
|
...priceUpdatesCalls,
|
|
54
52
|
...assetsToWithdraw.map(
|
|
@@ -85,11 +83,10 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
85
83
|
calls: [],
|
|
86
84
|
creditAccount: ca
|
|
87
85
|
});
|
|
88
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
89
|
-
ca.creditManager,
|
|
90
|
-
ca
|
|
91
|
-
|
|
92
|
-
);
|
|
86
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
87
|
+
creditManager: ca.creditManager,
|
|
88
|
+
creditAccount: ca
|
|
89
|
+
});
|
|
93
90
|
const calls = [
|
|
94
91
|
...operation === "close" ? [] : priceUpdates,
|
|
95
92
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
@@ -120,11 +117,10 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
120
117
|
calls: [],
|
|
121
118
|
creditAccount: ca
|
|
122
119
|
});
|
|
123
|
-
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
124
|
-
ca.creditManager,
|
|
125
|
-
ca
|
|
126
|
-
|
|
127
|
-
);
|
|
120
|
+
const priceUpdates = await this.getPriceUpdatesForFacade({
|
|
121
|
+
creditManager: ca.creditManager,
|
|
122
|
+
creditAccount: ca
|
|
123
|
+
});
|
|
128
124
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
129
125
|
const calls = [
|
|
130
126
|
...priceUpdates,
|
|
@@ -157,11 +153,11 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
157
153
|
creditAccount: ca
|
|
158
154
|
});
|
|
159
155
|
if (claimPath.calls.length === 0) throw new Error("No path to execute");
|
|
160
|
-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
161
|
-
ca.creditManager,
|
|
162
|
-
ca,
|
|
163
|
-
averageQuota
|
|
164
|
-
);
|
|
156
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
157
|
+
creditManager: ca.creditManager,
|
|
158
|
+
creditAccount: ca,
|
|
159
|
+
desiredQuotas: averageQuota
|
|
160
|
+
});
|
|
165
161
|
const calls = [
|
|
166
162
|
...priceUpdatesCalls,
|
|
167
163
|
...claimPath.calls,
|
|
@@ -3,9 +3,9 @@ import type { CreditAccountData } from "../base/index.js";
|
|
|
3
3
|
import { SDKConstruct } from "../base/index.js";
|
|
4
4
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
5
5
|
import type { OnDemandPriceUpdates, PriceUpdateV300, PriceUpdateV310, UpdatePriceFeedsResult } from "../market/index.js";
|
|
6
|
-
import { type Asset, type
|
|
6
|
+
import { type Asset, type RouterCASlice } from "../router/index.js";
|
|
7
7
|
import type { MultiCall } from "../types/index.js";
|
|
8
|
-
import type { ClaimDelayedProps, FullyLiquidateProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, StartDelayedWithdrawalProps } from "./types";
|
|
8
|
+
import type { ClaimDelayedProps, FullyLiquidateProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, PriceUpdatesOptions, StartDelayedWithdrawalProps } from "./types";
|
|
9
9
|
import type { AddCollateralProps, ChangeDeptProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, GetCreditAccountsOptions, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, Rewards, UpdateQuotasProps } from "./types.js";
|
|
10
10
|
export interface CreditAccountServiceOptions {
|
|
11
11
|
batchSize?: number;
|
|
@@ -182,15 +182,13 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
|
|
|
182
182
|
* @returns
|
|
183
183
|
*/
|
|
184
184
|
getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
|
|
185
|
-
protected getUpdateForAccount(
|
|
185
|
+
protected getUpdateForAccount(options: PriceUpdatesOptions): Promise<UpdatePriceFeedsResult>;
|
|
186
186
|
/**
|
|
187
187
|
* Returns account price updates that can be used in credit facade multicall or liquidator calls
|
|
188
|
-
* @param
|
|
189
|
-
* @param creditAccount
|
|
190
|
-
* @param desiredQuotas
|
|
188
|
+
* @param options
|
|
191
189
|
* @returns
|
|
192
190
|
*/
|
|
193
|
-
getOnDemandPriceUpdates(
|
|
191
|
+
getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<OnDemandPriceUpdates<PriceUpdateV310 | PriceUpdateV300>>;
|
|
194
192
|
/**
|
|
195
193
|
* Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
|
|
196
194
|
* - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
|
|
@@ -199,7 +197,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
|
|
|
199
197
|
* @param acc
|
|
200
198
|
* @returns
|
|
201
199
|
*/
|
|
202
|
-
getPriceUpdatesForFacade(
|
|
200
|
+
getPriceUpdatesForFacade(options: PriceUpdatesOptions): Promise<Array<MultiCall>>;
|
|
203
201
|
protected prepareDisableQuotas(ca: RouterCASlice): Array<MultiCall>;
|
|
204
202
|
protected prepareUpdateQuotas(creditFacade: Address, { averageQuota, minQuota }: PrepareUpdateQuotasProps): Array<MultiCall>;
|
|
205
203
|
protected prepareDecreaseDebt(ca: RouterCASlice): Array<MultiCall>;
|
|
@@ -32,6 +32,12 @@ export interface GetCreditAccountsOptions {
|
|
|
32
32
|
*/
|
|
33
33
|
ignoreReservePrices?: boolean;
|
|
34
34
|
}
|
|
35
|
+
export interface PriceUpdatesOptions {
|
|
36
|
+
creditManager: Address;
|
|
37
|
+
creditAccount?: CreditAccountTokensSlice;
|
|
38
|
+
desiredQuotas?: Asset[];
|
|
39
|
+
ignoreReservePrices?: boolean;
|
|
40
|
+
}
|
|
35
41
|
export interface CloseCreditAccountResult extends CreditAccountOperationResult {
|
|
36
42
|
routerCloseResult: RouterCloseResult;
|
|
37
43
|
}
|
|
@@ -305,6 +311,10 @@ export interface FullyLiquidateProps {
|
|
|
305
311
|
* List of assets to keep on account after liquidation
|
|
306
312
|
*/
|
|
307
313
|
keepAssets?: Address[];
|
|
314
|
+
/**
|
|
315
|
+
* If true, will ignore reserve prices
|
|
316
|
+
*/
|
|
317
|
+
ignoreReservePrices?: boolean;
|
|
308
318
|
}
|
|
309
319
|
export interface PermitResult {
|
|
310
320
|
r: Address;
|
|
@@ -518,20 +528,16 @@ export interface ICreditAccountsService extends SDKConstruct {
|
|
|
518
528
|
getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
|
|
519
529
|
/**
|
|
520
530
|
* Returns account price updates that can be used in credit facade multicall or liquidator calls
|
|
521
|
-
* @param
|
|
522
|
-
* @param creditAccount
|
|
523
|
-
* @param desiredQuotas
|
|
531
|
+
* @param options
|
|
524
532
|
* @returns
|
|
525
533
|
*/
|
|
526
|
-
getOnDemandPriceUpdates(
|
|
534
|
+
getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<OnDemandPriceUpdates<PriceUpdateV310 | PriceUpdateV300>>;
|
|
527
535
|
/**
|
|
528
536
|
* Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
|
|
529
|
-
* @param
|
|
530
|
-
* @param creditAccount
|
|
531
|
-
* @param desiredQuotas
|
|
537
|
+
* @param options
|
|
532
538
|
* @returns
|
|
533
539
|
*/
|
|
534
|
-
getPriceUpdatesForFacade(
|
|
540
|
+
getPriceUpdatesForFacade(options: PriceUpdatesOptions): Promise<Array<MultiCall>>;
|
|
535
541
|
/**
|
|
536
542
|
* Withdraws a single collateral from credit account to wallet to and updates quotas;
|
|
537
543
|
* technically can withdraw several tokens at once
|