Compute gas price for EIP-1559 transaction (#157)

This commit is contained in:
nikugogoi 2022-08-09 10:50:25 +05:30 committed by GitHub
parent 1a903fccc6
commit 5077abc90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 7 deletions

View File

@ -44,7 +44,7 @@ export const handler = async (argv: any): Promise<void> => {
await db.init(); await db.init();
{{#if (subgraphPath)}} {{#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(); await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

View File

@ -53,7 +53,7 @@ export const handler = async (argv: any): Promise<void> => {
const db = new Database(config.database); const db = new Database(config.database);
await db.init(); 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(); await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

View File

@ -33,8 +33,10 @@ export interface Transaction {
to: string; to: string;
value: string; value: string;
gasLimit: string; gasLimit: string;
gasPrice: string; gasPrice?: string;
input: string; input: string;
maxPriorityFeePerGas?: string,
maxFeePerGas?: string,
} }
export interface Block { export interface Block {
@ -53,6 +55,7 @@ export interface Block {
gasUsed: string; gasUsed: string;
author: string; author: string;
size: string; size: string;
baseFee?: string;
} }
export interface EventData { export interface EventData {
@ -369,7 +372,18 @@ export const createEvent = async (instanceExports: any, contractAddress: string,
const gasLimitStringPtr = await __newString(tx.gasLimit); const gasLimitStringPtr = await __newString(tx.gasLimit);
const txGasLimitPtr = await BigInt.fromString(gasLimitStringPtr); 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 txGasPricePtr = await BigInt.fromString(gasPriceStringPtr);
const inputStringPtr = await __newString(tx.input); const inputStringPtr = await __newString(tx.input);

View File

@ -41,7 +41,7 @@ export const handler = async (argv: any): Promise<void> => {
const db = new Database(config.database); const db = new Database(config.database);
await db.init(); 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(); await graphDb.init();
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

View File

@ -209,7 +209,8 @@ export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.
gasLimit: header.GasLimit.toString(), gasLimit: header.GasLimit.toString(),
gasUsed: header.GasUsed.toString(), gasUsed: header.GasUsed.toString(),
author: header.Beneficiary, 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(), value: txData.value.toString(),
gasLimit: txData.gasLimit.toString(), gasLimit: txData.gasLimit.toString(),
gasPrice: txData.gasPrice?.toString(), gasPrice: txData.gasPrice?.toString(),
input: txData.data input: txData.data,
maxPriorityFeePerGas: txData.maxPriorityFeePerGas?.toString(),
maxFeePerGas: txData.maxFeePerGas?.toString()
}; };
}; };