Skip to content

feat: fastswap sweep redesign#929

Open
owen-eth wants to merge 2 commits into
mainfrom
fastswap-sweep-redesign
Open

feat: fastswap sweep redesign#929
owen-eth wants to merge 2 commits into
mainfrom
fastswap-sweep-redesign

Conversation

@owen-eth
Copy link
Copy Markdown
Contributor

@owen-eth owen-eth commented May 11, 2026

Describe your changes

Full info on changes: https://www.notion.so/primev/SWEEP_IMPROVEMENTS_PLAN-V2-1-35d6865efd6f809785b9e4d2088ef085?source=copy_link

What this PR does

  • Decouples user miles from sweep timing — users see miles in minutes instead of waiting for sweep settlement
  • Sweeps run on per-token cadence, optimized for protocol P&L

Backtest result

  • ~+18% total miles vs current design, no bleed cases
  • USDC +51%, WBTC +48%, USDT +13%, DAI +21%

Two commits for staged deploy

  1. Foundation utilities — adds new files + helpers, nothing calls them yet → no-op deploy
  2. Wire it up — main.go instantiation + miles.go refactor → behavior change

Plan: deploy commit 1's image, verify pod healthy, then deploy commit 2's image, merge after stable.

New components

  • chainlink_oracle.go — Chainlink Feed Registry for ERC20→ERC20 pricing
  • cost_estimator.go — per-token p25 of realized sweep overhead (refreshed every 30min)
  • gas_buffer.go — in-memory L1 gas observations, persisted for restart
  • sweep_scheduler.godecideSweep decision logic + sweepClock with persistence
  • sweep_loop.go — per-token cadence-based sweep iterator with volume-based override
  • reconciliation.go — hourly miles-paid vs realized-profit ratio, with per-token breakdown

Security: attacker-token defense

  • Risk: malicious actor mints worthless token + controls liquidity + fastswaps to extract fake-surplus miles
  • Defense: whitelist-only upfront miles (only tokens in tokenConfigs)
  • Unknown tokens defer to sweep — attacker tokens never sweep (Barter can't quote, profitability blocks)

Pricing by swap shape (verified live on mainnet)

  • Output is ETH/WETH → surplus is already wei
  • ETH/WETH-input + whitelisted output → event-derived from trade execution rate
  • Whitelisted ERC20→ERC20 with Chainlink coverage → Feed Registry
  • WBTC/ARB/PEPE as output of ERC20-input → defer (no Registry feed, reverts handled)
  • Non-whitelisted output → defer

Chainlink Registry coverage

  • ✓ Covered: USDC, USDT, DAI, LINK, COMP, UNI, SUSHI, 1INCH, YFI
  • ✗ Not in Registry: WBTC, ARB, PEPE (defer to sweep)

Cadence config

  • Stables (USDC 24h, USDT/DAI 48h) — gas cap at p25 of recent
  • Blue chips (24h) — gas cap at p50
  • Volatile (no cadence, every cycle eligible) — gas cap at p75
  • Force-sweep at 1.5× cadence (6h for volatile)
  • Volume override: bypass cadence when accumulated rows × per-row-estimate ≥ 1.2 × sweep gas

Observability

  • erc20_cycle_summary — per-cycle counts: upfront_awarded, no_profit, deferred breakdown, orphaned
  • awarding upfront erc20 miles — per row: surplus_eth, overhead_eth, net_profit_eth, pricing source
  • sweep_executed + sweep_vs_obligation — per-sweep realized profit vs accrued miles obligation
  • reconciliation_metric — hourly aggregate ratio; warn at >1.05 or <0.75
  • reconciliation_per_token — per-token miles obligation
  • cadence_override_triggered — when high-volume override fires
  • chainlink registry lookup failed — once per unsupported token

What's preserved

  • ETH/WETH-output path unchanged
  • Non-eligible rows still get miles via legacy sweep path (no regression)
  • 4-layer idempotency defense from prior PR intact

Out of scope (follow-ups)

  • Frontend miles estimator changes
  • Direct Chainlink feed addresses for WBTC/ARB/PEPE
  • Uniswap V3 TWAP fallback for tokens without Chainlink

Issue ticket number and link

Fixes # (issue)

Checklist before requesting a review

  • I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation

@owen-eth owen-eth requested a review from harshsingh1002 May 11, 2026 16:56
@owen-eth owen-eth force-pushed the fastswap-sweep-redesign branch from ceadd07 to f6b9dc3 Compare May 11, 2026 17:15
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