-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
91 lines (72 loc) · 2.9 KB
/
index.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
84
85
86
87
88
89
90
91
import { BigNumber } from "ethers";
import { formatEther } from "ethers/lib/utils";
import fetch from "node-fetch";
import slots from "./slots.json";
import * as fs from "fs";
const possibleBidsAPI = [
`https://boost-relay.flashbots.net/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
`https://bloxroute.max-profit.blxrbdn.com/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
`https://bloxroute.ethical.blxrbdn.com/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
`https://bloxroute.regulated.blxrbdn.com/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
`https://builder-relay-mainnet.blocknative.com/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
`https://relay.edennetwork.io/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
// `https://mainnet-relay.securerpc.com/relay/v1/data/bidtraces/builder_blocks_received?slot=`,
];
const findMaxBid = <T extends { value: string }>(bids: T[]): T => {
return bids.reduce((max, cur) => {
if (BigNumber.from(cur.value).gt(BigNumber.from(max.value))) {
return cur;
}
return max;
});
};
const findMaxBidForSlot = async (slot: number) => {
const bids = await Promise.all(
possibleBidsAPI.map(async (url) => {
const response = await fetch(url + slot);
const result = await response.json();
const hostname = new URL(url).hostname;
return result.map((bid) => ({ ...bid, hostname }));
})
);
const flatBids = bids.flat();
return findMaxBid(flatBids);
};
(async () => {
let totalReceivedValue = BigNumber.from(0);
let totalPossibleValue = BigNumber.from(0);
let totalLidoReceivedValue = BigNumber.from(0);
let totalLidoPossibleValue = BigNumber.from(0);
const result = [];
for (let i = 0; i < slots.length; i++) {
const { slot, deltaBalance, operator } = slots[i];
const maxBid = await findMaxBidForSlot(slot);
totalReceivedValue = BigNumber.from(deltaBalance).gt(0)
? totalReceivedValue.add(deltaBalance)
: totalReceivedValue;
totalPossibleValue = totalPossibleValue.add(maxBid.value);
if (operator != null) {
totalLidoReceivedValue = BigNumber.from(deltaBalance).gt(0)
? totalLidoReceivedValue.add(deltaBalance)
: totalLidoReceivedValue;
totalLidoPossibleValue = totalLidoPossibleValue.add(maxBid.value);
}
result.push({
slot,
operator,
deltaBalance: formatEther(deltaBalance),
maxBid: formatEther(maxBid.value),
relayUrl: maxBid.hostname,
});
console.log(`slot ${slot} processed`);
}
const summary = {
totalReceivedValue: formatEther(totalReceivedValue),
totalPossibleValue: formatEther(totalPossibleValue),
totalLidoReceivedValue: formatEther(totalLidoReceivedValue),
totalLidoPossibleValue: formatEther(totalLidoPossibleValue),
};
console.table(result);
console.table([summary]);
fs.writeFileSync("./dump.json", JSON.stringify(result));
})();