Skip to content

Commit

Permalink
updated gas computations
Browse files Browse the repository at this point in the history
  • Loading branch information
kakucodes committed Mar 2, 2024
1 parent 75ffdc1 commit 96777c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ at time of writing the results look as such

```json
{
"mean": "0.0752 JUNO (1,002,915 gas)",
"median": "0.0642 JUNO (856,634 gas)",
"lowest": "0.0091 JUNO (120,677 gas)",
"highest": "0.3773 JUNO (5,031,033 gas)",
"mean": "0.0764 JUNO (1,018,828 gas)",
"median": "0.0653 JUNO (870,018 gas)",
"lowest": "0.0105 JUNO (140,302 gas)",
"highest": "0.3845 JUNO (5,126,844 gas)",
"totalCount": 11400,
"totalGasWanted": "871.0986 JUNO (11,614,647,418 gas)",
"totalGasUsed": "857.4926 JUNO (11,433,234,409 gas)"
}
```
16 changes: 11 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const displayGas = (gas: bigint): string =>
{ sender: string; amount: bigint; txHash: string[]; burnCount: number }
> = {};

let sumGasUsed = BigInt(0);
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(
Expand All @@ -29,17 +30,21 @@ const displayGas = (gas: bigint): string =>
);

const allGasFeesUsed =
compoundings?.txs?.map(({ gas_used }) => BigInt(gas_used)) || [];
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++;
sumGasUsed += used;
allGasWanted += used;
});
}

const mean = displayGas(sumGasUsed / BigInt(totalTxs));
const mean = displayGas(allGasWanted / BigInt(totalTxs));

const sortedGassesPaid = allGasPaid.sort(
(a, b) => Number(a.toString()) - Number(b.toString())
Expand All @@ -57,6 +62,7 @@ const displayGas = (gas: bigint): string =>
lowest,
highest,
totalCount: totalTxs,
totalGasUsed: displayGas(sumGasUsed),
totalGasWanted: displayGas(allGasWanted),
totalGasUsed: displayGas(allGasUsed.reduce((a, b) => a + b)),
});
})();

0 comments on commit 96777c8

Please sign in to comment.