Skip to content

Latest commit

 

History

History
150 lines (98 loc) · 4.02 KB

File metadata and controls

150 lines (98 loc) · 4.02 KB

DSR Wrapped Flash

Flash-based triangular arbitrage contract built on top of Uniswap V3 flash swap mechanics.

DSR stands for Direct Swap Router — an execution model where all swaps are performed directly against liquidity pools, without using external router contracts.

The contract allows executing multi-hop arbitrage routes using a combination of Uniswap V2 and Uniswap V3 pools within a single atomic transaction.


Direct Swap Router (DSR)

Unlike traditional DEX routers (Uniswap Router, Pancake Router, etc.), DSR interacts directly with liquidity pools and does not rely on any external routing logic.

Core Principles

  • No external router contracts
  • Direct interaction with V2 and V3 pools
  • Native pool swap mechanics only
  • Full control over execution and callbacks

All swaps are executed by calling:

  • pair.swap() for Uniswap V2–style pools
  • pool.swap() for Uniswap V3–style pools

The contract effectively acts as its own router.

Why Direct Routing

Using original router contracts introduces:

  • additional external calls
  • unnecessary abstraction layers
  • higher gas usage
  • limited execution control
  • reduced flexibility for MEV execution

Direct Swap Routing removes these limitations and enables:

  • deterministic execution flow
  • minimal call depth
  • precise callback handling
  • flash swap compatibility
  • MEV-optimized transaction structure

Key Features

  • Uniswap V3 flash swap as liquidity source
  • Triangle arbitrage (tokenIn → tokenMid → tokenOut)
  • Supports Uniswap V2 and V3 compatible pools
  • Direct pool interaction (no routers)
  • Automatic profit extraction
  • Optional MEV builder bribe support
  • ETH-based final settlement

Flash Triangle Architecture

Core Concept

  1. A flash loan is taken from a Uniswap V3 pool
  2. Two swaps are executed sequentially:
    • tokenIn → tokenMid
    • tokenMid → tokenOut
  3. Flash loan is repaid in tokenOut
  4. Remaining balance represents net arbitrage profit
  5. Profit is converted to ETH and distributed

Swap Routing

The arbitrage path is defined externally and passed to the contract as a structured route.

Each swap supports:

  • Uniswap V2-style pools
  • Uniswap V3-style pools
  • Any compatible forks

Routing is fully dynamic and does not rely on hardcoded DEX addresses.


Callback Handling

The contract handles two different Uniswap V3 callbacks:

  • Flash swap callback — executes arbitrage logic
  • Regular swap callback — pays exact input for V3 swaps

Routing is implemented via an internal execution flag.


MEV Builder Integration

Optional builder incentives are supported:

  • Bribe paid in ETH
  • Configurable percentage (basis points)
  • Applied only if profit exceeds minimum threshold
  • Compatible with private bundles and block builders

Safety Constraints

  • Flash loan must be fully repaid
  • Minimum profit enforced
  • Output token balance must increase
  • Unauthorized callbacks are rejected
  • All operations are atomic

Disclaimer

This project reflects practical research and experimentation within modern DeFi execution environments.

In current market conditions, characterized by a high concentration of MEV searchers, arbitrage bots, and professional infrastructure participants, the primary challenge is no longer the implementation of swap logic or custom routing mechanisms.

The real complexity lies in:

  • real-time on-chain opportunity discovery
  • latency-sensitive arbitrage execution
  • participation in MEV auctions
  • access to block builders and private order flow

Without direct access to builder auctions and privileged execution channels, sustainable profitability becomes extremely difficult to achieve.

As a result, further development of this project was discontinued.

Nevertheless, the work provided valuable hands-on experience and a deep technical understanding of Uniswap V2 and V3 swap mechanics, flash execution flows, and low-level pool interaction.

No financial profit was achieved during this research.

This repository is published for educational and architectural reference purposes only.