Created
June 21, 2022 05:31
-
-
Save eshaben/0bcdf907b59f64f2e5b537c4605459ab 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 | |
def get_transfers(query): | |
res = requests.post("https://api.subquery.network/sq/eshaben/moonriver-asset-transfers", json={'query': query}).json() | |
transfers =res['data']['transfers']['nodes'] | |
return transfers | |
outflow_balance = 0 | |
inflow_balance = 0 | |
counter = 0 | |
offset_count = 0 | |
offset = "" | |
has_more = True | |
def update_inflow_query(offset): | |
return """query { | |
transfers (filter: { | |
to: {equalToInsensitive: "0x1caaf75ef37b6b96676bea6bcea04ffd201e8e1f" } | |
assetId: {equalToInsensitive: "42259045809535163221576417993425387648"} | |
}""" + offset + """ | |
) { | |
nodes { | |
id | |
assetId | |
to | |
from | |
balance | |
} | |
} | |
}""" | |
def update_outflow_query(offset): | |
return """query { | |
transfers (filter: { | |
from: {equalToInsensitive: "0x1caaf75ef37b6b96676bea6bcea04ffd201e8e1f" } | |
assetId: {equalToInsensitive: "42259045809535163221576417993425387648"} | |
}""" + offset + """ | |
) { | |
nodes { | |
id | |
assetId | |
to | |
from | |
balance | |
} | |
} | |
}""" | |
while has_more: | |
query = update_inflow_query(offset) | |
transfers = get_transfers(query) | |
for transfer in transfers: | |
inflow_balance += int(transfer['balance']) | |
counter += 1 | |
# update the offset and reset the counter | |
if (counter == 100): | |
offset_count += 100 | |
offset = ", offset: " + str(offset_count) | |
counter = 0 | |
continue | |
if (len(transfers) < 100): | |
counter = 0 | |
offset = "" | |
offset_count = 0 | |
has_more = False | |
break | |
has_more = True | |
while has_more: | |
query = update_outflow_query(offset) | |
transfers = get_transfers(query) | |
for transfer in transfers: | |
outflow_balance += int(transfer['balance']) | |
counter += 1 | |
# update the offset and reset the counter | |
if (counter == 100): | |
offset_count += 100 | |
offset = ", offset: " + str(offset_count) | |
counter = 0 | |
continue | |
if (len(transfers) < 100): | |
has_more = False | |
break | |
# for moonbeam the below calculation is 10 ** -10 | |
print("OUTFLOW: ", outflow_balance * 10 ** -12, " INFLOW: ", inflow_balance * 10 ** -12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment