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.
It also allows you to contribute to liquidity pools for any ERC20 token, and therefore gain commissions in the form of exchange fees for doing so.
Uniswap sounds like a big deal; being able to exchange any ERC20 token, including the native ETH token, without middle men, and allowing anyone with an Ethereum address to contribute to the exchange’s liquidity, and thus earn from it, is no small feat.
This article will break down exactly what the exchange can do and how you can benefit from it, as well as the underlying formulas for calculating exchange rates for each token.
A live running front-end deployment of the exchange can be found at https://uniswap.exchange. At this time the MetaMask plugin is needed for the exchange to operate as a means to interact with your Ethereum addresses.
Let’s run through some high level features of Uniswap, before exploring the smart contracts and the underlying workings of the exchange.
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:
Start Today your Uniswap Project!
© 2020 - All Rights Reserved - CafeScripts Web Solutions