-
Notifications
You must be signed in to change notification settings - Fork 8
/
HoneyPotChecker.sol
216 lines (174 loc) · 4.76 KB
/
HoneyPotChecker.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.7;
//By : 0xdaebak
//https://github.com/0xdaebak
contract HoneyPotChecker{
struct HoneyPot{
bool isHoneyPot;
address base;
address token;
uint256 estimatedBuy;
uint256 buyAmount;
uint256 estimatedSell;
uint256 sellAmount;
uint256 buyGas;
uint256 sellGas;
}
function isHoneyPot(address router, address base, address token) external payable returns(HoneyPot memory){
HoneyPot memory response;
bool success;
uint256 amount;
uint256 estimatedBuyAmount;
uint256 buyAmount;
uint256 sellAmount;
uint256 estimatedSellAmount;
address[] memory path = new address[](2);
uint256[] memory gas = new uint256[](2);
address WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
if(base == WBNB){
success = deposit(base, msg.value);
if(success == false){
response = failedResponse(token,base);
return response;
}
}else{
success = deposit(WBNB, msg.value);
if(success == false){
response = failedResponse(token,base);
return response;
}
success = swapBase(base);
if(success == false){
response = failedResponse(token,base);
return response;
}
}
success = approve(base, router);
if(success == false){
response = failedResponse(token,base);
return response;
}
amount = balanceOf(base);
path[0] = base;
path[1] = token;
(success,estimatedBuyAmount) = getAmountsOut(router, amount, path);
if(success == false){
response = failedResponse(token,base);
return response;
}
gas[0] = gasleft();
success = swap(router, amount, path);
if(success == false){
response = failedResponse(token,base);
return response;
}
gas[0] = gas[0] - gasleft();
buyAmount = balanceOf(token);
path[0] = token;
path[1] = base;
success = approve(token,router);
if(success == false){
response = failedResponse(token,base);
return response;
}
(success,estimatedSellAmount) = getAmountsOut(router, buyAmount, path);
if(success == false){
response = failedResponse(token,base);
return response;
}
gas[1] = gasleft();
success = swap(router,buyAmount,path);
if(success == false){
response = failedResponse(token,base);
return response;
}
gas[1] = gas[1] - gasleft();
sellAmount = balanceOf(base);
response = HoneyPot(
false,
base,
token,
estimatedBuyAmount,
buyAmount,
estimatedSellAmount,
sellAmount,
gas[0],
gas[1]
);
return response;
}
function failedResponse(address token,address base)public pure returns(HoneyPot memory){
HoneyPot memory response;
response = HoneyPot(
true,
base,
token,
0,
0,
0,
0,
0,
0
);
return response;
}
function deposit(address to,uint256 amount) public payable returns(bool success) {
assembly{
mstore(0,hex"d0e30db0")
let _s := call(gas(),to,amount,0,4,0,0)
switch _s
case 0{
success := false
}
case 1{
success := true
}
}
}
function balanceOf(address to) public view returns(uint256 amount){
(,bytes memory data) = to.staticcall(abi.encodeWithSignature("balanceOf(address)",address(this)));
amount = abi.decode(data,(uint256));
return amount;
}
function approve(address to,address token) public payable returns(bool success){
uint256 approveInfinity =
115792089237316195423570985008687907853269984665640564039457584007913129639935;
(success,) = to.call(abi.encodeWithSignature("approve(address,uint256)",token,approveInfinity));
if(success == false){
return false;
}
return true;
}
function getAmountsOut(address router,uint256 amountIn,address[] memory path) public view returns(bool success, uint256 amount){
(bool _s,bytes memory data) = router.staticcall(abi.encodeWithSignature("getAmountsOut(uint256,address[])",amountIn,path));
if(_s == false){
return(false,0);
}
(uint256[] memory amounts) = abi.decode(data,(uint256[]));
return (true,amounts[1]);
}
function swap(address router,uint256 amountIn,address[] memory path) public payable returns(bool){
(bool success,) = router.call(abi.encodeWithSignature("swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256,uint256,address[],address,uint256)",amountIn,1,path,address(this),block.timestamp + 60));
if(success == false){
return false;
}
return true;
}
function swapBase(address token) public payable returns(bool success){
address WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
address router = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
address[] memory path = new address[](2);
path[0] = WBNB;
path[1] = token;
uint256 amountIn = balanceOf(WBNB);
bool _s = approve(WBNB,router);
if(_s == false){
return false;
}
_s = swap(router,amountIn,path);
if(_s == false){
return false;
}
return true;
}
}