Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mehdikhosa50/peoplesstakingdapp

A Solidity-based staking system that allows users to stake ERC20 tokens and earn rewards over time. Built with Hardhat and OpenZeppelin, this project implements secure staking, withdrawal, and reward claiming functionalities, complete with comprehensive testing.
https://github.com/mehdikhosa50/peoplesstakingdapp

chai-mocha ethersjs hardhat javascript openzeppelin solidity staking-rewards unit-testing

Last synced: 3 months ago
JSON representation

A Solidity-based staking system that allows users to stake ERC20 tokens and earn rewards over time. Built with Hardhat and OpenZeppelin, this project implements secure staking, withdrawal, and reward claiming functionalities, complete with comprehensive testing.

Awesome Lists containing this project

README

        

𝐒𝐭𝐚𝐤𝐢𝐧𝐠 𝐒𝐦𝐚𝐫𝐭 𝐂𝐨𝐧𝐭𝐫𝐚𝐜𝐭 𝐏𝐫𝐨𝐣𝐞𝐜𝐭

#Overview
This project implements a staking smart contract system using Solidity and Hardhat. Users can stake ERC20 tokens and earn rewards over time. The system includes a main Staking contract, along with separate ERC20 tokens for staking and rewards.

𝐅𝐞𝐚𝐭𝐮𝐫𝐞𝐬
Stake ERC20 tokens
Earn rewards based on staking duration and amount
Withdraw staked tokens
Claim accumulated rewards
Configurable reward rate

𝐓𝐞𝐜𝐡𝐧𝐨𝐥𝐨𝐠𝐢𝐞𝐬 𝐔𝐬𝐞𝐝
Solidity ^0.8.0
Hardhat
Ethers.js
OpenZeppelin Contracts
Chai (for testing)

𝐏𝐫𝐨𝐣𝐞𝐜𝐭 𝐒𝐭𝐫𝐮𝐜𝐭𝐮𝐫𝐞
├── contracts/
│ ├── Staking.sol
│ ├── RewardToken.sol
│ └── StakedToken.sol
├── test/
│ └── Staking.js
├── scripts/
├── hardhat.config.js
└── package.json
Setup

𝐂𝐥𝐨𝐧𝐞 𝐭𝐡𝐞 𝐫𝐞𝐩𝐨𝐬𝐢𝐭𝐨𝐫𝐲:
git clone
cd

𝐈𝐧𝐬𝐭𝐚𝐥𝐥 𝐝𝐞𝐩𝐞𝐧𝐝𝐞𝐧𝐜𝐢𝐞𝐬:
npm install

𝐂𝐨𝐦𝐩𝐢𝐥𝐞 𝐭𝐡𝐞 𝐜𝐨𝐧𝐭𝐫𝐚𝐜𝐭𝐬:
npx hardhat compile

𝐑𝐮𝐧 𝐭𝐞𝐬𝐭𝐬:
npx hardhat test

𝐑𝐮𝐧𝐧𝐢𝐧𝐠 𝐓𝐞𝐬𝐭𝐬:
The project includes a comprehensive test suite. To run the tests:
npx hardhat test
This will run all tests in the test/ directory.
Deployment
𝐓𝐨 𝐝𝐞𝐩𝐥𝐨𝐲 𝐭𝐡𝐞 𝐜𝐨𝐧𝐭𝐫𝐚𝐜𝐭𝐬 𝐭𝐨 𝐚 𝐧𝐞𝐭𝐰𝐨𝐫𝐤:

Set up your network configuration in hardhat.config.js
Create a deployment script in the scripts/ directory
𝐑𝐮𝐧 𝐭𝐡𝐞 𝐝𝐞𝐩𝐥𝐨𝐲𝐦𝐞𝐧𝐭 𝐬𝐜𝐫𝐢𝐩𝐭:
npx hardhat run scripts/deploy.js --network

𝐂𝐨𝐧𝐭𝐫𝐚𝐜𝐭 𝐃𝐞𝐭𝐚𝐢𝐥𝐬
Staking.sol
The main contract that handles staking, withdrawing, and reward distribution.

𝐊𝐞𝐲 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬:
Stake(uint256 _amount): Stake tokens
Withdraw(uint256 _amount): Withdraw staked tokens
ClaimReward(): Claim accumulated rewards

RewardToken.sol and StakedToken.sol
ERC20 token contracts for the reward and staked tokens respectively.
Security Considerations

The contract uses OpenZeppelin's SafeMath library to prevent overflow/underflow issues.
Token transfers are checked for success to prevent silent failures.
The contract includes access control to prevent unauthorized actions.

𝐇𝐨𝐰𝐞𝐯𝐞𝐫, 𝐛𝐞𝐟𝐨𝐫𝐞 𝐝𝐞𝐩𝐥𝐨𝐲𝐢𝐧𝐠 𝐭𝐨 𝐚 𝐥𝐢𝐯𝐞 𝐧𝐞𝐭𝐰𝐨𝐫𝐤:

Conduct a thorough code review.
Consider getting a professional audit, especially if significant value will be managed by the contract.
Test extensively on a testnet before deploying to mainnet.

Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
𝐋𝐢𝐜𝐞𝐧𝐬𝐞
𝐓𝐡𝐢𝐬 𝐩𝐫𝐨𝐣𝐞𝐜𝐭 𝐢𝐬 𝐥𝐢𝐜𝐞𝐧𝐬𝐞𝐝 𝐮𝐧𝐝𝐞𝐫 𝐭𝐡𝐞 𝐌𝐈𝐓 𝐋𝐢𝐜𝐞𝐧𝐬𝐞.