Skip to content

feat(miles): per-swap predicted gasLimit from Barter quote#146

Merged
owen-eth merged 3 commits into
mainfrom
gas-usage-estimate-updates
May 13, 2026
Merged

feat(miles): per-swap predicted gasLimit from Barter quote#146
owen-eth merged 3 commits into
mainfrom
gas-usage-estimate-updates

Conversation

@owen-eth
Copy link
Copy Markdown
Contributor

Replace the session-wide Edge Config gas averages with a per-swap predicted gasLimit derived from Barter's gasEstimation field, mirroring the executor formula in mev-commit/tools/preconf-rpc/ fastswap/fastswap.go line-for-line: max(400_000, floor(barter × 2.5) + 135_000_or_152_000). Drives both the bid cost (priorityFee × limit) and the user L1 gas term on the permit path (baseFee × limit × gasUsedRatio, ratio derived live from Edge Config so it tracks hourly). Falls back to the rolling averages when Barter hasn't returned a quote yet, preserving cold-load behavior.

Empirical validation across 59 recent permit-path swaps showed the gasUsed/gasLimit ratio is tight (stddev/p50 = 12.6%, regime-stable across the 2026-05-11 floor change), so a single ratio scaled to the per-swap predicted limit tracks realized consumption better than the flat averages.

Replace the session-wide Edge Config gas averages with a per-swap
predicted gasLimit derived from Barter's `gasEstimation` field,
mirroring the executor formula in `mev-commit/tools/preconf-rpc/
fastswap/fastswap.go` line-for-line: `max(400_000, floor(barter ×
2.5) + 135_000_or_152_000)`. Drives both the bid cost (priorityFee ×
limit) and the user L1 gas term on the permit path (baseFee × limit ×
gasUsedRatio, ratio derived live from Edge Config so it tracks
hourly). Falls back to the rolling averages when Barter hasn't
returned a quote yet, preserving cold-load behavior.

Empirical validation across 59 recent permit-path swaps showed the
gasUsed/gasLimit ratio is tight (stddev/p50 = 12.6%, regime-stable
across the 2026-05-11 floor change), so a single ratio scaled to the
per-swap predicted limit tracks realized consumption better than the
flat averages.
@owen-eth owen-eth requested a review from passandscore May 13, 2026 19:14
@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fastprotocolapp Ready Ready Preview, Comment May 13, 2026 8:19pm

Request Review

Replace the inline `avgGasUsed / avgGasLimit` ratio derivation with a
hardcoded p75 (0.77) of the realized `gas_used / gas_limit`
distribution. The mean-based ratio under-predicted gas cost, which
over-promised miles — users saw a higher badge number than realized
miles. Switching to p75 envelopes the upper end of the realized
distribution so predicted gasCost rarely undershoots actual, keeping
miles estimates conservative.

Empirical: 46 post-floor permit-path swaps (2026-05-11 → 2026-05-13),
gas_used/gas_limit p75 = 0.768 (stddev/p50 ≈ 13%, tight). Rounded to
0.77 for the constant.
API has been observed returning ~$1 for ETH during transient backend
issues, which cascaded into 13x surplus inflation in the miles calculator
(one user saw 30,927 miles vs. actual ~17). Add per-symbol plausibility
bounds at the fetch boundary: ETH/WETH in [100, 100k], stables in
[0.5, 2]. Skip setPrice and warn on out-of-range data so the last good
value stays in state, rather than poisoning every downstream consumer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@owen-eth owen-eth merged commit d905fea into main May 13, 2026
3 checks passed
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