Skip to content

Commit

Permalink
flashbots: Add baseFee to callBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jparyani committed Aug 5, 2021
1 parent 44a53e7 commit c4cf5a9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,7 @@ type CallBundleArgs struct {
Timeout *int64 `json:"timeout"`
GasLimit *uint64 `json:"gasLimit"`
Difficulty *big.Int `json:"difficulty"`
BaseFee *big.Int `json:"baseFee"`
}

// CallBundle will simulate a bundle of transactions at the top of a given block
Expand Down Expand Up @@ -2187,13 +2188,20 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st
if args.GasLimit != nil {
gasLimit = *args.GasLimit
}
var baseFee *big.Int
if args.BaseFee != nil {
baseFee = args.BaseFee
} else if s.b.ChainConfig().IsLondon(big.NewInt(args.BlockNumber.Int64())) {
baseFee = misc.CalcBaseFee(s.b.ChainConfig(), parent)
}
header := &types.Header{
ParentHash: parent.Hash(),
Number: blockNumber,
GasLimit: gasLimit,
Time: timestamp,
Difficulty: difficulty,
Coinbase: coinbase,
BaseFee: baseFee,
}

// Setup context so it may be cancelled the call has completed
Expand Down Expand Up @@ -2246,7 +2254,11 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st
"toAddress": to,
}
totalGasUsed += receipt.GasUsed
gasFeesTx := new(big.Int).Mul(big.NewInt(int64(receipt.GasUsed)), tx.GasPrice())
gasPrice, err := tx.EffectiveGasTip(header.BaseFee)
if err != nil {
return nil, fmt.Errorf("err: %w; txhash %s", err, tx.Hash())
}
gasFeesTx := new(big.Int).Mul(big.NewInt(int64(receipt.GasUsed)), gasPrice)
gasFees.Add(gasFees, gasFeesTx)
bundleHash.Write(tx.Hash().Bytes())
if result.Err != nil {
Expand Down

0 comments on commit c4cf5a9

Please sign in to comment.