-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (56 loc) · 1.9 KB
/
main.py
File metadata and controls
62 lines (56 loc) · 1.9 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
import pandas as pd
import requests
import time
# Load wallet addresses
wallet_df = pd.read_csv("C:/Users/nehag/wallet-risk-scoring/wallets.csv")
wallets = wallet_df['wallet_id'].tolist()
# Compound V3 Subgraph for USDC on Ethereum Mainnet
COMPOUND_V3_URL = "https://api.thegraph.com/subgraphs/name/0xngmi/compound-v3-ethereum"
# GraphQL query template
def create_query(wallet):
return {
"query": """
{
account(id: "%s") {
id
positions {
id
market {
name
}
totalDeposited
totalBorrowed
totalRepaid
totalWithdrawn
}
}
}
""" % wallet.lower()
}
# Collect data
data_list = []
for wallet in wallets:
try:
response = requests.post(COMPOUND_V3_URL, json=create_query(wallet))
if response.status_code == 200:
result = response.json()
acct = result.get('data', {}).get('account')
if acct:
for pos in acct['positions']:
data_list.append({
"wallet_id": wallet,
"market": pos['market']['name'],
"deposited": float(pos['totalDeposited']),
"borrowed": float(pos['totalBorrowed']),
"repaid": float(pos['totalRepaid']),
"withdrawn": float(pos['totalWithdrawn'])
})
else:
print(f"Failed for {wallet}: {response.status_code}")
time.sleep(0.5) # Respect rate limit
except Exception as e:
print(f"Error for {wallet}: {str(e)}")
# Save collected data
df = pd.DataFrame(data_list)
df.to_csv("compound_v3_wallet_data.csv", index=False)
print("✅ Data saved to compound_v3_wallet_data.csv")