@gearbox-protocol/sdk 1.19.4 → 1.19.5
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/lib/apy/convexAPY.js +1 -1
- package/lib/apy/curveAPY.d.ts +6 -5
- package/lib/apy/curveAPY.js +57 -55
- package/package.json +1 -1
package/lib/apy/convexAPY.js
CHANGED
|
@@ -151,6 +151,6 @@ function calculateConvexAPY(_a) {
|
|
|
151
151
|
return extraAPY;
|
|
152
152
|
});
|
|
153
153
|
var extraAPYTotal = extraAPRs.reduce(function (acc, apy) { return acc.add(apy); }, ethers_1.BigNumber.from(0));
|
|
154
|
-
var baseApyWAD = curveAPY[underlying];
|
|
154
|
+
var baseApyWAD = curveAPY[underlying].base;
|
|
155
155
|
return baseApyWAD.add(crvAPY).add(cvxAPY).add(extraAPYTotal);
|
|
156
156
|
}
|
package/lib/apy/curveAPY.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
import { CurveLPToken } from "../tokens/curveLP";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface GEARCurveAPY {
|
|
3
|
+
import { GearboxToken } from "../tokens/gear";
|
|
4
|
+
declare type CurveAPYTokens = CurveLPToken | GearboxToken;
|
|
5
|
+
interface CurveAPY {
|
|
7
6
|
base: BigNumber;
|
|
8
7
|
crv: BigNumber;
|
|
9
|
-
|
|
8
|
+
gauge: Array<[string, BigNumber]>;
|
|
10
9
|
}
|
|
10
|
+
export declare type CurveAPYResult = Record<CurveAPYTokens, CurveAPY>;
|
|
11
|
+
export declare function getCurveAPY(): Promise<CurveAPYResult>;
|
|
11
12
|
export {};
|
package/lib/apy/curveAPY.js
CHANGED
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
49
|
};
|
|
@@ -52,57 +61,77 @@ var APY_DICTIONARY = {
|
|
|
52
61
|
LUSD3CRV: "33",
|
|
53
62
|
crvPlain3andSUSD: "15",
|
|
54
63
|
steCRV: "14",
|
|
55
|
-
crvFRAX: "44",
|
|
64
|
+
crvFRAX: "44",
|
|
65
|
+
GEAR: "factory-crypto-192", // 0x0e9b5b092cad6f1c5e6bc7f89ffe1abb5c95f1c2
|
|
56
66
|
};
|
|
57
67
|
var CRV_APY_RESPONSE_DECIMALS = 100;
|
|
58
|
-
var ZERO =
|
|
59
|
-
|
|
68
|
+
var ZERO = {
|
|
69
|
+
base: ethers_1.BigNumber.from(0),
|
|
70
|
+
crv: ethers_1.BigNumber.from(0),
|
|
71
|
+
gauge: [],
|
|
72
|
+
};
|
|
60
73
|
// const CRYPTO = "https://api.curve.fi/api/getPools/ethereum/crypto";
|
|
61
74
|
// const FACTORY = "https://api.curve.fi/api/getPools/ethereum/factory";
|
|
62
75
|
var CURVE_FACTORY_CRYPTO_URL = "https://api.curve.fi/api/getPools/ethereum/factory-crypto";
|
|
76
|
+
var CURVE_MAIN_URL = "https://api.curve.fi/api/getPools/ethereum/main";
|
|
63
77
|
var CURVE_APY_URL = "https://www.convexfinance.com/api/curve-apys";
|
|
64
78
|
function getCurveAPY() {
|
|
65
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var _a, apyData,
|
|
67
|
-
return __generator(this, function (
|
|
68
|
-
switch (
|
|
80
|
+
var _a, apyData, factoryCrypto, main, apys_1, _b, factoryCryptoPoolData, _c, mainPoolData, poolDataByID_1, curveAPY, e_1;
|
|
81
|
+
return __generator(this, function (_d) {
|
|
82
|
+
switch (_d.label) {
|
|
69
83
|
case 0:
|
|
70
|
-
|
|
84
|
+
_d.trys.push([0, 2, , 3]);
|
|
71
85
|
return [4 /*yield*/, Promise.all([
|
|
72
86
|
axios_1.default.get(CURVE_APY_URL),
|
|
73
87
|
axios_1.default.get(CURVE_FACTORY_CRYPTO_URL),
|
|
88
|
+
axios_1.default.get(CURVE_MAIN_URL),
|
|
74
89
|
])];
|
|
75
90
|
case 1:
|
|
76
|
-
_a =
|
|
91
|
+
_a = _d.sent(), apyData = _a[0].data, factoryCrypto = _a[1].data, main = _a[2].data;
|
|
77
92
|
apys_1 = (apyData || {}).apys;
|
|
93
|
+
_b = ((factoryCrypto === null || factoryCrypto === void 0 ? void 0 : factoryCrypto.data) || {}).poolData, factoryCryptoPoolData = _b === void 0 ? [] : _b;
|
|
94
|
+
_c = ((main === null || main === void 0 ? void 0 : main.data) || {}).poolData, mainPoolData = _c === void 0 ? [] : _c;
|
|
95
|
+
poolDataByID_1 = Object.fromEntries(__spreadArray(__spreadArray([], factoryCryptoPoolData.map(function (p) { return [p.id, p]; }), true), mainPoolData.map(function (p) { return [p.id, p]; }), true));
|
|
78
96
|
curveAPY = (0, mappers_1.objectEntries)(APY_DICTIONARY).reduce(function (acc, _a) {
|
|
79
97
|
var curveSymbol = _a[0], poolId = _a[1];
|
|
80
|
-
var
|
|
98
|
+
var _b = apys_1[poolId] || {}, baseApy = _b.baseApy, crvApy = _b.crvApy;
|
|
81
99
|
if (baseApy === undefined)
|
|
82
100
|
console.warn("No base apy for: ".concat(curveSymbol, ", ").concat(poolId));
|
|
83
|
-
|
|
101
|
+
var pool = poolDataByID_1[poolId];
|
|
102
|
+
var _c = (pool || {}).gaugeRewards, gaugeRewards = _c === void 0 ? [] : _c;
|
|
103
|
+
if (pool === undefined)
|
|
104
|
+
console.warn("No pool data for: ".concat(curveSymbol, ", ").concat(poolId));
|
|
105
|
+
var extraRewards = gaugeRewards.map(function (_a) {
|
|
106
|
+
var _b = _a.apy, apy = _b === void 0 ? 0 : _b, symbol = _a.symbol;
|
|
107
|
+
return [
|
|
108
|
+
symbol.toLowerCase(),
|
|
109
|
+
curveAPYToBn(apy),
|
|
110
|
+
];
|
|
111
|
+
});
|
|
112
|
+
var maxCrv = (pool === null || pool === void 0 ? void 0 : pool.gaugeCrvApy.length) > 0 ? Math.max.apply(Math, pool.gaugeCrvApy) : crvApy;
|
|
113
|
+
acc[curveSymbol] = {
|
|
114
|
+
base: curveAPYToBn(baseApy || 0),
|
|
115
|
+
crv: curveAPYToBn(maxCrv || 0),
|
|
116
|
+
gauge: extraRewards,
|
|
117
|
+
};
|
|
84
118
|
return acc;
|
|
85
119
|
}, {});
|
|
86
|
-
return [
|
|
120
|
+
return [2 /*return*/, curveAPY];
|
|
87
121
|
case 2:
|
|
88
|
-
|
|
89
|
-
return [2 /*return*/, [curveAPY, gearAPY]];
|
|
90
|
-
case 3:
|
|
91
|
-
e_1 = _b.sent();
|
|
122
|
+
e_1 = _d.sent();
|
|
92
123
|
console.error(e_1);
|
|
93
|
-
return [2 /*return*/,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
]];
|
|
105
|
-
case 4: return [2 /*return*/];
|
|
124
|
+
return [2 /*return*/, {
|
|
125
|
+
"3Crv": ZERO,
|
|
126
|
+
crvFRAX: ZERO,
|
|
127
|
+
FRAX3CRV: ZERO,
|
|
128
|
+
gusd3CRV: ZERO,
|
|
129
|
+
LUSD3CRV: ZERO,
|
|
130
|
+
crvPlain3andSUSD: ZERO,
|
|
131
|
+
steCRV: ZERO,
|
|
132
|
+
GEAR: ZERO,
|
|
133
|
+
}];
|
|
134
|
+
case 3: return [2 /*return*/];
|
|
106
135
|
}
|
|
107
136
|
});
|
|
108
137
|
});
|
|
@@ -111,30 +140,3 @@ exports.getCurveAPY = getCurveAPY;
|
|
|
111
140
|
function curveAPYToBn(baseApy) {
|
|
112
141
|
return (0, formatter_1.toBN)((baseApy / CRV_APY_RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
|
|
113
142
|
}
|
|
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
|
-
}
|