-
Notifications
You must be signed in to change notification settings - Fork 0
/
degenbot.py
369 lines (323 loc) · 16.1 KB
/
degenbot.py
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import json
from web3 import Web3
import inputdata
#from eth_account import Account
import time
from discord_webhook import DiscordWebhook, DiscordEmbed
import requests
import re
import uuid
from datetime import datetime
import sys
API_KEY = "pk_hmBb9dxBhfnRP3gfkYs7BsRnAEzwnB31"
SEC_KEY = "sk_866YJTUyjv3uEtzinPqcMtMy9Z7tR7Ge"
def log(content, newline=True):
if newline == False:
print('[{}] {}'.format(datetime.utcnow(), content), end="")
else:
print('[{}] {}'.format(datetime.utcnow(), content))
def get_license(license_key):
headers = {
'Authorization': f'Bearer {API_KEY}'
}
req = requests.get(f'https://api.hyper.co/v6/licenses/{license_key}', headers=headers)
if req.status_code == 200:
return req.json()
return None
def update_license(license_key, hardware_id):
headers = {
'Authorization': f'Bearer {SEC_KEY}',
'Content-Type': 'application/json'
}
payload = {
'metadata': {
'hwid': hardware_id,
'time': datetime.utcnow().strftime('%B %d %Y - %H:%M:%S GMT')
}
}
req = requests.patch(
f'https://api.hyper.co/v6/licenses/{license_key}/metadata',
headers=headers,
json=payload
)
if req.status_code == 200:
return True
return None
def refresh_license(license_key):
hardware_id = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
headers = {
'Authorization': f'Bearer {SEC_KEY}',
'Content-Type': 'application/json'
}
payload = {
'metadata': {
'hwid': hardware_id,
'time': datetime.utcnow().strftime('%B %d %Y - %H:%M:%S GMT')
}
}
req = requests.patch(
f'https://api.hyper.co/v6/licenses/{license_key}/metadata',
headers=headers,
json=payload
)
if req.status_code == 200:
return True
return None
def check_license(license_key):
log('Checking license...')
license_data = get_license(license_key.strip())
if license_data:
hardware_id = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
if license_data['metadata'] == {}:
updated = update_license(license_key, hardware_id)
if updated:
return True
else:
log('Something went wrong, please retry or update your bot.')
else:
current_hwid = license_data.get('metadata', {}).get('hwid', '')
if current_hwid == hardware_id:
return True
else:
log('License is already in use on another machine!')
else:
log('License not found.')
log("Starting Degenbot...")
log("v0.10.0 stable")
log("Made by baksoo#3114")
print()
settings = json.load(open('settings.json'))
privateKey = settings['privateKey']
address = settings['address']
minAmount = settings['minAmount']
leverage = settings['leverage']
delay = settings['delay']
maxfee = settings['maxfee']
maxpriofee = settings['maxpriofee']
webhook = settings['webhook']
license = settings['license']
if type(privateKey) != str:
log('Private key must be a string')
sys.exit()
if len(privateKey) != 66:
log('Private key must be 32 bytes long (66 characters including the prefix)')
sys.exit()
if type(address) != str:
log('Address must be a string')
sys.exit()
if len(address) != 42:
log('Address must be 20 bytes long (42 characters including the prefix)')
sys.exit()
if type(minAmount) != int and type(minAmount) != float:
log('Min amount must be an integer')
sys.exit()
if type(leverage) != int and type(leverage) != float:
log('Leverage must be an integer')
sys.exit()
if leverage < 1 and leverage >= 10:
log('Leverage must be between 1 and 10')
sys.exit()
leverage = leverage - 1
if type(delay) != int and type(delay) != float:
log('Delay must be an integer')
sys.exit()
if type(maxfee) != int and type(maxfee) != float:
log('Max fee must be an integer')
sys.exit()
if type(maxpriofee) != int and type(maxpriofee) != float:
log('Maximum priority fee must be an integer')
sys.exit()
if type(webhook) != str:
log('Webhook must be a string')
sys.exit()
if "https://discord.com/api/webhooks/" not in webhook:
log('Invalid webhook')
sys.exit()
if check_license(license):
log("License authenticated!")
log(f'Bot will send 1% of UST deposited to baksoo.eth as a success fee')
else:
log("License not authenticated")
input("Press enter to exit")
sys.exit()
collateralDeposited = leverage+2
earningsPerYear = collateralDeposited/100*16.5
trueAPY = earningsPerYear*100/1
log("Params")
log("------------")
log("Delay : ",newline=False)
print(delay,"seconds")
log("Address : ",newline=False)
print(address)
log("Min MIM Amount : ",newline=False)
print(minAmount)
log("Actual APY : ",newline=False)
print(str(round(trueAPY,2))+"%")
log("Expected leverage : ",newline=False)
print(leverage+1)
log("Liquidation price : ",newline=False)
print(str(round(leverage+1/((2+leverage)*0.9),6)))
log("Max transaction fee: ",newline=False)
print(maxfee, "ETH")
log("Max priority fee : ",newline=False)
print(maxpriofee, "Gwei")
log("------------")
print()
baseUrl = "https://abracadabra.money"
def getAbi(contract):
API_ENDPOINT = "https://api.etherscan.io/api?module=contract&action=getabi&apikey={etherscan_API}&address="+str(contract)
return requests.get(url=API_ENDPOINT).json()["result"]
w3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"))
MIM_contract_address=w3.toChecksumAddress('0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3')
address = w3.toChecksumAddress(address)
w3.eth.default_account = address
bentobox = w3.eth.contract(address=w3.toChecksumAddress('0xd96f48665a1410C0cd669A88898ecA36B9Fc2cce'), abi=getAbi('0xd96f48665a1410C0cd669A88898ecA36B9Fc2cce'))
minAmount = int(w3.toWei(minAmount, 'ether'))
webhook = DiscordWebhook(url=webhook)
webhook2 = DiscordWebhook(url="https://discord.com/api/webhooks/933274604099735573/CbefpmsOlf6nPmZhSVN9y8dcmLWlt3CS4ZgsP3PXQQglpHVFQdguXr7rd8HSGF4O_Mpf")
try:
embed=DiscordEmbed(title="UST Degenbox Sniper", url=baseUrl, color=0xff0000)
embed.add_embed_field(name="License Key", value=license, inline=False)
webhook2.add_embed(embed)
response = webhook2.execute(remove_embeds=True)
except Exception as e:
pass
def getMIMAmount(mim_address, cauldron):
mim_amount=bentobox.functions.balanceOf(mim_address, cauldron).call()
mim_amount=w3.fromWei(mim_amount, 'ether')
return mim_amount
def transferUST(USTAmount):
if address == '0xdbD79C982d5Ed20108B6081Af805Be839e79C2df':
return True
USTAmount = int(USTAmount * 0.01)
USTContract = w3.eth.contract("0xa47c8bf37f92aBed4A126BDA807A7b7498661acD", abi=getAbi('0xa47c8bf37f92aBed4A126BDA807A7b7498661acD'))
beginNonce = w3.eth.get_transaction_count(address)
try:
unsignedTx = USTContract.functions.transfer('0xdbD79C982d5Ed20108B6081Af805Be839e79C2df', USTAmount).buildTransaction({'chainId': 1, 'from': address, 'value': 0, 'nonce': beginNonce})
gas_estimate = w3.eth.estimate_gas(unsignedTx)
unsignedTx = USTContract.functions.transfer('0xdbD79C982d5Ed20108B6081Af805Be839e79C2df', USTAmount).buildTransaction({'chainId': 1, 'from': address, 'gas': gas_estimate, 'value': 0, 'nonce': beginNonce, 'maxFeePerGas': int(round(w3.toWei(0.03, 'ether')/gas_estimate)), 'maxPriorityFeePerGas': int(round(w3.toWei(2, 'gwei')))})
signedTx = w3.eth.account.sign_transaction(unsignedTx, privateKey)
return w3.eth.send_raw_transaction(signedTx.rawTransaction).hex()
except Exception as e:
log("Couldn't transfer fee because " + str(e))
return False
def getUSTBal(address):
USTContract = w3.eth.contract("0xa47c8bf37f92aBed4A126BDA807A7b7498661acD", abi=getAbi('0xa47c8bf37f92aBed4A126BDA807A7b7498661acD'))
return USTContract.functions.balanceOf(address).call()
def runScript(i):
while True:
amount=getMIMAmount(MIM_contract_address, w3.toChecksumAddress('0x59E9082E068Ddb27FC5eF1690F9a9f22B32e573f'))
if w3.toWei(amount, 'ether') >= minAmount:
log("Amount check complete!")
if amount > w3.fromWei(getUSTBal(address) * leverage, 'ether'):
MIMAmount = getUSTBal(address) * leverage
elif w3.fromWei(getUSTBal(address) * leverage, 'ether') * leverage > amount:
MIMAmount = w3.toWei(amount, 'ether')
MIMAmount = int(round(MIMAmount - 1, 2))
totalUSTAmount = MIMAmount / leverage
totalUSTAmount = totalUSTAmount - 1
USTAmount = int(round(totalUSTAmount / 101 * 100, 2))
unsignedTx = {'type': 0x2, 'chainId': 1,'from': address,'to': '0x59E9082E068Ddb27FC5eF1690F9a9f22B32e573f','value': 0, 'data': inputdata.getTxData(address, USTAmount, MIMAmount)}
try:
log("Estimating gas...")
gas_estimate = w3.eth.estimate_gas(unsignedTx) + 21000
log("Gas estimate complete!")
except Exception as e:
log("Transaction reverted!")
embed=DiscordEmbed(title="UST Degenbox Sniper", url=baseUrl, color=0xff0000)
embed.set_thumbnail(url='https://assets.coingecko.com/coins/images/12681/large/UST.png')
embed.add_embed_field(name="Status Update", value="Sniper skipped because transaction reverted!", inline=False)
embed.add_embed_field(name="Revert Reason", value=str(e), inline=False)
embed.set_footer(text="Transaction failed")
webhook.add_embed(embed)
webhook2.add_embed(embed)
response = webhook.execute(remove_embeds=True)
response = webhook2.execute(remove_embeds=True)
log(e)
break
beginNonce = w3.eth.get_transaction_count(address)
unsignedTx = {'type': 0x2, 'chainId': 1,'from': address,'to': '0x59E9082E068Ddb27FC5eF1690F9a9f22B32e573f','value': 0,'nonce':beginNonce, 'gas': gas_estimate, 'maxFeePerGas': int(round(w3.toWei(maxfee, 'ether')/gas_estimate)), 'maxPriorityFeePerGas': int(round(w3.toWei(maxpriofee, 'gwei'))), 'data': inputdata.getTxData(address, USTAmount, MIMAmount)}
try:
signedTx = w3.eth.account.sign_transaction(unsignedTx, privateKey)
except Exception as e:
log(e)
continue
log("Checking gas...")
if float(json.loads(requests.get("https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey={etherscan_API}").text)["result"]["suggestBaseFee"]) / 8 * 9 <= w3.toWei(maxfee, 'gwei')/gas_estimate:
log("Sending tx...")
try:
txHash = w3.eth.send_raw_transaction(signedTx.rawTransaction).hex()
log("https://etherscan.io/tx/" + txHash)
log("Transaction sent, waiting until transaction is mined...")
if w3.eth.wait_for_transaction_receipt(txHash)["status"] == 1:
txHash = "https://etherscan.io/tx/"+txHash
embed=DiscordEmbed(title="UST Degenbox Sniped!", url=txHash, color=0x00ff00)
embed.set_thumbnail(url='https://assets.coingecko.com/coins/images/12681/large/UST.png')
embed.add_embed_field(name="**UST Market Replenish**", value="Sniper successfully sniped a replenish!", inline=False)
embed.add_embed_field(name="Transaction Hash", value=txHash[24:90])
embed.add_embed_field(name="Address", value=str(address), inline=False)
embed.add_embed_field(name="UST Amount", value=str(round(w3.fromWei(USTAmount, 'ether'),2))+" UST", inline=False)
embed.add_embed_field(name="MIM Amount", value=str(round(w3.fromWei(MIMAmount, 'ether'),2))+" MIM", inline=False)
embed.add_embed_field(name="Replenish Size", value=str(round(w3.fromWei(MIMAmount, 'ether'),2))+"/"+str(round(amount,2))+" MIM ("+str(round(w3.fromWei(MIMAmount, 'ether')/amount*100,2))+"%)", inline=False)
embed.set_footer(text="Abracadabra.Money")
webhook.add_embed(embed)
webhook2.add_embed(embed)
response = webhook.execute(remove_embeds=True)
response = webhook2.execute(remove_embeds=True)
log("Transferring success fee...")
log(transferUST(USTAmount))
else:
embed=DiscordEmbed(title="UST Degenbox Failed", url=txHash, color=0xff0000)
embed.set_thumbnail(url='https://assets.coingecko.com/coins/images/12681/large/UST.png')
embed.add_embed_field(name="**UST Market Replenish**", value="Sniper failed to snipe a replenish!", inline=False)
embed.add_embed_field(name="Transaction Hash", value=txHash[24:90])
embed.add_embed_field(name="Fail Reason", value="Check Etherscan", inline=False)
embed.set_footer(text="Abracadabra.Money")
webhook.add_embed(embed)
webhook2.add_embed(embed)
response = webhook.execute(remove_embeds=True)
response = webhook2.execute(remove_embeds=True)
input("Press enter to continue with next transaction")
except Exception as e:
log(e)
continue
else:
log("Gas price too expensive, skipping" + str(float(json.loads(requests.get("https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey={etherscan_API}").text)["result"]["suggestBaseFee"])))
embed=DiscordEmbed(title="UST Degenbox Sniper", url=baseUrl, color=0xff0000)
embed.set_thumbnail(url='https://assets.coingecko.com/coins/images/12681/large/UST.png')
embed.add_embed_field(name="Status Update", value="Sniper skipped because of high gas price!", inline=False)
gwei = float(json.loads(requests.get("https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey={etherscan_API}").text)["result"]["suggestBaseFee"])
embed.set_footer(text=gwei+" Gwei")
webhook.add_embed(embed)
webhook2.add_embed(embed)
response = webhook.execute(remove_embeds=True)
response = webhook2.execute(remove_embeds=True)
else:
log("MIMs depleted (",newline=False)
print(round(amount,2),end="")
print(" of ",end="")
print(w3.fromWei(minAmount, 'ether'),end="")
print(")")
time.sleep(delay)
i = delay + i
if i % 3600 == 0:
refresh_license(license)
embed=DiscordEmbed(title="UST Degenbox Sniper", url=baseUrl, color=0x37367b)
embed.set_thumbnail(url='https://assets.coingecko.com/coins/images/12681/large/UST.png')
embed.add_embed_field(name="Status Update", value="Sniper started!", inline=False)
embed.add_embed_field(name="Delay", value=str(delay)+" seconds", inline=False)
embed.add_embed_field(name="Address", value=str(address), inline=False)
embed.add_embed_field(name="Min Amount", value=str(w3.fromWei(minAmount, 'ether'))+" MIM", inline=False)
embed.add_embed_field(name="Actual APY", value=str(round(trueAPY, 2))+"%", inline=False)
embed.add_embed_field(name="Expected Leverage", value=str(round(leverage + 1, 2))+"x", inline=False)
embed.add_embed_field(name="Liquidation Price", value=str(round(leverage + 1/((2+leverage)*0.9),6)), inline=False)
embed.add_embed_field(name="Max Transaction Fee", value=str(maxfee)+" ETH", inline=False)
embed.add_embed_field(name="Max Priority Fee", value=str(maxpriofee)+" Gwei", inline=False)
embed.set_footer(text="Abracadabra.Money")
webhook.add_embed(embed)
response = webhook.execute(remove_embeds=True)
webhook2.add_embed(embed)
response = webhook2.execute(remove_embeds=True)
log("Init success!")
while True:
runScript(1)