@gearbox-protocol/sdk 0.0.107 → 0.0.110

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 (118) hide show
  1. package/lib/apy/convexAPY copy.d.ts +6 -0
  2. package/lib/apy/convexAPY copy.js +201 -0
  3. package/lib/apy/convexAPY.d.ts +9 -5
  4. package/lib/apy/convexAPY.js +29 -69
  5. package/lib/apy/curveAPY.d.ts +4 -0
  6. package/lib/apy/curveAPY.js +94 -0
  7. package/lib/apy/index.d.ts +6 -0
  8. package/lib/apy/index.js +20 -0
  9. package/lib/apy/lidoAPY.d.ts +1 -1
  10. package/lib/apy/lidoAPY.js +3 -3
  11. package/lib/apy/yearnAPY.d.ts +4 -0
  12. package/lib/apy/yearnAPY.js +90 -0
  13. package/lib/contracts/contractsRegister.js +2 -1
  14. package/lib/core/creditAccount.d.ts +2 -1
  15. package/lib/core/creditAccount.js +19 -12
  16. package/lib/core/creditManager.d.ts +3 -1
  17. package/lib/core/creditManager.js +25 -9
  18. package/lib/core/errors.d.ts +1 -1
  19. package/lib/core/pool.js +4 -4
  20. package/lib/core/strategy.d.ts +5 -3
  21. package/lib/core/strategy.js +6 -4
  22. package/lib/index.d.ts +4 -4
  23. package/lib/index.js +7 -6
  24. package/lib/strategies/curve.js +8 -10
  25. package/lib/strategies/yearn.js +8 -4
  26. package/lib/tokens/convex.d.ts +3 -0
  27. package/lib/tokens/convex.js +44 -18
  28. package/lib/tokens/curveLP.d.ts +1 -0
  29. package/lib/tokens/curveLP.js +11 -7
  30. package/lib/tokens/normal.d.ts +1 -0
  31. package/lib/tokens/normal.js +5 -1
  32. package/lib/tokens/token.d.ts +7 -2
  33. package/lib/tokens/token.js +10 -1
  34. package/lib/tokens/tokenData.js +2 -3
  35. package/lib/tokens/yearn.d.ts +1 -0
  36. package/lib/tokens/yearn.js +11 -7
  37. package/lib/utils/extracter.d.ts +11 -0
  38. package/lib/utils/extracter.js +19 -0
  39. package/lib/utils/mappers.d.ts +2 -2
  40. package/lib/utils/price.d.ts +8 -0
  41. package/lib/utils/price.js +26 -0
  42. package/package.json +1 -1
  43. package/src/apy/convexAPY.ts +47 -96
  44. package/src/apy/curveAPY.ts +68 -0
  45. package/src/apy/index.ts +8 -0
  46. package/src/apy/lidoAPY.ts +1 -1
  47. package/src/apy/yearnAPY.ts +66 -0
  48. package/src/contracts/contractsRegister.ts +2 -1
  49. package/src/core/creditAccount.ts +20 -12
  50. package/src/core/creditManager.ts +38 -11
  51. package/src/core/errors.ts +1 -0
  52. package/src/core/pool.ts +4 -4
  53. package/src/core/strategy.ts +16 -10
  54. package/src/index.ts +4 -4
  55. package/src/strategies/convex.ts +9 -3
  56. package/src/strategies/curve.ts +26 -18
  57. package/src/strategies/lido.ts +6 -2
  58. package/src/strategies/yearn.ts +17 -6
  59. package/src/tokens/convex.ts +43 -20
  60. package/src/tokens/curveLP.ts +9 -6
  61. package/src/tokens/normal.ts +3 -0
  62. package/src/tokens/token.ts +24 -6
  63. package/src/tokens/tokenData.ts +2 -4
  64. package/src/tokens/yearn.ts +9 -6
  65. package/src/utils/extracter.ts +30 -0
  66. package/src/utils/mappers.ts +2 -2
  67. package/src/utils/price.ts +33 -0
  68. package/lib/core/price.d.ts +0 -2
  69. package/lib/core/price.js +0 -14
  70. package/lib/types/@chainlink/contracts/src/v0.6/index.d.ts +0 -2
  71. package/lib/types/@chainlink/contracts/src/v0.6/index.js +0 -2
  72. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.d.ts +0 -146
  73. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.js +0 -2
  74. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
  75. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -2
  76. package/lib/types/contracts/integrations/lido/IstETH.d.ts +0 -154
  77. package/lib/types/contracts/integrations/lido/IstETH.js +0 -2
  78. package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.d.ts +0 -50
  79. package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.js +0 -2
  80. package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.d.ts +0 -27
  81. package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.js +0 -2
  82. package/lib/types/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
  83. package/lib/types/contracts/pathfinder/Balances.sol/index.js +0 -2
  84. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.d.ts +0 -269
  85. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.js +0 -2
  86. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
  87. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -2
  88. package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.d.ts +0 -58
  89. package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.js +0 -2
  90. package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.d.ts +0 -528
  91. package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.js +0 -2
  92. package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.d.ts +0 -528
  93. package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.js +0 -2
  94. package/lib/types/factories/@chainlink/contracts/src/v0.6/index.d.ts +0 -1
  95. package/lib/types/factories/@chainlink/contracts/src/v0.6/index.js +0 -30
  96. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.d.ts +0 -22
  97. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.js +0 -133
  98. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
  99. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -8
  100. package/lib/types/factories/contracts/integrations/lido/IstETH__factory.d.ts +0 -35
  101. package/lib/types/factories/contracts/integrations/lido/IstETH__factory.js +0 -224
  102. package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.d.ts +0 -18
  103. package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.js +0 -40
  104. package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.d.ts +0 -28
  105. package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.js +0 -76
  106. package/lib/types/factories/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
  107. package/lib/types/factories/contracts/pathfinder/Balances.sol/index.js +0 -8
  108. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.d.ts +0 -144
  109. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.js +0 -522
  110. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
  111. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -8
  112. package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.d.ts +0 -34
  113. package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.js +0 -110
  114. package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.d.ts +0 -65
  115. package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.js +0 -775
  116. package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.d.ts +0 -65
  117. package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.js +0 -775
  118. package/src/core/price.ts +0 -13
