hackquest logo
 

DEX - Part 3

In Part 3 of the DEX course, we will wrap up the DEX series by learning to implement removing liquidity and swapping. After this series of lessons, we challenge you to build an even better DEX than Uniswap!

Language

Solidity

Total Length

1.7h

Part of Learning Track

Build on Ethereum + 1

What You’ll Learn

Implementing liquidity removal, calculating the quantity of tokenB exchanged based on the amount of tokenA, and facilitating the swap between tokenA and tokenB
remove liquidity
swap

Syllabus

removeLiquidity - Section 1

This section focuses on the process of burning LP tokens and subsequently calculating the corresponding reserve tokens from the liquidity pool.

removeLiquidity - Section 2

We will learn how to conduct a transfer using the IERC20 interface and the importance of updating the reserves in the liquidity pool thereafter.

calculateAmountB

Delving into the mechanics, this section will teach you how to determine the amount of tokenB that can be exchanged for a given amount of tokenA.

swapFromAToB - Section 1

How can we go from tokenA to tokenB? This section covers swapping from tokenA to tokenB, including the calculation of exchangeable tokens and the subsequent update of reserves in the liquidity pool.

swapFromAToB - Section 2

We learn how to transfer tokens.

swapFromBToA

In this final section, we will develop and understand the swapFromBToA function, which enables the swapping of tokenB for tokenA, a crucial skill for users in this field.