Skip to content

Commit

Permalink
Fixed EIP-1559 from address calculation bug (#1610).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 24, 2021
1 parent 2a7ce0e commit 319987e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/abstract-provider/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface _Block {
miner: string;
extraData: string;

baseFee?: null | BigNumber;
baseFeePerGas?: null | BigNumber;
}

export interface Block extends _Block {
Expand Down Expand Up @@ -238,12 +238,12 @@ export abstract class Provider implements OnceBlockable {

let maxFeePerGas = null, maxPriorityFeePerGas = null;

if (block && block.baseFee) {
if (block && block.baseFeePerGas) {
// We may want to compute this more accurately in the future,
// using the formula "check if the base fee is correct".
// See: https://eips.ethereum.org/EIPS/eip-1559
maxPriorityFeePerGas = BigNumber.from("1000000000");
maxFeePerGas = block.baseFee.mul(2).add(maxPriorityFeePerGas);
maxFeePerGas = block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas);
}

return { maxFeePerGas, maxPriorityFeePerGas, gasPrice };
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src.ts/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class Formatter {

transactions: Formatter.allowNull(Formatter.arrayOf(hash)),

baseFee: Formatter.allowNull(bigNumber)
baseFeePerGas: Formatter.allowNull(bigNumber)
};

formats.blockWithTransactions = shallowCopy(formats.block);
Expand Down
4 changes: 2 additions & 2 deletions packages/transactions/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function _parseEip1559(payload: Uint8Array): Transaction {
nonce: handleNumber(transaction[1]).toNumber(),
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
gasPrice: maxPriorityFeePerGas.add(maxFeePerGas),
gasPrice: maxFeePerGas,
gasLimit: handleNumber(transaction[4]),
to: handleAddress(transaction[5]),
value: handleNumber(transaction[6]),
Expand All @@ -375,7 +375,7 @@ function _parseEip1559(payload: Uint8Array): Transaction {

tx.hash = keccak256(payload);

_parseEipSignature(tx, transaction.slice(9), _serializeEip2930);
_parseEipSignature(tx, transaction.slice(9), _serializeEip1559);

return tx;
}
Expand Down

0 comments on commit 319987e

Please sign in to comment.