@@ -4,13 +4,18 @@ import { CurveLPToken, CurveLPTokenData, MetaCurveLPTokenData } from "./curveLP"
4
4
  import { YearnLPToken, YearnVaultOfCurveLPTokenData, YearnVaultOfMetaCurveLPTokenData, YearnVaultTokenData } from "./yearn";
5
5
  import { ConvexLPToken, ConvexLPTokenData, ConvexPhantomTokenData, ConvexStakedPhantomToken } from "./convex";
6
6
  import { DieselTokenData, DieselTokenTypes, GearboxToken, GearboxTokenData } from "./gear";
7
- export declare type SupportedToken = NormalToken | YearnLPToken | CurveLPToken | ConvexLPToken | ConvexStakedPhantomToken | DieselTokenTypes | GearboxToken;
7
+ export declare type LPTokens = YearnLPToken | CurveLPToken | ConvexLPToken | ConvexStakedPhantomToken;
8
+ export declare type SupportedToken = NormalToken | LPTokens | DieselTokenTypes | GearboxToken;
8
9
  export interface TokenBase {
9
10
  name: string;
10
11
  symbol: string;
11
12
  decimals: number;
12
13
  }
13
- export declare type TokenDataI = NormalTokenData | CurveLPTokenData | MetaCurveLPTokenData | YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData | ConvexLPTokenData | ConvexPhantomTokenData | DieselTokenData | GearboxTokenData;
14
+ export declare type LPTokenDataI = CurveLPTokenData | MetaCurveLPTokenData | YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData | ConvexLPTokenData | ConvexPhantomTokenData;
15
+ export declare type TokenDataI = NormalTokenData | LPTokenDataI | DieselTokenData | GearboxTokenData;
16
+ export declare const lpTokens: Record<LPTokens, LPTokenDataI>;
14
17
  export declare const supportedTokens: Record<SupportedToken, TokenDataI>;
15
18
  export declare const tokenDataByNetwork: Record<NetworkType, Record<SupportedToken, string>>;
16
19
  export declare const tokenSymbolByAddress: Record<string, SupportedToken>;
20
+ export declare const isSupportedToken: (t: unknown) => t is SupportedToken;
21
+ export declare const isLPToken: (t: unknown) => t is LPTokens;
@@ -11,13 +11,14 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.tokenSymbolByAddress = exports.tokenDataByNetwork = exports.supportedTokens = void 0;
14
+ exports.isLPToken = exports.isSupportedToken = exports.tokenSymbolByAddress = exports.tokenDataByNetwork = exports.supportedTokens = exports.lpTokens = void 0;
15
15
  var mappers_1 = require("../utils/mappers");
