@gearbox-protocol/sdk 1.5.22 → 1.5.23
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
import { LpTokensAPY } from "../apy";
|
|
3
|
-
import {
|
|
3
|
+
import { CreditAccountDataPayload } from "../payload/creditAccount";
|
|
4
4
|
import { TokenData } from "../tokens/tokenData";
|
|
5
5
|
import { Asset, LpAsset } from "./assets";
|
|
6
6
|
import { CreditManagerData } from "./creditManager";
|
|
@@ -25,6 +25,9 @@ export declare class CreditAccountData {
|
|
|
25
25
|
isDeleting: boolean;
|
|
26
26
|
enabledTokenMask: BigNumber;
|
|
27
27
|
readonly version: number;
|
|
28
|
+
readonly repayAmount: BigNumber;
|
|
29
|
+
readonly liquidationAmount: BigNumber;
|
|
30
|
+
readonly canBeClosed: boolean;
|
|
28
31
|
constructor(payload: CreditAccountDataPayload);
|
|
29
32
|
balancesSorted(prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<Asset>;
|
|
30
33
|
calcBorrowAmountPlusInterestRate(currentCumulativeIndex: BigNumber): BigNumber;
|
|
@@ -36,15 +39,6 @@ export declare class CreditAccountData {
|
|
|
36
39
|
export declare function sortBalances(balances: Record<string, BigNumber>, prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<[string, BigNumber]>;
|
|
37
40
|
export declare function tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1;
|
|
38
41
|
export declare function amountAbcComparator(t1: BigNumber, t2: BigNumber): 1 | -1;
|
|
39
|
-
export declare class CreditAccountDataExtended extends CreditAccountData {
|
|
40
|
-
readonly repayAmount: BigNumber;
|
|
41
|
-
readonly liquidationAmount: BigNumber;
|
|
42
|
-
readonly borrowedAmount: BigNumber;
|
|
43
|
-
readonly canBeClosed: boolean;
|
|
44
|
-
readonly cumulativeIndexAtOpen: BigNumber;
|
|
45
|
-
readonly since: number;
|
|
46
|
-
constructor(payload: CreditAccountDataExtendedPayload);
|
|
47
|
-
}
|
|
48
42
|
export interface CalcOverallAPYProps {
|
|
49
43
|
lpAssets: Array<LpAsset>;
|
|
50
44
|
lpAPY: LpTokensAPY | undefined;
|
|
@@ -1,21 +1,6 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.calcOverallAPY = exports.
|
|
3
|
+
exports.calcOverallAPY = exports.amountAbcComparator = exports.tokensAbcComparator = exports.sortBalances = exports.CreditAccountData = void 0;
|
|
19
4
|
var ethers_1 = require("ethers");
|
|
20
5
|
var formatter_1 = require("../utils/formatter");
|
|
21
6
|
var price_1 = require("../utils/price");
|
|
@@ -34,30 +19,32 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
34
19
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
35
20
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
36
21
|
this.since = ethers_1.BigNumber.from(payload.since).toNumber();
|
|
37
|
-
this.cumulativeIndexAtOpen =
|
|
38
|
-
this.borrowedAmount =
|
|
39
|
-
this.borrowedAmountPlusInterest =
|
|
40
|
-
this.totalValue =
|
|
41
|
-
this.healthFactor =
|
|
42
|
-
ethers_1.BigNumber.from(payload.healthFactor).toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
22
|
+
this.cumulativeIndexAtOpen = payload.cumulativeIndexAtOpen;
|
|
23
|
+
this.borrowedAmount = payload.borrowedAmount;
|
|
24
|
+
this.borrowedAmountPlusInterest = payload.borrowedAmountPlusInterest;
|
|
25
|
+
this.totalValue = payload.totalValue;
|
|
26
|
+
this.healthFactor = payload.healthFactor.toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
43
27
|
this.borrowRate =
|
|
44
|
-
|
|
28
|
+
payload.borrowRate
|
|
45
29
|
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
46
30
|
.mul(constants_1.PERCENTAGE_DECIMALS)
|
|
47
31
|
.div(constants_1.RAY)
|
|
48
32
|
.toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
49
|
-
|
|
33
|
+
payload.balances.forEach(function (b) {
|
|
50
34
|
var tokenLC = b.token.toLowerCase();
|
|
51
35
|
if (b.isAllowed) {
|
|
52
|
-
_this.balances[tokenLC] =
|
|
36
|
+
_this.balances[tokenLC] = b.balance;
|
|
53
37
|
_this.collateralTokens.push(tokenLC);
|
|
54
38
|
}
|
|
55
|
-
_this.allBalances[tokenLC] =
|
|
39
|
+
_this.allBalances[tokenLC] = b.balance;
|
|
56
40
|
_this.allTokens.push(tokenLC);
|
|
57
41
|
});
|
|
58
|
-
this.enabledTokenMask =
|
|
42
|
+
this.enabledTokenMask = payload.enabledTokenMask;
|
|
59
43
|
this.isDeleting = false;
|
|
60
|
-
this.version =
|
|
44
|
+
this.version = payload.version;
|
|
45
|
+
this.repayAmount = payload.repayAmount;
|
|
46
|
+
this.liquidationAmount = payload.liquidationAmount;
|
|
47
|
+
this.canBeClosed = payload.canBeClosed;
|
|
61
48
|
}
|
|
62
49
|
CreditAccountData.prototype.balancesSorted = function (prices, tokens) {
|
|
63
50
|
return sortBalances(this.balances, prices, tokens).map(function (_a) {
|
|
@@ -137,21 +124,6 @@ function amountAbcComparator(t1, t2) {
|
|
|
137
124
|
return (t1 === null || t1 === void 0 ? void 0 : t1.gt(t2)) ? -1 : 1;
|
|
138
125
|
}
|
|
139
126
|
exports.amountAbcComparator = amountAbcComparator;
|
|
140
|
-
var CreditAccountDataExtended = /** @class */ (function (_super) {
|
|
141
|
-
__extends(CreditAccountDataExtended, _super);
|
|
142
|
-
function CreditAccountDataExtended(payload) {
|
|
143
|
-
var _this = _super.call(this, payload) || this;
|
|
144
|
-
_this.borrowedAmount = ethers_1.BigNumber.from(payload.borrowedAmount);
|
|
145
|
-
_this.cumulativeIndexAtOpen = ethers_1.BigNumber.from(payload.cumulativeIndexAtOpen);
|
|
146
|
-
_this.repayAmount = ethers_1.BigNumber.from(payload.repayAmount);
|
|
147
|
-
_this.liquidationAmount = ethers_1.BigNumber.from(payload.liquidationAmount);
|
|
148
|
-
_this.canBeClosed = payload.canBeClosed || false;
|
|
149
|
-
_this.since = ethers_1.BigNumber.from(payload.since).toNumber();
|
|
150
|
-
return _this;
|
|
151
|
-
}
|
|
152
|
-
return CreditAccountDataExtended;
|
|
153
|
-
}(CreditAccountData));
|
|
154
|
-
exports.CreditAccountDataExtended = CreditAccountDataExtended;
|
|
155
127
|
function calcOverallAPY(_a) {
|
|
156
128
|
var lpAssets = _a.lpAssets, lpAPY = _a.lpAPY, prices = _a.prices, tokensList = _a.tokensList, totalValue = _a.totalValue, debt = _a.debt, borrowRate = _a.borrowRate, underlyingToken = _a.underlyingToken;
|
|
157
129
|
if (!lpAPY || !totalValue || !debt)
|
|
@@ -5,7 +5,6 @@ import { TokenData } from "../tokens/tokenData";
|
|
|
5
5
|
import { ICreditManager } from "../types";
|
|
6
6
|
import { Asset } from "./assets";
|
|
7
7
|
export declare class CreditManagerData {
|
|
8
|
-
readonly id: string;
|
|
9
8
|
readonly address: string;
|
|
10
9
|
readonly underlyingToken: string;
|
|
11
10
|
readonly pool: string;
|
|
@@ -41,6 +40,7 @@ export declare class CreditManagerData {
|
|
|
41
40
|
validateOpenAccount(collateral: BigNumber, debt: BigNumber): true;
|
|
42
41
|
protected validateOpenAccountV1(collateral: BigNumber, debt: BigNumber): true;
|
|
43
42
|
protected validateOpenAccountV2(debt: BigNumber): true;
|
|
43
|
+
get id(): string;
|
|
44
44
|
}
|
|
45
45
|
export declare class CreditManagerStat extends CreditManagerData {
|
|
46
46
|
readonly uniqueUsers: number;
|
|
@@ -37,22 +37,21 @@ var errors_1 = require("./errors");
|
|
|
37
37
|
var CreditManagerData = /** @class */ (function () {
|
|
38
38
|
function CreditManagerData(payload) {
|
|
39
39
|
this.isPaused = false;
|
|
40
|
-
this.id = payload.addr.toLowerCase();
|
|
41
40
|
this.address = payload.addr.toLowerCase();
|
|
42
41
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
43
42
|
this.pool = payload.pool.toLowerCase();
|
|
44
43
|
this.isWETH = payload.isWETH;
|
|
45
44
|
this.canBorrow = payload.canBorrow;
|
|
46
45
|
this.borrowRate =
|
|
47
|
-
|
|
48
|
-
.mul(
|
|
46
|
+
payload.borrowRate
|
|
47
|
+
.mul(payload.feeInterest + constants_1.PERCENTAGE_FACTOR)
|
|
49
48
|
.mul(constants_1.PERCENTAGE_DECIMALS)
|
|
50
49
|
.div(constants_1.RAY)
|
|
51
50
|
.toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
52
|
-
this.minAmount =
|
|
53
|
-
this.maxAmount =
|
|
51
|
+
this.minAmount = payload.minAmount;
|
|
52
|
+
this.maxAmount = payload.maxAmount;
|
|
54
53
|
this.maxLeverageFactor = ethers_1.BigNumber.from(payload.maxLeverageFactor).toNumber();
|
|
55
|
-
this.availableLiquidity =
|
|
54
|
+
this.availableLiquidity = payload.availableLiquidity;
|
|
56
55
|
this.collateralTokens = payload.collateralTokens.map(function (t) { return t.toLowerCase(); });
|
|
57
56
|
this.adapters = payload.adapters.reduce(function (acc, _a) {
|
|
58
57
|
var _b;
|
|
@@ -62,21 +61,21 @@ var CreditManagerData = /** @class */ (function () {
|
|
|
62
61
|
this.liquidationThresholds = payload.liquidationThresholds.reduce(function (acc, threshold, index) {
|
|
63
62
|
var address = payload.collateralTokens[index];
|
|
64
63
|
if (address)
|
|
65
|
-
acc[address.toLowerCase()] =
|
|
64
|
+
acc[address.toLowerCase()] = threshold;
|
|
66
65
|
return acc;
|
|
67
66
|
}, {});
|
|
68
|
-
this.version =
|
|
69
|
-
this.creditFacade =
|
|
70
|
-
this.creditConfigurator =
|
|
71
|
-
this.isDegenMode = payload.isDegenMode
|
|
72
|
-
this.degenNFT =
|
|
73
|
-
this.isIncreaseDebtForbidden = payload.isIncreaseDebtForbidden
|
|
74
|
-
this.forbiddenTokenMask =
|
|
75
|
-
this.feeInterest =
|
|
76
|
-
this.feeLiquidation =
|
|
77
|
-
this.liquidationDiscount =
|
|
78
|
-
this.feeLiquidationExpired =
|
|
79
|
-
this.liquidationDiscountExpired =
|
|
67
|
+
this.version = payload.version;
|
|
68
|
+
this.creditFacade = payload.creditFacade.toLowerCase();
|
|
69
|
+
this.creditConfigurator = payload.creditConfigurator.toLowerCase();
|
|
70
|
+
this.isDegenMode = payload.isDegenMode;
|
|
71
|
+
this.degenNFT = payload.degenNFT.toLowerCase();
|
|
72
|
+
this.isIncreaseDebtForbidden = payload.isIncreaseDebtForbidden;
|
|
73
|
+
this.forbiddenTokenMask = payload.forbiddenTokenMask;
|
|
74
|
+
this.feeInterest = payload.feeInterest;
|
|
75
|
+
this.feeLiquidation = payload.feeLiquidation;
|
|
76
|
+
this.liquidationDiscount = payload.feeLiquidation;
|
|
77
|
+
this.feeLiquidationExpired = payload.feeLiquidationExpired;
|
|
78
|
+
this.liquidationDiscountExpired = payload.feeLiquidationExpired;
|
|
80
79
|
if (this.creditFacade !== "") {
|
|
81
80
|
txParser_1.TxParser.addCreditFacade(this.creditFacade, token_1.tokenSymbolByAddress[this.underlyingToken]);
|
|
82
81
|
txParser_1.TxParser.addAdapters(payload.adapters.map(function (a) { return ({
|
|
@@ -143,6 +142,13 @@ var CreditManagerData = /** @class */ (function () {
|
|
|
143
142
|
throw new errors_1.OpenAccountError("insufficientPoolLiquidity", ethers_1.BigNumber.from(this.availableLiquidity));
|
|
144
143
|
return true;
|
|
145
144
|
};
|
|
145
|
+
Object.defineProperty(CreditManagerData.prototype, "id", {
|
|
146
|
+
get: function () {
|
|
147
|
+
return this.address;
|
|
148
|
+
},
|
|
149
|
+
enumerable: false,
|
|
150
|
+
configurable: true
|
|
151
|
+
});
|
|
146
152
|
return CreditManagerData;
|
|
147
153
|
}());
|
|
148
154
|
exports.CreditManagerData = CreditManagerData;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CreditAccountDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
1
|
+
import { CreditAccountDataStruct, CreditAccountDataStructOutput } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
2
|
export declare type TokenBalancePayload = CreditAccountDataStruct["balances"];
|
|
3
|
-
export declare type CreditAccountDataPayload =
|
|
4
|
-
export declare type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
|
|
3
|
+
export declare type CreditAccountDataPayload = CreditAccountDataStructOutput;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
|
-
import {
|
|
2
|
+
import { CreditManagerDataStructOutput } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
3
3
|
export interface AdapterPayload {
|
|
4
4
|
allowedContract: string;
|
|
5
5
|
adapter: string;
|
|
6
6
|
}
|
|
7
|
-
export declare type CreditManagerDataPayload =
|
|
7
|
+
export declare type CreditManagerDataPayload = CreditManagerDataStructOutput;
|
|
8
8
|
export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
9
9
|
allowedContracts?: Array<string>;
|
|
10
10
|
uniqueUsers: number;
|
|
@@ -18,9 +18,4 @@ export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
|
18
18
|
totalRepaid?: BigNumberish;
|
|
19
19
|
totalProfit?: BigNumberish;
|
|
20
20
|
totalLosses?: BigNumberish;
|
|
21
|
-
feeInterest: BigNumberish;
|
|
22
|
-
feeLiquidation: BigNumberish;
|
|
23
|
-
liquidationDiscount: BigNumberish;
|
|
24
|
-
feeLiquidationExpired: BigNumberish;
|
|
25
|
-
liquidationDiscountExpired: BigNumberish;
|
|
26
21
|
}
|