Uniswap X
Uniswap X is the latest iteration of the Uniswap protocol, introducing a new trading architecture focused on gas efficiency, MEV protection, and improved user experience through a unified router system.
Overview
Uniswap X introduces several key innovations:
- Universal Router: A unified contract for executing trades across multiple protocols
- Permit2: A token approval system that reduces gas costs and improves security
- Dutch Auction Orders: Enables limit orders and other advanced trading features
- MEV Protection: Built-in mechanisms to protect users from maximal extractable value
- Gas Optimization: Significantly reduced gas costs compared to previous versions
Integration with Bloctopus
When using Bloctopus with a forked Ethereum network, you can interact with Uniswap X contracts that are already deployed on mainnet. This allows you to test your DeFi applications against the latest Uniswap infrastructure.
This sample guide is for forked Ethereum networks but you can adapt the respective contract addresses when using other forked networks (e.g. Optimism, Arbitrum)
Key Contracts
The main Uniswap X contracts you'll interact with:
- Universal Router:
0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD
- Permit2:
0x000000000022D473030F116dDEE9F6B43aC78BA3
Sample Implementation
The DeFi Samples repository contains ready-to-use scripts for interacting with Uniswap X:
- Info: info.js - Get information about Uniswap X contracts and their deployment status
- Quote: quote.js - Get price quotes for token swaps using Uniswap X
- Swap: swap.js - Execute token swaps using the Universal Router
Running the Scripts
To run these scripts with Bloctopus:
Clone the DeFi Samples repository:
git clone https://github.com/LZeroAnalytics/defi-samples.git
cd defi-samplesInstall dependencies:
npm install
Create a
.env
file with your Bloctopus RPC endpoint and private key:RPC_URL=https://your-bloctopus-rpc-endpoint
PRIVATE_KEY=your-private-keyRun a script:
npx hardhat run scripts/protocols/uniswap-x/info.js
npx hardhat run scripts/protocols/uniswap-x/quote.js
npx hardhat run scripts/protocols/uniswap-x/swap.js
Testing with Bloctopus
To test Uniswap X interactions using Bloctopus:
- Create a forked Ethereum network in Bloctopus
- Configure your Hardhat project to use the Bloctopus RPC endpoint
- Run your scripts or tests against the forked network