@gearbox-protocol/sdk 1.20.17 → 1.20.19
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/chains.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const GOERLI_NETWORK = 5;
|
|
|
4
4
|
export declare const OPTIMISM_NETWORK = 10;
|
|
5
5
|
export declare const POLYGON_NETWORK = 137;
|
|
6
6
|
export declare const LOCAL_NETWORK = 1337;
|
|
7
|
+
export declare const TENDERLY_NETWORK = 123456;
|
|
7
8
|
export declare const HARDHAT_NETWORK = 31337;
|
|
8
9
|
export declare const ARBITRUM_NETWORK = 42161;
|
|
9
10
|
export declare const CHAINS: {
|
|
@@ -11,6 +12,7 @@ export declare const CHAINS: {
|
|
|
11
12
|
readonly Goerli: 5;
|
|
12
13
|
readonly Local: 1337;
|
|
13
14
|
readonly Hardhat: 31337;
|
|
15
|
+
readonly Tenderly: 123456;
|
|
14
16
|
readonly Optimism: 10;
|
|
15
17
|
readonly Polygon: 137;
|
|
16
18
|
readonly Arbiturum: 42161;
|
package/lib/core/chains.js
CHANGED
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
var _a;
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.detectNetwork = exports.isSupportedNetwork = exports.getNetworkType = exports.CHAINS = exports.ARBITRUM_NETWORK = exports.HARDHAT_NETWORK = exports.LOCAL_NETWORK = exports.POLYGON_NETWORK = exports.OPTIMISM_NETWORK = exports.GOERLI_NETWORK = exports.MAINNET_NETWORK = void 0;
|
|
40
|
+
exports.detectNetwork = exports.isSupportedNetwork = exports.getNetworkType = exports.CHAINS = exports.ARBITRUM_NETWORK = exports.HARDHAT_NETWORK = exports.TENDERLY_NETWORK = exports.LOCAL_NETWORK = exports.POLYGON_NETWORK = exports.OPTIMISM_NETWORK = exports.GOERLI_NETWORK = exports.MAINNET_NETWORK = void 0;
|
|
41
41
|
var token_1 = require("../tokens/token");
|
|
42
42
|
var types_1 = require("../types");
|
|
43
43
|
var constants_1 = require("./constants");
|
|
@@ -46,6 +46,7 @@ exports.GOERLI_NETWORK = 5;
|
|
|
46
46
|
exports.OPTIMISM_NETWORK = 10;
|
|
47
47
|
exports.POLYGON_NETWORK = 137;
|
|
48
48
|
exports.LOCAL_NETWORK = 1337;
|
|
49
|
+
exports.TENDERLY_NETWORK = 123456;
|
|
49
50
|
exports.HARDHAT_NETWORK = 31337;
|
|
50
51
|
exports.ARBITRUM_NETWORK = 42161;
|
|
51
52
|
exports.CHAINS = {
|
|
@@ -53,6 +54,7 @@ exports.CHAINS = {
|
|
|
53
54
|
Goerli: exports.GOERLI_NETWORK,
|
|
54
55
|
Local: exports.LOCAL_NETWORK,
|
|
55
56
|
Hardhat: exports.HARDHAT_NETWORK,
|
|
57
|
+
Tenderly: exports.TENDERLY_NETWORK,
|
|
56
58
|
Optimism: exports.OPTIMISM_NETWORK,
|
|
57
59
|
Polygon: exports.POLYGON_NETWORK,
|
|
58
60
|
Arbiturum: exports.ARBITRUM_NETWORK,
|
|
@@ -61,6 +63,7 @@ var SUPPORTED_CHAINS = (_a = {},
|
|
|
61
63
|
_a[exports.CHAINS.Mainnet] = "Mainnet",
|
|
62
64
|
_a[exports.CHAINS.Goerli] = "Goerli",
|
|
63
65
|
_a[exports.CHAINS.Local] = "Mainnet",
|
|
66
|
+
_a[exports.CHAINS.Tenderly] = "Mainnet",
|
|
64
67
|
_a);
|
|
65
68
|
var getNetworkType = function (chainId, localAs) {
|
|
66
69
|
if (localAs === void 0) { localAs = "Mainnet"; }
|
|
@@ -33,7 +33,7 @@ export declare class CreditAccountData {
|
|
|
33
33
|
balancesSorted(prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<Asset>;
|
|
34
34
|
calcBorrowAmountPlusInterestRate(currentCumulativeIndex: BigNumber): BigNumber;
|
|
35
35
|
updateHealthFactor(creditManager: CreditManagerData, currentCumulativeIndex: BigNumber, priceOracle: PriceOracleData): void;
|
|
36
|
-
static calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: BigNumber, maxLeverageFactor: number, underlyingLT: number): BigNumber;
|
|
36
|
+
static calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: BigNumber, maxLeverageFactor: number, underlyingLT: number, minHf?: number): BigNumber;
|
|
37
37
|
get id(): string;
|
|
38
38
|
hash(): string;
|
|
39
39
|
static hash(creditManager: string, borrower: string): string;
|
|
@@ -78,11 +78,12 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
78
78
|
.div(this.calcBorrowAmountPlusInterestRate(currentCumulativeIndex))
|
|
79
79
|
.toNumber();
|
|
80
80
|
};
|
|
81
|
-
CreditAccountData.calcMaxIncreaseBorrow = function (healthFactor, borrowAmountPlusInterest, maxLeverageFactor, underlyingLT) {
|
|
81
|
+
CreditAccountData.calcMaxIncreaseBorrow = function (healthFactor, borrowAmountPlusInterest, maxLeverageFactor, underlyingLT, minHf) {
|
|
82
|
+
if (minHf === void 0) { minHf = constants_1.PERCENTAGE_FACTOR; }
|
|
82
83
|
var minHealthFactor = maxLeverageFactor > 0
|
|
83
84
|
? Math.floor((underlyingLT * (maxLeverageFactor + constants_1.LEVERAGE_DECIMALS)) /
|
|
84
85
|
maxLeverageFactor)
|
|
85
|
-
:
|
|
86
|
+
: minHf;
|
|
86
87
|
var result = borrowAmountPlusInterest
|
|
87
88
|
.mul(healthFactor - minHealthFactor)
|
|
88
89
|
.div(minHealthFactor - underlyingLT);
|
|
@@ -137,7 +138,11 @@ function amountAbcComparator(t1, t2) {
|
|
|
137
138
|
exports.amountAbcComparator = amountAbcComparator;
|
|
138
139
|
function calcOverallAPY(_a) {
|
|
139
140
|
var caAssets = _a.caAssets, lpAPY = _a.lpAPY, prices = _a.prices, totalValue = _a.totalValue, debt = _a.debt, borrowRate = _a.borrowRate, underlyingToken = _a.underlyingToken;
|
|
140
|
-
if (!lpAPY ||
|
|
141
|
+
if (!lpAPY ||
|
|
142
|
+
!totalValue ||
|
|
143
|
+
totalValue.lte(0) ||
|
|
144
|
+
!debt ||
|
|
145
|
+
totalValue.lte(debt))
|
|
141
146
|
return undefined;
|
|
142
147
|
var assetAPYMoney = caAssets.reduce(function (acc, _a) {
|
|
143
148
|
var tokenAddress = _a.token, amount = _a.balance;
|
package/lib/core/strategy.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare class Strategy {
|
|
|
29
29
|
static maxLeverage(lpToken: string, cms: Array<PartialCM>): number;
|
|
30
30
|
maxAPY(baseAPY: number, maxLeverage: number, borrowAPY: number): number;
|
|
31
31
|
overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
|
|
32
|
-
liquidationPrice({ prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }: LiquidationPriceProps): BigNumber;
|
|
32
|
+
static liquidationPrice({ prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }: LiquidationPriceProps): BigNumber;
|
|
33
33
|
protected farmLev(leverage: number, depositCollateral: string): number;
|
|
34
34
|
protected inBaseAssets(depositCollateral: string): boolean;
|
|
35
35
|
protected inLeveragableAssets(depositCollateral: string): boolean;
|
package/lib/core/strategy.js
CHANGED
|
@@ -35,8 +35,7 @@ var Strategy = /** @class */ (function () {
|
|
|
35
35
|
var farmLev = this.farmLev(leverage, depositCollateral);
|
|
36
36
|
return roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
Strategy.prototype.liquidationPrice = function (_a) {
|
|
38
|
+
Strategy.liquidationPrice = function (_a) {
|
|
40
39
|
var prices = _a.prices, liquidationThresholds = _a.liquidationThresholds, borrowed = _a.borrowed, underlyingToken = _a.underlyingToken, lpAmount = _a.lpAmount, lpToken = _a.lpToken;
|
|
41
40
|
var underlyingTokenAddressLC = underlyingToken.toLowerCase();
|
|
42
41
|
var underlyingTokenSymbol = token_1.tokenSymbolByAddress[underlyingTokenAddressLC];
|
|
@@ -50,7 +50,7 @@ describe("Strategy test", function () {
|
|
|
50
50
|
(0, chai_1.expect)(result).to.be.eq(332716);
|
|
51
51
|
});
|
|
52
52
|
it("liquidationPrice calculation is correct", function () {
|
|
53
|
-
var result =
|
|
53
|
+
var result = strategy_1.Strategy.liquidationPrice({
|
|
54
54
|
liquidationThresholds: liquidationThresholds,
|
|
55
55
|
prices: prices,
|
|
56
56
|
borrowed: (0, formatter_1.toBN)("350", decimals_1.decimals.WETH),
|