@gearbox-protocol/sdk 10.2.6 → 10.2.7
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.
|
@@ -31,6 +31,7 @@ var import_v300 = require("../../abi/v300.js");
|
|
|
31
31
|
var import_AbstractMigrateCreditAccountsService = require("../accountMigration/AbstractMigrateCreditAccountsService.js");
|
|
32
32
|
var import_base = require("../base/index.js");
|
|
33
33
|
var import_constants = require("../constants/index.js");
|
|
34
|
+
var import__ = require("../index.js");
|
|
34
35
|
var import_router = require("../router/index.js");
|
|
35
36
|
var import_utils = require("../utils/index.js");
|
|
36
37
|
var import_viem2 = require("../utils/viem/index.js");
|
|
@@ -413,13 +414,14 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
413
414
|
*/
|
|
414
415
|
async changeDebt({
|
|
415
416
|
creditAccount,
|
|
416
|
-
amount
|
|
417
|
+
amount,
|
|
418
|
+
addCollateral
|
|
417
419
|
}) {
|
|
418
420
|
if (amount === 0n) {
|
|
419
421
|
throw new Error("debt increase or decrease must be non-zero");
|
|
420
422
|
}
|
|
421
423
|
const isDecrease = amount < 0n;
|
|
422
|
-
const change =
|
|
424
|
+
const change = import__.BigIntMath.abs(amount);
|
|
423
425
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
424
426
|
creditAccount.creditManager
|
|
425
427
|
);
|
|
@@ -427,10 +429,21 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
427
429
|
creditManager: creditAccount.creditManager,
|
|
428
430
|
creditAccount
|
|
429
431
|
});
|
|
432
|
+
const addCollateralCalls = addCollateral && isDecrease ? this.prepareAddCollateral(
|
|
433
|
+
creditAccount.creditFacade,
|
|
434
|
+
[
|
|
435
|
+
{
|
|
436
|
+
token: creditAccount.underlying,
|
|
437
|
+
balance: change
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
{}
|
|
441
|
+
) : [];
|
|
430
442
|
const underlyingEnabled = (creditAccount.enabledTokensMask & 1n) === 1n;
|
|
431
443
|
const shouldEnable = !isDecrease && !underlyingEnabled;
|
|
432
444
|
const calls = [
|
|
433
445
|
...priceUpdatesCalls,
|
|
446
|
+
...addCollateralCalls,
|
|
434
447
|
...shouldEnable ? this.#prepareEnableTokens(creditAccount.creditFacade, [
|
|
435
448
|
creditAccount.underlying
|
|
436
449
|
]) : [],
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
RAY,
|
|
23
23
|
VERSION_RANGE_310
|
|
24
24
|
} from "../constants/index.js";
|
|
25
|
+
import { BigIntMath } from "../index.js";
|
|
25
26
|
import { assetsMap } from "../router/index.js";
|
|
26
27
|
import { AddressMap, childLogger } from "../utils/index.js";
|
|
27
28
|
import { simulateWithPriceUpdates } from "../utils/viem/index.js";
|
|
@@ -404,13 +405,14 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
404
405
|
*/
|
|
405
406
|
async changeDebt({
|
|
406
407
|
creditAccount,
|
|
407
|
-
amount
|
|
408
|
+
amount,
|
|
409
|
+
addCollateral
|
|
408
410
|
}) {
|
|
409
411
|
if (amount === 0n) {
|
|
410
412
|
throw new Error("debt increase or decrease must be non-zero");
|
|
411
413
|
}
|
|
412
414
|
const isDecrease = amount < 0n;
|
|
413
|
-
const change =
|
|
415
|
+
const change = BigIntMath.abs(amount);
|
|
414
416
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
415
417
|
creditAccount.creditManager
|
|
416
418
|
);
|
|
@@ -418,10 +420,21 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
418
420
|
creditManager: creditAccount.creditManager,
|
|
419
421
|
creditAccount
|
|
420
422
|
});
|
|
423
|
+
const addCollateralCalls = addCollateral && isDecrease ? this.prepareAddCollateral(
|
|
424
|
+
creditAccount.creditFacade,
|
|
425
|
+
[
|
|
426
|
+
{
|
|
427
|
+
token: creditAccount.underlying,
|
|
428
|
+
balance: change
|
|
429
|
+
}
|
|
430
|
+
],
|
|
431
|
+
{}
|
|
432
|
+
) : [];
|
|
421
433
|
const underlyingEnabled = (creditAccount.enabledTokensMask & 1n) === 1n;
|
|
422
434
|
const shouldEnable = !isDecrease && !underlyingEnabled;
|
|
423
435
|
const calls = [
|
|
424
436
|
...priceUpdatesCalls,
|
|
437
|
+
...addCollateralCalls,
|
|
425
438
|
...shouldEnable ? this.#prepareEnableTokens(creditAccount.creditFacade, [
|
|
426
439
|
creditAccount.underlying
|
|
427
440
|
]) : [],
|
|
@@ -104,7 +104,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
|
|
|
104
104
|
positive value for debt increase.
|
|
105
105
|
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
106
106
|
*/
|
|
107
|
-
changeDebt({ creditAccount, amount, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
|
|
107
|
+
changeDebt({ creditAccount, amount, addCollateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
|
|
108
108
|
/**
|
|
109
109
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
110
110
|
- Swap is executed in the following order: price update -> execute swap path -> update quotas
|
|
@@ -291,6 +291,10 @@ export interface ChangeDeptProps {
|
|
|
291
291
|
* positive value for debt increase.
|
|
292
292
|
*/
|
|
293
293
|
amount: bigint;
|
|
294
|
+
/**
|
|
295
|
+
* If true, will add collateral to the credit account
|
|
296
|
+
*/
|
|
297
|
+
addCollateral: boolean;
|
|
294
298
|
}
|
|
295
299
|
export interface FullyLiquidateProps {
|
|
296
300
|
/**
|