rerun dataset/profitability script 08032024
Browse files- .gitattributes +1 -0
- .gitignore +1 -0
- all_trades_profitability.csv +2 -2
- dataset.csv +2 -2
- delivers.csv +2 -2
- fpmmTrades.csv +3 -0
- fpmms.csv +0 -0
- requests.csv +2 -2
- summary_profitability.csv +3 -131
- tools.csv +2 -2
- tools.py +0 -833
.gitattributes
CHANGED
@@ -58,3 +58,4 @@ delivers.csv filter=lfs diff=lfs merge=lfs -text
|
|
58 |
requests.csv filter=lfs diff=lfs merge=lfs -text
|
59 |
tools.csv filter=lfs diff=lfs merge=lfs -text
|
60 |
all_trades_profitability.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
58 |
requests.csv filter=lfs diff=lfs merge=lfs -text
|
59 |
tools.csv filter=lfs diff=lfs merge=lfs -text
|
60 |
all_trades_profitability.csv filter=lfs diff=lfs merge=lfs -text
|
61 |
+
*.csv filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.DS_Store
|
all_trades_profitability.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:66e559687b5bb7bffa8171b82f92f6c3a91788d5e974d42a04d4a8a0b463999e
|
3 |
+
size 19856756
|
dataset.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1ce1654c8c632eecb10632dfa6bce98992feca3d01b9a800e3417b367d09fda0
|
3 |
+
size 696381766
|
delivers.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c9766dbbd5973a9cfa9ed7c2498b2bcc6bce5b9a33677e0a66d1628496a5055d
|
3 |
+
size 530850877
|
fpmmTrades.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1ed9a49e309fe9e6dbddbe7067cb03951876e3374c097cd2e91548a91482be1e
|
3 |
+
size 44361982
|
fpmms.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
requests.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:58364dbf755b1fdccf8a57a65d42f7afbada936b3ad79c6fb5a4cfa9e5ef1beb
|
3 |
+
size 87020976
|
summary_profitability.csv
CHANGED
@@ -1,131 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
0x07ffed9c3d33fa5711ab12cea242dbeb59b2cb79,6,3.0,0.0,0.17310532058113895,0.003462106411622777,16,0.16,0.24922074516983383,0.0,-0.0873466818229279,-0.5045869273670663,2.6666666666666665,0.02666666666666667,0.0726533181770721,0.41970586422857875
|
5 |
-
0x0d049dcaece0ecb6fc81a460da7bcc2a4785d6e5,509,249.0,330.0,42.76665318111589,0.8511913498119009,1266,12.66,41.25178766269511,40.762571305587734,-15.026056868232683,-0.35134984270566233,2.487229862475442,0.02487229862475442,-2.3660568682326826,-0.05532480781726081
|
6 |
-
0x0dd96dff8bcd9cc556e4def5e6baf6a66e6c8495,137,77.0,53.0,21.244198547280302,0.42488397094560604,396,3.96,22.889235948983846,12.777967760099445,-2.7398465692420646,-0.1289691660122816,2.8905109489051095,0.028905109489051093,1.2201534307579354,0.057434665188352815
|
7 |
-
0x0e49a2761cae218268daf6d125fdd6fad746bc8a,2,0.0,0.0,0.12,0.0024,4,0.04,0.0,0.0,-0.1624,-1.3533333333333333,2.0,0.02,-0.12239999999999998,-1.0199999999999998
|
8 |
-
0x0e84150ded38d87ab4d2571d178293749982e5ff,348,162.0,177.0,31.17870367926636,0.6235740735853271,570,5.7,27.57449883434355,27.398869957041356,-9.927778918508135,-0.318415384444288,1.6379310344827587,0.016379310344827588,-4.227778918508135,-0.13559829048696406
|
9 |
-
0x0f007356ccf9a4b2799c4074c0563dbfb3159486,6,2.0,0.0,0.36,0.0072,10,0.1,0.23321781320495394,0.0,-0.23398218679504607,-0.649950518875128,1.6666666666666667,0.016666666666666666,-0.13398218679504606,-0.37217274109735016
|
10 |
-
0x10ddea37aa2604359e917c5421889d73e71c1ebb,710,309.0,414.0,42.46,0.8422,2488,24.88,34.438286168429975,33.98288493920601,-33.743913831570026,-0.7947224171354221,3.5042253521126763,0.03504225352112676,-8.863913831570027,-0.20875915759703315
|
11 |
-
0x131d77cfc88a3d27a0ab147f81e65ad2b9f06fdc,142,76.0,83.0,7.8999999999999995,0.158,493,4.93,7.667506749301581,6.489435851071462,-5.320493250698419,-0.6734801583162556,3.471830985915493,0.03471830985915493,-0.39049325069841956,-0.049429525404863235
|
12 |
-
0x15f36dd420b53cb46c210f886c5d2c8ef0538f14,51,22.0,0.0,3.12,0.060599999999999994,548,5.4799999999999995,2.411214359190959,0.0,-6.249385640809042,-2.003008218208026,10.745098039215685,0.10745098039215685,-0.769385640809042,-0.24659796179776988
|
13 |
-
0x197a0a79d62af21c50813899b79947c7621281ad,445,178.0,232.0,36.42176584147949,0.7232940925648215,1284,12.84,26.154756781818666,24.08915139512629,-23.83030315222565,-0.6542874185711814,2.885393258426966,0.028853932584269663,-10.99030315222565,-0.30175096946313273
|
14 |
-
0x1bde46e6a3128fff5f0b94911bf6c447ad909215,500,225.0,246.0,57.698196020142596,1.1538639204028518,2350,23.5,55.19819998401545,43.854458705406124,-27.15385995653,-0.47061887250427226,4.7,0.047,-3.653859956529999,-0.06332710913967617
|
15 |
-
0x1de45bf8bca2844a3c216181c11dac3f9448475a,783,421.0,586.0,63.4977022891255,1.2680425358427865,3371,33.71,69.87640308572432,68.22366753085727,-28.599341739243965,-0.4503996319271829,4.305236270753512,0.043052362707535125,5.110658260756036,0.08048571958534126
|
16 |
-
0x1e94157ddb3eefc7404fd67351c580f6f6932a8e,1,1.0,0.0,0.236978,0.00473956,0,0.0,0.47258730763891155,0.0,0.23086974763891158,0.9742243906139455,0.0,0.0,0.23086974763891158,0.9742243906139455
|
17 |
-
0x1f03eed6caa2524ec89f5d7cd117258a9ac07513,13,7.0,0.0,2.6,0.052000000000000005,63,0.63,2.627006065793214,0.0,-0.654993934206786,-0.2519207439256869,4.846153846153846,0.04846153846153846,-0.024993934206785973,-0.009613051617994604
|
18 |
-
0x22335c348afa4eae4cc6d2158c1ac259aaaecdfe,309,131.0,147.0,23.64864839692515,0.47297296793850296,589,5.89,20.125446009826497,18.95431051896689,-9.886175355037157,-0.4180439908913602,1.9061488673139158,0.019061488673139157,-3.996175355037157,-0.16898113109740126
|
19 |
-
0x244aeca2ec979e5d250fb99e2aa2bbd264ad07ca,418,199.0,180.0,25.91,0.5179,1914,19.14,23.35800106821856,18.94251890681114,-22.20989893178144,-0.8571940923111323,4.578947368421052,0.045789473684210526,-3.069898931781438,-0.1184831698873577
|
20 |
-
0x27c8e5d91f87fa54219b4fee63228051a31c3590,413,189.0,180.0,26.38,0.5264,1718,17.18,22.665973252059995,17.89764417302902,-21.420426747940002,-0.811994948746778,4.159806295399516,0.04159806295399516,-4.240426747940003,-0.1607440010591358
|
21 |
-
0x2820e94958e3bc08562c3f2fae7924062ea9e1cb,4,1.0,0.0,0.39,0.0078,4,0.04,0.19504892057833234,0.0,-0.24275107942166768,-0.6224386651837632,1.0,0.01,-0.20275107942166767,-0.5198745626196607
|
22 |
-
0x2b28ee2438131c9131cd06c4bb37d73208ea8895,17,10.0,0.0,2.0260458504019256,0.040520917008038504,32,0.32,2.606445752447773,0.0,0.21987898503780867,0.1085261643976069,1.8823529411764706,0.018823529411764708,0.5398789850378087,0.26646928297832345
|
23 |
-
0x324267d9c6190f9bbcc126d10047eb9f761df540,207,99.0,80.0,15.602873355928859,0.3112404757401519,327,3.27,14.013055842553603,9.86862440170557,-5.171057989115407,-0.3314170326935636,1.5797101449275361,0.01579710144927536,-1.9010579891154067,-0.1218402499173675
|
24 |
-
0x32f47d021ffc0b8b883a8aef184556f68e993aba,967,422.0,538.0,80.51531126319652,1.6083872189239568,3113,31.13,66.33298125367949,63.19246985925961,-46.920717228440985,-0.5827552113046156,3.21923474663909,0.0321923474663909,-15.790717228440986,-0.19612067544299377
|
25 |
-
0x37cdc93194dc7f46f3cc377cf4350f56455a4f85,1299,554.0,744.0,193.39481336599584,3.861524479789556,4346,43.46,158.74544982929197,157.7682145240799,-81.97088801649345,-0.4238525666216558,3.3456505003849113,0.03345650500384911,-38.510888016493446,-0.19913092469347848
|
26 |
-
0x426ad67dde120ade455eed20c8a7917ff343ebf7,44,20.0,17.0,2.7521257747171983,0.055042515494343955,238,2.38,3.5257718204426656,2.0075496048321795,-1.6613964697688763,-0.6036775226741218,5.409090909090909,0.054090909090909085,0.7186035302311236,0.2611085353847847
|
27 |
-
0x43e9941492628384ac38fbd38e2c45013d8783df,63,22.0,0.0,3.78,0.07379999999999999,575,5.75,2.213418645522343,0.0,-7.390381354477657,-1.9551273424544067,9.126984126984127,0.09126984126984126,-1.6403813544776567,-0.4339633212903854
|
28 |
-
0x440c3738af2a029726f2ce1be93f9e536d23d8a6,13,4.0,0.0,0.72,0.0144,13,0.13,0.41596120169531176,0.0,-0.44843879830468825,-0.622831664312067,1.0,0.01,-0.31843879830468824,-0.44227610875651147
|
29 |
-
0x44d97681a1d4d86d8ddb7d960b063e22fd9db490,724,324.0,370.0,52.003848582577,1.03155587825154,21658,216.58,46.689947953000534,42.519057833014344,-222.92545650782802,-4.286710745145031,29.914364640883978,0.2991436464088398,-6.345456507828004,-0.12201897899444966
|
30 |
-
0x48fb5ef17b634b19846e016fec797e66cf5a5631,24,7.0,0.0,1.44,0.0254,24,0.24,0.5892699137027375,0.0,-1.1161300862972625,-0.7750903377064323,1.0,0.01,-0.8761300862972625,-0.6084236710397657
|
31 |
-
0x4c9c5b55812ace79661804475624b75282865c94,9,4.0,4.0,0.16898906004121308,0.003379781200824258,10,0.1,0.17245325334097536,0.17245325334097536,-0.099915587901062,-0.5912547704371784,1.1111111111111112,0.011111111111111112,8.441209893800261e-05,0.0004995122105384583
|
32 |
-
0x4ecc9626b80a623e7bb2545d5cc1082ace765d03,453,216.0,306.0,26.939109464926688,0.5383821892985337,1125,11.25,28.78744371960279,28.78744371960279,-9.940047934622433,-0.3689820536779011,2.4834437086092715,0.024834437086092714,1.3099520653775674,0.04862640567547552
|
33 |
-
0x576380386858e0f21ae6cd0272be3d8caf6476fc,567,241.0,334.0,112.72384013091035,2.252568363536409,1354,13.540000000000001,105.12543255416934,103.59051343385454,-23.390975940277425,-0.20750691169776175,2.3880070546737215,0.023880070546737214,-9.850975940277424,-0.08739035086843318
|
34 |
-
0x57c4d31a91dedd15c48030f9334e484e6f4d6fb1,87,30.0,0.0,20.32,0.4026,168,1.68,17.150334004795933,0.0,-5.252265995204066,-0.2584776572442946,1.9310344827586208,0.019310344827586205,-3.5722659952040665,-0.1758004918899639
|
35 |
-
0x57cc4826e56ce2cc90a2ed4bce62de454bbac6a9,102,36.0,0.0,6.2,0.11599999999999999,1544,15.44,3.875953868024938,0.0,-17.88004613197506,-2.883878408383074,15.137254901960784,0.15137254901960784,-2.440046131975061,-0.39355582773791303
|
36 |
-
0x5e6a68166f495ab1c302d12db39885b28ad7f9c7,335,136.0,103.0,20.28,0.4038,1669,16.69,15.925197119491532,11.310351856524584,-21.448602880508467,-1.0576234161986422,4.982089552238806,0.04982089552238806,-4.758602880508466,-0.23464511245110778
|
37 |
-
0x5ec969393e982fd19ccee2035fd98928c168b964,16,7.0,1.0,1.156985838892075,0.023139716777841497,24,0.24,1.3848338254040746,0.16345363550629105,-0.03529173026584187,-0.03050316527610838,1.5,0.015,0.20470826973415812,0.17693239005430345
|
38 |
-
0x5ffb258f89a0b66264c2597fd8c9567526722275,2,2.0,2.0,2.0,0.04,0,0.0,3.7652215619661904,3.7652215619661904,1.7252215619661906,0.8626107809830953,0.0,0.0,1.7252215619661906,0.8626107809830953
|
39 |
-
0x61f5c7fa710bae60ab917fad0043f8efb4f8c3be,512,206.0,248.0,43.33728487480052,0.8667456974960102,2200,22.0,34.12276941960349,26.877599192011527,-32.08126115269303,-0.740269291105208,4.296875,0.04296875,-10.081261152693031,-0.23262327535786667
|
40 |
-
0x6200bf2a60f0174a3def2a82617153cbe6641f52,172,57.0,49.0,15.798296486858904,0.315965929737178,201,2.0100000000000002,10.718866447830411,9.596597276201262,-7.405395968765671,-0.4687464863648757,1.1686046511627908,0.011686046511627909,-5.395395968765671,-0.34151757901578733
|
41 |
-
0x625cf416a9f525d9480cafb9b9ac83401a2b2b33,1719,784.0,1054.0,223.79731004522532,4.462837707831318,9574,95.74,222.0122270913184,216.24312281437705,-101.98792066173823,-0.4557155787132935,5.5695171611401975,0.05569517161140197,-6.247920661738235,-0.02791776478669759
|
42 |
-
0x659d2ae397b01fda11046448d686d074c3f42b9b,236,103.0,95.0,17.944212107175098,0.35730835927422155,339,3.39,13.68709223736142,10.687412542836986,-8.0044282290879,-0.4460729833820501,1.4364406779661016,0.014364406779661018,-4.614428229087899,-0.2571541286698675
|
43 |
-
0x65de5aa270d7b07986f0ce2814c7e644d39f9412,36,17.0,0.0,2.12,0.04239999999999999,55,0.55,1.8736486510113175,0.0,-0.8387513489886824,-0.3956374287682464,1.5277777777777777,0.015277777777777779,-0.2887513489886824,-0.13620346650409546
|
44 |
-
0x68eb2f25405a3dfaae99c747cee45f403b6557e5,59,34.0,22.0,23.529297143239233,0.47058594286478467,102,1.02,28.280666273536276,11.379267061793394,3.260783187432257,0.1385839605654855,1.728813559322034,0.01728813559322034,4.280783187432257,0.18193417174223886
|
45 |
-
0x69908fec34b34f8415212f841b9744fa271781e1,57,34.0,23.0,15.358409410496416,0.30716818820992825,148,1.48,21.996343947855625,11.136707569326811,4.850766349149281,0.3158378071256595,2.5964912280701755,0.025964912280701753,6.330766349149281,0.4122019526854544
|
46 |
-
0x6cbd1a957cbf3a84187113f58c0c026c268c7294,226,93.0,91.0,18.365502370786178,0.3673100474157235,250,2.5,15.776660672991994,15.379041433674413,-5.456151745209906,-0.29708698597262184,1.1061946902654867,0.011061946902654867,-2.9561517452099064,-0.16096220432892855
|
47 |
-
0x6d6e0aabc7814b88962db050c00487ffc8894d43,142,94.0,87.0,177.59627542637597,3.545925508527519,329,3.29,223.94473167707488,178.72405905389962,39.51253074217139,0.22248513178167212,2.316901408450704,0.023169014084507042,42.80253074217139,0.24101029506058275
|
48 |
-
0x6d8a0e329c5d474f058e632d1dd2d362f1763d7b,429,195.0,173.0,26.48,0.5284,2737,27.37,22.589160388736648,18.504135618885535,-31.78923961126335,-1.200499985319613,6.37995337995338,0.0637995337995338,-4.41923961126335,-0.16688971341628966
|
49 |
-
0x6f99ccc54f239a9c0e7fe501e99c16b89785b96b,467,196.0,272.0,38.3037384570474,0.7597059504367853,1441,14.41,31.797337176932277,31.397552529967708,-21.67610723055191,-0.5659005648980924,3.0856531049250537,0.030856531049250537,-7.26610723055191,-0.1896970771847738
|
50 |
-
0x716684617d61ec5e6f990e9495ed4cd586efde77,221,102.0,116.0,16.14114323654835,0.32061937159401693,343,3.43,17.108903698691414,17.108903698691414,-2.7828589094509524,-0.17240779470624684,1.5520361990950227,0.015520361990950226,0.6471410905490478,0.0400926428236959
|
51 |
-
0x78ab82437e8bea64bdade3bc16daa86fd3d9e6c0,6,1.0,0.0,0.33999999999999997,0.0068,6,0.06,0.07884085459320514,0.0,-0.3279591454067948,-0.9645857217846907,1.0,0.01,-0.26795914540679483,-0.7881151335493967
|
52 |
-
0x7a980512664351f785536498b27cfe3410bf0775,253,110.0,59.0,19.48,0.3868,671,6.71,15.813134221698359,7.761018671154535,-10.763665778301641,-0.5525495779415627,2.652173913043478,0.026521739130434784,-4.053665778301641,-0.2080937257855052
|
53 |
-
0x7bce37e71d9800a0723f84b5940572714c9dd6fe,124,53.0,6.0,7.22,0.1444,460,4.6,5.4283742053248245,0.47614391808517936,-6.536025794675176,-0.9052667305644289,3.7096774193548385,0.037096774193548385,-1.9360257946751762,-0.26814761699102163
|
54 |
-
0x7d03fcaaad54f0a067e2d9d438abc9783489d9bb,70,30.0,0.0,4.2,0.0802,134,1.34,3.087102730572653,0.0,-2.5330972694273473,-0.6031183974827017,1.9142857142857144,0.019142857142857145,-1.1930972694273472,-0.28407077843508266
|
55 |
-
0x7d3a0da18e14ccb63375cdc250e8a8399997816f,13,8.0,0.0,0.241,0.00482,0,0.0,0.24914084485962038,0.0,0.0033208448596203782,0.01377943925153684,0.0,0.0,0.0033208448596203782,0.01377943925153684
|
56 |
-
0x7ed78745e8ded49158b90cf0b4d72c1e3cc6b7ed,22,11.0,0.0,7.198329394506154,0.14396658789012307,34,0.34,10.382814948350672,0.0,2.7005189659543962,0.37515912622940856,1.5454545454545454,0.015454545454545455,3.040518965954396,0.42239230789785115
|
57 |
-
0x80f49ec29033d11434e4f1ed7574ef50fa37b804,12,5.0,0.0,0.7,0.013999999999999999,12,0.12,0.5469753181104209,0.0,-0.28702468188957914,-0.4100352598422559,1.0,0.01,-0.16702468188957914,-0.23860668841368451
|
58 |
-
0x85f139e3c10bb68fb743cf2ed5130683252eddbe,13,4.0,0.0,0.7999999999999999,0.016,16,0.16,0.4597549935741434,0.0,-0.5162450064258566,-0.6453062580323208,1.2307692307692308,0.012307692307692308,-0.35624500642585655,-0.4453062580323207
|
59 |
-
0x86e14d2f91776b6c36f1e278cc5b9fe1dd94a1ba,31,12.0,10.0,1.94,0.0388,38,0.38,1.4416811362920205,1.1979154372119154,-0.9171188637079796,-0.47274168232370084,1.2258064516129032,0.012258064516129033,-0.5371188637079796,-0.276865393663907
|
60 |
-
0x87022d0dd9c00fe99335027c720d27925ce5df22,706,218.0,342.0,53.979638672390756,1.079592773447815,3961,39.61,31.480940527465023,30.037119669814196,-63.18829091837355,-1.1705949219458707,5.610481586402266,0.05610481586402266,-23.578290918373554,-0.4367997174170279
|
61 |
-
0x89427157dd4101a506fba0f23f653d2ca90c43c5,302,156.0,95.0,18.94,0.37879999999999997,991,9.91,18.121204865034414,11.209303621294833,-11.107595134965585,-0.5864622563339802,3.281456953642384,0.032814569536423845,-1.1975951349655851,-0.0632309997341914
|
62 |
-
0x8dd0f0f64e575a356545d9ed096122a1887e64bf,554,255.0,385.0,40.67857131607321,0.8135714263214641,1575,15.75,41.411304151417994,41.096131514562344,-15.830838590976684,-0.38916899189921866,2.8429602888086642,0.028429602888086644,-0.08083859097668444,-0.001987252461463486
|
63 |
-
0x8f1b505135b4baf646d45430ecd91e214040a7bb,19,9.0,0.0,1.16,0.0232,19,0.19,1.0450938230917104,0.0,-0.3281061769082897,-0.2828501525071463,1.0,0.01,-0.1381061769082897,-0.11905704905887043
|
64 |
-
0x902a59ffe708d36f4498c8c9df51802250c5111c,713,333.0,483.0,64.75145621455718,1.2889016099131834,1832,18.32,57.609933162329774,57.609933162329774,-26.750424662140592,-0.41312468052458506,2.5694249649368865,0.025694249649368863,-8.430424662140592,-0.13019668058438652
|
65 |
-
0x93be3869bf173034d45e5eb294c5785855b6631f,40,19.0,15.0,6.203856525430098,0.12407713050860193,62,0.62,7.771735545899522,6.624743707773776,0.8238018899608222,0.13278867533186706,1.55,0.0155,1.443801889960822,0.23272651197566613
|
66 |
-
0x9411898847c4e91344c44e017d446f58ad05c1af,27,11.0,0.0,2.82,0.0564,374,3.74,2.7031475549619017,0.0,-3.9132524450380983,-1.3876781719993256,13.851851851851851,0.1385185185185185,-0.1732524450380981,-0.06143703724755253
|
67 |
-
0x9694c0fdb79a37d048ea19deb15e051482a690c4,406,164.0,195.0,36.35040167780915,0.7247752346709715,930,9.3,32.171735704975504,32.171735704975504,-14.20344120750462,-0.39073684338886966,2.29064039408867,0.0229064039408867,-4.903441207504619,-0.1348937282995149
|
68 |
-
0x970b4b61e4cd87805c96408a84129e08f7281c91,595,226.0,292.0,72.12452612374028,1.4424905224748055,2068,20.68,57.41127471321702,56.1048410908447,-36.83574193299807,-0.5107242142541208,3.4756302521008404,0.034756302521008406,-16.15574193299807,-0.22399789366075704
|
69 |
-
0x972bf3148722087a11eafd6649201d137a326cd7,9,6.0,0.0,0.54,0.010799999999999999,21,0.21000000000000002,0.697646613768064,0.0,-0.06315338623193593,-0.11695071524432579,2.3333333333333335,0.023333333333333334,0.14684661376806407,0.2719381736445631
|
70 |
-
0x98973c9c66a79b6cc7ed655d830d1ad84067c5e5,621,303.0,380.0,54.2507445719125,1.0850148914382498,1419,14.19,55.220747019037205,53.66834227945647,-14.305012444313538,-0.26368324632579776,2.285024154589372,0.02285024154589372,-0.11501244431353896,-0.002120015959616615
|
71 |
-
0x9a03c32625324451324777268ce29287b158538e,1,1.0,0.0,0.002,4e-05,0,0.0,0.003958087435689176,0.0,0.0019180874356891755,0.9590437178445878,0.0,0.0,0.0019180874356891755,0.9590437178445878
|
72 |
-
0x9c0b8a6e2caf043f1866b958e1a80a295fd119fb,1348,660.0,675.0,117.2149010357043,2.3388980207140855,8207,82.07000000000001,122.93783146995571,99.36307044649172,-78.68596758646268,-0.6712966260364329,6.088278931750742,0.06088278931750742,3.3840324135373265,0.028870326073188696
|
73 |
-
0x9c38651f44c4290e32d6aa2fae948c7cfa28a36e,54,25.0,6.0,4.32,0.0864,424,4.24,3.696873817549134,0.846029696035919,-4.9495261824508665,-1.1457236533451078,7.851851851851852,0.07851851851851853,-0.7095261824508663,-0.16424217186362644
|
74 |
-
0xa0748aa2cc9ac8e5c7a813171590b92140aee491,50,28.0,0.0,3.881542123406444,0.07763084246812886,66,0.66,4.487299391600191,0.0,-0.13187357427438193,-0.03397453127692702,1.32,0.0132,0.5281264257256181,0.1360609801297568
|
75 |
-
0xa7314a168445a32fe43da3759d5861630f3b5d91,2358,1103.0,1526.0,130.57735468742118,2.598226750925765,20003,200.03,119.68143131049331,116.59983333104155,-213.52415012785363,-1.6352310907124152,8.48303647158609,0.0848303647158609,-13.49415012785363,-0.10334219252761101
|
76 |
-
0xabcd4cabcc15fa003b26f226c1654741820e343c,1,0.0,0.0,0.55236978022,0.0110473956044,4,0.04,0.0,0.0,-0.6034171758244,-1.0924152577356216,4.0,0.04,-0.5634171758244,-1.0199999999999998
|
77 |
-
0xac414aa6b522ccd2ac26151c1668f03c9d8e09b3,2,1.0,0.0,2.0,0.04,0,0.0,1.8308537492608645,0.0,-0.2091462507391355,-0.10457312536956775,0.0,0.0,-0.2091462507391355,-0.10457312536956775
|
78 |
-
0xb0d60608aaaa475525a4ee330349895a82356d62,3,2.0,0.0,0.22,0.0044,3,0.03,0.3125571097565215,0.0,0.05815710975652148,0.26435049889327944,1.0,0.01,0.08815710975652148,0.40071413525691585
|
79 |
-
0xb2a4c72a9a40db30b48ec241cb6bd32948c7f9f4,9,3.0,0.0,0.58,0.0116,25,0.25,0.363723005693572,0.0,-0.477876994306428,-0.8239258522524621,2.7777777777777777,0.027777777777777776,-0.227876994306428,-0.3928913694938414
|
80 |
-
0xb2b30b71bf8166fa3a3b9744a48765d43eb93d53,251,126.0,127.0,28.891700057269418,0.5778340011453883,1054,10.540000000000001,31.232464845902346,24.380577712524353,-8.777069212512464,-0.3037920646799762,4.199203187250996,0.041992031872509966,1.7629307874875373,0.06101858956008259
|
81 |
-
0xb3b344edde7396ff386c0b02a70842a5fd8d1e5e,38,16.0,0.0,2.939307174304723,0.05878614348609444,90,0.9,2.4203804586575304,0.0,-1.4777128591332866,-0.5027418951143926,2.3684210526315788,0.02368421052631579,-0.5777128591332866,-0.196547289845588
|
82 |
-
0xb40e6d923a9c30c71ca7339d1c76de2cb69f144b,114,57.0,37.0,7.08,0.1416,128,1.28,6.86641543709549,4.374170840515095,-1.6351845629045099,-0.23095827159668217,1.1228070175438596,0.011228070175438597,-0.35518456290450984,-0.05016731114470478
|
83 |
-
0xb6062841b14e92c3b0f4709a5a4cbc7d841ebe2d,60,32.0,40.0,3.6599999999999997,0.0732,407,4.07,3.715670678308474,3.6027872660563234,-4.087529321691526,-1.1168112900796519,6.783333333333333,0.06783333333333334,-0.017529321691525546,-0.004789432156154521
|
84 |
-
0xb866339cd8ad051be97a5659871743962dd93fff,37,14.0,0.0,12.34,0.2434,37,0.37,11.525900569160438,0.0,-1.4274994308395623,-0.11568066700482676,1.0,0.01,-1.0574994308395622,-0.08569687446025626
|
85 |
-
0xba33c7f59ccc650032086858fce27896089df2fc,1,1.0,0.0,0.04,0.0008,1,0.01,0.07824693601083751,0.0,0.027446936010837523,0.6861734002709381,1.0,0.01,0.037446936010837525,0.9361734002709381
|
86 |
-
0xbaaed66b70f88ca8d50219ba8bf3cbfa8fbee4a7,1,1.0,0.0,0.06,0.0012,4,0.04,0.11832144210913825,0.0,0.01712144210913824,0.28535736848563736,4.0,0.04,0.05712144210913824,0.952024035152304
|
87 |
-
0xbabed7f63ff6c00a9476ddd99372c60138e69073,4,2.0,0.0,0.4,0.008,4,0.04,0.49602875344085817,0.0,0.048028753440858135,0.12007188360214534,1.0,0.01,0.08802875344085814,0.22007188360214536
|
88 |
-
0xbb30b2e1137b6a0a7f065e341b92677f71e2361c,1,0.0,0.0,0.04,0.0008,2,0.02,0.0,0.0,-0.0608,-1.52,2.0,0.02,-0.0408,-1.02
|
89 |
-
0xbd5aa77b29f5669aabb2efee39a5df94c40a079a,43,21.0,0.0,18.02,0.3604,78,0.78,16.37967252399068,0.0,-2.7807274760093197,-0.15431340044446837,1.813953488372093,0.018139534883720932,-2.0007274760093194,-0.11102816182071695
|
90 |
-
0xbf83b5c3f4bac83ec6ea842cf60d20abeaa3592b,43,14.0,0.0,2.55,0.051,68,0.68,1.6047625328344122,0.0,-1.6762374671655877,-0.6573480263394462,1.5813953488372092,0.015813953488372095,-0.9962374671655877,-0.3906813596727795
|
91 |
-
0xc2cec5bd2e585ff0ec1998ef368065b71dc26257,2,1.0,0.0,0.8,0.016,0,0.0,0.9434045669539883,0.0,0.12740456695398833,0.1592557086924854,0.0,0.0,0.12740456695398833,0.1592557086924854
|
92 |
-
0xc2f5b26090ef3d50f6954fc0118e86a76c3d2de7,2,2.0,0.0,0.12,0.0024,8,0.08,0.2279193803213406,0.0,0.025519380321340573,0.21266150267783812,4.0,0.04,0.10551938032134058,0.8793281693445049
|
93 |
-
0xc598397ce2b8bdf93071c0446d1eedc2141f01d0,900,359.0,506.0,106.73379173342522,2.1327643248599073,3501,35.01,92.81772363329995,90.96167271636249,-51.05883242498518,-0.4783755134691366,3.89,0.0389,-16.04883242498518,-0.15036318081033054
|
94 |
-
0xc63089d8a68883b75ad99009724d78c4a32d11e1,320,137.0,98.0,21.259999999999998,0.42519999999999997,724,7.24,19.051649394242347,13.381573897540564,-9.873550605757654,-0.46441912538841273,2.2625,0.022625,-2.6335506057576534,-0.12387349980045408
|
95 |
-
0xc6cfcc8f88e660a0c93332520cf204f62f9b5a87,2,0.0,0.0,0.12,0.0024,2,0.02,0.0,0.0,-0.1424,-1.1866666666666668,1.0,0.01,-0.1224,-1.02
|
96 |
-
0xc75845cc7752dfe787b69096ac2c0c69fde7cc74,25,13.0,10.0,0.8349840236552157,0.016699680473104307,58,0.58,0.8196135651620855,0.5742036640390805,-0.6120701389662345,-0.7330321558571191,2.32,0.0232,-0.03207013896623456,-0.03840808693062739
|
97 |
-
0xc79bf3f6370e8a8002a3093c379752f395a3c291,5,3.0,0.0,0.44,0.0088,12,0.12000000000000001,0.48895958799044614,0.0,-0.07984041200955391,-0.18145548183989527,2.4,0.024,0.0401595879904461,0.0912717908873775
|
98 |
-
0xc9881a80fbfc01bd2a5ffa598e02d556d4307ed5,770,334.0,357.0,68.03,1.3466,4838,48.38,61.77382359083681,55.48496370214474,-55.98277640916319,-0.822913073778674,6.283116883116883,0.06283116883116883,-7.602776409163191,-0.11175623120921932
|
99 |
-
0xca4176d8b70f5a3bd80c02c0a64376f65be9c7c4,119,57.0,45.0,7.359999999999999,0.1472,126,1.26,6.491608782172349,5.039575505762622,-2.27559121782765,-0.30918358937875684,1.0588235294117647,0.010588235294117647,-1.01559121782765,-0.13798793720484376
|
100 |
-
0xca74e5dc5a8941b41858d597125071284572e9c6,95,43.0,49.0,11.938910371412188,0.23877820742824374,167,1.67,10.05280277829441,10.05280277829441,-3.794885800546022,-0.3178586388949619,1.7578947368421052,0.01757894736842105,-2.1248858005460223,-0.17797987709448573
|
101 |
-
0xcc986773cf2078a2a9945f1a1dcfa43ee306b351,862,382.0,510.0,63.42488509435114,1.2681977018870227,2765,27.65,55.88848930240974,54.06804890906509,-36.454593493828426,-0.5747679864078337,3.2076566125290022,0.03207656612529002,-8.804593493828428,-0.1388192265658925
|
102 |
-
0xcf291f8448988f6ce737b5aa8b6936ac41d383b6,21,6.0,2.0,1.26,0.025199999999999997,50,0.5,0.7013271205062471,0.27254309276723354,-1.0838728794937529,-0.860216571026788,2.380952380952381,0.023809523809523808,-0.5838728794937529,-0.4633911742013912
|
103 |
-
0xd162f96573f7500524b448c7e5e07a7501cce7e4,275,117.0,64.0,16.86,0.32839999999999997,1137,11.37,12.670141491496254,5.96913600767045,-15.888258508503744,-0.9423640870998663,4.134545454545455,0.04134545454545454,-4.518258508503745,-0.267986862900578
|
104 |
-
0xd254eea0e55674f418611a82d5dbc035efc89785,207,99.0,74.0,15.855570344921034,0.31711140689842066,313,3.13,14.271567221854903,9.557587870963447,-5.031114529964552,-0.3173089595970386,1.5120772946859904,0.015120772946859902,-1.901114529964552,-0.11990199586693077
|
105 |
-
0xd4026606d3d3046722ebcfdc594eb7513a2ba5e3,8,3.0,0.0,0.5,0.009999999999999998,8,0.08,0.3907026795981461,0.0,-0.1992973204018539,-0.3985946408037078,1.0,0.01,-0.11929732040185391,-0.23859464080370782
|
106 |
-
0xd646394f16215d013a1681ada64afbcd0ef619a0,154,70.0,57.0,9.28,0.1856,226,2.2600000000000002,7.5233163075123315,5.035145672913762,-4.2022836924876685,-0.4528322944491022,1.4675324675324675,0.014675324675324676,-1.9422836924876683,-0.2092978116904815
|
107 |
-
0xdacbe9368b329af4244727acfe20514d64d129ac,518,217.0,301.0,44.1105001558539,0.8783869692752594,1515,15.15,33.76772629246949,33.76772629246949,-26.371160832659672,-0.5978431606869903,2.9247104247104247,0.029247104247104246,-11.221160832659672,-0.2543875220868588
|
108 |
-
0xde6bf4b2b15f5a69b65d4b2459c3362cce48ce42,3,1.0,0.0,0.18,0.0036,3,0.03,0.11755714549268102,0.0,-0.09604285450731898,-0.5335714139295499,1.0,0.01,-0.06604285450731898,-0.3669047472628832
|
109 |
-
0xdf5d21397543eb0fb47afc616073cd922e020635,914,409.0,389.0,57.3694640557069,1.1234808701201593,11826,118.26,50.66785436458541,38.596660400177356,-126.08509056124164,-2.1977735479419938,12.938730853391684,0.12938730853391686,-7.8250905612416375,-0.1363981813329007
|
110 |
-
0xe31fe9ad4ff42cfb235cbe6639ee7d9a6ad654e6,9,7.0,0.0,0.32,0.0063999999999999994,8,0.08,0.40742223628967916,0.0,0.001022236289679141,0.003194488405247316,0.8888888888888888,0.008888888888888889,0.08102223628967914,0.25319448840524733
|
111 |
-
0xe41e4117e7f55c245fdf25b70086d9be1edb8216,34,19.0,9.0,4.682687124332405,0.0936537424866481,53,0.53,4.733707580904102,0.9489998912680002,-0.572633285914952,-0.1222873257833963,1.5588235294117647,0.015588235294117648,-0.04263328591495197,-0.00910444895910701
|
112 |
-
0xe6f2206f28d5d481eb6c411e6d65eec4afb9b862,8,5.0,0.0,0.48,0.0096,8,0.08,0.5846231275366699,0.0,0.015023127536669949,0.031298182368062394,1.0,0.01,0.09502312753666994,0.19796484903472905
|
113 |
-
0xe711f95807145121e027df264612098ddf202fd7,326,125.0,136.0,26.7940867472861,0.535881734945722,544,5.44,22.044530515236975,22.044530515236975,-10.725437966994848,-0.4002912309777156,1.6687116564417177,0.016687116564417178,-5.285437966994848,-0.1972613590769312
|
114 |
-
0xe7715def604bccfb93f34ccaf3610ed6ee9c6741,395,169.0,223.0,72.89864970665475,1.455742780472764,1449,14.49,85.24837134990675,84.4362254405684,-3.596021137220769,-0.04932905001246541,3.668354430379747,0.03668354430379747,10.893978862779232,0.14944006379565006
|
115 |
-
0xe84605f215126abdafb0b5a47de2d513e80aba68,769,383.0,483.0,53.80661760216288,1.073320842232291,2280,22.8,52.11432248143652,47.92678102528325,-25.565615962958653,-0.475138878864056,2.964889466840052,0.02964889466840052,-2.765615962958652,-0.051399178878091784
|
116 |
-
0xea6c5047d44388964124c69a8a9926fffdee6af7,13,4.0,3.0,0.78,0.0156,13,0.13,0.4255042975046315,0.30864111318141413,-0.5000957024953685,-0.6411483365325237,1.0,0.01,-0.3700957024953685,-0.47448166986585705
|
117 |
-
0xeb3be1f63f453edeef10c770232dcfd85ee6bd19,4,1.0,0.0,0.24,0.0048,4,0.04,0.1184726843224399,0.0,-0.1663273156775601,-0.6930304819898337,1.0,0.01,-0.1263273156775601,-0.526363815323167
|
118 |
-
0xec97bdf61fcb901033a3b8fcbcde77a372927b61,2888,1341.0,1958.0,243.2781995796075,4.853294495091604,16939,169.39000000000001,229.54202463890203,229.54202463890203,-187.97946943579706,-0.7726934421605864,5.865304709141275,0.058653047091412745,-18.589469435797042,-0.07641239316930264
|
119 |
-
0xecf3ddd00b7baa6333fe35e26c5ccbd0a4e8214d,5,4.0,0.0,29.6,0.592,0,0.0,38.50272161451244,0.0,8.31072161451244,0.28076762211190676,0.0,0.0,8.31072161451244,0.28076762211190676
|
120 |
-
0xed86737d98bd390770d946907f639e518671790a,3,2.0,0.0,0.19,0.0038,0,0.0,0.16663059444252543,0.0,-0.027169405557474574,-0.14299687135512934,0.0,0.0,-0.027169405557474574,-0.14299687135512934
|
121 |
-
0xf080a724b973c67170df6bf588190346b122c3b7,272,131.0,48.0,16.5,0.32999999999999996,782,7.82,15.149010875540522,3.913181428325511,-9.500989124459478,-0.5758175226945138,2.875,0.02875,-1.6809891244594777,-0.10187812875511985
|
122 |
-
0xf21d9a4e2ecb9257523d87656cbab2332c270628,340,163.0,91.0,20.15,0.40299999999999997,758,7.58,18.135398104894584,8.800041492136387,-9.997601895105415,-0.49615890298289905,2.2294117647058824,0.022294117647058825,-2.417601895105415,-0.11998024293327123
|
123 |
-
0xf29cccfa44b5e129d9ce04635f7177bd84e0847d,36,14.0,7.0,1.23,0.024599999999999997,68,0.6799999999999999,0.8654693831163107,0.4001375291244711,-1.0691306168836894,-0.8692118836452759,1.8888888888888888,0.018888888888888886,-0.38913061688368944,-0.3163663551899914
|
124 |
-
0xf56f2b0770c642524b545b2a060c00c38273b0dd,27,9.0,9.0,1.68,0.0336,27,0.27,0.9842719676973612,0.9842719676973612,-0.9993280323026388,-0.5948381144658564,1.0,0.01,-0.7293280323026388,-0.4341238287515707
|
125 |
-
0xf5db877894a8597452fa185d4f73c69ba8746ed7,132,59.0,0.0,8.66,0.1732,271,2.71,7.365333987179727,0.0,-4.177866012820273,-0.4824325649907936,2.053030303030303,0.02053030303030303,-1.4678660128202727,-0.16949953958663658
|
126 |
-
0xf660f0b01569b9e2a81d6b57c224c869f2e0ca63,49,23.0,22.0,25.82612920326901,0.5165225840653802,144,1.44,22.80070743797798,21.418104686293916,-4.981944349356409,-0.19290325352843843,2.938775510204082,0.029387755102040815,-3.541944349356409,-0.13714576897989336
|
127 |
-
0xf785587edf543dcbe3af53444a17f0f1c1dc0ab1,48,26.0,11.0,16.228042532795207,0.3245608506559041,280,2.8,19.832754436928877,5.261927978506468,0.4801510534777634,0.029587736937922576,5.833333333333333,0.05833333333333333,3.280151053477763,0.20212857138184812
|
128 |
-
0xf8980526b117bce7a64b948255db22999c7af80f,5,0.0,0.0,0.27999999999999997,0.0056,5,0.05,0.0,0.0,-0.3356,-1.1985714285714286,1.0,0.01,-0.2856,-1.0200000000000002
|
129 |
-
0xf8a323e669edabca3952e3bf7f18ade953d7e9b9,438,200.0,273.0,34.64245352907898,0.687376784405273,1492,14.92,33.213924698864226,33.213924698864226,-17.035905614620024,-0.49176382961212706,3.406392694063927,0.03406392694063927,-2.115905614620024,-0.06107839945123767
|
130 |
-
0xfb81fbe03043e03dab2ca64862581cd3d34ea7fe,379,364.0,359.0,1560.54,31.210800000000003,0,0.0,2235.017582706753,2179.513199783264,643.2667827067526,0.4122078144147235,0.0,0.0,643.2667827067526,0.4122078144147235
|
131 |
-
0xfd59da9bba5722cc59dfc5fb0dac23dd6262addf,23,7.0,0.0,1.4,0.027999999999999997,23,0.23,0.7802794936003471,0.0,-0.8777205063996529,-0.626943218856895,1.0,0.01,-0.647720506399653,-0.4626575045711807
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:afa5de4ae7d284cf42e45dfc49d45531f2b5b71eecc4fa0d03337330b89c3d47
|
3 |
+
size 33827
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:376ea73f5fd643e8c545c08055feed67818eeba644fc7ce731e67b01fa7dbc9e
|
3 |
+
size 750214066
|
tools.py
DELETED
@@ -1,833 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
# ------------------------------------------------------------------------------
|
3 |
-
#
|
4 |
-
# Copyright 2023 Valory AG
|
5 |
-
#
|
6 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7 |
-
# you may not use this file except in compliance with the License.
|
8 |
-
# You may obtain a copy of the License at
|
9 |
-
#
|
10 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11 |
-
#
|
12 |
-
# Unless required by applicable law or agreed to in writing, software
|
13 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15 |
-
# See the License for the specific language governing permissions and
|
16 |
-
# limitations under the License.
|
17 |
-
#
|
18 |
-
# ------------------------------------------------------------------------------
|
19 |
-
|
20 |
-
import json
|
21 |
-
import os.path
|
22 |
-
import re
|
23 |
-
import sys
|
24 |
-
import time
|
25 |
-
import random
|
26 |
-
from dataclasses import dataclass
|
27 |
-
from enum import Enum
|
28 |
-
from io import StringIO
|
29 |
-
from typing import (
|
30 |
-
Optional,
|
31 |
-
List,
|
32 |
-
Dict,
|
33 |
-
Any,
|
34 |
-
Union,
|
35 |
-
Callable,
|
36 |
-
Tuple,
|
37 |
-
)
|
38 |
-
|
39 |
-
import pandas as pd
|
40 |
-
import requests
|
41 |
-
from json.decoder import JSONDecodeError
|
42 |
-
from eth_typing import ChecksumAddress
|
43 |
-
from eth_utils import to_checksum_address
|
44 |
-
from requests.adapters import HTTPAdapter
|
45 |
-
from requests.exceptions import (
|
46 |
-
ReadTimeout as RequestsReadTimeoutError,
|
47 |
-
HTTPError as RequestsHTTPError,
|
48 |
-
)
|
49 |
-
from tqdm import tqdm
|
50 |
-
from urllib3 import Retry
|
51 |
-
from urllib3.exceptions import (
|
52 |
-
ReadTimeoutError as Urllib3ReadTimeoutError,
|
53 |
-
HTTPError as Urllib3HTTPError,
|
54 |
-
)
|
55 |
-
from web3 import Web3, HTTPProvider
|
56 |
-
from web3.exceptions import MismatchedABI
|
57 |
-
from web3.types import BlockParams
|
58 |
-
from concurrent.futures import ThreadPoolExecutor, as_completed
|
59 |
-
|
60 |
-
CONTRACTS_PATH = "contracts"
|
61 |
-
MECH_TO_INFO = {
|
62 |
-
# this block number is when the creator had its first tx ever, and after this mech's creation
|
63 |
-
"0xff82123dfb52ab75c417195c5fdb87630145ae81": ("old_mech_abi.json", 28911547),
|
64 |
-
# this block number is when this mech was created
|
65 |
-
"0x77af31de935740567cf4ff1986d04b2c964a786a": ("new_mech_abi.json", 30776879),
|
66 |
-
}
|
67 |
-
# optionally set the latest block to stop searching for the delivered events
|
68 |
-
LATEST_BLOCK: Optional[int] = None
|
69 |
-
LATEST_BLOCK_NAME: BlockParams = "latest"
|
70 |
-
BLOCK_DATA_NUMBER = "number"
|
71 |
-
BLOCKS_CHUNK_SIZE = 10_000
|
72 |
-
REDUCE_FACTOR = 0.25
|
73 |
-
EVENT_ARGUMENTS = "args"
|
74 |
-
DATA = "data"
|
75 |
-
REQUEST_ID = "requestId"
|
76 |
-
REQUEST_ID_FIELD = "request_id"
|
77 |
-
REQUEST_SENDER = "sender"
|
78 |
-
PROMPT_FIELD = "prompt"
|
79 |
-
BLOCK_FIELD = "block"
|
80 |
-
CID_PREFIX = "f01701220"
|
81 |
-
HTTP = "http://"
|
82 |
-
HTTPS = HTTP[:4] + "s" + HTTP[4:]
|
83 |
-
IPFS_ADDRESS = f"{HTTPS}gateway.autonolas.tech/ipfs/"
|
84 |
-
IPFS_LINKS_SERIES_NAME = "ipfs_links"
|
85 |
-
BACKOFF_FACTOR = 1
|
86 |
-
STATUS_FORCELIST = [404, 500, 502, 503, 504]
|
87 |
-
DEFAULT_FILENAME = "tools.csv"
|
88 |
-
RE_RPC_FILTER_ERROR = r"Filter with id: '\d+' does not exist."
|
89 |
-
ABI_ERROR = "The event signature did not match the provided ABI"
|
90 |
-
SLEEP = 0.5
|
91 |
-
HTTP_TIMEOUT = 60
|
92 |
-
N_IPFS_RETRIES = 2
|
93 |
-
N_RPC_RETRIES = 100
|
94 |
-
RPC_POLL_INTERVAL = 0.05
|
95 |
-
IPFS_POLL_INTERVAL = 0.05
|
96 |
-
FORMAT_UPDATE_BLOCK_NUMBER = 30411638
|
97 |
-
IRRELEVANT_TOOLS = [
|
98 |
-
"openai-text-davinci-002",
|
99 |
-
"openai-text-davinci-003",
|
100 |
-
"openai-gpt-3.5-turbo",
|
101 |
-
"openai-gpt-4",
|
102 |
-
"stabilityai-stable-diffusion-v1-5",
|
103 |
-
"stabilityai-stable-diffusion-xl-beta-v2-2-2",
|
104 |
-
"stabilityai-stable-diffusion-512-v2-1",
|
105 |
-
"stabilityai-stable-diffusion-768-v2-1",
|
106 |
-
"deepmind-optimization-strong",
|
107 |
-
"deepmind-optimization",
|
108 |
-
]
|
109 |
-
# this is how frequently we will keep a snapshot of the progress so far in terms of blocks' batches
|
110 |
-
# for example, the value 1 means that for every `BLOCKS_CHUNK_SIZE` blocks that we search, we also store the snapshot
|
111 |
-
SNAPSHOT_RATE = 10
|
112 |
-
NUM_WORKERS = 10
|
113 |
-
GET_CONTENTS_BATCH_SIZE = 1000
|
114 |
-
|
115 |
-
|
116 |
-
class MechEventName(Enum):
|
117 |
-
"""The mech's event names."""
|
118 |
-
|
119 |
-
REQUEST = "Request"
|
120 |
-
DELIVER = "Deliver"
|
121 |
-
|
122 |
-
|
123 |
-
@dataclass
|
124 |
-
class MechEvent:
|
125 |
-
"""A mech's on-chain event representation."""
|
126 |
-
|
127 |
-
for_block: int
|
128 |
-
requestId: int
|
129 |
-
data: bytes
|
130 |
-
sender: str
|
131 |
-
|
132 |
-
def _ipfs_link(self) -> Optional[str]:
|
133 |
-
"""Get the ipfs link for the data."""
|
134 |
-
return f"{IPFS_ADDRESS}{CID_PREFIX}{self.data.hex()}"
|
135 |
-
|
136 |
-
@property
|
137 |
-
def ipfs_request_link(self) -> Optional[str]:
|
138 |
-
"""Get the IPFS link for the request."""
|
139 |
-
return f"{self._ipfs_link()}/metadata.json"
|
140 |
-
|
141 |
-
@property
|
142 |
-
def ipfs_deliver_link(self) -> Optional[str]:
|
143 |
-
"""Get the IPFS link for the deliver."""
|
144 |
-
if self.requestId is None:
|
145 |
-
return None
|
146 |
-
return f"{self._ipfs_link()}/{self.requestId}"
|
147 |
-
|
148 |
-
def ipfs_link(self, event_name: MechEventName) -> Optional[str]:
|
149 |
-
"""Get the ipfs link based on the event."""
|
150 |
-
if event_name == MechEventName.REQUEST:
|
151 |
-
if self.for_block < FORMAT_UPDATE_BLOCK_NUMBER:
|
152 |
-
return self._ipfs_link()
|
153 |
-
return self.ipfs_request_link
|
154 |
-
if event_name == MechEventName.DELIVER:
|
155 |
-
return self.ipfs_deliver_link
|
156 |
-
return None
|
157 |
-
|
158 |
-
|
159 |
-
@dataclass(init=False)
|
160 |
-
class MechRequest:
|
161 |
-
"""A structure for a request to a mech."""
|
162 |
-
|
163 |
-
request_id: Optional[int]
|
164 |
-
request_block: Optional[int]
|
165 |
-
prompt_request: Optional[str]
|
166 |
-
tool: Optional[str]
|
167 |
-
nonce: Optional[str]
|
168 |
-
trader_address: Optional[str]
|
169 |
-
|
170 |
-
def __init__(self, **kwargs: Any) -> None:
|
171 |
-
"""Initialize the request ignoring extra keys."""
|
172 |
-
self.request_id = int(kwargs.pop(REQUEST_ID, 0))
|
173 |
-
self.request_block = int(kwargs.pop(BLOCK_FIELD, 0))
|
174 |
-
self.prompt_request = kwargs.pop(PROMPT_FIELD, None)
|
175 |
-
self.tool = kwargs.pop("tool", None)
|
176 |
-
self.nonce = kwargs.pop("nonce", None)
|
177 |
-
self.trader_address = kwargs.pop("sender", None)
|
178 |
-
|
179 |
-
|
180 |
-
@dataclass(init=False)
|
181 |
-
class PredictionResponse:
|
182 |
-
"""A response of a prediction."""
|
183 |
-
|
184 |
-
p_yes: float
|
185 |
-
p_no: float
|
186 |
-
confidence: float
|
187 |
-
info_utility: float
|
188 |
-
vote: Optional[str]
|
189 |
-
win_probability: Optional[float]
|
190 |
-
|
191 |
-
def __init__(self, **kwargs: Any) -> None:
|
192 |
-
"""Initialize the mech's prediction ignoring extra keys."""
|
193 |
-
try:
|
194 |
-
self.p_yes = float(kwargs.pop("p_yes"))
|
195 |
-
self.p_no = float(kwargs.pop("p_no"))
|
196 |
-
self.confidence = float(kwargs.pop("confidence"))
|
197 |
-
self.info_utility = float(kwargs.pop("info_utility"))
|
198 |
-
self.win_probability = 0
|
199 |
-
|
200 |
-
# Validate probabilities
|
201 |
-
probabilities = {
|
202 |
-
"p_yes": self.p_yes,
|
203 |
-
"p_no": self.p_no,
|
204 |
-
"confidence": self.confidence,
|
205 |
-
"info_utility": self.info_utility,
|
206 |
-
}
|
207 |
-
|
208 |
-
for name, prob in probabilities.items():
|
209 |
-
if not 0 <= prob <= 1:
|
210 |
-
raise ValueError(f"{name} probability is out of bounds: {prob}")
|
211 |
-
|
212 |
-
if self.p_yes + self.p_no != 1:
|
213 |
-
raise ValueError(
|
214 |
-
f"Sum of p_yes and p_no is not 1: {self.p_yes} + {self.p_no}"
|
215 |
-
)
|
216 |
-
|
217 |
-
self.vote = self.get_vote()
|
218 |
-
self.win_probability = self.get_win_probability()
|
219 |
-
|
220 |
-
except KeyError as e:
|
221 |
-
raise KeyError(f"Missing key in PredictionResponse: {e}")
|
222 |
-
except ValueError as e:
|
223 |
-
raise ValueError(f"Invalid value in PredictionResponse: {e}")
|
224 |
-
|
225 |
-
def get_vote(self) -> Optional[str]:
|
226 |
-
"""Return the vote."""
|
227 |
-
if self.p_no == self.p_yes:
|
228 |
-
return None
|
229 |
-
if self.p_no > self.p_yes:
|
230 |
-
return "No"
|
231 |
-
return "Yes"
|
232 |
-
|
233 |
-
def get_win_probability(self) -> Optional[float]:
|
234 |
-
"""Return the probability estimation for winning with vote."""
|
235 |
-
return max(self.p_no, self.p_yes)
|
236 |
-
|
237 |
-
|
238 |
-
@dataclass(init=False)
|
239 |
-
class MechResponse:
|
240 |
-
"""A structure for the response of a mech."""
|
241 |
-
|
242 |
-
request_id: int
|
243 |
-
deliver_block: Optional[int]
|
244 |
-
result: Optional[PredictionResponse]
|
245 |
-
error: Optional[str]
|
246 |
-
error_message: Optional[str]
|
247 |
-
prompt_response: Optional[str]
|
248 |
-
mech_address: Optional[str]
|
249 |
-
|
250 |
-
def __init__(self, **kwargs: Any) -> None:
|
251 |
-
"""Initialize the mech's response ignoring extra keys."""
|
252 |
-
self.error = kwargs.get("error", None)
|
253 |
-
self.request_id = int(kwargs.get(REQUEST_ID, 0))
|
254 |
-
self.deliver_block = int(kwargs.get(BLOCK_FIELD, 0))
|
255 |
-
self.result = kwargs.get("result", None)
|
256 |
-
self.prompt_response = kwargs.get(PROMPT_FIELD, None)
|
257 |
-
self.mech_address = kwargs.get("sender", None)
|
258 |
-
|
259 |
-
if self.result != "Invalid response":
|
260 |
-
self.error_message = kwargs.get("error_message", None)
|
261 |
-
|
262 |
-
try:
|
263 |
-
if isinstance(self.result, str):
|
264 |
-
kwargs = json.loads(self.result)
|
265 |
-
self.result = PredictionResponse(**kwargs)
|
266 |
-
self.error = str(False)
|
267 |
-
|
268 |
-
except JSONDecodeError:
|
269 |
-
self.error_message = "Response parsing error"
|
270 |
-
self.error = str(True)
|
271 |
-
|
272 |
-
except Exception as e:
|
273 |
-
self.error_message = str(e)
|
274 |
-
self.error = str(True)
|
275 |
-
|
276 |
-
else:
|
277 |
-
self.error_message = "Invalid response from tool"
|
278 |
-
self.error = str(True)
|
279 |
-
self.result = None
|
280 |
-
|
281 |
-
|
282 |
-
EVENT_TO_MECH_STRUCT = {
|
283 |
-
MechEventName.REQUEST: MechRequest,
|
284 |
-
MechEventName.DELIVER: MechResponse,
|
285 |
-
}
|
286 |
-
|
287 |
-
|
288 |
-
def parse_args() -> str:
|
289 |
-
"""Parse the arguments and return the RPC."""
|
290 |
-
if len(sys.argv) != 2:
|
291 |
-
raise ValueError("Expected the RPC as a positional argument.")
|
292 |
-
return sys.argv[1]
|
293 |
-
|
294 |
-
|
295 |
-
def read_abi(abi_path: str) -> str:
|
296 |
-
"""Read and return the wxDAI contract's ABI."""
|
297 |
-
with open(abi_path) as abi_file:
|
298 |
-
return abi_file.read()
|
299 |
-
|
300 |
-
|
301 |
-
def reduce_window(contract_instance, event, from_block, batch_size, latest_block):
|
302 |
-
"""Dynamically reduce the batch size window."""
|
303 |
-
keep_fraction = 1 - REDUCE_FACTOR
|
304 |
-
events_filter = contract_instance.events[event].build_filter()
|
305 |
-
events_filter.fromBlock = from_block
|
306 |
-
batch_size = int(batch_size * keep_fraction)
|
307 |
-
events_filter.toBlock = min(from_block + batch_size, latest_block)
|
308 |
-
tqdm.write(f"RPC timed out! Resizing batch size to {batch_size}.")
|
309 |
-
time.sleep(SLEEP)
|
310 |
-
return events_filter, batch_size
|
311 |
-
|
312 |
-
|
313 |
-
def get_events(
|
314 |
-
w3: Web3,
|
315 |
-
event: str,
|
316 |
-
mech_address: ChecksumAddress,
|
317 |
-
mech_abi_path: str,
|
318 |
-
earliest_block: int,
|
319 |
-
latest_block: int,
|
320 |
-
) -> List:
|
321 |
-
"""Get the delivered events."""
|
322 |
-
abi = read_abi(mech_abi_path)
|
323 |
-
contract_instance = w3.eth.contract(address=mech_address, abi=abi)
|
324 |
-
|
325 |
-
events = []
|
326 |
-
from_block = earliest_block
|
327 |
-
batch_size = BLOCKS_CHUNK_SIZE
|
328 |
-
with tqdm(
|
329 |
-
total=latest_block - from_block,
|
330 |
-
desc=f"Searching {event} events for mech {mech_address}",
|
331 |
-
unit="blocks",
|
332 |
-
) as pbar:
|
333 |
-
while from_block < latest_block:
|
334 |
-
events_filter = contract_instance.events[event].build_filter()
|
335 |
-
events_filter.fromBlock = from_block
|
336 |
-
events_filter.toBlock = min(from_block + batch_size, latest_block)
|
337 |
-
|
338 |
-
entries = None
|
339 |
-
retries = 0
|
340 |
-
while entries is None:
|
341 |
-
try:
|
342 |
-
entries = events_filter.deploy(w3).get_all_entries()
|
343 |
-
retries = 0
|
344 |
-
except (RequestsHTTPError, Urllib3HTTPError) as exc:
|
345 |
-
if "Request Entity Too Large" in exc.args[0]:
|
346 |
-
events_filter, batch_size = reduce_window(
|
347 |
-
contract_instance,
|
348 |
-
event,
|
349 |
-
from_block,
|
350 |
-
batch_size,
|
351 |
-
latest_block,
|
352 |
-
)
|
353 |
-
except (Urllib3ReadTimeoutError, RequestsReadTimeoutError):
|
354 |
-
events_filter, batch_size = reduce_window(
|
355 |
-
contract_instance, event, from_block, batch_size, latest_block
|
356 |
-
)
|
357 |
-
except Exception as exc:
|
358 |
-
retries += 1
|
359 |
-
if retries == N_RPC_RETRIES:
|
360 |
-
tqdm.write(
|
361 |
-
f"Skipping events for blocks {events_filter.fromBlock} - {events_filter.toBlock} "
|
362 |
-
f"as the retries have been exceeded."
|
363 |
-
)
|
364 |
-
break
|
365 |
-
sleep = SLEEP * retries
|
366 |
-
if (
|
367 |
-
(
|
368 |
-
isinstance(exc, ValueError)
|
369 |
-
and re.match(
|
370 |
-
RE_RPC_FILTER_ERROR, exc.args[0].get("message", "")
|
371 |
-
)
|
372 |
-
is None
|
373 |
-
)
|
374 |
-
and not isinstance(exc, ValueError)
|
375 |
-
and not isinstance(exc, MismatchedABI)
|
376 |
-
):
|
377 |
-
tqdm.write(
|
378 |
-
f"An error was raised from the RPC: {exc}\n Retrying in {sleep} seconds."
|
379 |
-
)
|
380 |
-
time.sleep(sleep)
|
381 |
-
|
382 |
-
from_block += batch_size
|
383 |
-
pbar.update(batch_size)
|
384 |
-
|
385 |
-
if entries is None:
|
386 |
-
continue
|
387 |
-
|
388 |
-
chunk = list(entries)
|
389 |
-
events.extend(chunk)
|
390 |
-
time.sleep(RPC_POLL_INTERVAL)
|
391 |
-
|
392 |
-
return events
|
393 |
-
|
394 |
-
|
395 |
-
def parse_events(raw_events: List) -> List[MechEvent]:
|
396 |
-
"""Parse all the specified MechEvents."""
|
397 |
-
parsed_events = []
|
398 |
-
for event in raw_events:
|
399 |
-
for_block = event.get("blockNumber", 0)
|
400 |
-
args = event.get(EVENT_ARGUMENTS, {})
|
401 |
-
request_id = args.get(REQUEST_ID, 0)
|
402 |
-
data = args.get(DATA, b"")
|
403 |
-
sender = args.get(REQUEST_SENDER, "")
|
404 |
-
parsed_event = MechEvent(for_block, request_id, data, sender)
|
405 |
-
parsed_events.append(parsed_event)
|
406 |
-
|
407 |
-
return parsed_events
|
408 |
-
|
409 |
-
|
410 |
-
def create_session() -> requests.Session:
|
411 |
-
"""Create a session with a retry strategy."""
|
412 |
-
session = requests.Session()
|
413 |
-
retry_strategy = Retry(
|
414 |
-
total=N_IPFS_RETRIES + 1,
|
415 |
-
backoff_factor=BACKOFF_FACTOR,
|
416 |
-
status_forcelist=STATUS_FORCELIST,
|
417 |
-
)
|
418 |
-
adapter = HTTPAdapter(max_retries=retry_strategy)
|
419 |
-
for protocol in (HTTP, HTTPS):
|
420 |
-
session.mount(protocol, adapter)
|
421 |
-
|
422 |
-
return session
|
423 |
-
|
424 |
-
|
425 |
-
def request(
|
426 |
-
session: requests.Session, url: str, timeout: int = HTTP_TIMEOUT
|
427 |
-
) -> Optional[requests.Response]:
|
428 |
-
"""Perform a request with a session."""
|
429 |
-
try:
|
430 |
-
response = session.get(url, timeout=timeout)
|
431 |
-
response.raise_for_status()
|
432 |
-
except requests.exceptions.HTTPError as exc:
|
433 |
-
tqdm.write(f"HTTP error occurred: {exc}.")
|
434 |
-
except Exception as exc:
|
435 |
-
tqdm.write(f"Unexpected error occurred: {exc}.")
|
436 |
-
else:
|
437 |
-
return response
|
438 |
-
return None
|
439 |
-
|
440 |
-
|
441 |
-
def limit_text(text: str, limit: int = 200) -> str:
|
442 |
-
"""Limit the given text"""
|
443 |
-
if len(text) > limit:
|
444 |
-
return f"{text[:limit]}..."
|
445 |
-
return text
|
446 |
-
|
447 |
-
|
448 |
-
def parse_ipfs_response(
|
449 |
-
session: requests.Session,
|
450 |
-
url: str,
|
451 |
-
event: MechEvent,
|
452 |
-
event_name: MechEventName,
|
453 |
-
response: requests.Response,
|
454 |
-
) -> Optional[Dict[str, str]]:
|
455 |
-
"""Parse a response from IPFS."""
|
456 |
-
try:
|
457 |
-
return response.json()
|
458 |
-
except requests.exceptions.JSONDecodeError:
|
459 |
-
# this is a workaround because the `metadata.json` file was introduced and removed multiple times
|
460 |
-
if event_name == MechEventName.REQUEST and url != event.ipfs_request_link:
|
461 |
-
url = event.ipfs_request_link
|
462 |
-
response = request(session, url)
|
463 |
-
if response is None:
|
464 |
-
tqdm.write(f"Skipping {event=}.")
|
465 |
-
return None
|
466 |
-
|
467 |
-
try:
|
468 |
-
return response.json()
|
469 |
-
except requests.exceptions.JSONDecodeError:
|
470 |
-
pass
|
471 |
-
|
472 |
-
tqdm.write(f"Failed to parse response into json for {url=}.")
|
473 |
-
return None
|
474 |
-
|
475 |
-
|
476 |
-
def parse_ipfs_tools_content(
|
477 |
-
raw_content: Dict[str, str], event: MechEvent, event_name: MechEventName
|
478 |
-
) -> Optional[Union[MechRequest, MechResponse]]:
|
479 |
-
"""Parse tools content from IPFS."""
|
480 |
-
struct = EVENT_TO_MECH_STRUCT.get(event_name)
|
481 |
-
raw_content[REQUEST_ID] = str(event.requestId)
|
482 |
-
raw_content[BLOCK_FIELD] = str(event.for_block)
|
483 |
-
raw_content["sender"] = str(event.sender)
|
484 |
-
|
485 |
-
try:
|
486 |
-
mech_response = struct(**raw_content)
|
487 |
-
except (ValueError, TypeError, KeyError):
|
488 |
-
tqdm.write(f"Could not parse {limit_text(str(raw_content))}")
|
489 |
-
return None
|
490 |
-
|
491 |
-
if event_name == MechEventName.REQUEST and mech_response.tool in IRRELEVANT_TOOLS:
|
492 |
-
return None
|
493 |
-
|
494 |
-
return mech_response
|
495 |
-
|
496 |
-
|
497 |
-
def get_contents(
|
498 |
-
session: requests.Session, events: List[MechEvent], event_name: MechEventName
|
499 |
-
) -> pd.DataFrame:
|
500 |
-
"""Fetch the tools' responses."""
|
501 |
-
contents = []
|
502 |
-
for event in tqdm(events, desc=f"Tools' results", unit="results"):
|
503 |
-
url = event.ipfs_link(event_name)
|
504 |
-
response = request(session, url)
|
505 |
-
if response is None:
|
506 |
-
tqdm.write(f"Skipping {event=}.")
|
507 |
-
continue
|
508 |
-
|
509 |
-
raw_content = parse_ipfs_response(session, url, event, event_name, response)
|
510 |
-
if raw_content is None:
|
511 |
-
continue
|
512 |
-
|
513 |
-
mech_response = parse_ipfs_tools_content(raw_content, event, event_name)
|
514 |
-
if mech_response is None:
|
515 |
-
continue
|
516 |
-
contents.append(mech_response)
|
517 |
-
time.sleep(IPFS_POLL_INTERVAL)
|
518 |
-
|
519 |
-
return pd.DataFrame(contents)
|
520 |
-
|
521 |
-
|
522 |
-
def clean(df: pd.DataFrame) -> pd.DataFrame:
|
523 |
-
"""Clean the dataframe."""
|
524 |
-
cleaned = df.drop_duplicates()
|
525 |
-
cleaned[REQUEST_ID_FIELD] = cleaned[REQUEST_ID_FIELD].astype("str")
|
526 |
-
return cleaned
|
527 |
-
|
528 |
-
|
529 |
-
def transform_request(contents: pd.DataFrame) -> pd.DataFrame:
|
530 |
-
"""Transform the requests dataframe."""
|
531 |
-
return clean(contents)
|
532 |
-
|
533 |
-
|
534 |
-
def transform_deliver(contents: pd.DataFrame, full_contents=False) -> pd.DataFrame:
|
535 |
-
"""Transform the delivers dataframe."""
|
536 |
-
unpacked_result = pd.json_normalize(contents.result)
|
537 |
-
# # drop result column if it exists
|
538 |
-
if "result" in unpacked_result.columns:
|
539 |
-
unpacked_result.drop(columns=["result"], inplace=True)
|
540 |
-
|
541 |
-
# drop prompt column if it exists
|
542 |
-
if "prompt" in unpacked_result.columns:
|
543 |
-
unpacked_result.drop(columns=["prompt"], inplace=True)
|
544 |
-
|
545 |
-
# rename prompt column to prompt_deliver
|
546 |
-
unpacked_result.rename(columns={"prompt": "prompt_deliver"}, inplace=True)
|
547 |
-
contents = pd.concat((contents, unpacked_result), axis=1)
|
548 |
-
|
549 |
-
if "result" in contents.columns:
|
550 |
-
contents.drop(columns=["result"], inplace=True)
|
551 |
-
|
552 |
-
if "prompt" in contents.columns:
|
553 |
-
contents.drop(columns=["prompt"], inplace=True)
|
554 |
-
|
555 |
-
return clean(contents)
|
556 |
-
|
557 |
-
|
558 |
-
def gen_event_filename(event_name: MechEventName) -> str:
|
559 |
-
"""Generate the filename of an event."""
|
560 |
-
return f"{event_name.value.lower()}s.csv"
|
561 |
-
|
562 |
-
|
563 |
-
def read_n_last_lines(filename: str, n: int = 1) -> str:
|
564 |
-
"""Return the `n` last lines' content of a file."""
|
565 |
-
num_newlines = 0
|
566 |
-
with open(filename, "rb") as f:
|
567 |
-
try:
|
568 |
-
f.seek(-2, os.SEEK_END)
|
569 |
-
while num_newlines < n:
|
570 |
-
f.seek(-2, os.SEEK_CUR)
|
571 |
-
if f.read(1) == b"\n":
|
572 |
-
num_newlines += 1
|
573 |
-
except OSError:
|
574 |
-
f.seek(0)
|
575 |
-
last_line = f.readline().decode()
|
576 |
-
return last_line
|
577 |
-
|
578 |
-
|
579 |
-
def get_earliest_block(event_name: MechEventName) -> int:
|
580 |
-
"""Get the earliest block number to use when filtering for events."""
|
581 |
-
filename = gen_event_filename(event_name)
|
582 |
-
if not os.path.exists(filename):
|
583 |
-
return 0
|
584 |
-
|
585 |
-
cols = pd.read_csv(filename, index_col=0, nrows=0).columns.tolist()
|
586 |
-
last_line_buff = StringIO(read_n_last_lines(filename))
|
587 |
-
last_line_series = pd.read_csv(last_line_buff, names=cols)
|
588 |
-
block_field = f"{event_name.value.lower()}_{BLOCK_FIELD}"
|
589 |
-
return int(last_line_series[block_field].values[0])
|
590 |
-
|
591 |
-
|
592 |
-
def pipeline_step(
|
593 |
-
w3: Web3,
|
594 |
-
session: requests.Session,
|
595 |
-
event_to_contents: Dict[MechEventName, pd.DataFrame],
|
596 |
-
event_to_transformer: Dict[MechEventName, Callable],
|
597 |
-
mech_to_info: Dict[ChecksumAddress, Tuple[str, int]],
|
598 |
-
stop_block: Optional[int] = None,
|
599 |
-
start_block: Optional[int] = None,
|
600 |
-
full_contents: bool = False,
|
601 |
-
):
|
602 |
-
"""Perform a step of the pipeline, from start block (or default earliest) to stop block."""
|
603 |
-
for event_name, transformer in event_to_transformer.items():
|
604 |
-
events = []
|
605 |
-
for address, (abi, earliest_block) in mech_to_info.items():
|
606 |
-
if start_block is None:
|
607 |
-
start_block = max(earliest_block, get_earliest_block(event_name))
|
608 |
-
stop_block = start_block + SNAPSHOT_RATE * BLOCKS_CHUNK_SIZE
|
609 |
-
|
610 |
-
# Parallelize the fetching of events
|
611 |
-
with ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
|
612 |
-
futures = []
|
613 |
-
for i in range(start_block, stop_block, BLOCKS_CHUNK_SIZE):
|
614 |
-
futures.append(
|
615 |
-
executor.submit(
|
616 |
-
get_events,
|
617 |
-
w3,
|
618 |
-
event_name.value,
|
619 |
-
address,
|
620 |
-
abi,
|
621 |
-
i,
|
622 |
-
min(i + BLOCKS_CHUNK_SIZE, stop_block),
|
623 |
-
)
|
624 |
-
)
|
625 |
-
|
626 |
-
for future in tqdm(
|
627 |
-
as_completed(futures),
|
628 |
-
total=len(futures),
|
629 |
-
desc=f"Fetching {event_name.value} Events",
|
630 |
-
):
|
631 |
-
current_mech_events = future.result()
|
632 |
-
events.extend(current_mech_events)
|
633 |
-
|
634 |
-
parsed = parse_events(events)
|
635 |
-
|
636 |
-
# Parallelize the fetching of contents; use tqdm to show progress
|
637 |
-
contents = []
|
638 |
-
with ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
|
639 |
-
futures = []
|
640 |
-
for i in range(0, len(parsed), 1000):
|
641 |
-
futures.append(
|
642 |
-
executor.submit(
|
643 |
-
get_contents, session, parsed[i : i + 1000], event_name
|
644 |
-
)
|
645 |
-
)
|
646 |
-
|
647 |
-
for future in tqdm(
|
648 |
-
as_completed(futures),
|
649 |
-
total=len(futures),
|
650 |
-
desc=f"Fetching {event_name.value} Contents",
|
651 |
-
):
|
652 |
-
current_mech_contents = future.result()
|
653 |
-
contents.append(current_mech_contents)
|
654 |
-
|
655 |
-
contents = pd.concat(contents, ignore_index=True)
|
656 |
-
|
657 |
-
if event_name == MechEventName.REQUEST:
|
658 |
-
transformed = transformer(contents)
|
659 |
-
elif event_name == MechEventName.DELIVER:
|
660 |
-
transformed = transformer(contents, full_contents=full_contents)
|
661 |
-
|
662 |
-
events_filename = gen_event_filename(event_name)
|
663 |
-
if os.path.exists(events_filename):
|
664 |
-
old = pd.read_csv(events_filename)
|
665 |
-
|
666 |
-
# Reset index to avoid index conflicts
|
667 |
-
old.reset_index(drop=True, inplace=True)
|
668 |
-
transformed.reset_index(drop=True, inplace=True)
|
669 |
-
|
670 |
-
# Concatenate DataFrames
|
671 |
-
transformed = pd.concat([old, transformed], ignore_index=True)
|
672 |
-
|
673 |
-
# Drop duplicates if necessary
|
674 |
-
transformed.drop_duplicates(inplace=True)
|
675 |
-
|
676 |
-
event_to_contents[event_name] = transformed.copy()
|
677 |
-
|
678 |
-
return stop_block
|
679 |
-
|
680 |
-
|
681 |
-
def store_progress(
|
682 |
-
filename: str,
|
683 |
-
event_to_contents: Dict[MechEventName, pd.DataFrame],
|
684 |
-
tools: pd.DataFrame,
|
685 |
-
) -> None:
|
686 |
-
"""Store the given progress."""
|
687 |
-
if filename:
|
688 |
-
for event_name, content in event_to_contents.items():
|
689 |
-
event_filename = gen_event_filename(event_name)
|
690 |
-
if "error" in content.columns:
|
691 |
-
content.drop(columns=["error"], inplace=True)
|
692 |
-
|
693 |
-
if "result" in content.columns:
|
694 |
-
content.drop(columns=["result"], inplace=True)
|
695 |
-
|
696 |
-
content.to_csv(event_filename, index=False, escapechar="\\")
|
697 |
-
|
698 |
-
# drop result and error columns
|
699 |
-
if "result" in tools.columns:
|
700 |
-
tools.drop(columns=["result"], inplace=True)
|
701 |
-
|
702 |
-
tools.to_csv(filename, index=False, escapechar="\\")
|
703 |
-
|
704 |
-
|
705 |
-
def etl(
|
706 |
-
rpcs: List[str], filename: Optional[str] = None, full_contents: bool = True
|
707 |
-
) -> pd.DataFrame:
|
708 |
-
"""Fetch from on-chain events, process, store and return the tools' results on all the questions as a Dataframe."""
|
709 |
-
w3s = [Web3(HTTPProvider(r)) for r in rpcs]
|
710 |
-
session = create_session()
|
711 |
-
event_to_transformer = {
|
712 |
-
MechEventName.REQUEST: transform_request,
|
713 |
-
MechEventName.DELIVER: transform_deliver,
|
714 |
-
}
|
715 |
-
mech_to_info = {
|
716 |
-
to_checksum_address(address): (
|
717 |
-
os.path.join(CONTRACTS_PATH, filename),
|
718 |
-
earliest_block,
|
719 |
-
)
|
720 |
-
for address, (filename, earliest_block) in MECH_TO_INFO.items()
|
721 |
-
}
|
722 |
-
event_to_contents = {}
|
723 |
-
|
724 |
-
latest_block = LATEST_BLOCK
|
725 |
-
if latest_block is None:
|
726 |
-
latest_block = w3s[0].eth.get_block(LATEST_BLOCK_NAME)[BLOCK_DATA_NUMBER]
|
727 |
-
|
728 |
-
next_start_block = None
|
729 |
-
|
730 |
-
# Loop through events in event_to_transformer
|
731 |
-
for event_name, transformer in event_to_transformer.items():
|
732 |
-
if next_start_block is None:
|
733 |
-
next_start_block_base = get_earliest_block(event_name)
|
734 |
-
|
735 |
-
# Loop through mech addresses in mech_to_info
|
736 |
-
events = []
|
737 |
-
for address, (abi, earliest_block) in mech_to_info.items():
|
738 |
-
if next_start_block_base == 0:
|
739 |
-
next_start_block = earliest_block
|
740 |
-
else:
|
741 |
-
next_start_block = next_start_block_base
|
742 |
-
|
743 |
-
print(
|
744 |
-
f"Searching for {event_name.value} events for mech {address} from block {next_start_block} to {latest_block}."
|
745 |
-
)
|
746 |
-
|
747 |
-
# parallelize the fetching of events
|
748 |
-
with ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
|
749 |
-
futures = []
|
750 |
-
for i in range(
|
751 |
-
next_start_block, latest_block, BLOCKS_CHUNK_SIZE * SNAPSHOT_RATE
|
752 |
-
):
|
753 |
-
futures.append(
|
754 |
-
executor.submit(
|
755 |
-
get_events,
|
756 |
-
random.choice(w3s),
|
757 |
-
event_name.value,
|
758 |
-
address,
|
759 |
-
abi,
|
760 |
-
i,
|
761 |
-
min(i + BLOCKS_CHUNK_SIZE * SNAPSHOT_RATE, latest_block),
|
762 |
-
)
|
763 |
-
)
|
764 |
-
|
765 |
-
for future in tqdm(
|
766 |
-
as_completed(futures),
|
767 |
-
total=len(futures),
|
768 |
-
desc=f"Fetching {event_name.value} Events",
|
769 |
-
):
|
770 |
-
current_mech_events = future.result()
|
771 |
-
events.extend(current_mech_events)
|
772 |
-
|
773 |
-
parsed = parse_events(events)
|
774 |
-
|
775 |
-
contents = []
|
776 |
-
with ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
|
777 |
-
futures = []
|
778 |
-
for i in range(0, len(parsed), GET_CONTENTS_BATCH_SIZE):
|
779 |
-
futures.append(
|
780 |
-
executor.submit(
|
781 |
-
get_contents,
|
782 |
-
session,
|
783 |
-
parsed[i : i + GET_CONTENTS_BATCH_SIZE],
|
784 |
-
event_name,
|
785 |
-
)
|
786 |
-
)
|
787 |
-
|
788 |
-
for future in tqdm(
|
789 |
-
as_completed(futures),
|
790 |
-
total=len(futures),
|
791 |
-
desc=f"Fetching {event_name.value} Contents",
|
792 |
-
):
|
793 |
-
current_mech_contents = future.result()
|
794 |
-
contents.append(current_mech_contents)
|
795 |
-
|
796 |
-
contents = pd.concat(contents, ignore_index=True)
|
797 |
-
|
798 |
-
full_contents = True
|
799 |
-
if event_name == MechEventName.REQUEST:
|
800 |
-
transformed = transformer(contents)
|
801 |
-
elif event_name == MechEventName.DELIVER:
|
802 |
-
transformed = transformer(contents, full_contents=full_contents)
|
803 |
-
|
804 |
-
events_filename = gen_event_filename(event_name)
|
805 |
-
|
806 |
-
if os.path.exists(events_filename):
|
807 |
-
old = pd.read_csv(events_filename)
|
808 |
-
|
809 |
-
# Reset index to avoid index conflicts
|
810 |
-
old.reset_index(drop=True, inplace=True)
|
811 |
-
transformed.reset_index(drop=True, inplace=True)
|
812 |
-
|
813 |
-
# Concatenate DataFrames
|
814 |
-
transformed = pd.concat([old, transformed], ignore_index=True)
|
815 |
-
|
816 |
-
# Drop duplicates if necessary
|
817 |
-
transformed.drop_duplicates(inplace=True)
|
818 |
-
|
819 |
-
event_to_contents[event_name] = transformed.copy()
|
820 |
-
|
821 |
-
# Store progress
|
822 |
-
tools = pd.merge(*event_to_contents.values(), on=REQUEST_ID_FIELD)
|
823 |
-
store_progress(filename, event_to_contents, tools)
|
824 |
-
|
825 |
-
return tools
|
826 |
-
|
827 |
-
|
828 |
-
if __name__ == "__main__":
|
829 |
-
RPCs = [
|
830 |
-
"https://lb.nodies.app/v1/406d8dcc043f4cb3959ed7d6673d311a",
|
831 |
-
]
|
832 |
-
|
833 |
-
tools = etl(rpcs=RPCs, filename=DEFAULT_FILENAME, full_contents=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|