feat(miles): per-swap predicted gasLimit from Barter quote#146
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the session-wide Edge Config gas averages with a per-swap predicted gasLimit derived from Barter's
gasEstimationfield, mirroring the executor formula inmev-commit/tools/preconf-rpc/ fastswap/fastswap.goline-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.