⚗ Add dune analytics queries examples

This commit is contained in:
r1oga
2022-11-01 12:24:16 +01:00
parent eebc329c22
commit 495645e401
9 changed files with 150 additions and 31 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.idea
venv

View File

@@ -1,3 +1,4 @@
select distinct(from_address)
from ethereum-analytics-366016.crypto_ethereum.transactions
where to_address = "0x00000000219ab540356cbb839cbe05303d7705fa" and value = 32e18
where to_address = "0x00000000219ab540356cbb839cbe05303d7705fa"
and value = 32e18

View File

@@ -3,36 +3,32 @@
-- union
-- select distinct(contract_address) from tornado_cash.withdrawals
-- select distinct(contract_address) from tornado_cash.deposits
-- union
-- select distinct(contract_address) from tornado_cash.withdrawals
select distinct(from_address)
from ethereum-analytics-366016.crypto_ethereum.transactions
where to_address in (
"0x0836222f2b2b24a3f36f98668ed8f0b38d1a872f",
"0x1e34a77868e19a6647b1f2f47b51ed72dede95dd",
"0x47ce0c6ed5b0ce3d3a51fdb1c52dc66a7c3c2936",
"0xf67721a2d8f736e75a49fdd7fad2e31d8676542a",
"0xdf231d99ff8b6c6cbf4e9b9a945cbacef9339178",
"0xbb93e510bbcd0b7beb5a853875f9ec60275cf498",
"0x07687e702b410fa43f4cb4af7fa097918ffd2730",
"0x22aaa7720ddd5388a3c0a3333430953c68f1849b",
"0x4736dcf1b7a3d580672cce6e7c65cd5cc9cfba9d",
"0xb529a618ffedefe5cfa4df8dbb0b32d8c29ca2e8",
"0xa5c2254e4253490c54cef0a4347fddb8f75a4998",
"0xaf4c0b70b2ea9fb7487c7cbb37ada259579fe040",
"0x169ad27a470d064dede56a2d3ff727986b15d52b",
"0x23773e65ed146a459791799d01336db287f25334",
"0xaf8d1839c3c67cf571aa74b5c12398d4901147b3",
"0xa160cdab225685da1d56aa342ad8841c3b53f291",
"0x84443cfd09a48af6ef360c6976c5392ac5023a1f",
"0x610b717796ad172b316836ac95a2ffad065ceab4",
"0x910cbd523d972eb0a6f4cae4618ad62622b39dbf",
"0xd47438c816c9e7f2e2888e060936a499af9582b3",
"0xd96f2b1c14db8458374d9aca76e26c3d18364307",
"0xf60dd140cff0706bae9cd734ac3ae76ad9ebc32a",
"0x12d66f87a04a9e220743712ce6d9bb1b5616b8fc",
"0x330bdfade01ee9bf63c209ee33102dd334618e0a",
"0xba214c1c1928a32bffe790263e38b4af9bfcd659"
)
"0x0836222f2b2b24a3f36f98668ed8f0b38d1a872f",
"0x1e34a77868e19a6647b1f2f47b51ed72dede95dd",
"0x47ce0c6ed5b0ce3d3a51fdb1c52dc66a7c3c2936",
"0xf67721a2d8f736e75a49fdd7fad2e31d8676542a",
"0xdf231d99ff8b6c6cbf4e9b9a945cbacef9339178",
"0xbb93e510bbcd0b7beb5a853875f9ec60275cf498",
"0x07687e702b410fa43f4cb4af7fa097918ffd2730",
"0x22aaa7720ddd5388a3c0a3333430953c68f1849b",
"0x4736dcf1b7a3d580672cce6e7c65cd5cc9cfba9d",
"0xb529a618ffedefe5cfa4df8dbb0b32d8c29ca2e8",
"0xa5c2254e4253490c54cef0a4347fddb8f75a4998",
"0xaf4c0b70b2ea9fb7487c7cbb37ada259579fe040",
"0x169ad27a470d064dede56a2d3ff727986b15d52b",
"0x23773e65ed146a459791799d01336db287f25334",
"0xaf8d1839c3c67cf571aa74b5c12398d4901147b3",
"0xa160cdab225685da1d56aa342ad8841c3b53f291",
"0x84443cfd09a48af6ef360c6976c5392ac5023a1f",
"0x610b717796ad172b316836ac95a2ffad065ceab4",
"0x910cbd523d972eb0a6f4cae4618ad62622b39dbf",
"0xd47438c816c9e7f2e2888e060936a499af9582b3",
"0xd96f2b1c14db8458374d9aca76e26c3d18364307",
"0xf60dd140cff0706bae9cd734ac3ae76ad9ebc32a",
"0x12d66f87a04a9e220743712ce6d9bb1b5616b8fc",
"0x330bdfade01ee9bf63c209ee33102dd334618e0a",
"0xba214c1c1928a32bffe790263e38b4af9bfcd659"
)

