Liquidity on Uniswap
The design architecture of the Uniswap protocol is different from the model in traditional digital asset exchanges. Most traditional exchanges maintain an order book and use it to match buyers and sellers of a particular asset. And Uniswap uses **liquidity reserves** to realize the transaction of digital assets in the agreement.
Liquidity reserves for trading contracts are provided by liquidity providers in the network. These liquidity providers deposit equivalent ETH and ERC20 tokens into specific ERC20 token trading contracts. The first liquidity provider to provide liquidity to an exchange contract will first set the exchange rate between ETH and the corresponding ERC20 token in that exchange contract. Liquidity providers set this exchange rate by depositing what they believe is the equivalent of ETH and the ERC20 token backed by the contract. If the exchange rate set by the liquidity provider is inconsistent with the broader cryptocurrency exchange market, then arbitrage traders will lead the exchange rate between ETH and ERC20 tokens to what the market believes is the correct exchange rate. Therefore, all subsequent liquidity providers will use the exchange rate when they deposit assets to deposit liquidity.
Uniswap also uses so-called **"liquidity tokens" (liquidity tokens), which are themselves ERC20 compliant. These tokens can be seen as a representation of the liquidity provider's contribution to the trading contract. The rationale behind Uniswap’s limitation of supporting only one ERC20 token per trading contract is to encourage liquidity providers to pool their liquidity assets into a single reserve**. Uniswap tracks the relative proportion of each liquidity provider contributing to the total reserve by minting liquidity tokens. Liquidity providers are able to burn their liquidity tokens at a time of their choice so that they can withdraw a proportional share of their ETH and ERC20 tokens from the exchange contract.
Liquidity providers can choose to sell or transfer their liquidity tokens without removing liquidity from the exchange contract. However, Uniswap's liquidity tokens are strictly assigned to an exchange contract. There is no single native digital asset associated with the Uniswap protocol. Liquidity providers can also deposit liquidity into trading contracts by calling the addLiquidity() function. As a reward for providing liquidity, liquidity providers will receive a certain percentage of transaction fees when the transaction is execute
Trade on Uniswap: ETH ⇄ ERC20 trade One type of transaction that can be performed in the Uniswap protocol is the exchange of ETH for any specific ERC20 token.As mentioned above,the exchange rate between ETH and a certain ERC20 token is based on the relative size of each asset liquidity pool in the trading contract. The exchange rate is based on the invariant of Uniswap: ETH pool token pool = invariant (invariant). During the execution of any transaction on the Uniswap protocol, an invariant (invariant) remains unchanged. Furthermore, the invariants only change when the liquidity in the traded contracts increases or decreases.
Example ETH ⇄ BAT: Bob wants to initiate a transaction to exchange 1 ETH for ERC20 token BAT. Bob will use an existing exchange contract on the Uniswap protocol to execute this transaction. The liquidity provider has deposited a certain amount of ETH and BAT into the exchange contract, for this example, let's say 10 ETH and 500 BAT. The underlying invariant is set as: ETH pool *BAT pool = invariant (invariant), that is:
ETH pool = 10 BAT
pool = 500
Invariants = 10 * 500 = 5,000
Bob initiates his transaction by sending 1 ETH to the ETH pool of the transaction contract, and deducts 0.3% as a fee for liquidity providers on this basis. The remaining 0.997 ETH was added to the ETH pool. Then, divide the invariant by the new total ETH to determine the latest size of the BAT pool. The remaining BAT tokens are then sent to the buyer, in this case Bob. That is:
ETH pool = 10 BAT
pool = 500
Invariants = 10 * 500 = 5,000 Bob
initiates his transaction by sending 1 ETH to the ETH pool of the transaction contract, and deducts 0.3% as a fee for liquidity providers on this basis. The remaining 0.997 ETH was added to the ETH pool. Then, divide the invariant by the new total ETH to determine the latest size of the BAT pool. The remaining BAT tokens are then sent to the buyer, in this case Bob. That is:
Bob sends: 1 ETH
Handling fee: 0.003 ETH
ETH pool = 10 + (1 – 0.003) = 10.997
BAT pool = 5000/10.997 = 454.67
Bob receives: 500 – 454.67 = 45.33 BAT
The handling fee paid to the liquidity provider was deducted when Bob initiated the transaction, and now this handling fee is added to the liquidity pool (which means that the invariant will increase). This acts as a payment to liquidity providers, which they can collect when they remove their liquidity contributions from the market. Because this fee is re-added after the price calculation, as each transaction on the exchange contract is executed, the invariant gradually increases,making the act of depositing liquidity into an exchange contract important for liquidity It is a profitable activity for sex providers. at this time:
ETH pool = 10.997 + 0.003 = 11
BAT pool = 454.67 new
invariant = 5,001.37
In this transaction, Bob obtains BAT at an exchange rate of 45.33 BAT/ETH.
Input: 1 ETH
Output: 45.33 BAT
Exchange rate = 45.33 BAT/ETH
Trading on Uniswap: ERC20 ⇄ ERC20 Trading
Another type of transaction that can be performed in the Uniswap protocol is exchanging one ERC20 token for another ERC20 token. Since ETH is used as a public trading pair for all ERC20 tokens, Uniswap uses ETH as an intermediary asset for direct transactions between ERC20 and ERC20. For example, Uniswap can convert BAT tokens to ETH in a certain transaction contract, and then convert this part of ETH to OMG in another transaction contract, all of which are completed in one transaction, so that any two Exchange between ERC20 tokens is possible.
This formula works very much like a normal market in that the more tokens you buy, the higher the marginal exchange rate you have to pay to buy one more unit of tokens.


