-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsweepAssets.py
More file actions
318 lines (298 loc) · 13.8 KB
/
Copy pathsweepAssets.py
File metadata and controls
318 lines (298 loc) · 13.8 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
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
import json
import time
from web3 import Web3
import AccessToken
import txUtils
from assetTypes import axieFunctions
from assetTypes import itemFunctions
from assetTypes import landFunctions
# DO NOT TOUCH ANYTHING IN THIS FILE OR YOU WILL BREAK IT.
if True:
try:
with open("filter.json") as f:
filterData = json.load(f)
if filterData == {}:
filterData = {
"price": 0,
"filter": {},
"num": 0,
"type": ""
}
except:
with open("filter.json", "w") as f:
filterData = {
"price": 0,
"filter": {},
"num": 0,
"type": ""
}
f.write(json.dumps(filterData))
with open("config.json") as f:
json_data = json.load(f)
key = json_data['key']
if key == "0xYOUR_PRIVATE_KEY":
key = input("Please enter your private key")
if json_data['address'] == "ronin:YOUR_RONIN_ADDRESS":
json_data['address'] = input("Please enter your ronin address")
if not Web3.is_address(json_data['address'].replace("ronin:", "0x")):
print("Invalid address entered. Please try again. Both ronin: and 0x are accepted. Exiting.")
raise SystemExit
address = Web3.to_checksum_address(json_data['address'].replace("ronin:", "0x"))
accessToken = AccessToken.GenerateAccessToken(key, address)
if not str(type(json_data['gasPrice'])) == "<class 'int'>":
print("Invalid gas price entered. Must be a whole number. Exiting.")
raise SystemExit
gasPrice = json_data['gasPrice']
ethContract = txUtils.eth()
marketplaceContract = txUtils.marketplace()
# THIS IS FOR APPROVING ETH TO BE SPENT BY THE MARKETPLACE.
# WHEN YOU MAKE A NEW ACCOUNT ON MARKETPLACE, IT DOES THE SAME THING.
# The address being approved is 0xfff9ce5f71ca6178d3beecedb61e7eff1602950e which is Contract: Marketplace Gateway V2
# https://explorer.roninchain.com/address/ronin:fff9ce5f71ca6178d3beecedb61e7eff1602950e
# The amount approved is 115792089237316195423570985008687907853269984665640564039457584007913129639935
# This is the same amount that the ronin wallet approves.
def approve():
send_txn = ethContract.functions.approve(
Web3.to_checksum_address('0xfff9ce5f71ca6178d3beecedb61e7eff1602950e'),
115792089237316195423570985008687907853269984665640564039457584007913129639935
).build_transaction({
'chainId': 2020,
'gas': 481337,
'gasPrice': Web3.to_wei(20, 'gwei'),
'nonce': txUtils.getNonce(address)
})
signed_txn = txUtils.w3.eth.account.sign_transaction(send_txn, private_key=key)
sentTx = Web3.to_hex(Web3.keccak(signed_txn.rawTransaction))
txUtils.sendTx(signed_txn)
return sentTx
def buyAsset(asset):
order = asset['order']
marketTx = marketplaceContract.functions.interactWith(
'ORDER_EXCHANGE',
marketplaceContract.encodeABI(fn_name='settleOrder', args=[
0,
int(order['currentPrice']),
Web3.to_checksum_address("0xa8Da6b8948D011f063aF3aA8B6bEb417f75d1194"),
order['signature'],
[
Web3.to_checksum_address(order['maker']),
1,
[[
1,
Web3.to_checksum_address(order['assets'][0]['address']),
int(order['assets'][0]['id']),
int(order['assets'][0]['quantity'])
]],
int(order['expiredAt']),
Web3.to_checksum_address("0xc99a6A985eD2Cac1ef41640596C5A5f9F4E19Ef5"),
int(order['startedAt']),
int(order['basePrice']),
int(order['endedAt']),
int(order['endedPrice']),
0,
int(order['nonce']),
425
]
])
).build_transaction({
'chainId': 2020,
'gas': 481337,
'gasPrice': Web3.to_wei(int(gasPrice), 'gwei'),
'nonce': txUtils.getNonce(address)
})
signedTx = txUtils.w3.eth.account.sign_transaction(marketTx, private_key=key)
return signedTx
def runLoop(filterData):
assetType = filterData['type']
myFilter = filterData['filter']
numAssets = filterData['num']
price = Web3.to_wei(filterData['price'], 'ether')
txs = []
attemptedAssets = []
attemptedTxs = {}
count = 0
numToBuy = numAssets
balance = ethContract.functions.balanceOf(address).call()
while True:
amountToSpend = 0
if assetType == "axies":
market = axieFunctions.fetchMarket(accessToken, myFilter)
elif assetType == "lands":
market = landFunctions.fetchMarket(accessToken, myFilter)
elif assetType == "items":
market = itemFunctions.fetchMarket(accessToken, myFilter)
else:
print("Filter did match any of the availible types, something is wrong.")
raise SystemExit
for asset in market['data'][assetType]['results']:
if 'id' in asset and asset['id'] in attemptedAssets:
continue
elif 'tokenId' in asset and asset['tokenId'] in attemptedAssets:
continue
if price >= int(asset['order']['currentPrice']):
if int(asset['order']['endedPrice']) == 0 and int(asset['order']['endedAt']) == 0:
priceChange = 0
else:
priceChange = (int(asset['order']['endedPrice']) - int(asset['order']['basePrice'])) / int(
asset['order']['duration'])
# this is to check if they are doing a sale from 0 -> 10000 over 1 day in attempt to fool bots.
# worst case, a tx takes 10 seconds from when it was pulled from marketplace to when it goes through
# i doubt it will ever take 10s, but would rather be safe.
# feel free to change the 10 to something less if you want to (at your own risk)
if int(asset['order']['currentPrice']) + (priceChange * 10) > price:
if 'id' in asset:
print(f"not buying {asset['id']}, someone is doing something funky.")
else:
print(f"not buying {asset['tokenId']}, someone is doing something funky.")
continue
amountToSpend += int(asset['order']['currentPrice'])
if amountToSpend > balance:
break
tx = buyAsset(asset)
txs.append(tx)
if 'id' in asset:
print(f"Attempting to buy Asset #{asset['id']}.")
attemptedTxs[Web3.to_hex(Web3.keccak(tx.rawTransaction))] = asset['id']
attemptedAssets.append(asset['id'])
else:
print(f"Attempting to buy Asset #{asset['tokenId']}.")
attemptedTxs[Web3.to_hex(Web3.keccak(tx.rawTransaction))] = asset['tokenId']
attemptedAssets.append(asset['tokenId'])
numToBuy -= 1
if numToBuy <= 0:
break
if len(txs) > 0:
txUtils.sendTxThreads(txs)
for tx in txs:
sentTx = Web3.to_hex(Web3.keccak(tx.rawTransaction))
receipt = txUtils.w3.eth.get_transaction_receipt(sentTx)
if not receipt.status == 1:
numToBuy += 1
print(f"Buying asset {attemptedTxs[sentTx]} failed.")
else:
print(f"Buying asset {attemptedTxs[sentTx]} succeded.")
txs = []
if numToBuy <= 0:
print(f"Bought {numAssets} assets. This is the limit. Exiting.")
raise SystemExit
balance = ethContract.functions.balanceOf(address).call()
if balance <= price:
print(f"You do not have enough ETH to buy anything. Current price you have set is {price / (10 ** 18)} ETH and you only have {balance / (10 ** 18)} ETH. Exiting.")
raise SystemExit
count += 1
if count % 120 == 0:
print("Still waiting. Printing this so you know I am still alive.")
time.sleep(1)
def createFilter(purchasePrice=0, newFilter=None, numAssets=0, assetType=""):
if purchasePrice == 0:
purchasePrice = input("Please enter the purchase price of assets for this filter.\n")
try:
purchasePrice = float(purchasePrice)
except:
print("Purchase price is invalid. Please only enter a number.")
return createFilter(newFilter=newFilter, numAssets=numAssets, assetType=assetType)
if numAssets == 0:
numAssets = input("Please enter the number of assets to buy with this filter.\n")
try:
numAssets = int(numAssets)
except:
print("Num assets is invalid. Please only enter a number.")
return createFilter(purchasePrice=purchasePrice, newFilter=newFilter, assetType=assetType)
if newFilter is None:
newFilter = {}
url = input("Please paste full marketplace URL\n")
if assetType == "":
assetType = url[:url.find("?")].replace("https://app.axieinfinity.com/marketplace/", "").replace("/", "")
try:
inputData = url[url.find("?") + 1:].split("&")
for value in inputData:
tempData = value.split("=")
filterType = tempData[0]
try:
filterValue = int(tempData[1])
except:
filterValue = tempData[1]
if filterType in ["auctionTypes", "stage", "page", "partTypes", "specialCollection"]:
continue
if filterType in ["numMystic", "numJapan", "numXmas", "numShiny", "numSummer"]:
if filterType in newFilter:
if filterValue < newFilter[filterType][0]:
inc = -1
else:
inc = 1
for i in range(newFilter[filterType][0]+inc, filterValue, inc):
newFilter[filterType].append(i)
if filterType == "excludeParts":
filterType = "parts"
if filterType in newFilter and filterValue in newFilter['parts']:
newFilter['parts'][newFilter['parts'].index(filterValue)] = "!" + filterValue
continue
else:
filterValue = "!" + filterValue
if filterType == 'title':
filterValue = filterValue.replace("+", " ")
if filterType == "type":
filterType = "landType"
if not filterType in newFilter:
newFilter[filterType] = []
newFilter[filterType].append(filterValue)
for value in newFilter:
if len(newFilter[value]) == 0:
newFilter[value] = None
except:
print("Something went wrong with the filter. Did you enter the URL correctly?")
print("Ex: https://app.axieinfinity.com/marketplace/axies/?class=Beast&mystic=1&auctionTypes=Sale")
print("Would search for a 1 part mystic beast")
return createFilter(purchasePrice=purchasePrice, numAssets=numAssets)
if assetType == "axies":
num = axieFunctions.checkFilter(accessToken, newFilter)
elif assetType == "lands":
num = landFunctions.checkFilter(accessToken, newFilter)
elif assetType == "items":
num = itemFunctions.checkFilter(accessToken, newFilter)
else:
print("Filter did match any of the availible types, something is wrong.")
raise SystemExit
if num == 0:
print("No axies exist with your filter. Please enter a new filter and try again.")
return createFilter(purchasePrice=purchasePrice, numAssets=numAssets)
else:
print(f"Found {num} assets that match your filter. Moving to next step.")
filterData = {
"price": purchasePrice,
"filter": newFilter,
"num": numAssets,
"type": assetType
}
with open("./filter.json", "w") as f:
f.write(json.dumps(filterData))
return filterData
def init(filterData):
if filterData['type'] == "" or filterData['filter'] == {} or filterData['num'] == 0 or filterData['price'] == 0:
filterData = createFilter()
else:
choice = input("Would you like to use the current filter? (Y/N)\n")
if not choice.lower() == "y":
filterData = createFilter()
price = Web3.to_wei(filterData['price'], 'ether')
balance = ethContract.functions.balanceOf(address).call()
if balance < price:
print("You do not have enough ETH to buy anything. Current price you have set is " + str(price / (10 ** 18)) + " ETH and you only have " + str(balance / (10 ** 18)) + " ETH. Exiting.")
raise SystemExit
ronBalance = txUtils.w3.eth.get_balance(address)
if ronBalance < (481337 * Web3.to_wei(int(gasPrice), 'gwei')):
print("You do not have enough RON for the entered gas price. Please lower gas price or add more RON.")
raise SystemExit
allowance = ethContract.functions.allowance(address, "0xffF9Ce5f71ca6178D3BEEcEDB61e7Eff1602950E").call()
if allowance == 0:
print("We need to approve eth for spending on the marketplace. Approving...")
sentTx = approve()
allowance = ethContract.functions.allowance(address, "0xffF9Ce5f71ca6178D3BEEcEDB61e7Eff1602950E").call()
if allowance == 0:
print("Something went wrong, approval didnt work. Exiting.")
raise SystemExit
else:
print("Approved at tx: " + str(sentTx))
print("Starting loop.")
runLoop(filterData)
init(filterData)