@gearbox-protocol/sdk 0.0.101 → 0.0.104
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/.eslintignore +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +7 -9
- package/lib/apy/lidoAPY.js +35 -29
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/contracts/contractsRegister.js +13 -1
- package/lib/core/constants.d.ts +5 -3
- package/lib/core/constants.js +8 -6
- package/lib/core/creditAccount.d.ts +2 -2
- package/lib/core/creditAccount.js +12 -11
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +4 -10
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.d.ts +1 -3
- package/lib/core/price.js +9 -7
- package/lib/core/strategy.d.ts +8 -6
- package/lib/core/strategy.js +25 -25
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -2
- package/lib/index.js +8 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +22 -22
- 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/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +8 -8
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +13 -12
- package/src/apy/lidoAPY.ts +35 -27
- package/src/contracts/contracts.ts +27 -17
- package/src/contracts/contractsRegister.ts +16 -1
- package/src/core/constants.ts +8 -5
- package/src/core/creditAccount.ts +42 -16
- package/src/core/creditManager.ts +33 -7
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +10 -13
- package/src/core/strategy.ts +54 -43
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +32 -17
- package/src/payload/creditAccount.ts +4 -4
- package/src/payload/creditManager.ts +3 -13
- package/src/payload/pool.ts +2 -2
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +360 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +13 -9
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: "@typescript-eslint/parser",
|
|
4
|
+
parserOptions: {
|
|
5
|
+
project: ["./tsconfig.json"],
|
|
6
|
+
tsconfigRootDir: __dirname
|
|
7
|
+
},
|
|
8
|
+
plugins: ["@typescript-eslint", "prettier"],
|
|
9
|
+
extends: [
|
|
10
|
+
"airbnb-base",
|
|
11
|
+
"airbnb-typescript/base",
|
|
12
|
+
"plugin:import/recommended",
|
|
13
|
+
"prettier"
|
|
14
|
+
],
|
|
15
|
+
settings: {
|
|
16
|
+
"import/resolver": {
|
|
17
|
+
typescript: {},
|
|
18
|
+
node: {
|
|
19
|
+
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
|
20
|
+
moduleDirectory: ["node_modules", "./"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
react: {
|
|
24
|
+
version: "detect"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
rules: {
|
|
28
|
+
"prettier/prettier": "error",
|
|
29
|
+
"import/no-extraneous-dependencies": ["error", { devDependencies: true }],
|
|
30
|
+
"@typescript-eslint/no-use-before-define": [
|
|
31
|
+
"error",
|
|
32
|
+
{
|
|
33
|
+
functions: false,
|
|
34
|
+
classes: false
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"no-console": ["error", { allow: ["warn", "error", "debug"] }],
|
|
38
|
+
"@typescript-eslint/default-param-last": ["warn"],
|
|
39
|
+
|
|
40
|
+
"no-nested-ternary": ["warn"],
|
|
41
|
+
"@typescript-eslint/no-unused-vars": ["warn"],
|
|
42
|
+
"no-underscore-dangle": ["error", { allowAfterThis: true }],
|
|
43
|
+
|
|
44
|
+
"react/no-unused-prop-types": ["off"], // switch on when necessary
|
|
45
|
+
"max-classes-per-file": ["off"],
|
|
46
|
+
"react/jsx-props-no-spreading": ["off"],
|
|
47
|
+
"react/no-array-index-key": ["off"],
|
|
48
|
+
"react/require-default-props": ["off"],
|
|
49
|
+
"import/prefer-default-export": ["off"],
|
|
50
|
+
"react/jsx-no-useless-fragment": ["off"]
|
|
51
|
+
}
|
|
52
|
+
};
|
package/.husky/pre-push
ADDED
package/lib/apy/convexAPY.js
CHANGED
|
@@ -79,21 +79,19 @@ function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
|
79
79
|
basePoolAddress = contractsList[pool];
|
|
80
80
|
swapPoolAddress = contractsList[curveSwapByPool[pool]];
|
|
81
81
|
cvxAddress = tokenList.CVX;
|
|
82
|
-
extraPoolAddresses = poolParams.extraRewards.map(function (d) {
|
|
83
|
-
return d.poolAddress[networkType];
|
|
84
|
-
});
|
|
82
|
+
extraPoolAddresses = poolParams.extraRewards.map(function (d) { return d.poolAddress[networkType]; });
|
|
85
83
|
return [4 /*yield*/, getPoolData(basePoolAddress, swapPoolAddress, cvxAddress, extraPoolAddresses, provider)];
|
|
86
84
|
case 1:
|
|
87
85
|
_a = _b.sent(), basePoolRate = _a[0], basePoolSupply = _a[1], vPrice = _a[2], cvxSupply = _a[3], extra = _a.slice(4);
|
|
88
|
-
cvxPrice = getTokenPrice(tokenList
|
|
89
|
-
crvPrice = getTokenPrice(tokenList
|
|
86
|
+
cvxPrice = getTokenPrice(tokenList.CVX);
|
|
87
|
+
crvPrice = getTokenPrice(tokenList.CRV);
|
|
90
88
|
crvPerSecond = basePoolRate;
|
|
91
89
|
virtualSupply = basePoolSupply.mul(vPrice).div(constants_1.WAD);
|
|
92
90
|
crvPerUnderlying = crvPerSecond.mul(constants_1.WAD).div(virtualSupply);
|
|
93
91
|
crvPerYear = crvPerUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
94
92
|
cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
|
|
95
|
-
crvAPY = crvPerYear.mul(cvxPrice).div(constants_1.
|
|
96
|
-
cvxAPY = cvxPerYear.mul(crvPrice).div(constants_1.
|
|
93
|
+
crvAPY = crvPerYear.mul(cvxPrice).div(constants_1.PRICE_DECIMALS);
|
|
94
|
+
cvxAPY = cvxPerYear.mul(crvPrice).div(constants_1.PRICE_DECIMALS);
|
|
97
95
|
return [4 /*yield*/, Promise.all(extraPoolAddresses.map(function (_, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
98
96
|
var extraRewardSymbol, extraPoolRate, perUnderlying, perYear, extraPrise, extraAPY;
|
|
99
97
|
return __generator(this, function (_a) {
|
|
@@ -102,7 +100,7 @@ function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
|
102
100
|
perUnderlying = extraPoolRate.mul(constants_1.WAD).div(virtualSupply);
|
|
103
101
|
perYear = perUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
104
102
|
extraPrise = getTokenPrice(tokenList[extraRewardSymbol]);
|
|
105
|
-
extraAPY = perYear.mul(extraPrise).div(constants_1.
|
|
103
|
+
extraAPY = perYear.mul(extraPrise).div(constants_1.PRICE_DECIMALS);
|
|
106
104
|
return [2 /*return*/, extraAPY];
|
|
107
105
|
});
|
|
108
106
|
}); }))];
|
|
@@ -190,7 +188,7 @@ function getCurveBaseApy(curveLPToken) {
|
|
|
190
188
|
case 2:
|
|
191
189
|
result = _b.sent();
|
|
192
190
|
_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.
|
|
191
|
+
return [2 /*return*/, (0, formatter_1.toBN)((baseApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW)];
|
|
194
192
|
case 3:
|
|
195
193
|
e_1 = _b.sent();
|
|
196
194
|
return [2 /*return*/, ethers_1.BigNumber.from(0)];
|
package/lib/apy/lidoAPY.js
CHANGED
|
@@ -38,15 +38,14 @@ 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
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var lidoStEthAddress = {
|
|
48
|
-
Mainnet: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
|
|
49
|
-
Kovan: ""
|
|
45
|
+
var lidoOracles = contracts_1.contractParams.LIDO_STETH_GATEWAY.oracle;
|
|
46
|
+
var lidoStEth = {
|
|
47
|
+
Mainnet: token_1.tokenDataByNetwork.Mainnet.STETH,
|
|
48
|
+
Kovan: token_1.tokenDataByNetwork.Kovan.STETH
|
|
50
49
|
};
|
|
51
50
|
function getLidoApy(provider, networkType) {
|
|
52
51
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -54,13 +53,13 @@ function getLidoApy(provider, networkType) {
|
|
|
54
53
|
return __generator(this, function (_c) {
|
|
55
54
|
switch (_c.label) {
|
|
56
55
|
case 0:
|
|
57
|
-
if (!
|
|
58
|
-
throw "No Lido APR oracle found on current network: ".concat(networkType);
|
|
56
|
+
if (!lidoOracles[networkType]) {
|
|
57
|
+
throw new Error("No Lido APR oracle found on current network: ".concat(networkType));
|
|
59
58
|
}
|
|
60
|
-
if (!
|
|
61
|
-
throw "No Lido stETH found on current network: ".concat(networkType);
|
|
59
|
+
if (!lidoStEth[networkType]) {
|
|
60
|
+
throw new Error("No Lido stETH found on current network: ".concat(networkType));
|
|
62
61
|
}
|
|
63
|
-
return [4 /*yield*/, geLidoData(
|
|
62
|
+
return [4 /*yield*/, geLidoData(lidoOracles[networkType], lidoStEth[networkType], provider, networkType)];
|
|
64
63
|
case 1:
|
|
65
64
|
_a = _c.sent(), _b = _a[0], postTotalPooledEther = _b.postTotalPooledEther, preTotalPooledEther = _b.preTotalPooledEther, timeElapsed = _b.timeElapsed, fee = _a[1];
|
|
66
65
|
lidoAPRRay = postTotalPooledEther
|
|
@@ -74,24 +73,31 @@ function getLidoApy(provider, networkType) {
|
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
exports.getLidoApy = getLidoApy;
|
|
77
|
-
|
|
76
|
+
exports.LIDO_FEE_DECIMALS = 10000;
|
|
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
|
}
|
|
97
|
-
exports.LIDO_FEE_DECIMALS = 10000;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { YearnLPToken } from "src/tokens/yearn";
|
|
1
2
|
import { AdapterInterface } from "./adapters";
|
|
2
3
|
import { NetworkType } from "../core/constants";
|
|
3
4
|
import { Protocols } from "./protocols";
|
|
4
5
|
import { ConvexStakedPhantomToken } from "../tokens/convex";
|
|
5
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
6
|
+
import type { CurveLPToken } from "../tokens/curveLP";
|
|
6
7
|
import { NormalToken } from "../tokens/normal";
|
|
7
8
|
export declare type UniswapV2Contract = "UNISWAP_V2_ROUTER" | "SUSHISWAP_ROUTER";
|
|
8
9
|
export declare type CurvePoolContract = "CURVE_3CRV_POOL" | "CURVE_STETH_GATEWAY" | "CURVE_FRAX_POOL" | "CURVE_LUSD_POOL" | "CURVE_GUSD_POOL" | "CURVE_SUSD_POOL" | "CURVE_SUSD_DEPOSIT";
|
|
@@ -34,11 +35,13 @@ export declare type CurveSteCRVPoolParams = {
|
|
|
34
35
|
protocol: Protocols.Curve;
|
|
35
36
|
type: AdapterInterface.CURVE_V1_STECRV_POOL;
|
|
36
37
|
pool: Record<NetworkType, string>;
|
|
38
|
+
tokens: ["WETH", "STETH"];
|
|
37
39
|
lpToken: "steCRV";
|
|
38
40
|
} & BaseContractParams;
|
|
39
|
-
declare type YearnParams = {
|
|
41
|
+
export declare type YearnParams = {
|
|
40
42
|
protocol: Protocols.Yearn;
|
|
41
43
|
type: AdapterInterface.YEARN_V2;
|
|
44
|
+
shareToken: YearnLPToken;
|
|
42
45
|
} & BaseContractParams;
|
|
43
46
|
declare type ConvexParams = {
|
|
44
47
|
protocol: Protocols.Convex;
|
|
@@ -12,11 +12,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.contractsByAddress = exports.contractParams = exports.UNISWAP_V3_QUOTER = exports.contractsByNetwork = void 0;
|
|
15
|
-
/*
|
|
16
|
-
* SPDX-License-Identifier: BSL-1.1
|
|
17
|
-
* Gearbox. Generalized leverage protocol, which allows to take leverage and then use it across other DeFi protocols and platforms in a composable way.
|
|
18
|
-
* (c) Gearbox.fi, 2021
|
|
19
|
-
*/
|
|
20
15
|
var mappers_1 = require("../utils/mappers");
|
|
21
16
|
var adapters_1 = require("./adapters");
|
|
22
17
|
var protocols_1 = require("./protocols");
|
|
@@ -123,6 +118,7 @@ exports.contractParams = {
|
|
|
123
118
|
Mainnet: "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022",
|
|
124
119
|
Kovan: "0xF5C73b58B70709e89aA1D322d48b0D0C71123cB4"
|
|
125
120
|
},
|
|
121
|
+
tokens: ["WETH", "STETH"],
|
|
126
122
|
lpToken: "steCRV"
|
|
127
123
|
},
|
|
128
124
|
CURVE_FRAX_POOL: {
|
|
@@ -130,14 +126,14 @@ exports.contractParams = {
|
|
|
130
126
|
protocol: protocols_1.Protocols.Curve,
|
|
131
127
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
132
128
|
lpToken: "FRAX3CRV",
|
|
133
|
-
tokens: ["
|
|
129
|
+
tokens: ["FRAX", "3Crv"]
|
|
134
130
|
},
|
|
135
131
|
CURVE_LUSD_POOL: {
|
|
136
132
|
name: "Curve LUSD",
|
|
137
133
|
protocol: protocols_1.Protocols.Curve,
|
|
138
134
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
139
135
|
lpToken: "LUSD3CRV",
|
|
140
|
-
tokens: ["
|
|
136
|
+
tokens: ["LUSD", "3Crv"]
|
|
141
137
|
},
|
|
142
138
|
CURVE_SUSD_POOL: {
|
|
143
139
|
name: "Curve SUSD",
|
|
@@ -152,45 +148,50 @@ exports.contractParams = {
|
|
|
152
148
|
protocol: protocols_1.Protocols.Curve,
|
|
153
149
|
type: adapters_1.AdapterInterface.CURVE_V1_WRAPPER,
|
|
154
150
|
lpToken: "crvPlain3andSUSD",
|
|
155
|
-
tokens: ["DAI", "USDC", "USDT", "sUSD"]
|
|
156
|
-
wrapper: "CURVE_SUSD_DEPOSIT"
|
|
151
|
+
tokens: ["DAI", "USDC", "USDT", "sUSD"]
|
|
157
152
|
},
|
|
158
153
|
CURVE_GUSD_POOL: {
|
|
159
154
|
name: "Curve GUSD",
|
|
160
155
|
protocol: protocols_1.Protocols.Curve,
|
|
161
156
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
162
157
|
lpToken: "gusd3CRV",
|
|
163
|
-
tokens: ["
|
|
158
|
+
tokens: ["GUSD", "3Crv"]
|
|
164
159
|
},
|
|
165
160
|
YEARN_DAI_VAULT: {
|
|
166
161
|
name: "Yearn DAI",
|
|
167
162
|
protocol: protocols_1.Protocols.Yearn,
|
|
168
|
-
type: adapters_1.AdapterInterface.YEARN_V2
|
|
163
|
+
type: adapters_1.AdapterInterface.YEARN_V2,
|
|
164
|
+
shareToken: "yvDAI"
|
|
169
165
|
},
|
|
170
166
|
YEARN_USDC_VAULT: {
|
|
171
167
|
name: "Yearn USDC",
|
|
172
168
|
protocol: protocols_1.Protocols.Yearn,
|
|
173
|
-
type: adapters_1.AdapterInterface.YEARN_V2
|
|
169
|
+
type: adapters_1.AdapterInterface.YEARN_V2,
|
|
170
|
+
shareToken: "yvUSDC"
|
|
174
171
|
},
|
|
175
172
|
YEARN_WETH_VAULT: {
|
|
176
173
|
name: "Yearn WETH",
|
|
177
174
|
protocol: protocols_1.Protocols.Yearn,
|
|
178
|
-
type: adapters_1.AdapterInterface.YEARN_V2
|
|
175
|
+
type: adapters_1.AdapterInterface.YEARN_V2,
|
|
176
|
+
shareToken: "yvWETH"
|
|
179
177
|
},
|
|
180
178
|
YEARN_WBTC_VAULT: {
|
|
181
179
|
name: "Yearn WBTC",
|
|
182
180
|
protocol: protocols_1.Protocols.Yearn,
|
|
183
|
-
type: adapters_1.AdapterInterface.YEARN_V2
|
|
181
|
+
type: adapters_1.AdapterInterface.YEARN_V2,
|
|
182
|
+
shareToken: "yvWBTC"
|
|
184
183
|
},
|
|
185
184
|
YEARN_CURVE_FRAX_VAULT: {
|
|
186
185
|
name: "Yearn Curve FRAX",
|
|
187
186
|
protocol: protocols_1.Protocols.Yearn,
|
|
188
|
-
type: adapters_1.AdapterInterface.YEARN_V2
|
|
187
|
+
type: adapters_1.AdapterInterface.YEARN_V2,
|
|
188
|
+
shareToken: "yvCurve_FRAX"
|
|
189
189
|
},
|
|
190
190
|
YEARN_CURVE_STETH_VAULT: {
|
|
191
191
|
name: "Yearn Curve STETH",
|
|
192
192
|
protocol: protocols_1.Protocols.Yearn,
|
|
193
|
-
type: adapters_1.AdapterInterface.YEARN_V2
|
|
193
|
+
type: adapters_1.AdapterInterface.YEARN_V2,
|
|
194
|
+
shareToken: "yvCurve_stETH"
|
|
194
195
|
},
|
|
195
196
|
CONVEX_BOOSTER: {
|
|
196
197
|
name: "Convex BOOSTER",
|
|
@@ -288,6 +289,6 @@ exports.contractParams = {
|
|
|
288
289
|
}
|
|
289
290
|
};
|
|
290
291
|
exports.contractsByAddress = (0, mappers_1.objectEntries)(exports.contractsByNetwork).reduce(function (acc, _a) {
|
|
291
|
-
var
|
|
292
|
-
return __assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(contracts))));
|
|
292
|
+
var contracts = _a[1];
|
|
293
|
+
return (__assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(contracts)))));
|
|
293
294
|
}, {});
|
|
@@ -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;
|
|
@@ -18,4 +20,4 @@ export declare const UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = 9300;
|
|
|
18
20
|
export declare const timeRanges: Record<string, number>;
|
|
19
21
|
export declare const LEVERAGE_DECIMALS = 100;
|
|
20
22
|
export declare const SLIPPAGE_DECIMALS = 100;
|
|
21
|
-
export declare const
|
|
23
|
+
export declare const ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
|
package/lib/core/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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;
|
|
@@ -37,4 +39,4 @@ exports.timeRanges = {
|
|
|
37
39
|
};
|
|
38
40
|
exports.LEVERAGE_DECIMALS = 100;
|
|
39
41
|
exports.SLIPPAGE_DECIMALS = 100;
|
|
40
|
-
exports.
|
|
42
|
+
exports.ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
|
|
@@ -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,15 +70,17 @@ 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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
if (totalPrice1.eq(totalPrice2)) {
|
|
78
|
+
return tokensAbcComparator(token1, token2);
|
|
79
|
+
}
|
|
80
|
+
if (totalPrice1.gt(totalPrice2)) {
|
|
81
|
+
return -1;
|
|
82
|
+
}
|
|
83
|
+
return 1;
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
exports.sortBalances = sortBalances;
|
|
@@ -22,8 +22,8 @@ export declare class CreditManagerData {
|
|
|
22
22
|
readonly degenNFT: string;
|
|
23
23
|
readonly isIncreaseDebtForbidden: boolean;
|
|
24
24
|
readonly forbiddenTokenMask: BigNumber;
|
|
25
|
+
readonly isPaused: boolean;
|
|
25
26
|
constructor(payload: CreditManagerDataPayload);
|
|
26
|
-
get isPaused(): boolean;
|
|
27
27
|
getContractETH(signer: Signer | ethers.providers.Provider): ICreditManager;
|
|
28
28
|
contractToAdapter(contractAddress: string): string | undefined;
|
|
29
29
|
encodeAddCollateral(accountAddress: string, tokenAddress: string, amount: BigNumber): MultiCall;
|
|
@@ -33,6 +33,7 @@ var constants_1 = require("./constants");
|
|
|
33
33
|
var errors_1 = require("./errors");
|
|
34
34
|
var CreditManagerData = /** @class */ (function () {
|
|
35
35
|
function CreditManagerData(payload) {
|
|
36
|
+
this.isPaused = false;
|
|
36
37
|
this.id = payload.addr;
|
|
37
38
|
this.address = payload.addr;
|
|
38
39
|
this.underlyingToken = payload.underlying || "";
|
|
@@ -54,26 +55,19 @@ var CreditManagerData = /** @class */ (function () {
|
|
|
54
55
|
var allowedContract = _a.allowedContract, adapter = _a.adapter;
|
|
55
56
|
return (__assign(__assign({}, acc), (_b = {}, _b[allowedContract] = adapter, _b)));
|
|
56
57
|
}, {});
|
|
57
|
-
this.liquidationThresholds = payload.liquidationThresholds.reduce(function (acc, threshold, index) {
|
|
58
|
+
this.liquidationThresholds = (payload.liquidationThresholds || []).reduce(function (acc, threshold, index) {
|
|
58
59
|
var address = payload.collateralTokens[index];
|
|
59
60
|
if (address)
|
|
60
|
-
acc[address.toLowerCase()] = threshold;
|
|
61
|
+
acc[address.toLowerCase()] = ethers_1.BigNumber.from(threshold);
|
|
61
62
|
return acc;
|
|
62
63
|
}, {});
|
|
63
|
-
this.version = payload.version || 1;
|
|
64
|
+
this.version = ethers_1.BigNumber.from(payload.version || 1).toNumber();
|
|
64
65
|
this.creditFacade = payload.creditFacade || "";
|
|
65
66
|
this.isDegenMode = payload.isDegenMode || false;
|
|
66
67
|
this.degenNFT = payload.degenNFT || "";
|
|
67
68
|
this.isIncreaseDebtForbidden = payload.isIncreaseDebtForbidden || false;
|
|
68
69
|
this.forbiddenTokenMask = ethers_1.BigNumber.from(payload.forbiddenTokenMask || 0);
|
|
69
70
|
}
|
|
70
|
-
Object.defineProperty(CreditManagerData.prototype, "isPaused", {
|
|
71
|
-
get: function () {
|
|
72
|
-
return false;
|
|
73
|
-
},
|
|
74
|
-
enumerable: false,
|
|
75
|
-
configurable: true
|
|
76
|
-
});
|
|
77
71
|
CreditManagerData.prototype.getContractETH = function (signer) {
|
|
78
72
|
return types_1.ICreditManager__factory.connect(this.address, signer);
|
|
79
73
|
};
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -11,7 +22,7 @@ var statusEnum = [
|
|
|
11
22
|
"active",
|
|
12
23
|
"closed",
|
|
13
24
|
"repaid",
|
|
14
|
-
"liquidated"
|
|
25
|
+
"liquidated"
|
|
15
26
|
];
|
|
16
27
|
var CreditSession = /** @class */ (function () {
|
|
17
28
|
function CreditSession(payload) {
|
|
@@ -33,8 +44,8 @@ var CreditSession = /** @class */ (function () {
|
|
|
33
44
|
ethers_1.BigNumber.from(payload.healthFactor || 0).toNumber() / constants_1.PERCENTAGE_FACTOR;
|
|
34
45
|
this.score = payload.score;
|
|
35
46
|
this.operations = (payload.operations || []).map(function (op) {
|
|
36
|
-
|
|
37
|
-
return
|
|
47
|
+
var formattedOp = __assign(__assign({}, op), { date: (0, moment_1.default)(op.timestamp * 1000).format("Do MMM YYYY") });
|
|
48
|
+
return formattedOp;
|
|
38
49
|
});
|
|
39
50
|
this.sinceDate = (0, moment_1.default)(payload.sinceTimestamp * 1000).format("Do MMM YYYY");
|
|
40
51
|
this.closedAtDate = (0, moment_1.default)(payload.closedAtTimestamp * 1000).format("Do MMM YYYY");
|
package/lib/core/eventOrTx.d.ts
CHANGED