Building Crypto-Trading Smart Contracts
In the previous chapters, we dived into Decentralized Exchanges (DEXs) and went through the processes of how various DEXs handle crypto trading. In this chapter, we will apply this knowledge in practice by building smart contracts for trading cryptocurrencies.
The smart contracts we will build in this chapter conform to the architecture and workflows we discussed in the Architecture of AMM section of Chapter 4, Introduction to Decentralized Exchanges. These smart contracts will make up the on-chain components of a Constant Product Market Maker (CPMM), which is a type of DEX we discussed in Chapter 4, Introduction to Decentralized Exchanges. These components include token pairs, pair factories, and AMM routers. An example implementation of a CPMM is Uniswap v2. You can refer to the whitepaper of Uniswap v2 at https://docs.uniswap.org/whitepaper.pdf and its implementation at https://github.com/Uniswap/v2-core.
Because of the complexity of...