Summary
In this chapter, we explored how to support native tokens in a DEX, refactoring the smart contracts and UI code to support the native token for liquidity management and token-swapping features. We learned how to use the WETH smart contract to wrap ETH get WETH, which is the ERC20 form of ETH, and use the same smart contract to convert WETH back to ETH. We explored the new functions (addLiquidityETH
and removeLiquidityETH
) in the AMMRouter
smart contract that are added to support liquidity provisioning with ETH, and we looked at liquidity removal to get ETH by leveraging WETH liquidity pools. We also added the four swapExactETHForTokens
, swapETHForExactTokens
, swapTokensForExactETH
, and swapExactTokensForETH
functions in the AMMRouter
smart contract to perform swapping with ETH.
The approaches we have learned in the chapter should inspire you to implement native token support for other types of DeFi applications. When we build other DeFi applications in this book, such as...