A smart contract system that enables token staking with streaming rewards powered by the Superfluid Protocol.
This project implements a staking mechanism where users can:
- Stake ERC20 tokens
- Earn rewards that are distributed continuously using Superfluid streams
- Claim accumulated rewards at any time
- Unstake their tokens with full flexibility
- Continuous Reward Distribution: Utilizes Superfluid's streaming capability to distribute rewards in real-time
- Scalable Architecture: Uses a separate claim contract for each staker to manage rewards efficiently
- Owner Controls: Allows the contract owner to:
- Supply reward tokens
- Set distribution duration
- Perform emergency withdrawals if needed
- Flexible Staking: Users can stake and unstake any amount at any time
- Scaler: A scaling factor is used to ensure that the flow rate per unit is always significantly larger than 1, minimizing the impact of integer division and ensuring that the accumulated remainder over a year is less than 0.001% of the total supply of the reward token. For more details, see SCALER.md.
- Framework: Foundry
- Language: Solidity ^0.8.0
- Dependencies:
- OpenZeppelin Contracts (v4.9.3)
- Superfluid Protocol
- Forge Standard Library
- Install Foundry:
curl -L https://foundry.paradigm.xyz | bash
foundryup
- Clone the repository:
git clone <repository-url>
cd <repository-name>
- Install dependencies:
forge install
forge build
forge test
forge script script/Deploy.s.sol:DeployScript --rpc-url <your_rpc_url> --private-key <your_private_key>
-
SuperfluidStaking.sol
- Main staking contract
- Handles stake/unstake operations
- Manages reward distribution
- Controls fund supply
-
ClaimContract.sol
- Individual contract for each staker
- Manages reward claims
- Handles reward withdrawals
The project includes comprehensive tests covering:
- Staking functionality
- Reward distribution
- Multiple staker scenarios
- Emergency procedures
- Access control
Run specific tests:
forge test --match-test testStake -vvv
- Access control implemented using OpenZeppelin's
Ownable
- Emergency withdrawal function for contract owner
- Individual claim contracts to isolate user rewards
- Comprehensive require statements for input validation
MIT
Contributions are welcome! Please feel free to submit a Pull Request.