这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@fengtality
Copy link
Contributor

Summary

This PR improves gas estimation across Ethereum and Solana chains with refactored configuration parameters, per-network caching, and enhanced error handling.

Key Changes

1. Gas Configuration Refactoring

EIP-1559 Networks (Ethereum Mainnet, Polygon, Arbitrum, Optimism, Base):

  • ✅ Replace maxFeePerGas and maxPriorityFeePerGas with baseFee and priorityFee
  • ✅ Add configurable baseFeeMultiplier parameter (default: 1.2 for 20% buffer)
  • ✅ Transaction fee formula: maxFeePerGas = baseFee * baseFeeMultiplier + priorityFee
  • ✅ Change default priorityFee from 0.01 to 0.001 GWEI
  • ✅ Support partial configuration (can override individual parameters)
  • ✅ Fetch from Etherscan API or network RPC when not configured

Legacy Networks (Avalanche, BSC, Celo, Sepolia):

  • ✅ Rename minGasPrice to gasPrice
  • ✅ Fetch from network RPC when not configured
  • ✅ Remove hardcoded fallback values (throw clear errors instead)

2. Per-Network Gas Caching

Bug Fix: Fixed cross-network cache contamination where Base network was returning Mainnet gas prices

  • ✅ Change from single static cache to per-network map
  • ✅ Each network maintains independent 10-second cache
  • ✅ Applies to both Ethereum (ethereum.ts) and Solana (solana-priority-fees.ts)

3. Enhanced Error Handling

Better HTTP status codes and error messages for gas estimation failures:

  • 503 Service Unavailable: RPC provider/network connectivity errors
  • 400 Bad Request: Invalid network configuration
  • 500 Internal Server Error: Generic failures

Error messages now include network context and specific failure reasons.

4. Schema and Configuration Updates

  • ✅ Update ethereum-network-schema.json with new gas parameters
  • ✅ Update solana-network-schema.json for consistency
  • ✅ Update all 9 Ethereum network templates (src/templates/chains/ethereum/)
  • ✅ Update 2 Solana network templates (src/templates/chains/solana/)
  • ✅ Add type unions ["number", "null"] for optional numeric fields

Files Changed

Core Implementation (5 files):

  • src/chains/ethereum/ethereum.config.ts - Update interface with new gas parameters
  • src/chains/ethereum/ethereum.ts - Refactor gas estimation logic, per-network cache
  • src/chains/ethereum/routes/estimate-gas.ts - Enhanced error handling
  • src/chains/solana/solana-priority-fees.ts - Per-network cache for Solana
  • src/chains/solana/solana.ts - Pass network parameter to priority fee estimation

Templates (13 files):

  • All Ethereum network configs (9 networks)
  • All Solana network configs (2 networks)
  • Network JSON schemas (2 files)

Tests (2 files):

  • test/chains/ethereum/routes/estimate-gas.test.ts - Updated for new params and error handling
  • test/chains/ethereum/infura-service.test.ts - Removed deprecated minGasPrice

Test Plan

  • ✅ All estimate-gas route tests passing (6 tests)
  • ✅ All Infura service tests passing (10 tests)
  • ✅ All Etherscan service tests passing (17 tests)
  • ✅ All main Ethereum chain tests passing (12 tests)
  • ✅ TypeScript compilation successful
  • ✅ Linter checks passing

Test Coverage

# Run estimate-gas tests
TMPDIR=/tmp GATEWAY_TEST_MODE=dev pnpm test test/chains/ethereum/routes/estimate-gas.test.ts

# Run Infura service tests
TMPDIR=/tmp GATEWAY_TEST_MODE=dev pnpm test test/chains/ethereum/infura-service.test.ts

# Run Etherscan service tests
TMPDIR=/tmp GATEWAY_TEST_MODE=dev pnpm test test/chains/ethereum/etherscan-service.test.ts

Migration Notes

Breaking Changes: Gas parameter names have changed in network configuration files. Users will need to update their conf/chains/ethereum/*.yml and conf/chains/solana/*.yml files.

Before (EIP-1559):

maxFeePerGas: 100
maxPriorityFeePerGas: 2

After (EIP-1559):

baseFee:
baseFeeMultiplier: 1.2
priorityFee: 0.001

Before (Legacy):

minGasPrice: 25

After (Legacy):

gasPrice:

Leave values empty to fetch from network. The baseFeeMultiplier defaults to 1.2 if not specified.

🤖 Generated with Claude Code

…ror handling

## Gas Configuration Refactoring

### EIP-1559 Networks (Ethereum, Polygon, Arbitrum, Optimism, Base)
- Replace `maxFeePerGas` and `maxPriorityFeePerGas` with `baseFee` and `priorityFee`
- Add configurable `baseFeeMultiplier` parameter (default: 1.2)
- Transaction fee formula: `maxFeePerGas = baseFee * baseFeeMultiplier + priorityFee`
- Default `priorityFee` changed from 0.01 to 0.001 GWEI
- Support partial configuration: can override individual gas parameters
- Fetch values from network/Etherscan API when not configured

### Legacy Networks (Avalanche, BSC, Celo, Sepolia)
- Rename `minGasPrice` to `gasPrice`
- Fetch from network RPC when not configured
- Remove hardcoded fallback values

## Per-Network Gas Caching
- Fix cross-network cache contamination bug
- Change from single static cache to per-network map
- Each network maintains independent 10-second cache
- Applies to both Ethereum and Solana chains

## Improved Error Handling
- **503 Service Unavailable**: RPC provider/network errors
- **400 Bad Request**: Invalid network configuration
- **500 Internal Server Error**: Generic failures
- Better error messages with context

## Schema Updates
- Update `ethereum-network-schema.json` and `solana-network-schema.json`
- Add type unions `["number", "null"]` for optional numeric fields
- Update all 9 Ethereum network templates
- Update 2 Solana network templates

## Test Coverage
- Update estimate-gas route tests for new parameters
- Add comprehensive error handling test cases
- Remove deprecated `minGasPrice` from mock configs
- All tests passing (6 estimate-gas tests, 10 infura tests, 17 etherscan tests)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@fengtality fengtality closed this Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants