@gearbox-protocol/sdk 1.20.7 → 1.20.9
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.
- package/lib/core/assets.d.ts +22 -14
- package/lib/core/assets.js +81 -81
- package/lib/core/creditManager.spec.js +9 -5
- package/lib/core/creditSession.d.ts +43 -9
- package/lib/core/creditSession.js +75 -25
- package/lib/core/pool/data.d.ts +86 -0
- package/lib/core/{pool.js → pool/data.js} +69 -58
- package/lib/core/pool/index.d.ts +2 -0
- package/lib/core/pool/index.js +18 -0
- package/lib/core/pool/operation.d.ts +29 -0
- package/lib/core/pool/operation.js +48 -0
- package/lib/payload/creditSession.d.ts +66 -12
- package/lib/payload/pool.d.ts +45 -24
- package/package.json +1 -1
- package/lib/core/pool.d.ts +0 -45
package/lib/core/assets.d.ts
CHANGED
|
@@ -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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 {};
|
package/lib/core/assets.js
CHANGED
|
@@ -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.
|
|
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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
119
|
-
var afterSwap =
|
|
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 {
|
|
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
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
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 =
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
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.
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
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;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BigNumber, providers, Signer } from "ethers";
|
|
2
|
+
import { ChartsPoolDataPayload, PoolDataPayload } from "../../payload/pool";
|
|
3
|
+
import { IPoolService } from "../../types";
|
|
4
|
+
export declare class PoolData {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly address: string;
|
|
7
|
+
readonly underlyingToken: string;
|
|
8
|
+
readonly dieselToken: string;
|
|
9
|
+
readonly isWETH: boolean;
|
|
10
|
+
readonly expectedLiquidity: BigNumber;
|
|
11
|
+
readonly expectedLiquidityLimit: BigNumber;
|
|
12
|
+
readonly availableLiquidity: BigNumber;
|
|
13
|
+
readonly totalBorrowed: BigNumber;
|
|
14
|
+
readonly depositAPY: number;
|
|
15
|
+
readonly borrowAPY: number;
|
|
16
|
+
readonly borrowAPYRay: BigNumber;
|
|
17
|
+
readonly dieselRate: number;
|
|
18
|
+
readonly dieselRateRay: BigNumber;
|
|
19
|
+
readonly withdrawFee: number;
|
|
20
|
+
readonly timestampLU: BigNumber;
|
|
21
|
+
readonly cumulativeIndex_RAY: BigNumber;
|
|
22
|
+
readonly isPaused: boolean;
|
|
23
|
+
constructor(payload: PoolDataPayload);
|
|
24
|
+
getContractETH(signer: Signer): IPoolService;
|
|
25
|
+
static calculateBorrowRate({ modelAddress, provider, expectedLiquidity, availableLiquidity, }: calculateBorrowRateProps): Promise<BigNumber>;
|
|
26
|
+
}
|
|
27
|
+
interface calculateBorrowRateProps {
|
|
28
|
+
modelAddress: string;
|
|
29
|
+
provider: providers.Provider;
|
|
30
|
+
expectedLiquidity: BigNumber;
|
|
31
|
+
availableLiquidity: BigNumber;
|
|
32
|
+
}
|
|
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;
|
|
55
|
+
readonly availableLiquidityInUSD: number;
|
|
56
|
+
readonly caLockedValue: number;
|
|
57
|
+
readonly caLockedValueChange: number;
|
|
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;
|
|
67
|
+
readonly totalBorrowedInUSD: 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;
|
|
79
|
+
readonly depositAPY7D: number;
|
|
80
|
+
readonly depositAPY30D: number;
|
|
81
|
+
readonly oldUniqueLPs: number;
|
|
82
|
+
readonly uniqueLPs: number;
|
|
83
|
+
readonly uniqueLPsChange: number;
|
|
84
|
+
constructor(payload: ChartsPoolDataPayload);
|
|
85
|
+
}
|
|
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,23 +35,12 @@ 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");
|
|
78
|
-
var types_1 = require("
|
|
79
|
-
var formatter_1 = require("
|
|
80
|
-
var constants_1 = require("
|
|
41
|
+
var types_1 = require("../../types");
|
|
42
|
+
var formatter_1 = require("../../utils/formatter");
|
|
43
|
+
var constants_1 = require("../constants");
|
|
81
44
|
var PoolData = /** @class */ (function () {
|
|
82
45
|
function PoolData(payload) {
|
|
83
46
|
this.isPaused = false;
|
|
@@ -116,24 +79,72 @@ var PoolData = /** @class */ (function () {
|
|
|
116
79
|
return PoolData;
|
|
117
80
|
}());
|
|
118
81
|
exports.PoolData = PoolData;
|
|
119
|
-
var ChartsPoolData = /** @class */ (function (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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)
|
|
93
|
+
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
94
|
+
.div(ethers_1.BigNumber.from(payload.expectedLiquidity || 0))
|
|
95
|
+
.toNumber() / constants_1.PERCENTAGE_DECIMALS;
|
|
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;
|
|
136
147
|
}
|
|
137
148
|
return ChartsPoolData;
|
|
138
|
-
}(
|
|
149
|
+
}());
|
|
139
150
|
exports.ChartsPoolData = ChartsPoolData;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./data"), exports);
|
|
18
|
+
__exportStar(require("./operation"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { TokenData } from "../../tokens/tokenData";
|
|
3
|
+
export interface BasePoolOperation {
|
|
4
|
+
amount: string;
|
|
5
|
+
pool: string;
|
|
6
|
+
session_id: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
tx_hash: string;
|
|
9
|
+
user: string;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class AbstractPoolOperation {
|
|
12
|
+
readonly txHash: string;
|
|
13
|
+
readonly date: string;
|
|
14
|
+
readonly timestamp: number;
|
|
15
|
+
readonly user: string;
|
|
16
|
+
readonly sessionId: string;
|
|
17
|
+
readonly pool: string;
|
|
18
|
+
readonly amount: BigNumber;
|
|
19
|
+
constructor(opts: BasePoolOperation);
|
|
20
|
+
abstract toString(token: TokenData): string;
|
|
21
|
+
}
|
|
22
|
+
export declare type PoolOperationResponse = BasePoolOperation & {
|
|
23
|
+
event: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class PoolOperation extends AbstractPoolOperation {
|
|
26
|
+
readonly event: string;
|
|
27
|
+
constructor(ops: PoolOperationResponse);
|
|
28
|
+
toString(token: TokenData): string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PoolOperation = exports.AbstractPoolOperation = void 0;
|
|
19
|
+
var ethers_1 = require("ethers");
|
|
20
|
+
var moment_1 = require("moment");
|
|
21
|
+
var contractsRegister_1 = require("../../contracts/contractsRegister");
|
|
22
|
+
var formatter_1 = require("../../utils/formatter");
|
|
23
|
+
var AbstractPoolOperation = /** @class */ (function () {
|
|
24
|
+
function AbstractPoolOperation(opts) {
|
|
25
|
+
this.txHash = opts.tx_hash;
|
|
26
|
+
this.amount = ethers_1.BigNumber.from(opts.amount);
|
|
27
|
+
this.pool = opts.pool;
|
|
28
|
+
this.sessionId = opts.session_id;
|
|
29
|
+
this.user = opts.user;
|
|
30
|
+
this.timestamp = opts.timestamp;
|
|
31
|
+
this.date = (0, moment_1.unix)(opts.timestamp).format("Do MMM YYYY");
|
|
32
|
+
}
|
|
33
|
+
return AbstractPoolOperation;
|
|
34
|
+
}());
|
|
35
|
+
exports.AbstractPoolOperation = AbstractPoolOperation;
|
|
36
|
+
var PoolOperation = /** @class */ (function (_super) {
|
|
37
|
+
__extends(PoolOperation, _super);
|
|
38
|
+
function PoolOperation(ops) {
|
|
39
|
+
var _this = _super.call(this, ops) || this;
|
|
40
|
+
_this.event = ops.event;
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
PoolOperation.prototype.toString = function (token) {
|
|
44
|
+
return "".concat(this.event, " ").concat((0, formatter_1.formatBN)(ethers_1.BigNumber.from(this.amount), token.decimals), " ").concat((0, contractsRegister_1.getContractName)(this.pool));
|
|
45
|
+
};
|
|
46
|
+
return PoolOperation;
|
|
47
|
+
}(AbstractPoolOperation));
|
|
48
|
+
exports.PoolOperation = PoolOperation;
|
|
@@ -1,23 +1,77 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 CreditSessionsAggregatedStats {
|
|
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 {};
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
package/lib/core/pool.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { BigNumber, providers, Signer } from "ethers";
|
|
2
|
-
import { ChartsPoolDataPayload, PoolDataPayload } from "../payload/pool";
|
|
3
|
-
import { IPoolService } from "../types";
|
|
4
|
-
export declare class PoolData {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
readonly address: string;
|
|
7
|
-
readonly underlyingToken: string;
|
|
8
|
-
readonly dieselToken: string;
|
|
9
|
-
readonly isWETH: boolean;
|
|
10
|
-
readonly expectedLiquidity: BigNumber;
|
|
11
|
-
readonly expectedLiquidityLimit: BigNumber;
|
|
12
|
-
readonly availableLiquidity: BigNumber;
|
|
13
|
-
readonly totalBorrowed: BigNumber;
|
|
14
|
-
readonly depositAPY: number;
|
|
15
|
-
readonly borrowAPY: number;
|
|
16
|
-
readonly borrowAPYRay: BigNumber;
|
|
17
|
-
readonly dieselRate: number;
|
|
18
|
-
readonly dieselRateRay: BigNumber;
|
|
19
|
-
readonly withdrawFee: number;
|
|
20
|
-
readonly timestampLU: BigNumber;
|
|
21
|
-
readonly cumulativeIndex_RAY: BigNumber;
|
|
22
|
-
readonly isPaused: boolean;
|
|
23
|
-
constructor(payload: PoolDataPayload);
|
|
24
|
-
getContractETH(signer: Signer): IPoolService;
|
|
25
|
-
static calculateBorrowRate({ modelAddress, provider, expectedLiquidity, availableLiquidity, }: calculateBorrowRateProps): Promise<BigNumber>;
|
|
26
|
-
}
|
|
27
|
-
interface calculateBorrowRateProps {
|
|
28
|
-
modelAddress: string;
|
|
29
|
-
provider: providers.Provider;
|
|
30
|
-
expectedLiquidity: BigNumber;
|
|
31
|
-
availableLiquidity: BigNumber;
|
|
32
|
-
}
|
|
33
|
-
export declare class ChartsPoolData extends PoolData {
|
|
34
|
-
readonly expectedLiquidityInUSD: number;
|
|
35
|
-
readonly expectedLiquidityLimitInUSD: number;
|
|
36
|
-
readonly availableLiquidityInUSD: number;
|
|
37
|
-
readonly caLockedValueInUSD: number;
|
|
38
|
-
readonly totalBorrowedInUSD: number;
|
|
39
|
-
readonly uniqueLPs: number;
|
|
40
|
-
readonly depositAPY7D: number;
|
|
41
|
-
readonly depositAPY30D: number;
|
|
42
|
-
readonly lmAPY: number;
|
|
43
|
-
constructor({ expectedLiquidityInUSD, expectedLiquidityLimitInUSD, availableLiquidityInUSD, totalBorrowedInUSD, caLockedValueInUSD, uniqueLPs, dieselAPY7D, dieselAPY30D, lmAPY, ...restPayload }: ChartsPoolDataPayload);
|
|
44
|
-
}
|
|
45
|
-
export {};
|