Repository navigation
feat: MEVCapture v2.1 exact model and parity (EKU-1577) - #41
Draft
moodysalem wants to merge 2 commits into
Draft
moodysalem wants to merge 2 commits into
moodysalem wants to merge 2 commits into
Conversation
Origin: EKU-946; delivery: EKU-1577 under EKU-1023. Checkpoint only: executable swap parity remains pending. Co-Authored-By: Paperclip <noreply@paperclip.ing>
Adds MevCaptureV21Pool (Pool impl + simulate_swap with per-call records and resources): first-touch gate, toward call, away segments with sqrt-ratio membership, N1, user minFee, call budget, checked int128 sums, post-swap refresh, and an emulation of the v2.1 Core step loop (bitmap word ends, skipAhead, Core tick). Replays swaps.json (32 swaps / 152 calls) plus contract-generated supplement (9/61) and nondefault-config (6/10) vectors with zero differences. Origin: EKU-946; delivery: EKU-1577 under EKU-1023. No publish or deployment. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This branch has not been deployed
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.
Board origin and outcome
da368348238a46857d39b6db57bdb2b432c979df, design rev6ad3e6585-8135-431e-82af-7a177d7f5282.What this adds
src/quoting/pools/mev_capture_v21.rsis a separate module. The v1mev_capture.rsis unchanged. Base is rust-sdk32af207, and no launchpad or auction work is included.MevCaptureV21Configis the exactgetConfigtuple and is validated against the constructor.MevCaptureV21Anchorholds all sevengetAnchorfields.MevCaptureV21PoolKeycarries the contract Q0.16 fee andtick_spacing_exp.MevCaptureV21Pool::new(key, config, state, sorted_ticks). ImplementsPool(Meta = BlockTimestamp).simulate_swap(state, MevCaptureV21SwapParams { is_token1, amount, sqrt_ratio_limit, min_fee, skip_ahead }, now). Returns:max(segmentFee, userMinFee); Core also takes the max with the pool feemaxSegmentsbudgetskipAheadand Core's stored tick. Every step rounds its fee separately, so this matters for exact amounts. Step math is the SDK'scompute_step::<Evm>withfee << 48.Evidence (zero differences, inputs only)
swaps.json(merged contract): 32 swaps / 152 Core calls. Each swap checks gate, every call (limit, minFee, remaining amount, in order), both deltas, pool sqrt ratio/tick/liquidity and all seven anchor fields.Pool::quoteis also checked against the same result.tests/data/mevcapture-v21/generator, and in the same environment the merged generator reproducedswaps.jsonbyte for byte.swapsSupplement.json(9 / 61) covers word-boundary step splits with liquidity, user minFee on away segments, and the refresh raise and its suppression.swapsNondefault.json(6 / 10) covers a nondefault config, decay clamp, capped segments and a pass-through swap.maxSegmentsbudget clause (fee reaches maxFee first, by the constructor's budget lemma) and the int128 output clamp at 2^127.cargo test --features evm,starknet,serde(193 lib + 8 v2.1 tests);cargo fmt --check; CI clippy with and withoutno_std,-D warnings;no_std,evmbuild. The existing 9 v1 tests pass.fee_q16_to_q64is lossless. Sqrt ratios are 64.128 fixed values that are exactly representable as compressedSqrtRatio, and the replay checks the round trip.Known limits
Pool::quoteuses minFee 0 and skipAhead 0. Usesimulate_swapfor other values.No publish, deployment, migration, activation, extension address or monitoring claim. CTO owns ordinary review and merge, and launch and deployment holds remain.