Repository navigation
Expand file tree
/
Copy pathriptide.py
More file actions
174 lines (113 loc) · 4.58 KB
/
Copy pathriptide.py
File metadata and controls
174 lines (113 loc) · 4.58 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
import json
import math
from time import sleep
from datetime import datetime
from solana.rpc.api import Client
import asyncio
import numpy
Voteaccount = "GhJVN91EJ7M68dXDVWoJvNbr5Gsqyb2wyoo8p5G6rRxL" # voting PDA ATA
# Solana Ignition Hackathon East Asia - Dorahacks
# BVCaVh8mNzYgorruQJ7QvSg4PuggAfdbC71Qu5GNGRA8
# Solana Riptide Hackathon East Asia - Scallop
# GhJVN91EJ7M68dXDVWoJvNbr5Gsqyb2wyoo8p5G6rRxL
pathtx = 'riptide_asia_tx.txt'
pathaddup = 'riptide_asia_addup.txt'
txfile = open(pathtx, 'w')
addupfile = open(pathaddup, 'w')
outarr = []
def arruni(listA): # delet repeat things
return sorted(set(listA), key=listA.index)
def noneto0(num):
try:
num = int(num)
except TypeError:
num = 0
return num
def outputjson(outarr):
backupjson = open('riptide_list.json', 'w+')
outjson = []
for tx in outarr:
data = {}
data["address"] = tx[0][0]
data["VoteUSDC"] = tx[0][1]*math.pow(10, -6)
data["signature"] = tx[1]
outjson.append(data)
output = json.dumps(outjson)
backupjson.write(output)
backupjson.close()
def voteoutput(outarr): # address voted USDC add up function
output = []
for addressandtx in outarr:
output.append(addressandtx[0][0])
output = arruni(output)
# print(output)
outputwithusdc = []
for address in output:
outputwithusdc.append([address, 0])
# print(outputwithusdc)
for addressandtx in outarr:
for address in outputwithusdc:
if address[0] == addressandtx[0][0]:
address[1] += addressandtx[0][1]
# print(outputwithusdc)
for voteusdc in outputwithusdc:
voteusdc[1] = voteusdc[1]*math.pow(10, -6)
outputsort = sorted(outputwithusdc, key=lambda s: s[1], reverse=True)
return outputsort
def addupout(outarr):
addupusdc = 0
for addusd in outarr:
addupusdc += addusd[0][1]
print("Add up USDC:", addupusdc*math.pow(10, -6), file=addupfile)
async def main():
solana_client = Client("https://api.mainnet-beta.solana.com") # Don't use Serum RPC
today = datetime.now()
# print(today.strftime("%Y-%m-%d %H:%M:%S"), file=txfile)
print(today.strftime("%Y-%m-%d %H:%M:%S"), file=addupfile)
lastesttx = ""
while True:
if lastesttx == "":
reqjson = solana_client.get_confirmed_signature_for_address2(Voteaccount, limit=1000)
else:
# break
reqjson = solana_client.get_confirmed_signature_for_address2(Voteaccount, before=lastesttx)
resultlen = len(reqjson["result"])
try:
lastesttx = reqjson["result"][resultlen-1]["signature"]
except:
print("We've hit the bottom of target datas!")
break
if len(reqjson["result"]) != 0:
print(len(reqjson["result"]))
for i in range(0, len(reqjson["result"])):
tx = reqjson["result"][i]["signature"]
# Only count success transaction.
if reqjson["result"][i]["err"] == None:
print(tx)
votingreqjson = solana_client.get_confirmed_transaction(tx)
sleep(0.8)
if "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" in json.dumps(votingreqjson): # If this tx voted USDC for Your Project (This should be upgrade!!!)
voteraddress = votingreqjson["result"]["transaction"]["message"]["accountKeys"][0]
try:
preBalances = noneto0(votingreqjson["result"]["meta"]["preTokenBalances"][0]["uiTokenAmount"]["amount"])
postBalances = noneto0(votingreqjson["result"]["meta"]["postTokenBalances"][0]["uiTokenAmount"]["amount"])
except:
print("Captching amount error, Maybe we've hit the bottom.")
break
voterusdc = abs(preBalances - postBalances) #sometimes the order is not correct. so we need to abs().
# print(voterusdc)
outarr.append([[voteraddress, voterusdc], [tx]])
txtout = voteraddress, voterusdc*math.pow(10, -6), tx
print(txtout, file=txfile)
else:
break
outputjson(outarr)
addupout(outarr)
print("Scraping Over!")
outputsort = voteoutput(outarr)
for addressandvote in outputsort:
print(addressandvote, file=addupfile)
numpy.save('riptide_array', outputsort)
txfile.close()
addupfile.close()
asyncio.run(main())