-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor NewOutboundData. Reserve space for EIP-1559
- Loading branch information
Showing
5 changed files
with
445 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package signer | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// gas represents gas parameters for EVM transactions. | ||
// | ||
// This is pretty interesting because all EVM chains now support EIP-1559, but some chains do it in a specific way | ||
// https://eips.ethereum.org/EIPS/eip-1559 | ||
// https://www.blocknative.com/blog/eip-1559-fees | ||
// https://github.com/bnb-chain/BEPs/blob/master/BEPs/BEP226.md (tl;dr: baseFee is always zero) | ||
type gas struct { | ||
Limit uint64 | ||
|
||
// MaxFeePerUnit absolute maximum we're willing to pay per unit of gas to get tx included in a block. | ||
MaxFeePerUnit *big.Int | ||
|
||
// PriorityFeePerUnit optional fee paid directly to validators. | ||
PriorityFeePerUnit *big.Int | ||
} | ||
|
||
func (g gas) validate() error { | ||
if g.Limit == 0 { | ||
return errors.New("gas limit is zero") | ||
} | ||
|
||
if g.MaxFeePerUnit == nil { | ||
return errors.New("max fee per unit is nil") | ||
} | ||
|
||
if g.PriorityFeePerUnit == nil { | ||
return errors.New("priority fee per unit is nil") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// isLegacy determines whether this gas is meant for LegacyTx{} (pre EIP-1559) | ||
// or DynamicFeeTx{} (post EIP-1559). | ||
// | ||
// Returns true if priority fee is <= 0. | ||
func (g gas) isLegacy() bool { | ||
return g.PriorityFeePerUnit.Sign() <= 1 | ||
} |
Oops, something went wrong.