Skip to content

lumoswiz/BowTiedERC20Staking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ERC20 Token Staking

Inspired by a BowTiedPickle twitter post.

Setup

  • 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

Exercise Description

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.

Next steps

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.

Testing Coverage

  • 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.

Acknowledgements

When I found myself feeling stuck, I referred to the following contracts:

  • ERC20StakingPool.sol from ZeframLou's Playpen (here).
  • Staking Rewards from Solidity By Example (here).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published