@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.
Files changed (129) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.js +3 -5
  5. package/lib/apy/lidoAPY.js +8 -9
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/core/constants.d.ts +1 -1
  9. package/lib/core/constants.js +2 -2
  10. package/lib/core/creditAccount.js +7 -5
  11. package/lib/core/creditManager.d.ts +1 -1
  12. package/lib/core/creditManager.js +1 -7
  13. package/lib/core/creditSession.js +14 -3
  14. package/lib/core/eventOrTx.d.ts +1 -1
  15. package/lib/core/events.d.ts +19 -19
  16. package/lib/core/events.js +23 -21
  17. package/lib/core/pool.d.ts +1 -1
  18. package/lib/core/pool.js +1 -7
  19. package/lib/core/price.js +6 -1
  20. package/lib/core/strategy.d.ts +1 -3
  21. package/lib/core/strategy.js +14 -13
  22. package/lib/core/tokenDistributor.js +1 -1
  23. package/lib/core/transactions.d.ts +18 -3
  24. package/lib/core/transactions.js +39 -3
  25. package/lib/index.d.ts +8 -2
  26. package/lib/index.js +8 -1
  27. package/lib/oracles/priceFeeds.js +1 -1
  28. package/lib/pathfinder/convexLP.d.ts +1 -1
  29. package/lib/pathfinder/convexLP.js +26 -29
  30. package/lib/pathfinder/curveLP.d.ts +1 -1
  31. package/lib/pathfinder/curveLP.js +5 -7
  32. package/lib/pathfinder/path.d.ts +1 -1
  33. package/lib/pathfinder/path.js +38 -42
  34. package/lib/pathfinder/trade.d.ts +1 -2
  35. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  36. package/lib/pathfinder/yVault.d.ts +2 -2
  37. package/lib/pathfinder/yVault.js +18 -15
  38. package/lib/strategies/convex.d.ts +12 -0
  39. package/lib/strategies/convex.js +74 -1
  40. package/lib/strategies/creditFacade.d.ts +1 -0
  41. package/lib/strategies/creditFacade.js +3 -0
  42. package/lib/strategies/curve.d.ts +15 -60
  43. package/lib/strategies/curve.js +74 -1
  44. package/lib/strategies/lido.d.ts +6 -0
  45. package/lib/strategies/lido.js +23 -1
  46. package/lib/strategies/uniswapV2.d.ts +1 -0
  47. package/lib/strategies/uniswapV2.js +6 -19
  48. package/lib/strategies/uniswapV3.d.ts +1 -0
  49. package/lib/strategies/uniswapV3.js +4 -1
  50. package/lib/strategies/yearn.d.ts +8 -0
  51. package/lib/strategies/yearn.js +92 -12
  52. package/lib/tokens/convex.d.ts +3 -3
  53. package/lib/tokens/curveLP.d.ts +7 -2
  54. package/lib/tokens/curveLP.js +8 -1
  55. package/lib/tokens/gear.d.ts +2 -2
  56. package/lib/tokens/gear.js +1 -1
  57. package/lib/tokens/normal.d.ts +1 -1
  58. package/lib/tokens/token.js +4 -4
  59. package/lib/tokens/tokenData.d.ts +3 -1
  60. package/lib/tokens/tokenData.js +10 -8
  61. package/lib/tokens/yearn.d.ts +6 -2
  62. package/lib/tokens/yearn.js +6 -0
  63. package/lib/utils/errors.d.ts +6 -0
  64. package/lib/utils/errors.js +13 -0
  65. package/lib/utils/formatter.d.ts +1 -1
  66. package/lib/utils/formatter.js +17 -14
  67. package/lib/utils/loading.d.ts +2 -1
  68. package/lib/utils/loading.js +9 -13
  69. package/lib/utils/mappers.js +2 -2
  70. package/lib/utils/network.js +2 -2
  71. package/lib/utils/repeater.js +12 -24
  72. package/lib/utils/validate.js +1 -1
  73. package/package.json +24 -7
  74. package/src/apy/convexAPY.ts +6 -6
  75. package/src/apy/lidoAPY.ts +12 -11
  76. package/src/contracts/contracts.ts +27 -17
  77. package/src/core/constants.ts +1 -1
  78. package/src/core/creditAccount.ts +28 -5
  79. package/src/core/creditManager.ts +29 -4
  80. package/src/core/creditOperation.ts +7 -7
  81. package/src/core/creditSession.ts +25 -5
  82. package/src/core/errors.ts +1 -0
  83. package/src/core/eventOrTx.ts +8 -5
  84. package/src/core/events.ts +85 -24
  85. package/src/core/history.ts +46 -46
  86. package/src/core/operations.ts +6 -0
  87. package/src/core/pool.ts +16 -4
  88. package/src/core/price.ts +7 -3
  89. package/src/core/strategy.ts +27 -23
  90. package/src/core/tokenDistributor.ts +2 -2
  91. package/src/core/transactions.ts +427 -350
  92. package/src/index.ts +10 -3
  93. package/src/oracles/priceFeeds.ts +523 -523
  94. package/src/pathfinder/contracts.ts +15 -13
  95. package/src/pathfinder/convexLP.ts +29 -25
  96. package/src/pathfinder/curveLP.ts +57 -53
  97. package/src/pathfinder/path.ts +17 -9
  98. package/src/pathfinder/priority.ts +11 -11
  99. package/src/pathfinder/trade.ts +84 -77
  100. package/src/pathfinder/tradeTypes.ts +98 -94
  101. package/src/pathfinder/yVault.ts +26 -11
  102. package/src/payload/token.ts +3 -3
  103. package/src/strategies/convex.ts +361 -186
  104. package/src/strategies/creditFacade.ts +74 -53
  105. package/src/strategies/curve.ts +400 -189
  106. package/src/strategies/lido.ts +70 -32
  107. package/src/strategies/uniswapV2.ts +93 -111
  108. package/src/strategies/uniswapV3.ts +118 -91
  109. package/src/strategies/yearn.ts +187 -60
  110. package/src/tokens/connectors.ts +6 -6
  111. package/src/tokens/convex.ts +297 -296
  112. package/src/tokens/curveLP.ts +176 -165
  113. package/src/tokens/gear.ts +47 -45
  114. package/src/tokens/normal.ts +801 -802
  115. package/src/tokens/token.ts +9 -5
  116. package/src/tokens/tokenData.ts +19 -9
  117. package/src/tokens/tokenType.ts +11 -11
  118. package/src/tokens/yearn.ts +130 -124
  119. package/src/utils/errors.ts +11 -0
  120. package/src/utils/formatter.ts +22 -18
  121. package/src/utils/loading.ts +14 -6
  122. package/src/utils/mappers.ts +8 -6
  123. package/src/utils/multicall.ts +2 -0
  124. package/src/utils/network.ts +21 -21
  125. package/src/utils/repeater.ts +2 -2
  126. package/src/utils/validate.ts +1 -1
  127. package/lib/utils/events.d.ts +0 -2
  128. package/lib/utils/events.js +0 -13
  129. package/src/utils/events.ts +0 -10
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadingProgress = void 0;
4
- function loadingProgress() {
5
- var params = [];
6
- for (var _i = 0; _i < arguments.length; _i++) {
7
- params[_i] = arguments[_i];
8
- }
9
- var isLoaded = 0;
10
- for (var _a = 0, params_1 = params; _a < params_1.length; _a++) {
11
- var item = params_1[_a];
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;
@@ -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 !!key ? __assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)) : acc;
38
+ return (key ? __assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)) : acc);
39
39
  }, {});
