@gearbox-protocol/sdk 3.0.0-next.190 → 3.0.0-next.192

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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.190",
3
+ "version": "3.0.0-next.192",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@gearbox-protocol/bots-v3": "^1.5.1",
34
- "@gearbox-protocol/sdk-gov": "^2.2.8",
34
+ "@gearbox-protocol/sdk-gov": "^2.4.0",
35
35
  "axios": "^1.2.6",
36
36
  "decimal.js-light": "^2.5.1",
37
37
  "deep-eql": "^4.1.0",