@gearbox-protocol/sdk 3.0.0-next.79 → 3.0.0-next.80
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.
|
@@ -29,6 +29,7 @@ export interface CalcQuotaUpdateProps {
|
|
|
29
29
|
assetsAfterUpdate: Record<string, AssetWithAmountInTarget>;
|
|
30
30
|
allowedToSpend: Record<string, {}>;
|
|
31
31
|
allowedToObtain: Record<string, {}>;
|
|
32
|
+
quotaReserve: bigint;
|
|
32
33
|
}
|
|
33
34
|
interface CalcQuotaUpdateReturnType {
|
|
34
35
|
desiredQuota: Record<string, Asset>;
|
|
@@ -86,7 +87,7 @@ export declare class CreditAccountData {
|
|
|
86
87
|
hash(): string;
|
|
87
88
|
static hash(creditManager: string, borrower: string): string;
|
|
88
89
|
static calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, borrowed, prices, }: CalcHealthFactorProps): number;
|
|
89
|
-
static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, allowedToSpend, allowedToObtain, }: CalcQuotaUpdateProps): CalcQuotaUpdateReturnType;
|
|
90
|
+
static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, allowedToSpend, allowedToObtain, quotaReserve, }: CalcQuotaUpdateProps): CalcQuotaUpdateReturnType;
|
|
90
91
|
static calcQuotaBorrowRate({ quotas, quotaRates, borrowAmount, }: CalcQuotaBorrowRateProps): number;
|
|
91
92
|
}
|
|
92
93
|
export {};
|
|
@@ -204,7 +204,7 @@ class CreditAccountData {
|
|
|
204
204
|
const hfInPercent = borrowedMoney > 0n ? assetLTMoney / borrowedMoney : 0n;
|
|
205
205
|
return Number(hfInPercent);
|
|
206
206
|
}
|
|
207
|
-
static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, allowedToSpend, allowedToObtain, }) {
|
|
207
|
+
static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, allowedToSpend, allowedToObtain, quotaReserve, }) {
|
|
208
208
|
const r = Object.values(quotas).reduce((acc, cmQuota) => {
|
|
209
209
|
const { token, isActive } = cmQuota;
|
|
210
210
|
const { quota: initialQuota = 0n } = initialQuotas[token] || {};
|
|
@@ -217,7 +217,8 @@ class CreditAccountData {
|
|
|
217
217
|
}
|
|
218
218
|
const after = assetsAfterUpdate[token];
|
|
219
219
|
const { amountInTarget = 0n } = after || {};
|
|
220
|
-
const desiredQuota = (amountInTarget *
|
|
220
|
+
const desiredQuota = (amountInTarget * (sdk_gov_1.PERCENTAGE_FACTOR + quotaReserve)) /
|
|
221
|
+
sdk_gov_1.PERCENTAGE_FACTOR;
|
|
221
222
|
const quotaChange = desiredQuota - initialQuota;
|
|
222
223
|
const correctIncrease = after && allowedToObtain[token] && quotaChange > 0;
|
|
223
224
|
const correctDecrease = after && allowedToSpend[token] && quotaChange < 0;
|
|
@@ -6,6 +6,7 @@ const formatter_1 = require("../utils/formatter");
|
|
|
6
6
|
const price_1 = require("../utils/price");
|
|
7
7
|
const assets_1 = require("./assets");
|
|
8
8
|
const creditAccount_1 = require("./creditAccount");
|
|
9
|
+
const QUOTA_RESERVE = 100n;
|
|
9
10
|
const prices = {
|
|
10
11
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: (0, formatter_1.toBN)("1738.11830000", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
11
12
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: (0, formatter_1.toBN)("0.99941103", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
@@ -411,6 +412,7 @@ const caQuota = {
|
|
|
411
412
|
describe("CreditAccount calcQuotaUpdate test", () => {
|
|
412
413
|
it("open account should buy quota", () => {
|
|
413
414
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
415
|
+
quotaReserve: QUOTA_RESERVE,
|
|
414
416
|
quotas: cmQuotas,
|
|
415
417
|
initialQuotas: {},
|
|
416
418
|
assetsAfterUpdate: {
|
|
@@ -459,6 +461,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
459
461
|
});
|
|
460
462
|
it("add collateral should buy quota", () => {
|
|
461
463
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
464
|
+
quotaReserve: QUOTA_RESERVE,
|
|
462
465
|
quotas: cmQuotas,
|
|
463
466
|
initialQuotas: caQuota,
|
|
464
467
|
assetsAfterUpdate: {
|
|
@@ -497,6 +500,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
497
500
|
});
|
|
498
501
|
it("add collateral should add additional quota", () => {
|
|
499
502
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
503
|
+
quotaReserve: QUOTA_RESERVE,
|
|
500
504
|
quotas: cmQuotas,
|
|
501
505
|
initialQuotas: caQuota,
|
|
502
506
|
assetsAfterUpdate: {
|
|
@@ -535,6 +539,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
535
539
|
});
|
|
536
540
|
it("add collateral shouldn't add additional quota", () => {
|
|
537
541
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
542
|
+
quotaReserve: QUOTA_RESERVE,
|
|
538
543
|
quotas: cmQuotas,
|
|
539
544
|
initialQuotas: caQuota,
|
|
540
545
|
assetsAfterUpdate: {
|
|
@@ -568,6 +573,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
568
573
|
});
|
|
569
574
|
it("swap should buy quota", () => {
|
|
570
575
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
576
|
+
quotaReserve: QUOTA_RESERVE,
|
|
571
577
|
quotas: cmQuotas,
|
|
572
578
|
initialQuotas: caQuota,
|
|
573
579
|
assetsAfterUpdate: {
|
|
@@ -613,6 +619,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
613
619
|
});
|
|
614
620
|
it("swap should add additional quota", () => {
|
|
615
621
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
622
|
+
quotaReserve: QUOTA_RESERVE,
|
|
616
623
|
quotas: cmQuotas,
|
|
617
624
|
initialQuotas: caQuota,
|
|
618
625
|
assetsAfterUpdate: {
|
|
@@ -663,6 +670,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
663
670
|
});
|
|
664
671
|
it("swap shouldn't add additional quota", () => {
|
|
665
672
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
673
|
+
quotaReserve: QUOTA_RESERVE,
|
|
666
674
|
quotas: cmQuotas,
|
|
667
675
|
initialQuotas: caQuota,
|
|
668
676
|
assetsAfterUpdate: {
|
|
@@ -706,6 +714,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
706
714
|
});
|
|
707
715
|
it("shouldn't change quota if disallowed", () => {
|
|
708
716
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
717
|
+
quotaReserve: QUOTA_RESERVE,
|
|
709
718
|
quotas: cmQuotas,
|
|
710
719
|
initialQuotas: caQuota,
|
|
711
720
|
assetsAfterUpdate: {
|
|
@@ -742,6 +751,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
742
751
|
});
|
|
743
752
|
it("shouldn't change quota if it is disabled", () => {
|
|
744
753
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
754
|
+
quotaReserve: QUOTA_RESERVE,
|
|
745
755
|
quotas: {
|
|
746
756
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {
|
|
747
757
|
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|