@gearbox-protocol/sdk 1.19.3 → 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 +9 -1
- package/lib/apy/curveAPY.js +59 -20
- 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/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,4 +1,12 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
import { CurveLPToken } from "../tokens/curveLP";
|
|
3
|
-
|
|
3
|
+
import { GearboxToken } from "../tokens/gear";
|
|
4
|
+
declare type CurveAPYTokens = CurveLPToken | GearboxToken;
|
|
5
|
+
interface CurveAPY {
|
|
6
|
+
base: BigNumber;
|
|
7
|
+
crv: BigNumber;
|
|
8
|
+
gauge: Array<[string, BigNumber]>;
|
|
9
|
+
}
|
|
10
|
+
export declare type CurveAPYResult = Record<CurveAPYTokens, CurveAPY>;
|
|
4
11
|
export declare function getCurveAPY(): Promise<CurveAPYResult>;
|
|
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
|
};
|
|
@@ -45,46 +54,72 @@ var ethers_1 = require("ethers");
|
|
|
45
54
|
var constants_1 = require("../core/constants");
|
|
46
55
|
var formatter_1 = require("../utils/formatter");
|
|
47
56
|
var mappers_1 = require("../utils/mappers");
|
|
48
|
-
var
|
|
57
|
+
var APY_DICTIONARY = {
|
|
49
58
|
"3Crv": "0",
|
|
50
59
|
FRAX3CRV: "34",
|
|
51
60
|
gusd3CRV: "19",
|
|
52
61
|
LUSD3CRV: "33",
|
|
53
62
|
crvPlain3andSUSD: "15",
|
|
54
63
|
steCRV: "14",
|
|
55
|
-
crvFRAX: "44",
|
|
64
|
+
crvFRAX: "44",
|
|
65
|
+
GEAR: "factory-crypto-192", // 0x0e9b5b092cad6f1c5e6bc7f89ffe1abb5c95f1c2
|
|
66
|
+
};
|
|
67
|
+
var CRV_APY_RESPONSE_DECIMALS = 100;
|
|
68
|
+
var ZERO = {
|
|
69
|
+
base: ethers_1.BigNumber.from(0),
|
|
70
|
+
crv: ethers_1.BigNumber.from(0),
|
|
71
|
+
gauge: [],
|
|
56
72
|
};
|
|
57
|
-
var RESPONSE_DECIMALS = 100;
|
|
58
|
-
var ZERO = ethers_1.BigNumber.from(0);
|
|
59
|
-
// const MAIN = "https://api.curve.fi/api/getPools/ethereum/main";
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var URL = "https://www.convexfinance.com/api/curve-apys";
|
|
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";
|
|
77
|
+
var CURVE_APY_URL = "https://www.convexfinance.com/api/curve-apys";
|
|
66
78
|
function getCurveAPY() {
|
|
67
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
-
var
|
|
69
|
-
return __generator(this, function (
|
|
70
|
-
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) {
|
|
71
83
|
case 0:
|
|
72
|
-
|
|
73
|
-
return [4 /*yield*/,
|
|
84
|
+
_d.trys.push([0, 2, , 3]);
|
|
85
|
+
return [4 /*yield*/, Promise.all([
|
|
86
|
+
axios_1.default.get(CURVE_APY_URL),
|
|
87
|
+
axios_1.default.get(CURVE_FACTORY_CRYPTO_URL),
|
|
88
|
+
axios_1.default.get(CURVE_MAIN_URL),
|
|
89
|
+
])];
|
|
74
90
|
case 1:
|
|
75
|
-
|
|
76
|
-
apys_1 = (
|
|
77
|
-
|
|
91
|
+
_a = _d.sent(), apyData = _a[0].data, factoryCrypto = _a[1].data, main = _a[2].data;
|
|
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));
|
|
96
|
+
curveAPY = (0, mappers_1.objectEntries)(APY_DICTIONARY).reduce(function (acc, _a) {
|
|
78
97
|
var curveSymbol = _a[0], poolId = _a[1];
|
|
79
|
-
var
|
|
98
|
+
var _b = apys_1[poolId] || {}, baseApy = _b.baseApy, crvApy = _b.crvApy;
|
|
80
99
|
if (baseApy === undefined)
|
|
81
100
|
console.warn("No base apy for: ".concat(curveSymbol, ", ").concat(poolId));
|
|
82
|
-
|
|
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
|
+
};
|
|
83
118
|
return acc;
|
|
84
119
|
}, {});
|
|
85
120
|
return [2 /*return*/, curveAPY];
|
|
86
121
|
case 2:
|
|
87
|
-
e_1 =
|
|
122
|
+
e_1 = _d.sent();
|
|
88
123
|
console.error(e_1);
|
|
89
124
|
return [2 /*return*/, {
|
|
90
125
|
"3Crv": ZERO,
|
|
@@ -94,6 +129,7 @@ function getCurveAPY() {
|
|
|
94
129
|
LUSD3CRV: ZERO,
|
|
95
130
|
crvPlain3andSUSD: ZERO,
|
|
96
131
|
steCRV: ZERO,
|
|
132
|
+
GEAR: ZERO,
|
|
97
133
|
}];
|
|
98
134
|
case 3: return [2 /*return*/];
|
|
99
135
|
}
|
|
@@ -101,3 +137,6 @@ function getCurveAPY() {
|
|
|
101
137
|
});
|
|
102
138
|
}
|
|
103
139
|
exports.getCurveAPY = getCurveAPY;
|
|
140
|
+
function curveAPYToBn(baseApy) {
|
|
141
|
+
return (0, formatter_1.toBN)((baseApy / CRV_APY_RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
|
|
142
|
+
}
|
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
|
-
}
|