Inspired by a BowTiedPickle twitter post.
- Install Foundry.
- To run the all tests, in CL enter:
forge test
- To run a specific test (with stack and setup traces displayed):
forge test --match-test [TEST_NAME_HERE] -vvvvv
Problem specifications are as follows:
- Owner can fund with an ERC-20 reward token and define a total reward rate.
- Users can stake an ERC-20 staking token at any time.
- Users receive rewards (denominated in reward token) proportional to their staked portion of the pool.
- Users can withdraw at any time.
- Users can claim rewards at any time.
As I had to refer to existing staking contracts to make progress on this exercise, my future plans for this exercise involve:
- Summarise what I learnt from the studying the reference contracts (in particular, the Playpen
ERC20StakingPool.sol
contract). - Wait a sufficiently long time (approximately a month) before attempting this exercise again with no referencing allowed.
- A new reward period can be started when reward tokens have already been deposited to the pool:
testNewRewardPeriodRewardTokensAlreadyDeposited
- Owner cannot start a new reward period with no reward tokens in the pool:
testNewRewardPeriodRewardTokensAlreadyDeposited
- Staking works as intended:
testStake
- Cannot stake zero stake tokens:
testStakeZeroAmount
- Withdrawing works as intended:
testWithdraw
- Cannot withdraw more than your stake token balance:
testWithdrawAmountExceedingBalance
- Withdrawing rewards only works as intended:
testGetRewards
- Cannot withdraw reward tokens if they haven't been earned yet:
testGetRewardsZeroRewards
- Can exit the pool by withdrawing stake tokens and rewards earned:
testExitPoolWithStakeAndRewards
Testing improvements:
- Incorporated fuzz testing for: stake amounts, stake duration, withdrawal amounts.
When I found myself feeling stuck, I referred to the following contracts: