Ultimate magazine theme for WordPress.

Deep end of the liquidity pool in the DEX space? | by Mabel Oza | coin monks

Liquidity pools allow individuals to become market makers on decentralized exchanges. Let’s dive deep into how it works.

Here we dive deep into how decentralized exchanges with liquidity pools work and create a liquidity pool on Uniswap. If you are unfamiliar with the basics of liquidity pools, read Part 1, “Dive into Liquidity Pools”.

How do centralized exchanges get liquidity?

How do decentralized exchanges get liquidity?

Where can you create a liquidity pool?

How to create a liquidity pool in Uniswap with your ERC20 tokens?

  1. Connect to Uniswap and go to the “Pool” section.
  2. Import the selected ERC20 tokens into the pool
  3. Set Fees
  4. Setting the price
  5. Setting the price range
  6. deposit of amounts
  7. Checking the execution of smart contracts
  8. Management of the liquidity pool

Create and programmatically manage liquidity pools

Many of us grappled with the complexities of exchange from a young age, starting in the canteen. A peer-to-peer exchange is like finding a friend willing to trade your lunch with theirs. This usually happens when you bring in a commonly requested lunch (for most North American school children) such as pudding or an apple. In this scenario you are liquid.

New to trade? Try crypto trading bots or copy trades on the best crypto exchanges

But what if your mom or dad packed you something more ethnic, like a spicy samosa? As delicious as samosas are, it’s going to be a lot harder to find a friend in a North American school who’s willing to trade with you. In this scenario, you run the risk of being illiquid.

Exchanges usually require both parties to agree on a buy/sell price, and usually these parties have to agree fairly quickly. But what if both parties don’t agree on a buy/sell price, or if someone wants to trade their asset for another asset that isn’t available? Now our exchange is illiquid or at risk of liquidity and people may not be able to dump their assets.

Exchanges limit their exposure to liquidity risk by turning to their rich friends (market makers) who have enough commodities (liquidity) to make the deal happen.

PFOF (Payment for Order Flow) is a rebate that market makers send to brokerage firms to encourage brokers to pass orders to them. The reason they want to fill the orders is that the market makers make their income from the spread of the bid and ask price.

fun fact: PFOF was developed by the one and only…Bernie Madoff. He was known for his work around PFOF before becoming known for his Ponzi scheme.

In the case of a decentralized exchange, the order is fulfilled by a liquid provider, a group of people pooling their funds to provide liquidity for a pair of assets. These liquidity providers enter into a smart contract when they create their liquidity pool. They agree to deliver their assets to the DEX for a trading fee.

When demand for the tokens increases, the DEX uses an algorithm that adjusts the price. This concept is called Automated Market Market (AMM) because an algorithm does the market making and determines the price. The AMM algorithm used is mostly referred to as constant product, but this is not the case for all liquidity pool protocols.

Some of the most popular liquidity pool platforms in the DEX space are Uniswap, Sushiswap, Curve and Balancerthese platforms are consistently in the top 10 for their TVL (Total Value Locked), volume traded and support for a wide range of crypto assets. Today we will dive into Uniswap.

Below are the rankings of Messari’s top 10 platforms.

Top 10 TVL (Total Locked)

https://messari.io/protocol/uniswap-v3 (1.10.22)

Top 10 traded volume

https://messari.io/protocol/uniswap-v3 (1.10.22)

Below is a video to see the whole process of creating a liquidity pool on Uniswap. In this blog, we go through each step in detail.

requirements

Before we begin, you should have a solid understanding of the following points:

  • Set up your wallet with testnet tokens
  • ERC20 tokens and adding them to your wallet

You need a plugin wallet with 2 Ethereum compatible tokens on a testnet network (preferably Goerli). One of them can be Ethereum, or both can be ERC20 tokens.

1. Connect to Uniswap and go to the pool area

Go to https://uniswap.org/ and connect your web3 wallet (e.g. Exodus, Metamask, etc.) to the app. Then navigate to the pool section of the app to create your liquidity pool.

2. Import your ERC20 tokens into the pool

Get the token contract address

Select a token in your wallet. In this case I chose the token APL. If you click on the 3 dots above, select the “Token Details” option.

In the Token Details section, you will be given a “Token Contract Address”. This is the address of the contract address of the token APL, which serves as the identifier of the token. Copy this address, we will use it to import your token into Uniswap.

Import tokens into Uniswap

Back in Uniswap please select one of the tokens; It should take you to a search bar.

If you enter the token contract address, you will see the ERC20 token and its metadata. You can either import a pair of ERC20 tokens or just one ERC20 token and pair it with Ethereum. In this case we are pairing apples (APL) with grapes (GRP).

3. Set Fees

After the tokens have been added and paired with each other, the next step is to set a fee for the liquidity pool.

This is the fee that the liquidity provider (in this case you) receives every time a trade is made against your pool.

  • 0.05% is often used for token pairs that are closely correlated in prices like USDC and DAI, which are closely tied to $1.
  • 0.3% is typically used for most pairs and was the default in previous versions.
  • 1% is used for low liquidity assets like meme coins.

We choose the 0.3% fee to earn 0.3% of fees on each trade of apples or grapes from our liquidity pool.

4. Setting the price

Here the price of an apple is 4 grapes, so in the Set Starting Price section we set the current price of an APL (apple) to 4 GRPs (grapes).

5. Setting the price range

We need to set the price range; The determination of the range is based on how market demand affects your asset price over time. The price range must not be too narrow and not too wide.

What if the price range is too narrow?

You will not receive a trading fee if your asset is outside the range. So if the price range is too narrow, the chances of earning fees decrease.

If you have a stablecoin and you can guarantee that the price will always be within a dollar, with a 5% margin above and below a dollar, then you can have a tight range.

What if the price range is too big?

If your price range is too wide, you introduce market inefficiencies and high slippage (the difference between expected and actual prices) to traders. A large bandwidth can increase your chance of being charged, but the fees you earn will be less than if you had a narrow bandwidth. This is because the trading fees charged in a given price range are shared pro-rata by LPs (Liquidity Providers) in proportion to the amount of liquidity they have contributed to that range.

Uniswap v3 has addressed the risk of going out of bounds at narrow price ranges and market inefficiencies at wide price ranges through implementation concentrated liquidity. You can create multiple areas that are narrow enough; Check out the concept of concentrated liquidity,

We didn’t put too much analysis into determining the price range here and randomly selected a price range between ~2 and ~20.

6. Deposit the amounts

As a final step, we will approve both the Apple and Grape tokens and deposit the tokens into the Liquidity smart contract.

When we confirm the transaction with our wallet, we add tokens to the liquidity smart contract.

7. Verification of Contract Execution

After the contract is deployed, you can check the transaction details on Etherscan (a popular Ethereum blockchain explorer) using the transaction ID provided by Uniswap (or Link).

The “View on Etherscan” link takes you directly to your transaction.

If you can find your transaction details on Etherscan and the status says ‘Success’ then you know the transaction took place and is tied to the Ethereum network. Below you can see that 2 APL (apple token) and 4.22 GRP (grape token) have been transferred into a smart contract.

How do I know that the address my tokens were transferred to is not just someone’s wallet but an actual contract?

In the “Interacted With (To):” field you will see the term “Contract” and an address of the contract, in this case the address is 0xc36442b4a4522e871399cd717abdd847ab11fe88 in this image. If you browse this contract on Etherscan Goerli (or any blockchain explorer for the Goerli chain), you can go to the “Contract” tab and see the contract code that was deployed on the chain. This is an assurance that your funds are locked into the smart contract and will only behave as the contract intends.

8. Liquidity Pool Management

Once your liquidity pool is created, you can manage it on Uniswap. They can either remove or increase liquidity and charge fees from trades. You can also monitor where your price is currently within the set price range.

If you are a financial services company that needs to create liquidity pools for multiple clients at the same time with different criteria, using the interface may not be the most efficient. So you would approach it programmatically by either:

  1. Create a project by copying Uniswap’s smart contracts and deploying them with your own app

This approach will be difficult to maintain and is only advisable if the plan is to deviate from the Uniswap protocol.

2. Use Uniswap’s SDK

The easiest approach to get started. The limitation is that the SDK is only available in Typescript and you would have to rewrite your entire code base if you wanted to switch protocols.

3. Inherit smart contract from Uniswap (recommended)

This is the most recommended approach because you are calling the continuously checked Uniswap protocol, but you are also doing it from within your smart contract and not your entire stack.

Learn Crypto Trading, Yield Farms, Income strategies and more at CrytoAnswers
https://nov.link/cryptoanswers

Comments are closed.

%d bloggers like this: