Deep dive: Story of UniPeg becoming Uniswap
A decentralized exchange to trade ERC-20 token and make liquidity more accessible to the users.
Hayden Adams, founder of Uniswap, was laid off from his first job out of college. He did not know how to code before building Uniswap. He mentions he could not imagine a world where Uniswap competed with “real” projects. Today, Uniswap has a TVL (total value locked) of $5.5 Billion! With more than 300k $UNI token holders and stellar innovation and vibrant community in the Defi ecosystem.
Brooklyn based Hayden did mechanical engineering from Stony Brook University and he chose quite an unconventional path of choosing a job in mechanical engineering. In July of 2017, he got laid off from that job. Disheartened, he messaged his friend Karl who was working on Casper FFG at Ethereum foundation at that time. He encouraged him saying “Congratulations, this is the best thing that could have happened to you!!!”
Karl onboarded Hayden to Ethereum and sold him the idea to build on Ethereum. Hayden also thought to give it a shot. He spent the next two months learning required skill sets to develop on Ethereum.
Genesis of UnipegSwap
Even though Uniswap did not come up with an idea of automated market makers (AMMs). It was the first protocol to successfully utilize AMMs in order to allow automated exchange of tokens on Ethereum. Vitalik started writing about this after Martin Koppleman of Gnosis told Vitalik about the idea.
He started going to crypto conferences in different cities in the world while living off of his cryptocurrencies, explaining the idea of Uniswap to people and sharpening his own idea of the protocol. He started working out of MakerDAO’s NYC office. Just like that, he met Vitalik in Deconomy 2018, who read Uniswap code on his phone and gave him some code suggestions.
Working name for Uniswap was Unipeg, — a mixture of a Unicorn and a Pegasus. When Hayden told Vitalik about the name, he said ““Unipeg? it sounds more like a Uniswap”
Before we discuss Uniswap v1, 2 & 3. Let’s get TL;DR version of AMMs and Liquidity Pool:
Automated market maker, also known as AMM, is an algorithm that allows digital assets to be traded in a permission-less and automated way. Instead of traditional order books, we use liquidity pools in the market.
Liquidity pools are collections of funds locked digitally in a smart contract. People supply the tokens they hold in liquidity pools.
All the providers of tokens are called liquidity providers. When they deposit their tokens, they receive liquidity provider tokens, also called LP Token.
Products
Uniswap and other protocols alike usually use typically web 2.0 terminology of versions for referring to their updates in the product. Let’s understand each of the version of Uniswap one-by-one:
Uniswap v1
As a decentralized exchange, Uniswap swaps ETH for any ERC-20 token in the protocol. It is built in a way that any ERC-20 token which does not have an exchange yet can have one by Uniswap’s smart (factory) contract. Hence, creating one exchange contract for each ERC-20 token. And each token creates its own separate exchange under the hood. Which is then run using an Automated Market Maker (AMM), in place of an order book i.e. exchanges where buyers and sellers create orders according to the calculated average price in the market.
For each exchange, it holds both ETH and corresponding ERC-20 tokens in the reserve. In order to maintain liquidity in the reserve, Uniswap relies on liquidity providers or LPs. They can provide liquidity to the particular pool and in return will receive another token (“pool token”) to track the proportion of their contribution to the pool.
There is a 0.3% liquidity provider fee collected on every trade in the pool. So, instead of the interest accrued for their liquidity, liquidity providers get a proportion from the total fee in the pool. It can be collected by burning the “pool tokens” they received after successfully adding liquidity to the pool.
ETH <> ERC-20 Reserve
It uses its famous constant product formula (x*y = k) for market making in order to set the exchange rate based on the relative size of the ETH and ERC20 reserve. The formula helps to automatically set the new prices.
For example, selling the ERC-20 token decreases ETH reserve in the pool. This change will increase the price of ETH relative to the ERC-20 token. Simply, they use a typical supply and demand strategy to value the pair in the particular pool. This also incentivizes arbitrageurs to fix the price difference among assets in the pool while earning profit.
Uniswap v2
On 19th May 2020, Uniswap launched the v2 on Ethereum mainnet after a few months of trial run on the Rinkeby Test Network. The version 2 of course bought several upgrades and new features to the protocol. One of them being ERC-20 to ERC20 token swap.
In v1, if you wanted to convert your token A to B, you needed to do more than one transaction. Which included first swapping token A for ETH, then swapping that ETH for token B. This was inefficient in terms of fees and user’s time.
In v2, they removed ETH as utility token in exchanges that enable direct swap of ERC-20 token pairs. On top of that, if no pool exists for those token pairs but there exists a pool between ETH and those two tokens, users still have the option to swap those two tokens by using ETH as the intermediary token. With the update in token swapping, v2 also bought price oracles and flash swapping to Uniswap.
Price oracles allowed developers building on Uniswap to calculate an average token price based on the token’s price movement over a several blocks in a particular time period. They calculate average price by dividing final cumulative price (final price - initial price) with time duration (final timestamp - initial timestamp). Based on their functionality, these are called TWAPs or “Time Weighted Average Prices”.
Flash Swapping refers to a loan that is initiated and finished in a single transaction. Because of innate capability to guarantee pay-back, there are many ways to leverage the flash loan like arbitrage trading etc.
With v2, Uniswap also introduced a protocol fee of 0.05% which will be deducted from the standard 0.3% charge on each trade.
Uniswap v3
After almost one year of mainnet launch of v2, Uniswap launched v3 on May 5th, 2021 followed by Optimism (alphae version) launch shortly after.
V3 enabled concentrated liquidity to liquidity providers. Meaning that LPs can put their liquidity on smaller price intervals as before and they will exit their position based on the rise and fall in the asset prices set by LPs. Once it exits, the position's liquidity is no longer active or earns any fees.
Similarly, it allowed new features called Ranged Orders. Which allowed them to provide a single token and a custom price range that is above or below the current price. If afterwards, the asset value falls under the range specified by the LP, they can sell one asset for another while earning swap fees.
Continuing the benefits of liquidity providers in v1 & v2, the fee for LPs were fixed at 0.3%. While in v3, Uniswap introduced multiple fee tiers. Because single tier fee structure could be high for stablecoins while being too low for the high volatility tokens in the protocol. Still, all pools are created by the same factory contract. But allowing contracts to be created at three fee tiers: 0.05%, 0.3%, and 1%.
Governance
As several protocols, Uniswap is also governed by their own token holders. They launched their governance token, UNI, in September 2021, minting 1 billion coins. Which are supposed to be released to the public over the next four years. 60% of total genesis supply went to the community, while the remaining 40% will be allocated to Uniswap team members, investors, and advisors. At the time of this writing Uniswap has 309,086 token holders.
UNI holders have ownership of community treasury, protocol governance, protocol fee switch with several other benefits. Any addresses with more than 2.5M UNI (0.25% of total supply) can take decisions and get involved in the governance.
With different focus and goals in mind, they also diversified the “Uniswap” protocol. As per the v3 updated docs, the protocol was structured as follows:
Uniswap Labs: The company which developed the Uniswap protocol, along with the web interface.
The Uniswap Protocol: The dApps which users interact with.
The Uniswap Interface: The interface to create easy interaction with the Uniswap protocol.
Uniswap Governance: A governance system for governing the Uniswap Protocol, enabled by the UNI token.
With several initiatives alike, Uniswap has constantly been building products, services, and programs to educate people about Defi and help projects that are built using Uniswap. For example, the recent Uniswap Lab Ventures launch. Indeed, I am quite excited about the product and will be looking forward to seeing what innovation they bring next in v4!
References:
Website | Founding Story | Docs | DApp | Twitter
Disclaimer: Not at all a financial advice, dummy. DYOR!