You may have heard of an Ethereum based exchange named Uniswap. Uniswap is a decentralised exchange in the form of two smart contracts hosted on the Ethereum blockchain, as well as a public, open source front-end client. It’s a 100% on-chain market maker allowing the swapping of ERC20 tokens, as well as ETH to an ERC20, and vice-versa.
Let’s run through some high level features of Uniswap, before exploring the smart contracts and the underlying workings of the exchange.
You may have heard of an Ethereum based exchange named Uniswap. Uniswap is a decentralised exchange in the form of two smart contracts hosted on the Ethereum blockchain, as well as a public, open source front-end client. It’s a 100% on-chain market maker allowing the swapping of ERC20 tokens, as well as ETH to an ERC20, and vice-versa.
Let’s run through some high level features of Uniswap, before exploring the smart contracts and the underlying workings of the exchange.
Token swaps in Uniswap are a simple way to trade one ERC-20 token for another.
Guaranteed Liquidity for millions of users and hundreds of Ethereum applications.
You can see your charts and find what token is getting better on the market.
- OpenX.app
Uniswap at a High Level
Let’s dive straight in to what Uniswap offers, starting with its Exchange infrastructure.
The Exchange contract can support any ERC20 token. But how do we set up an exchange for a particular ERC20? With one method call from the Factory.
By calling the createExchange method from the Factory contract, an Exchange contract is then deployed for a particular ERC20 token you specify. Every ERC20 token therefore, by design, utilises its own Exchange smart contract.
Uniswap is 100% on-chain. The “Factory” smart contract contains an exchange registry, and a method to deploy an “Exchange” contract for a particular ERC20 token. An exchange can be created for any valid ERC20 token.
But in order for the exchange to work and for swaps to take place, there needs to be tokens readily available — where do they come from? They are supplied by liquidity providers, and anyone can be one, by depositing tokens into an Exchanges’ liquidity pool.
Liquidity pools are Uniswaps’ decentralised liquidity solution, allowing anyone to take part in them and to be rewarded for supplying this liquidity.
Adding liquidity to a Uniswap token pool alsorequires an equivalent value of ETH to be deposited: Concretely, 50% value ETH and 50% value ERC20.
Every Uniswap Exchange mints its own Liquidity tokens (another ERC20 token) when liquidity is added to keep track of the share ratios of the liquidity pool. These tokens are burned upon withdrawing funds from a pool. You are also free to exchange your liquidity tokens to transfer share ownership, without disturbing the actual pool funds.
The x * y = k formula is important to understand as it determines the price for all exchange tokens. Vitalik Buterin posted on Ether Research in early 2018 describing the equation and how it could be utilised with a decentralised exchange. The post has received a lot of attention and feedback, and ultimately has been adopted to make Uniswap function as a market maker.Within that aforementioned post, the following graph was posted describing the x * y = k formula:
©2021 - 2022 OpenX . All rights reserved. +Swap
2815 Elliott Ave Suite 100, Seattle, WA, 98121