@gearbox-protocol/sdk 1.19.3 → 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.
- package/lib/apy/curveAPY.d.ts +9 -2
- package/lib/apy/curveAPY.js +64 -27
- package/lib/apy/index.d.ts +0 -1
- package/lib/apy/index.js +0 -1
- package/package.json +1 -1
- package/lib/apy/gearCurveAPY.d.ts +0 -22
- package/lib/apy/gearCurveAPY.js +0 -58
package/lib/apy/curveAPY.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
import { CurveLPToken } from "../tokens/curveLP";
|
|
3
|
-
|
|
4
|
-
export declare
|
|
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 {};
|
package/lib/apy/curveAPY.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
63
|
-
|
|
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
|
|
69
|
-
return __generator(this, function (
|
|
70
|
-
switch (
|
|
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
|
-
|
|
73
|
-
return [4 /*yield*/,
|
|
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
|
-
|
|
76
|
-
apys_1 = (
|
|
77
|
-
curveAPY = (0, mappers_1.objectEntries)(
|
|
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] = (
|
|
83
|
+
acc[curveSymbol] = curveAPYToBn(baseApy || 0);
|
|
83
84
|
return acc;
|
|
84
85
|
}, {});
|
|
85
|
-
return [
|
|
86
|
+
return [4 /*yield*/, getGEARCurveAPY(apys_1, poolDataResp)];
|
|
86
87
|
case 2:
|
|
87
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
}
|
package/lib/apy/index.d.ts
CHANGED
|
@@ -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);
|
package/package.json
CHANGED
|
@@ -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
|
-
};
|
package/lib/apy/gearCurveAPY.js
DELETED
|
@@ -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
|
-
}
|