-
Notifications
You must be signed in to change notification settings - Fork 0
/
scroll.ts
83 lines (76 loc) · 2.14 KB
/
scroll.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
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
75
76
77
78
79
80
81
82
83
import { createPublicClient, defineChain } from "viem";
import { subscribeToChainLinkPriceUpdates } from "../src/Aggregator.js";
import { scrollDataFeeds } from "../src/dataFeeds/scroll.js";
import { useWebsocketOrHttpTransport } from "../src/utils.js";
import ChainLinkDataFeed from "../src/ChainLinkDataFeed.js";
import { loadBalance } from "@ponder/utils";
const rpcList = [
"https://scroll-mainnet.public.blastapi.io",
"https://scroll.blockpi.network/v1/rpc/public ",
"https://rpc.scroll.io",
];
const transports = loadBalance(
rpcList.map((rpc) => useWebsocketOrHttpTransport(rpc))
);
const scrollChain = defineChain({
id: 534352,
name: "Scroll",
network: "scroll",
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
rpcUrls: {
public: {
http: ["https://rpc.scroll.io"],
},
default: {
http: ["https://rpc.scroll.io"],
},
},
blockExplorers: {
default: {
name: "ScrollScan",
url: "https://scrollscan.com/",
},
},
contracts: {
multicall3: {
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
blockCreated: 14,
},
},
});
const callClient = createPublicClient({
name: "ScrollCall",
transport: transports,
chain: scrollChain,
batch: {
multicall: true,
},
});
const feed = new ChainLinkDataFeed({
contractAddress: scrollDataFeeds["ETH / USD"],
viemClient: callClient,
});
console.log("Price of ETH / USD :", await feed.getLatestRoundData(true));
subscribeToChainLinkPriceUpdates({
feedAddresses: Object.values(scrollDataFeeds),
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("----------------------------------------");
}
},
});