@gearbox-protocol/sdk 0.0.101 → 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.js +4 -4
- package/lib/apy/lidoAPY.js +30 -23
- package/lib/contracts/contractsRegister.js +13 -1
- package/lib/core/constants.d.ts +4 -2
- package/lib/core/constants.js +7 -5
- package/lib/core/creditAccount.d.ts +2 -2
- package/lib/core/creditAccount.js +7 -8
- package/lib/core/creditManager.js +3 -3
- package/lib/core/price.d.ts +1 -3
- package/lib/core/price.js +5 -8
- package/lib/core/strategy.d.ts +8 -4
- package/lib/core/strategy.js +12 -13
- package/lib/pathfinder/yVault.js +5 -8
- package/lib/payload/creditAccount.d.ts +4 -4
- package/lib/payload/creditManager.d.ts +3 -13
- package/lib/payload/pool.d.ts +2 -2
- package/lib/tokens/token.js +4 -4
- package/package.json +1 -1
- package/src/apy/convexAPY.ts +7 -6
- package/src/apy/lidoAPY.ts +25 -18
- package/src/contracts/contractsRegister.ts +16 -1
- package/src/core/constants.ts +7 -4
- package/src/core/creditAccount.ts +16 -13
- package/src/core/creditManager.ts +4 -3
- package/src/core/price.ts +4 -11
- package/src/core/strategy.ts +30 -23
- package/src/pathfinder/yVault.ts +7 -7
- package/src/payload/creditAccount.ts +4 -4
- package/src/payload/creditManager.ts +3 -13
- package/src/payload/pool.ts +2 -2
- package/src/tokens/token.ts +4 -4
package/lib/apy/convexAPY.js
CHANGED
|
@@ -92,8 +92,8 @@ function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
|
92
92
|
crvPerUnderlying = crvPerSecond.mul(constants_1.WAD).div(virtualSupply);
|
|
93
93
|
crvPerYear = crvPerUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
94
94
|
cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
|
|
95
|
-
crvAPY = crvPerYear.mul(cvxPrice).div(constants_1.
|
|
96
|
-
cvxAPY = cvxPerYear.mul(crvPrice).div(constants_1.
|
|
95
|
+
crvAPY = crvPerYear.mul(cvxPrice).div(constants_1.PRICE_DECIMALS);
|
|
96
|
+
cvxAPY = cvxPerYear.mul(crvPrice).div(constants_1.PRICE_DECIMALS);
|
|
97
97
|
return [4 /*yield*/, Promise.all(extraPoolAddresses.map(function (_, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
98
98
|
var extraRewardSymbol, extraPoolRate, perUnderlying, perYear, extraPrise, extraAPY;
|
|
99
99
|
return __generator(this, function (_a) {
|
|
@@ -102,7 +102,7 @@ function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
|
102
102
|
perUnderlying = extraPoolRate.mul(constants_1.WAD).div(virtualSupply);
|
|
103
103
|
perYear = perUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
104
104
|
extraPrise = getTokenPrice(tokenList[extraRewardSymbol]);
|
|
105
|
-
extraAPY = perYear.mul(extraPrise).div(constants_1.
|
|
105
|
+
extraAPY = perYear.mul(extraPrise).div(constants_1.PRICE_DECIMALS);
|
|
106
106
|
return [2 /*return*/, extraAPY];
|
|
107
107
|
});
|
|
108
108
|
}); }))];
|
|
@@ -190,7 +190,7 @@ function getCurveBaseApy(curveLPToken) {
|
|
|
190
190
|
case 2:
|
|
191
191
|
result = _b.sent();
|
|
192
192
|
_a = (result.data.apys[poolName] || {}).baseApy, baseApy = _a === void 0 ? 0 : _a;
|
|
193
|
-
return [2 /*return*/, (0, formatter_1.toBN)((baseApy / RESPONSE_DECIMALS).toString(), constants_1.
|
|
193
|
+
return [2 /*return*/, (0, formatter_1.toBN)((baseApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW)];
|
|
194
194
|
case 3:
|
|
195
195
|
e_1 = _b.sent();
|
|
196
196
|
return [2 /*return*/, ethers_1.BigNumber.from(0)];
|
package/lib/apy/lidoAPY.js
CHANGED
|
@@ -38,15 +38,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.LIDO_FEE_DECIMALS = exports.getLidoApy = void 0;
|
|
40
40
|
var multicall_1 = require("../utils/multicall");
|
|
41
|
+
var contracts_1 = require("../contracts/contracts");
|
|
42
|
+
var token_1 = require("../tokens/token");
|
|
41
43
|
var constants_1 = require("../core/constants");
|
|
42
44
|
var types_1 = require("../types");
|
|
43
|
-
var lidoOracleAddress =
|
|
44
|
-
|
|
45
|
-
Kovan: ""
|
|
46
|
-
};
|
|
45
|
+
var lidoOracleAddress = contracts_1.contractParams.LIDO_STETH_GATEWAY
|
|
46
|
+
.oracle;
|
|
47
47
|
var lidoStEthAddress = {
|
|
48
|
-
Mainnet:
|
|
49
|
-
Kovan:
|
|
48
|
+
Mainnet: token_1.tokenDataByNetwork.Mainnet.STETH,
|
|
49
|
+
Kovan: token_1.tokenDataByNetwork.Kovan.STETH
|
|
50
50
|
};
|
|
51
51
|
function getLidoApy(provider, networkType) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -60,7 +60,7 @@ function getLidoApy(provider, networkType) {
|
|
|
60
60
|
if (!lidoStEthAddress[networkType]) {
|
|
61
61
|
throw "No Lido stETH found on current network: ".concat(networkType);
|
|
62
62
|
}
|
|
63
|
-
return [4 /*yield*/, geLidoData(lidoOracleAddress[networkType], lidoStEthAddress[networkType], provider)];
|
|
63
|
+
return [4 /*yield*/, geLidoData(lidoOracleAddress[networkType], lidoStEthAddress[networkType], provider, networkType)];
|
|
64
64
|
case 1:
|
|
65
65
|
_a = _c.sent(), _b = _a[0], postTotalPooledEther = _b.postTotalPooledEther, preTotalPooledEther = _b.preTotalPooledEther, timeElapsed = _b.timeElapsed, fee = _a[1];
|
|
66
66
|
lidoAPRRay = postTotalPooledEther
|
|
@@ -74,23 +74,30 @@ function getLidoApy(provider, networkType) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
exports.getLidoApy = getLidoApy;
|
|
77
|
-
function geLidoData(lidoOracleAddress, stETHAddress, provider) {
|
|
77
|
+
function geLidoData(lidoOracleAddress, stETHAddress, provider, network) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
var calls;
|
|
80
|
-
return __generator(this, function (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
79
|
+
var calls, _a, stats, _b, fee;
|
|
80
|
+
return __generator(this, function (_c) {
|
|
81
|
+
switch (_c.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
calls = [
|
|
84
|
+
{
|
|
85
|
+
address: lidoOracleAddress,
|
|
86
|
+
interface: types_1.ILidoOracle__factory.createInterface(),
|
|
87
|
+
method: "getLastCompletedReportDelta()"
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
if (network !== "Kovan")
|
|
91
|
+
calls.push({
|
|
92
|
+
address: stETHAddress,
|
|
93
|
+
interface: types_1.IstETH__factory.createInterface(),
|
|
94
|
+
method: "getFee()"
|
|
95
|
+
});
|
|
96
|
+
return [4 /*yield*/, (0, multicall_1.multicall)(calls, provider)];
|
|
97
|
+
case 1:
|
|
98
|
+
_a = _c.sent(), stats = _a[0], _b = _a[1], fee = _b === void 0 ? Math.floor(exports.LIDO_FEE_DECIMALS / 10) : _b;
|
|
99
|
+
return [2 /*return*/, [stats, fee]];
|
|
100
|
+
}
|
|
94
101
|
});
|
|
95
102
|
});
|
|
96
103
|
}
|
|
@@ -38,10 +38,22 @@ exports.deployedContracts = {
|
|
|
38
38
|
"0xe04b4db67127d1930D36f16B51653120C4285708": "WBTC",
|
|
39
39
|
"0x600073357c29d169aAF3E543A4519749830553F1": "WETH",
|
|
40
40
|
"0xdBAd1361d9A03B81Be8D3a54Ef0dc9e39a1bA5b3": "USDC",
|
|
41
|
-
"0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI"
|
|
41
|
+
"0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI",
|
|
42
42
|
// [YEARN_DAI_VAULT_KOVAN_MOCK]: "Yearn DAI",
|
|
43
43
|
// [YEARN_USDC_VAULT_KOVAN_MOCK]: "Yearn USDC",
|
|
44
44
|
// [SUSHISWAP_KOVAN]: "Sushiswap"
|
|
45
|
+
"0x94cd5F09727ae04d7D6fd36A9c9DD96D0d54646B": "DAI",
|
|
46
|
+
"0x53B4a7389EA369a9299DfF524f916EC3cB77ffF4": "USDC",
|
|
47
|
+
"0xE6631f7b18744651A385a02ea2C89634d20D7819": "WETH",
|
|
48
|
+
"0x4d2cBA0E43Ad3B3E1C3B1922fe6E8e910b8C3ae0": "WBTC",
|
|
49
|
+
"0x6Ae9Ed829AF469Df9526FA7443E876bfaBC79eff": "DAI V2",
|
|
50
|
+
"0x8E0a874E3475de1C16490E386b7E2904CdC03086": "USDC V2",
|
|
51
|
+
"0x816a74B75D60839247C848518545fb17cedDC460": "WETH V2",
|
|
52
|
+
// pools
|
|
53
|
+
"0xA7b1C8f322596C40A04dBd3DffaE37a0849B8b59": "DAI",
|
|
54
|
+
"0xb8ecDB926F07FCbd870eafE72d116413A0BEb236": "USDC",
|
|
55
|
+
"0xAda6b2747295b2ba6ba52ce2d0D5e681D25D63D8": "WETH",
|
|
56
|
+
"0x85c54CCCf27466eEa1C74a73F75CbE385C271EE4": "WBTC"
|
|
45
57
|
};
|
|
46
58
|
var contractNames = Object.entries(contracts_1.contractsByAddress).reduce(function (acc, _a) {
|
|
47
59
|
var _b;
|
package/lib/core/constants.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ export declare const KOVAN_NETWORK = 42;
|
|
|
5
5
|
export declare const LOCAL_NETWORK = 1337;
|
|
6
6
|
export declare type NetworkType = "Mainnet" | "Kovan";
|
|
7
7
|
export declare const getNetworkType: (chainId: number) => NetworkType;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const RAY_DECIMALS_POW = 27;
|
|
9
9
|
export declare const RAY: BigNumber;
|
|
10
10
|
export declare const halfRAY: BigNumber;
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const WAD_DECIMALS_POW = 18;
|
|
12
12
|
export declare const WAD: BigNumber;
|
|
13
|
+
export declare const PRICE_DECIMALS_POW = 8;
|
|
14
|
+
export declare const PRICE_DECIMALS: BigNumber;
|
|
13
15
|
export declare const SECONDS_PER_YEAR: number;
|
|
14
16
|
export declare const PERCENTAGE_DECIMALS = 100;
|
|
15
17
|
export declare const PERCENTAGE_FACTOR = 10000;
|
package/lib/core/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ADDRESS_0x0 = exports.SLIPPAGE_DECIMALS = exports.LEVERAGE_DECIMALS = exports.timeRanges = exports.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = exports.LIQUIDATION_DISCOUNTED_SUM = exports.PERCENTAGE_FACTOR = exports.PERCENTAGE_DECIMALS = exports.SECONDS_PER_YEAR = exports.WAD = exports.
|
|
3
|
+
exports.ADDRESS_0x0 = exports.SLIPPAGE_DECIMALS = exports.LEVERAGE_DECIMALS = exports.timeRanges = exports.UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = exports.LIQUIDATION_DISCOUNTED_SUM = exports.PERCENTAGE_FACTOR = exports.PERCENTAGE_DECIMALS = exports.SECONDS_PER_YEAR = exports.PRICE_DECIMALS = exports.PRICE_DECIMALS_POW = exports.WAD = exports.WAD_DECIMALS_POW = exports.halfRAY = exports.RAY = exports.RAY_DECIMALS_POW = exports.getNetworkType = exports.LOCAL_NETWORK = exports.KOVAN_NETWORK = exports.MAINNET_NETWORK = exports.MAX_INT = void 0;
|
|
4
4
|
var ethers_1 = require("ethers");
|
|
5
5
|
exports.MAX_INT = ethers_1.BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
6
6
|
exports.MAINNET_NETWORK = 1;
|
|
@@ -18,11 +18,13 @@ var getNetworkType = function (chainId) {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
exports.getNetworkType = getNetworkType;
|
|
21
|
-
exports.
|
|
22
|
-
exports.RAY = ethers_1.BigNumber.from(10).pow(exports.
|
|
21
|
+
exports.RAY_DECIMALS_POW = 27;
|
|
22
|
+
exports.RAY = ethers_1.BigNumber.from(10).pow(exports.RAY_DECIMALS_POW);
|
|
23
23
|
exports.halfRAY = exports.RAY.div(2);
|
|
24
|
-
exports.
|
|
25
|
-
exports.WAD = ethers_1.BigNumber.from(10).pow(exports.
|
|
24
|
+
exports.WAD_DECIMALS_POW = 18;
|
|
25
|
+
exports.WAD = ethers_1.BigNumber.from(10).pow(exports.WAD_DECIMALS_POW);
|
|
26
|
+
exports.PRICE_DECIMALS_POW = 8;
|
|
27
|
+
exports.PRICE_DECIMALS = ethers_1.BigNumber.from(10).pow(exports.PRICE_DECIMALS_POW);
|
|
26
28
|
exports.SECONDS_PER_YEAR = 365 * 24 * 3600;
|
|
27
29
|
exports.PERCENTAGE_DECIMALS = 100;
|
|
28
30
|
exports.PERCENTAGE_FACTOR = 1e4;
|
|
@@ -23,9 +23,9 @@ export declare class CreditAccountData {
|
|
|
23
23
|
isDeleting: boolean;
|
|
24
24
|
readonly version: number;
|
|
25
25
|
constructor(payload: CreditAccountDataPayload);
|
|
26
|
-
balancesSorted(prices: Record<string,
|
|
26
|
+
balancesSorted(prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<Balance>;
|
|
27
27
|
}
|
|
28
|
-
export declare function sortBalances(balances: Record<string, BigNumber>, prices: Record<string,
|
|
28
|
+
export declare function sortBalances(balances: Record<string, BigNumber>, prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): [string, BigNumber][];
|
|
29
29
|
export declare function tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1;
|
|
30
30
|
export declare class CreditAccountDataExtended extends CreditAccountData {
|
|
31
31
|
readonly repayAmount: BigNumber;
|
|
@@ -54,8 +54,7 @@ var CreditAccountData = /** @class */ (function () {
|
|
|
54
54
|
this.isDeleting = false;
|
|
55
55
|
}
|
|
56
56
|
CreditAccountData.prototype.balancesSorted = function (prices, tokens) {
|
|
57
|
-
|
|
58
|
-
return sortBalances(safeBalances, prices, tokens).map(function (_a) {
|
|
57
|
+
return sortBalances(this.balances, prices, tokens).map(function (_a) {
|
|
59
58
|
var address = _a[0], balance = _a[1];
|
|
60
59
|
return ({ address: address, balance: balance });
|
|
61
60
|
});
|
|
@@ -71,13 +70,13 @@ function sortBalances(balances, prices, tokens) {
|
|
|
71
70
|
var addr2Lc = addr2.toLowerCase();
|
|
72
71
|
var token1 = tokens[addr1Lc];
|
|
73
72
|
var token2 = tokens[addr2Lc];
|
|
74
|
-
var price1 = prices[addr1Lc] ||
|
|
75
|
-
var price2 = prices[addr2Lc] ||
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
return
|
|
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)
|
|
79
78
|
? tokensAbcComparator(token1, token2)
|
|
80
|
-
:
|
|
79
|
+
: totalPrice1.gt(totalPrice2)
|
|
81
80
|
? -1
|
|
82
81
|
: 1;
|
|
83
82
|
});
|
|
@@ -54,13 +54,13 @@ var CreditManagerData = /** @class */ (function () {
|
|
|
54
54
|
var allowedContract = _a.allowedContract, adapter = _a.adapter;
|
|
55
55
|
return (__assign(__assign({}, acc), (_b = {}, _b[allowedContract] = adapter, _b)));
|
|
56
56
|
}, {});
|
|
57
|
-
this.liquidationThresholds = payload.liquidationThresholds.reduce(function (acc, threshold, index) {
|
|
57
|
+
this.liquidationThresholds = (payload.liquidationThresholds || []).reduce(function (acc, threshold, index) {
|
|
58
58
|
var address = payload.collateralTokens[index];
|
|
59
59
|
if (address)
|
|
60
|
-
acc[address.toLowerCase()] = threshold;
|
|
60
|
+
acc[address.toLowerCase()] = ethers_1.BigNumber.from(threshold);
|
|
61
61
|
return acc;
|
|
62
62
|
}, {});
|
|
63
|
-
this.version = payload.version || 1;
|
|
63
|
+
this.version = ethers_1.BigNumber.from(payload.version || 1).toNumber();
|
|
64
64
|
this.creditFacade = payload.creditFacade || "";
|
|
65
65
|
this.isDegenMode = payload.isDegenMode || false;
|
|
66
66
|
this.degenNFT = payload.degenNFT || "";
|
package/lib/core/price.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
-
|
|
3
|
-
export declare const PRICE_DECIMALS = 1000;
|
|
4
|
-
export declare const priceCalc: (price: number, amount: BigNumber, token: TokenData | undefined) => BigNumber;
|
|
2
|
+
export declare const calcTotalPrice: (price: BigNumber, amount: BigNumber, decimals?: number) => BigNumber;
|
package/lib/core/price.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.calcTotalPrice = void 0;
|
|
4
4
|
var ethers_1 = require("ethers");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return amount
|
|
9
|
-
.mul(Math.floor(exports.PRICE_DECIMALS * price))
|
|
10
|
-
.div(ethers_1.BigNumber.from(10).pow(decimals));
|
|
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));
|
|
11
8
|
};
|
|
12
|
-
exports.
|
|
9
|
+
exports.calcTotalPrice = calcTotalPrice;
|
package/lib/core/strategy.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
1
2
|
export interface StrategyPayload {
|
|
2
3
|
apy?: number;
|
|
3
4
|
name: string;
|
|
@@ -11,6 +12,11 @@ interface PoolStats {
|
|
|
11
12
|
borrowRate: number;
|
|
12
13
|
}
|
|
13
14
|
declare type PoolList = Record<string, PoolStats>;
|
|
15
|
+
interface TokenDescription {
|
|
16
|
+
price: BigNumber;
|
|
17
|
+
amount: BigNumber;
|
|
18
|
+
decimals: number | undefined;
|
|
19
|
+
}
|
|
14
20
|
export declare class Strategy {
|
|
15
21
|
apy: number | undefined;
|
|
16
22
|
name: string;
|
|
@@ -20,11 +26,9 @@ export declare class Strategy {
|
|
|
20
26
|
leveragableCollateral: Array<string>;
|
|
21
27
|
baseAssets: Array<string>;
|
|
22
28
|
constructor(payload: StrategyPayload);
|
|
23
|
-
|
|
29
|
+
maxAPY(apy: number, maxLeverage: number, poolApy: PoolList): number;
|
|
24
30
|
overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
|
|
25
|
-
liquidationPrice(
|
|
26
|
-
ltStrategyLP(maxLeverage: number): number;
|
|
27
|
-
maxLeverage(ltStrategyLP: number): number;
|
|
31
|
+
liquidationPrice(borrowed: TokenDescription, collateral: TokenDescription, lp: TokenDescription, ltCollateral: BigNumber): BigNumber;
|
|
28
32
|
private roi;
|
|
29
33
|
private minBorrowApy;
|
|
30
34
|
private farmLev;
|
package/lib/core/strategy.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Strategy = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
4
5
|
var constants_1 = require("../core/constants");
|
|
6
|
+
var price_1 = require("../core/price");
|
|
5
7
|
var Strategy = /** @class */ (function () {
|
|
6
8
|
function Strategy(payload) {
|
|
7
9
|
this.apy = payload.apy;
|
|
@@ -12,7 +14,7 @@ var Strategy = /** @class */ (function () {
|
|
|
12
14
|
this.leveragableCollateral = payload.leveragableCollateral;
|
|
13
15
|
this.baseAssets = payload.baseAssets;
|
|
14
16
|
}
|
|
15
|
-
Strategy.prototype.
|
|
17
|
+
Strategy.prototype.maxAPY = function (apy, maxLeverage, poolApy) {
|
|
16
18
|
var minApy = this.minBorrowApy(poolApy);
|
|
17
19
|
return this.roi(apy, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
|
|
18
20
|
};
|
|
@@ -20,18 +22,15 @@ var Strategy = /** @class */ (function () {
|
|
|
20
22
|
var farmLev = this.farmLev(leverage, depositCollateral);
|
|
21
23
|
return this.roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
|
|
22
24
|
};
|
|
23
|
-
Strategy.prototype.liquidationPrice = function (
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Strategy.prototype.maxLeverage = function (ltStrategyLP) {
|
|
33
|
-
var leverage = Math.floor(1 / (1 - ltStrategyLP));
|
|
34
|
-
return Math.floor(leverage * constants_1.LEVERAGE_DECIMALS);
|
|
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);
|
|
35
34
|
};
|
|
36
35
|
Strategy.prototype.roi = function (apy, farmLev, debtLev, borrowAPY) {
|
|
37
36
|
return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
|
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,13 +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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// callData:
|
|
89
|
-
// IYVault__factory.createInterface().encodeFunctionData("withdraw()")
|
|
90
|
-
// });
|
|
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 });
|
|
91
88
|
}
|
|
92
89
|
return [4 /*yield*/, p.withdrawTokens()];
|
|
93
90
|
case 2: return [2 /*return*/, _c.sent()];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type TokenBalancePayload =
|
|
3
|
-
export declare type CreditAccountDataPayload =
|
|
4
|
-
export declare type CreditAccountDataExtendedPayload =
|
|
1
|
+
import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
|
|
2
|
+
export declare type TokenBalancePayload = CreditAccountDataStruct["balances"];
|
|
3
|
+
export declare type CreditAccountDataPayload = CreditAccountDataStruct;
|
|
4
|
+
export declare type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import { BigNumberish
|
|
2
|
-
import {
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { CreditManagerDataStruct } 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 = CreditManagerDataStruct;
|
|
8
8
|
export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
9
|
-
addr: string;
|
|
10
|
-
underlyingToken?: 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>;
|
|
19
9
|
allowedContracts?: Array<string>;
|
|
20
10
|
uniqueUsers: number;
|
|
21
11
|
openedAccountsCount?: number;
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type PoolDataPayload =
|
|
1
|
+
import { PoolDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
|
+
export declare type PoolDataPayload = PoolDataStruct;
|
package/lib/tokens/token.js
CHANGED
|
@@ -151,10 +151,10 @@ exports.tokenDataByNetwork = {
|
|
|
151
151
|
stkcvxsteCRV: "0xd8bAbB7EfBF7F931a69B209f71b27421F8b18516",
|
|
152
152
|
stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
|
|
153
153
|
//GEARBOX
|
|
154
|
-
dDAI: "
|
|
155
|
-
dUSDC: "
|
|
156
|
-
dWBTC: "
|
|
157
|
-
dWETH: "
|
|
154
|
+
dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
|
|
155
|
+
dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
|
|
156
|
+
dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
|
|
157
|
+
dWETH: "0x19e4F905749D3b487CA4927b54e55b64625a1143",
|
|
158
158
|
GEAR: "0xe01c5d0297c56e992dab3886057a1441485ff7c7"
|
|
159
159
|
}
|
|
160
160
|
};
|
package/package.json
CHANGED
package/src/apy/convexAPY.ts
CHANGED
|
@@ -28,8 +28,9 @@ import { AwaitedRes } from "../utils/types";
|
|
|
28
28
|
import {
|
|
29
29
|
SECONDS_PER_YEAR,
|
|
30
30
|
WAD,
|
|
31
|
-
|
|
32
|
-
NetworkType
|
|
31
|
+
WAD_DECIMALS_POW,
|
|
32
|
+
NetworkType,
|
|
33
|
+
PRICE_DECIMALS
|
|
33
34
|
} from "../core/constants";
|
|
34
35
|
|
|
35
36
|
type SupportedPools = Extract<
|
|
@@ -100,8 +101,8 @@ export async function getConvexApy(
|
|
|
100
101
|
const crvPerYear = crvPerUnderlying.mul(SECONDS_PER_YEAR);
|
|
101
102
|
const cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
|
|
102
103
|
|
|
103
|
-
const crvAPY = crvPerYear.mul(cvxPrice).div(
|
|
104
|
-
const cvxAPY = cvxPerYear.mul(crvPrice).div(
|
|
104
|
+
const crvAPY = crvPerYear.mul(cvxPrice).div(PRICE_DECIMALS);
|
|
105
|
+
const cvxAPY = cvxPerYear.mul(crvPrice).div(PRICE_DECIMALS);
|
|
105
106
|
|
|
106
107
|
const extraAPRs = await Promise.all(
|
|
107
108
|
extraPoolAddresses.map(async (_, index) => {
|
|
@@ -113,7 +114,7 @@ export async function getConvexApy(
|
|
|
113
114
|
|
|
114
115
|
const extraPrise = getTokenPrice(tokenList[extraRewardSymbol]);
|
|
115
116
|
|
|
116
|
-
const extraAPY = perYear.mul(extraPrise).div(
|
|
117
|
+
const extraAPY = perYear.mul(extraPrise).div(PRICE_DECIMALS);
|
|
117
118
|
|
|
118
119
|
return extraAPY;
|
|
119
120
|
})
|
|
@@ -242,7 +243,7 @@ export async function getCurveBaseApy(
|
|
|
242
243
|
|
|
243
244
|
const { baseApy = 0 } = result.data.apys[poolName] || {};
|
|
244
245
|
|
|
245
|
-
return toBN((baseApy / RESPONSE_DECIMALS).toString(),
|
|
246
|
+
return toBN((baseApy / RESPONSE_DECIMALS).toString(), WAD_DECIMALS_POW);
|
|
246
247
|
} catch (e) {
|
|
247
248
|
return BigNumber.from(0);
|
|
248
249
|
}
|
package/src/apy/lidoAPY.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { providers } from "ethers";
|
|
2
2
|
|
|
3
3
|
import { multicall, MCall } from "../utils/multicall";
|
|
4
|
+
import { contractParams, LidoParams } from "../contracts/contracts";
|
|
5
|
+
import { tokenDataByNetwork } from "../tokens/token";
|
|
4
6
|
|
|
5
7
|
import { WAD, SECONDS_PER_YEAR, NetworkType } from "../core/constants";
|
|
6
8
|
|
|
@@ -15,14 +17,12 @@ type ILidoOracleInterface = ILidoOracle["interface"];
|
|
|
15
17
|
|
|
16
18
|
type IstETHInterface = IstETH["interface"];
|
|
17
19
|
|
|
18
|
-
const lidoOracleAddress
|
|
19
|
-
|
|
20
|
-
Kovan: ""
|
|
21
|
-
};
|
|
20
|
+
const lidoOracleAddress = (contractParams.LIDO_STETH_GATEWAY as LidoParams)
|
|
21
|
+
.oracle;
|
|
22
22
|
|
|
23
23
|
const lidoStEthAddress: Record<NetworkType, string> = {
|
|
24
|
-
Mainnet:
|
|
25
|
-
Kovan:
|
|
24
|
+
Mainnet: tokenDataByNetwork.Mainnet.STETH,
|
|
25
|
+
Kovan: tokenDataByNetwork.Kovan.STETH
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export async function getLidoApy(
|
|
@@ -40,7 +40,8 @@ export async function getLidoApy(
|
|
|
40
40
|
await geLidoData(
|
|
41
41
|
lidoOracleAddress[networkType],
|
|
42
42
|
lidoStEthAddress[networkType],
|
|
43
|
-
provider
|
|
43
|
+
provider,
|
|
44
|
+
networkType
|
|
44
45
|
);
|
|
45
46
|
|
|
46
47
|
const lidoAPRRay = postTotalPooledEther
|
|
@@ -55,27 +56,33 @@ export async function getLidoApy(
|
|
|
55
56
|
async function geLidoData(
|
|
56
57
|
lidoOracleAddress: string,
|
|
57
58
|
stETHAddress: string,
|
|
58
|
-
provider: providers.Provider
|
|
59
|
+
provider: providers.Provider,
|
|
60
|
+
network: NetworkType
|
|
59
61
|
) {
|
|
60
|
-
const calls: [MCall<ILidoOracleInterface>, MCall<IstETHInterface
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
const calls: [MCall<ILidoOracleInterface>, ...Array<MCall<IstETHInterface>>] =
|
|
63
|
+
[
|
|
64
|
+
{
|
|
65
|
+
address: lidoOracleAddress,
|
|
66
|
+
interface: ILidoOracle__factory.createInterface(),
|
|
67
|
+
method: "getLastCompletedReportDelta()"
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
if (network !== "Kovan")
|
|
72
|
+
calls.push({
|
|
67
73
|
address: stETHAddress,
|
|
68
74
|
interface: IstETH__factory.createInterface(),
|
|
69
75
|
method: "getFee()"
|
|
70
|
-
}
|
|
71
|
-
];
|
|
76
|
+
});
|
|
72
77
|
|
|
73
|
-
|
|
78
|
+
const [stats, fee = Math.floor(LIDO_FEE_DECIMALS / 10)] = await multicall<
|
|
74
79
|
[
|
|
75
80
|
Awaited<ReturnType<ILidoOracle["getLastCompletedReportDelta"]>>,
|
|
76
81
|
Awaited<ReturnType<IstETH["getFee"]>>
|
|
77
82
|
]
|
|
78
83
|
>(calls, provider);
|
|
84
|
+
|
|
85
|
+
return [stats, fee] as const;
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
export const LIDO_FEE_DECIMALS = 10000;
|
|
@@ -27,10 +27,25 @@ export const deployedContracts: Record<string, string> = {
|
|
|
27
27
|
"0xe04b4db67127d1930D36f16B51653120C4285708": "WBTC",
|
|
28
28
|
"0x600073357c29d169aAF3E543A4519749830553F1": "WETH",
|
|
29
29
|
"0xdBAd1361d9A03B81Be8D3a54Ef0dc9e39a1bA5b3": "USDC",
|
|
30
|
-
"0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI"
|
|
30
|
+
"0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI",
|
|
31
31
|
// [YEARN_DAI_VAULT_KOVAN_MOCK]: "Yearn DAI",
|
|
32
32
|
// [YEARN_USDC_VAULT_KOVAN_MOCK]: "Yearn USDC",
|
|
33
33
|
// [SUSHISWAP_KOVAN]: "Sushiswap"
|
|
34
|
+
|
|
35
|
+
"0x94cd5F09727ae04d7D6fd36A9c9DD96D0d54646B": "DAI",
|
|
36
|
+
"0x53B4a7389EA369a9299DfF524f916EC3cB77ffF4": "USDC",
|
|
37
|
+
"0xE6631f7b18744651A385a02ea2C89634d20D7819": "WETH",
|
|
38
|
+
"0x4d2cBA0E43Ad3B3E1C3B1922fe6E8e910b8C3ae0": "WBTC",
|
|
39
|
+
|
|
40
|
+
"0x6Ae9Ed829AF469Df9526FA7443E876bfaBC79eff": "DAI V2",
|
|
41
|
+
"0x8E0a874E3475de1C16490E386b7E2904CdC03086": "USDC V2",
|
|
42
|
+
"0x816a74B75D60839247C848518545fb17cedDC460": "WETH V2",
|
|
43
|
+
|
|
44
|
+
// pools
|
|
45
|
+
"0xA7b1C8f322596C40A04dBd3DffaE37a0849B8b59": "DAI",
|
|
46
|
+
"0xb8ecDB926F07FCbd870eafE72d116413A0BEb236": "USDC",
|
|
47
|
+
"0xAda6b2747295b2ba6ba52ce2d0D5e681D25D63D8": "WETH",
|
|
48
|
+
"0x85c54CCCf27466eEa1C74a73F75CbE385C271EE4": "WBTC"
|
|
34
49
|
};
|
|
35
50
|
|
|
36
51
|
const contractNames = Object.entries(contractsByAddress).reduce<
|
package/src/core/constants.ts
CHANGED
|
@@ -22,11 +22,14 @@ export const getNetworkType = (chainId: number): NetworkType => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export const
|
|
26
|
-
export const RAY = BigNumber.from(10).pow(
|
|
25
|
+
export const RAY_DECIMALS_POW = 27;
|
|
26
|
+
export const RAY = BigNumber.from(10).pow(RAY_DECIMALS_POW);
|
|
27
27
|
export const halfRAY = RAY.div(2);
|
|
28
|
-
export const
|
|
29
|
-
export const WAD = BigNumber.from(10).pow(
|
|
28
|
+
export const WAD_DECIMALS_POW = 18;
|
|
29
|
+
export const WAD = BigNumber.from(10).pow(WAD_DECIMALS_POW);
|
|
30
|
+
|
|
31
|
+
export const PRICE_DECIMALS_POW = 8;
|
|
32
|
+
export const PRICE_DECIMALS = BigNumber.from(10).pow(PRICE_DECIMALS_POW);
|
|
30
33
|
|
|
31
34
|
export const SECONDS_PER_YEAR = 365 * 24 * 3600;
|
|
32
35
|
|
|
@@ -3,9 +3,14 @@ import {
|
|
|
3
3
|
CreditAccountDataExtendedPayload,
|
|
4
4
|
CreditAccountDataPayload
|
|
5
5
|
} from "../payload/creditAccount";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
PERCENTAGE_FACTOR,
|
|
8
|
+
RAY,
|
|
9
|
+
PERCENTAGE_DECIMALS,
|
|
10
|
+
PRICE_DECIMALS
|
|
11
|
+
} from "./constants";
|
|
7
12
|
import { TokenData } from "../tokens/tokenData";
|
|
8
|
-
import {
|
|
13
|
+
import { calcTotalPrice } from "./price";
|
|
9
14
|
|
|
10
15
|
export type Balance = { address: string; balance: BigNumber };
|
|
11
16
|
|
|
@@ -62,12 +67,10 @@ export class CreditAccountData {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
balancesSorted(
|
|
65
|
-
prices: Record<string,
|
|
70
|
+
prices: Record<string, BigNumber>,
|
|
66
71
|
tokens: Record<string, TokenData>
|
|
67
72
|
): Array<Balance> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return sortBalances(safeBalances, prices, tokens).map(
|
|
73
|
+
return sortBalances(this.balances, prices, tokens).map(
|
|
71
74
|
([address, balance]) => ({ address, balance })
|
|
72
75
|
);
|
|
73
76
|
}
|
|
@@ -75,7 +78,7 @@ export class CreditAccountData {
|
|
|
75
78
|
|
|
76
79
|
export function sortBalances(
|
|
77
80
|
balances: Record<string, BigNumber>,
|
|
78
|
-
prices: Record<string,
|
|
81
|
+
prices: Record<string, BigNumber>,
|
|
79
82
|
tokens: Record<string, TokenData>
|
|
80
83
|
) {
|
|
81
84
|
return Object.entries(balances).sort(([addr1, amount1], [addr2, amount2]) => {
|
|
@@ -85,15 +88,15 @@ export function sortBalances(
|
|
|
85
88
|
const token1 = tokens[addr1Lc];
|
|
86
89
|
const token2 = tokens[addr2Lc];
|
|
87
90
|
|
|
88
|
-
const price1 = prices[addr1Lc] ||
|
|
89
|
-
const price2 = prices[addr2Lc] ||
|
|
91
|
+
const price1 = prices[addr1Lc] || PRICE_DECIMALS;
|
|
92
|
+
const price2 = prices[addr2Lc] || PRICE_DECIMALS;
|
|
90
93
|
|
|
91
|
-
const
|
|
92
|
-
const
|
|
94
|
+
const totalPrice1 = calcTotalPrice(price1, amount1, token1?.decimals);
|
|
95
|
+
const totalPrice2 = calcTotalPrice(price2, amount2, token2?.decimals);
|
|
93
96
|
|
|
94
|
-
return
|
|
97
|
+
return totalPrice1.eq(totalPrice2)
|
|
95
98
|
? tokensAbcComparator(token1, token2)
|
|
96
|
-
:
|
|
99
|
+
: totalPrice1.gt(totalPrice2)
|
|
97
100
|
? -1
|
|
98
101
|
: 1;
|
|
99
102
|
});
|
|
@@ -74,16 +74,17 @@ export class CreditManagerData {
|
|
|
74
74
|
{}
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
this.liquidationThresholds = payload.liquidationThresholds.reduce<
|
|
77
|
+
this.liquidationThresholds = (payload.liquidationThresholds || []).reduce<
|
|
78
78
|
Record<string, BigNumber>
|
|
79
79
|
>((acc, threshold, index) => {
|
|
80
80
|
const address = payload.collateralTokens[index];
|
|
81
81
|
|
|
82
|
-
if (address) acc[address.toLowerCase()] = threshold;
|
|
82
|
+
if (address) acc[address.toLowerCase()] = BigNumber.from(threshold);
|
|
83
83
|
|
|
84
84
|
return acc;
|
|
85
85
|
}, {});
|
|
86
|
-
|
|
86
|
+
|
|
87
|
+
this.version = BigNumber.from(payload.version || 1).toNumber();
|
|
87
88
|
this.creditFacade = payload.creditFacade || "";
|
|
88
89
|
this.isDegenMode = payload.isDegenMode || false;
|
|
89
90
|
this.degenNFT = payload.degenNFT || "";
|
package/src/core/price.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
-
import { TokenData } from "../tokens/tokenData";
|
|
3
2
|
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
export const priceCalc = (
|
|
7
|
-
price: number,
|
|
3
|
+
export const calcTotalPrice = (
|
|
4
|
+
price: BigNumber,
|
|
8
5
|
amount: BigNumber,
|
|
9
|
-
|
|
6
|
+
decimals: number = 18
|
|
10
7
|
) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return amount
|
|
14
|
-
.mul(Math.floor(PRICE_DECIMALS * price))
|
|
15
|
-
.div(BigNumber.from(10).pow(decimals));
|
|
8
|
+
return amount.mul(price).div(BigNumber.from(10).pow(decimals));
|
|
16
9
|
};
|
package/src/core/strategy.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "../core/constants";
|
|
3
|
+
import { calcTotalPrice } from "../core/price";
|
|
2
4
|
|
|
3
5
|
export interface StrategyPayload {
|
|
4
6
|
apy?: number;
|
|
@@ -19,6 +21,12 @@ interface PoolStats {
|
|
|
19
21
|
|
|
20
22
|
type PoolList = Record<string, PoolStats>;
|
|
21
23
|
|
|
24
|
+
interface TokenDescription {
|
|
25
|
+
price: BigNumber;
|
|
26
|
+
amount: BigNumber;
|
|
27
|
+
decimals: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export class Strategy {
|
|
23
31
|
apy: number | undefined;
|
|
24
32
|
|
|
@@ -42,7 +50,7 @@ export class Strategy {
|
|
|
42
50
|
this.baseAssets = payload.baseAssets;
|
|
43
51
|
}
|
|
44
52
|
|
|
45
|
-
public
|
|
53
|
+
public maxAPY(apy: number, maxLeverage: number, poolApy: PoolList) {
|
|
46
54
|
const minApy = this.minBorrowApy(poolApy);
|
|
47
55
|
|
|
48
56
|
return this.roi(apy, maxLeverage, maxLeverage - LEVERAGE_DECIMALS, minApy);
|
|
@@ -60,29 +68,28 @@ export class Strategy {
|
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
public liquidationPrice(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ltCollateral:
|
|
67
|
-
|
|
68
|
-
depositCollateral: string
|
|
71
|
+
borrowed: TokenDescription,
|
|
72
|
+
collateral: TokenDescription,
|
|
73
|
+
lp: TokenDescription,
|
|
74
|
+
ltCollateral: BigNumber
|
|
69
75
|
) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(leverage - LEVERAGE_DECIMALS - ltCollateral * (leverage - farmLev)) /
|
|
75
|
-
(ltStrategy * farmLev)
|
|
76
|
+
const borrowedMoney = calcTotalPrice(
|
|
77
|
+
borrowed.price,
|
|
78
|
+
borrowed.amount,
|
|
79
|
+
borrowed.decimals
|
|
76
80
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
81
|
+
const collateralMoney = calcTotalPrice(
|
|
82
|
+
collateral.price,
|
|
83
|
+
collateral.amount,
|
|
84
|
+
collateral.decimals
|
|
85
|
+
)
|
|
86
|
+
.mul(ltCollateral)
|
|
87
|
+
.div(PERCENTAGE_FACTOR);
|
|
88
|
+
const lpMoney = calcTotalPrice(lp.price, lp.amount, lp.decimals);
|
|
89
|
+
|
|
90
|
+
return lpMoney.gt(0)
|
|
91
|
+
? borrowedMoney.sub(collateralMoney).mul(WAD).div(lpMoney)
|
|
92
|
+
: BigNumber.from(0);
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
private roi(
|
package/src/pathfinder/yVault.ts
CHANGED
|
@@ -61,13 +61,13 @@ export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
|
61
61
|
BigNumber.from(vb?.balance || 0).mul(prices[i])
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
const tokenAddress = tokenDataByNetwork[p.networkType][vault];
|
|
65
|
+
const adapterAddress = p.creditManager.adapters[tokenAddress];
|
|
66
|
+
|
|
67
|
+
const callData =
|
|
68
|
+
IYVault__factory.createInterface().encodeFunctionData("withdraw()");
|
|
69
|
+
|
|
70
|
+
p.calls.push({ target: adapterAddress, callData });
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
return await p.withdrawTokens();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
|
|
2
2
|
|
|
3
|
-
export type TokenBalancePayload =
|
|
3
|
+
export type TokenBalancePayload = CreditAccountDataStruct["balances"];
|
|
4
4
|
|
|
5
|
-
export type CreditAccountDataPayload =
|
|
5
|
+
export type CreditAccountDataPayload = CreditAccountDataStruct;
|
|
6
6
|
|
|
7
|
-
export type CreditAccountDataExtendedPayload =
|
|
7
|
+
export type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
import { BigNumberish
|
|
2
|
-
import {
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { CreditManagerDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
3
3
|
|
|
4
4
|
export interface AdapterPayload {
|
|
5
5
|
allowedContract: string;
|
|
6
6
|
adapter: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export type CreditManagerDataPayload =
|
|
9
|
+
export type CreditManagerDataPayload = CreditManagerDataStruct;
|
|
10
10
|
|
|
11
11
|
export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
12
|
-
addr: string;
|
|
13
|
-
underlyingToken?: string;
|
|
14
|
-
isWETH: boolean;
|
|
15
|
-
canBorrow: boolean;
|
|
16
|
-
borrowRate: BigNumber;
|
|
17
|
-
minAmount: BigNumber;
|
|
18
|
-
maxAmount: BigNumber;
|
|
19
|
-
maxLeverageFactor: BigNumber;
|
|
20
|
-
availableLiquidity: BigNumber;
|
|
21
|
-
allowedTokens: Array<string>;
|
|
22
12
|
allowedContracts?: Array<string>;
|
|
23
13
|
uniqueUsers: number;
|
|
24
14
|
openedAccountsCount?: number;
|
package/src/payload/pool.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PoolDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
2
|
|
|
3
|
-
export type PoolDataPayload =
|
|
3
|
+
export type PoolDataPayload = PoolDataStruct;
|
package/src/tokens/token.ts
CHANGED
|
@@ -218,10 +218,10 @@ export const tokenDataByNetwork: Record<
|
|
|
218
218
|
stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
|
|
219
219
|
|
|
220
220
|
//GEARBOX
|
|
221
|
-
dDAI: "
|
|
222
|
-
dUSDC: "
|
|
223
|
-
dWBTC: "
|
|
224
|
-
dWETH: "
|
|
221
|
+
dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
|
|
222
|
+
dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
|
|
223
|
+
dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
|
|
224
|
+
dWETH: "0x19e4F905749D3b487CA4927b54e55b64625a1143",
|
|
225
225
|
|
|
226
226
|
GEAR: "0xe01c5d0297c56e992dab3886057a1441485ff7c7"
|
|
227
227
|
}
|