npm install- Downloading required packages.npx hardhat init-foundry- Installing Foundry in order to perform fuzz testing.npx hardhat run scripts/deploy.js --network <NETWORK_NAME>- Deploying theStakingPool.solsmart contract.
- Unit testing through Hardhat -
npx hardhat test test/TestStakingPool.js --network <NETWORK_NAME> - Fuzz testing through Foundry -
forge test --match-path test/TestStakingPool.sol -vv
The Staking Pool is a smart contract where multiple holders of a ERC20 token can earn passive income based on the amount of tokens that they have been staking. The smart contract has no time restrictions which means that the token holders are allowed to stake, unstake or claim their current rewards at any time. This approach doesn't have hardcoded or flexiable APY, in matter of fact it doesn't have APY at all. The way that rewards are being generated are based on fees which are being collected from every stake or unstake action. Everytime someone join or leave the staking pool he is being charged with small fees which are scattered among the stakers based on their stake. The longer you keep your staking position inside the pool the higher rewards you will generate thanks to the stakers who joined after you. The pool is a custom code and it doesn't follow the ERC4626 approach where shares are actually tokens that being minted or burned to users. The pool's shares are dynamic values which are calculated in real time.
_token- This is the token contract to which the Staking Program will apply. Holders of this token will have the opportunity to take part in the staking._stakingFee- this is the fee in percentages that the user will be charged with whenever he is staking particular amount of tokens. ( Example - setting_stakingFeeto 2 will make every user to pay 2% fee for his staking. )_unstakingFee- this is the fee in percentages that the user will be charged with whenever he is unstaking particular amount of tokens. ( Example - setting_unstakingFeeto 2 will make every user to pay 2% fee for his unstaking. )
- Method
stake- this method accepts one parameter_amountwhich is the amount of tokens that themsg.senderis willing to stake. - Method
unstake- this method accepts one parameter_amountwhich is the amount of tokens that themsg.senderis willing to unstake. - Method
claimReward- this method transfers all the current existing staking rewards to themsg.senderaddress. - Method
donateToPool- This method accepts on parameter_amountand is designed if someone wants to make a donation to current the stakeholders. The_amountamount goes directly to the smart contract and is scattered among the stakers based on their stake. - Method
getPendingReward- getter method which accepts one parameter_stakerand is returning all the current existing staking rewards for_stakeraddress. - The current round & staked amount for each user can be taken by the
mapping(address => Staker) public stakerswhere the mapping key is the staker address.
- Method
setFees- with this method the owner have the permission to update the contract fees, but there is a condition which is protecting stakers that the fees can never be higher than 10 percentages. - Method
pause- this is a standard method by OpenZeppelin to active thePausable.sollogic. ( Currently only methodsstakeanddonateToPoolhave the modifier whenNotPaused which means that in the future this smart contract be retired without without restricting stakers from withdrawing their tokens. ) - Method
unpause- this is a standard method by OpenZeppelin to deactive thePausable.sollogic.
WARNING! - This contract is currently supporting only ERC20 tokens. The current version of the smart contract has not being audited by 3rd party and using it will be at your own risk.