-
Notifications
You must be signed in to change notification settings - Fork 11
/
VampireAdapter.sol
83 lines (68 loc) · 4.23 KB
/
VampireAdapter.sol
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract Victim{}
library VampireAdapter {
// Victim info
function rewardToken(Victim victim) external view returns (IERC20) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("rewardToken()"));
require(success, "rewardToken() staticcall failed.");
return abi.decode(result, (IERC20));
}
function poolCount(Victim victim) external view returns (uint256) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("poolCount()"));
require(success, "poolCount() staticcall failed.");
return abi.decode(result, (uint256));
}
function sellableRewardAmount(Victim victim) external view returns (uint256) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("sellableRewardAmount()"));
require(success, "sellableRewardAmount() staticcall failed.");
return abi.decode(result, (uint256));
}
// Victim actions
function sellRewardForWeth(Victim victim, uint256 rewardAmount, address to) external returns(uint256) {
(bool success, bytes memory result) = address(victim).delegatecall(abi.encodeWithSignature("sellRewardForWeth(address,uint256,address)", address(victim), rewardAmount, to));
require(success, "sellRewardForWeth(uint256 rewardAmount, address to) delegatecall failed.");
return abi.decode(result, (uint256));
}
// Pool info
function lockableToken(Victim victim, uint256 poolId) external view returns (IERC20) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("lockableToken(uint256)", poolId));
require(success, "lockableToken(uint256 poolId) staticcall failed.");
return abi.decode(result, (IERC20));
}
function lockedAmount(Victim victim, uint256 poolId) external view returns (uint256) {
// note the impersonation
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("lockedAmount(address,uint256)", address(this), poolId));
require(success, "lockedAmount(uint256 poolId) staticcall failed.");
return abi.decode(result, (uint256));
}
// Pool actions
function deposit(Victim victim, uint256 poolId, uint256 amount) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("deposit(address,uint256,uint256)", address(victim), poolId, amount));
require(success, "deposit(uint256 poolId, uint256 amount) delegatecall failed.");
}
function withdraw(Victim victim, uint256 poolId, uint256 amount) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("withdraw(address,uint256,uint256)", address(victim), poolId, amount));
require(success, "withdraw(uint256 poolId, uint256 amount) delegatecall failed.");
}
function claimReward(Victim victim, uint256 poolId) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("claimReward(address,uint256)", address(victim), poolId));
require(success, "claimReward(uint256 poolId) delegatecall failed.");
}
function emergencyWithdraw(Victim victim, uint256 poolId) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("emergencyWithdraw(address,uint256)", address(victim), poolId));
require(success, "emergencyWithdraw(uint256 poolId) delegatecall failed.");
}
// Service methods
function poolAddress(Victim victim, uint256 poolId) external view returns (address) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("poolAddress(uint256)", poolId));
require(success, "poolAddress(uint256 poolId) staticcall failed.");
return abi.decode(result, (address));
}
function rewardToWethPool(Victim victim) external view returns (address) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("rewardToWethPool()"));
require(success, "rewardToWethPool() staticcall failed.");
return abi.decode(result, (address));
}
}