Skip to content

fix: align browser fee caps with suggested tips#14894

Open
Perico-perica46 wants to merge 9 commits into
foundry-rs:masterfrom
Perico-perica46:fix/browser-suggested-tip-fee-caps
Open

fix: align browser fee caps with suggested tips#14894
Perico-perica46 wants to merge 9 commits into
foundry-rs:masterfrom
Perico-perica46:fix/browser-suggested-tip-fee-caps

Conversation

@Perico-perica46
Copy link
Copy Markdown
Contributor

Motivation

Browser wallets can replace the locally estimated priority fee with the value from eth_maxPriorityFeePerGas. The script broadcast path already accounts for that by raising maxFeePerGas when the browser-suggested tip is higher than the fee-history estimate. forge create --browser and cast erc20 ... --browser still used the raw EIP-1559 estimate, which can leave the fee cap below the tip the wallet submits.

Solution

When filling browser-submitted transactions without an explicit priority fee, compare the EIP-1559 estimate with eth_maxPriorityFeePerGas. If the suggested tip is higher, raise the fee cap by the same delta and use that tip before sending the request to the browser wallet.

Copy link
Copy Markdown
Collaborator

@stevencartavia stevencartavia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Moved the eth_maxPriorityFeePerGas bump in cast erc20 behind a new browser: bool flag on fill_tx, so non browser sponsor flows don't make the extra RPC or get a silently-raised tip.
  • Added a priority <= maxFee check after fee filling in both erc20.rs and create.rs to reject invalid EIP-1559 pairs locally instead of sending them to the wallet/RPC.
  • Placed that check outside the inner if, so it also catches the case where the user explicitly supplies both --gas price and --priority-gas-price with priority > maxFee.

stevencartavia
stevencartavia previously approved these changes May 25, 2026
@Perico-perica46
Copy link
Copy Markdown
Contributor Author

@stevencartavia Thanks for the update and approval. LGTM!

Comment thread crates/forge/src/cmd/create.rs
Comment thread crates/forge/src/cmd/create.rs Outdated
@Perico-perica46
Copy link
Copy Markdown
Contributor Author

@figtracer Updated, please take another look, thanks.

Comment thread crates/cast/src/cmd/erc20.rs Outdated
} else {
if tx.max_fee_per_gas().is_none() || tx.max_priority_fee_per_gas().is_none() {
let mut estimate = provider.estimate_eip1559_fees().await?;
if browser
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast send --browser still uses the shared fee filler without this tip bump, so the same browser fee-cap issue can still happen outside cast erc20.

let's move this into the shared builder

a better long-term solution for all of these would be an actual robust provider filler for the browser wallet as mentioned by @mablr... but we can keep this as-is for now i think

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep def need to revamp all these browser cheats/workarounds. Not the scope of this PR.

@Perico-perica46
Copy link
Copy Markdown
Contributor Author

@mablr @figtracer Done, please take another look, thanks.

@figtracer
Copy link
Copy Markdown
Collaborator

can you fix conflicts pls? @Perico-perica46

Copy link
Copy Markdown
Collaborator

@mablr mablr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants