-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
83 lines (68 loc) · 2.11 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
import { CompoundResp, MessageType } from "./compounds";
const { StargateClient } = require("@cosmjs/stargate");
const fs = require("fs");
const GAS_FEE = 0.075;
const stdDev = (xs: number[], mean: number): number =>
Math.sqrt(
xs.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / xs.length
);
const displayGas = (gas: bigint): string =>
`${((Number(gas) * GAS_FEE) / 1_000_000).toFixed(4)} JUNO (${Number(
gas
).toLocaleString()} gas)`;
(async () => {
const allBurnEvents: Record<
string,
{ sender: string; amount: bigint; txHash: string[]; burnCount: number }
> = {};
let allGasWanted = BigInt(0);
let totalTxs = 0;
let allGasPaid: bigint[] = [];
let allGasUsed: bigint[] = [];
for (let i = 1; i < 229; i++) {
const compoundings: CompoundResp = JSON.parse(
fs.readFileSync(`./compounds_query_results/test_output.${i}.json`, {
encoding: "utf8",
flag: "r",
})
);
const allGasFeesUsed =
compoundings?.txs?.map(({ gas_wanted }) => BigInt(gas_wanted)) || [];
compoundings.txs.forEach(({ gas_used }) =>
allGasUsed.push(BigInt(gas_used))
);
allGasPaid = allGasPaid.concat(allGasFeesUsed);
allGasFeesUsed.forEach((used) => {
totalTxs++;
allGasWanted += used;
});
}
const mean = displayGas(allGasWanted / BigInt(totalTxs));
const sortedGassesPaid = allGasPaid.sort(
(a, b) => Number(a.toString()) - Number(b.toString())
);
const median = displayGas(
sortedGassesPaid[Math.floor(sortedGassesPaid.length / 2)]
);
const lowest = displayGas(sortedGassesPaid[0]);
const highest = displayGas(sortedGassesPaid.at(-1) || BigInt(0));
console.log({
mean,
median,
lowest,
highest,
totalCount: totalTxs,
totalGasWanted: displayGas(allGasWanted),
// totalGasUsed: displayGas(allGasUsed.reduce((a, b) => a + b)),
// gasWantedStdDeviation: displayGas(
// BigInt(
// parseInt(
// stdDev(
// allGasPaid.map(Number),
// Number(allGasWanted / BigInt(totalTxs))
// ).toString()
// )
// )
// ),
});
})();