Reader small image

You're reading from  Building Full Stack DeFi Applications

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781837634118
Edition1st Edition
Concepts
Right arrow
Author (1)
Samuel Zhou
Samuel Zhou
author image
Samuel Zhou

Samuel Zhou has over 15 years of software engineering experience in top high tech companies including being a blockchain developer as his hobby since 2018. In 2022, Samuel turned his enthusiasm on blockchain technology into a business by founding TiFi, which is a silicon valley based startup that builds e-Commerce platform on blockchain and brings blockchain to everyday life. Over there he has created TiFi Token that offers token rebates so people can get cash back when spending the token. Also he has built TiFi Bank which is a DeFi application that offers crypto saving, lending, trading, staking and liquidity management features. Samuel holds a Master Degree and a Bachelor Degree in Computer Science.
Read more about Samuel Zhou

Right arrow

Implementing AMM router smart contracts

The AMM router is a smart contract for users and off-chain systems to access the DEX to perform activities including liquidity provisioning, liquidity removal, and token swapping. The AMM router accesses the functions in a pair factory and token pairs to perform these operations. In the process of implementing its code, we will also create several library functions to support the AMM router.

Let’s create the starter code for the AMMRouter smart contract by creating a new Solidity file located at src/backend/contracts/AMMRouter.sol, and implement the constructor of the smart contract like this:

address public override factory;
bytes32 private initCodeHash;
constructor(address _factory) {
    factory = _factory;
    initCodeHash = IPairFactory(factory).INIT_CODE_PAIR_HASH();
}

In the starter code of AMMRouter, we initialized the factory’s address and assigned initCodeHash within the...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Building Full Stack DeFi Applications
Published in: Mar 2024Publisher: PacktISBN-13: 9781837634118

Author (1)

author image
Samuel Zhou

Samuel Zhou has over 15 years of software engineering experience in top high tech companies including being a blockchain developer as his hobby since 2018. In 2022, Samuel turned his enthusiasm on blockchain technology into a business by founding TiFi, which is a silicon valley based startup that builds e-Commerce platform on blockchain and brings blockchain to everyday life. Over there he has created TiFi Token that offers token rebates so people can get cash back when spending the token. Also he has built TiFi Bank which is a DeFi application that offers crypto saving, lending, trading, staking and liquidity management features. Samuel holds a Master Degree and a Bachelor Degree in Computer Science.
Read more about Samuel Zhou