crypto-pro
crypto-pro
Crypto-pro
1 post
Don't wanna be here? Send us removal request.
crypto-pro · 3 years ago
Text
DeFi programming
Introduction
The best way to learn something is to teach others. The second best way to learn something is to do it yourself. I decided to combine these two ways and teach myself and you how to program DeFi services on Ethereum (and any other blockchain based on EVM - Ethereum Virtual Machine).
We will focus on how these services work, trying to understand the economic mechanics that make them what they are (and all DeFi are based on economic mechanics). We will figure out, disassemble, study and create the basic DeFi mechanics.
However, we will only be working on smart contracts: creating a front-end for smart contracts is also a big and interesting task, but it is beyond the scope of this article.
Different versions of Uniswap
As of June 2021, three versions of Uniswap were launched.
The first version (V1) was launched in November 2018 and only allowed exchanges between eth and tokens. And token to to token exchanges were also possible.
The second version (V2) was launched in March 2020 and was an improvement of V1, allowing direct exchange between any ERC20 tokens as well as linked exchange between any pairs.
The third version (V3) was launched in May 2021 and significantly improved capital efficiency, allowing liquidity providers to withdraw more of their liquidity from pools and still earn the same rewards (or squeeze capital in lower price ranges and earn up to 4000x returns).
In this series we will break down each version of the protocol and try to build simplified copies of each.
This article focuses on Uniswap V1 in order to keep the chronological order and better understand what the improvements were from version to version.
Tumblr media
What is Uniswap?
Uniswap is a decentralised cryptocurrency exchange (DEX) that aims to be an alternative to centralised exchanges. It runs on the Ethereum blockchain and is fully automated: there are no administrators, managers or users with privileged access.At the bottom level is a protocol that allows pools, or pairs of tokens, to be created and populated with liquidity so that users can exchange (trade) tokens using that liquidity. Such an algorithm is called an automated market maker or automated liquidity provider.
More about market makers
Market makers (market makers, market makers) are organisations that provide liquidity (trading assets) in classical markets. Liquidity is what makes deals possible: if you want to sell something but no one buys it, there is no deal. Some trading pairs have high liquidity (like BTC-USDT) and some have low or no liquidity (like some fraudulent or questionable altcoins).But trading on all pairs is supported by trading robots, reviews of them can be found at https://scammerwatch.com/. Trading robots allow market makers to react to market events using the algorithmic capabilities of bots.
DEX must have sufficient liquidity to function and serve as an alternative to centralised exchanges. One way to get that liquidity is for developers to put their own money (or their investors' money) into DEX and become a market maker. However, this is a difficult solution to implement, as it would take a lot of money to provide sufficient liquidity for all pairs, given that DEX allows any token to be exchanged. Moreover, this would make DEX centralised: being the only market makers, developers would have a lot of power in their hands.
The best solution is to allow everyone to become a market maker, and that is what makes Uniswap an automated market maker: any user can put their funds into a trading pair (and benefit from it).
The important role of Uniswap
Another important role of Uniswap is as a price oracle. Price oracles are services that receive token prices from centralised exchanges and provide them to smart contracts - these prices are usually difficult to manipulate because the volumes on centralised exchanges are often very high. However, without such high volumes, Uniswap can still serve as a price oracle.
Uniswap acts as a secondary market, attracting arbitrageurs who profit from the difference in prices between Uniswap and the centralised exchanges. This ensures that prices in Uniswap pools are as close as possible to prices on larger exchanges. And this would not have been possible without proper pricing and reserve balancing functions.
1 note · View note