Skip to content

fix: Uniswap V4 Quoter ABI, MEV unit correctness, Permit2 two-leg app…#1

Merged
PrazwalR merged 1 commit into
mainfrom
fix/v0.2.0-audit
Jun 9, 2026
Merged

fix: Uniswap V4 Quoter ABI, MEV unit correctness, Permit2 two-leg app…#1
PrazwalR merged 1 commit into
mainfrom
fix/v0.2.0-audit

Conversation

@PrazwalR

@PrazwalR PrazwalR commented Jun 9, 2026

Copy link
Copy Markdown
Owner

…roval + cleanup

Copilot AI review requested due to automatic review settings June 9, 2026 22:41
@PrazwalR PrazwalR merged commit 34eba2f into main Jun 9, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"] || "";
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