-
-
Save Fitblip/d18ab280f31a623cb85734cc0f6e30f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import csv | |
from io import StringIO | |
from collections import defaultdict | |
airdrop_data = requests.get('https://raw.githubusercontent.com/Hover-Labs/kdao-airdrop/main/airdrop-data.csv') | |
cleaned_data = [x.strip().rstrip(',').replace(', ', ',') for x in airdrop_data.content.decode().split('\n') if x] | |
data_strio = StringIO('\n'.join(cleaned_data)) | |
addresses = {} | |
tx_data = defaultdict() | |
for airdrop_recipient in csv.DictReader(data_strio): | |
addresses[airdrop_recipient['address']] = airdrop_recipient['token allocation'] | |
printed_output = '' | |
for index, (address, _amt) in enumerate(addresses.items()): | |
sent_funds = requests.get('https://api.tzkt.io/v1/operations/transactions?type=transaction¶meter.null&status=applied&sender={}&limit=10000'.format(address)).json() | |
#recv_funds = requests.get('https://api.tzkt.io/v1/operations/transactions?type=transaction¶meter.null&status=applied&target={}&limit=10000'.format(address)).json() | |
sent_txs = [] | |
for tx in sent_funds: | |
if tx['target']['address'] in addresses and tx['target']['address'] != address: | |
tx_payload = {"timestamp": tx['timestamp'], "amount": int(tx['amount']) / 10 ** 6} | |
if address not in tx_data: | |
tx_data[address] = { | |
'sent_txs': { | |
tx['target']['address']: [tx_payload] | |
} | |
} | |
elif tx['target']['address'] not in tx_data[address]['sent_txs']: | |
tx_data[address]['sent_txs'][tx['target']['address']] = [tx_payload] | |
else: | |
tx_data[address]['sent_txs'][tx['target']['address']].append(tx_payload) | |
sent_txs.append(tx) | |
if len(sent_txs) != 0: | |
line = "[{}/{}] {} Sus Txs: {} ".format(str(index + 1).zfill(3), len(addresses), address, len(sent_txs)) | |
print(line) | |
for tx in sent_txs: | |
tx_line = ' => {} - Funds sent from this address to fellow airdropper {} (who is getting ~{} kDAO) for {} XTZ'.format(tx['timestamp'], tx['target']['address'], int(float(addresses[tx['target']['address']])), int(tx['amount']) / 10 ** 6) | |
print(tx_line) | |
printed_output += tx_line + "\n" | |
clusters_larger_than_two = {} | |
for address, results in tx_data.items(): | |
if len(results['sent_txs']) > 2: | |
clusters_larger_than_two[address] = results | |
print(address, results) | |
for address, results in clusters_larger_than_two.items(): | |
print("+ {} (getting {} kDAO)".format(address, int(float(addresses[sent_to])))) | |
for sent_to, sends in results['sent_txs'].items(): | |
total = sum([x['amount'] for x in sends]) | |
print(" |- Sent {} XTZ total to {} (who is getting {} kDAO)".format(total, sent_to, int(float(addresses[sent_to])))) | |
for address, results in clusters_larger_than_two.items(): | |
print("+ {} (getting {} kDAO)".format(address, int(float(addresses[sent_to])))) | |
for sent_to, sends in results['sent_txs'].items(): | |
total = sum([x['amount'] for x in sends]) | |
print(" |- Sent {} XTZ total to {} (who is getting {} kDAO)".format(total, sent_to, int(float(addresses[sent_to])))) | |
for send in sends: | |
print(' \\- {} - {} XTZ'.format(send['timestamp'], send['amount'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment