@gearbox-protocol/sdk 0.0.99 → 0.0.102
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 +104 -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 +16 -4
- package/lib/core/constants.d.ts +6 -0
- package/lib/core/constants.js +10 -4
- package/lib/core/creditAccount.d.ts +3 -1
- package/lib/core/creditAccount.js +31 -31
- 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 +2 -0
- package/lib/core/price.js +9 -0
- package/lib/core/strategy.d.ts +38 -0
- package/lib/core/strategy.js +56 -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 +5 -5
- package/lib/payload/creditAccount.d.ts +4 -26
- package/lib/payload/creditManager.d.ts +3 -25
- package/lib/payload/pool.d.ts +2 -17
- package/lib/payload/pool.js +0 -1
- package/lib/tokens/token.js +8 -8
- 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 +250 -0
- package/src/apy/lidoAPY.ts +88 -0
- package/src/config.ts +2 -1
- package/src/contracts/contracts.ts +69 -16
- package/src/contracts/contractsRegister.ts +19 -4
- package/src/core/constants.ts +10 -3
- package/src/core/creditAccount.ts +46 -37
- package/src/core/creditManager.ts +231 -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 +9 -0
- package/src/core/strategy.ts +130 -0
- package/src/index.ts +8 -1
- package/src/pathfinder/path.ts +154 -154
- package/src/pathfinder/yVault.ts +63 -62
- package/src/payload/creditAccount.ts +4 -26
- package/src/payload/creditManager.ts +4 -26
- package/src/payload/pool.ts +2 -19
- package/src/tokens/token.ts +14 -9
- 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
|
@@ -15,9 +15,10 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.CreditAccountDataExtended = exports.CreditAccountData = void 0;
|
|
18
|
+
exports.CreditAccountDataExtended = exports.tokensAbcComparator = exports.sortBalances = exports.CreditAccountData = void 0;
|
|
19
19
|
var ethers_1 = require("ethers");
|
|
20
20
|
var constants_1 = require("./constants");
|
|
21
|
+
var price_1 = require("./price");
|
|
21
22
|
var CreditAccountData = /** @class */ (function () {
|
|
22
23
|
function CreditAccountData(payload) {
|
|
23
24
|
var _this = this;
|
|
@@ -31,7 +32,7 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
31
32
|
this.borrower = payload.borrower;
|
|
32
33
|
this.inUse = payload.inUse;
|
|
33
34
|
this.creditManager = payload.creditManager;
|
|
34
|
-
this.underlyingToken = payload.
|
|
35
|
+
this.underlyingToken = payload.underlying;
|
|
35
36
|
this.borrowedAmountPlusInterest = ethers_1.BigNumber.from(payload.borrowedAmountPlusInterest);
|
|
36
37
|
this.totalValue = ethers_1.BigNumber.from(payload.totalValue);
|
|
37
38
|
this.healthFactor =
|
|
@@ -39,7 +40,7 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
39
40
|
this.borrowRate =
|
|
40
41
|
ethers_1.BigNumber.from(payload.borrowRate)
|
|
41
42
|
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
42
|
-
.mul(
|
|
43
|
+
.mul(constants_1.PERCENTAGE_DECIMALS)
|
|
43
44
|
.div(constants_1.RAY)
|
|
44
45
|
.toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
45
46
|
(payload.balances || []).forEach(function (b) {
|
|
@@ -53,34 +54,7 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
53
54
|
this.isDeleting = false;
|
|
54
55
|
}
|
|
55
56
|
CreditAccountData.prototype.balancesSorted = function (prices, tokens) {
|
|
56
|
-
|
|
57
|
-
var price = prices[addr] || 0;
|
|
58
|
-
var _a = (tokens[addr] || {}).decimals, decimals = _a === void 0 ? 18 : _a;
|
|
59
|
-
return amount
|
|
60
|
-
.mul(Math.floor(1000 * price))
|
|
61
|
-
.div(ethers_1.BigNumber.from(10).pow(decimals));
|
|
62
|
-
};
|
|
63
|
-
var tokensAbcComparator = function (t1, t2) {
|
|
64
|
-
var _a = (t1 || {}).symbol, symbol1 = _a === void 0 ? "" : _a;
|
|
65
|
-
var _b = (t2 || {}).symbol, symbol2 = _b === void 0 ? "" : _b;
|
|
66
|
-
return symbol1 > symbol2 ? 1 : -1;
|
|
67
|
-
};
|
|
68
|
-
var safeBalances = this.balances || [];
|
|
69
|
-
return Object.entries(safeBalances)
|
|
70
|
-
.sort(function (_a, _b) {
|
|
71
|
-
var addr1 = _a[0], amount1 = _a[1];
|
|
72
|
-
var addr2 = _b[0], amount2 = _b[1];
|
|
73
|
-
var addr1Lc = addr1.toLowerCase();
|
|
74
|
-
var addr2Lc = addr2.toLowerCase();
|
|
75
|
-
var price1 = priceCalc(addr1Lc, amount1);
|
|
76
|
-
var price2 = priceCalc(addr2Lc, amount2);
|
|
77
|
-
return price1.eq(price2)
|
|
78
|
-
? tokensAbcComparator(tokens[addr1Lc], tokens[addr2Lc])
|
|
79
|
-
: price1.gt(price2)
|
|
80
|
-
? -1
|
|
81
|
-
: 1;
|
|
82
|
-
})
|
|
83
|
-
.map(function (_a) {
|
|
57
|
+
return sortBalances(this.balances, prices, tokens).map(function (_a) {
|
|
84
58
|
var address = _a[0], balance = _a[1];
|
|
85
59
|
return ({ address: address, balance: balance });
|
|
86
60
|
});
|
|
@@ -88,6 +62,32 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
88
62
|
return CreditAccountData;
|
|
89
63
|
}());
|
|
90
64
|
exports.CreditAccountData = CreditAccountData;
|
|
65
|
+
function sortBalances(balances, prices, tokens) {
|
|
66
|
+
return Object.entries(balances).sort(function (_a, _b) {
|
|
67
|
+
var addr1 = _a[0], amount1 = _a[1];
|
|
68
|
+
var addr2 = _b[0], amount2 = _b[1];
|
|
69
|
+
var addr1Lc = addr1.toLowerCase();
|
|
70
|
+
var addr2Lc = addr2.toLowerCase();
|
|
71
|
+
var token1 = tokens[addr1Lc];
|
|
72
|
+
var token2 = tokens[addr2Lc];
|
|
73
|
+
var price1 = prices[addr1Lc] || constants_1.PRICE_DECIMALS;
|
|
74
|
+
var price2 = prices[addr2Lc] || constants_1.PRICE_DECIMALS;
|
|
75
|
+
var totalPrice1 = (0, price_1.calcTotalPrice)(price1, amount1, token1 === null || token1 === void 0 ? void 0 : token1.decimals);
|
|
76
|
+
var totalPrice2 = (0, price_1.calcTotalPrice)(price2, amount2, token2 === null || token2 === void 0 ? void 0 : token2.decimals);
|
|
77
|
+
return totalPrice1.eq(totalPrice2)
|
|
78
|
+
? tokensAbcComparator(token1, token2)
|
|
79
|
+
: totalPrice1.gt(totalPrice2)
|
|
80
|
+
? -1
|
|
81
|
+
: 1;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.sortBalances = sortBalances;
|
|
85
|
+
function tokensAbcComparator(t1, t2) {
|
|
86
|
+
var _a = (t1 || {}).symbol, symbol1 = _a === void 0 ? "" : _a;
|
|
87
|
+
var _b = (t2 || {}).symbol, symbol2 = _b === void 0 ? "" : _b;
|
|
88
|
+
return symbol1 > symbol2 ? 1 : -1;
|
|
89
|
+
}
|
|
90
|
+
exports.tokensAbcComparator = tokensAbcComparator;
|
|
91
91
|
var CreditAccountDataExtended = /** @class */ (function (_super) {
|
|
92
92
|
__extends(CreditAccountDataExtended, _super);
|
|
93
93
|
function CreditAccountDataExtended(payload) {
|
|
@@ -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()] = ethers_1.BigNumber.from(threshold);
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
63
|
+
this.version = ethers_1.BigNumber.from(payload.version || 1).toNumber();
|
|
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,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcTotalPrice = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var calcTotalPrice = function (price, amount, decimals) {
|
|
6
|
+
if (decimals === void 0) { decimals = 18; }
|
|
7
|
+
return amount.mul(price).div(ethers_1.BigNumber.from(10).pow(decimals));
|
|
8
|
+
};
|
|
9
|
+
exports.calcTotalPrice = calcTotalPrice;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
export interface StrategyPayload {
|
|
3
|
+
apy?: number;
|
|
4
|
+
name: string;
|
|
5
|
+
lpToken: string;
|
|
6
|
+
pools: Array<string>;
|
|
7
|
+
unleveragableCollateral: Array<string>;
|
|
8
|
+
leveragableCollateral: Array<string>;
|
|
9
|
+
baseAssets: Array<string>;
|
|
10
|
+
}
|
|
11
|
+
interface PoolStats {
|
|
12
|
+
borrowRate: number;
|
|
13
|
+
}
|
|
14
|
+
declare type PoolList = Record<string, PoolStats>;
|
|
15
|
+
interface TokenDescription {
|
|
16
|
+
price: BigNumber;
|
|
17
|
+
amount: BigNumber;
|
|
18
|
+
decimals: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare class Strategy {
|
|
21
|
+
apy: number | undefined;
|
|
22
|
+
name: string;
|
|
23
|
+
lpToken: string;
|
|
24
|
+
pools: Array<string>;
|
|
25
|
+
unleveragableCollateral: Array<string>;
|
|
26
|
+
leveragableCollateral: Array<string>;
|
|
27
|
+
baseAssets: Array<string>;
|
|
28
|
+
constructor(payload: StrategyPayload);
|
|
29
|
+
maxAPY(apy: number, maxLeverage: number, poolApy: PoolList): number;
|
|
30
|
+
overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
|
|
31
|
+
liquidationPrice(borrowed: TokenDescription, collateral: TokenDescription, lp: TokenDescription, ltCollateral: BigNumber): BigNumber;
|
|
32
|
+
private roi;
|
|
33
|
+
private minBorrowApy;
|
|
34
|
+
private farmLev;
|
|
35
|
+
private inBaseAssets;
|
|
36
|
+
private inLeveragableAssets;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Strategy = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var constants_1 = require("../core/constants");
|
|
6
|
+
var price_1 = require("../core/price");
|
|
7
|
+
var Strategy = /** @class */ (function () {
|
|
8
|
+
function Strategy(payload) {
|
|
9
|
+
this.apy = payload.apy;
|
|
10
|
+
this.name = payload.name;
|
|
11
|
+
this.lpToken = payload.lpToken;
|
|
12
|
+
this.pools = payload.pools;
|
|
13
|
+
this.unleveragableCollateral = payload.unleveragableCollateral;
|
|
14
|
+
this.leveragableCollateral = payload.leveragableCollateral;
|
|
15
|
+
this.baseAssets = payload.baseAssets;
|
|
16
|
+
}
|
|
17
|
+
Strategy.prototype.maxAPY = function (apy, maxLeverage, poolApy) {
|
|
18
|
+
var minApy = this.minBorrowApy(poolApy);
|
|
19
|
+
return this.roi(apy, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
|
|
20
|
+
};
|
|
21
|
+
Strategy.prototype.overallAPY = function (apy, leverage, depositCollateral, borrowAPY) {
|
|
22
|
+
var farmLev = this.farmLev(leverage, depositCollateral);
|
|
23
|
+
return this.roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
|
|
24
|
+
};
|
|
25
|
+
Strategy.prototype.liquidationPrice = function (borrowed, collateral, lp, ltCollateral) {
|
|
26
|
+
var borrowedMoney = (0, price_1.calcTotalPrice)(borrowed.price, borrowed.amount, borrowed.decimals);
|
|
27
|
+
var collateralMoney = (0, price_1.calcTotalPrice)(collateral.price, collateral.amount, collateral.decimals)
|
|
28
|
+
.mul(ltCollateral)
|
|
29
|
+
.div(constants_1.PERCENTAGE_FACTOR);
|
|
30
|
+
var lpMoney = (0, price_1.calcTotalPrice)(lp.price, lp.amount, lp.decimals);
|
|
31
|
+
return lpMoney.gt(0)
|
|
32
|
+
? borrowedMoney.sub(collateralMoney).mul(constants_1.WAD).div(lpMoney)
|
|
33
|
+
: ethers_1.BigNumber.from(0);
|
|
34
|
+
};
|
|
35
|
+
Strategy.prototype.roi = function (apy, farmLev, debtLev, borrowAPY) {
|
|
36
|
+
return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
|
|
37
|
+
};
|
|
38
|
+
Strategy.prototype.minBorrowApy = function (poolApy) {
|
|
39
|
+
var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
|
|
40
|
+
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
41
|
+
};
|
|
42
|
+
Strategy.prototype.farmLev = function (leverage, depositCollateral) {
|
|
43
|
+
return this.inBaseAssets(depositCollateral) ||
|
|
44
|
+
this.inLeveragableAssets(depositCollateral)
|
|
45
|
+
? leverage
|
|
46
|
+
: leverage - constants_1.LEVERAGE_DECIMALS;
|
|
47
|
+
};
|
|
48
|
+
Strategy.prototype.inBaseAssets = function (depositCollateral) {
|
|
49
|
+
return this.baseAssets.some(function (c) { return c.toLowerCase() === depositCollateral.toLowerCase(); });
|
|
50
|
+
};
|
|
51
|
+
Strategy.prototype.inLeveragableAssets = function (depositCollateral) {
|
|
52
|
+
return this.leveragableCollateral.some(function (c) { return c.toLowerCase() === depositCollateral.toLowerCase(); });
|
|
53
|
+
};
|
|
54
|
+
return Strategy;
|
|
55
|
+
}());
|
|
56
|
+
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
|
@@ -51,7 +51,7 @@ var YearnVaultPathFinder = /** @class */ (function () {
|
|
|
51
51
|
}
|
|
52
52
|
YearnVaultPathFinder.prototype.findWithdrawPaths = function (p) {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
var vaultBalances, _i, _a, _b, yVault, tokenData, currentBalance, vaultList, multicallData, prices, i, vault, vb;
|
|
54
|
+
var vaultBalances, _i, _a, _b, yVault, tokenData, currentBalance, vaultList, multicallData, prices, i, vault, vb, tokenAddress, adapterAddress, callData;
|
|
55
55
|
return __generator(this, function (_c) {
|
|
56
56
|
switch (_c.label) {
|
|
57
57
|
case 0:
|
|
@@ -81,10 +81,10 @@ 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
|
-
p.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
84
|
+
tokenAddress = token_1.tokenDataByNetwork[p.networkType][vault];
|
|
85
|
+
adapterAddress = p.creditManager.adapters[tokenAddress];
|
|
86
|
+
callData = types_1.IYVault__factory.createInterface().encodeFunctionData("withdraw()");
|
|
87
|
+
p.calls.push({ target: adapterAddress, callData: callData });
|
|
88
88
|
}
|
|
89
89
|
return [4 /*yield*/, p.withdrawTokens()];
|
|
90
90
|
case 2: return [2 /*return*/, _c.sent()];
|