16
16
  var normal_1 = require("./normal");
17
17
  var curveLP_1 = require("./curveLP");
18
18
  var yearn_1 = require("./yearn");
19
19
  var convex_1 = require("./convex");
20
20
  var gear_1 = require("./gear");
21
+ exports.lpTokens = __assign(__assign(__assign({}, curveLP_1.curveTokens), convex_1.convexTokens), yearn_1.yearnTokens);
21
22
  exports.supportedTokens = __assign(__assign(__assign(__assign(__assign({}, normal_1.normalTokens), curveLP_1.curveTokens), convex_1.convexTokens), yearn_1.yearnTokens), gear_1.gearTokens);
22
23
  exports.tokenDataByNetwork = {
23
24
  //
@@ -162,3 +163,11 @@ exports.tokenSymbolByAddress = (0, mappers_1.objectEntries)(exports.tokenDataByN
162
163
  var tokens = _a[1];
163
164
  return (__assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(tokens)))));
164
165
  }, {});
166
+ var isSupportedToken = function (t) {
167
+ return typeof t === "string" && !!exports.supportedTokens[t];
168
+ };
169
+ exports.isSupportedToken = isSupportedToken;
170
+ var isLPToken = function (t) {
171
+ return typeof t === "string" && !!exports.supportedTokens[t];
172
+ };
173
+ exports.isLPToken = isLPToken;
@@ -11,9 +11,8 @@ var TokenData = /** @class */ (function () {
11
11
  function TokenData(payload, symbolReplacements) {
12
12
  if (symbolReplacements === void 0) { symbolReplacements = defaultSymbolReplacement; }
13
13
  var _a;
14
- this.id = payload.addr;
15
- this.address = payload.addr;
16
- // this.name = payload.name;
14
+ this.id = payload.addr.toLowerCase();
15
+ this.address = payload.addr.toLowerCase();
17
16
  this.symbol = symbolReplacements[payload.symbol] || payload.symbol;
18
17
  this.decimals = payload.decimals;
19
18
  this.icon = "".concat(config_1.STATIC_TOKEN).concat((_a = payload.symbol) === null || _a === void 0 ? void 0 : _a.toLowerCase(), ".svg");
@@ -27,3 +27,4 @@ export declare type YearnVaultOfMetaCurveLPTokenData = {
27
27
  vault: YearnVaultContract;
28
28
  } & TokenBase;
29
29
  export declare const yearnTokens: Record<YearnLPToken, YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData>;
30
+ export declare const isYearnLPToken: (t: unknown) => t is YearnLPToken;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.yearnTokens = void 0;
3
+ exports.isYearnLPToken = exports.yearnTokens = void 0;
4
4
  var tradeTypes_1 = require("../pathfinder/tradeTypes");
5
5
  var tokenType_1 = require("./tokenType");
6
6
  exports.yearnTokens = {
7
7
  // YEARN TOKENS
8
8
  yvDAI: {
9
- name: "yvDAI",
9
+ name: "Yearn yvDAI",
10
10
  decimals: 18,
11
11
  symbol: "yvDAI",
12
12
  type: tokenType_1.TokenType.YEARN_VAULT,
@@ -21,7 +21,7 @@ exports.yearnTokens = {
21
21
  ]
22
22
  },
23
23
  yvUSDC: {
24
- name: "yvUSDC",
24
+ name: "Yearn yvUSDC",
25
25
  decimals: 6,
26
26
  symbol: "yvUSDC",
27
27
  type: tokenType_1.TokenType.YEARN_VAULT,
@@ -36,7 +36,7 @@ exports.yearnTokens = {
36
36
  ]
37
37
  },
38
38
  yvWETH: {
39
- name: "yvWETH",
39
+ name: "Yearn yvWETH",
40
40
  decimals: 18,
41
41
  symbol: "yvWETH",
42
42
  type: tokenType_1.TokenType.YEARN_VAULT,
@@ -51,7 +51,7 @@ exports.yearnTokens = {
51
51
  ]
52
52
  },
53
53
  yvWBTC: {
54
- name: "yvWBTC",
54
+ name: "Yearn yvWBTC",
55
55
  decimals: 8,
56
56
  symbol: "yvWBTC",
57
57
  type: tokenType_1.TokenType.YEARN_VAULT,
@@ -67,7 +67,7 @@ exports.yearnTokens = {
67
67
  },
68
68
  // YEARN- CURVE TOKENS
69
69
  yvCurve_stETH: {
70
- name: "yvCurve-stETH",
70
+ name: "Yearn yvCurve-stETH",
71
71
  decimals: 18,
72
72
  symbol: "yvCurve_stETH",
73
73
  type: tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP,
@@ -82,7 +82,7 @@ exports.yearnTokens = {
82
82
  ]
83
83
  },
84
84
  yvCurve_FRAX: {
85
- name: "yvCurve-FRAX",
85
+ name: "Yearn yvCurve-FRAX",
86
86
  decimals: 18,
87
87
  symbol: "yvCurve_FRAX",
88
88
  type: tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP,
@@ -97,3 +97,7 @@ exports.yearnTokens = {
97
97
  ]
98
98
  }
99
99
  };
100
+ var isYearnLPToken = function (t) {
101
+ return typeof t === "string" && !!exports.yearnTokens[t];
102
+ };
103
+ exports.isYearnLPToken = isYearnLPToken;
@@ -0,0 +1,11 @@
1
+ import { PoolData } from "../core/pool";
2
+ export interface PoolTokens {
3
+ dieselToken: string | undefined;
4
+ underlyingToken: string | undefined;
5
+ }
6
+ export declare function getPoolTokens(pool: PoolData | undefined | Error): PoolTokens;
7
+ interface WithUnderlyingToken {
8
+ readonly underlyingToken: string;
9
+ }
10
+ export declare function getUnderlyingToken(c: WithUnderlyingToken | undefined | Error): string | undefined;
11
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUnderlyingToken = exports.getPoolTokens = void 0;
4
+ function getPoolTokens(pool) {
5
+ var safePool = pool instanceof Error ? undefined : pool;
6
+ var _a = safePool || {}, dieselToken = _a.dieselToken, underlyingToken = _a.underlyingToken;
7
+ return {
8
+ dieselToken: dieselToken,
9
+ underlyingToken: underlyingToken
10
+ };
11
+ }
12
+ exports.getPoolTokens = getPoolTokens;
13
+ function getUnderlyingToken(c) {
14
+ if (!c || c instanceof Error) {
15
+ return undefined;
16
+ }
17
+ return c.underlyingToken;
18
+ }
19
+ exports.getUnderlyingToken = getUnderlyingToken;
@@ -1,7 +1,7 @@
1
1
  declare type SupportedValue = string | number;
2
2
  declare const objectEntries: <K extends SupportedValue, T>(o: Record<K, T>) => [K, T][];
3
3
  declare const swapKeyValue: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<T, K>;
4
- declare const keyToLowercase: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<K, T>;
5
- declare const filterEmptyKeys: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<K, T>;
4
+ declare const keyToLowercase: <K extends SupportedValue, T>(o: Record<K, T>) => Record<K, T>;
5
+ declare const filterEmptyKeys: <K extends SupportedValue, T>(o: Record<K, T>) => Record<K, T>;
6
6
  export type { SupportedValue };
7
7
  export { objectEntries, swapKeyValue, keyToLowercase, filterEmptyKeys };
@@ -0,0 +1,8 @@
1
+ import { BigNumber } from "ethers";
2
+ export declare const calcTotalPrice: (price: BigNumber, amount: BigNumber, decimals?: number) => BigNumber;
3
+ interface Target {
4
+ price: BigNumber;
5
+ decimals: number | undefined;
6
+ }
7
+ export declare function convertByPrice(totalMoney: BigNumber, { price: targetPrice, decimals: targetDecimals }: Target): BigNumber;
8
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertByPrice = exports.calcTotalPrice = void 0;
4
+ var ethers_1 = require("ethers");
5
+ var constants_1 = require("../core/constants");
6
+ var calcTotalPrice = function (price, amount, decimals) {
7
+ if (decimals === void 0) { decimals = 18; }
8
+ return amount
9
+ .mul(constants_1.WAD)
10
+ .mul(price)
11
+ .div(ethers_1.BigNumber.from(10).pow(decimals))
12
+ .div(constants_1.PRICE_DECIMALS);
13
+ };
14
+ exports.calcTotalPrice = calcTotalPrice;
15
+ function convertByPrice(totalMoney, _a) {
16
+ var targetPrice = _a.price, _b = _a.decimals, targetDecimals = _b === void 0 ? 18 : _b;
17
+ var isWrongTargetPrice = targetPrice.isZero() || targetPrice.isNegative();
18
+ return isWrongTargetPrice
19
+ ? ethers_1.BigNumber.from(0)
20
+ : totalMoney
21
+ .mul(ethers_1.BigNumber.from(10).pow(targetDecimals))
22
+ .mul(constants_1.PRICE_DECIMALS)
23
+ .div(targetPrice)
24
+ .div(constants_1.WAD);
25
+ }
26
+ exports.convertByPrice = convertByPrice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "0.0.107",
3
+ "version": "0.0.110",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1,15 +1,13 @@
1
1
  import { BigNumber, providers } from "ethers";
2
- import axios from "axios";
3
2
  import {
4
3
  ConvexPoolContract,
5
4
  ConvexPoolParams,
6
5
  contractsByNetwork,
7
- contractParams,
8
- CurvePoolContract
6
+ contractParams
9
7
  } from "../contracts/contracts";
10
8
 
11
9
  import { tokenDataByNetwork, supportedTokens } from "../tokens/token";
12
- import { CurveLPToken } from "../tokens/curveLP";
10
+ import { CurveLPTokenData } from "../tokens/curveLP";
13
11
  import { ConvexPhantomTokenData } from "../tokens/convex";
14
12
 
15
13
  import {
@@ -22,49 +20,32 @@ import {
22
20
  } from "../types";
23
21
 
24
22
  import { multicall, MCall } from "../utils/multicall";
25
- import { toBN } from "../utils/formatter";
26
23
  import { AwaitedRes } from "../utils/types";
27
24
 
28
25
  import {
29
26
  SECONDS_PER_YEAR,
30
27
  WAD,
31
- WAD_DECIMALS_POW,
32
28
  NetworkType,
33
29
  PRICE_DECIMALS
34
30
  } from "../core/constants";
35
31
 
36
- type SupportedPools = Extract<
37
- ConvexPoolContract,
38
- | "CONVEX_3CRV_POOL"
39
- | "CONVEX_FRAX3CRV_POOL"
40
- | "CONVEX_LUSD3CRV_POOL"
41
- | "CONVEX_GUSD_POOL"
42
- | "CONVEX_SUSD_POOL"
43
- >;
44
-
45
- type SupportedConvex = Extract<
46
- CurvePoolContract,
47
- | "CURVE_3CRV_POOL"
48
- | "CURVE_FRAX_POOL"
49
- | "CURVE_LUSD_POOL"
50
- | "CURVE_GUSD_POOL"
51
- | "CURVE_SUSD_POOL"
52
- >;
53
-
54
- const curveSwapByPool: Record<SupportedPools, SupportedConvex> = {
55
- CONVEX_3CRV_POOL: "CURVE_3CRV_POOL",
56
- CONVEX_FRAX3CRV_POOL: "CURVE_FRAX_POOL",
57
- CONVEX_LUSD3CRV_POOL: "CURVE_LUSD_POOL",
58
- CONVEX_GUSD_POOL: "CURVE_GUSD_POOL",
59
- CONVEX_SUSD_POOL: "CURVE_SUSD_POOL"
60
- };
61
-
62
- export async function getConvexApy(
63
- pool: SupportedPools,
64
- provider: providers.Provider,
65
- networkType: NetworkType,
66
- getTokenPrice: (tokenAddress: string) => BigNumber
67
- ) {
32
+ import { CurveAPYResult } from "./curveAPY";
33
+
34
+ export interface GetConvexAPYProps {
35
+ pool: ConvexPoolContract;
36
+ provider: providers.Provider;
37
+ networkType: NetworkType;
38
+ getTokenPrice: (tokenAddress: string) => BigNumber;
39
+ curveAPY: CurveAPYResult;
40
+ }
41
+
42
+ export async function getConvexAPY({
43
+ pool,
44
+ provider,
45
+ networkType,
46
+ getTokenPrice,
47
+ curveAPY
48
+ }: GetConvexAPYProps) {
68
49
  const tokenList = tokenDataByNetwork[networkType];
69
50
  const contractsList = contractsByNetwork[networkType];
70
51
 
@@ -75,7 +56,10 @@ export async function getConvexApy(
75
56
 
76
57
  const { underlying } = stakedTokenParams;
77
58
  const basePoolAddress = contractsList[pool];
78
- const swapPoolAddress = contractsList[curveSwapByPool[pool]];
59
+
60
+ const crvParams = supportedTokens[underlying] as CurveLPTokenData;
61
+
62
+ const swapPoolAddress = contractsList[crvParams.pool];
79
63
  const cvxAddress = tokenList.CVX;
80
64
 
81
65
  const extraPoolAddresses = poolParams.extraRewards.map(
@@ -83,13 +67,13 @@ export async function getConvexApy(
83
67
  );
84
68
 
85
69
  const [basePoolRate, basePoolSupply, vPrice, cvxSupply, ...extra] =
86
- await getPoolData(
70
+ await getPoolData({
87
71
  basePoolAddress,
88
72
  swapPoolAddress,
89
73
  cvxAddress,
90
74
  extraPoolAddresses,
91
75
  provider
92
- );
76
+ });
93
77
 
94
78
  const cvxPrice = getTokenPrice(tokenList.CVX);
95
79
  const crvPrice = getTokenPrice(tokenList.CRV);
@@ -101,8 +85,8 @@ export async function getConvexApy(
101
85
  const crvPerYear = crvPerUnderlying.mul(SECONDS_PER_YEAR);
102
86
  const cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
103
87
 
104
- const crvAPY = crvPerYear.mul(cvxPrice).div(PRICE_DECIMALS);
105
- const cvxAPY = cvxPerYear.mul(crvPrice).div(PRICE_DECIMALS);
88
+ const crvAPY = crvPerYear.mul(crvPrice).div(PRICE_DECIMALS);
89
+ const cvxAPY = cvxPerYear.mul(cvxPrice).div(PRICE_DECIMALS);
106
90
 
107
91
  const extraAPRs = await Promise.all(
108
92
  extraPoolAddresses.map(async (_, index) => {
@@ -112,9 +96,9 @@ export async function getConvexApy(
112
96
  const perUnderlying = extraPoolRate.mul(WAD).div(virtualSupply);
113
97
  const perYear = perUnderlying.mul(SECONDS_PER_YEAR);
114
98
 
115
- const extraPrise = getTokenPrice(tokenList[extraRewardSymbol]);
99
+ const extraPrice = getTokenPrice(tokenList[extraRewardSymbol]);
116
100
 
117
- const extraAPY = perYear.mul(extraPrise).div(PRICE_DECIMALS);
101
+ const extraAPY = perYear.mul(extraPrice).div(PRICE_DECIMALS);
118
102
 
119
103
  return extraAPY;
120
104
  })
@@ -125,9 +109,9 @@ export async function getConvexApy(
125
109
  BigNumber.from(0)
126
110
  );
127
111
 
128
- const baseApyRAY = await getCurveBaseApy(underlying);
112
+ const baseApyWAD = curveAPY[underlying];
129
113
 
130
- return baseApyRAY.add(crvAPY).add(cvxAPY).add(extraAPYTotal);
114
+ return baseApyWAD.add(crvAPY).add(cvxAPY).add(extraAPYTotal);
131
115
  }
132
116
 
133
117
  const CVX_MAX_SUPPLY = WAD.mul(100000000);
@@ -154,13 +138,21 @@ type IBaseRewardPoolInterface = IBaseRewardPool["interface"];
154
138
  type IConvexTokenInterface = IConvexToken["interface"];
155
139
  type CurveV1AdapterStETHInterface = CurveV1AdapterStETH["interface"];
156
140
 
157
- async function getPoolData(
158
- basePoolAddress: string,
159
- underlying: string,
160
- cvxAddress: string,
161
- extraPoolAddresses: string[],
162
- provider: providers.Provider
163
- ) {
141
+ interface GetPoolDataProps {
142
+ basePoolAddress: string;
143
+ swapPoolAddress: string;
144
+ cvxAddress: string;
145
+ extraPoolAddresses: string[];
146
+ provider: providers.Provider;
147
+ }
148
+
149
+ async function getPoolData({
150
+ basePoolAddress,
151
+ swapPoolAddress,
152
+ cvxAddress,
153
+ extraPoolAddresses,
154
+ provider
155
+ }: GetPoolDataProps) {
164
156
  const calls: [
165
157
  MCall<IBaseRewardPoolInterface>,
166
158
  MCall<IBaseRewardPoolInterface>,
@@ -179,7 +171,7 @@ async function getPoolData(
179
171
  method: "totalSupply()"
180
172
  },
181
173
  {
182
- address: underlying,
174
+ address: swapPoolAddress,
183
175
  interface: CurveV1AdapterStETH__factory.createInterface(),
184
176
  method: "get_virtual_price()"
185
177
  },
@@ -207,44 +199,3 @@ async function getPoolData(
207
199
  ]
208
200
  >(calls, provider);
209
201
  }
210
-
211
- interface CurveAPRData {
212
- baseApy: number;
213
- crvApy: number;
214
- crvBoost: number;
215
- crvPrice: number;
216
- }
217
-
218
- interface APYResponse {
219
- apys: Record<string, CurveAPRData>;
220
- }
221
-
222
- const curveLPTokenToPoolName: Record<CurveLPToken, string> = {
223
- "3Crv": "3pool",
224
- FRAX3CRV: "frax",
225
- gusd3CRV: "gusd",
226
- LUSD3CRV: "lusd",
227
- crvPlain3andSUSD: "susdv2",
228
- steCRV: "steth"
229
- };
230
-
231
- const RESPONSE_DECIMALS = 100;
232
-
233
- // https://www.convexfinance.com/api/curve-apys
234
-
235
- export async function getCurveBaseApy(
236
- curveLPToken: CurveLPToken
237
- ): Promise<BigNumber> {
238
- const poolName = curveLPTokenToPoolName[curveLPToken];
239
-
240
- try {
241
- const url = "https://www.convexfinance.com/api/curve-apys";
242
- const result = await axios.get<APYResponse>(url);
243
-
244
- const { baseApy = 0 } = result.data.apys[poolName] || {};
245
-
246
- return toBN((baseApy / RESPONSE_DECIMALS).toString(), WAD_DECIMALS_POW);
247
- } catch (e) {
248
- return BigNumber.from(0);
249
- }
250
- }
@@ -0,0 +1,68 @@
1
+ import { BigNumber } from "ethers";
2
+ import axios from "axios";
3
+
4
+ import { CurveLPToken } from "../tokens/curveLP";
5
+
6
+ import { toBN } from "../utils/formatter";
7
+
8
+ import { WAD_DECIMALS_POW } from "../core/constants";
9
+ import { objectEntries } from "../utils/mappers";
10
+
11
+ interface CurveAPYData {
12
+ baseApy: number;
13
+ crvApy: number;
14
+ crvBoost: number;
15
+ crvPrice: number;
16
+ }
17
+
18
+ interface Response {
19
+ apys: Record<string, CurveAPYData>;
20
+ }
21
+
22
+ const NAME_DICTIONARY: Record<CurveLPToken, string> = {
23
+ "3Crv": "3pool",
24
+ FRAX3CRV: "frax",
25
+ gusd3CRV: "gusd",
26
+ LUSD3CRV: "lusd",
27
+ crvPlain3andSUSD: "susdv2",
28
+ steCRV: "steth"
29
+ };
30
+
31
+ const RESPONSE_DECIMALS = 100;
32
+ const ZERO = BigNumber.from(0);
33
+
34
+ // https://www.convexfinance.com/api/curve-apys
35
+ // http://localhost:8000/api/curve-apys
36
+ const URL = "https://www.convexfinance.com/api/curve-apys";
37
+
38
+ export type CurveAPYResult = Record<CurveLPToken, BigNumber>;
39
+
40
+ export async function getCurveAPY(): Promise<CurveAPYResult> {
41
+ try {
42
+ const { data } = await axios.get<Response>(URL);
43
+ const { apys } = data || {};
44
+
45
+ const curveAPY = objectEntries(NAME_DICTIONARY).reduce<CurveAPYResult>(
46
+ (acc, [curveSymbol, apiEntry]) => {
47
+ const { baseApy = 0 } = apys[apiEntry] || {};
48
+ acc[curveSymbol] = toBN(
49
+ (baseApy / RESPONSE_DECIMALS).toString(),
50
+ WAD_DECIMALS_POW
51
+ );
52
+ return acc;
53
+ },
54
+ {} as CurveAPYResult
55
+ );
56
+
57
+ return curveAPY;
58
+ } catch (e) {
59
+ return {
60
+ "3Crv": ZERO,
61
+ FRAX3CRV: ZERO,
62
+ gusd3CRV: ZERO,
63
+ LUSD3CRV: ZERO,
64
+ crvPlain3andSUSD: ZERO,
65
+ steCRV: ZERO
66
+ };
67
+ }
68
+ }
@@ -0,0 +1,8 @@
1
+ import { LPTokens, SupportedToken } from "../tokens/token";
2
+
3
+ export type TokensWithAPY = LPTokens | Extract<SupportedToken, "LDO">;
4
+
5
+ export * from "./convexAPY";
6
+ export * from "./lidoAPY";
7
+ export * from "./curveAPY";
8
+ export * from "./yearnAPY";
@@ -24,7 +24,7 @@ const lidoStEth: Record<NetworkType, string> = {
24
24
  Kovan: tokenDataByNetwork.Kovan.STETH
25
25
  };
26
26
 
27
- export async function getLidoApy(
27
+ export async function getLidoAPY(
28
28
  provider: providers.Provider,
29
29
  networkType: NetworkType
30
30
  ) {
@@ -0,0 +1,66 @@
1
+ import { BigNumber } from "ethers";
2
+ import axios from "axios";
3
+
4
+ import { YearnLPToken, yearnTokens } from "../tokens/yearn";
5
+
6
+ import { toBN } from "../utils/formatter";
7
+
8
+ import { WAD_DECIMALS_POW } from "../core/constants";
9
+ import { objectEntries } from "../utils/mappers";
10
+
11
+ interface YearnAPYData {
12
+ apy: {
13
+ gross_apr: number;
14
+ net_apy: number;
15
+ };
16
+
17
+ symbol: string;
18
+ display_name: string;
19
+ }
20
+
21
+ type Response = Array<YearnAPYData>;
22
+
23
+ const RESPONSE_DECIMALS = 1;
24
+ const ZERO = BigNumber.from(0);
25
+
26
+ const URL = "https://api.yearn.finance/v1/chains/1/vaults/all";
27
+
28
+ export type YearnAPYResult = Record<YearnLPToken, BigNumber>;
29
+
30
+ const transformSymbol = (s: string) => s.replaceAll("_", "-").toLowerCase();
31
+
32
+ export async function getYearnAPY(): Promise<YearnAPYResult> {
33
+ try {
34
+ const { data } = await axios.get<Response>(URL);
35
+
36
+ const dataBySymbol = data.reduce<Record<string, YearnAPYData>>((acc, d) => {
37
+ acc[d.symbol.toLowerCase()] = d;
38
+ return acc;
39
+ }, {});
40
+
41
+ const yearnAPY = objectEntries(yearnTokens).reduce<YearnAPYResult>(
42
+ (acc, [yearnSymbol]) => {
43
+ const { apy } = dataBySymbol[transformSymbol(yearnSymbol)] || {};
44
+ const { net_apy: netApy } = apy || {};
45
+
46
+ acc[yearnSymbol] = toBN(
47
+ (netApy / RESPONSE_DECIMALS).toString(),
48
+ WAD_DECIMALS_POW
49
+ );
50
+ return acc;
51
+ },
52
+ {} as YearnAPYResult
53
+ );
54
+
55
+ return yearnAPY;
56
+ } catch (e) {
57
+ return {
58
+ yvDAI: ZERO,
59
+ yvUSDC: ZERO,
60
+ yvWETH: ZERO,
61
+ yvWBTC: ZERO,
62
+ yvCurve_stETH: ZERO,
63
+ yvCurve_FRAX: ZERO
64
+ };
65
+ }
66
+ }
@@ -1,4 +1,5 @@
1
1
  import { keyToLowercase } from "../utils/mappers";
2
+ import { shortAddress } from "../utils/formatter";
2
3
  import { contractsByAddress, contractParams } from "./contracts";
3
4
 
4
5
  export const deployedContracts: Record<string, string> = {
@@ -63,5 +64,5 @@ const contractsFullList = {
63
64
  };
64
65
 
65
66
  export function getContractName(address: string): string {
66
- return contractsFullList[address.toLowerCase()] || address;
67
+ return contractsFullList[address.toLowerCase()] || shortAddress(address);
67
68
  }