@gearbox-protocol/sdk 0.0.102 → 0.0.105
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 +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- 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.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- 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 +18 -15
- 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 +4 -4
- 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 +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +27 -17
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- 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 +7 -3
- package/src/core/strategy.ts +27 -23
- 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 +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +361 -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 +9 -5
- 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/lib/utils/loading.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadingProgress = void 0;
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (item !== undefined)
|
|
13
|
-
isLoaded++;
|
|
14
|
-
}
|
|
15
|
-
return Math.floor((isLoaded / params.length) * 100);
|
|
3
|
+
exports.loadingProgress = exports.allLoaded = void 0;
|
|
4
|
+
var isLoaded = function (v) { return v !== undefined; };
|
|
5
|
+
function allLoaded(itemsToLoad) {
|
|
6
|
+
return itemsToLoad.reduce(function (acc, item) { return acc && isLoaded(item); }, true);
|
|
7
|
+
}
|
|
8
|
+
exports.allLoaded = allLoaded;
|
|
9
|
+
function loadingProgress(itemsToLoad) {
|
|
10
|
+
var loaded = itemsToLoad.reduce(function (acc, item) { return (isLoaded(item) ? acc + 1 : acc); }, 0);
|
|
11
|
+
return Math.floor((loaded / itemsToLoad.length) * 100);
|
|
16
12
|
}
|
|
17
13
|
exports.loadingProgress = loadingProgress;
|
package/lib/utils/mappers.js
CHANGED
|
@@ -18,7 +18,7 @@ var swapKeyValue = function (o) {
|
|
|
18
18
|
return objectEntries(o).reduce(function (acc, _a) {
|
|
19
19
|
var _b;
|
|
20
20
|
var key = _a[0], value = _a[1];
|
|
21
|
-
return __assign(__assign({}, acc), (_b = {}, _b[value] = key, _b));
|
|
21
|
+
return (__assign(__assign({}, acc), (_b = {}, _b[value] = key, _b)));
|
|
22
22
|
}, {});
|
|
23
23
|
};
|
|
24
24
|
exports.swapKeyValue = swapKeyValue;
|
|
@@ -35,7 +35,7 @@ var filterEmptyKeys = function (o) {
|
|
|
35
35
|
return objectEntries(o).reduce(function (acc, _a) {
|
|
36
36
|
var _b;
|
|
37
37
|
var key = _a[0], value = _a[1];
|
|
38
|
-
return
|
|
38
|
+
return (key ? __assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)) : acc);
|
|
39
39
|
}, {});
|
|
40
40
|
};
|
|
41
41
|
exports.filterEmptyKeys = filterEmptyKeys;
|
package/lib/utils/network.js
CHANGED
|
@@ -48,7 +48,7 @@ function detectNetwork(provider) {
|
|
|
48
48
|
case 0:
|
|
49
49
|
_c.trys.push([0, 2, , 7]);
|
|
50
50
|
usdcMainnet = types_1.ERC20__factory.connect(token_1.tokenDataByNetwork.Mainnet.USDC, provider);
|
|
51
|
-
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.
|
|
51
|
+
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
|
|
52
52
|
case 1:
|
|
53
53
|
_c.sent();
|
|
54
54
|
return [2 /*return*/, "Mainnet"];
|
|
@@ -58,7 +58,7 @@ function detectNetwork(provider) {
|
|
|
58
58
|
case 3:
|
|
59
59
|
_c.trys.push([3, 5, , 6]);
|
|
60
60
|
usdcMainnet = types_1.ERC20__factory.connect(token_1.tokenDataByNetwork.Kovan.USDC, provider);
|
|
61
|
-
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.
|
|
61
|
+
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
|
|
62
62
|
case 4:
|
|
63
63
|
_c.sent();
|
|
64
64
|
return [2 /*return*/, "Kovan"];
|
package/lib/utils/repeater.js
CHANGED
|
@@ -40,32 +40,20 @@ exports.callRepeater = void 0;
|
|
|
40
40
|
function callRepeater(call, step) {
|
|
41
41
|
if (step === void 0) { step = 0; }
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var _this = this;
|
|
44
43
|
return __generator(this, function (_a) {
|
|
45
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return [3 /*break*/, 3];
|
|
56
|
-
case 2:
|
|
57
|
-
e_1 = _b.sent();
|
|
58
|
-
console.error("Error ".concat(step, ": ").concat(e_1));
|
|
59
|
-
if (step > 5 || e_1.code !== -32000)
|
|
60
|
-
reject(e_1);
|
|
61
|
-
else {
|
|
62
|
-
setTimeout(function () { return resolve(callRepeater(call, step + 1)); }, 200);
|
|
63
|
-
}
|
|
64
|
-
return [3 /*break*/, 3];
|
|
65
|
-
case 3: return [2 /*return*/];
|
|
44
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
45
|
+
try {
|
|
46
|
+
call().then(function (r) { return resolve(r); });
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.error("Error ".concat(step, ": ").concat(e));
|
|
50
|
+
if (step > 5 || e.code !== -32000)
|
|
51
|
+
reject(e);
|
|
52
|
+
else {
|
|
53
|
+
setTimeout(function () { return resolve(callRepeater(call, step + 1)); }, 200);
|
|
66
54
|
}
|
|
67
|
-
}
|
|
68
|
-
})
|
|
55
|
+
}
|
|
56
|
+
})];
|
|
69
57
|
});
|
|
70
58
|
});
|
|
71
59
|
}
|
package/lib/utils/validate.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.105",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -9,22 +9,39 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"dev": "tsc -w",
|
|
12
|
-
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish"
|
|
12
|
+
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish",
|
|
13
|
+
"lint": "eslint . --ext .tsx,.ts --fix",
|
|
14
|
+
"prepush": "yarn lint --max-warnings=0",
|
|
15
|
+
"prepare": "husky install"
|
|
13
16
|
},
|
|
14
17
|
"dependencies": {
|
|
15
18
|
"decimal.js-light": "^2.5.1",
|
|
16
19
|
"moment": "^2.29.1"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
19
|
-
"@types/jest": "^26.0.
|
|
20
|
-
"@types/node": "^
|
|
22
|
+
"@types/jest": "^26.0.15",
|
|
23
|
+
"@types/node": "^17.0.41",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
25
|
+
"@typescript-eslint/parser": "^5.7.0",
|
|
21
26
|
"axios": "^0.27.2",
|
|
22
27
|
"dotenv": "^16.0.1",
|
|
23
|
-
"
|
|
28
|
+
"eslint": "^7.11.0",
|
|
29
|
+
"eslint-config-airbnb": "^19.0.2",
|
|
30
|
+
"eslint-config-airbnb-typescript": "^16.1.0",
|
|
31
|
+
"eslint-config-prettier": "^8.3.0",
|
|
32
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
33
|
+
"eslint-plugin-import": "^2.22.1",
|
|
34
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
35
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
36
|
+
"eslint-plugin-react": "^7.27.1",
|
|
37
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
38
|
+
"ethers": "5.6.9",
|
|
39
|
+
"husky": "^8.0.0",
|
|
40
|
+
"husky-init": "^8.0.0",
|
|
24
41
|
"jest": "^26.1.0",
|
|
25
|
-
"prettier": "^2.
|
|
42
|
+
"prettier": "^2.7.1",
|
|
26
43
|
"ts-node": "^10.1.0",
|
|
27
44
|
"tslog": "^3.3.3",
|
|
28
|
-
"typescript": "^4.
|
|
45
|
+
"typescript": "^4.7.3"
|
|
29
46
|
}
|
|
30
47
|
}
|
package/src/apy/convexAPY.ts
CHANGED
|
@@ -73,14 +73,14 @@ export async function getConvexApy(
|
|
|
73
73
|
poolParams.stakedToken
|
|
74
74
|
] as ConvexPhantomTokenData;
|
|
75
75
|
|
|
76
|
-
const underlying = stakedTokenParams
|
|
76
|
+
const { underlying } = stakedTokenParams;
|
|
77
77
|
const basePoolAddress = contractsList[pool];
|
|
78
78
|
const swapPoolAddress = contractsList[curveSwapByPool[pool]];
|
|
79
79
|
const cvxAddress = tokenList.CVX;
|
|
80
80
|
|
|
81
|
-
const extraPoolAddresses = poolParams.extraRewards.map(
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const extraPoolAddresses = poolParams.extraRewards.map(
|
|
82
|
+
d => d.poolAddress[networkType]
|
|
83
|
+
);
|
|
84
84
|
|
|
85
85
|
const [basePoolRate, basePoolSupply, vPrice, cvxSupply, ...extra] =
|
|
86
86
|
await getPoolData(
|
|
@@ -91,8 +91,8 @@ export async function getConvexApy(
|
|
|
91
91
|
provider
|
|
92
92
|
);
|
|
93
93
|
|
|
94
|
-
const cvxPrice = getTokenPrice(tokenList
|
|
95
|
-
const crvPrice = getTokenPrice(tokenList
|
|
94
|
+
const cvxPrice = getTokenPrice(tokenList.CVX);
|
|
95
|
+
const crvPrice = getTokenPrice(tokenList.CRV);
|
|
96
96
|
|
|
97
97
|
const crvPerSecond = basePoolRate;
|
|
98
98
|
const virtualSupply = basePoolSupply.mul(vPrice).div(WAD);
|
package/src/apy/lidoAPY.ts
CHANGED
|
@@ -17,10 +17,9 @@ type ILidoOracleInterface = ILidoOracle["interface"];
|
|
|
17
17
|
|
|
18
18
|
type IstETHInterface = IstETH["interface"];
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
.oracle;
|
|
20
|
+
const lidoOracles = (contractParams.LIDO_STETH_GATEWAY as LidoParams).oracle;
|
|
22
21
|
|
|
23
|
-
const
|
|
22
|
+
const lidoStEth: Record<NetworkType, string> = {
|
|
24
23
|
Mainnet: tokenDataByNetwork.Mainnet.STETH,
|
|
25
24
|
Kovan: tokenDataByNetwork.Kovan.STETH
|
|
26
25
|
};
|
|
@@ -29,17 +28,19 @@ export async function getLidoApy(
|
|
|
29
28
|
provider: providers.Provider,
|
|
30
29
|
networkType: NetworkType
|
|
31
30
|
) {
|
|
32
|
-
if (!
|
|
33
|
-
throw
|
|
31
|
+
if (!lidoOracles[networkType]) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`No Lido APR oracle found on current network: ${networkType}`
|
|
34
|
+
);
|
|
34
35
|
}
|
|
35
|
-
if (!
|
|
36
|
-
throw `No Lido stETH found on current network: ${networkType}
|
|
36
|
+
if (!lidoStEth[networkType]) {
|
|
37
|
+
throw new Error(`No Lido stETH found on current network: ${networkType}`);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
const [{ postTotalPooledEther, preTotalPooledEther, timeElapsed }, fee] =
|
|
40
41
|
await geLidoData(
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
lidoOracles[networkType],
|
|
43
|
+
lidoStEth[networkType],
|
|
43
44
|
provider,
|
|
44
45
|
networkType
|
|
45
46
|
);
|
|
@@ -53,6 +54,8 @@ export async function getLidoApy(
|
|
|
53
54
|
return [lidoAPRRay, fee] as const;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
export const LIDO_FEE_DECIMALS = 10000;
|
|
58
|
+
|
|
56
59
|
async function geLidoData(
|
|
57
60
|
lidoOracleAddress: string,
|
|
58
61
|
stETHAddress: string,
|
|
@@ -84,5 +87,3 @@ async function geLidoData(
|
|
|
84
87
|
|
|
85
88
|
return [stats, fee] as const;
|
|
86
89
|
}
|
|
87
|
-
|
|
88
|
-
export const LIDO_FEE_DECIMALS = 10000;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Gearbox. Generalized leverage protocol, which allows to take leverage and then use it across other DeFi protocols and platforms in a composable way.
|
|
4
4
|
* (c) Gearbox.fi, 2021
|
|
5
5
|
*/
|
|
6
|
+
import type { YearnLPToken } from "../tokens/yearn";
|
|
6
7
|
import {
|
|
7
8
|
keyToLowercase,
|
|
8
9
|
objectEntries,
|
|
@@ -14,7 +15,7 @@ import { NetworkType } from "../core/constants";
|
|
|
14
15
|
import { Protocols } from "./protocols";
|
|
15
16
|
import { tokenDataByNetwork } from "../tokens/token";
|
|
16
17
|
import { ConvexStakedPhantomToken } from "../tokens/convex";
|
|
17
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
18
|
+
import type { CurveLPToken } from "../tokens/curveLP";
|
|
18
19
|
import { NormalToken } from "../tokens/normal";
|
|
19
20
|
|
|
20
21
|
export type UniswapV2Contract = "UNISWAP_V2_ROUTER" | "SUSHISWAP_ROUTER";
|
|
@@ -169,12 +170,14 @@ export type CurveSteCRVPoolParams = {
|
|
|
169
170
|
protocol: Protocols.Curve;
|
|
170
171
|
type: AdapterInterface.CURVE_V1_STECRV_POOL;
|
|
171
172
|
pool: Record<NetworkType, string>;
|
|
173
|
+
tokens: ["WETH", "STETH"];
|
|
172
174
|
lpToken: "steCRV";
|
|
173
175
|
} & BaseContractParams;
|
|
174
176
|
|
|
175
|
-
type YearnParams = {
|
|
177
|
+
export type YearnParams = {
|
|
176
178
|
protocol: Protocols.Yearn;
|
|
177
179
|
type: AdapterInterface.YEARN_V2;
|
|
180
|
+
shareToken: YearnLPToken;
|
|
178
181
|
} & BaseContractParams;
|
|
179
182
|
|
|
180
183
|
type ConvexParams = {
|
|
@@ -247,6 +250,7 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
|
|
|
247
250
|
Mainnet: "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022",
|
|
248
251
|
Kovan: "0xF5C73b58B70709e89aA1D322d48b0D0C71123cB4"
|
|
249
252
|
},
|
|
253
|
+
tokens: ["WETH", "STETH"],
|
|
250
254
|
lpToken: "steCRV"
|
|
251
255
|
},
|
|
252
256
|
CURVE_FRAX_POOL: {
|
|
@@ -254,14 +258,14 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
|
|
|
254
258
|
protocol: Protocols.Curve,
|
|
255
259
|
type: AdapterInterface.CURVE_V1_2ASSETS,
|
|
256
260
|
lpToken: "FRAX3CRV",
|
|
257
|
-
tokens: ["
|
|
261
|
+
tokens: ["FRAX", "3Crv"]
|
|
258
262
|
},
|
|
259
263
|
CURVE_LUSD_POOL: {
|
|
260
264
|
name: "Curve LUSD",
|
|
261
265
|
protocol: Protocols.Curve,
|
|
262
266
|
type: AdapterInterface.CURVE_V1_2ASSETS,
|
|
263
267
|
lpToken: "LUSD3CRV",
|
|
264
|
-
tokens: ["
|
|
268
|
+
tokens: ["LUSD", "3Crv"]
|
|
265
269
|
},
|
|
266
270
|
CURVE_SUSD_POOL: {
|
|
267
271
|
name: "Curve SUSD",
|
|
@@ -277,8 +281,7 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
|
|
|
277
281
|
protocol: Protocols.Curve,
|
|
278
282
|
type: AdapterInterface.CURVE_V1_WRAPPER,
|
|
279
283
|
lpToken: "crvPlain3andSUSD",
|
|
280
|
-
tokens: ["DAI", "USDC", "USDT", "sUSD"]
|
|
281
|
-
wrapper: "CURVE_SUSD_DEPOSIT"
|
|
284
|
+
tokens: ["DAI", "USDC", "USDT", "sUSD"]
|
|
282
285
|
},
|
|
283
286
|
|
|
284
287
|
CURVE_GUSD_POOL: {
|
|
@@ -286,38 +289,44 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
|
|
|
286
289
|
protocol: Protocols.Curve,
|
|
287
290
|
type: AdapterInterface.CURVE_V1_2ASSETS,
|
|
288
291
|
lpToken: "gusd3CRV",
|
|
289
|
-
tokens: ["
|
|
292
|
+
tokens: ["GUSD", "3Crv"]
|
|
290
293
|
},
|
|
291
294
|
|
|
292
295
|
YEARN_DAI_VAULT: {
|
|
293
296
|
name: "Yearn DAI",
|
|
294
297
|
protocol: Protocols.Yearn,
|
|
295
|
-
type: AdapterInterface.YEARN_V2
|
|
298
|
+
type: AdapterInterface.YEARN_V2,
|
|
299
|
+
shareToken: "yvDAI"
|
|
296
300
|
},
|
|
297
301
|
YEARN_USDC_VAULT: {
|
|
298
302
|
name: "Yearn USDC",
|
|
299
303
|
protocol: Protocols.Yearn,
|
|
300
|
-
type: AdapterInterface.YEARN_V2
|
|
304
|
+
type: AdapterInterface.YEARN_V2,
|
|
305
|
+
shareToken: "yvUSDC"
|
|
301
306
|
},
|
|
302
307
|
YEARN_WETH_VAULT: {
|
|
303
308
|
name: "Yearn WETH",
|
|
304
309
|
protocol: Protocols.Yearn,
|
|
305
|
-
type: AdapterInterface.YEARN_V2
|
|
310
|
+
type: AdapterInterface.YEARN_V2,
|
|
311
|
+
shareToken: "yvWETH"
|
|
306
312
|
},
|
|
307
313
|
YEARN_WBTC_VAULT: {
|
|
308
314
|
name: "Yearn WBTC",
|
|
309
315
|
protocol: Protocols.Yearn,
|
|
310
|
-
type: AdapterInterface.YEARN_V2
|
|
316
|
+
type: AdapterInterface.YEARN_V2,
|
|
317
|
+
shareToken: "yvWBTC"
|
|
311
318
|
},
|
|
312
319
|
YEARN_CURVE_FRAX_VAULT: {
|
|
313
320
|
name: "Yearn Curve FRAX",
|
|
314
321
|
protocol: Protocols.Yearn,
|
|
315
|
-
type: AdapterInterface.YEARN_V2
|
|
322
|
+
type: AdapterInterface.YEARN_V2,
|
|
323
|
+
shareToken: "yvCurve_FRAX"
|
|
316
324
|
},
|
|
317
325
|
YEARN_CURVE_STETH_VAULT: {
|
|
318
326
|
name: "Yearn Curve STETH",
|
|
319
327
|
protocol: Protocols.Yearn,
|
|
320
|
-
type: AdapterInterface.YEARN_V2
|
|
328
|
+
type: AdapterInterface.YEARN_V2,
|
|
329
|
+
shareToken: "yvCurve_stETH"
|
|
321
330
|
},
|
|
322
331
|
|
|
323
332
|
CONVEX_BOOSTER: {
|
|
@@ -420,9 +429,10 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
|
|
|
420
429
|
|
|
421
430
|
export const contractsByAddress = objectEntries(contractsByNetwork).reduce<
|
|
422
431
|
Record<string, SupportedContract>
|
|
423
|
-
>(
|
|
424
|
-
|
|
432
|
+
>(
|
|
433
|
+
(acc, [, contracts]) => ({
|
|
425
434
|
...acc,
|
|
426
435
|
...filterEmptyKeys(keyToLowercase(swapKeyValue(contracts)))
|
|
427
|
-
}
|
|
428
|
-
|
|
436
|
+
}),
|
|
437
|
+
{}
|
|
438
|
+
);
|
package/src/core/constants.ts
CHANGED
|
@@ -48,4 +48,4 @@ export const timeRanges: Record<string, number> = {
|
|
|
48
48
|
|
|
49
49
|
export const LEVERAGE_DECIMALS = 100;
|
|
50
50
|
export const SLIPPAGE_DECIMALS = 100;
|
|
51
|
-
export const
|
|
51
|
+
export const ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
|
|
@@ -18,19 +18,33 @@ export class CreditAccountData {
|
|
|
18
18
|
public readonly id: string;
|
|
19
19
|
|
|
20
20
|
public readonly addr: string;
|
|
21
|
+
|
|
21
22
|
public readonly borrower: string;
|
|
23
|
+
|
|
22
24
|
public readonly inUse: boolean;
|
|
25
|
+
|
|
23
26
|
public readonly creditManager: string;
|
|
27
|
+
|
|
24
28
|
public readonly underlyingToken: string;
|
|
29
|
+
|
|
25
30
|
public borrowedAmountPlusInterest: BigNumber;
|
|
31
|
+
|
|
26
32
|
public totalValue: BigNumber;
|
|
33
|
+
|
|
27
34
|
public healthFactor: number;
|
|
35
|
+
|
|
28
36
|
public borrowRate: number;
|
|
37
|
+
|
|
29
38
|
public readonly allowedTokens: Array<string> = [];
|
|
39
|
+
|
|
30
40
|
public readonly allTokens: Array<string> = [];
|
|
41
|
+
|
|
31
42
|
public balances: Record<string, BigNumber> = {};
|
|
43
|
+
|
|
32
44
|
public allBalances: Record<string, BigNumber> = {};
|
|
45
|
+
|
|
33
46
|
public isDeleting: boolean;
|
|
47
|
+
|
|
34
48
|
public readonly version: number = 1;
|
|
35
49
|
|
|
36
50
|
constructor(payload: CreditAccountDataPayload) {
|
|
@@ -94,11 +108,15 @@ export function sortBalances(
|
|
|
94
108
|
const totalPrice1 = calcTotalPrice(price1, amount1, token1?.decimals);
|
|
95
109
|
const totalPrice2 = calcTotalPrice(price2, amount2, token2?.decimals);
|
|
96
110
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
if (totalPrice1.eq(totalPrice2)) {
|
|
112
|
+
return tokensAbcComparator(token1, token2);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (totalPrice1.gt(totalPrice2)) {
|
|
116
|
+
return -1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return 1;
|
|
102
120
|
});
|
|
103
121
|
}
|
|
104
122
|
|
|
@@ -111,10 +129,15 @@ export function tokensAbcComparator(t1?: TokenData, t2?: TokenData) {
|
|
|
111
129
|
|
|
112
130
|
export class CreditAccountDataExtended extends CreditAccountData {
|
|
113
131
|
public readonly repayAmount: BigNumber;
|
|
132
|
+
|
|
114
133
|
public readonly liquidationAmount: BigNumber;
|
|
134
|
+
|
|
115
135
|
public readonly borrowedAmount: BigNumber;
|
|
136
|
+
|
|
116
137
|
public readonly canBeClosed: boolean;
|
|
138
|
+
|
|
117
139
|
public readonly cumulativeIndexAtOpen: BigNumber;
|
|
140
|
+
|
|
118
141
|
public readonly since: number;
|
|
119
142
|
|
|
120
143
|
constructor(payload: CreditAccountDataExtendedPayload) {
|
|
@@ -22,26 +22,45 @@ import { OpenAccountError } from "./errors";
|
|
|
22
22
|
|
|
23
23
|
export class CreditManagerData {
|
|
24
24
|
public readonly id: string;
|
|
25
|
+
|
|
25
26
|
public readonly address: string;
|
|
27
|
+
|
|
26
28
|
public readonly underlyingToken: string;
|
|
29
|
+
|
|
27
30
|
public readonly isWETH: boolean;
|
|
31
|
+
|
|
28
32
|
public readonly canBorrow: boolean;
|
|
33
|
+
|
|
29
34
|
public readonly borrowRate: number;
|
|
35
|
+
|
|
30
36
|
public readonly minAmount: BigNumber;
|
|
37
|
+
|
|
31
38
|
public readonly maxAmount: BigNumber;
|
|
39
|
+
|
|
32
40
|
public readonly maxLeverageFactor: number; // for V1 only
|
|
41
|
+
|
|
33
42
|
public readonly availableLiquidity: BigNumber;
|
|
43
|
+
|
|
34
44
|
public readonly allowedTokens: Array<string>;
|
|
45
|
+
|
|
35
46
|
public readonly adapters: Record<string, string>;
|
|
36
47
|
|
|
37
48
|
public readonly liquidationThresholds: Record<string, BigNumber>;
|
|
49
|
+
|
|
38
50
|
public readonly version: number;
|
|
51
|
+
|
|
39
52
|
public readonly creditFacade: string; // V2 only: address of creditFacade
|
|
53
|
+
|
|
40
54
|
public readonly isDegenMode: boolean; // V2 only: true if contract is in Degen mode
|
|
55
|
+
|
|
41
56
|
public readonly degenNFT: string; // V2 only: degenNFT, address(0) if not in degen mode
|
|
57
|
+
|
|
42
58
|
public readonly isIncreaseDebtForbidden: boolean; // V2 only: true if increasing debt is forbidden
|
|
59
|
+
|
|
43
60
|
public readonly forbiddenTokenMask: BigNumber; // V2 only: mask which forbids some particular tokens
|
|
44
61
|
|
|
62
|
+
public readonly isPaused: boolean = false;
|
|
63
|
+
|
|
45
64
|
constructor(payload: CreditManagerDataPayload) {
|
|
46
65
|
this.id = payload.addr;
|
|
47
66
|
this.address = payload.addr;
|
|
@@ -92,10 +111,6 @@ export class CreditManagerData {
|
|
|
92
111
|
this.forbiddenTokenMask = BigNumber.from(payload.forbiddenTokenMask || 0);
|
|
93
112
|
}
|
|
94
113
|
|
|
95
|
-
get isPaused(): boolean {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
114
|
getContractETH(signer: Signer | ethers.providers.Provider): ICreditManager {
|
|
100
115
|
return ICreditManager__factory.connect(this.address, signer);
|
|
101
116
|
}
|
|
@@ -229,15 +244,25 @@ export function calcHealthFactorAfterAddingCollateral(
|
|
|
229
244
|
|
|
230
245
|
export class CreditManagerStat extends CreditManagerData {
|
|
231
246
|
public readonly uniqueUsers: number;
|
|
247
|
+
|
|
232
248
|
public readonly openedAccountsCount: number;
|
|
249
|
+
|
|
233
250
|
public readonly totalOpenedAccounts: number;
|
|
251
|
+
|
|
234
252
|
public readonly totalClosedAccounts: number;
|
|
253
|
+
|
|
235
254
|
public readonly totalRepaidAccounts: number;
|
|
255
|
+
|
|
236
256
|
public readonly totalLiquidatedAccounts: number;
|
|
257
|
+
|
|
237
258
|
public readonly totalBorrowed: BigNumber;
|
|
259
|
+
|
|
238
260
|
public readonly cumulativeBorrowed: BigNumber;
|
|
261
|
+
|
|
239
262
|
public readonly totalRepaid: BigNumber;
|
|
263
|
+
|
|
240
264
|
public readonly totalProfit: BigNumber;
|
|
265
|
+
|
|
241
266
|
public readonly totalLosses: BigNumber;
|
|
242
267
|
|
|
243
268
|
constructor(payload: CreditManagerStatPayload) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface CreditOperation {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
id: number;
|
|
3
|
+
txHash: string;
|
|
4
|
+
blockNum: number;
|
|
5
|
+
protocol: string;
|
|
6
|
+
operation: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
date: string;
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
+
import moment from "moment";
|
|
2
3
|
import { CreditOperation } from "./creditOperation";
|
|
3
4
|
import { CreditSessionPayload } from "../payload/creditSession";
|
|
4
|
-
import moment from "moment";
|
|
5
5
|
import { PERCENTAGE_FACTOR } from "./constants";
|
|
6
6
|
|
|
7
7
|
export type CreditSessionStatus = "active" | "closed" | "repaid" | "liquidated";
|
|
@@ -10,29 +10,46 @@ const statusEnum: Array<CreditSessionStatus> = [
|
|
|
10
10
|
"active",
|
|
11
11
|
"closed",
|
|
12
12
|
"repaid",
|
|
13
|
-
"liquidated"
|
|
13
|
+
"liquidated"
|
|
14
14
|
];
|
|
15
15
|
|
|
16
16
|
export class CreditSession {
|
|
17
17
|
public readonly id: string;
|
|
18
18
|
|
|
19
19
|
public readonly status: CreditSessionStatus;
|
|
20
|
+
|
|
20
21
|
public readonly name: string;
|
|
22
|
+
|
|
21
23
|
public readonly background: string;
|
|
24
|
+
|
|
22
25
|
public readonly borrower: string;
|
|
26
|
+
|
|
23
27
|
public readonly creditManager: string;
|
|
28
|
+
|
|
24
29
|
public readonly account: string;
|
|
30
|
+
|
|
25
31
|
public readonly since: number;
|
|
32
|
+
|
|
26
33
|
public readonly sinceDate: string;
|
|
34
|
+
|
|
27
35
|
public readonly closedAt: number;
|
|
36
|
+
|
|
28
37
|
public readonly closedAtDate: string;
|
|
38
|
+
|
|
29
39
|
public readonly initialAmount: BigNumber;
|
|
40
|
+
|
|
30
41
|
public readonly borrowedAmount: BigNumber;
|
|
42
|
+
|
|
31
43
|
public readonly totalValue: BigNumber;
|
|
44
|
+
|
|
32
45
|
public readonly healthFactor: number;
|
|
46
|
+
|
|
33
47
|
public readonly profit: BigNumber;
|
|
48
|
+
|
|
34
49
|
public readonly profitPercentage: number;
|
|
50
|
+
|
|
35
51
|
public readonly score: number;
|
|
52
|
+
|
|
36
53
|
public readonly operations: Array<CreditOperation>;
|
|
37
54
|
|
|
38
55
|
constructor(payload: CreditSessionPayload) {
|
|
@@ -53,9 +70,12 @@ export class CreditSession {
|
|
|
53
70
|
this.healthFactor =
|
|
54
71
|
BigNumber.from(payload.healthFactor || 0).toNumber() / PERCENTAGE_FACTOR;
|
|
55
72
|
this.score = payload.score;
|
|
56
|
-
this.operations = (payload.operations || []).map(
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
this.operations = (payload.operations || []).map(op => {
|
|
74
|
+
const formattedOp = {
|
|
75
|
+
...op,
|
|
76
|
+
date: moment(op.timestamp * 1000).format("Do MMM YYYY")
|
|
77
|
+
};
|
|
78
|
+
return formattedOp;
|
|
59
79
|
});
|
|
60
80
|
this.sinceDate = moment(payload.sinceTimestamp * 1000).format(
|
|
61
81
|
"Do MMM YYYY"
|
package/src/core/errors.ts
CHANGED