@gearbox-protocol/sdk 3.0.0-next.25 → 3.0.0-next.26

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.
@@ -84,7 +84,7 @@ export declare class CreditAccountData {
84
84
  isTokenEnabled(index: number): boolean;
85
85
  static isTokenEnabled(index: number, enabledTokenMask: bigint): boolean;
86
86
  static calcMaxDebtIncrease(healthFactor: number, borrowAmountPlusInterest: bigint, underlyingLT: number, minHf?: number): bigint;
87
- static calcOverallAPY({ caAssets, lpAPY, prices, quotas, quotaRates, totalValue, debt, baseBorrowRate, underlyingToken, }: CalcOverallAPYProps): number | undefined;
87
+ static calcOverallAPY({ caAssets, lpAPY, prices, quotas, quotaRates, totalValue, debt, baseBorrowRate, underlyingToken, }: CalcOverallAPYProps): bigint | undefined;
88
88
  hash(): string;
89
89
  static hash(creditManager: string, borrower: string): string;
90
90
  static calcHealthFactor({ assets, quotas, liquidationThresholds, underlyingToken, borrowed, prices, }: CalcHealthFactorProps): number;
@@ -83,7 +83,7 @@ class CreditAccountData {
83
83
  isEnabled: b.isEnabled,
84
84
  isQuoted: b.isQuoted,
85
85
  quota: (0, sdk_gov_1.toBigInt)(b.quota),
86
- quotaRate: b.quotaRate,
86
+ quotaRate: Number((0, sdk_gov_1.toBigInt)(b.quotaRate) * sdk_gov_1.PERCENTAGE_DECIMALS),
87
87
  };
88
88
  if (!b.isForbidden) {
89
89
  this.balances[token] = balance.balance;
@@ -181,10 +181,8 @@ class CreditAccountData {
181
181
  });
182
182
  const debtAPY = debt * BigInt(baseBorrowRate);
183
183
  const yourAssets = totalValue - debt;
184
- const apyInPercent = ((assetAPYAmountInUnderlying - debtAPY) * sdk_gov_1.WAD) /
185
- yourAssets /
186
- sdk_gov_1.PERCENTAGE_FACTOR;
187
- return Number((0, formatter_1.toSignificant)(apyInPercent, sdk_gov_1.WAD_DECIMALS_POW));
184
+ const apyInPercent = (assetAPYAmountInUnderlying - debtAPY) / yourAssets;
185
+ return apyInPercent;
188
186
  }
189
187
  hash() {
190
188
  return CreditAccountData.hash(this.creditManager, this.borrower);
@@ -79,7 +79,7 @@ describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
79
79
  lpAPY,
80
80
  prices,
81
81
  });
82
- (0, chai_1.expect)(result).to.be.eq(-6.94841);
82
+ (0, chai_1.expect)(result).to.be.eq(-69484n);
83
83
  });
84
84
  it("overall APY calculation for caWithLP is correct", () => {
85
85
  const result = creditAccount_1.CreditAccountData.calcOverallAPY({
@@ -93,7 +93,7 @@ describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
93
93
  lpAPY,
94
94
  prices,
95
95
  });
96
- (0, chai_1.expect)(result).to.be.eq(14.4919);
96
+ (0, chai_1.expect)(result).to.be.eq(144919n);
97
97
  });
98
98
  it("overall APY is undefined when !lpAPY", () => {
99
99
  const result = creditAccount_1.CreditAccountData.calcOverallAPY({
@@ -163,7 +163,7 @@ describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
163
163
  lpAPY,
164
164
  prices,
165
165
  });
166
- (0, chai_1.expect)(result).to.be.eq(-1.86801);
166
+ (0, chai_1.expect)(result).to.be.eq(-18680n);
167
167
  });
168
168
  it("overall APY calculation for caWithLP with insufficient quota is correct", () => {
169
169
  const result = creditAccount_1.CreditAccountData.calcOverallAPY({
@@ -182,7 +182,7 @@ describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
182
182
  lpAPY,
183
183
  prices,
184
184
  });
185
- (0, chai_1.expect)(result).to.be.eq(14.4919);
185
+ (0, chai_1.expect)(result).to.be.eq(144919n);
186
186
  });
