Install
$ agentstack add skill-sperax-sperax-skills-gas-optimization-guide ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Gas Optimization Guide
Gas costs can make or break DeFi strategies. This guide covers how gas works and how to minimize costs across chains.
How Gas Works
Ethereum L1
Transaction Cost = Gas Used × Gas Price (Gwei) × ETH Price
Example:
- Simple transfer: 21,000 gas
- Gas price: 30 Gwei
- ETH price: $3,200
- Cost: 21,000 × 30 × 10⁻⁹ × $3,200 = $2.02
Key terms: | Term | Meaning | |------|---------| | Gas Limit | Maximum gas you're willing to consume | | Gas Used | Actual gas consumed by the transaction | | Base Fee | Minimum fee set by the network (burned) | | Priority Fee (Tip) | Extra fee to incentivize miners/validators | | Max Fee | Maximum total you'll pay per gas unit |
L2 Chains (Arbitrum, Base, Optimism)
L2 gas has two components:
L2 Cost = L2 Execution + L1 Data Posting
L2 Execution: Very cheap (~100x cheaper than L1)
L1 Data Posting: Variable (posting tx data to Ethereum)
After EIP-4844 (blobs), L1 data costs dropped dramatically:
- Pre-4844: L1 data was ~80% of L2 tx cost
- Post-4844: L1 data is negligible for most L2s
Real Cost Comparison
| Operation | Ethereum L1 | Arbitrum | Base | Polygon | |-----------|------------|----------|------|---------| | ETH Transfer | $2–10 | $0.01–0.05 | $0.01–0.03 | $0.01 | | ERC-20 Transfer | $5–15 | $0.02–0.10 | $0.02–0.05 | $0.01 | | Uniswap Swap | $10–50 | $0.05–0.30 | $0.03–0.15 | $0.02 | | Aave Supply | $10–40 | $0.05–0.20 | $0.03–0.10 | $0.02 | | LP Add Liquidity | $15–60 | $0.10–0.50 | $0.05–0.20 | $0.03 | | Complex DeFi (multi-step) | $30–100+ | $0.20–1.00 | $0.10–0.50 | $0.05 |
Bottom line: Arbitrum and Base are 50–200x cheaper than Ethereum L1 for the same operations.
> This is why protocols like Sperax deploy on Arbitrum — USDs minting, SPA staking, and farm operations all cost pennies instead of dollars.
Gas Price APIs
Ethereum L1
| Source | Endpoint | Key | |--------|----------|-----| | Etherscan | api.etherscan.io/api?module=gastracker&action=gasoracle | Free API key | | Blocknative | api.blocknative.com/gasprices/blockprices | Free tier | | ETH Gas Station | ethgasstation.info/api/ethgasAPI.json | None |
L2 Chains
Most L2s don't need gas trackers — gas is consistently cheap. Use standard eth_gasPrice RPC call.
Multi-Chain Gas Comparison
// Quick check via RPC
const gasPrice = await provider.getGasPrice();
const gasPriceGwei = ethers.utils.formatUnits(gasPrice, "gwei");
When to Transact
Ethereum L1 Gas Patterns
| Time (UTC) | Gas Level | Why | |------------|-----------|-----| | 00:00–06:00 | Lowest | US asleep, Asia winding down | | 06:00–08:00 | Rising | Europe waking up | | 12:00–16:00 | Highest | US + Europe overlap | | 20:00–00:00 | Declining | US evening |
Weekend vs Weekday: Weekends are 20–40% cheaper on average.
L2 Tip
Gas timing doesn't matter much on L2s — costs are already pennies. Don't overthink it.
Gas by Operation Type
Cheapest to Most Expensive
21,000 gas — ETH transfer
~65,000 gas — ERC-20 transfer
~100,000 gas — ERC-20 approve
~150,000 gas — Simple swap (V2)
~200,000 gas — Swap (V3)
~250,000 gas — Add liquidity (V2)
~350,000 gas — Add liquidity (V3, concentrated)
~400,000 gas — Aave supply + borrow
~500,000+ gas — Complex strategies (multi-hop, flash loan)
Optimization Strategies
Strategy 1: Use L2s
The single biggest optimization. Move your DeFi activity to Arbitrum, Base, or Optimism.
Cost to bridge: ~$2–5 (one-time) Savings: $10–50 per transaction thereafter
Strategy 2: Batch Transactions
Some protocols support batching multiple operations:
- Multicall: Execute multiple contract calls in one transaction
- Permit2: Batch approvals (Uniswap's approach)
- Safe (Gnosis): Batch multiple operations in one multisig tx
Strategy 3: Use Permit Instead of Approve
Traditional flow: approve() (1 tx) + swap() (1 tx) = 2 transactions With Permit: Sign message off-chain + swap() (1 tx) = 1 transaction
Supported by: Uniswap Permit2, 1inch, many modern protocols
Strategy 4: Set Gas Intelligently
// Don't overpay — set reasonable max fee
const tx = {
maxFeePerGas: currentBaseFee * 1.5, // 50% buffer
maxPriorityFeePerGas: 1_500_000_000, // 1.5 Gwei tip
};
Strategy 5: Avoid Peak Times (L1 Only)
For non-urgent L1 transactions:
- Check current gas price
- Set a target (e.g., active farming** for small portfolios — gas costs eat into farms under $5K on L1
- Arbitrum is ideal — same DeFi functionality at 1/100th the cost (why Sperax chose it)
Links
- Etherscan Gas Tracker: https://etherscan.io/gastracker
- Blocknative Gas Estimator: https://blocknative.com/gas-estimator
- Arbiscan: https://arbiscan.io
- L2 Fees: https://l2fees.info
- Sperax on Arbitrum: https://app.sperax.io
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: Sperax
- Source: Sperax/sperax-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.