@gearbox-protocol/sdk 1.19.2 → 1.19.4

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.
@@ -1,4 +1,11 @@
1
1
  import { BigNumber } from "ethers";
2
2
  import { CurveLPToken } from "../tokens/curveLP";
3
- export declare type CurveAPYResult = Record<CurveLPToken, BigNumber>;
4
- export declare function getCurveAPY(): Promise<CurveAPYResult>;
3
+ declare type CurveAPYTokens = CurveLPToken;
4
+ export declare type CurveAPYResult = Record<CurveAPYTokens, BigNumber>;
5
+ export declare function getCurveAPY(): Promise<[CurveAPYResult, GEARCurveAPY]>;
6
+ interface GEARCurveAPY {
7
+ base: BigNumber;
8
+ crv: BigNumber;
9
+ gear: BigNumber;
10
+ }
11
+ export {};
@@ -45,7 +45,7 @@ var ethers_1 = require("ethers");
45
45
  var constants_1 = require("../core/constants");
46
46
  var formatter_1 = require("../utils/formatter");
47
47
  var mappers_1 = require("../utils/mappers");
48
- var POOL_DICTIONARY = {
48
+ var APY_DICTIONARY = {
49
49
  "3Crv": "0",
50
50
  FRAX3CRV: "34",
51
51
  gusd3CRV: "19",
@@ -54,50 +54,87 @@ var POOL_DICTIONARY = {
54
54
  steCRV: "14",
55
55
  crvFRAX: "44", // 0xDcEF968d416a41Cdac0ED8702fAC8128A64241A2
56
56
  };
57
- var RESPONSE_DECIMALS = 100;
57
+ var CRV_APY_RESPONSE_DECIMALS = 100;
58
58
  var ZERO = ethers_1.BigNumber.from(0);
59
59
  // const MAIN = "https://api.curve.fi/api/getPools/ethereum/main";
60
60
  // const CRYPTO = "https://api.curve.fi/api/getPools/ethereum/crypto";
61
61
  // const FACTORY = "https://api.curve.fi/api/getPools/ethereum/factory";
62
- // const FACTORY_CRYPTO = "https://api.curve.fi/api/getPools/ethereum/factory-crypto";
63
- // https://www.convexfinance.com/api/curve-apys
64
- // http://localhost:8000/api/curve-apys
65
- var URL = "https://www.convexfinance.com/api/curve-apys";
62
+ var CURVE_FACTORY_CRYPTO_URL = "https://api.curve.fi/api/getPools/ethereum/factory-crypto";
63
+ var CURVE_APY_URL = "https://www.convexfinance.com/api/curve-apys";
66
64
  function getCurveAPY() {
67
65
  return __awaiter(this, void 0, void 0, function () {
68
- var data, apys_1, curveAPY, e_1;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
66
+ var _a, apyData, poolDataResp, apys_1, curveAPY, gearAPY, e_1;
67
+ return __generator(this, function (_b) {
68
+ switch (_b.label) {
71
69
  case 0:
72
- _a.trys.push([0, 2, , 3]);
73
- return [4 /*yield*/, axios_1.default.get(URL)];
70
+ _b.trys.push([0, 3, , 4]);
71
+ return [4 /*yield*/, Promise.all([
72
+ axios_1.default.get(CURVE_APY_URL),
73
+ axios_1.default.get(CURVE_FACTORY_CRYPTO_URL),
74
+ ])];
74
75
  case 1:
75
- data = (_a.sent()).data;
76
- apys_1 = (data || {}).apys;
77
- curveAPY = (0, mappers_1.objectEntries)(POOL_DICTIONARY).reduce(function (acc, _a) {
76
+ _a = _b.sent(), apyData = _a[0].data, poolDataResp = _a[1].data;
77
+ apys_1 = (apyData || {}).apys;
78
+ curveAPY = (0, mappers_1.objectEntries)(APY_DICTIONARY).reduce(function (acc, _a) {
78
79
  var curveSymbol = _a[0], poolId = _a[1];
79
80
  var baseApy = (apys_1[poolId] || {}).baseApy;
80
81
  if (baseApy === undefined)
81
82
  console.warn("No base apy for: ".concat(curveSymbol, ", ").concat(poolId));
82
- acc[curveSymbol] = (0, formatter_1.toBN)(((baseApy || 0) / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
83
+ acc[curveSymbol] = curveAPYToBn(baseApy || 0);
83
84
  return acc;
84
85
  }, {});
85
- return [2 /*return*/, curveAPY];
86
+ return [4 /*yield*/, getGEARCurveAPY(apys_1, poolDataResp)];
86
87
  case 2:
87
- e_1 = _a.sent();
88
+ gearAPY = _b.sent();
89
+ return [2 /*return*/, [curveAPY, gearAPY]];
90
+ case 3:
91
+ e_1 = _b.sent();
88
92
  console.error(e_1);
89
- return [2 /*return*/, {
90
- "3Crv": ZERO,
91
- crvFRAX: ZERO,
92
- FRAX3CRV: ZERO,
93
- gusd3CRV: ZERO,
94
- LUSD3CRV: ZERO,
95
- crvPlain3andSUSD: ZERO,
96
- steCRV: ZERO,
97
- }];
98
- case 3: return [2 /*return*/];
93
+ return [2 /*return*/, [
94
+ {
95
+ "3Crv": ZERO,
96
+ crvFRAX: ZERO,
97
+ FRAX3CRV: ZERO,
98
+ gusd3CRV: ZERO,
99
+ LUSD3CRV: ZERO,
100
+ crvPlain3andSUSD: ZERO,
101
+ steCRV: ZERO,
102
+ },
103
+ { base: ZERO, crv: ZERO, gear: ZERO },
104
+ ]];
105
+ case 4: return [2 /*return*/];
99
106
  }
100
107
  });
101
108
  });
102
109
  }
103
110
  exports.getCurveAPY = getCurveAPY;
111
+ function curveAPYToBn(baseApy) {
112
+ return (0, formatter_1.toBN)((baseApy / CRV_APY_RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
113
+ }
114
+ var POOL_DICTIONARY = {
115
+ GEAR: "factory-crypto-192", // 0x0e9b5b092cad6f1c5e6bc7f89ffe1abb5c95f1c2
116
+ };
117
+ function getGEARCurveAPY(apys, poolDataResp) {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var _a, poolData, gearPool, _b, gaugeRewards, gearGauge, _c, gearApy, _d, baseApy, crvApy, base, crv, gear;
120
+ return __generator(this, function (_e) {
121
+ _a = ((poolDataResp === null || poolDataResp === void 0 ? void 0 : poolDataResp.data) || {}).poolData, poolData = _a === void 0 ? [] : _a;
122
+ gearPool = poolData.find(function (p) { return p.id === POOL_DICTIONARY.GEAR; });
123
+ if (gearPool === undefined)
124
+ console.warn("No GEAR pool found");
125
+ _b = (gearPool || {}).gaugeRewards, gaugeRewards = _b === void 0 ? [] : _b;
126
+ console.log("GEAR POOL", gaugeRewards);
127
+ gearGauge = gaugeRewards.find(function (g) { return g.symbol.toLowerCase() === "gear"; });
128
+ if (gearGauge === undefined)
129
+ console.warn("No GEAR gauge found");
130
+ _c = (gearGauge || {}).apy, gearApy = _c === void 0 ? 0 : _c;
131
+ _d = apys[POOL_DICTIONARY.GEAR] || {}, baseApy = _d.baseApy, crvApy = _d.crvApy;
132
+ if (baseApy === undefined)
133
+ console.warn("No base apy for: GEAR, ".concat(POOL_DICTIONARY.GEAR));
134
+ base = curveAPYToBn(baseApy || 0);
135
+ crv = curveAPYToBn(crvApy || 0);
136
+ gear = curveAPYToBn(gearApy || 0);
137
+ return [2 /*return*/, { base: base, crv: crv, gear: gear }];
138
+ });
139
+ });
140
+ }
@@ -6,6 +6,5 @@ export declare type LpTokensAPY = Record<TokensWithAPY, number>;
6
6
  export declare const isTokenWithAPY: (t: unknown) => t is TokensWithAPY;
7
7
  export * from "./convexAPY";
8
8
  export * from "./curveAPY";
9
- export * from "./gearCurveAPY";
10
9
  export * from "./lidoAPY";
11
10
  export * from "./yearnAPY";
package/lib/apy/index.js CHANGED
@@ -27,6 +27,5 @@ var isTokenWithAPY = function (t) {
27
27
  exports.isTokenWithAPY = isTokenWithAPY;
28
28
  __exportStar(require("./convexAPY"), exports);
29
29
  __exportStar(require("./curveAPY"), exports);
30
- __exportStar(require("./gearCurveAPY"), exports);
31
30
  __exportStar(require("./lidoAPY"), exports);
32
31
  __exportStar(require("./yearnAPY"), exports);
@@ -42,7 +42,8 @@ export declare type PriceFeedData = {
42
42
  upperBound: BigNumber;
43
43
  } | {
44
44
  type: OracleType.COMPOSITE_ORACLE;
45
- ethPriceFeed: Record<NetworkType, string>;
45
+ targetToBasePriceFeed: Record<NetworkType, string>;
46
+ baseToUsdPriceFeed: Record<NetworkType, string>;
46
47
  };
47
48
  export interface TokenPriceFeedData {
48
49
  priceFeedETH?: PriceFeedData;
@@ -215,8 +215,12 @@ exports.priceFeedsByNetwork = {
215
215
  },
216
216
  },
217
217
  priceFeedUSD: {
218
- type: oracles_1.OracleType.CHAINLINK_ORACLE,
219
- address: {
218
+ type: oracles_1.OracleType.COMPOSITE_ORACLE,
219
+ targetToBasePriceFeed: {
220
+ Mainnet: "0xfdfd9c85ad200c506cf9e21f1fd8dd01932fbb23",
221
+ Goerli: "",
222
+ },
223
+ baseToUsdPriceFeed: {
220
224
  Mainnet: "0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c",
221
225
  Goerli: "0x048F634279BE1CC4De3F17fD4c31101bAD0826c8",
222
226
  },
@@ -258,10 +262,14 @@ exports.priceFeedsByNetwork = {
258
262
  },
259
263
  priceFeedUSD: {
260
264
  type: oracles_1.OracleType.COMPOSITE_ORACLE,
261
- ethPriceFeed: {
265
+ targetToBasePriceFeed: {
262
266
  Mainnet: "0x86392dC19c0b719886221c78AB11eb8Cf5c52812",
263
267
  Goerli: "0x78622A939324C5dC1B646D113358f54f0BA4353B",
264
268
  },
269
+ baseToUsdPriceFeed: {
270
+ Mainnet: "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419",
271
+ Goerli: "0x491741d9F426130d1bC27Aee82f8b4Bd4E6E5f5D",
272
+ },
265
273
  },
266
274
  },
267
275
  wstETH: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.19.2",
3
+ "version": "1.19.4",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1,22 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- import { CurveGEARPoolParams } from "../contracts/contracts";
3
- import { NetworkType } from "../core/chains";
4
- import { MCall } from "../utils/multicall";
5
- export interface GetGEARCurveAPYProps {
6
- response: Array<BigNumber>;
7
- }
8
- export declare function getGEARCurveAPY({ response }: GetGEARCurveAPYProps): {
9
- tradingAPY: BigNumber;
10
- cideredAPYPlusLM: BigNumber;
11
- };
12
- export interface GetGEARCurveAPYCallsProps {
13
- pool: "CURVE_GEAR_POOL";
14
- networkType: NetworkType;
15
- }
16
- export declare function getGEARCurveAPYCalls(props: GetGEARCurveAPYCallsProps): {
17
- poolInfo: {
18
- poolParams: CurveGEARPoolParams;
19
- poolAddress: string;
20
- };
21
- calls: [MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool").ICurvePoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool").ICurvePoolInterface>];
22
- };
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGEARCurveAPYCalls = exports.getGEARCurveAPY = void 0;
4
- var contracts_1 = require("../contracts/contracts");
5
- var constants_1 = require("../core/constants");
6
- var types_1 = require("../types");
7
- var formatter_1 = require("../utils/formatter");
8
- function getGEARCurveAPY(_a) {
9
- var response = _a.response;
10
- return calculateGearCurveAPY(response);
11
- }
12
- exports.getGEARCurveAPY = getGEARCurveAPY;
13
- function getGEARCurveAPYCalls(props) {
14
- var poolInfo = getPoolInfo(props);
15
- var calls = getPoolDataCalls(poolInfo);
16
- return { poolInfo: poolInfo, calls: calls };
17
- }
18
- exports.getGEARCurveAPYCalls = getGEARCurveAPYCalls;
19
- function getPoolDataCalls(_a) {
20
- var poolAddress = _a.poolAddress, poolParams = _a.poolParams;
21
- var calls = [
22
- {
23
- address: poolAddress,
24
- interface: types_1.ICurvePool__factory.createInterface(),
25
- method: "get_virtual_price()",
26
- },
27
- {
28
- address: poolAddress,
29
- interface: types_1.ICurvePool__factory.createInterface(),
30
- method: "balances(uint256)",
31
- params: [poolParams.tokens.findIndex(function (t) { return t === "GEAR"; })],
32
- },
33
- ];
34
- return calls;
35
- }
36
- function getPoolInfo(_a) {
37
- var pool = _a.pool, networkType = _a.networkType;
38
- var contractsList = contracts_1.contractsByNetwork[networkType];
39
- var poolParams = contracts_1.contractParams[pool];
40
- var poolAddress = contractsList[pool];
41
- return { poolParams: poolParams, poolAddress: poolAddress };
42
- }
43
- var POOL_START = 1671264000 * 1000;
44
- var lmRewardsPerMonth = (0, formatter_1.toBN)("3330000", 18);
45
- var ciderFees = (0, formatter_1.toBN)("15000000", 18);
46
- var rewardsAmountPerMonth = lmRewardsPerMonth.add(ciderFees.div(4));
47
- function calculateGearCurveAPY(response) {
48
- var vPrice = response[0], gearBalance = response[1];
49
- var tradingAPY = vPrice
50
- .sub(constants_1.WAD)
51
- .mul(constants_1.MS_PER_YEAR)
52
- .div(Date.now() - POOL_START);
53
- var cideredAPYPlusLM = rewardsAmountPerMonth
54
- .mul(constants_1.WAD)
55
- .mul(12)
56
- .div(gearBalance.mul(2));
57
- return { tradingAPY: tradingAPY, cideredAPYPlusLM: cideredAPYPlusLM };
58
- }