187
187
  });
188
188
  describe("CreditAccount calcMaxIncreaseBorrow test", () => {
@@ -1,8 +1,10 @@
1
1
  import { MultiCall } from "../pathfinder/core";
2
2
  import { ChartsCreditManagerPayload, CreditManagerDataPayload, QuotaInfo } from "../payload/creditManager";
3
3
  import { LinearModel } from "../payload/pool";
4
+ type PoolType = "universal" | "trade" | "farm";
4
5
  export declare class CreditManagerData {
5
6
  readonly address: string;
7
+ readonly type: PoolType;
6
8
  readonly underlyingToken: string;
7
9
  readonly pool: string;
8
10
  readonly creditFacade: string;
@@ -32,6 +34,8 @@ export declare class CreditManagerData {
32
34
  readonly quotas: Record<string, QuotaInfo>;
33
35
  readonly interestModel: LinearModel;
34
36
  constructor(payload: CreditManagerDataPayload);
37
+ get id(): string;
38
+ static getCMType(name: string): PoolType;
35
39
  isQuoted(token: string): boolean;
36
40
  encodeAddCollateralV2(tokenAddress: string, amount: bigint): MultiCall;
37
41
  encodeAddCollateralV3(tokenAddress: string, amount: bigint): MultiCall;
@@ -45,7 +49,6 @@ export declare class CreditManagerData {
45
49
  encodeDisableTokenV3(token: string): MultiCall;
46
50
  encodeUpdateQuotaV3(token: string, quotaChange: bigint, minQuota: bigint): MultiCall;
47
51
  static withdrawAllAndUnwrap_Convex(address: string, claim: boolean): MultiCall;
48
- get id(): string;
49
52
  }
50
53
  export declare class ChartsCreditManagerData {
51
54
  readonly id: string;
@@ -90,3 +93,4 @@ export declare class ChartsCreditManagerData {
90
93
  readonly liquidationThresholds: Record<string, bigint>;
91
94
  constructor(payload: ChartsCreditManagerPayload);
92
95
  }
96
+ export {};
@@ -6,6 +6,7 @@ const txParser_1 = require("../parsers/txParser");
6
6
  const types_1 = require("../types");
7
7
  class CreditManagerData {
8
8
  address;
9
+ type;
9
10
  underlyingToken;
10
11
  pool;
11
12
  creditFacade; // V2 only: address of creditFacade
@@ -37,6 +38,8 @@ class CreditManagerData {
37
38
  constructor(payload) {
38
39
  this.address = payload.addr.toLowerCase();
39
40
  this.underlyingToken = payload.underlying.toLowerCase();
41
+ this.type = CreditManagerData.getCMType(payload.name || "");
42
+ this.name = payload.name;
40
43
  this.pool = payload.pool.toLowerCase();
41
44
  this.creditFacade = payload.creditFacade.toLowerCase();
42
45
  this.creditConfigurator = payload.creditConfigurator.toLowerCase();
@@ -46,7 +49,6 @@ class CreditManagerData {
46
49
  this.isPaused = payload.isPaused;
47
50
  this.forbiddenTokenMask = (0, sdk_gov_1.toBigInt)(payload.forbiddenTokenMask);
48
51
  this.maxEnabledTokensLength = payload.maxEnabledTokensLength;
49
- this.name = payload.name;
50
52
  this.baseBorrowRate = Number(((0, sdk_gov_1.toBigInt)(payload.baseBorrowRate) *
51
53
  ((0, sdk_gov_1.toBigInt)(payload.feeInterest) + sdk_gov_1.PERCENTAGE_FACTOR) *
52
54
  sdk_gov_1.PERCENTAGE_DECIMALS) /
@@ -80,7 +82,7 @@ class CreditManagerData {
80
82
  q.token.toLowerCase(),
81
83
  {
82
84
  token: q.token.toLowerCase(),
83
- rate: q.rate,
85
+ rate: Number((0, sdk_gov_1.toBigInt)(q.rate) * sdk_gov_1.PERCENTAGE_DECIMALS),
84
86
  quotaIncreaseFee: q.quotaIncreaseFee,
85
87
  totalQuoted: (0, sdk_gov_1.toBigInt)(q.totalQuoted),
86
88
  limit: (0, sdk_gov_1.toBigInt)(q.limit),
@@ -107,6 +109,18 @@ class CreditManagerData {
107
109
  })));
108
110
  }
109
111
  }
112
+ get id() {
113
+ return this.address;
114
+ }
115
+ static getCMType(name) {
116
+ const [identity = ""] = name.split(" ") || [];
117
+ const lc = identity.toLowerCase();
118
+ if (lc === "farm")
119
+ return "farm";
120
+ if (lc === "trade")
121
+ return "trade";
122
+ return "universal";
123
+ }
110
124
  isQuoted(token) {
111
125
  return !!this.quotas[token];
112
126
  }
@@ -182,9 +196,6 @@ class CreditManagerData {
182
196
  callData: types_1.IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData("withdrawAllAndUnwrap", [claim]),
183
197
  };
184
198
  }
185
- get id() {
186
- return this.address;
187
- }
188
199
  }
189
200
  exports.CreditManagerData = CreditManagerData;
190
201
  class ChartsCreditManagerData {
package/lib/core/gauge.js CHANGED
@@ -22,9 +22,9 @@ class GaugeData {
22
22
  {
23
23
  token: q.token.toLowerCase(),
24
24
  isActive: q.isActive,
25
- rate: q.rate,
26
- minRate: q.minRate,
27
- maxRate: q.maxRate,
25
+ rate: Number((0, sdk_gov_1.toBigInt)(q.rate) * sdk_gov_1.PERCENTAGE_DECIMALS),
26
+ minRate: Number((0, sdk_gov_1.toBigInt)(q.minRate) * sdk_gov_1.PERCENTAGE_DECIMALS),
27
+ maxRate: Number((0, sdk_gov_1.toBigInt)(q.maxRate) * sdk_gov_1.PERCENTAGE_DECIMALS),
28
28
  quotaIncreaseFee: q.quotaIncreaseFee,
29
29
  totalQuoted: (0, sdk_gov_1.toBigInt)(q.totalQuoted),
30
30
  limit: (0, sdk_gov_1.toBigInt)(q.limit),
package/lib/core/pool.js CHANGED
@@ -69,7 +69,7 @@ class PoolData {
69
69
  token,
70
70
  {
71
71
  token,
72
- rate: q.rate,
72
+ rate: Number((0, sdk_gov_1.toBigInt)(q.rate) * sdk_gov_1.PERCENTAGE_DECIMALS),
73
73
  quotaIncreaseFee: q.quotaIncreaseFee,
74
74
  totalQuoted: (0, sdk_gov_1.toBigInt)(q.totalQuoted),
75
75
  limit: (0, sdk_gov_1.toBigInt)(q.limit),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.25",
3
+ "version": "3.0.0-next.26",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -43,9 +43,9 @@
43
43
  "@gearbox-protocol/core-v2": "1.19.0-base.17",
44
44
  "@gearbox-protocol/core-v3": "^1.41.0",
45
45
  "@gearbox-protocol/eslint-config": "^1.4.1",
46
- "@gearbox-protocol/integrations-v3": "^1.18.0",
46
+ "@gearbox-protocol/integrations-v3": "^1.18.4",
47
47
  "@gearbox-protocol/oracles-v3": "^1.7.6",
48
- "@gearbox-protocol/periphery-v3": "^1.3.0",
48
+ "@gearbox-protocol/periphery-v3": "^1.3.1",
49
49
  "@gearbox-protocol/prettier-config": "^1.4.1",
50
50
  "@openzeppelin/contracts": "^4.9.3",
51
51
  "@typechain/ethers-v5": "^10.1.0",