This project demonstrates a staking and yield farming contract written in Solidity. Users can stake ERC-20 tokens and earn rewards over time, with features for withdrawing stakes and claiming rewards.
- Introduction
- Features
- Technologies Used
- Installation and Setup
- Usage
- Testing
- Deployment
- Front-End Integration
- License
The Staking and Yield Farming Contract allows users to:
- Stake ERC-20 tokens.
- Earn rewards based on how long they have staked their tokens.
- Withdraw their staked tokens at any time.
- Claim rewards once they have been earned.
This contract is intended to provide a simple mechanism for staking, with future plans for implementing yield farming and more advanced reward mechanisms.
- Staking: Users can stake an amount of ERC-20 tokens in exchange for rewards.
- Rewards: Rewards are distributed based on a predefined reward rate.
- Withdrawals: Users can withdraw their staked tokens at any time.
- Claim Rewards: Users can claim accumulated rewards from staking.
- Event Emissions: Contract emits events for staking, withdrawal, and reward claims.
- Solidity: Smart contract language for writing the staking logic.
- Hardhat: Ethereum development environment.
- OpenZeppelin: Library for using standard ERC-20 token interfaces.
- Ethers.js: JavaScript library for interacting with the Ethereum blockchain (optional for front-end).
- Node.js: For managing dependencies and running the development environment.
To get started with this project, follow these steps:
Ensure you have the following installed:
- Node.js (https://nodejs.org/)
- npm or yarn
-
Clone the repository:
git clone https://github.com/FekherJ/ChainFlight.git cd staking-contract
-
Install the project dependencies:
npm install
-
Install OpenZeppelin contracts:
npm install @openzeppelin/contracts
-
Create a new Hardhat project:
npx hardhat
-
Follow the prompts to create a basic project structure.
In your hardhat.config.js
, set up the required network details (for testnets or mainnet deployment) by adding Infura/Alchemy and your private key for deployment.
- Deploy the contract using Hardhat.
- Users can stake ERC-20 tokens by interacting with the
stake
function. - Staked tokens will accumulate rewards based on the
rewardRate
.
- Users can withdraw their staked tokens by calling the
withdraw
function. - The contract ensures that users cannot withdraw more than they have staked.
- Users can call the
getReward
function to claim their earned rewards.
- You can test the contract using Hardhat. Write tests to verify:
- Users can stake tokens.
- Rewards are calculated correctly over time.
- Users can withdraw staked tokens.
- Users can claim rewards.
Run the tests with:
npx hardhat test
You can deploy the contract to a testnet (like Goerli) or mainnet using Hardhat.
- Update your
hardhat.config.js
with the testnet or mainnet configuration (Infura/Alchemy keys, private key). - Deploy the contract using:
npx hardhat run scripts/deploy.js --network goerli
- You can integrate this smart contract with a front-end dApp using React and ethers.js.
- Create a dashboard to show:
- User staked balances.
- Earned rewards.
- Withdraw and claim buttons.
This project is licensed under the MIT License.