Skip to content

feat: Gas Estimation Agent for multi-chain cost comparison#21

Open
dagangtj wants to merge 1 commit intoPayPol-Foundation:mainfrom
dagangtj:feat/gas-estimator-agent
Open

feat: Gas Estimation Agent for multi-chain cost comparison#21
dagangtj wants to merge 1 commit intoPayPol-Foundation:mainfrom
dagangtj:feat/gas-estimator-agent

Conversation

@dagangtj
Copy link

Overview

This PR implements a Gas Estimation Agent that compares real-time gas costs across Tempo L1, Ethereum, Arbitrum, and Base, helping users choose the most cost-effective chain for their transactions.

Closes

Closes #7

Features

Multi-chain support: Tempo L1, Ethereum, Arbitrum, Base
Real-time gas prices in gwei and USD equivalent
Cost estimation for common operations:

  • Simple transfer (21k gas)
  • ERC-20 transfer (65k gas)
  • Contract deployment (1.5M gas)
    Smart recommendations for cheapest chain
    15-second caching for performance
    RPC fallback handling for reliability

Example Response

{
  "operation": "ERC-20 Transfer",
  "estimates": [
    {"chain": "Tempo L1", "gasPrice": "0.00 gwei", "cost": "$0.0000", "speed": "1s"},
    {"chain": "Base", "gasPrice": "0.02 gwei", "cost": "$0.0039", "speed": "2s"},
    {"chain": "Arbitrum", "gasPrice": "0.05 gwei", "cost": "$0.0098", "speed": "2s"},
    {"chain": "Ethereum", "gasPrice": "25.00 gwei", "cost": "$4.8750", "speed": "12s"}
  ],
  "recommendation": "Tempo L1 has zero gas fees with fast finality (1s). Highly recommended for cost-sensitive operations."
}

Acceptance Criteria

All requirements from issue #7 fulfilled:

  • ✅ Queries gas prices from 4+ chains (Tempo, Ethereum, Arbitrum, Base)
  • ✅ Returns gas costs in native units (gwei) and USD equivalent
  • ✅ Estimates cost for common operations (transfer, ERC-20, deploy)
  • ✅ Provides recommendation for cheapest chain
  • ✅ Caches results with configurable TTL (default 15s)
  • ✅ Handles RPC failures gracefully with fallbacks
  • ✅ Registers on PayPol marketplace via SDK

Testing

cd agents/gas-estimator
npm install
npm run dev

Test endpoints:

  • GET /health - Health check
  • GET /manifest - Agent metadata
  • POST /execute - Run gas estimation

Implementation Details

  • RPC providers: Public endpoints with fallback support
  • Caching: 15-second TTL to reduce RPC calls
  • Error handling: Graceful degradation on RPC failures
  • Price oracle: ETH/USD price for cost calculations
  • TypeScript: Full type safety with ethers.js v6

Files Changed

  • agents/gas-estimator/src/index.ts - Main agent logic
  • agents/gas-estimator/src/register.ts - Marketplace registration
  • agents/gas-estimator/package.json - Dependencies
  • agents/gas-estimator/README.md - Documentation
  • agents/gas-estimator/.env.example - Configuration template

Implements issue PayPol-Foundation#7 - Gas Estimation Agent

Features:
- Multi-chain gas price queries (Tempo L1, Ethereum, Arbitrum, Base)
- Real-time gas costs in gwei and USD equivalent
- Cost estimation for common operations (transfer, ERC-20, deploy)
- Smart chain recommendation based on cost
- 15-second result caching for performance
- RPC failure handling with fallback providers

Acceptance criteria fulfilled:
✅ Queries gas prices from 4+ chains
✅ Returns costs in native units and USD
✅ Estimates common operation costs
✅ Provides cheapest chain recommendation
✅ Configurable TTL caching (15s)
✅ Graceful RPC failure handling
✅ PayPol marketplace SDK integration

Closes PayPol-Foundation#7
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.

Build a Gas Estimation Agent for Multi-chain

1 participant