-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkatana.js
More file actions
275 lines (240 loc) · 7.69 KB
/
katana.js
File metadata and controls
275 lines (240 loc) · 7.69 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
const scheduler = require("node-schedule");
const { ethers } = require("ethers");
const figlet = require("figlet");
require("dotenv").config();
const fs = require("fs");
// Import environment variables
const RPC_URL = process.env.RONIN_RPC;
const WALLET_ADDRESS = process.env.USER_ADDRESS;
const USER_AGENT = process.env.USER_AGENT;
const PRIV_KEY = process.env.USER_PRIVATE_KEY;
// State storage object for claims
var claims = {
previousClaim: "",
nextClaim: "",
};
// Initialize ethers components
const provider = new ethers.getDefaultProvider(
RPC_URL,
(request_kwargs = {
headers: { "content-type": "application/json", "user-agent": USER_AGENT },
})
);
// Contract ABIs
const stakingABI = ["function stake(uint256)"];
const claimsABI = ["function claimPendingRewards()"];
const erc20ABI = ["function balanceOf(address) view returns (uint256)"];
const katanaABI = [
"function swapExactRONForTokens(uint256, address[], address, uint256) payable",
"function getAmountsOut(uint, address[]) public view returns (uint[])",
];
// All relevant addresses needed
const AXS = "0x97a9107c1793bc407d6f527b77e7fff4d812bece";
const WRON = "0xe514d9deb7966c8be0ca922de8a064264ea6bcd4";
const WETH = "0xc99a6a985ed2cac1ef41640596c5a5f9f4e19ef5";
const katanaAdd = "0x7d0556d55ca1a92708681e2e231733ebd922597d";
const claimsAdd = "0xd4640c26c1a31cd632d8ae1a96fe5ac135d1eb52";
const stakingAdd = "0x05b0bb3c1c320b280501b86706c3551995bc8571";
// Setup wallet and contract connections
const wallet = new ethers.Wallet(PRIV_KEY, provider);
const axsContract = new ethers.Contract(AXS, erc20ABI, provider);
const katanaRouter = new ethers.Contract(
katanaAdd,
katanaABI,
provider
).connect(wallet);
const stakingContract = new ethers.Contract(
stakingAdd,
stakingABI,
provider
).connect(wallet);
const claimsContract = new ethers.Contract(
claimsAdd,
claimsABI,
provider
).connect(wallet);
// Main Function
const main = async () => {
try {
// hello world
console.log(
figlet.textSync("RONCompound", {
font: "Standard",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
);
// current ronin balance
const balance = await provider.getBalance(WALLET_ADDRESS);
console.log("RON Balance: " + ethers.utils.formatEther(balance));
let claimsExists = false;
try {
// get stored values from file
const storedData = JSON.parse(fs.readFileSync("./claims.json"));
// not first launch, check data
if ("nextClaim" in storedData) {
const nextClaim = new Date(storedData.nextClaim);
const currentDate = new Date();
// restore claims schedule
if (nextClaim > currentDate) {
console.log("Restored Claim: " + nextClaim);
scheduler.scheduleJob(nextClaim, RONCompound);
claimsExists = true;
}
}
} catch (error) {
console.error(error);
}
//no previous launch
if (!claimsExists) {
RONCompound();
}
} catch (error) {
console.error(error);
}
};
// RON Compound Function
const RONCompound = async () => {
try {
// claim RON rewards and swap for AXS
const balance = await claimRONrewards();
const swapped = await swapRONforAXS(balance);
// stake the swapped AXS tokens
if (swapped) {
return await stakeAXStokens();
}
} catch (error) {
console.error(error);
}
return false;
};
// Stake Function
const stakeAXStokens = async () => {
try {
// get current AXS balance
const balance = await axsContract.balanceOf(WALLET_ADDRESS);
const formattedBal = ethers.utils.formatEther(balance);
console.log("AXS Balance: " + formattedBal);
// reject staking if too small
if (formattedBal < 0.01) throw "Staking value too small!";
// set random gasLimit to avoid detection
const randomGas = 400000 + (Math.random() * (99999 - 10000) + 10000);
const overrideOptions = {
gasLimit: Math.floor(randomGas),
};
// execute AXS staking transaction
console.log("Staking AXS Tokens...");
const stake = await stakingContract.stake(balance, overrideOptions);
const receipt = await stake.wait();
// wait for transaction to complete
if (receipt) {
console.log("AXS STAKE SUCCESSFUL");
const ronBal = await provider.getBalance(WALLET_ADDRESS);
console.log("RON Balance: " + ethers.utils.formatEther(ronBal));
const axsBal = await axsContract.balanceOf(WALLET_ADDRESS);
console.log("AXS Balance: " + ethers.utils.formatEther(axsBal));
return true;
}
} catch (error) {
console.error(error);
}
return false;
};
// Swap Function
const swapRONforAXS = async (amount) => {
try {
// cannot swap if too small
if (amount < 0.04) throw "Conversion value too small!";
// set gasLimit and value amount
const randomGas = Math.floor(Math.random() * (500000 - 400001) + 400000);
const overrideOptions = {
gasLimit: randomGas,
value: amountIn,
};
// save some RON tokens for gas
amount = amount - 0.02 - ethers.utils.formatEther(randomGas);
const path = [WRON, WETH, AXS];
// calculate input variables
const amountIn = ethers.utils.parseEther(amount.toString());
const result = await katanaRouter.getAmountsOut(amountIn, path);
const amountOut = Number(ethers.utils.formatEther(result[2])) * 0.99;
const amountOutMin = ethers.utils.parseEther(amountOut.toString());
const deadline = Date.now() + 1000 * 60 * 5;
// execute the RON swapping transaction
console.log(`Swapping: ${amount} RON, For: ~ ${amountOut} AXS`);
const swap = await katanaRouter.swapExactRONForTokens(
amountOutMin,
path,
WALLET_ADDRESS,
deadline,
overrideOptions
);
// wait for transaction to complete
const receipt = await swap.wait();
if (receipt) {
console.log("RON SWAP SUCCESSFUL");
return true;
}
} catch (error) {
console.error(error);
}
return false;
};
// Claims Function
const claimRONrewards = async () => {
try {
// set random gasLimit to avoid detection
const randomGas = 400000 + (Math.random() * (99999 - 10000) + 10000);
const overrideOptions = {
gasLimit: Math.floor(randomGas),
};
// execute the RON claiming transaction
const claim = await claimsContract.claimPendingRewards(overrideOptions);
const receipt = await claim.wait();
// wait for transaction to complete
if (receipt) {
claims.previousClaim = new Date().toString();
console.log("RON CLAIM SUCCESSFUL");
let balance = await provider.getBalance(WALLET_ADDRESS);
balance = ethers.utils.formatEther(balance);
console.log("RON Balance: " + balance);
// claim successful schedule next
scheduleNext(new Date());
return balance;
}
} catch (error) {
console.error(error);
// claims failed trying again tomorrow
console.log("Claims Attempt Failed!");
console.log("Trying again tomorrow.");
scheduleNext(new Date());
}
return false;
};
// Job Scheduler Function
const scheduleNext = async (nextDate) => {
// set next (24hrs, 1min, 30sec from now)
nextDate.setHours(nextDate.getHours() + 24);
nextDate.setMinutes(nextDate.getMinutes() + 1);
nextDate.setSeconds(nextDate.getSeconds() + 30);
claims.nextClaim = nextDate.toString();
console.log("Next Claim: " + nextDate);
// schedule next restake
scheduler.scheduleJob(nextDate, RONCompound);
storeData();
return;
};
// Data Storage Function
const storeData = async () => {
const data = JSON.stringify(claims);
fs.writeFile("./claims.json", data, (err) => {
if (err) {
console.error(err);
} else {
console.log("Data stored: \n" + data);
}
});
};
main();