Skip to content

[Feature 11] Gas Optimization #30

@onlyhyde

Description

@onlyhyde

Overview

Implement gas estimation, EIP-1559 pricing, and retry logic with gas bumping.

Implementation Details

Files:

  • internal/gas/estimator.go - Gas estimation
  • internal/gas/eip1559.go - EIP-1559 gas pricing
  • internal/gas/retry.go - Retry with gas bumping

Gas Estimator

type EstimatorConfig struct {
    GasLimitMultiplier float64  // Default: 1.2 (20% buffer)
    MaxGasLimit        uint64   // Default: 3,000,000
    MinGasLimit        uint64   // Default: 21,000
}

func (e *Estimator) Estimate(ctx, msg ethereum.CallMsg) (uint64, error)

EIP-1559 Gas Price Oracle

type GasPrice struct {
    MaxFeePerGas         *big.Int
    MaxPriorityFeePerGas *big.Int
    BaseFee              *big.Int
}

func (o *PriceOracle) GetGasPrice(ctx) (*GasPrice, error)
  • Get base fee from latest block
  • Get priority fee from eth_maxPriorityFeePerGas
  • Calculate: MaxFee = 2 * BaseFee + PriorityFee
  • Apply configurable max limits

Retry Logic

type RetryConfig struct {
    MaxRetries       int           // Default: 3
    InitialDelay     time.Duration // Default: 5s
    MaxDelay         time.Duration // Default: 30s
    GasBumpPercent   int64         // Default: 10 (10%)
    MaxGasBumpFactor int64         // Default: 3 (3x original)
}

Retryable Errors:

  • "replacement transaction underpriced"
  • "nonce too low"
  • "transaction underpriced"
  • "intrinsic gas too low"

Gas Bumping: Increase gas price by GasBumpPercent per retry attempt.

Integration

func (s *EVMSigner) SendTransactionWithRetry(
    ctx context.Context,
    to string,
    data []byte,
    gasEstimator *gas.Estimator,
    gasOracle *gas.PriceOracle,
    retrier *gas.Retrier,
) (string, error)

Acceptance Criteria

  • Gas estimator with buffer
  • EIP-1559 gas price oracle
  • Retry logic with exponential backoff
  • Gas price bumping on retry
  • Max limits enforcement
  • Retryable error detection
  • Unit tests
  • Integration tests with testnet

Dependencies

Branch

feature/gas-optimization

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions