Skip to content

feat: fastswap intent top of block#920

Merged
owen-eth merged 2 commits into
mainfrom
fastswap-top-of-block
Apr 27, 2026
Merged

feat: fastswap intent top of block#920
owen-eth merged 2 commits into
mainfrom
fastswap-top-of-block

Conversation

@owen-eth
Copy link
Copy Markdown
Contributor

@owen-eth owen-eth commented Apr 15, 2026

Describe your changes

Adds an optional topPercentile int32 field to POST /fastswap. When set
(1-100), attaches a PositionConstraint{TOP, PERCENTILE, value} to the bid,
reusing the mechanism already used by the /top/percentile/N/ URL prefix.

Behavior:

  • omitted or 0 -> no constraint, identical to today (non-breaking)
  • 1-100 -> top-of-block constraint at that percentile
  • out of range -> HTTP 400
  • logged as topPercentile on swap submission

Scope:

  • Intent path (POST /fastswap) only. Native-ETH path needs a separate
    rework (MetaMask broadcasts bypass our RPC).
  • Bid amount is not currently adjusted when the constraint is set. Matches existing
    /top/percentile/N/ behavior. Possibly worth measuring commit rate before tuning.
  • $100 min to be enforced client-side

Tests: TestHandleSwap_TopPercentile and TestHandler_TopPercentile
(valid / omitted / zero / out-of-range).

Second commit:

Pricer changes:

Extended Blocknative API call to fetch confidence level 90 (was 70/75/80/85, now 70/75/80/85/90). Added the corresponding switch case to store it.
Sender changes:

Two new constants: topOfBlockSwapConfidence = 80, topOfBlockSubsequentAttempts = 90
In calculatePriceForNextBlock: when a fastswap has a PositionConstraint set (txn.Constraint != nil && txn.Type == TxTypeFastSwap), override the confidence — p80 on first attempt, p90 on retries. This runs after the normal escalation logic, so it fully replaces the default 70/80/85 pattern with 80/90/90 for top-of-block swaps.

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 merged commit 4d83628 into main Apr 27, 2026
8 checks passed
@owen-eth owen-eth deleted the fastswap-top-of-block branch April 27, 2026 19:25
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.

2 participants