-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolygon.ts
46 lines (42 loc) · 1.45 KB
/
polygon.ts
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
import { createPublicClient } from "viem";
import { polygon } from "viem/chains";
import { polygonDataFeeds } from "../src/dataFeeds/polygon.js";
import { subscribeToChainLinkPriceUpdates } from "../src/Aggregator.js";
import { useWebsocketOrHttpTransport } from "../src/utils.js";
import { loadBalance } from "@ponder/utils";
const polygonRpcList = [
"https://public.stackup.sh/api/v1/node/polygon-mainnet",
"https://polygon.gateway.tenderly.co",
"https://polygon.blockpi.network/v1/rpc/public",
"https://polygon-rpc.com",
];
const transports = loadBalance(
polygonRpcList.map((rpc) => useWebsocketOrHttpTransport(rpc))
);
const polyCallClient = createPublicClient({
name: "PolyCall",
transport: transports,
chain: polygon,
batch: {
multicall: true,
},
});
subscribeToChainLinkPriceUpdates({
feedAddresses: Object.values(polygonDataFeeds),
publicClient: polyCallClient,
onLogsFunction: (array) => {
for (const feed of array) {
console.log(`Asset: ${feed.description}`);
console.log(`🔘 Round ID: ${feed.roundId}`);
if (feed.description.includes("USD")) {
console.log(`📈 Answer: $${feed.current}`);
} else if (feed.description.includes("/ ETH")) {
console.log(`📈 Answer: Ξ${feed.current}`);
} else {
console.log(`📈 Answer: ${feed.current}`);
}
console.log(`⏰ Time: ${feed.updatedAt}`);
console.log("----------------------------------------");
}
},
});