Skip to content

Use chain gas price for L2 cost estimates and funding#5

Open
bxpana wants to merge 1 commit into
mainfrom
fix/use-chain-gas-price-for-estimates
Open

Use chain gas price for L2 cost estimates and funding#5
bxpana wants to merge 1 commit into
mainfrom
fix/use-chain-gas-price-for-estimates

Conversation

@bxpana

@bxpana bxpana commented Mar 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix inflated gas estimates: Use the chain's actual gas price (via getFeeData()) instead of the 100 gwei price embedded in pre-signed transactions when computing estimated costs. On L2s (especially zkSync-style chains), estimateGas returns gas units in the L2's model which must be priced at the L2 gas price — not the L1 gas price baked into the legacy tx.
  • Fix deploy under-funding: Enforce gasLimit × txGasPrice as a floor for deployer funding so the node always accepts the pre-signed transaction, while still allowing the chain gas price to drive the estimate when it produces a higher value.
  • Improve --gas-estimate output: Show both the tx-embedded gas price and the chain's actual gas price, and label estimated costs with the pricing source.

Test plan

  • --gas-estimate reports realistic totals (~0.004 ETH vs previous ~7 ETH on local zkSync L2)
  • --dry-run works unchanged
  • Full deploy (--confirm) successfully funds and publishes all 6 contracts on local L2
  • Re-running deploy correctly detects all contracts as already deployed
  • TypeScript compiles cleanly (tsc --noEmit)

🤖 Generated with Claude Code

Pre-signed transactions embed a gas price (e.g. 100 gwei) designed for L1,
but L2 chains (especially zkSync-style) have a different gas model where
estimateGas returns L2 gas units at much lower prices. Multiplying L2 gas
units by the L1 gas price produced wildly inflated estimates (~7 ETH instead
of ~0.004 ETH) and caused deploy funding to either over-send or under-send.

- Fetch chain's actual gas price via provider.getFeeData() for cost estimates
- In deployOnL2, enforce node minimum (gasLimit × txGasPrice) as a floor so
  deployer funding never drops below what the node requires to accept the tx
- Show both tx gas price and chain gas price in --gas-estimate summary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant