Uniswap

Overview of the Uniswap protocol and its capabilities as a decentralized exchange.

Uniswap is a peer-to-peer DeFi protocol that serves as a decentralized exchange. Users can participate in Uniswap as traders, exchanging a pair of ERC-20 tokens, or as liquidity providers, depositing their own ERC-20 tokens to enable trading by other users.

Uniswap facilitates trading tokens via an automated market maker mechanism that is powered by a collection of smart contracts. Each pool smart contract manages a liquidity pool that consists of reserves of two ERC-20 tokens e.g. DAI/USDC. To exchange tokens, the user selects an ERC-20 token that they own and a token they would like to swap it for. The swap is executed by selling the user’s currently owned tokens for the proportional amount of the desired tokens. Every swap or trade incurs a small fee.

In addition to utilizing Uniswap to exchange tokens, users can become liquidity providers for a pair by depositing their tokens into the protocol. The deposited tokens provide liquidity for other traders.

Key Features of Uniswap

  1. Automated market maker that allows users to participate as traders or liquidity providers
  2. Flash swaps, a user can withdraw as much of any ERC-20 token as they want, with no upfront collateral, given that they return the tokens with fees at the end of the transaction
  3. Liquidity provider fees, liquidity providers are rewarded for providing liquidity and facilitating trades for a token pair

Automated Market Making and the Constant Product Formula
Uniswap v2 has a smart contract for each possible pairing of available ERC-20 tokens. Uniswap v3 has a smart contract for each possible combination of ERC-20 token pairs, fee-tier and ticks. For both versions of the protocol, the theoretical underpinning of these smart contracts is the constant product formula, which specifies that the product of both pool token reserves must be constant.

Flash Swaps
The Uniswap protocol allows users to withdraw up to the full reserves of any ERC-20 token available on the protocol given that by the end of the transaction, the user has paid for the withdrawn tokens with the associated paired token or returned the withdrawn tokens with an added fee.

Flash swaps allow users to implement arbitrage strategies and increase leverage without upfront capital or order-of-operation constraints for complex transactions that involve Uniswap.

Liquidity Provider Fees
Every token swap or trade incurs a fee. The fee accumulates within the liquidity pool and is paid out to liquidity providers when they remove liquidity.

In Uniswap v2, the fee is a fixed 0.3%. In Uniswap v3, there are three fee tiers per pool, 0.05%, 0.30% and 1.00%. With the tiered-fee model, in v3, liquidity providers can receive higher compensation for risky non-correlated token pairs and lower compensation for correlated token pairs.

Benefits of the Uniswap Lens APIs

  1. Comprehensive collection of protocol-related events. Get insights into what transactions are happening in any liquidity pool and get insights into how a specific wallet is interacting with the protocol
  • With Lens - Protocol, see the core protocol specific events.

  • With Lens - Pool, see every swap, liquidity and state change event for a given pool.

  • With Lens - Wallet, see every swap and liquidity event for a given wallet.

  1. Latest and historical data for v2 and v3 of Uniswap
  2. Normalized data makes events simple to interpret and actionable