@gearbox-protocol/sdk 1.20.10 → 1.20.11

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.
@@ -121,10 +121,7 @@ function sortBalances(balances, prices, tokens) {
121
121
  ? tokensAbcComparator(token1, token2)
122
122
  : amountAbcComparator(amount1, amount2);
123
123
  }
124
- if (totalPrice1.gt(totalPrice2)) {
125
- return -1;
126
- }
127
- return 1;
124
+ return amountAbcComparator(totalPrice1, totalPrice2);
128
125
  });
129
126
  }
130
127
  exports.sortBalances = sortBalances;
@@ -135,7 +132,7 @@ function tokensAbcComparator(t1, t2) {
135
132
  }
136
133
  exports.tokensAbcComparator = tokensAbcComparator;
137
134
  function amountAbcComparator(t1, t2) {
138
- return (t1 === null || t1 === void 0 ? void 0 : t1.gt(t2)) ? -1 : 1;
135
+ return t1.gt(t2) ? -1 : 1;
139
136
  }
140
137
  exports.amountAbcComparator = amountAbcComparator;
141
138
  function calcOverallAPY(_a) {
@@ -1,9 +1,13 @@
1
- import { BigNumber } from "ethers";
1
+ import { BigNumber, BigNumberish } from "ethers";
2
2
  import { CreditSessionFilteredPayload, CreditSessionPayload } from "../payload/creditSession";
3
3
  import { AssetWithView } from "./assets";
4
4
  export declare type CreditSessionStatus = "active" | "closed" | "repaid" | "liquidated" | "liquidateExpired" | "liquidatePaused";
5
5
  export declare const CREDIT_SESSION_STATUS_BY_ID: Record<number, CreditSessionStatus>;
6
6
  export declare const CREDIT_SESSION_ID_BY_STATUS: Record<CreditSessionStatus, number>;
7
+ export interface CreditSessionBalance {
8
+ balance: BigNumber;
9
+ token: string;
10
+ }
7
11
  export declare class CreditSession {
8
12
  readonly id: string;
9
13
  readonly status: CreditSessionStatus;
@@ -26,11 +30,18 @@ export declare class CreditSession {
26
30
  readonly apy: number;
27
31
  readonly currentBlock: number;
28
32
  readonly currentTimestamp: number;
33
+ readonly borrowAPY_RAY: BigNumberish;
34
+ readonly borrowAPY7D: number;
35
+ readonly totalValueUSD: number;
36
+ readonly debt: BigNumberish;
37
+ readonly debtUSD: number;
38
+ readonly leverage: number;
39
+ readonly tfIndex: number;
29
40
  readonly spotDebt: BigNumber;
30
41
  readonly spotTotalValue: BigNumber;
31
42
  readonly spotUserFunds: BigNumber;
32
- readonly cvxUnclaimedRewards: Record<string, BigNumber>;
33
- readonly balances: Record<string, BigNumber>;
43
+ readonly cvxUnclaimedRewards: Record<string, CreditSessionBalance>;
44
+ readonly balances: Record<string, CreditSessionBalance>;
34
45
  constructor(payload: CreditSessionPayload);
35
46
  }
36
47
  export declare class CreditSessionFiltered {
@@ -47,6 +47,13 @@ var CreditSession = /** @class */ (function () {
47
47
  this.profitInUnderlying = payload.profitInUnderlying || 0;
48
48
  this.collateralInUSD = payload.collateralInUSD || 0;
49
49
  this.collateralInUnderlying = payload.collateralInUnderlying || 0;
50
+ this.borrowAPY_RAY = ethers_1.BigNumber.from(payload.borrowAPY_RAY || 0);
51
+ this.borrowAPY7D = (payload.borrowAPY7D || 0) * constants_1.PERCENTAGE_DECIMALS;
52
+ this.totalValueUSD = payload.totalValueUSD || 0;
53
+ this.debt = ethers_1.BigNumber.from(payload.debt || 0);
54
+ this.debtUSD = payload.debtUSD || 0;
55
+ this.leverage = payload.leverage || 0;
56
+ this.tfIndex = (payload.tfIndex || 0) * constants_1.PERCENTAGE_DECIMALS;
50
57
  this.roi = (payload.roi || 0) / constants_1.PERCENTAGE_DECIMALS;
51
58
  this.apy = (payload.apy || 0) / constants_1.PERCENTAGE_DECIMALS;
52
59
  this.currentBlock = payload.currentBlock || 0;
@@ -54,15 +61,23 @@ var CreditSession = /** @class */ (function () {
54
61
  this.spotDebt = ethers_1.BigNumber.from(payload.spotDebt || 0);
55
62
  this.spotTotalValue = ethers_1.BigNumber.from(payload.spotTotalValue || 0);
56
63
  this.spotUserFunds = ethers_1.BigNumber.from(payload.spotUserFunds || 0);
57
- this.cvxUnclaimedRewards = Object.entries(payload.cvxUnclaimedRewards).reduce(function (acc, _a) {
64
+ this.cvxUnclaimedRewards = Object.entries(payload.cvxUnclaimedRewards || {}).reduce(function (acc, _a) {
58
65
  var _b;
59
66
  var token = _a[0], balance = _a[1];
60
- return (__assign(__assign({}, acc), (_b = {}, _b[token.toLowerCase()] = ethers_1.BigNumber.from(balance.bi), _b)));
67
+ var tokenLC = token.toLowerCase();
68
+ return __assign(__assign({}, acc), (_b = {}, _b[tokenLC] = {
69
+ balance: ethers_1.BigNumber.from(balance.bi),
70
+ token: tokenLC,
71
+ }, _b));
61
72
  }, {});
62
- this.balances = Object.entries(payload.balances).reduce(function (acc, _a) {
73
+ this.balances = Object.entries(payload.balances || {}).reduce(function (acc, _a) {
63
74
  var _b;
64
75
  var token = _a[0], balance = _a[1];
65
- return (__assign(__assign({}, acc), (_b = {}, _b[token.toLowerCase()] = ethers_1.BigNumber.from(balance.BI), _b)));
76
+ var tokenLC = token.toLowerCase();
77
+ return __assign(__assign({}, acc), (_b = {}, _b[tokenLC] = {
78
+ balance: ethers_1.BigNumber.from(balance.BI),
79
+ token: tokenLC,
80
+ }, _b));
66
81
  }, {});
67
82
  }
68
83
  return CreditSession;
@@ -89,7 +104,7 @@ var CreditSessionFiltered = /** @class */ (function () {
89
104
  this.profitInUSD = payload.pnlUSD || 0;
90
105
  this.profitInUnderlying = payload.pnl || 0;
91
106
  this.tfIndex = (payload.tfIndex || 0) * constants_1.PERCENTAGE_DECIMALS;
92
- this.balances = Object.entries(payload.balances).map(function (_a) {
107
+ this.balances = Object.entries(payload.balances || {}).map(function (_a) {
93
108
  var token = _a[0], balance = _a[1];
94
109
  return ({
95
110
  token: token.toLowerCase(),
@@ -1,5 +1,5 @@
1
1
  import { BigNumberish } from "ethers";
2
- export interface CreditSessionBalance {
2
+ export interface CreditSessionBalancePayload {
3
3
  BI: string;
4
4
  F: number;
5
5
  ind: number;
@@ -18,30 +18,37 @@ export interface CreditSessionPayload {
18
18
  borrower: string;
19
19
  account: string;
20
20
  creditManager: string;
21
+ borrowAPY_RAY: BigNumberish;
22
+ borrowAPY7D: number;
21
23
  healthFactor: BigNumberish;
24
+ leverage: number;
25
+ tfIndex: number;
22
26
  initialAmount: BigNumberish;
27
+ collateralInUSD: number;
28
+ collateralInUnderlying: number;
29
+ spotUserFunds: BigNumberish;
30
+ debt: BigNumberish;
31
+ debtUSD: number;
23
32
  borrowedAmount: BigNumberish;
33
+ spotDebt: BigNumberish;
24
34
  totalValue: BigNumberish;
35
+ totalValueUSD: number;
36
+ spotTotalValue: BigNumberish;
25
37
  since: number;
26
38
  sinceTimestamp: number;
27
39
  closedAt: number;
28
40
  closedAtTimestamp: number;
29
- collateralInUSD: number;
30
- collateralInUnderlying: number;
31
- spotDebt: BigNumberish;
32
- spotTotalValue: BigNumberish;
33
- spotUserFunds: BigNumberish;
34
41
  profitInUSD: number;
35
42
  profitInUnderlying: number;
36
43
  apy: number;
37
44
  roi: number;
38
45
  currentBlock: number;
39
46
  currentTimestamp: number;
40
- cvxUnclaimedRewards: Array<CreditSessionReward>;
41
- balances: Record<string, CreditSessionBalance>;
47
+ cvxUnclaimedRewards: Record<string, CreditSessionReward>;
48
+ balances: Record<string, CreditSessionBalancePayload>;
42
49
  }
43
50
  export interface CreditSessionFilteredPayload {
44
- balances: Record<string, CreditSessionBalance>;
51
+ balances: Record<string, CreditSessionBalancePayload>;
45
52
  id: string;
46
53
  borrower: string;
47
54
  account: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.20.10",
3
+ "version": "1.20.11",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",