A simple and secure ERC20 staking pool smart contract built with Solidity and tested using Foundry.
This project allows users to stake ERC20 tokens, earn rewards over time, withdraw their stake, and claim accumulated rewards. The contract is protected against reentrancy attacks and uses OpenZeppelin's audited libraries.
- Stake ERC20 tokens
- Withdraw staked tokens
- Time-based reward distribution
- Claim accumulated rewards
- Owner-funded reward pool
- Configurable reward rate
- Reentrancy protection
- Comprehensive unit tests using Foundry
- Solidity
^0.8.20 - Foundry
- OpenZeppelin Contracts
.
├── src/
│ ├── MockERC20.sol
│ └── StakingPool.sol
├── test/
│ ├── StakingPool.t.sol
│ ├── StakingPoolHandler.sol
│ └── StakingPoolInvariant.t.sol
├── lib/
├── foundry.toml
├── LICENSE
└── README.md
Clone the repository:
git clone https://github.com/ArashGandomkar/StakingPool.git
cd StakingPoolInstall dependencies:
forge installforge buildRun all tests:
forge testRun tests with verbose output:
forge test -vvvvGenerate gas report:
forge test --gas-reportUsers deposit ERC20 tokens into the staking pool.
Users can withdraw part or all of their staked tokens.
Rewards accumulate over time according to the configured reward rate.
Users can claim their earned rewards at any time, provided the reward pool contains sufficient funds.
The contract owner can:
- Fund the reward pool
- Update the reward rate
The contract uses:
- OpenZeppelin
SafeERC20 - OpenZeppelin
Ownable - OpenZeppelin
ReentrancyGuard
to improve security and reduce common vulnerabilities.
The project includes unit tests covering:
- Staking
- Withdrawals
- Reward calculation
- Reward claiming
- Reward funding
- Owner permissions
- Revert scenarios
- Event emission
This project is licensed under the MIT License.