-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·74 lines (61 loc) · 2.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const puppeteer = require("puppeteer");
async function fetchAuraApr(poolId) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`https://app.aura.finance/#/1/pool/${poolId}`, {
waitUntil: "networkidle0",
}); // Replace with the URL of your website
// Using XPath to find the element containing the APR percentage
const aprValue = await page.evaluate(() => {
// Find the <p> with text 'Current vAPR'
const vAPRTextElement = [...document.querySelectorAll("p")].find(
(p) => !!p.textContent && p.textContent.includes("Current vAPR")
);
// Navigate to the next sibling <div> and find the <p> inside it
if (vAPRTextElement && vAPRTextElement.nextElementSibling) {
const aprElement = vAPRTextElement.nextElementSibling.querySelector("p");
const aprElementText = aprElement ? aprElement.textContent : null;
const apr = aprElementText
? Number(aprElementText.replace("%", "")) / 100
: 0;
return apr;
}
return null;
});
console.log(aprValue); // This should log '21.04%'
await browser.close();
}
async function fetchConvexApr(poolId) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`https://curve.convexfinance.com/stake/ethereum/${poolId}`, {
waitUntil: "networkidle0",
}); // Replace with the URL of your website
// Using XPath to find the element containing the APR percentage
const percentageValue = await page.evaluate(() => {
console.log("entered ");
const allSpans = Array.from(document.querySelectorAll("span"));
// Find the span that contains "proj."
const projSpan = allSpans.find((span) =>
span.textContent ? span.textContent.includes("proj.") : false
);
if (projSpan) {
const textContent = projSpan.textContent ?? "";
const number = textContent.split("%")[0]; // Regex to extract digits followed by a '%'
return !Number.isNaN(number) ? Number(number) / 100 : 0;
}
return null;
});
console.log(`Pool: ${poolId} - ${percentageValue * 100}%`); // This should log '21.04%'
await browser.close();
}
// fetchAuraApr(185); // pxETH/wETH - 0.2087
// fetchAuraApr(109); // rETH/wETH - 0.0419
// fetchAuraApr(74); // alcx/wETH - 0.06
// fetchConvexApr(120); //ALCX_FRAXBP - 34.65
// // fetchConvexApr(138); //OHM_FRAXBP - weird
// fetchConvexApr(25); //steth+eth - 1.6
// fetchConvexApr(270); //pyusd+usdc -
// fetchConvexApr(271); //PXETH_WETH - 28.14
fetchConvexApr(182); //CRVUSD_USDC - 9.26
fetchConvexApr(179); //CRVUSD_USDT - 9.26