@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 unsafeChange = quotaChange[token]?.balance || 0n;
310
- const change = unsafeChange === exports.MIN_INT96
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 = this.calcDefaultQuota({
340
- lt,
341
- quotaReserve: props.quotaReserve,
342
- amount: amountInTarget,
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()]: (timestamp) => {
17
+ [sdk_gov_1.tokenDataByNetwork.Mainnet.sdGHOV3.toLowerCase()]: (_) => {
18
18
  const REWARD_PERIOD = 14 * 24 * 60 * 60;
19
- // const REWARDS_FIRST_START = 1711641600;
20
- // const REWARDS_FIRST_END = 1712844000;
21
- // const REWARDS_SECOND_END = 1714150800;
22
- const REWARDS_THIRD_END = 1715374800;
23
- const REWARDS_FOURTH_END = REWARDS_THIRD_END + REWARD_PERIOD;
24
- // const REWARD_FIRST_PART = toBN("15000", decimals.GHO);
25
- // const REWARD_SECOND_PART = toBN("15000", decimals.GHO);
26
- const REWARD_THIRD_PART = (0, formatter_1.toBN)("15000", sdk_gov_1.decimals.GHO);
27
- const REWARD_FOURTH_PART = (0, formatter_1.toBN)("7500", sdk_gov_1.decimals.GHO);
28
- const reward = timestamp >= REWARDS_THIRD_END ? REWARD_FOURTH_PART : REWARD_THIRD_PART;
29
- const finished = timestamp >= REWARDS_THIRD_END ? REWARDS_FOURTH_END : REWARDS_THIRD_END;
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),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.191",
3
+ "version": "3.0.0-next.193",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",