-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethereum.ts
48 lines (44 loc) · 1.42 KB
/
ethereum.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
47
48
import { createPublicClient, fallback } from "viem";
import { mainnet } from "viem/chains";
import { ethereumDataFeeds } from "../src/dataFeeds/ethereum.js";
import { subscribeToChainLinkPriceUpdates } from "../src/Aggregator.js";
import { useWebsocketOrHttpTransport } from "../src/utils.js";
import { loadBalance } from "@ponder/utils";
const rpcList = [
"https://eth.drpc.org",
"wss://ethereum.publicnode.com",
"https://rpc.mevblocker.io/noreverts",
];
const transports = loadBalance(
rpcList.map((rpc) => useWebsocketOrHttpTransport(rpc))
);
const callClient = createPublicClient({
name: "EthereumCall",
transport: transports,
chain: mainnet,
batch: {
multicall: true,
},
});
/**
* Subscribe to Chainlink price updates
*/
subscribeToChainLinkPriceUpdates({
feedAddresses: Object.values(ethereumDataFeeds),
publicClient: callClient,
onLogsFunction: (arrayOfLogs) => {
for (const log of arrayOfLogs) {
console.log(`Asset: ${log.description}`);
console.log(`🔘 Round ID: ${log.roundId}`);
if (log.description.includes("USD")) {
console.log(`📈 Answer: $${log.current}`);
} else if (log.description.includes("/ ETH")) {
console.log(`📈 Answer: Ξ${log.current}`);
} else {
console.log(`📈 Answer: ${log.current}`);
}
console.log(`⏰ Time: ${log.updatedAt}`);
console.log("----------------------------------------");
}
},
});