@gearbox-protocol/sdk 3.0.0-next.191 → 3.0.0-next.193
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.
|
@@ -50,6 +50,10 @@ export interface CalcQuotaUpdateProps {
|
|
|
50
50
|
liquidationThresholds: Record<string, bigint>;
|
|
51
51
|
assetsAfterUpdate: Record<string, AssetWithAmountInTarget>;
|
|
52
52
|
maxDebt: bigint;
|
|
53
|
+
calcModification?: {
|
|
54
|
+
type: "recommendedQuota";
|
|
55
|
+
debt: bigint;
|
|
56
|
+
};
|
|
53
57
|
allowedToSpend: Record<string, {}>;
|
|
54
58
|
allowedToObtain: Record<string, {}>;
|
|
55
59
|
quotaReserve: bigint;
|
|
@@ -306,11 +306,8 @@ class CreditAccountData {
|
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
else {
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
? math_1.BigIntMath.neg(this.roundUpQuota(initialQuotas[cmQuota.token]?.quota || 0n))
|
|
312
|
-
: unsafeChange;
|
|
313
|
-
const quotaAfter = initialQuota + change;
|
|
309
|
+
const change = quotaChange[token]?.balance || 0n;
|
|
310
|
+
const quotaAfter = change === exports.MIN_INT96 ? 0n : initialQuota + change;
|
|
314
311
|
acc[token] = {
|
|
315
312
|
balance: quotaAfter,
|
|
316
313
|
token,
|
|
@@ -336,11 +333,19 @@ class CreditAccountData {
|
|
|
336
333
|
const lt = props.liquidationThresholds[token] || 0n;
|
|
337
334
|
const maxQuotaIncrease = this.roundUpQuota(unsafeMaxQuotaIncrease);
|
|
338
335
|
const initialQuota = this.roundUpQuota(unsafeInitialQuota);
|
|
339
|
-
const defaultQuota =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
336
|
+
const defaultQuota = props.calcModification?.type === "recommendedQuota" &&
|
|
337
|
+
props.calcModification.debt > 0
|
|
338
|
+
? this.calcRecommendedQuota({
|
|
339
|
+
lt,
|
|
340
|
+
quotaReserve: props.quotaReserve,
|
|
341
|
+
amount: amountInTarget,
|
|
342
|
+
debt: props.calcModification.debt,
|
|
343
|
+
})
|
|
344
|
+
: this.calcDefaultQuota({
|
|
345
|
+
lt,
|
|
346
|
+
quotaReserve: props.quotaReserve,
|
|
347
|
+
amount: amountInTarget,
|
|
348
|
+
});
|
|
344
349
|
const unsafeQuotaChange = this.roundUpQuota(defaultQuota - initialQuota);
|
|
345
350
|
const quotaChange = unsafeQuotaChange > 0
|
|
346
351
|
? math_1.BigIntMath.min(maxQuotaIncrease, unsafeQuotaChange)
|
|
@@ -810,6 +810,63 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
810
810
|
},
|
|
811
811
|
});
|
|
812
812
|
});
|
|
813
|
+
it("swap should buy additional quota with respect to debt", () => {
|
|
814
|
+
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
815
|
+
maxDebt: HUGE_MAX_DEBT,
|
|
816
|
+
quotaReserve: QUOTA_RESERVE,
|
|
817
|
+
quotas: cmQuotas,
|
|
818
|
+
initialQuotas: caQuota,
|
|
819
|
+
calcModification: {
|
|
820
|
+
debt: 7n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
821
|
+
type: "recommendedQuota",
|
|
822
|
+
},
|
|
823
|
+
assetsAfterUpdate: {
|
|
824
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {
|
|
825
|
+
amountInTarget: 10n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
826
|
+
balance: 0n,
|
|
827
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
828
|
+
},
|
|
829
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
830
|
+
amountInTarget: 0n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
831
|
+
balance: 0n,
|
|
832
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH,
|
|
833
|
+
},
|
|
834
|
+
},
|
|
835
|
+
allowedToObtain: {
|
|
836
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {},
|
|
837
|
+
},
|
|
838
|
+
allowedToSpend: {
|
|
839
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {},
|
|
840
|
+
},
|
|
841
|
+
liquidationThresholds: DEFAULT_LT,
|
|
842
|
+
});
|
|
843
|
+
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
844
|
+
{
|
|
845
|
+
balance: 2n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
846
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
847
|
+
},
|
|
848
|
+
]);
|
|
849
|
+
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([
|
|
850
|
+
{
|
|
851
|
+
balance: creditAccount_1.MIN_INT96,
|
|
852
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH,
|
|
853
|
+
},
|
|
854
|
+
]);
|
|
855
|
+
(0, chai_1.expect)(result.desiredQuota).to.be.deep.eq({
|
|
856
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {
|
|
857
|
+
balance: 7n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
858
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
859
|
+
},
|
|
860
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
861
|
+
balance: 0n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
862
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH,
|
|
863
|
+
},
|
|
864
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
865
|
+
balance: 0n * sdk_gov_1.PERCENTAGE_FACTOR,
|
|
866
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.STETH,
|
|
867
|
+
},
|
|
868
|
+
});
|
|
869
|
+
});
|
|
813
870
|
it("swap shouldn't buy additional quota", () => {
|
|
814
871
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
815
872
|
maxDebt: HUGE_MAX_DEBT,
|
|
@@ -14,19 +14,20 @@ const formatter_1 = require("../utils/formatter");
|
|
|
14
14
|
const math_1 = require("../utils/math");
|
|
15
15
|
const abi_1 = require("./abi");
|
|
16
16
|
const EXTRA_LM_MINING = {
|
|
17
|
-
[sdk_gov_1.tokenDataByNetwork.Mainnet.sdGHOV3.toLowerCase()]: (
|
|
17
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.sdGHOV3.toLowerCase()]: (_) => {
|
|
18
18
|
const REWARD_PERIOD = 14 * 24 * 60 * 60;
|
|
19
|
-
// const
|
|
20
|
-
// const
|
|
21
|
-
// const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
// const
|
|
25
|
-
// const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
19
|
+
// const REWARDS_1_END = 1712844000;
|
|
20
|
+
// const REWARDS_2_END = 1714150800;
|
|
21
|
+
// const REWARDS_3_END = 1715374800;
|
|
22
|
+
// const REWARDS_4_END = 1716793200;
|
|
23
|
+
const REWARDS_5_END = 1718024669;
|
|
24
|
+
// const REWARD_1_PART = toBN("15000", decimals.GHO);
|
|
25
|
+
// const REWARD_2_PART = toBN("15000", decimals.GHO);
|
|
26
|
+
// const REWARD_3_PART = toBN("15000", decimals.GHO);
|
|
27
|
+
// const REWARD_4_PART = toBN("7500", decimals.GHO);
|
|
28
|
+
const REWARD_5_PART = (0, formatter_1.toBN)("3750", sdk_gov_1.decimals.GHO);
|
|
29
|
+
const reward = REWARD_5_PART;
|
|
30
|
+
const finished = REWARDS_5_END;
|
|
30
31
|
return {
|
|
31
32
|
balance: 0n,
|
|
32
33
|
duration: BigInt(REWARD_PERIOD),
|