Depositing in the Staking contract does not increase user claimable funds due to an error with claimable internal accounting.
Because 3 is made before 2, user is set as having no claimable rewards.
pragma solidity ^0.8.19;
import "../src/Staking.sol";
import "../src/Beedle.sol";
import "forge-std/Test.sol";
contract WETH9 is ERC20 {
constructor () ERC20("WETH", "WETH") {}
function name() public pure override returns (string memory) {
return "Test ERC20";
}
function symbol() public pure override returns (string memory) {
return "WETH";
}
function mint(address _to, uint256 _amount) public {
_mint(_to, _amount);
}
}
contract StakingTest is Test {
Beedle public beedle;
WETH9 public weth;
Staking public staking;
address public user1 = makeAddr("user1");
address public user2 = makeAddr("user2");
address public user3 = makeAddr("user3");
function setUp() public {
beedle = new Beedle();
weth = new WETH9();
staking = new Staking(address(beedle), address(weth));
beedle.mint(user1, 1000e18);
beedle.mint(user2, 1000e18);
beedle.mint(user3, 1000e18);
vm.startPrank(user1);
beedle.approve(address(staking), 1000e18);
staking.deposit(1000e18);
vm.stopPrank();
vm.startPrank(user2);
beedle.approve(address(staking), 1000e18);
staking.deposit(1000e18);
vm.stopPrank();
vm.startPrank(user3);
beedle.approve(address(staking), 1000e18);
staking.deposit(1000e18);
vm.stopPrank();
weth.mint(address(staking), 100e18);
}
function testDepositDoesNotIncreaseClaimable() public {
address user4 = makeAddr("user4");
beedle.mint(user4, 1000e18);
vm.startPrank(user4);
beedle.approve(address(staking), 10000e18);
console.log("staking.claimable(user4) before deposit:", staking.claimable(user4));
assertEq(staking.claimable(user4), 0);
staking.deposit(1000e18);
assertEq(staking.claimable(user4), 0);
console.log("staking.claimable(user4) after deposit: ", staking.claimable(user4));
vm.stopPrank();
}
}
Users have no incentive to deposit tokens into the staking contract as they will get nothing in return.