/Muniversal-Router

A more universal router than Uniswap's Universal Router

Primary LanguageSolidityGNU General Public License v3.0GPL-3.0

Muniversal Router

A more universal router than Uniswap's Universal Router which additionally supports flash swap, chained V2 swaps on any DEX, enabling risk-free arbitrage.

About the universal router

Smart contracts allows EOAs to interact with the blockchain programmatically, to some extent. Unlike Cosmos, each Ethereum transaction can only contain a call to a contract. While the contract called can subsequently call as many other contracts as EVM allows, the sequence of actions is predefined when the contract is deployed. To change the logic or to program the transaction differently, usually a new contract has to be written and deployed, which is a lot of effort and overhead.

While the Multicall contract allows multiple contract calls to be executed sequentially, it has its limitations. On the one hand, using it requires the knowledge and familiarity with ABI encoding/decoding. On the other hand, it lacks certain callback functions required by popular contracts, e.g. onERC721Received, onERC1155Received, uniswapV2Call.

With the advance of Universal Router from Uniswap, one can program transactions offchain and interact with popular contracts/protocols using a more friendly interface without the need to deploy his own contract.

Contract Overview

Command encoding

Refer to the original repo.

   ┌──────┬───────────────────────────────┐
   │ 0x00 │  V3_SWAP_EXACT_IN             │
   ├──────┼───────────────────────────────┤
   │ 0x01 │  V3_SWAP_EXACT_OUT            │
   ├──────┼───────────────────────────────┤
   │ 0x02 │  PERMIT2_TRANSFER_FROM        │
   ├──────┼───────────────────────────────┤
   │ 0x03 │  PERMIT2_PERMIT_BATCH         │
   ├──────┼───────────────────────────────┤
   │ 0x1e-│  -------                      │
   │ 0x3f │                               │
   └──────┴───────────────────────────────┘

Usage

To Install Dependencies

yarn install
forge install

To Format

yarn run prettier

To Compile and Run Tests

forge build
forge test

To Update Gas Snapshots

forge snapshot