@gearbox-protocol/sdk 3.0.0-next.128 → 3.0.0-next.129
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 -2
- package/lib/apy/curveAPY.js +104 -68
- package/lib/apy/defiLamaAPY.js +5 -2
- package/lib/apy/yearnAPY.d.ts +2 -2
- package/lib/apy/yearnAPY.js +2 -1
- package/lib/core/endpoint.d.ts +1 -0
- package/lib/core/endpoint.js +2 -0
- package/lib/core/rewardConvex.js +0 -2
- package/package.json +1 -1
package/lib/apy/convexAPY.js
CHANGED
|
@@ -168,7 +168,7 @@ function calculateConvexAPY(props) {
|
|
|
168
168
|
return finished ? 0n : extraAPY;
|
|
169
169
|
});
|
|
170
170
|
const extraAPYTotal = extraAPRs.reduce((acc, apy) => acc + apy, 0n);
|
|
171
|
-
const baseApy = props.curveAPY?.[crvToken]
|
|
171
|
+
const baseApy = props.curveAPY?.[crvToken]?.base || 0;
|
|
172
172
|
const apyTotal = crvAPY + cvxAPY + extraAPYTotal;
|
|
173
173
|
const apyTotalInPercent = apyTotal * sdk_gov_1.PERCENTAGE_DECIMALS * sdk_gov_1.PERCENTAGE_FACTOR;
|
|
174
174
|
const r = baseApy + Math.round(Number((apyTotalInPercent * 10n) / sdk_gov_1.WAD) / 10);
|
package/lib/apy/curveAPY.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NetworkType, PartialRecord } from "@gearbox-protocol/sdk-gov";
|
|
1
2
|
import { CurveLPToken } from "@gearbox-protocol/sdk-gov/lib/tokens/curveLP";
|
|
2
3
|
import { GearboxToken } from "@gearbox-protocol/sdk-gov/lib/tokens/gear";
|
|
3
4
|
interface CurvePoolData {
|
|
@@ -50,7 +51,13 @@ interface CurveAPY {
|
|
|
50
51
|
crv: number;
|
|
51
52
|
gauge: Array<[string, number]>;
|
|
52
53
|
}
|
|
53
|
-
export type CurveAPYResult =
|
|
54
|
-
export declare function getCurveAPY(): Promise<
|
|
54
|
+
export type CurveAPYResult = PartialRecord<CurveAPYTokens, CurveAPY>;
|
|
55
|
+
export declare function getCurveAPY(network: NetworkType): Promise<{
|
|
56
|
+
curveAPY: CurveAPYResult;
|
|
57
|
+
gearAPY: CurveAPY;
|
|
58
|
+
} | {
|
|
59
|
+
curveAPY?: undefined;
|
|
60
|
+
gearAPY?: undefined;
|
|
61
|
+
}>;
|
|
55
62
|
export declare function getCurveGearPool(): Promise<CurvePoolData | undefined>;
|
|
56
63
|
export {};
|
package/lib/apy/curveAPY.js
CHANGED
|
@@ -6,76 +6,66 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getCurveGearPool = exports.getCurveAPY = void 0;
|
|
7
7
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
crvPlain3andSUSD: "15",
|
|
15
|
-
steCRV: "14",
|
|
16
|
-
crvFRAX: "44",
|
|
17
|
-
GEAR: "factory-crypto-192",
|
|
18
|
-
OHMFRAXBP: "factory-crypto-158",
|
|
19
|
-
MIM_3LP3CRV: "40",
|
|
20
|
-
crvCRVETH: "crypto-3",
|
|
21
|
-
crvCVXETH: "crypto-4",
|
|
22
|
-
crvUSDTWBTCWETH: "factory-tricrypto-1",
|
|
23
|
-
LDOETH: "factory-crypto-204",
|
|
24
|
-
crvUSDUSDC: "factory-crvusd-0",
|
|
25
|
-
crvUSDUSDT: "factory-crvusd-1",
|
|
26
|
-
crvUSDFRAX: "factory-crvusd-4",
|
|
27
|
-
crvUSDETHCRV: "factory-tricrypto-4",
|
|
28
|
-
rETH_f: "factory-crypto-210",
|
|
29
|
-
wstETHCRV: "unknown",
|
|
30
|
-
"2CRV": "unknown",
|
|
31
|
-
"3c-crvUSD": "unknown",
|
|
32
|
-
crvUSDC: "unknown",
|
|
33
|
-
crvUSDT: "unknown",
|
|
34
|
-
crvUSDC_e: "unknown",
|
|
35
|
-
"3CRV": "unknown", // 0xEfDE221f306152971D8e9f181bFe998447975810
|
|
9
|
+
const GEAR_POOL = "0x5Be6C45e2d074fAa20700C49aDA3E88a1cc0025d".toLowerCase();
|
|
10
|
+
const CURVE_CHAINS = {
|
|
11
|
+
Arbitrum: "arbitrum",
|
|
12
|
+
Mainnet: "ethereum",
|
|
13
|
+
Optimism: "optimism",
|
|
36
14
|
};
|
|
37
|
-
// const CRYPTO = "https://api.curve.fi/api/getPools/
|
|
38
|
-
// const FACTORY = "https://api.curve.fi/api/getPools/
|
|
39
|
-
const CURVE_APY_URL = "https://www.convexfinance.com/api/curve-apys";
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
15
|
+
// const CRYPTO = "https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/crypto";
|
|
16
|
+
// const FACTORY = "https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/factory";
|
|
17
|
+
// const CURVE_APY_URL = "https://www.convexfinance.com/api/curve-apys";
|
|
18
|
+
const getVolumesURL = (n) => `https://api.curve.fi/api/getVolumes/${CURVE_CHAINS[n]}`;
|
|
19
|
+
const getMainURL = (n) => `https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/main`;
|
|
20
|
+
const getFactoryCryptoURL = (n) => `https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/factory-crypto`;
|
|
21
|
+
const getCryptoURL = (n) => `https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/crypto`;
|
|
22
|
+
const getFactoryTriCryptoURL = (n) => `https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/factory-tricrypto`;
|
|
23
|
+
const getFactoryCrvUsdURL = (n) => `https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/factory-crvusd`;
|
|
24
|
+
const getFactoryStableNgURL = (n) => `https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/factory-stable-ng`;
|
|
25
|
+
async function getCurveAPY(network) {
|
|
46
26
|
try {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.map(resp => {
|
|
58
|
-
const { poolData = [] } = resp?.data?.data || {};
|
|
59
|
-
return poolData.map(p => [p.id, p]);
|
|
27
|
+
const currentTokens = sdk_gov_1.tokenDataByNetwork[network];
|
|
28
|
+
const { mainnetVolumes, mainnetFactoryPools, volumes, pools } = await getCurvePools(network);
|
|
29
|
+
const volumeByAddress = Object.fromEntries(volumes.data.data.pools.map(v => [v.address.toLowerCase(), v]));
|
|
30
|
+
const poolDataByAddress = Object.fromEntries(pools
|
|
31
|
+
.map(poolCategory => {
|
|
32
|
+
const { poolData = [] } = poolCategory?.data?.data || {};
|
|
33
|
+
return poolData.map((p) => [
|
|
34
|
+
p.lpTokenAddress.toLowerCase(),
|
|
35
|
+
p,
|
|
36
|
+
]);
|
|
60
37
|
})
|
|
61
38
|
.flat(1));
|
|
62
|
-
const curveAPY = sdk_gov_1.TypedObjectUtils.entries(
|
|
63
|
-
const
|
|
64
|
-
const pool =
|
|
65
|
-
const
|
|
66
|
-
const
|
|
39
|
+
const curveAPY = sdk_gov_1.TypedObjectUtils.entries(sdk_gov_1.curveTokens).reduce((acc, [curveSymbol]) => {
|
|
40
|
+
const address = (currentTokens?.[curveSymbol] || "").toLowerCase();
|
|
41
|
+
const pool = poolDataByAddress[address];
|
|
42
|
+
const volume = volumeByAddress[(pool?.address || "").toLowerCase()];
|
|
43
|
+
const baseAPY = volume?.latestDailyApyPcent || 0;
|
|
44
|
+
const maxCrv = Math.max(...(pool?.gaugeCrvApy || []), 0);
|
|
45
|
+
const extraRewards = (pool?.gaugeRewards || []).map(({ apy = 0, symbol }) => [
|
|
67
46
|
symbol.toLowerCase(),
|
|
68
47
|
curveAPYToBn(apy),
|
|
69
48
|
]);
|
|
70
|
-
const maxCrv = pool?.gaugeCrvApy?.length > 0 ? Math.max(...pool.gaugeCrvApy) : crvApy;
|
|
71
49
|
acc[curveSymbol] = {
|
|
72
|
-
base: curveAPYToBn(
|
|
73
|
-
crv: curveAPYToBn(maxCrv
|
|
50
|
+
base: curveAPYToBn(baseAPY),
|
|
51
|
+
crv: curveAPYToBn(maxCrv),
|
|
74
52
|
gauge: extraRewards,
|
|
75
53
|
};
|
|
76
54
|
return acc;
|
|
77
55
|
}, {});
|
|
78
|
-
|
|
56
|
+
const poolFactoryByAddress = Object.fromEntries((mainnetFactoryPools?.data?.data?.poolData || []).map((p) => [p.lpTokenAddress.toLowerCase(), p]));
|
|
57
|
+
const mainnetVolumeByAddress = Object.fromEntries(mainnetVolumes.data.data.pools.map(v => [v.address.toLowerCase(), v]));
|
|
58
|
+
const gearPool = poolFactoryByAddress[GEAR_POOL];
|
|
59
|
+
const gearVolume = mainnetVolumeByAddress[(gearPool?.address || "").toLowerCase()];
|
|
60
|
+
const gearAPY = {
|
|
61
|
+
base: curveAPYToBn(gearVolume?.latestDailyApyPcent || 0),
|
|
62
|
+
crv: curveAPYToBn(Math.max(...(gearPool?.gaugeCrvApy || []), 0)),
|
|
63
|
+
gauge: (gearPool?.gaugeRewards || []).map(({ apy = 0, symbol }) => [
|
|
64
|
+
symbol.toLowerCase(),
|
|
65
|
+
curveAPYToBn(apy),
|
|
66
|
+
]),
|
|
67
|
+
};
|
|
68
|
+
return { curveAPY, gearAPY };
|
|
79
69
|
}
|
|
80
70
|
catch (e) {
|
|
81
71
|
console.error(e);
|
|
@@ -83,20 +73,66 @@ async function getCurveAPY() {
|
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
75
|
exports.getCurveAPY = getCurveAPY;
|
|
76
|
+
async function getCurvePools(network) {
|
|
77
|
+
switch (network) {
|
|
78
|
+
case "Mainnet": {
|
|
79
|
+
const [volumes, mainnetFactoryPools, ...pools] = await Promise.all([
|
|
80
|
+
axios_1.default.get(getVolumesURL(network)),
|
|
81
|
+
axios_1.default.get(getFactoryCryptoURL(network)),
|
|
82
|
+
axios_1.default.get(getMainURL(network)),
|
|
83
|
+
axios_1.default.get(getCryptoURL(network)),
|
|
84
|
+
axios_1.default.get(getFactoryTriCryptoURL(network)),
|
|
85
|
+
axios_1.default.get(getFactoryCrvUsdURL(network)),
|
|
86
|
+
]);
|
|
87
|
+
return {
|
|
88
|
+
mainnetVolumes: volumes,
|
|
89
|
+
mainnetFactoryPools,
|
|
90
|
+
volumes,
|
|
91
|
+
pools: [mainnetFactoryPools, ...pools],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
case "Arbitrum": {
|
|
95
|
+
const [mainnetVolumes, mainnetFactoryPools, volumes, ...pools] = await Promise.all([
|
|
96
|
+
axios_1.default.get(getVolumesURL("Mainnet")),
|
|
97
|
+
axios_1.default.get(getFactoryCryptoURL("Mainnet")),
|
|
98
|
+
axios_1.default.get(getVolumesURL(network)),
|
|
99
|
+
axios_1.default.get(getMainURL(network)),
|
|
100
|
+
axios_1.default.get(getFactoryStableNgURL(network)),
|
|
101
|
+
]);
|
|
102
|
+
return {
|
|
103
|
+
mainnetVolumes,
|
|
104
|
+
mainnetFactoryPools,
|
|
105
|
+
volumes,
|
|
106
|
+
pools,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
case "Optimism": {
|
|
110
|
+
const [mainnetVolumes, mainnetFactoryPools, volumes, ...pools] = await Promise.all([
|
|
111
|
+
axios_1.default.get(getVolumesURL("Mainnet")),
|
|
112
|
+
axios_1.default.get(getFactoryCryptoURL("Mainnet")),
|
|
113
|
+
axios_1.default.get(getVolumesURL(network)),
|
|
114
|
+
axios_1.default.get(getMainURL(network)),
|
|
115
|
+
axios_1.default.get(getFactoryStableNgURL(network)),
|
|
116
|
+
]);
|
|
117
|
+
return {
|
|
118
|
+
mainnetVolumes,
|
|
119
|
+
mainnetFactoryPools,
|
|
120
|
+
volumes,
|
|
121
|
+
pools,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
throw new Error("Unknown network");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
86
128
|
function curveAPYToBn(baseApy) {
|
|
87
129
|
return Math.round(baseApy * Number(sdk_gov_1.PERCENTAGE_FACTOR));
|
|
88
130
|
}
|
|
89
131
|
async function getCurveGearPool() {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
]);
|
|
93
|
-
const
|
|
94
|
-
.map(resp => {
|
|
95
|
-
const { poolData = [] } = resp?.data?.data || {};
|
|
96
|
-
return poolData.map(p => [p.id, p]);
|
|
97
|
-
})
|
|
98
|
-
.flat(1));
|
|
99
|
-
const gearPool = poolDataByID[APY_DICTIONARY.GEAR];
|
|
132
|
+
const resp = await axios_1.default.get(getFactoryCryptoURL("Mainnet"));
|
|
133
|
+
const { poolData = [] } = resp?.data?.data || {};
|
|
134
|
+
const poolDataByAddress = Object.fromEntries(poolData.map(p => [p.lpTokenAddress.toLowerCase(), p]));
|
|
135
|
+
const gearPool = poolDataByAddress[GEAR_POOL];
|
|
100
136
|
return gearPool;
|
|
101
137
|
}
|
|
102
138
|
exports.getCurveGearPool = getCurveGearPool;
|
package/lib/apy/defiLamaAPY.js
CHANGED
|
@@ -10,7 +10,10 @@ const LAMA_URL = "https://charts-server.fly.dev/api/defillama?ids=";
|
|
|
10
10
|
async function getDefiLamaAPY(networkType) {
|
|
11
11
|
try {
|
|
12
12
|
const currentNormal = NORMAL_TO_LAMA[networkType];
|
|
13
|
-
const
|
|
13
|
+
const idList = Object.values(currentNormal);
|
|
14
|
+
if (idList.length === 0)
|
|
15
|
+
return {};
|
|
16
|
+
const res = await axios_1.default.get(`${LAMA_URL}${idList.join(",")}`);
|
|
14
17
|
const itemsRecord = res.data.data.reduce((acc, item) => {
|
|
15
18
|
acc[item.pool] = item;
|
|
16
19
|
return acc;
|
|
@@ -34,7 +37,7 @@ const NORMAL_TO_LAMA = {
|
|
|
34
37
|
osETH: "4d01599c-69ae-41a3-bae1-5fab896f04c8",
|
|
35
38
|
auraB_rETH_STABLE_vault: "a4b5b995-99e7-4b8f-916d-8940b5627d70",
|
|
36
39
|
},
|
|
37
|
-
Optimism: {
|
|
40
|
+
Optimism: {},
|
|
38
41
|
Arbitrum: {},
|
|
39
42
|
};
|
|
40
43
|
// const CONVEX_TO_LAMA: Record<
|
package/lib/apy/yearnAPY.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NetworkType, YearnLPToken } from "@gearbox-protocol/sdk-gov";
|
|
2
|
-
export type YearnAPYResult =
|
|
1
|
+
import { NetworkType, PartialRecord, YearnLPToken } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
export type YearnAPYResult = PartialRecord<YearnLPToken, number>;
|
|
3
3
|
export declare function getYearnAPY(network: NetworkType): Promise<YearnAPYResult>;
|
package/lib/apy/yearnAPY.js
CHANGED
|
@@ -10,13 +10,14 @@ const getUrl = (chainId) => `https://ydaemon.yearn.finance/vaults/all?chainids=$
|
|
|
10
10
|
async function getYearnAPY(network) {
|
|
11
11
|
try {
|
|
12
12
|
const chainId = sdk_gov_1.CHAINS[network];
|
|
13
|
+
const currentTokens = sdk_gov_1.tokenDataByNetwork[network];
|
|
13
14
|
const { data } = await axios_1.default.get(getUrl(chainId));
|
|
14
15
|
const dataByAddress = data.reduce((acc, d) => {
|
|
15
16
|
acc[d.address.toLowerCase()] = d;
|
|
16
17
|
return acc;
|
|
17
18
|
}, {});
|
|
18
19
|
const yearnAPY = sdk_gov_1.TypedObjectUtils.entries(sdk_gov_1.yearnTokens).reduce((acc, [yearnSymbol]) => {
|
|
19
|
-
const address = (
|
|
20
|
+
const address = (currentTokens?.[yearnSymbol] || "").toLowerCase();
|
|
20
21
|
const data = dataByAddress[address];
|
|
21
22
|
const { apr: apy } = data || {};
|
|
22
23
|
const { netAPR } = apy || {};
|
package/lib/core/endpoint.d.ts
CHANGED
package/lib/core/endpoint.js
CHANGED
|
@@ -5,6 +5,7 @@ const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
|
5
5
|
exports.TESTNET_CHAINS = {
|
|
6
6
|
Mainnet: 7878,
|
|
7
7
|
Optimism: 7879,
|
|
8
|
+
Arbitrum: 7880,
|
|
8
9
|
};
|
|
9
10
|
const CHARTS_BACKEND_ADDRESSES = {
|
|
10
11
|
[sdk_gov_1.CHAINS.Mainnet]: "https://charts-server.fly.dev",
|
|
@@ -12,6 +13,7 @@ const CHARTS_BACKEND_ADDRESSES = {
|
|
|
12
13
|
[exports.TESTNET_CHAINS.Mainnet]: "https://testnet.gearbox.foundation",
|
|
13
14
|
// !& test server for optimism
|
|
14
15
|
[exports.TESTNET_CHAINS.Optimism]: "https://testnet.gearbox.foundation",
|
|
16
|
+
[exports.TESTNET_CHAINS.Arbitrum]: "https://testnet.gearbox.foundation",
|
|
15
17
|
};
|
|
16
18
|
class ChartsApi {
|
|
17
19
|
static getUrl = (url, chainId, options, priceSource) => [
|
package/lib/core/rewardConvex.js
CHANGED
|
@@ -10,8 +10,6 @@ const types_1 = require("../types");
|
|
|
10
10
|
class RewardConvex {
|
|
11
11
|
static poolInterface = types_1.IBaseRewardPool__factory.createInterface();
|
|
12
12
|
static async findRewards(ca, cm, network, provider) {
|
|
13
|
-
if (network !== "Mainnet")
|
|
14
|
-
return [];
|
|
15
13
|
const { auraCalls, auraDistribution, convexCalls, convexDistribution } = RewardConvex.prepareMultiCalls(ca.addr, cm, network);
|
|
16
14
|
const auraTotal = auraCalls.flat(1);
|
|
17
15
|
const convexTotal = convexCalls.flat(1);
|