@gearbox-protocol/sdk 1.20.8 → 1.20.10

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.
@@ -4,6 +4,12 @@ export interface Asset {
4
4
  token: string;
5
5
  balance: BigNumber;
6
6
  }
7
+ export interface AssetWithView extends Asset {
8
+ balanceView: string;
9
+ }
10
+ export interface AssetWithAmountInTarget extends Asset {
11
+ amountInTarget: BigNumber;
12
+ }
7
13
  interface NextAssetProps<T extends Asset> {
8
14
  allowedTokens: Array<string>;
9
15
  selectedAssets: Array<T>;
@@ -11,19 +17,21 @@ interface NextAssetProps<T extends Asset> {
11
17
  tokensList: Record<string, TokenData>;
12
18
  prices?: Record<string, BigNumber>;
13
19
  }
14
- export declare function nextAsset<T extends Asset>({ allowedTokens, selectedAssets, balances, tokensList, prices, }: NextAssetProps<T>): string | undefined;
15
- export declare function getBalances(allowedTokens: Array<string>, externalBalances: Record<string, BigNumber>): Record<string, BigNumber>;
16
- export declare function constructAssetRecord<A extends Asset>(a: Array<A>): Record<string, A>;
17
20
  export declare type WrapResult<T> = [Array<T>, BigNumber, BigNumber];
18
- export declare const memoWrapETH: (ethAddress: string, wethAddress: string) => <T extends Asset>(assets: T[]) => WrapResult<T>;
19
- /**
20
- * Sums the the second assets list into the first assets list
21
- * Creates new assets.
22
- */
23
- export declare function sumAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A | B>;
24
- /**
25
- * Subtracts the the second assets list from the first assets list
26
- * Balance cant be negative; doesn't create new assets.
27
- */
28
- export declare function subAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A>;
21
+ export declare class AssetUtils {
22
+ static nextAsset<T extends Asset>({ allowedTokens, selectedAssets, balances, tokensList, prices, }: NextAssetProps<T>): string | undefined;
23
+ static getBalances(allowedTokens: Array<string>, externalBalances: Record<string, BigNumber>): Record<string, BigNumber>;
24
+ static constructAssetRecord<A extends Asset>(a: Array<A>): Record<string, A>;
25
+ static memoWrapETH: (ethAddress: string, wethAddress: string) => <T extends Asset>(assets: T[]) => WrapResult<T>;
26
+ /**
27
+ * Sums the the second assets list into the first assets list
28
+ * Creates new assets.
29
+ */
30
+ static sumAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A | B>;
31
+ /**
32
+ * Subtracts the the second assets list from the first assets list
33
+ * Balance cant be negative; doesn't create new assets.
34
+ */
35
+ static subAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A>;
36
+ }
29
37
  export {};
@@ -11,88 +11,88 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.subAssets = exports.sumAssets = exports.memoWrapETH = exports.constructAssetRecord = exports.getBalances = exports.nextAsset = void 0;
14
+ exports.AssetUtils = void 0;
15
15
  var ethers_1 = require("ethers");
16
16
  var math_1 = require("../utils/math");
17
17
  var creditAccount_1 = require("./creditAccount");
18
- function nextAsset(_a) {
19
- var allowedTokens = _a.allowedTokens, selectedAssets = _a.selectedAssets, balances = _a.balances, tokensList = _a.tokensList, _b = _a.prices, prices = _b === void 0 ? {} : _b;
20
- var selectedRecord = selectedAssets.reduce(function (acc, _a) {
21
- var token = _a.token;
22
- acc[token.toLowerCase()] = true;
23
- return acc;
24
- }, {});
25
- var notSelected = allowedTokens.filter(function (allowedToken) {
26
- var alreadySelected = selectedRecord[allowedToken.toLowerCase()];
27
- return !alreadySelected;
28
- });
29
- var sorted = (0, creditAccount_1.sortBalances)(getBalances(notSelected, balances), prices, tokensList);
30
- var address = (sorted[0] || [])[0];
31
- return address;
32
- }
33
- exports.nextAsset = nextAsset;
34
- function getBalances(allowedTokens, externalBalances) {
35
- return allowedTokens.reduce(function (acc, address) {
36
- var _a;
37
- var addressLc = address.toLowerCase();
38
- return __assign(__assign({}, acc), (_a = {}, _a[addressLc] = externalBalances[addressLc] || ethers_1.BigNumber.from(0), _a));
39
- }, {});
40
- }
41
- exports.getBalances = getBalances;
42
- function constructAssetRecord(a) {
43
- var record = a.reduce(function (acc, asset) {
44
- acc[asset.token] = asset;
45
- return acc;
46
- }, {});
47
- return record;
48
- }
49
- exports.constructAssetRecord = constructAssetRecord;
50
- var memoWrapETH = function (ethAddress, wethAddress) {
51
- return function wrapETH(assets) {
52
- var assetsRecord = constructAssetRecord(assets);
53
- var weth = assetsRecord[wethAddress];
54
- var _a = (weth || {}).balance, wethAmount = _a === void 0 ? ethers_1.BigNumber.from(0) : _a;
55
- var eth = assetsRecord[ethAddress];
56
- var _b = (eth || {}).balance, ethAmount = _b === void 0 ? ethers_1.BigNumber.from(0) : _b;
57
- var wethOrETH = weth || eth;
58
- if (wethOrETH) {
59
- assetsRecord[wethAddress] = __assign(__assign({}, wethOrETH), { token: wethAddress, balance: (0, math_1.nonNegativeBn)(ethAmount).add((0, math_1.nonNegativeBn)(wethAmount)) });
60
- }
61
- if (eth) {
62
- delete assetsRecord[ethAddress];
63
- }
64
- return [Object.values(assetsRecord), ethAmount, wethAmount];
18
+ var AssetUtils = /** @class */ (function () {
19
+ function AssetUtils() {
20
+ }
21
+ AssetUtils.nextAsset = function (_a) {
22
+ var allowedTokens = _a.allowedTokens, selectedAssets = _a.selectedAssets, balances = _a.balances, tokensList = _a.tokensList, _b = _a.prices, prices = _b === void 0 ? {} : _b;
23
+ var selectedRecord = selectedAssets.reduce(function (acc, _a) {
24
+ var token = _a.token;
25
+ acc[token.toLowerCase()] = true;
26
+ return acc;
27
+ }, {});
28
+ var notSelected = allowedTokens.filter(function (allowedToken) {
29
+ var alreadySelected = selectedRecord[allowedToken.toLowerCase()];
30
+ return !alreadySelected;
31
+ });
32
+ var sorted = (0, creditAccount_1.sortBalances)(AssetUtils.getBalances(notSelected, balances), prices, tokensList);
33
+ var address = (sorted[0] || [])[0];
34
+ return address;
65
35
  };
66
- };
67
- exports.memoWrapETH = memoWrapETH;
68
- /**
69
- * Sums the the second assets list into the first assets list
70
- * Creates new assets.
71
- */
72
- function sumAssets(a, b) {
73
- var aRecord = constructAssetRecord(a);
74
- var resRecord = b.reduce(function (acc, bAsset) {
75
- var aAsset = acc[bAsset.token];
76
- var _a = (aAsset || {}).balance, amount = _a === void 0 ? ethers_1.BigNumber.from(0) : _a;
77
- var amountSum = (0, math_1.nonNegativeBn)(bAsset.balance).add((0, math_1.nonNegativeBn)(amount));
78
- var aOrB = aAsset || bAsset;
79
- acc[bAsset.token] = __assign(__assign({}, aOrB), { balance: amountSum });
80
- return acc;
81
- }, aRecord);
82
- return Object.values(resRecord);
83
- }
84
- exports.sumAssets = sumAssets;
85
- /**
86
- * Subtracts the the second assets list from the first assets list
87
- * Balance cant be negative; doesn't create new assets.
88
- */
89
- function subAssets(a, b) {
90
- var bRecord = constructAssetRecord(b);
91
- return a.map(function (asset) {
92
- var bAsset = bRecord[asset.token];
93
- var _a = (bAsset || {}).balance, bAmount = _a === void 0 ? ethers_1.BigNumber.from(0) : _a;
94
- var amountSub = (0, math_1.nonNegativeBn)(asset.balance).sub((0, math_1.nonNegativeBn)(bAmount));
95
- return __assign(__assign({}, asset), { balance: (0, math_1.nonNegativeBn)(amountSub) });
96
- });
97
- }
98
- exports.subAssets = subAssets;
36
+ AssetUtils.getBalances = function (allowedTokens, externalBalances) {
37
+ return allowedTokens.reduce(function (acc, address) {
38
+ var _a;
39
+ var addressLc = address.toLowerCase();
40
+ return __assign(__assign({}, acc), (_a = {}, _a[addressLc] = externalBalances[addressLc] || ethers_1.BigNumber.from(0), _a));
41
+ }, {});
42
+ };
43
+ AssetUtils.constructAssetRecord = function (a) {
44
+ var record = a.reduce(function (acc, asset) {
45
+ acc[asset.token] = asset;
46
+ return acc;
47
+ }, {});
48
+ return record;
49
+ };
50
+ /**
51
+ * Sums the the second assets list into the first assets list
52
+ * Creates new assets.
53
+ */
54
+ AssetUtils.sumAssets = function (a, b) {
55
+ var aRecord = AssetUtils.constructAssetRecord(a);
56
+ var resRecord = b.reduce(function (acc, bAsset) {
57
+ var aAsset = acc[bAsset.token];
58
+ var _a = (aAsset || {}).balance, amount = _a === void 0 ? ethers_1.BigNumber.from(0) : _a;
59
+ var amountSum = (0, math_1.nonNegativeBn)(bAsset.balance).add((0, math_1.nonNegativeBn)(amount));
60
+ var aOrB = aAsset || bAsset;
61
+ acc[bAsset.token] = __assign(__assign({}, aOrB), { balance: amountSum });
62
+ return acc;
63
+ }, aRecord);
64
+ return Object.values(resRecord);
65
+ };
66
+ /**
67
+ * Subtracts the the second assets list from the first assets list
68
+ * Balance cant be negative; doesn't create new assets.
69
+ */
70
+ AssetUtils.subAssets = function (a, b) {
71
+ var bRecord = AssetUtils.constructAssetRecord(b);
72
+ return a.map(function (asset) {
73
+ var bAsset = bRecord[asset.token];
74
+ var _a = (bAsset || {}).balance, bAmount = _a === void 0 ? ethers_1.BigNumber.from(0) : _a;
75
+ var amountSub = (0, math_1.nonNegativeBn)(asset.balance).sub((0, math_1.nonNegativeBn)(bAmount));
76
+ return __assign(__assign({}, asset), { balance: (0, math_1.nonNegativeBn)(amountSub) });
77
+ });
78
+ };
79
+ AssetUtils.memoWrapETH = function (ethAddress, wethAddress) {
80
+ return function wrapETH(assets) {
81
+ var assetsRecord = AssetUtils.constructAssetRecord(assets);
82
+ var weth = assetsRecord[wethAddress];
83
+ var _a = (weth || {}).balance, wethAmount = _a === void 0 ? ethers_1.BigNumber.from(0) : _a;
84
+ var eth = assetsRecord[ethAddress];
85
+ var _b = (eth || {}).balance, ethAmount = _b === void 0 ? ethers_1.BigNumber.from(0) : _b;
86
+ var wethOrETH = weth || eth;
87
+ if (wethOrETH) {
88
+ assetsRecord[wethAddress] = __assign(__assign({}, wethOrETH), { token: wethAddress, balance: (0, math_1.nonNegativeBn)(ethAmount).add((0, math_1.nonNegativeBn)(wethAmount)) });
89
+ }
90
+ if (eth) {
91
+ delete assetsRecord[ethAddress];
92
+ }
93
+ return [Object.values(assetsRecord), ethAmount, wethAmount];
94
+ };
95
+ };
96
+ return AssetUtils;
97
+ }());
98
+ exports.AssetUtils = AssetUtils;
@@ -61,7 +61,7 @@ describe("CreditManager calcHealthFactor test", function () {
61
61
  balance: (0, formatter_1.toBN)("10", decimals_1.decimals.WETH),
62
62
  token: token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
63
63
  };
64
- var afterAdd = (0, assets_1.sumAssets)(defaultCA.assets, [collateral]);
64
+ var afterAdd = assets_1.AssetUtils.sumAssets(defaultCA.assets, [collateral]);
65
65
  var result = (0, creditManager_1.calcHealthFactor)({
66
66
  assets: afterAdd,
67
67
  prices: prices,
@@ -77,7 +77,9 @@ describe("CreditManager calcHealthFactor test", function () {
77
77
  balance: amountDecrease,
78
78
  token: defaultCA.underlyingToken,
79
79
  };
80
- var afterDecrease = (0, assets_1.subAssets)(defaultCA.assets, [debtDecrease]);
80
+ var afterDecrease = assets_1.AssetUtils.subAssets(defaultCA.assets, [
81
+ debtDecrease,
82
+ ]);
81
83
  var result = (0, creditManager_1.calcHealthFactor)({
82
84
  assets: afterDecrease,
83
85
  prices: prices,
@@ -93,7 +95,9 @@ describe("CreditManager calcHealthFactor test", function () {
93
95
  balance: amountIncrease,
94
96
  token: defaultCA.underlyingToken,
95
97
  };
96
- var afterIncrease = (0, assets_1.sumAssets)(defaultCA.assets, [debtIncrease]);
98
+ var afterIncrease = assets_1.AssetUtils.sumAssets(defaultCA.assets, [
99
+ debtIncrease,
100
+ ]);
97
101
  var result = (0, creditManager_1.calcHealthFactor)({
98
102
  assets: afterIncrease,
99
103
  prices: prices,
@@ -115,8 +119,8 @@ describe("CreditManager calcHealthFactor test", function () {
115
119
  balance: getAmount,
116
120
  token: token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
117
121
  };
118
- var afterSub = (0, assets_1.subAssets)(defaultCA.assets, [swapAsset]);
119
- var afterSwap = (0, assets_1.sumAssets)(afterSub, [getAsset]);
122
+ var afterSub = assets_1.AssetUtils.subAssets(defaultCA.assets, [swapAsset]);
123
+ var afterSwap = assets_1.AssetUtils.sumAssets(afterSub, [getAsset]);
120
124
  var result = (0, creditManager_1.calcHealthFactor)({
121
125
  assets: afterSwap,
122
126
  prices: prices,
@@ -1,12 +1,12 @@
1
1
  import { BigNumber } from "ethers";
2
- import { CreditSessionPayload } from "../payload/creditSession";
3
- import { CreditOperation } from "./creditOperation";
4
- export declare type CreditSessionStatus = "active" | "closed" | "repaid" | "liquidated";
2
+ import { CreditSessionFilteredPayload, CreditSessionPayload } from "../payload/creditSession";
3
+ import { AssetWithView } from "./assets";
4
+ export declare type CreditSessionStatus = "active" | "closed" | "repaid" | "liquidated" | "liquidateExpired" | "liquidatePaused";
5
+ export declare const CREDIT_SESSION_STATUS_BY_ID: Record<number, CreditSessionStatus>;
6
+ export declare const CREDIT_SESSION_ID_BY_STATUS: Record<CreditSessionStatus, number>;
5
7
  export declare class CreditSession {
6
8
  readonly id: string;
7
9
  readonly status: CreditSessionStatus;
8
- readonly name: string;
9
- readonly background: string;
10
10
  readonly borrower: string;
11
11
  readonly creditManager: string;
12
12
  readonly account: string;
@@ -18,9 +18,43 @@ export declare class CreditSession {
18
18
  readonly borrowedAmount: BigNumber;
19
19
  readonly totalValue: BigNumber;
20
20
  readonly healthFactor: number;
21
- readonly profit: BigNumber;
22
- readonly profitPercentage: number;
23
- readonly score: number;
24
- readonly operations: Array<CreditOperation>;
21
+ readonly profitInUSD: number;
22
+ readonly profitInUnderlying: number;
23
+ readonly collateralInUSD: number;
24
+ readonly collateralInUnderlying: number;
25
+ readonly roi: number;
26
+ readonly apy: number;
27
+ readonly currentBlock: number;
28
+ readonly currentTimestamp: number;
29
+ readonly spotDebt: BigNumber;
30
+ readonly spotTotalValue: BigNumber;
31
+ readonly spotUserFunds: BigNumber;
32
+ readonly cvxUnclaimedRewards: Record<string, BigNumber>;
33
+ readonly balances: Record<string, BigNumber>;
25
34
  constructor(payload: CreditSessionPayload);
26
35
  }
36
+ export declare class CreditSessionFiltered {
37
+ readonly id: string;
38
+ readonly borrower: string;
39
+ readonly account: string;
40
+ readonly creditManager: string;
41
+ readonly underlyingToken: string;
42
+ readonly status: CreditSessionStatus;
43
+ readonly since: number;
44
+ readonly sinceDate: string;
45
+ readonly closedAt: number;
46
+ readonly closedAtDate: string;
47
+ readonly healthFactor: number;
48
+ readonly leverage: number;
49
+ readonly debt: BigNumber;
50
+ readonly debtUSD: number;
51
+ readonly totalValue: BigNumber;
52
+ readonly totalValueUSD: number;
53
+ readonly profitInUSD: number;
54
+ readonly profitInUnderlying: number;
55
+ readonly tfIndex: number;
56
+ readonly balances: Array<AssetWithView>;
57
+ constructor(payload: CreditSessionFilteredPayload);
58
+ }
59
+ export declare type CreditSessionSortFields = "type" | "tvl" | "hf" | "debt" | "pnl" | "leverage" | "tfIndex";
60
+ export declare type CreditSessionSortType = "asc" | "desc";
@@ -14,40 +14,90 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.CreditSession = void 0;
17
+ exports.CreditSessionFiltered = exports.CreditSession = exports.CREDIT_SESSION_ID_BY_STATUS = exports.CREDIT_SESSION_STATUS_BY_ID = void 0;
18
18
  var ethers_1 = require("ethers");
19
19
  var moment_1 = __importDefault(require("moment"));
20
- var statusEnum = [
21
- "active",
22
- "closed",
23
- "repaid",
24
- "liquidated",
25
- ];
20
+ var mappers_1 = require("../utils/mappers");
21
+ var constants_1 = require("./constants");
22
+ exports.CREDIT_SESSION_STATUS_BY_ID = {
23
+ 0: "active",
24
+ 1: "closed",
25
+ 2: "repaid",
26
+ 3: "liquidated",
27
+ 4: "liquidateExpired",
28
+ 5: "liquidatePaused",
29
+ };
30
+ exports.CREDIT_SESSION_ID_BY_STATUS = (0, mappers_1.swapKeyValue)(exports.CREDIT_SESSION_STATUS_BY_ID);
26
31
  var CreditSession = /** @class */ (function () {
27
32
  function CreditSession(payload) {
28
- this.id = payload.id;
29
- this.status = statusEnum[payload.status];
30
- this.name = payload.name;
31
- this.background = payload.background;
32
- this.borrower = payload.borrower;
33
- this.creditManager = payload.creditManager;
34
- this.account = payload.account;
35
- this.since = payload.since;
36
- this.closedAt = payload.closedAt;
33
+ this.id = (payload.id || "").toLowerCase();
34
+ this.status = exports.CREDIT_SESSION_STATUS_BY_ID[payload.status || 0];
35
+ this.borrower = (payload.borrower || "").toLowerCase();
36
+ this.creditManager = (payload.creditManager || "").toLowerCase();
37
+ this.account = (payload.account || "").toLowerCase();
37
38
  this.initialAmount = ethers_1.BigNumber.from(payload.initialAmount || 0);
38
39
  this.borrowedAmount = ethers_1.BigNumber.from(payload.borrowedAmount || 0);
39
- this.profit = ethers_1.BigNumber.from(payload.profit || 0);
40
- this.profitPercentage = payload.profitPercentage || 0;
41
40
  this.totalValue = ethers_1.BigNumber.from(payload.totalValue || 0);
42
41
  this.healthFactor = ethers_1.BigNumber.from(payload.healthFactor || 0).toNumber();
43
- this.score = payload.score;
44
- this.operations = (payload.operations || []).map(function (op) {
45
- var formattedOp = __assign(__assign({}, op), { date: (0, moment_1.default)(op.timestamp * 1000).format("Do MMM YYYY") });
46
- return formattedOp;
47
- });
48
- this.sinceDate = (0, moment_1.default)(payload.sinceTimestamp * 1000).format("Do MMM YYYY");
49
- this.closedAtDate = (0, moment_1.default)(payload.closedAtTimestamp * 1000).format("Do MMM YYYY");
42
+ this.since = payload.since || 0;
43
+ this.closedAt = payload.closedAt || 0;
44
+ this.sinceDate = (0, moment_1.default)((payload.sinceTimestamp || 0) * 1000).format("Do MMM YYYY");
45
+ this.closedAtDate = (0, moment_1.default)((payload.closedAtTimestamp || 0) * 1000).format("Do MMM YYYY");
46
+ this.profitInUSD = payload.profitInUSD || 0;
47
+ this.profitInUnderlying = payload.profitInUnderlying || 0;
48
+ this.collateralInUSD = payload.collateralInUSD || 0;
49
+ this.collateralInUnderlying = payload.collateralInUnderlying || 0;
50
+ this.roi = (payload.roi || 0) / constants_1.PERCENTAGE_DECIMALS;
51
+ this.apy = (payload.apy || 0) / constants_1.PERCENTAGE_DECIMALS;
52
+ this.currentBlock = payload.currentBlock || 0;
53
+ this.currentTimestamp = payload.currentTimestamp || 0;
54
+ this.spotDebt = ethers_1.BigNumber.from(payload.spotDebt || 0);
55
+ this.spotTotalValue = ethers_1.BigNumber.from(payload.spotTotalValue || 0);
56
+ this.spotUserFunds = ethers_1.BigNumber.from(payload.spotUserFunds || 0);
57
+ this.cvxUnclaimedRewards = Object.entries(payload.cvxUnclaimedRewards).reduce(function (acc, _a) {
58
+ var _b;
59
+ var token = _a[0], balance = _a[1];
60
+ return (__assign(__assign({}, acc), (_b = {}, _b[token.toLowerCase()] = ethers_1.BigNumber.from(balance.bi), _b)));
61
+ }, {});
62
+ this.balances = Object.entries(payload.balances).reduce(function (acc, _a) {
63
+ var _b;
64
+ var token = _a[0], balance = _a[1];
65
+ return (__assign(__assign({}, acc), (_b = {}, _b[token.toLowerCase()] = ethers_1.BigNumber.from(balance.BI), _b)));
66
+ }, {});
50
67
  }
51
68
  return CreditSession;
52
69
  }());
53
70
  exports.CreditSession = CreditSession;
71
+ var CreditSessionFiltered = /** @class */ (function () {
72
+ function CreditSessionFiltered(payload) {
73
+ this.id = (payload.id || "").toLowerCase();
74
+ this.borrower = (payload.borrower || "").toLowerCase();
75
+ this.account = (payload.account || "").toLowerCase();
76
+ this.creditManager = (payload.creditManager || "").toLowerCase();
77
+ this.underlyingToken = (payload.underlyingToken || "").toLowerCase();
78
+ this.status = exports.CREDIT_SESSION_STATUS_BY_ID[payload.status || 0];
79
+ this.since = payload.since || 0;
80
+ this.closedAt = payload.closedAt || 0;
81
+ this.sinceDate = (0, moment_1.default)((payload.since || 0) * 1000).format("Do MMM YYYY");
82
+ this.closedAtDate = (0, moment_1.default)((payload.closedAt || 0) * 1000).format("Do MMM YYYY");
83
+ this.healthFactor = ethers_1.BigNumber.from(payload.healthFactor || 0).toNumber();
84
+ this.leverage = payload.leverage || 0;
85
+ this.debt = ethers_1.BigNumber.from(payload.debt || 0);
86
+ this.debtUSD = payload.debtUSD || 0;
87
+ this.totalValue = ethers_1.BigNumber.from(payload.totalValue || 0);
88
+ this.totalValueUSD = payload.totalValueUSD || 0;
89
+ this.profitInUSD = payload.pnlUSD || 0;
90
+ this.profitInUnderlying = payload.pnl || 0;
91
+ this.tfIndex = (payload.tfIndex || 0) * constants_1.PERCENTAGE_DECIMALS;
92
+ this.balances = Object.entries(payload.balances).map(function (_a) {
93
+ var token = _a[0], balance = _a[1];
94
+ return ({
95
+ token: token.toLowerCase(),
96
+ balance: ethers_1.BigNumber.from(balance.BI),
97
+ balanceView: balance.F.toString(),
98
+ });
99
+ });
100
+ }
101
+ return CreditSessionFiltered;
102
+ }());
103
+ exports.CreditSessionFiltered = CreditSessionFiltered;
@@ -30,17 +30,57 @@ interface calculateBorrowRateProps {
30
30
  expectedLiquidity: BigNumber;
31
31
  availableLiquidity: BigNumber;
32
32
  }
33
- export declare class ChartsPoolData extends PoolData {
34
- readonly expectedLiquidityInUSD: number;
35
- readonly expectedLiquidityLimitInUSD: number;
33
+ export declare class ChartsPoolData {
34
+ readonly id: string;
35
+ readonly address: string;
36
+ readonly underlyingToken: string;
37
+ readonly dieselToken: string;
38
+ readonly isWETH: boolean;
39
+ readonly addLiqCount: number;
40
+ readonly addedLiquidity: number;
41
+ readonly removeLiqCount: number;
42
+ readonly removedLiquidity: number;
43
+ readonly earned7D: number;
44
+ readonly earned7DInUSD: number;
45
+ readonly utilization: number;
46
+ readonly dieselRate: number;
47
+ readonly dieselRateRay: BigNumber;
48
+ readonly depositAPY: number;
49
+ readonly depositAPYRay: BigNumber;
50
+ readonly borrowAPY: number;
51
+ readonly borrowAPYRay: BigNumber;
52
+ readonly lmAPY: number;
53
+ readonly availableLiquidity: BigNumber;
54
+ readonly availableLiquidityChange: number;
36
55
  readonly availableLiquidityInUSD: number;
56
+ readonly caLockedValue: number;
57
+ readonly caLockedValueChange: number;
37
58
  readonly caLockedValueInUSD: number;
59
+ readonly expectedLiquidity: BigNumber;
60
+ readonly expectedLiquidityChange: number;
61
+ readonly expectedLiquidityInUSD: number;
62
+ readonly expectedLiqWeekAgo: number;
63
+ readonly expectedLiquidityLimit: BigNumber;
64
+ readonly expectedLiquidityLimitInUSD: number;
65
+ readonly totalBorrowed: BigNumber;
66
+ readonly totalBorrowedChange: number;
38
67
  readonly totalBorrowedInUSD: number;
39
- readonly uniqueLPs: number;
68
+ readonly debtWithInterest: BigNumber;
69
+ readonly debtWithInterestChange: number;
70
+ readonly debtWithInterestInUSD: number;
71
+ readonly debtWithInterestOld: BigNumber;
72
+ readonly oldAvailableLiquidity: BigNumber;
73
+ readonly oldCALockedValue: number;
74
+ readonly oldExpectedLiquidity: BigNumber;
75
+ readonly oldTotalBorrowed: BigNumber;
76
+ readonly withdrawFee: number;
77
+ readonly depositAPY1D: number;
78
+ readonly depositAPY1DChange: number;
40
79
  readonly depositAPY7D: number;
41
80
  readonly depositAPY30D: number;
42
- readonly lmAPY: number;
43
- readonly utilization: number;
44
- constructor({ expectedLiquidityInUSD, expectedLiquidityLimitInUSD, availableLiquidityInUSD, totalBorrowedInUSD, caLockedValueInUSD, uniqueLPs, dieselAPY7D, dieselAPY30D, lmAPY, ...restPayload }: ChartsPoolDataPayload);
81
+ readonly oldUniqueLPs: number;
82
+ readonly uniqueLPs: number;
83
+ readonly uniqueLPsChange: number;
84
+ constructor(payload: ChartsPoolDataPayload);
45
85
  }
46
86
  export {};
@@ -1,30 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -61,17 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
36
  }
63
37
  };
64
- var __rest = (this && this.__rest) || function (s, e) {
65
- var t = {};
66
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
- t[p] = s[p];
68
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
- t[p[i]] = s[p[i]];
72
- }
73
- return t;
74
- };
75
38
  Object.defineProperty(exports, "__esModule", { value: true });
76
39
  exports.ChartsPoolData = exports.PoolData = void 0;
77
40
  var ethers_1 = require("ethers");
@@ -116,29 +79,72 @@ var PoolData = /** @class */ (function () {
116
79
  return PoolData;
117
80
  }());
118
81
  exports.PoolData = PoolData;
119
- var ChartsPoolData = /** @class */ (function (_super) {
120
- __extends(ChartsPoolData, _super);
121
- function ChartsPoolData(_a) {
122
- var _this = this;
123
- var expectedLiquidityInUSD = _a.expectedLiquidityInUSD, expectedLiquidityLimitInUSD = _a.expectedLiquidityLimitInUSD, availableLiquidityInUSD = _a.availableLiquidityInUSD, totalBorrowedInUSD = _a.totalBorrowedInUSD, caLockedValueInUSD = _a.caLockedValueInUSD, uniqueLPs = _a.uniqueLPs, _b = _a.dieselAPY7D, dieselAPY7D = _b === void 0 ? 0 : _b, _c = _a.dieselAPY30D, dieselAPY30D = _c === void 0 ? 0 : _c, lmAPY = _a.lmAPY, restPayload = __rest(_a, ["expectedLiquidityInUSD", "expectedLiquidityLimitInUSD", "availableLiquidityInUSD", "totalBorrowedInUSD", "caLockedValueInUSD", "uniqueLPs", "dieselAPY7D", "dieselAPY30D", "lmAPY"]);
124
- var _d = restPayload.underlying, underlying = _d === void 0 ? restPayload.underlyingToken : _d, _e = restPayload.linearCumulativeIndex, linearCumulativeIndex = _e === void 0 ? 0 : _e, _f = restPayload.cumulativeIndex_RAY, cumulativeIndexRAY = _f === void 0 ? 0 : _f, _g = restPayload.timestampLU, timestampLU = _g === void 0 ? 0 : _g, _h = restPayload.version, version = _h === void 0 ? 1 : _h, v1Props = __rest(restPayload, ["underlying", "linearCumulativeIndex", "cumulativeIndex_RAY", "timestampLU", "version"]);
125
- _this = _super.call(this, __assign(__assign({}, v1Props), { underlying: underlying, linearCumulativeIndex: linearCumulativeIndex, cumulativeIndex_RAY: cumulativeIndexRAY, timestampLU: timestampLU, version: version })) || this;
126
- _this.expectedLiquidityInUSD = expectedLiquidityInUSD;
127
- _this.expectedLiquidityLimitInUSD = expectedLiquidityLimitInUSD;
128
- _this.availableLiquidityInUSD = availableLiquidityInUSD;
129
- _this.totalBorrowedInUSD = totalBorrowedInUSD;
130
- _this.uniqueLPs = uniqueLPs;
131
- _this.depositAPY7D = dieselAPY7D / constants_1.PERCENTAGE_DECIMALS;
132
- _this.depositAPY30D = dieselAPY30D / constants_1.PERCENTAGE_DECIMALS;
133
- _this.caLockedValueInUSD = caLockedValueInUSD;
134
- _this.lmAPY = lmAPY / constants_1.PERCENTAGE_FACTOR;
135
- _this.utilization =
136
- ethers_1.BigNumber.from(v1Props.totalBorrowed)
82
+ var ChartsPoolData = /** @class */ (function () {
83
+ function ChartsPoolData(payload) {
84
+ this.id = payload.addr.toLowerCase();
85
+ this.address = payload.addr.toLowerCase();
86
+ this.underlyingToken = payload.underlyingToken.toLowerCase();
87
+ this.dieselToken = payload.dieselToken.toLowerCase();
88
+ this.isWETH = payload.isWETH;
89
+ this.earned7D = payload.earned7D || 0;
90
+ this.earned7DInUSD = payload.earned7DInUSD || 0;
91
+ this.utilization =
92
+ ethers_1.BigNumber.from(payload.totalBorrowed || 0)
137
93
  .mul(constants_1.PERCENTAGE_FACTOR)
138
- .div(ethers_1.BigNumber.from(v1Props.expectedLiquidity))
94
+ .div(ethers_1.BigNumber.from(payload.expectedLiquidity || 0))
139
95
  .toNumber() / constants_1.PERCENTAGE_DECIMALS;
140
- return _this;
96
+ this.dieselRate = (0, formatter_1.rayToNumber)(payload.dieselRate_RAY || 0);
97
+ this.dieselRateRay = ethers_1.BigNumber.from(payload.dieselRate_RAY || 0);
98
+ this.depositAPY =
99
+ (0, formatter_1.rayToNumber)(payload.depositAPY_RAY || 0) * constants_1.PERCENTAGE_DECIMALS;
100
+ this.depositAPYRay = ethers_1.BigNumber.from(payload.depositAPY_RAY || 0);
101
+ this.borrowAPY =
102
+ (0, formatter_1.rayToNumber)(payload.borrowAPY_RAY || 0) * constants_1.PERCENTAGE_DECIMALS;
103
+ this.borrowAPYRay = ethers_1.BigNumber.from(payload.borrowAPY_RAY || 0);
104
+ this.lmAPY = (payload.lmAPY || 0) / constants_1.PERCENTAGE_FACTOR;
105
+ this.availableLiquidity = ethers_1.BigNumber.from(payload.availableLiquidity || 0);
106
+ this.oldAvailableLiquidity = ethers_1.BigNumber.from(payload.availableLiquidityOld || 0);
107
+ this.availableLiquidityChange =
108
+ (payload.availableLiquidity10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
109
+ this.availableLiquidityInUSD = payload.availableLiquidityInUSD || 0;
110
+ this.caLockedValue = payload.caLockedValue || 0;
111
+ this.oldCALockedValue = payload.caLockedValueOld || 0;
112
+ this.caLockedValueChange =
113
+ (payload.caLockedValue10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
114
+ this.caLockedValueInUSD = payload.caLockedValueUSD || 0;
115
+ this.expectedLiquidity = ethers_1.BigNumber.from(payload.expectedLiquidity || 0);
116
+ this.oldExpectedLiquidity = ethers_1.BigNumber.from(payload.expectedLiquidityOld || 0);
117
+ this.expectedLiquidityChange =
118
+ (payload.expectedLiquidity10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
119
+ this.expectedLiquidityInUSD = payload.expectedLiquidityInUSD || 0;
120
+ this.expectedLiqWeekAgo = payload.expectedLiqWeekAgo || 0;
121
+ this.expectedLiquidityLimit = ethers_1.BigNumber.from(payload.expectedLiquidityLimit || 0);
122
+ this.expectedLiquidityLimitInUSD = payload.expectedLiquidityLimitInUSD || 0;
123
+ this.totalBorrowed = ethers_1.BigNumber.from(payload.totalBorrowed || 0);
124
+ this.oldTotalBorrowed = ethers_1.BigNumber.from(payload.totalBorrowedOld || 0);
125
+ this.totalBorrowedChange =
126
+ (payload.totalBorrowed10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
127
+ this.totalBorrowedInUSD = payload.totalBorrowedInUSD || 0;
128
+ this.debtWithInterest = ethers_1.BigNumber.from(payload.debtWithInterest || 0);
129
+ this.debtWithInterestOld = ethers_1.BigNumber.from(payload.debtWithInterestOld || 0);
130
+ this.debtWithInterestChange =
131
+ (payload.debtWithInterest10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
132
+ this.debtWithInterestInUSD = payload.debtWithInterestInUSD || 0;
133
+ this.withdrawFee = payload.withdrawFee || 0;
134
+ this.addLiqCount = payload.addLiqCount || 0;
135
+ this.addedLiquidity = payload.addedLiquidity || 0;
136
+ this.removeLiqCount = payload.removeLiqCount || 0;
137
+ this.removedLiquidity = payload.removedLiquidity || 0;
138
+ this.depositAPY1D = (payload.dieselAPY1D || 0) / constants_1.PERCENTAGE_DECIMALS;
139
+ this.depositAPY1DChange =
140
+ (payload.dieselAPY1D10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
141
+ this.depositAPY7D = (payload.dieselAPY7D || 0) / constants_1.PERCENTAGE_DECIMALS;
142
+ this.depositAPY30D = (payload.dieselAPY30D || 0) / constants_1.PERCENTAGE_DECIMALS;
143
+ this.uniqueLPs = payload.uniqueLPs || 0;
144
+ this.oldUniqueLPs = payload.uniqueLPsOld || 0;
145
+ this.uniqueLPsChange =
146
+ (payload.uniqueLPs10kBasis || 0) * constants_1.PERCENTAGE_DECIMALS;
141
147
  }
142
148
  return ChartsPoolData;
143
- }(PoolData));
149
+ }());
144
150
  exports.ChartsPoolData = ChartsPoolData;
@@ -1,23 +1,77 @@
1
1
  import { BigNumberish } from "ethers";
2
- import { CreditOperation } from "../core/creditOperation";
2
+ export interface CreditSessionBalance {
3
+ BI: string;
4
+ F: number;
5
+ ind: number;
6
+ isAllowed: boolean;
7
+ isEnabled: boolean;
8
+ }
9
+ interface CreditSessionReward {
10
+ bi: BigNumberish;
11
+ f: number;
12
+ pool: string;
13
+ symbol: string;
14
+ }
3
15
  export interface CreditSessionPayload {
4
16
  id: string;
5
17
  status: number;
6
- name: string;
7
- background: string;
8
18
  borrower: string;
9
- creditManager: string;
10
19
  account: string;
20
+ creditManager: string;
21
+ healthFactor: BigNumberish;
22
+ initialAmount: BigNumberish;
23
+ borrowedAmount: BigNumberish;
24
+ totalValue: BigNumberish;
11
25
  since: number;
12
26
  sinceTimestamp: number;
13
27
  closedAt: number;
14
28
  closedAtTimestamp: number;
15
- initialAmount: BigNumberish;
16
- borrowedAmount: BigNumberish;
17
- totalValue?: BigNumberish;
18
- healthFactor?: BigNumberish;
19
- profit: BigNumberish;
20
- profitPercentage: number;
21
- score: number;
22
- operations: Array<CreditOperation>;
29
+ collateralInUSD: number;
30
+ collateralInUnderlying: number;
31
+ spotDebt: BigNumberish;
32
+ spotTotalValue: BigNumberish;
33
+ spotUserFunds: BigNumberish;
34
+ profitInUSD: number;
35
+ profitInUnderlying: number;
36
+ apy: number;
37
+ roi: number;
38
+ currentBlock: number;
39
+ currentTimestamp: number;
40
+ cvxUnclaimedRewards: Array<CreditSessionReward>;
41
+ balances: Record<string, CreditSessionBalance>;
42
+ }
43
+ export interface CreditSessionFilteredPayload {
44
+ balances: Record<string, CreditSessionBalance>;
45
+ id: string;
46
+ borrower: string;
47
+ account: string;
48
+ creditManager: string;
49
+ underlyingToken: string;
50
+ status: number;
51
+ closedAt: number;
52
+ since: number;
53
+ healthFactor: BigNumberish;
54
+ leverage: number;
55
+ debt: BigNumberish;
56
+ debtUSD: number;
57
+ totalValue: BigNumberish;
58
+ totalValueUSD: number;
59
+ pnl: number;
60
+ pnlUSD: number;
61
+ tfIndex: number;
62
+ }
63
+ export interface CreditSessionsAggregatedStatsPayload {
64
+ healthFactor: BigNumberish;
65
+ healthFactorOld: BigNumberish;
66
+ healthFactor10kBasis: number;
67
+ leverage: number;
68
+ leverageOld: number;
69
+ leverage10kBasis: number;
70
+ activeAccounts: number;
71
+ activeAccountsOld: number;
72
+ activeAccounts10kBasis: number;
73
+ openedAccounts: number;
74
+ openedAccountsOld: number;
75
+ openedAccounts10kBasis: number;
23
76
  }
77
+ export {};
@@ -4,43 +4,64 @@ import { ExcludeArrayProps } from "../utils/types";
4
4
  export declare type PoolDataPayload = ExcludeArrayProps<PoolDataStruct>;
5
5
  export interface ChartsPoolDataPayload {
6
6
  addr: string;
7
- underlyingToken: string;
8
7
  dieselToken: string;
8
+ underlyingToken: string;
9
9
  isWETH: boolean;
10
- expectedLiquidity: string;
11
- expectedLiquidityLimit: string;
12
- availableLiquidity: string;
13
- totalBorrowed: string;
14
- depositAPY_RAY: string;
15
- borrowAPY_RAY: string;
16
- dieselRate_RAY: string;
17
- withdrawFee: number;
10
+ borrowAPY_RAY: BigNumberish;
11
+ depositAPY_RAY: BigNumberish;
12
+ dieselRate_RAY: BigNumberish;
18
13
  lmAPY: number;
19
- underlying: string;
20
- linearCumulativeIndex: BigNumberish;
21
- cumulativeIndex_RAY: BigNumberish;
22
- timestampLU: BigNumberish;
23
- version: number;
14
+ earned7D: number;
15
+ earned7DInUSD: number;
16
+ availableLiquidity: BigNumberish;
17
+ availableLiquidityOld: BigNumberish;
18
+ availableLiquidity10kBasis: number;
19
+ availableLiquidityInUSD: number;
20
+ expectedLiqWeekAgo: number;
21
+ expectedLiquidity: BigNumberish;
22
+ expectedLiquidityOld: BigNumberish;
23
+ expectedLiquidity10kBasis: number;
24
24
  expectedLiquidityInUSD: number;
25
+ expectedLiquidityLimit: BigNumberish;
25
26
  expectedLiquidityLimitInUSD: number;
26
- availableLiquidityInUSD: number;
27
+ caLockedValue: number;
28
+ caLockedValueOld: number;
29
+ caLockedValue10kBasis: number;
30
+ caLockedValueUSD: number;
31
+ totalBorrowed: BigNumberish;
32
+ totalBorrowedOld: BigNumberish;
33
+ totalBorrowed10kBasis: number;
27
34
  totalBorrowedInUSD: number;
28
- uniqueLPs: number;
29
- dieselAPY7D?: number;
30
- dieselAPY30D?: number;
35
+ debtWithInterest: BigNumberish;
36
+ debtWithInterest10kBasis: number;
37
+ debtWithInterestInUSD: number;
38
+ debtWithInterestOld: BigNumberish;
39
+ withdrawFee: number;
31
40
  addLiqCount: number;
32
41
  addedLiquidity: number;
33
- caLockedValue: number;
34
- caLockedValueInUSD: number;
35
- earned7D: number;
36
- earned7DInUSD: number;
37
- expectedLiqWeekAgo: number;
38
42
  removeLiqCount: number;
39
43
  removedLiquidity: number;
44
+ dieselAPY1D: number;
45
+ dieselAPY1D10kBasis: number;
46
+ dieselAPY7D: number;
47
+ dieselAPY30D: number;
48
+ uniqueLPsOld: number;
49
+ uniqueLPs: number;
50
+ uniqueLPs10kBasis: number;
40
51
  }
41
52
  export interface ChartsAggregatedStats {
42
- uniqueLPs: number;
53
+ caLockedValue: number;
54
+ caLockedValue10kBasis: number;
55
+ expectedLiquidity: number;
56
+ expectedLiquidity10kBasis: number;
57
+ totalBorrowed: number;
58
+ totalBorrowed10kBasis: number;
59
+ totalValue: number;
60
+ totalValue10kBasis: number;
61
+ debtWithInterest: number;
62
+ debtWithInterest10kBasis: number;
43
63
  earned7D: number;
64
+ uniqueLPs: number;
44
65
  }
45
66
  export interface ChartsAggregatedPoolPayload extends ChartsAggregatedStats {
46
67
  pools: Array<ChartsPoolDataPayload>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.20.8",
3
+ "version": "1.20.10",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",