How to Deploy a DEX in 10 minutes

Leon Do
Coinmonks

--

Deploy a Uniswap V3 Decentralized Exchange to any Rollup EVM

Overview

This guide will explain how to deploy a production ready Uniswap V3 decentralized exchange (DEX) for any rollup EVM. This includes

  • Deploy WETH
  • Deploy Uniswap V3 Contracts
  • Deploy PERMIT2
  • Deploy Universal Router
  • Adding values to the UI interface
  • Deploying the UI interface

Deploy WETH

Wrapped ETH (WETH) is used to give ETH the same functionality as an ERC-20 token. This deployment is needed for new chains.

Deploy V3

Most tutorials provide a simple smart contract DEX as a proof of concept. But this tutorial will deploy a Uniswap V3 a battle tested production ready DEX.

This deploys:

  • V3 Factory Contract: The contract is responsible for the creation of V3 pools.
  • Multicall Contract: Responsible for aggregating multiple contract constant function calls
  • NFT Contract: Is the token minted after creating an LP position.
git clone git@github.com:Uniswap/deploy-v3.git

yarn && yarn build

node dist/index.js \
--private-key $PRIVATE_KEY \
--json-rpc $RPC_URL \
--weth9-address $WETH9_ADDRESS \
--native-currency-label $NATIVE_CURRENCY_LABEL

Deploying V3 is the core of the application. The rest of the steps make the core deployment easier to interface with.

Deploy Permit2

Permit2 is an easier way to permit the sending of tokens.

The normal way is

  • User sets approval for 0xContractA to permit spending
  • User calls function for 0xContractA to spend
  • This requires 2 steps.
  • If user sets approval 0xContractB, then it’s another 2 steps

With Permit2

  • User sets approval for Permit2 address to permit spending
  • User calls function with signed message for 0xContractA to spend
  • This requires 1 step and can be use for any contract A, B, C etc…
git clone https://github.com/Uniswap/permit2.git
forge install

forge script --broadcast script/DeployPermit2.s.sol:DeployPermit2 \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--verifier-url $VERIFIER_URL \
--verifier blockscout

Deploy Universal Router

The Universal Router is an ETH, ERC20, and NFT swap router, that can aggregate trades across protocols to give users access flexible transactions. This is used in the UI interface deployed below.

git clone git@github.com:Uniswap/universal-router.git
git submodule update --init --recursive
yarn && yarn symlink

forge script --broadcast \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--sig 'run()' \
script/deployParameters/Deploy<network>.s.sol:Deploy<network>
Photo by José Martín Ramírez Carrasco on Unsplash

Add Environment Variables to UI Interface

Now that all of the contracts are deployed, it’s time to connect this to an interface.

Deploying the UI Interface

The interface has a mix of client side and server side logic. Luckily all of the swap and pool logic can be done on the client side. There is no critical backend dependency.

DEX as a Service

With the growth of modular blockchains, it’s becoming faster and cheaper to deploy a blockchain. Rollup as a service (RaaS) has made deploying blockchains as easy as deploying a smart contract.

Deploying a blockchain is an order of magnitude cheaper and faster than before. It’s only natural to provide cheaper and faster decentralized applications.

Deploying a DEX requires a lot of specialized knowledge that’ll take months for a team to understand and build. For a one click solution visit

--

--