-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
202 lines (179 loc) · 5.08 KB
/
main.js
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
const { ethers } = require("ethers");
const axios = require("axios");
require("dotenv").config({ path: __dirname + "/.env" });
const provider = new ethers.JsonRpcProvider("https://rpc.taiko.xyz");
const wallets = [
{
address: process.env.ADDRESS_1,
privateKey: process.env.PRIVATE_KEY_1,
},
{
address: process.env.ADDRESS_2,
privateKey: process.env.PRIVATE_KEY_2,
},
{
address: process.env.ADDRESS_3,
privateKey: process.env.PRIVATE_KEY_3,
},
{
address: process.env.ADDRESS_4,
privateKey: process.env.PRIVATE_KEY_4,
},
{
address: process.env.ADDRESS_5,
privateKey: process.env.PRIVATE_KEY_5,
},
{
address: process.env.ADDRESS_6,
privateKey: process.env.PRIVATE_KEY_6,
},
{
address: process.env.ADDRESS_7,
privateKey: process.env.PRIVATE_KEY_7,
},
];
const WETH_ADDRESS = "0xa51894664a773981c6c112c43ce576f315d5b1b6";
const WETH_ABI = [
"function deposit() public payable",
"function withdraw(uint wad) public",
"function balanceOf(address owner) view returns (uint256)",
];
function getRandomPercentage(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomDelay(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min) * 1000;
}
async function getBalance(contract, address) {
try {
return await contract.balanceOf(address);
} catch (error) {
console.error(`Error getting balance: ${error.message}`);
throw error;
}
}
async function getETHPriceInUSDT() {
try {
const response = await axios.get(
"https://api.coingecko.com/api/v3/simple/price",
{
params: {
ids: "ethereum",
vs_currencies: "usd",
},
}
);
const ethPriceInUSD = response.data.ethereum.usd;
return ethPriceInUSD;
} catch (error) {
console.error(`Error fetching ETH price: ${error.message}`);
throw error;
}
}
async function getCombinedBalanceInUSDT(walletAddress, ethPrice) {
const wethContract = new ethers.Contract(WETH_ADDRESS, WETH_ABI, provider);
const [ethBalance, wethBalance] = await Promise.all([
provider.getBalance(walletAddress),
getBalance(wethContract, walletAddress),
]);
const ethBalanceFormatted = ethers.formatEther(ethBalance);
const wethBalanceFormatted = ethers.formatEther(wethBalance);
const totalEth =
parseFloat(ethBalanceFormatted) + parseFloat(wethBalanceFormatted);
return totalEth * ethPrice;
}
async function wrapETH(contract, amount) {
try {
const tx = await contract.deposit({ value: amount });
await tx.wait();
} catch (error) {
console.error(`Error wrapping ETH: ${error.message}`);
throw error;
}
}
async function unwrapETH(contract, amount) {
try {
const tx = await contract.withdraw(amount);
await tx.wait();
} catch (error) {
console.error(`Error unwrapping ETH: ${error.message}`);
throw error;
}
}
async function performWrapsAndUnwraps(wallet) {
const walletInstance = new ethers.Wallet(wallet.privateKey, provider);
const wethContract = new ethers.Contract(
WETH_ADDRESS,
WETH_ABI,
walletInstance
);
try {
const [ethBalance, wethBalance] = await Promise.all([
provider.getBalance(wallet.address),
getBalance(wethContract, wallet.address),
]);
await performOperations(wrapETH.bind(null, wethContract), ethBalance, 3, 6);
await performOperations(
unwrapETH.bind(null, wethContract),
wethBalance,
3,
6
);
} catch (error) {
console.error(
`Error in main function for ${wallet.address}: ${error.message}`
);
}
}
async function performOperations(operation, balance, minTimes, maxTimes) {
const times =
Math.floor(Math.random() * (maxTimes - minTimes + 1)) + minTimes;
for (let i = 0; i < times; i++) {
const percentage = getRandomPercentage(0.08, 0.12);
const amount =
(BigInt(balance) * BigInt(Math.floor(percentage * 1e18))) / BigInt(1e18);
await operation(amount);
await new Promise((resolve) => setTimeout(resolve, getRandomDelay(2, 6)));
}
}
async function main() {
const promises = wallets.map((wallet) => performWrapsAndUnwraps(wallet));
await Promise.all(promises);
}
async function runMultipleTimes(times) {
const ethPrice = await getETHPriceInUSDT();
const initialBalances = await Promise.all(
wallets.map(async (wallet) => {
const balanceInUSDT = await getCombinedBalanceInUSDT(
wallet.address,
ethPrice
);
console.log(
`Initial balance for ${wallet.address.slice(
0,
6
)}...${wallet.address.slice(-4)}: ${balanceInUSDT.toFixed(2)}$`
);
return balanceInUSDT;
})
);
for (let i = 0; i < times; i++) {
await main();
}
const finalBalances = await Promise.all(
wallets.map(async (wallet) => {
const balanceInUSDT = await getCombinedBalanceInUSDT(
wallet.address,
ethPrice
);
console.log(
`Final balance for ${wallet.address.slice(
0,
6
)}...${wallet.address.slice(-4)}: ${balanceInUSDT.toFixed(2)}$`
);
return balanceInUSDT;
})
);
}
runMultipleTimes(20);