Skip to content

Commit

Permalink
Refactor NewOutboundData. Reserve space for EIP-1559
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 committed Jun 26, 2024
1 parent 0bfe518 commit f576733
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 276 deletions.
47 changes: 47 additions & 0 deletions zetaclient/chains/evm/signer/gas.go
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")

Check warning on line 27 in zetaclient/chains/evm/signer/gas.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/gas.go#L27

Added line #L27 was not covered by tests
}

if g.MaxFeePerUnit == nil {
return errors.New("max fee per unit is nil")

Check warning on line 31 in zetaclient/chains/evm/signer/gas.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/gas.go#L31

Added line #L31 was not covered by tests
}

if g.PriorityFeePerUnit == nil {
return errors.New("priority fee per unit is nil")

Check warning on line 35 in zetaclient/chains/evm/signer/gas.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/gas.go#L35

Added line #L35 was not covered by tests
}

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
}
Loading

0 comments on commit f576733

Please sign in to comment.