fix: Uniswap V4 Quoter ABI, MEV unit correctness, Permit2 two-leg app…#1
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses multiple correctness issues across the TypeScript SDK and Rust MEV engine, primarily targeting Uniswap V4 quoting/execution correctness and unit-correct MEV profitability decisions, along with type-safety cleanups and developer tooling/scripts for fork verification.
Changes:
- Fix Uniswap V4 Quoter ABI usage and speed up fee-tier quoting by running tiers concurrently.
- Implement the missing second-leg Permit2 approval flow for Uniswap V4 ERC-20 inputs (Permit2 → UniversalRouter), and update approval-strategy tests accordingly.
- Make the Rust MEV simulator’s profitability decision unit-correct by valuing trades in native-token wei; propagate “unknown” when unpriceable and update docs/tests.
Reviewed changes
Copilot reviewed 22 out of 24 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| swap-kit/pnpm-lock.yaml | Updates workspace lockfile resolution (notably CLI viem specifier line). |
| swap-kit/packages/core/src/types.ts | Adds typed slippageBps to 1inch/Paraswap route data for quote→execute propagation. |
| swap-kit/packages/core/src/test/gasless.test.ts | Fixes TS control-flow narrowing issue in callback capture for gasless tests. |
| swap-kit/packages/core/src/test/approval-strategy.test.ts | Extends Uniswap V4 tests to assert two-leg approval behavior and correct MAX types. |
| swap-kit/packages/core/src/execution/engine.ts | Adds Permit2 second-leg allowance logic for Uniswap V4 execution approvals. |
| swap-kit/packages/core/src/adapters/uniswap-v4.ts | Exports v4 address map, runs fee-tier quotes concurrently, and swaps to deployed V4 Quoter ABI. |
| swap-kit/packages/core/src/adapters/paraswap.ts | Removes unsafe as any routeData casting; threads slippage bps through execute. |
| swap-kit/packages/core/src/adapters/one-inch.ts | Removes unsafe as any routeData casting; threads slippage bps through execute. |
| swap-kit/packages/core/src/abis/index.ts | Replaces old v4 quoter shape with deployed IV4Quoter ABI; removes dead ABIs. |
| swap-kit/packages/core/scripts/oneinch-exec.ts | Adds a runnable fork execution script for 1inch ETH→USDC. |
| swap-kit/packages/core/scripts/logic-edge.ts | Adds pure-logic edge suite for slippage/normalization/minOut math. |
| swap-kit/packages/core/scripts/fork-verify.ts | Adds fork E2E verification script for v4 quote + swaps including Permit2 two-leg. |
| swap-kit/packages/core/scripts/fork-verify-permit2.ts | Adds isolated Permit2 two-leg approval verification script. |
| swap-kit/packages/core/scripts/fork-edge.ts | Adds fork-based good/bad edge matrix runner. |
| swap-kit/packages/core/package.json | Bumps core version to 0.2.0. |
| swap-kit/packages/cli/src/index.ts | Adds support for process.env["1INCH_API_KEY"] env var spelling. |
| swap-kit/packages/cli/package.json | Bumps CLI version to 0.2.0 and switches core dependency to workspace:*. |
| swap-kit/crates/swap-kit-types/src/lib.rs | Removes unused Rust quote request/response types. |
| swap-kit/crates/swap-kit-engine/src/mining/hook_miner.rs | Minor test cleanup (removes unnecessary mut). |
| swap-kit/crates/swap-kit-engine/src/mev/simulator.rs | Computes native-token notional and passes it into profitability calculation. |
| swap-kit/crates/swap-kit-engine/src/mev/liquidity.rs | Makes profitability unit-correct (native wei), adds helpers + tests, updates docs. |
| swap-kit/crates/swap-kit-engine/src/mev/bot_scanner.rs | Silences dead_code warnings for diagnostic fields. |
| README.md | Updates docs/changelog to reflect v0.2.0 fixes, unit correctness rationale, and test counts. |
| .gitignore | Adds .DS_Store. |
Files not reviewed (1)
- swap-kit/pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+261
to
+271
| const universalRouter = UNISWAP_V4_ADDRESSES[walletClient.chain!.id]?.universalRouter; | ||
| if (universalRouter) { | ||
| await this.ensurePermit2Allowance( | ||
| tokenAddress, | ||
| universalRouter, | ||
| amount, | ||
| owner, | ||
| walletClient, | ||
| publicClient | ||
| ); | ||
| } |
| userAddress, | ||
| quote.amountOut, | ||
| (routeData as any).slippageBps || 50 | ||
| routeData.slippageBps || 50 |
| } | ||
|
|
||
| const slippagePct = ((routeData as any).slippageBps || 50) / 100; | ||
| const slippagePct = (routeData.slippageBps || 50) / 100; |
| } | ||
| } | ||
|
|
||
| /// `value × (slippage_bps / 10000) × (EXTRACTION_EFFICIENCY_BPS / 10000)`, saturating. |
Comment on lines
+1
to
+15
| import { createWalletClient, createPublicClient, http, formatUnits } from "viem"; | ||
| import { privateKeyToAccount } from "viem/accounts"; | ||
| import { mainnet } from "viem/chains"; | ||
| import { OneInchFusionAdapter, ExecutionEngine, normalizeIntent } from "../src/index.js"; | ||
| import { getTokenBalance } from "../src/utils/token.js"; | ||
|
|
||
| const ANVIL = "http://127.0.0.1:8545"; | ||
| const PK = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" as const; | ||
| const ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; | ||
| const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; | ||
|
|
||
| const account = privateKeyToAccount(PK); | ||
| const walletClient = createWalletClient({ account, chain: mainnet, transport: http(ANVIL) }); | ||
| const publicClient = createPublicClient({ chain: mainnet, transport: http(ANVIL) }); | ||
| const key = process.env["1INCH_API_KEY"] || ""; |
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.
…roval + cleanup