baseFeePerGasBins = {
const allBaseFeesPerGas = blocks
.map((block) => block.baseFeePerGas)
.sort((a, b) => a - b);
const chunkRequests = _.uniqBy(
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100].map((percentile) => {
const index = Math.floor(allBaseFeesPerGas.length * (percentile / 100));
return { percentile, index };
}),
"index"
);
const bins = [];
for (let i = 0; i < chunkRequests.length - 1; i++) {
const [chunkRequest, nextChunkRequest] = [
chunkRequests[i],
chunkRequests[i + 1]
];
const chunk = allBaseFeesPerGas.slice(
chunkRequest.index,
nextChunkRequest.index
);
bins.push({
threshold: {
start: chunk[0],
end: chunk[chunk.length - 1]
},
size: chunk.length
});
}
return bins;
}