mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-08 12:28:05 +00:00
Compute gas price for EIP-1559 transaction (#157)
This commit is contained in:
parent
1a903fccc6
commit
5077abc90f
@ -44,7 +44,7 @@ export const handler = async (argv: any): Promise<void> => {
|
||||
await db.init();
|
||||
{{#if (subgraphPath)}}
|
||||
|
||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
|
||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../../entity/*'));
|
||||
await graphDb.init();
|
||||
|
||||
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
|
||||
|
@ -53,7 +53,7 @@ export const handler = async (argv: any): Promise<void> => {
|
||||
const db = new Database(config.database);
|
||||
await db.init();
|
||||
|
||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
|
||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../../entity/*'));
|
||||
await graphDb.init();
|
||||
|
||||
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
|
||||
|
@ -33,8 +33,10 @@ export interface Transaction {
|
||||
to: string;
|
||||
value: string;
|
||||
gasLimit: string;
|
||||
gasPrice: string;
|
||||
gasPrice?: string;
|
||||
input: string;
|
||||
maxPriorityFeePerGas?: string,
|
||||
maxFeePerGas?: string,
|
||||
}
|
||||
|
||||
export interface Block {
|
||||
@ -53,6 +55,7 @@ export interface Block {
|
||||
gasUsed: string;
|
||||
author: string;
|
||||
size: string;
|
||||
baseFee?: string;
|
||||
}
|
||||
|
||||
export interface EventData {
|
||||
@ -369,7 +372,18 @@ export const createEvent = async (instanceExports: any, contractAddress: string,
|
||||
const gasLimitStringPtr = await __newString(tx.gasLimit);
|
||||
const txGasLimitPtr = await BigInt.fromString(gasLimitStringPtr);
|
||||
|
||||
const gasPriceStringPtr = await __newString(tx.gasPrice);
|
||||
let gasPrice = tx.gasPrice;
|
||||
|
||||
if (!gasPrice) {
|
||||
// Compute gasPrice for EIP-1559 transaction
|
||||
// https://ethereum.stackexchange.com/questions/122090/what-does-tx-gasprice-represent-after-eip-1559
|
||||
const feeDifference = BigNumber.from(tx.maxFeePerGas).sub(BigNumber.from(blockData.baseFee));
|
||||
const maxPriorityFeePerGas = BigNumber.from(tx.maxPriorityFeePerGas);
|
||||
const priorityFeePerGas = maxPriorityFeePerGas.lt(feeDifference) ? maxPriorityFeePerGas : feeDifference;
|
||||
gasPrice = BigNumber.from(blockData.baseFee).add(priorityFeePerGas).toString();
|
||||
}
|
||||
|
||||
const gasPriceStringPtr = await __newString(gasPrice);
|
||||
const txGasPricePtr = await BigInt.fromString(gasPriceStringPtr);
|
||||
|
||||
const inputStringPtr = await __newString(tx.input);
|
||||
|
@ -41,7 +41,7 @@ export const handler = async (argv: any): Promise<void> => {
|
||||
const db = new Database(config.database);
|
||||
await db.init();
|
||||
|
||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
|
||||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../../entity/*'));
|
||||
await graphDb.init();
|
||||
|
||||
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
|
||||
|
@ -209,7 +209,8 @@ export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.
|
||||
gasLimit: header.GasLimit.toString(),
|
||||
gasUsed: header.GasUsed.toString(),
|
||||
author: header.Beneficiary,
|
||||
size: BigInt(size).toString()
|
||||
size: BigInt(size).toString(),
|
||||
baseFee: header.BaseFee?.toString()
|
||||
};
|
||||
};
|
||||
|
||||
@ -232,6 +233,8 @@ export const getFullTransaction = async (ethClient: EthClient, txHash: string):
|
||||
value: txData.value.toString(),
|
||||
gasLimit: txData.gasLimit.toString(),
|
||||
gasPrice: txData.gasPrice?.toString(),
|
||||
input: txData.data
|
||||
input: txData.data,
|
||||
maxPriorityFeePerGas: txData.maxPriorityFeePerGas?.toString(),
|
||||
maxFeePerGas: txData.maxFeePerGas?.toString()
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user