Skip to content

Instantly share code, notes, and snippets.

@garethtdavies
Last active May 17, 2023 02:27
Show Gist options
  • Save garethtdavies/47be69b6ef8fd4f8052ffaf968925fe1 to your computer and use it in GitHub Desktop.
Save garethtdavies/47be69b6ef8fd4f8052ffaf968925fe1 to your computer and use it in GitHub Desktop.
An analysis of MIP1 results
# This script replicates the Granola dashboard
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
# Select your transport with a defined url endpoint
transport = AIOHTTPTransport(url="https://graphql.minaexplorer.com")
# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)
# Get all memos that fit the MIP criteria (it appears allowing for some variation e.g. MIP1 mip1 no MIP1 NO MIP1)
query = gql("""
query MIP1 {
transactions(limit: 10000, query: {canonical: true, OR: [{memo: "E4YVPwLUQ8euGfXBeKuTSDmXfw3SyS1tj6nzTR3jD13VcoG7Geba9"}, {memo: "E4YVe5wR9SWMBYG1SZH9fZsCtHUt5QghXbevZVJ3WdNjfbYRBaffD"}, {memo: "E4YbUmaZZqAoU2bQ1NCy2JTJ764hF4hbpzhf2zbJUXhLLmxCNTDDH"}, {memo: "E4YbEczLn4C3jKtgYuTwyZvUmf7YZvDZZdVJVhDJgraJCun84nvHo"}], dateTime_gte: "2023-01-04T16:00:00Z", dateTime_lte: "2023-01-14T08:30:00Z"}, sortBy: NONCE_DESC) {
memo
canonical
from
to
hash
blockHeight
dateTime
}
}
""")
result = client.execute(query)
votes = result["transactions"]
print("All votes: " + str(len(votes)))
# Counters
mip1 = 0
mip1_stake = 0
nomip1 = 0
nomip1_stake = 0
collection = []
# Loop through all votes to check if they meet the criteria
for vote in votes:
# This must be a transaction to yourself
if vote["from"] == vote["to"]:
if vote["memo"] == "E4YVPwLUQ8euGfXBeKuTSDmXfw3SyS1tj6nzTR3jD13VcoG7Geba9" or vote[
"memo"] == "E4YVe5wR9SWMBYG1SZH9fZsCtHUt5QghXbevZVJ3WdNjfbYRBaffD":
collection.append(
[vote["blockHeight"], vote["dateTime"], vote["from"], "MIP1"])
elif vote["memo"] == "E4YbUmaZZqAoU2bQ1NCy2JTJ764hF4hbpzhf2zbJUXhLLmxCNTDDH" or vote[
"memo"] == "E4YbEczLn4C3jKtgYuTwyZvUmf7YZvDZZdVJVhDJgraJCun84nvHo":
collection.append([
vote["blockHeight"], vote["dateTime"], vote["from"], "noMIP1"
])
print("All valid votes: " + str(len(collection)))
latest_collection = {}
for k in collection:
# Just take the first instance, as we are sorting by nonce we must get the latest valid vote
if k[2] not in latest_collection:
latest_collection[k[2]] = k
#print(latest_collection.values())
#exit()
print("Votes no dupes: " + str(len(latest_collection)))
for l in latest_collection.values():
# Get the stake of the account but only count if same as delegated account
query2 = gql("""
query nextLedgerStakes {{
nextstakes(query: {{public_key: "{publicKey}" }}) {{
balance
delegate
public_key
nextDelegationTotals {{
countDelegates
totalDelegated
}}
}}
}}
""".format(publicKey=l[2]))
result2 = client.execute(query2)
balances = result2["nextstakes"]
if not balances: # Temp as might not yet be in the next staking ledger during testing
pass
else:
if l[3] == "MIP1" and balances[0]["delegate"] == l[2]:
mip1 += 1
mip1_stake += balances[0]["nextDelegationTotals"]["totalDelegated"]
print("MIP1 " + l[2],
balances[0]["nextDelegationTotals"]["totalDelegated"])
elif l[3] == "noMIP1" and balances[0]["delegate"] == l[2]:
nomip1 += 1
nomip1_stake += balances[0]["nextDelegationTotals"][
"totalDelegated"]
print("noMIP1 " + l[2],
balances[0]["nextDelegationTotals"]["totalDelegated"])
# this is the case where the delegator has delegated their account but still has someone delegating
elif l[3] == "MIP1" and balances[0]["nextDelegationTotals"]["totalDelegated"] is not None:
mip1 += 1
mip1_stake += balances[0]["nextDelegationTotals"]["totalDelegated"]
print("MIP1 " + l[2],
balances[0]["nextDelegationTotals"]["totalDelegated"])
elif l[3] == "noMIP1" and balances[0]["nextDelegationTotals"]["totalDelegated"] is not None:
nomip1 += 1
nomip1_stake += balances[0]["nextDelegationTotals"]["totalDelegated"]
print("noMIP1 " + l[2],
balances[0]["nextDelegationTotals"]["totalDelegated"])
print("Counted votes: ", mip1 + nomip1)
print("MIP1: ", mip1, round(mip1_stake, 0))
print("no MIP1: ", nomip1, round(nomip1_stake, 0))
@garethtdavies
Copy link
Author

Apparently for future versions all potential misspellings are allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment