-
Notifications
You must be signed in to change notification settings - Fork 0
/
navi-usdc.js
34 lines (28 loc) · 936 Bytes
/
navi-usdc.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
const fs = require("node:fs");
const puppeteer = require("puppeteer");
(async () => {
const timestamp = new Date();
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
await page.goto("https://app.naviprotocol.io/");
const usdcRow = await page.waitForSelector(
'xpath///*[text() = "USDC"]/ancestor::tr',
);
const [, , rate, tvl] = await page.evaluate((el) => {
return Array.from(el.querySelectorAll("td")).map((el) =>
el.textContent.trim(),
);
}, usdcRow);
console.log(rate, tvl);
await browser.close();
const results = {
id: "navi-usdc",
timestamp: timestamp.toISOString(),
protocol: "navi",
name: "USDC",
rate: parseFloat(rate),
tvl: parseFloat(tvl.split("$").at(-1).split(",").at(0)) * 1_000_000,
};
fs.writeFileSync("navi-usdc.json", JSON.stringify(results) + "\n");
})();