40
40
  };
41
41
  exports.filterEmptyKeys = filterEmptyKeys;
@@ -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.ADDRESS_0x0)];
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.ADDRESS_0x0)];
61
+ return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
62
62
  case 4:
63
63
  _c.sent();
64
64
  return [2 /*return*/, "Kovan"];
@@ -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) { return __awaiter(_this, void 0, void 0, function () {
46
- var _a, e_1;
47
- return __generator(this, function (_b) {
48
- switch (_b.label) {
49
- case 0:
50
- _b.trys.push([0, 2, , 3]);
51
- _a = resolve;
52
- return [4 /*yield*/, call()];
53
- case 1:
54
- _a.apply(void 0, [_b.sent()]);
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
  }
@@ -6,7 +6,7 @@ function isPositiveFloat(val) {
6
6
  if (!floatRegex.test(val))
7
7
  return false;
8
8
  var valF = parseFloat(val);
9
- if (isNaN(valF))
9
+ if (Number.isNaN(valF))
10
10
  return false;
11
11
  return true;
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "0.0.102",
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.4",
20
- "@types/node": "^14.0.23",
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
- "ethers": "^5.6.5",
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.3.0",
42
+ "prettier": "^2.7.1",
26
43
  "ts-node": "^10.1.0",
27
44
  "tslog": "^3.3.3",
28
- "typescript": "^4.2.4"
45
+ "typescript": "^4.7.3"
29
46
  }
30
47
  }
@@ -73,14 +73,14 @@ export async function getConvexApy(
73
73
  poolParams.stakedToken
74
74
  ] as ConvexPhantomTokenData;
75
75
 
76
- const underlying = stakedTokenParams.underlying;
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(d => {
82
- return d.poolAddress[networkType];
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["CVX"]);
95
- const crvPrice = getTokenPrice(tokenList["CRV"]);
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);
@@ -17,10 +17,9 @@ type ILidoOracleInterface = ILidoOracle["interface"];
17
17
 
18
18
  type IstETHInterface = IstETH["interface"];
19
19
 
20
- const lidoOracleAddress = (contractParams.LIDO_STETH_GATEWAY as LidoParams)
21
- .oracle;
20
+ const lidoOracles = (contractParams.LIDO_STETH_GATEWAY as LidoParams).oracle;
22
21
 
23
- const lidoStEthAddress: Record<NetworkType, string> = {
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 (!lidoOracleAddress[networkType]) {
33
- throw `No Lido APR oracle found on current network: ${networkType}`;
31
+ if (!lidoOracles[networkType]) {
32
+ throw new Error(
33
+ `No Lido APR oracle found on current network: ${networkType}`
34
+ );
34
35
  }
35
- if (!lidoStEthAddress[networkType]) {
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
- lidoOracleAddress[networkType],
42
- lidoStEthAddress[networkType],
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: ["3Crv", "FRAX"]
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: ["3Crv", "LUSD"]
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: ["3Crv", "FRAX"]
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
- >((acc, [_, contracts]) => {
424
- return {
432
+ >(
433
+ (acc, [, contracts]) => ({
425
434
  ...acc,
426
435
  ...filterEmptyKeys(keyToLowercase(swapKeyValue(contracts)))
427
- };
428
- }, {});
436
+ }),
437
+ {}
438
+ );
@@ -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 ADDRESS_0x0 = "0x0000000000000000000000000000000000000000";
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
- return totalPrice1.eq(totalPrice2)
98
- ? tokensAbcComparator(token1, token2)
99
- : totalPrice1.gt(totalPrice2)
100
- ? -1
101
- : 1;
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
- id: number,
3
- txHash: string,
4
- blockNum: number,
5
- protocol: string,
6
- operation: string,
7
- timestamp: number,
8
- date: string
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((op) => {
57
- op.date = moment(op.timestamp * 1000).format("Do MMM YYYY");
58
- return op;
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"
@@ -54,6 +54,7 @@ export type OpenAccountErrorTypes =
54
54
 
55
55
  export class OpenAccountError extends Error {
56
56
  message: OpenAccountErrorTypes;
57
+
57
58
  payload: { amount: BigNumber };
58
59
 
59
60
  constructor(errorType: OpenAccountErrorTypes, amount: BigNumber) {