Implementing the staking pool smart contract
In this section, we will implement the staking pool smart contract for staking ERC-20 tokens; the token can be an LP token (also known as farming) or something else (also known as staking). So, the smart contract code that we will explain in this section can be used for both farming and staking purposes.
To be able to follow along, we encourage you to pull the code from the chapter09-start
branch in this book’s GitHub repository at https://github.com/PacktPublishing/Building-Full-stack-DeFi-Application/.
Defining smart contract variables and implementing a constructor
We’ll start by creating a file that’s located at src/backend/contracts/StakingPool.sol
for the staking pool smart contract and implement the following code to define the global variables and the UserInfo
struct for the smart contract:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/Ownable...