The PausableStake smart contract is designed to facilitate staking of ERC20 tokens for rewards. It allows users to stake their tokens and earn rewards based on a pre-defined yield per block. The contract is capable of pausing staking operations and manages the distribution of rewards to stakers from a specified yield provider account.
- Staking: Users can stake ERC20 tokens into the contract.
- Reward Calculation: Rewards are calculated based on the amount of tokens staked and the duration of staking.
- Pausing: The contract can be paused by the owner, preventing further staking activities.
- Yield Limit: There is a pre-defined limit on the total amount of rewards that can be distributed.
- Withdrawal: Stakers can withdraw their staked tokens along with earned rewards.
Before deploying and testing the PausableStake contract, ensure the following prerequisites are met:
Node.js and npm: Install Node.js and npm (Node Package Manager) if not already installed on your system.
- Solidity v0.8.21
- OpenZeppelin Contracts v5.0.2
- Hardhat v2.21.0(for development and testing)
To set up this project locally and interact with the smart contract, follow these steps:
-
Clone the repository to your local machine:
git clone https://github.com/hrishijd/stake.git
-
Navigate to the project directory:
cd stake -
Install dependencies:
npm install
To run tests for the smart contract, use the following command:
npx hardhat testTo generate coverage report, use the following command:
npx hardhat coverageCurrently the tests have an extensive 100% coverage of the smart contracts.
Add YOUR_NETWORK with the desired network configuration to hardhat.config.js networks section, if not already present.
To deploy the smart contracts to a network, modify the deployment script as necessary (located in scripts/ directory) and then use the following command:
npx hardhat run scripts/deploy.js --network YOUR_NETWORKAfter this you will need to approve Staking contract for the token limit of ERC20 tokens by the supplier address after deployment.
*Note: This contract is designed for ethereum and its layer 2 solutions, which have a constant block time(interval after which next block is mined), not to be deployed on networks with variable block time or where block time depends on abundace of transactions, and example of blockchain with variable block time is Mantle.
The contract throws specific errors such as 'ZeroStaker', 'ZeroAmount', and 'YieldLimitExceeded' in case of invalid inputs or exceeding yield limits.
This contract is marked as experimental and may undergo changes or updates in the future. It is recommended to thoroughly test the contract in a safe environment before deployment on any mainnet.