fix the formulas for fast/slow
This commit is contained in:
parent
deee0f205a
commit
d28cc9b3f7
@ -17,9 +17,12 @@ const blockGasPricesObservable = new Observable<GasPrices>((observer) => {
|
|||||||
if (!block) throw new Error(`Error fetching block! ${blockNumber}`);
|
if (!block) throw new Error(`Error fetching block! ${blockNumber}`);
|
||||||
|
|
||||||
const gasPrices = block.prefetchedTransactions.map((tx) => tx.gasPrice);
|
const gasPrices = block.prefetchedTransactions.map((tx) => tx.gasPrice);
|
||||||
const fast = Number(formatUnits(gasPrices[Math.floor(gasPrices.length * 0.9)], "gwei"));
|
const fast = Number(formatUnits(gasPrices[Math.floor(gasPrices.length * 0.1)], "gwei"));
|
||||||
const average = Number(formatUnits(gasPrices[Math.floor(gasPrices.length / 2)], "gwei"));
|
const average = Number(formatUnits(gasPrices[Math.floor(gasPrices.length / 2)], "gwei"));
|
||||||
const slow = Number(formatUnits(gasPrices[Math.floor(gasPrices.length * 0.05)], "gwei"));
|
const slow = Number(formatUnits(gasPrices[Math.floor(gasPrices.length * 0.95)], "gwei"));
|
||||||
|
|
||||||
|
// Log averages every 10 blocks
|
||||||
|
if (blockNumber % 10 == 0) console.log(`Found new block data for ${blockNumber}! Base average transaction cost: ${slow} Gwei`)
|
||||||
|
|
||||||
observer.next({ fast, average, slow } as GasPrices);
|
observer.next({ fast, average, slow } as GasPrices);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -35,9 +38,9 @@ const averageGasPricesObservable = blockGasPricesObservable.pipe(
|
|||||||
const averageSum = blocks.reduce((sum, block) => sum + block.average, 0);
|
const averageSum = blocks.reduce((sum, block) => sum + block.average, 0);
|
||||||
const slowSum = blocks.reduce((sum, block) => sum + block.slow, 0);
|
const slowSum = blocks.reduce((sum, block) => sum + block.slow, 0);
|
||||||
return {
|
return {
|
||||||
fast: fastSum / blocks.length,
|
fast: Math.round(fastSum / blocks.length),
|
||||||
average: averageSum / blocks.length,
|
average: Math.round(averageSum / blocks.length),
|
||||||
slow: slowSum / blocks.length,
|
slow: Math.round(slowSum / blocks.length),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user