-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluefin-usdc.js
More file actions
35 lines (28 loc) · 1.07 KB
/
bluefin-usdc.js
File metadata and controls
35 lines (28 loc) · 1.07 KB
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
const fs = require("node:fs");
const puppeteer = require("puppeteer");
(async () => {
const timestamp = new Date();
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
await page.goto("https://trade.bluefin.io/lend", {
waitUntil: "domcontentloaded",
});
const trElement = await page.waitForSelector(`xpath/(//tr[td[normalize-space() = "USDC"]])`);
const [, supply, , , rate] = await page.evaluate((el) => {
const tdElements = el.querySelectorAll("td");
return Array.from(tdElements).map((el) => el.textContent.replace(/\s+/g, "").trim());
}, trElement);
await browser.close();
const [, tvl] = supply.match(/\$([\d,.]+)/) ?? [];
const results = {
id: "bluefin-usdc",
timestamp: timestamp.toISOString(),
protocol: "bluefin",
name: "USDC",
rate: parseFloat(rate),
tvl: parseFloat(tvl.replace(/,/g, "")) * 1_000_000,
};
console.log(results);
fs.writeFileSync("bluefin-usdc.json", JSON.stringify(results) + "\n");
})();