Skip to content

Commit

Permalink
Update Gas Magic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Sep 2, 2024
1 parent 0d03ab5 commit fc0af89
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
18 changes: 8 additions & 10 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ export const App = () => {
<div className="text-right font-bold text-lg">
{formatThousands(totals.renewAverage)}
</div>
{currentUSDCPrice ? (
<div className="text-light-text-secondary flex justify-between gap-2 items-center">
<div className="flex items-center gap-1">
<BsFuelPump />
{formatGas(
totals.renewGasPriceAverage
)}
</div>
<div className="text-light-text-secondary flex justify-between gap-2 items-center">
<div className="flex items-center gap-1">
<BsFuelPump />
{formatGas(totals.renewGasPriceAverage)}
</div>
{currentUSDCPrice ? (
<div className="text-right flex items-center justify-end">
~{' '}
{gasPriceMagic(
Expand All @@ -154,8 +152,8 @@ export const App = () => {
)}{' '}
USD
</div>
</div>
) : undefined}
) : undefined}
</div>
</div>
) : (
<div>Loading...</div>
Expand Down
23 changes: 17 additions & 6 deletions web/src/txHistory/TransactionEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FiBox, FiChevronDown } from 'react-icons/fi';
import { formatFullAndRelativeDate } from '../utils/date';
import { AllMultiReturnTypes } from '../utils/decodeTransaction';
import { useEthUsd } from '../utils/ethUsd';
import { formatGas } from '../utils/formatGas';
import { formatThousands } from '../utils/formatThousands';

const formatAddress = (address: string) =>
Expand Down Expand Up @@ -59,18 +60,28 @@ export const TransactionEntry: FC<{ tx: AllMultiReturnTypes }> = ({ tx }) => {
)}
{tx.length > 0 && (
<div className="text-center">
<div>
{formatThousands(
BigInt(tx.gas_used) / BigInt(tx.length)
)}
<div className="text-sm">
<span>
{formatThousands(
BigInt(tx.gas_used) / BigInt(tx.length)
)}
{tx.length > 1 && ' each'}
</span>
</div>
<div className="text-xs">Per Name</div>
{tx.length > 1 && (
<span className="text-xs">
<span>
{formatThousands(BigInt(tx.gas_used))}
</span>{' '}
total
</span>
)}
</div>
)}
<div className="flex flex-col justify-center items-center gap-1">
<div className="flex justify-center items-center gap-1">
<BsFuelPump />
<div>{formatThousands(BigInt(tx.gas_used))}</div>
<div>{formatGas(BigInt(tx.gas_price))}</div>
</div>
{ethUsd.data ? (
<div className="text-sm opacity-70">
Expand Down
4 changes: 4 additions & 0 deletions web/src/utils/aggregateTotals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AllMultiReturnTypes } from './decodeTransaction';

// gas_price - 9 decimals

export const aggregateTotals = (txs: AllMultiReturnTypes[]) => {
const aggregates = txs.reduce(
(aggregate, current) => {
Expand Down Expand Up @@ -38,6 +40,8 @@ export const aggregateTotals = (txs: AllMultiReturnTypes[]) => {
}
);

console.log({ aggregates });

return {
commitAverage: aggregates.commitTotal / aggregates.commitCount,
commitGasPriceAverage:
Expand Down
2 changes: 1 addition & 1 deletion web/src/utils/formatGas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Divide by 10e8 to get gwei but keep 2 decimals of precision so 1.23 return as string
export const formatGas = (gas: BigInt): string => {
return (Number(BigInt(gas.toString()) / BigInt(10e6)) / 10).toString();
return (Number(BigInt(gas.toString()) / BigInt(10e6)) / 100).toString();
};
8 changes: 1 addition & 7 deletions web/src/utils/gasMagic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ export const gasPriceMagic = (
ethUSDC: bigint
) => {
return (
Number(
BigInt(
Math.round(
Number(BigInt((gas * gasPrice) / 10_000n) * BigInt(ethUSDC))
)
) / 1_000_000n
) / 1_000_000_000_000
Number((BigInt(gas * gasPrice) * BigInt(ethUSDC)) / 1_000_000n) / 1e18
).toPrecision(3);
};

0 comments on commit fc0af89

Please sign in to comment.