← Back to all products
$13
Batch Optimizer
Optimize batch composition for minimal L1 cost — transaction ordering, compression, and timing.
TOMLPythonTypeScriptMarkdownJSON
📁 File Structure 17 files
batch-optimizer/
├── README.md
├── pyproject.toml
├── security-notes.md
├── src/
│ ├── python/
│ │ ├── __init__.py
│ │ ├── analyzers/
│ │ │ ├── __init__.py
│ │ │ └── batch_analyzer.py
│ │ ├── cli.py
│ │ ├── optimizers/
│ │ │ ├── __init__.py
│ │ │ ├── batch_optimizer.py
│ │ │ └── compression.py
│ │ └── utils/
│ │ ├── __init__.py
│ │ └── gas.py
│ └── typescript/
│ ├── config/
│ │ └── default.json
│ ├── package.json
│ ├── src/
│ │ └── index.ts
│ └── tsconfig.json
└── tests/
└── test_optimizer.py
📖 Documentation Preview README excerpt
Batch Optimizer
Minimize L1 data posting costs with intelligent batch sizing, compression analysis, and blob strategy routing.
Price: $12.99 | License: MIT | Category: Tooling | Python: >=3.10
Overview
batch-optimizer is a dual-language toolkit (Python + TypeScript) that analyzes and optimizes rollup batch posting to L1. It evaluates batch sizes, compression ratios, blob vs calldata cost routing, and gas price timing to minimize data availability costs.
Whether you're operating an OP Stack chain or building a custom rollup, this tool helps you find the optimal posting strategy that balances latency against L1 gas spend.
Features
- Optimal batch size calculation — Find the sweet spot between posting frequency and per-byte cost amortization
- Compression efficiency analysis — Measure zlib/zstd/brotli compression ratios on your actual transaction data
- Blob vs calldata cost routing — Automatically select EIP-4844 blob transactions or calldata based on current gas prices
- Timing strategy optimization — Identify low-gas windows for batch submission using historical gas price data
- Gas price prediction integration — Plug in gas oracle feeds to predict optimal submission timing
- Monte Carlo cost simulation — Run probabilistic cost scenarios for capacity planning
Tech Stack
| Component | Technology |
|---|---|
| Core Engine | Python 3.10+, pandas, numpy |
| Chain Interaction | web3.py, ethers.js |
| TypeScript SDK | TypeScript, ethers.js |
| Compression | zlib, zstandard, brotli |
| Visualization | matplotlib, rich |
Quick Start
Prerequisites
- Python 3.10+
- Node.js 18+ (for TypeScript components)
- An L1 RPC endpoint
Install
# Python package
pip install -e .
# TypeScript SDK (optional)
cd src/ts && npm install
Usage
# Analyze current batch economics
batch-opt analyze --rpc $L1_RPC --rollup-rpc $L2_RPC --blocks 500
# Find optimal batch size for your chain
batch-opt optimize --strategy balanced --gas-price 25
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/python/cli.py
# ═══════════════════════════════════════════════════════════════════════════
# BATCH OPTIMIZER CLI
# Command-line interface for batch analysis and optimization
# ═══════════════════════════════════════════════════════════════════════════
"""
CLI for the Batch Optimizer toolkit.
Commands:
analyze Analyze a batch of pending transactions
optimize Run optimization with a given strategy
benchmark Benchmark compression ratios on sample data
"""
from __future__ import annotations
import os
import zlib
import click
from python.analyzers.batch_analyzer import BatchAnalyzer, Transaction, TxType
from python.optimizers.batch_optimizer import BatchOptimizer, OptimizationConfig, Strategy
from python.optimizers.compression import CompressionOptimizer
@click.group()
@click.version_option(version="1.0.0", prog_name="batch-opt")
def main() -> None:
"""Batch Optimizer — Minimize L2 rollup batch posting costs."""
@main.command()
@click.option("--gas-price", type=float, default=30.0, help="L1 gas price in gwei.")
@click.option("--blob-fee", type=int, default=1_000_000_000, help="Blob base fee in wei.")
@click.option("--sample-size", type=int, default=100, help="Number of sample transactions.")
def analyze(gas_price: float, blob_fee: int, sample_size: int) -> None:
"""Analyze a batch of sample transactions.
Generates sample L2 transactions and analyzes batch posting costs,
comparing calldata vs blob posting.
"""
click.echo(f"Generating {sample_size} sample transactions...")
# Generate sample transactions
txs = _generate_sample_txs(sample_size)
analyzer = BatchAnalyzer(
l1_gas_price_gwei=gas_price,
blob_base_fee_wei=blob_fee,
)
# ... 144 more lines ...