View File

@@ -0,0 +1,14 @@
# [Dune Analytics](https://dune.com/) queries examples
## Getting started
1. Install dependencies (python 3.10): `pip -r requirements.txt`
2. Run queries (requires your dune analytics credentials)
```commandline
USERNAME=username PASSWORD=password python main.py beacon|tornado|ens_balance`
```
## Queries
| File | Description |
|----------------------------------------|-----------------------------------------------------------------------------------------------------|
| [beacon.sql](./beacon.sql) | Get the latest list of addresses who deposited in the Beacon Deposit Contract |
| [erc20_balance.sql](./eth_balance.sql) | Get the latest list of addresses who have a balance of at least X ERC20 (example with `ENS`) |
| [tornado.sql](./tornado.sql) | Get the latest list of addresses who deposited into or withdrew from a Tornado Cash Mixing Contract |

View File

@@ -0,0 +1,4 @@
-- https://dune.com/queries/1499468?d=1&category=canonical&namespace=ethereum&table=transactions&blockchains=ethereum
select distinct(`from`) as address
from ethereum.transactions
where `to` = '0x00000000219ab540356cbb839cbe05303d7705fa'

View File

@@ -0,0 +1,29 @@
import sys
from duneanalytics import DuneAnalytics
import pandas as pd
import os
dune = DuneAnalytics(os.environ['USERNAME'], os.environ['PASSWORD'])
dune.login()
dune.fetch_auth_token()
queries = {
'beacon': 1499468,
'tornado': 1499520,
'ens_balance': 1500107
}
def run_query(query_id: int):
result_id = dune.query_result_id(query_id=query_id)
data = dune.query_result(result_id)
df = pd.DataFrame.from_records([result['data'] for result in data['data']['get_result_by_result_id']])
print(df)
run_query(queries[sys.argv[1]])
# df.to_csv(os.getcwd() + 'data.txt', header=None, index=None, sep=' ', mode='a')

View File

@@ -0,0 +1,61 @@
apturl==0.5.2
blinker==1.4
Brlapi==0.8.3
certifi==2020.6.20
chardet==4.0.0
click==8.0.3
colorama==0.4.4
command-not-found==0.3
cryptography==3.4.8
cupshelpers==1.0
dbus-python==1.2.18
defer==1.0.6
distro==1.7.0
distro-info===1.1build1
httplib2==0.20.2
idna==3.3
importlib-metadata==4.6.4
jeepney==0.7.1
keyring==23.5.0
language-selector==0.1
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
louis==3.20.0
macaroonbakery==1.3.1
more-itertools==8.10.0
netifaces==0.11.0
oauthlib==3.2.0
olefile==0.46
pexpect==4.8.0
Pillow==9.0.1
protobuf==3.12.4
ptyprocess==0.7.0
pycairo==1.20.1
pycups==2.0.1
PyGObject==3.42.1
PyJWT==2.3.0
pymacaroons==0.13.0
PyNaCl==1.5.0
pyparsing==2.4.7
pyRFC3339==1.1
python-apt==2.3.0+ubuntu2.1
python-dateutil==2.8.1
python-debian===0.1.43ubuntu1
pytz==2022.1
pyxdg==0.27
PyYAML==5.4.1
reportlab==3.6.8
requests==2.25.1
SecretStorage==3.3.1
six==1.16.0
systemd-python==234
ubuntu-advantage-tools==27.11.2
ubuntu-drivers-common==0.0.0
ufw==0.36.1
unattended-upgrades==0.1
urllib3==1.26.5
wadllib==1.3.6
xdg==5
xkit==0.0.0
zipp==1.0.0

View File

@@ -0,0 +1,7 @@
select
distinct(wallet_address)
from
balances_ethereum.erc20_latest
where
token_address = '0xc18360217d8f7ab5e7c516566761ea12ce7f9d72'
and amount > 0

View File

@@ -0,0 +1,5 @@
select distinct(depositor) as address
from tornado_cash.deposits
union
select distinct(recipient)
from tornado_cash.withdrawals