@gearbox-protocol/sdk 0.0.98 → 0.0.101
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/apy/convexAPY.d.ts +8 -0
- package/lib/apy/convexAPY.js +202 -0
- package/lib/apy/lidoAPY.d.ts +4 -0
- package/lib/apy/lidoAPY.js +97 -0
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -1
- package/lib/contracts/contracts.d.ts +6 -1
- package/lib/contracts/contracts.js +52 -14
- package/lib/contracts/contractsRegister.js +3 -3
- package/lib/core/constants.d.ts +4 -0
- package/lib/core/constants.js +8 -4
- package/lib/core/creditAccount.d.ts +2 -0
- package/lib/core/creditAccount.js +31 -30
- package/lib/core/creditManager.d.ts +13 -2
- package/lib/core/creditManager.js +79 -29
- package/lib/core/errors.d.ts +10 -0
- package/lib/core/errors.js +16 -1
- package/lib/core/events.js +9 -9
- package/lib/core/multicall.d.ts +1 -1
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +7 -5
- package/lib/core/price.d.ts +4 -0
- package/lib/core/price.js +12 -0
- package/lib/core/strategy.d.ts +34 -0
- package/lib/core/strategy.js +57 -0
- package/lib/index.d.ts +7 -1
- package/lib/index.js +8 -3
- package/lib/pathfinder/path.js +1 -1
- package/lib/pathfinder/yVault.js +7 -4
- package/lib/payload/creditAccount.d.ts +4 -26
- package/lib/payload/creditManager.d.ts +12 -24
- package/lib/payload/pool.d.ts +2 -17
- package/lib/payload/pool.js +0 -1
- package/lib/tokens/token.js +4 -4
- package/lib/utils/formatter.d.ts +1 -0
- package/lib/utils/formatter.js +6 -1
- package/lib/utils/mappers.d.ts +2 -1
- package/lib/utils/mappers.js +13 -5
- package/lib/utils/multicall.js +4 -3
- package/lib/utils/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/apy/convexAPY.ts +249 -0
- package/src/apy/lidoAPY.ts +81 -0
- package/src/config.ts +2 -1
- package/src/contracts/contracts.ts +69 -16
- package/src/contracts/contractsRegister.ts +3 -3
- package/src/core/constants.ts +7 -3
- package/src/core/creditAccount.ts +39 -33
- package/src/core/creditManager.ts +230 -148
- package/src/core/errors.ts +24 -0
- package/src/core/events.ts +921 -915
- package/src/core/multicall.ts +1 -1
- package/src/core/pool.ts +56 -51
- package/src/core/price.ts +16 -0
- package/src/core/strategy.ts +123 -0
- package/src/index.ts +8 -1
- package/src/pathfinder/path.ts +154 -154
- package/src/pathfinder/yVault.ts +57 -56
- package/src/payload/creditAccount.ts +4 -26
- package/src/payload/creditManager.ts +13 -25
- package/src/payload/pool.ts +2 -19
- package/src/tokens/token.ts +10 -5
- package/src/utils/formatter.ts +5 -1
- package/src/utils/mappers.ts +12 -5
- package/src/utils/multicall.ts +4 -9
- package/src/utils/types.ts +6 -2
- package/lib/core/adapters.d.ts +0 -15
- package/lib/core/adapters.js +0 -19
- package/lib/core/contracts.d.ts +0 -67
- package/lib/core/contracts.js +0 -254
- package/lib/core/contractsRegister.d.ts +0 -2
- package/lib/core/contractsRegister.js +0 -58
- package/lib/core/creditCard.d.ts +0 -13
- package/lib/core/creditCard.js +0 -2
- package/lib/core/oracles.d.ts +0 -38
- package/lib/core/oracles.js +0 -12
- package/lib/core/priceFeeds.d.ts +0 -3
- package/lib/core/priceFeeds.js +0 -492
- package/lib/core/protocols.d.ts +0 -13
- package/lib/core/protocols.js +0 -39
- package/lib/core/swap.d.ts +0 -4
- package/lib/core/swap.js +0 -8
- package/lib/core/trade.d.ts +0 -35
- package/lib/core/trade.js +0 -62
- package/lib/core/tradeTypes.d.ts +0 -79
- package/lib/core/tradeTypes.js +0 -21
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BigNumber, ethers, Signer } from "ethers";
|
|
2
2
|
import { CreditManagerDataPayload, CreditManagerStatPayload } from "../payload/creditManager";
|
|
3
3
|
import { ICreditManager } from "../types";
|
|
4
|
+
import { MultiCall } from "./multicall";
|
|
4
5
|
export declare class CreditManagerData {
|
|
5
6
|
readonly id: string;
|
|
6
7
|
readonly address: string;
|
|
@@ -14,11 +15,21 @@ export declare class CreditManagerData {
|
|
|
14
15
|
readonly availableLiquidity: BigNumber;
|
|
15
16
|
readonly allowedTokens: Array<string>;
|
|
16
17
|
readonly adapters: Record<string, string>;
|
|
18
|
+
readonly liquidationThresholds: Record<string, BigNumber>;
|
|
17
19
|
readonly version: number;
|
|
20
|
+
readonly creditFacade: string;
|
|
21
|
+
readonly isDegenMode: boolean;
|
|
22
|
+
readonly degenNFT: string;
|
|
23
|
+
readonly isIncreaseDebtForbidden: boolean;
|
|
24
|
+
readonly forbiddenTokenMask: BigNumber;
|
|
18
25
|
constructor(payload: CreditManagerDataPayload);
|
|
19
|
-
validateOpenAccount(balance: BigNumber, decimals: number, amount_BN: BigNumber, leverage: number): string | null;
|
|
20
|
-
getContractETH(signer: Signer | ethers.providers.Provider): ICreditManager;
|
|
21
26
|
get isPaused(): boolean;
|
|
27
|
+
getContractETH(signer: Signer | ethers.providers.Provider): ICreditManager;
|
|
28
|
+
contractToAdapter(contractAddress: string): string | undefined;
|
|
29
|
+
encodeAddCollateral(accountAddress: string, tokenAddress: string, amount: BigNumber): MultiCall;
|
|
30
|
+
encodeIncreaseDebt(amount: BigNumber): MultiCall;
|
|
31
|
+
encodeDecreaseDebt(amount: BigNumber): MultiCall;
|
|
32
|
+
validateOpenAccount(totalAmount: BigNumber, leverage: number): true;
|
|
22
33
|
}
|
|
23
34
|
export declare function calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: BigNumber, maxLeverageFactor: number): BigNumber;
|
|
24
35
|
export declare function calcHealthFactorAfterIncreasingBorrow(healthFactor: number | undefined, borrowAmountPlusInterest: BigNumber | undefined, additional: BigNumber): number;
|
|
@@ -14,54 +14,59 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
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
|
+
};
|
|
17
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
29
|
exports.CreditManagerStat = exports.calcHealthFactorAfterAddingCollateral = exports.calcHealthFactorAfterIncreasingBorrow = exports.calcMaxIncreaseBorrow = exports.CreditManagerData = void 0;
|
|
19
30
|
var ethers_1 = require("ethers");
|
|
20
|
-
var formatter_1 = require("../utils/formatter");
|
|
21
|
-
var constants_1 = require("./constants");
|
|
22
31
|
var types_1 = require("../types");
|
|
32
|
+
var constants_1 = require("./constants");
|
|
33
|
+
var errors_1 = require("./errors");
|
|
23
34
|
var CreditManagerData = /** @class */ (function () {
|
|
24
35
|
function CreditManagerData(payload) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
var _a;
|
|
27
|
-
this.adapters = {};
|
|
28
|
-
this.version = 1;
|
|
29
36
|
this.id = payload.addr;
|
|
30
37
|
this.address = payload.addr;
|
|
31
|
-
this.underlyingToken = payload.
|
|
38
|
+
this.underlyingToken = payload.underlying || "";
|
|
32
39
|
this.isWETH = payload.isWETH || false;
|
|
33
40
|
this.canBorrow = payload.canBorrow || false;
|
|
34
41
|
this.borrowRate =
|
|
35
42
|
ethers_1.BigNumber.from(payload.borrowRate || 0)
|
|
36
43
|
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
37
|
-
.mul(
|
|
44
|
+
.mul(constants_1.PERCENTAGE_DECIMALS)
|
|
38
45
|
.div(constants_1.RAY)
|
|
39
46
|
.toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
40
47
|
this.minAmount = ethers_1.BigNumber.from(payload.minAmount || 0);
|
|
41
48
|
this.maxAmount = ethers_1.BigNumber.from(payload.maxAmount || 0);
|
|
42
49
|
this.maxLeverageFactor = ethers_1.BigNumber.from(payload.maxLeverageFactor || 0).toNumber();
|
|
43
50
|
this.availableLiquidity = ethers_1.BigNumber.from(payload.availableLiquidity || 0);
|
|
44
|
-
this.allowedTokens = payload.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
this.allowedTokens = payload.collateralTokens || [];
|
|
52
|
+
this.adapters = (payload.adapters || []).reduce(function (acc, _a) {
|
|
53
|
+
var _b;
|
|
54
|
+
var allowedContract = _a.allowedContract, adapter = _a.adapter;
|
|
55
|
+
return (__assign(__assign({}, acc), (_b = {}, _b[allowedContract] = adapter, _b)));
|
|
56
|
+
}, {});
|
|
57
|
+
this.liquidationThresholds = payload.liquidationThresholds.reduce(function (acc, threshold, index) {
|
|
58
|
+
var address = payload.collateralTokens[index];
|
|
59
|
+
if (address)
|
|
60
|
+
acc[address.toLowerCase()] = threshold;
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
63
|
+
this.version = payload.version || 1;
|
|
64
|
+
this.creditFacade = payload.creditFacade || "";
|
|
65
|
+
this.isDegenMode = payload.isDegenMode || false;
|
|
66
|
+
this.degenNFT = payload.degenNFT || "";
|
|
67
|
+
this.isIncreaseDebtForbidden = payload.isIncreaseDebtForbidden || false;
|
|
68
|
+
this.forbiddenTokenMask = ethers_1.BigNumber.from(payload.forbiddenTokenMask || 0);
|
|
48
69
|
}
|
|
49
|
-
CreditManagerData.prototype.validateOpenAccount = function (balance, decimals, amount_BN, leverage) {
|
|
50
|
-
if (balance.lt(amount_BN))
|
|
51
|
-
return "Insufficient funds";
|
|
52
|
-
if (amount_BN.lt(this.minAmount))
|
|
53
|
-
return "Amount is less than minimal (".concat((0, formatter_1.formatBN)(this.minAmount, decimals), ")");
|
|
54
|
-
if (amount_BN.gt(this.maxAmount))
|
|
55
|
-
return "Amount is greater than maximum (".concat((0, formatter_1.formatBN)(this.maxAmount, decimals), ")");
|
|
56
|
-
if (leverage > this.maxLeverageFactor)
|
|
57
|
-
return "Leverage is bigger than max";
|
|
58
|
-
if (amount_BN.mul(leverage).div(100).gt(this.availableLiquidity))
|
|
59
|
-
return "Insufficient liquidity in the pool";
|
|
60
|
-
return null;
|
|
61
|
-
};
|
|
62
|
-
CreditManagerData.prototype.getContractETH = function (signer) {
|
|
63
|
-
return types_1.ICreditManager__factory.connect(this.address, signer);
|
|
64
|
-
};
|
|
65
70
|
Object.defineProperty(CreditManagerData.prototype, "isPaused", {
|
|
66
71
|
get: function () {
|
|
67
72
|
return false;
|
|
@@ -69,12 +74,57 @@ var CreditManagerData = /** @class */ (function () {
|
|
|
69
74
|
enumerable: false,
|
|
70
75
|
configurable: true
|
|
71
76
|
});
|
|
77
|
+
CreditManagerData.prototype.getContractETH = function (signer) {
|
|
78
|
+
return types_1.ICreditManager__factory.connect(this.address, signer);
|
|
79
|
+
};
|
|
80
|
+
CreditManagerData.prototype.contractToAdapter = function (contractAddress) {
|
|
81
|
+
return this.adapters[contractAddress];
|
|
82
|
+
};
|
|
83
|
+
CreditManagerData.prototype.encodeAddCollateral = function (accountAddress, tokenAddress, amount) {
|
|
84
|
+
if (this.version !== 2)
|
|
85
|
+
throw new Error("Multicall is eligible only for version 2");
|
|
86
|
+
return {
|
|
87
|
+
target: this.creditFacade,
|
|
88
|
+
callData: types_1.ICreditFacade__factory.createInterface().encodeFunctionData("addCollateral", [accountAddress, tokenAddress, amount])
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
CreditManagerData.prototype.encodeIncreaseDebt = function (amount) {
|
|
92
|
+
if (this.version !== 2)
|
|
93
|
+
throw new Error("Multicall is eligible only for version 2");
|
|
94
|
+
return {
|
|
95
|
+
target: this.creditFacade,
|
|
96
|
+
callData: types_1.ICreditFacade__factory.createInterface().encodeFunctionData("increaseDebt", [amount])
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
CreditManagerData.prototype.encodeDecreaseDebt = function (amount) {
|
|
100
|
+
if (this.version !== 2)
|
|
101
|
+
throw new Error("Multicall is eligible only for version 2");
|
|
102
|
+
return {
|
|
103
|
+
target: this.creditFacade,
|
|
104
|
+
callData: types_1.ICreditFacade__factory.createInterface().encodeFunctionData("decreaseDebt", [amount])
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
CreditManagerData.prototype.validateOpenAccount = function (totalAmount, leverage) {
|
|
108
|
+
if (totalAmount.lt(this.minAmount))
|
|
109
|
+
throw new errors_1.OpenAccountError("amountLessMin", this.minAmount);
|
|
110
|
+
if (totalAmount.gt(this.maxAmount))
|
|
111
|
+
throw new errors_1.OpenAccountError("amountGreaterMax", this.maxAmount);
|
|
112
|
+
if (leverage > this.maxLeverageFactor)
|
|
113
|
+
throw new errors_1.OpenAccountError("leverageGreaterMax", ethers_1.BigNumber.from(this.maxLeverageFactor));
|
|
114
|
+
if (totalAmount
|
|
115
|
+
.mul(leverage)
|
|
116
|
+
.div(constants_1.LEVERAGE_DECIMALS)
|
|
117
|
+
.gt(this.availableLiquidity))
|
|
118
|
+
throw new errors_1.OpenAccountError("insufficientPoolLiquidity", ethers_1.BigNumber.from(this.availableLiquidity));
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
72
121
|
return CreditManagerData;
|
|
73
122
|
}());
|
|
74
123
|
exports.CreditManagerData = CreditManagerData;
|
|
75
124
|
function calcMaxIncreaseBorrow(healthFactor, borrowAmountPlusInterest, maxLeverageFactor) {
|
|
76
125
|
var healthFactorPercentage = Math.floor(healthFactor * constants_1.PERCENTAGE_FACTOR);
|
|
77
|
-
var minHealthFactor = Math.floor((constants_1.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD *
|
|
126
|
+
var minHealthFactor = Math.floor((constants_1.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD *
|
|
127
|
+
(maxLeverageFactor + constants_1.LEVERAGE_DECIMALS)) /
|
|
78
128
|
maxLeverageFactor);
|
|
79
129
|
var result = borrowAmountPlusInterest
|
|
80
130
|
.mul(healthFactorPercentage - minHealthFactor)
|
package/lib/core/errors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
1
2
|
export interface MetamaskError {
|
|
2
3
|
code: number;
|
|
3
4
|
message: string;
|
|
@@ -24,3 +25,12 @@ export declare class PathNotFoundError extends Error {
|
|
|
24
25
|
export declare class AccountsInAlllCreditManagersError extends Error {
|
|
25
26
|
constructor();
|
|
26
27
|
}
|
|
28
|
+
export declare type OpenAccountErrorTypes = "insufficientPoolLiquidity" | "leverageGreaterMax" | "amountGreaterMax" | "amountLessMin";
|
|
29
|
+
export declare class OpenAccountError extends Error {
|
|
30
|
+
message: OpenAccountErrorTypes;
|
|
31
|
+
payload: {
|
|
32
|
+
amount: BigNumber;
|
|
33
|
+
};
|
|
34
|
+
constructor(errorType: OpenAccountErrorTypes, amount: BigNumber);
|
|
35
|
+
static isOpenAccountError(e: unknown): e is OpenAccountError;
|
|
36
|
+
}
|
package/lib/core/errors.js
CHANGED
|
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AccountsInAlllCreditManagersError = exports.PathNotFoundError = exports.UserHasNotAccountError = exports.CreditManagerNotExistsError = exports.PoolNotExistsError = exports.IncorrectEthAddressError = exports.NetworkError = void 0;
|
|
18
|
+
exports.OpenAccountError = exports.AccountsInAlllCreditManagersError = exports.PathNotFoundError = exports.UserHasNotAccountError = exports.CreditManagerNotExistsError = exports.PoolNotExistsError = exports.IncorrectEthAddressError = exports.NetworkError = void 0;
|
|
19
19
|
var NetworkError = /** @class */ (function (_super) {
|
|
20
20
|
__extends(NetworkError, _super);
|
|
21
21
|
function NetworkError() {
|
|
@@ -72,3 +72,18 @@ var AccountsInAlllCreditManagersError = /** @class */ (function (_super) {
|
|
|
72
72
|
return AccountsInAlllCreditManagersError;
|
|
73
73
|
}(Error));
|
|
74
74
|
exports.AccountsInAlllCreditManagersError = AccountsInAlllCreditManagersError;
|
|
75
|
+
var OpenAccountError = /** @class */ (function (_super) {
|
|
76
|
+
__extends(OpenAccountError, _super);
|
|
77
|
+
function OpenAccountError(errorType, amount) {
|
|
78
|
+
var _this = _super.call(this) || this;
|
|
79
|
+
Object.setPrototypeOf(_this, OpenAccountError.prototype);
|
|
80
|
+
_this.message = errorType;
|
|
81
|
+
_this.payload = { amount: amount };
|
|
82
|
+
return _this;
|
|
83
|
+
}
|
|
84
|
+
OpenAccountError.isOpenAccountError = function (e) {
|
|
85
|
+
return e instanceof OpenAccountError;
|
|
86
|
+
};
|
|
87
|
+
return OpenAccountError;
|
|
88
|
+
}(Error));
|
|
89
|
+
exports.OpenAccountError = OpenAccountError;
|
package/lib/core/events.js
CHANGED
|
@@ -298,16 +298,16 @@ var EventCMNewParameters = /** @class */ (function (_super) {
|
|
|
298
298
|
msg += "max amount: ".concat((0, formatter_1.formatBN)(this.prevMaxAmount, token.decimals), " => ").concat((0, formatter_1.formatBN)(this.maxAmount, token.decimals), " ").concat(token.symbol, ", ");
|
|
299
299
|
}
|
|
300
300
|
if (this.maxLeverage !== this.prevMaxLeverage) {
|
|
301
|
-
msg += "max leverage: ".concat(this.prevMaxLeverage /
|
|
301
|
+
msg += "max leverage: ".concat(this.prevMaxLeverage / constants_1.LEVERAGE_DECIMALS + 1, " => ").concat(this.maxLeverage / constants_1.LEVERAGE_DECIMALS + 1, ", ");
|
|
302
302
|
}
|
|
303
303
|
if (this.feeInterest !== this.prevFeeInterest) {
|
|
304
|
-
msg += "interest fee: ".concat(this.prevFeeInterest /
|
|
304
|
+
msg += "interest fee: ".concat(this.prevFeeInterest / constants_1.PERCENTAGE_DECIMALS, "% => ").concat(this.feeInterest / constants_1.PERCENTAGE_DECIMALS, "%, ");
|
|
305
305
|
}
|
|
306
306
|
if (this.feeLiquidation !== this.prevFeeLiquidation) {
|
|
307
|
-
msg += "liquidation fee: ".concat(this.prevFeeLiquidation /
|
|
307
|
+
msg += "liquidation fee: ".concat(this.prevFeeLiquidation / constants_1.PERCENTAGE_DECIMALS, "% => ").concat(this.feeLiquidation / constants_1.PERCENTAGE_DECIMALS, "%, ");
|
|
308
308
|
}
|
|
309
309
|
if (this.liquidationDiscount !== this.prevLiquidationDiscount) {
|
|
310
|
-
msg += "liquidation premium: ".concat(
|
|
310
|
+
msg += "liquidation premium: ".concat(constants_1.PERCENTAGE_DECIMALS - this.prevLiquidationDiscount / constants_1.PERCENTAGE_DECIMALS, "% => ").concat(constants_1.PERCENTAGE_DECIMALS - this.liquidationDiscount / constants_1.PERCENTAGE_DECIMALS, "%, ");
|
|
311
311
|
}
|
|
312
312
|
return msg.slice(0, msg.length - 2);
|
|
313
313
|
};
|
|
@@ -334,11 +334,11 @@ var EventTokenAllowed = /** @class */ (function (_super) {
|
|
|
334
334
|
var msg = "Credit manager ".concat((0, contractsRegister_1.getContractName)(this.creditManager), " updated ");
|
|
335
335
|
switch (this.status) {
|
|
336
336
|
case "NewToken":
|
|
337
|
-
return "".concat(msg, ": New token allowed: ").concat(token.symbol, ", liquidation threshold: ").concat(this.liquidityThreshold /
|
|
337
|
+
return "".concat(msg, ": New token allowed: ").concat(token.symbol, ", liquidation threshold: ").concat(this.liquidityThreshold / constants_1.PERCENTAGE_DECIMALS, "%");
|
|
338
338
|
case "Allowed":
|
|
339
|
-
return "".concat(msg, ": ").concat(token.symbol, " is allowed now, liquidation threshold: ").concat(this.liquidityThreshold /
|
|
339
|
+
return "".concat(msg, ": ").concat(token.symbol, " is allowed now, liquidation threshold: ").concat(this.liquidityThreshold / constants_1.PERCENTAGE_DECIMALS, "%");
|
|
340
340
|
case "LTUpdated":
|
|
341
|
-
return "".concat(msg, ": ").concat(token.symbol, " liquidation threshold: ").concat((this.prevLiquidationThreshold || 0) /
|
|
341
|
+
return "".concat(msg, ": ").concat(token.symbol, " liquidation threshold: ").concat((this.prevLiquidationThreshold || 0) / constants_1.PERCENTAGE_DECIMALS, " => ").concat(this.liquidityThreshold / constants_1.PERCENTAGE_DECIMALS, "%");
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
344
|
return EventTokenAllowed;
|
|
@@ -565,8 +565,8 @@ var EventNewWithdrawFee = /** @class */ (function (_super) {
|
|
|
565
565
|
}
|
|
566
566
|
EventNewWithdrawFee.prototype.toString = function (_) {
|
|
567
567
|
return this.prevFee === 0
|
|
568
|
-
? "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: withdraw fee was set to: ").concat(this.newFee /
|
|
569
|
-
: "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: withdraw fee was ").concat(this.newFee > this.prevFee ? "increased" : "decreased", ": ").concat(this.prevFee /
|
|
568
|
+
? "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: withdraw fee was set to: ").concat(this.newFee / constants_1.PERCENTAGE_DECIMALS, "%")
|
|
569
|
+
: "Pool ".concat((0, contractsRegister_1.getContractName)(this.pool), " updated: withdraw fee was ").concat(this.newFee > this.prevFee ? "increased" : "decreased", ": ").concat(this.prevFee / constants_1.PERCENTAGE_DECIMALS, "% => ").concat(this.newFee / constants_1.PERCENTAGE_DECIMALS, "%");
|
|
570
570
|
};
|
|
571
571
|
return EventNewWithdrawFee;
|
|
572
572
|
}(eventOrTx_1.EVMEvent));
|
package/lib/core/multicall.d.ts
CHANGED
package/lib/core/pool.d.ts
CHANGED
package/lib/core/pool.js
CHANGED
|
@@ -2,25 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PoolData = void 0;
|
|
4
4
|
var ethers_1 = require("ethers");
|
|
5
|
-
var types_1 = require("../types");
|
|
6
5
|
var formatter_1 = require("../utils/formatter");
|
|
6
|
+
var types_1 = require("../types");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
7
8
|
var PoolData = /** @class */ (function () {
|
|
8
9
|
function PoolData(payload) {
|
|
9
10
|
this.id = payload.addr;
|
|
10
11
|
this.address = payload.addr;
|
|
11
|
-
this.underlyingToken = payload.
|
|
12
|
+
this.underlyingToken = payload.underlying || "";
|
|
12
13
|
this.dieselToken = payload.dieselToken || "";
|
|
13
14
|
this.isWETH = payload.isWETH || false;
|
|
14
15
|
this.expectedLiquidity = ethers_1.BigNumber.from(payload.expectedLiquidity);
|
|
15
16
|
this.expectedLiquidityLimit = ethers_1.BigNumber.from(payload.expectedLiquidityLimit || 0);
|
|
16
17
|
this.availableLiquidity = ethers_1.BigNumber.from(payload.availableLiquidity);
|
|
17
18
|
this.totalBorrowed = ethers_1.BigNumber.from(payload.totalBorrowed);
|
|
18
|
-
this.depositAPY = (0, formatter_1.rayToNumber)(payload.depositAPY_RAY) *
|
|
19
|
-
this.borrowAPY = (0, formatter_1.rayToNumber)(payload.borrowAPY_RAY) *
|
|
19
|
+
this.depositAPY = (0, formatter_1.rayToNumber)(payload.depositAPY_RAY) * constants_1.PERCENTAGE_DECIMALS;
|
|
20
|
+
this.borrowAPY = (0, formatter_1.rayToNumber)(payload.borrowAPY_RAY) * constants_1.PERCENTAGE_DECIMALS;
|
|
20
21
|
this.borrowAPYRay = ethers_1.BigNumber.from(payload.borrowAPY_RAY);
|
|
21
22
|
this.dieselRate = (0, formatter_1.rayToNumber)(payload.dieselRate_RAY);
|
|
22
23
|
this.dieselRateRay = ethers_1.BigNumber.from(payload.dieselRate_RAY);
|
|
23
|
-
this.withdrawFee =
|
|
24
|
+
this.withdrawFee =
|
|
25
|
+
ethers_1.BigNumber.from(payload.withdrawFee).toNumber() / constants_1.PERCENTAGE_DECIMALS;
|
|
24
26
|
this.timestampLU = ethers_1.BigNumber.from(payload.timestampLU || 0);
|
|
25
27
|
this.cumulativeIndex_RAY = ethers_1.BigNumber.from(payload.cumulativeIndex_RAY || 0);
|
|
26
28
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.priceCalc = exports.PRICE_DECIMALS = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
exports.PRICE_DECIMALS = 1000;
|
|
6
|
+
var priceCalc = function (price, amount, token) {
|
|
7
|
+
var _a = (token || {}).decimals, decimals = _a === void 0 ? 18 : _a;
|
|
8
|
+
return amount
|
|
9
|
+
.mul(Math.floor(exports.PRICE_DECIMALS * price))
|
|
10
|
+
.div(ethers_1.BigNumber.from(10).pow(decimals));
|
|
11
|
+
};
|
|
12
|
+
exports.priceCalc = priceCalc;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface StrategyPayload {
|
|
2
|
+
apy?: number;
|
|
3
|
+
name: string;
|
|
4
|
+
lpToken: string;
|
|
5
|
+
pools: Array<string>;
|
|
6
|
+
unleveragableCollateral: Array<string>;
|
|
7
|
+
leveragableCollateral: Array<string>;
|
|
8
|
+
baseAssets: Array<string>;
|
|
9
|
+
}
|
|
10
|
+
interface PoolStats {
|
|
11
|
+
borrowRate: number;
|
|
12
|
+
}
|
|
13
|
+
declare type PoolList = Record<string, PoolStats>;
|
|
14
|
+
export declare class Strategy {
|
|
15
|
+
apy: number | undefined;
|
|
16
|
+
name: string;
|
|
17
|
+
lpToken: string;
|
|
18
|
+
pools: Array<string>;
|
|
19
|
+
unleveragableCollateral: Array<string>;
|
|
20
|
+
leveragableCollateral: Array<string>;
|
|
21
|
+
baseAssets: Array<string>;
|
|
22
|
+
constructor(payload: StrategyPayload);
|
|
23
|
+
roiMax(apy: number, maxLeverage: number, poolApy: PoolList): number;
|
|
24
|
+
overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
|
|
25
|
+
liquidationPrice(leverage: number, ltStrategy: number, ltCollateral: number, depositCollateral: string): number;
|
|
26
|
+
ltStrategyLP(maxLeverage: number): number;
|
|
27
|
+
maxLeverage(ltStrategyLP: number): number;
|
|
28
|
+
private roi;
|
|
29
|
+
private minBorrowApy;
|
|
30
|
+
private farmLev;
|
|
31
|
+
private inBaseAssets;
|
|
32
|
+
private inLeveragableAssets;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Strategy = void 0;
|
|
4
|
+
var constants_1 = require("../core/constants");
|
|
5
|
+
var Strategy = /** @class */ (function () {
|
|
6
|
+
function Strategy(payload) {
|
|
7
|
+
this.apy = payload.apy;
|
|
8
|
+
this.name = payload.name;
|
|
9
|
+
this.lpToken = payload.lpToken;
|
|
10
|
+
this.pools = payload.pools;
|
|
11
|
+
this.unleveragableCollateral = payload.unleveragableCollateral;
|
|
12
|
+
this.leveragableCollateral = payload.leveragableCollateral;
|
|
13
|
+
this.baseAssets = payload.baseAssets;
|
|
14
|
+
}
|
|
15
|
+
Strategy.prototype.roiMax = function (apy, maxLeverage, poolApy) {
|
|
16
|
+
var minApy = this.minBorrowApy(poolApy);
|
|
17
|
+
return this.roi(apy, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
|
|
18
|
+
};
|
|
19
|
+
Strategy.prototype.overallAPY = function (apy, leverage, depositCollateral, borrowAPY) {
|
|
20
|
+
var farmLev = this.farmLev(leverage, depositCollateral);
|
|
21
|
+
return this.roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
|
|
22
|
+
};
|
|
23
|
+
Strategy.prototype.liquidationPrice = function (leverage, ltStrategy, ltCollateral, depositCollateral) {
|
|
24
|
+
var farmLev = this.farmLev(leverage, depositCollateral);
|
|
25
|
+
return (1 -
|
|
26
|
+
(leverage - constants_1.LEVERAGE_DECIMALS - ltCollateral * (leverage - farmLev)) /
|
|
27
|
+
(ltStrategy * farmLev));
|
|
28
|
+
};
|
|
29
|
+
Strategy.prototype.ltStrategyLP = function (maxLeverage) {
|
|
30
|
+
return 1 - constants_1.LEVERAGE_DECIMALS / maxLeverage;
|
|
31
|
+
};
|
|
32
|
+
Strategy.prototype.maxLeverage = function (ltStrategyLP) {
|
|
33
|
+
var leverage = Math.floor(1 / (1 - ltStrategyLP));
|
|
34
|
+
return Math.floor(leverage * constants_1.LEVERAGE_DECIMALS);
|
|
35
|
+
};
|
|
36
|
+
Strategy.prototype.roi = function (apy, farmLev, debtLev, borrowAPY) {
|
|
37
|
+
return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
|
|
38
|
+
};
|
|
39
|
+
Strategy.prototype.minBorrowApy = function (poolApy) {
|
|
40
|
+
var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
|
|
41
|
+
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
42
|
+
};
|
|
43
|
+
Strategy.prototype.farmLev = function (leverage, depositCollateral) {
|
|
44
|
+
return this.inBaseAssets(depositCollateral) ||
|
|
45
|
+
this.inLeveragableAssets(depositCollateral)
|
|
46
|
+
? leverage
|
|
47
|
+
: leverage - constants_1.LEVERAGE_DECIMALS;
|
|
48
|
+
};
|
|
49
|
+
Strategy.prototype.inBaseAssets = function (depositCollateral) {
|
|
50
|
+
return this.baseAssets.some(function (c) { return c.toLowerCase() === depositCollateral.toLowerCase(); });
|
|
51
|
+
};
|
|
52
|
+
Strategy.prototype.inLeveragableAssets = function (depositCollateral) {
|
|
53
|
+
return this.leveragableCollateral.some(function (c) { return c.toLowerCase() === depositCollateral.toLowerCase(); });
|
|
54
|
+
};
|
|
55
|
+
return Strategy;
|
|
56
|
+
}());
|
|
57
|
+
exports.Strategy = Strategy;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from "./core/constants";
|
|
2
|
+
export * from "./core/price";
|
|
2
3
|
export * from "./core/creditAccount";
|
|
3
4
|
export * from "./core/creditManager";
|
|
4
5
|
export * from "./core/creditSession";
|
|
5
6
|
export * from "./contracts/contracts";
|
|
7
|
+
export * from "./core/eventOrTx";
|
|
6
8
|
export * from "./core/events";
|
|
7
9
|
export * from "./core/errors";
|
|
8
10
|
export * from "./core/pool";
|
|
@@ -25,6 +27,7 @@ export * from "./utils/events";
|
|
|
25
27
|
export * from "./utils/math";
|
|
26
28
|
export * from "./payload/graphPayload";
|
|
27
29
|
export * from "./types/index";
|
|
30
|
+
export * from "./core/strategy";
|
|
28
31
|
export type { IDataCompressor, IWETHGateway } from "./types";
|
|
29
32
|
export { TokenType } from "./tokens/tokenType";
|
|
30
33
|
export * from "./tokens/token";
|
|
@@ -35,8 +38,11 @@ export * from "./tokens/curveLP";
|
|
|
35
38
|
export * from "./tokens/gear";
|
|
36
39
|
export * from "./tokens/normal";
|
|
37
40
|
export * from "./tokens/yearn";
|
|
41
|
+
export * from "./apy/lidoAPY";
|
|
42
|
+
export * from "./apy/convexAPY";
|
|
38
43
|
export * from "./core/history";
|
|
39
|
-
export
|
|
44
|
+
export * from "./utils/multicall";
|
|
45
|
+
export * from "./utils/types";
|
|
40
46
|
export { callRepeater } from "./utils/repeater";
|
|
41
47
|
export { getContractName } from "./contracts/contractsRegister";
|
|
42
48
|
export { AdapterInterface } from "./contracts/adapters";
|
package/lib/index.js
CHANGED
|
@@ -14,12 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.SwapType = exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.
|
|
17
|
+
exports.SwapType = exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.TokenType = void 0;
|
|
18
18
|
__exportStar(require("./core/constants"), exports);
|
|
19
|
+
__exportStar(require("./core/price"), exports);
|
|
19
20
|
__exportStar(require("./core/creditAccount"), exports);
|
|
20
21
|
__exportStar(require("./core/creditManager"), exports);
|
|
21
22
|
__exportStar(require("./core/creditSession"), exports);
|
|
22
23
|
__exportStar(require("./contracts/contracts"), exports);
|
|
24
|
+
__exportStar(require("./core/eventOrTx"), exports);
|
|
23
25
|
__exportStar(require("./core/events"), exports);
|
|
24
26
|
__exportStar(require("./core/errors"), exports);
|
|
25
27
|
__exportStar(require("./core/pool"), exports);
|
|
@@ -42,6 +44,7 @@ __exportStar(require("./utils/events"), exports);
|
|
|
42
44
|
__exportStar(require("./utils/math"), exports);
|
|
43
45
|
__exportStar(require("./payload/graphPayload"), exports);
|
|
44
46
|
__exportStar(require("./types/index"), exports);
|
|
47
|
+
__exportStar(require("./core/strategy"), exports);
|
|
45
48
|
// Tokens
|
|
46
49
|
var tokenType_1 = require("./tokens/tokenType");
|
|
47
50
|
Object.defineProperty(exports, "TokenType", { enumerable: true, get: function () { return tokenType_1.TokenType; } });
|
|
@@ -53,9 +56,11 @@ __exportStar(require("./tokens/curveLP"), exports);
|
|
|
53
56
|
__exportStar(require("./tokens/gear"), exports);
|
|
54
57
|
__exportStar(require("./tokens/normal"), exports);
|
|
55
58
|
__exportStar(require("./tokens/yearn"), exports);
|
|
59
|
+
__exportStar(require("./apy/lidoAPY"), exports);
|
|
60
|
+
__exportStar(require("./apy/convexAPY"), exports);
|
|
56
61
|
__exportStar(require("./core/history"), exports);
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
__exportStar(require("./utils/multicall"), exports);
|
|
63
|
+
__exportStar(require("./utils/types"), exports);
|
|
59
64
|
var repeater_1 = require("./utils/repeater");
|
|
60
65
|
Object.defineProperty(exports, "callRepeater", { enumerable: true, get: function () { return repeater_1.callRepeater; } });
|
|
61
66
|
var contractsRegister_1 = require("./contracts/contractsRegister");
|
package/lib/pathfinder/path.js
CHANGED
|
@@ -145,7 +145,7 @@ var Path = /** @class */ (function () {
|
|
|
145
145
|
// TODO: Add checks for lenght
|
|
146
146
|
if (existingTokens.length === 0)
|
|
147
147
|
throw new Error("No tokens with balance >1");
|
|
148
|
-
nextToken = existingTokens
|
|
148
|
+
nextToken = existingTokens[0][0];
|
|
149
149
|
// Get balances and keep non-zero only
|
|
150
150
|
// Find token with highest priority
|
|
151
151
|
// Get token type of this token
|
package/lib/pathfinder/yVault.js
CHANGED
|
@@ -81,10 +81,13 @@ var YearnVaultPathFinder = /** @class */ (function () {
|
|
|
81
81
|
vault = vaultList[i];
|
|
82
82
|
vb = vaultBalances[vault];
|
|
83
83
|
p.balances[vb.token] = (p.balances[vb.token] || ethers_1.BigNumber.from(0)).add(ethers_1.BigNumber.from((vb === null || vb === void 0 ? void 0 : vb.balance) || 0).mul(prices[i]));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
// !!!!!!!!!
|
|
85
|
+
// p.calls.push({
|
|
86
|
+
// targetContract:
|
|
87
|
+
// p.creditManager.adapters[tokenDataByNetwork[p.networkType][vault]],
|
|
88
|
+
// callData:
|
|
89
|
+
// IYVault__factory.createInterface().encodeFunctionData("withdraw()")
|
|
90
|
+
// });
|
|
88
91
|
}
|
|
89
92
|
return [4 /*yield*/, p.withdrawTokens()];
|
|
90
93
|
case 2: return [2 /*return*/, _c.sent()];
|
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
isAllowed: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface CreditAccountDataPayload {
|
|
8
|
-
addr: string;
|
|
9
|
-
borrower: string;
|
|
10
|
-
inUse: boolean;
|
|
11
|
-
creditManager: string;
|
|
12
|
-
underlyingToken: string;
|
|
13
|
-
borrowedAmountPlusInterest: BigNumberish;
|
|
14
|
-
totalValue: BigNumberish;
|
|
15
|
-
healthFactor: BigNumberish;
|
|
16
|
-
borrowRate: BigNumberish;
|
|
17
|
-
balances?: Array<TokenBalancePayload>;
|
|
18
|
-
}
|
|
19
|
-
export interface CreditAccountDataExtendedPayload extends CreditAccountDataPayload {
|
|
20
|
-
repayAmount: BigNumberish;
|
|
21
|
-
liquidationAmount: BigNumberish;
|
|
22
|
-
canBeClosed?: boolean;
|
|
23
|
-
borrowedAmount: BigNumberish;
|
|
24
|
-
cumulativeIndexAtOpen: BigNumberish;
|
|
25
|
-
since: BigNumberish;
|
|
26
|
-
}
|
|
1
|
+
import { CreditAccountDataStructOutput } from "../types/contracts/core/DataCompressor";
|
|
2
|
+
export declare type TokenBalancePayload = CreditAccountDataStructOutput["balances"];
|
|
3
|
+
export declare type CreditAccountDataPayload = CreditAccountDataStructOutput;
|
|
4
|
+
export declare type CreditAccountDataExtendedPayload = CreditAccountDataStructOutput;
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
import { BigNumberish } from "ethers";
|
|
1
|
+
import { BigNumberish, BigNumber } from "ethers";
|
|
2
|
+
import { CreditManagerDataStructOutput } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
3
|
export interface AdapterPayload {
|
|
3
4
|
allowedContract: string;
|
|
4
5
|
adapter: string;
|
|
5
6
|
}
|
|
6
|
-
export
|
|
7
|
+
export declare type CreditManagerDataPayload = CreditManagerDataStructOutput;
|
|
8
|
+
export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
7
9
|
addr: string;
|
|
8
|
-
hasAccount?: boolean;
|
|
9
10
|
underlyingToken?: string;
|
|
10
|
-
isWETH
|
|
11
|
-
canBorrow
|
|
12
|
-
borrowRate
|
|
13
|
-
minAmount
|
|
14
|
-
maxAmount
|
|
15
|
-
maxLeverageFactor
|
|
16
|
-
availableLiquidity
|
|
17
|
-
allowedTokens
|
|
18
|
-
adapters?: Array<AdapterPayload>;
|
|
19
|
-
}
|
|
20
|
-
export interface CreditManagerStatPayload {
|
|
21
|
-
addr: string;
|
|
22
|
-
underlyingToken?: string;
|
|
23
|
-
isWETH?: boolean;
|
|
24
|
-
canBorrow?: boolean;
|
|
25
|
-
borrowRate?: BigNumberish;
|
|
26
|
-
minAmount?: BigNumberish;
|
|
27
|
-
maxAmount?: BigNumberish;
|
|
28
|
-
maxLeverageFactor?: BigNumberish;
|
|
29
|
-
availableLiquidity?: BigNumberish;
|
|
30
|
-
allowedTokens?: Array<string>;
|
|
11
|
+
isWETH: boolean;
|
|
12
|
+
canBorrow: boolean;
|
|
13
|
+
borrowRate: BigNumber;
|
|
14
|
+
minAmount: BigNumber;
|
|
15
|
+
maxAmount: BigNumber;
|
|
16
|
+
maxLeverageFactor: BigNumber;
|
|
17
|
+
availableLiquidity: BigNumber;
|
|
18
|
+
allowedTokens: Array<string>;
|
|
31
19
|
allowedContracts?: Array<string>;
|
|
32
20
|
uniqueUsers: number;
|
|
33
21
|
openedAccountsCount?: number;
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
addr: string;
|
|
4
|
-
underlyingToken: string;
|
|
5
|
-
dieselToken: string;
|
|
6
|
-
isWETH: boolean;
|
|
7
|
-
expectedLiquidity: BigNumberish;
|
|
8
|
-
expectedLiquidityLimit?: BigNumberish;
|
|
9
|
-
availableLiquidity: BigNumberish;
|
|
10
|
-
totalBorrowed: BigNumberish;
|
|
11
|
-
depositAPY_RAY: BigNumberish;
|
|
12
|
-
borrowAPY_RAY: BigNumberish;
|
|
13
|
-
dieselRate_RAY: BigNumberish;
|
|
14
|
-
withdrawFee: BigNumberish;
|
|
15
|
-
timestampLU?: BigNumberish;
|
|
16
|
-
cumulativeIndex_RAY?: BigNumberish;
|
|
17
|
-
}
|
|
1
|
+
import { PoolDataStructOutput } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
|
+
export declare type PoolDataPayload = PoolDataStructOutput;
|
package/lib/payload/pool.js
CHANGED