Skip to content

Instantly share code, notes, and snippets.

@garethtdavies
Last active May 17, 2023 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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

garethtdavies commented Jan 12, 2023

Note, this will only work when the next staking ledger is the correct ledger to use.
After the fact, you can just use the regular epoch 46 ledger (as the votes were tallied at the end of epoch 44). So second query would be:

query votingLedgerStakes {{
  stakes(query: {{public_key: "{publicKey}", epoch: 46 }}) {{
    balance
    delegate
    public_key
    nextDelegationTotals {{
      countDelegates
      totalDelegated
    }}
  }}
}}

@garethtdavies
Copy link
Author

garethtdavies commented Jan 17, 2023

All votes: 271
All valid votes: 262
Votes no dupes: 251
MIP1 B62qrQiw9JhUumq457sMxicgQ94Z1WD9JChzJu19kBE8Szb5T8tcUAC 9388991.790018672
MIP1 B62qnXy1f75qq8c6HS2Am88Gk6UyvTHK3iSYh4Hb3nD6DS2eS6wZ4or 72982.649388449
Edge case
MIP1 B62qoXQhp63oNsLSN9Dy7wcF3PzLmdBnnin2rTnNWLbpgF7diABciU6 1017372.312023841
Edge case
MIP1 B62qq6ZYPG5JsjZnGJ3pADmRn6hU6qy13EhraTSymjSgyEDwoDR9Gd6 6332902.546651629
MIP1 B62qs2P91UjdhngetBJ57C56HQ8t5V7ECAYWBvpkaC45ovXNgnzqfG6 3628697.341440566
MIP1 B62qs2Lw5WZNSjd8eHBUZXFYyRjV8oKtrZMFDn1S1Ye62G71xCQJMYM 18435803.06218983
MIP1 B62qqD9f8CGy5QeFj1h3nsit3Zp2GDBntjEoVCdfj4SPQuubRW1CYXp 2132607.610715391
MIP1 B62qpYmDbDJAyADVkJzydoz7QeZy1ZTiWeH1LSuyMxXezvu5mAQi53U 11367197.016358607
MIP1 B62qqch9XkiTS8BLUDSM1sayfXNAtnYnQFChktYG1bfCJkDMUqs98Xr 2573600.510099954
MIP1 B62qoazqR1ag2hDwjkSSm6qV3eJtkiPvVPKhfVyeea7TehBAWu4dWJ5 248872.774693575
MIP1 B62qjok2BD2jB6TArVM1oGDSo16xk1SYGzTwZSjx63WbtZy4BuzPBDj 77952.078530734
MIP1 B62qqpujuZ5W9uGtEwJv9R9yP8475hjFd93D4fVXoVPi9tmAMsQZBhn 2197439.114063051
MIP1 B62qmM9KDeqvu3TVpQStGJARgg7KppxE8UF3xMdtKV9TDc33kSUGug5 2370371.530222545
MIP1 B62qpMcYjgezccPk8NfaSto4jyV3uGU8R24D9uSShMoqr8JdpAv4RKo 2249296.042308708
MIP1 B62qnR2AHmcnyb7v3cVvuZWriEnArx7yMkXBcnzpFQXCmGxAAv4nJSV 121071.622463962
MIP1 B62qqKoxyhPfHY9kw283dafk5jztbbKdH78eDXpNCyj69cmckC8KZqs 1060533.0586674511
MIP1 B62qp6qMf3Do4q4aKqEsLxVpVuXJaRCijtyhsjZBvDSEFUBGXg8Z9cs 2312961.111046771
MIP1 B62qnd1rPUp4aBpjVjCJ3XLXk64WxuM9ff3UkfZoRCkBF8vcyFnXNTs 983141.968897796
MIP1 B62qphpEdBwSycpN67XFjcXSEY9j18chmttFTXYerhTPMX4JkXubWkd 1074329.8336656839
MIP1 B62qjrwcG6cbvartJ63wJQQxYx1aY9N1gh8fhYkG8AwDmwQY42XfG6Y 2183917.292760833
MIP1 B62qj28AitWwLTU3HAhtoW34nJ6LkyHU7XKm5wC84q1RtF4ho1yEgGn 2115082.8463859637
noMIP1 B62qpZQ7xcNpv6zcY75D2y1V4K1DHXVpkbCJAYpPNHgutXAb6o5QSZE 1087441.611491034
MIP1 B62qmDdMwKoMNLHZYqf3c6SJ34FmtP5HpTtFGtbDQGJrDb7cc1HtuYT 2102170.751030251
MIP1 B62qr9jmNyuKG9Zhi1jENgPuswFRRDrkin3tP6D76qx8HNpjke5aUMs 1055335.797897093
MIP1 B62qn2Ne2JGRdbHXdfD8wkA6PTWuBjaxUDQ6QuPAmggrcYjTP3HwWkF 67808.080028607
MIP1 B62qqF2kUvSDw9r4XdukwST3qtqXE1S5oVfMidV4JBr3BFHpGQ3Pd4d 1091749.635148091
MIP1 B62qrnPdz8HpsDJfGHirDLpVrN2VeyeitdaTKBaccWtHpeVW9Hgwi75 88398.38254963001
noMIP1 B62qnTdTtkepo2yfBXCeMp9afk77oo3EKWDNWuvLzEHSZz2gkgr5JHj 2254074.987290769
MIP1 B62qksN97EtNvQGzH2RAgnDR8zLAawhPNE1QzWCgPRcknyL6NJ3CCgJ 158992.988086126
MIP1 B62qoKZLSQT9jJs3kAt7bXtS3tRwZVFkPkdBnvqs6jr9mVismyD7Eey 2200167.950070539
MIP1 B62qpanxZjnQLtZHQfY8VGgCYyE29aDcG7BL2KwkQJbDzaSxwwZqT7i 988711.438660425
MIP1 B62qj7tJG5rxdy1hxo2tPo8xJGN3qDHwQdPqq7UMH6xGfhyfUikyKV8 85766.012896518
MIP1 B62qkBqSkXgkirtU3n8HJ9YgwHh3vUD6kGJ5ZRkQYGNPeL5xYL2tL1L 2689796.963342801
MIP1 B62qn7HrKKt5ia1dvGYHuvuFGLdwNSXUSAERQgvS2yZbZvVaK5biQef 1022288.811977227
MIP1 B62qqDDZYhfU7mNcQKJfWHDJ3JjVTi6dG32oWiWY3KrrX4mSMLdEuUj 50011.549474612
MIP1 B62qrae3PEBj66KV2obWnzVxMjDCMuFWnyzxEzvLkQutaKPmWtfUPm3 2431945.480014706
MIP1 B62qijDC2gCTtcqYGnUAc9YgH2Uw4fzr8xEKKL4faZmWyAypgEe3oWC 13986521.358209515
MIP1 B62qrr4HsyQDc8BHf875XHizovkMqfXYKFxqxdcLPNahHnz1GZqCmXL 82123.327263556
MIP1 B62qqSDsgPh4c6E4DQw1Rbo1dCtZJMivQtXTDJcL58m95pydVupDDRE 2222942.968477403
MIP1 B62qnR6HKx34NCyDkSeRcJ44KATjUCs4xmQYDbwTXPJPQ4J6ebfeQe4 2681269.411045238
MIP1 B62qjhHENLQeq9KCTHZWEBQU6hR36JBkHqv9BQR7TDeWN4a5qxuoHoD 181.602743604
MIP1 B62qid146JcZD6eSrDt2p9iqrQC6eTxRxYB5HUyg5XpTezsqP73WWRR 1064301.6507700349
MIP1 B62qm8gXiEozEg8LggpTedU7qpreyZoMaciiqLGVXECnuWsDfoF3UDg 982598.420503462
MIP1 B62qrJ6V72vUoqTnJUsXwBFbCU2cCk42To4mmRRY19NiGMZqJuYLLJP 86651.164475008
MIP1 B62qpZTtpZL7QobzPX97h1f2CNFchXoXc4NJUZL1xdvNqTdwR5NCbkZ 383864.033265585
MIP1 B62qpge4uMq4Vv5Rvc8Gw9qSquUYd6xoW1pz7HQkMSHm6h1o7pvLPAN 49350863.83483966
MIP1 B62qr41Mf7gCaRXN2dn8yBCe5D5bedQ82gyG2ELtkx5Vcd3HNcnVhxE 2175971.163168168
MIP1 B62qoVopcNoQPFydweGWUBnJJbrokkebVDiWGmAzYoaLysrFfzNCbya 1181632.2213090009
noMIP1 B62qnVMHrtGPVRN3SrwyDzjbgBQhaFSgv16SAAFe5ddm2369KKzRn6d 123560.236955428
MIP1 B62qkoS4WmwwZXQyiNhyKCuKhzvcbwgwcca9aYQDdzCoAyWgZqxSjze 2.7528
MIP1 B62qqV16g8s744GHM6Dph1uhW4fggYwyvtDnVSoRUyYqNvTir3Rqqzx 26368732.40670785
MIP1 B62qpDR99MxbrKqbpsHKJmpAdu9SvuCA6Gy6AWQoG65QXNjDoCvgTfz 0.077
MIP1 B62qrgnUUduZy2z7zT8qCV8ngTJfSS1rK3Wh22SHUmrse3Tfqvrhx8q 89508.868517595
MIP1 B62qp6HmxzW5XXwCMiyZiJREoJ4b7omkNuCJiThVLNM1P3u1s1a3qzp 988607.090833627
MIP1 B62qq3TQ8AP7MFYPVtMx5tZGF3kWLJukfwG1A1RGvaBW1jfTPTkDBW6 22222699.64231692
MIP1 B62qjhiEXP45KEk8Fch4FnYJQ7UMMfiR3hq9ZeMUZ8ia3MbfEteSYDg 1368675.409333954
MIP1 B62qpaY38GFqhUcLdA1c5EMv46xwWBxgdWM2ddEM5guH6bi81SHXFJK 5832.99967458
MIP1 B62qpGgX3Dh7ih38xfCdkRrYxMbKkoVSw8UkpQh2NPZiwqhK3u84CUV 25509
MIP1 B62qnYBehkVZzgJBCC5yhFyF2L7mMRPsVnKW2xpcWFVuQYRVgoqwDCS 2344973.309133775
MIP1 B62qnSjFGjZ39C8iDGMErbFSX5NvKVyvjvHxvf7U1oDmyeU6ynxXZZF 6249313.56683611
MIP1 B62qjL2UtdqaekzYDLjhYm7GdxzKpL7P2GwgaL2MRjZfuFaU9G5JVrb 0.9899
MIP1 B62qnvyPyVq9MzKzfDvCz6CWootRZjedeLog3uMrJMbFQBCYZj5ww3A 0
MIP1 B62qqrHGT2vQewqYgoBwGyunwwHoztjXjeN1JNST4vXthKYwAdvXSyX 3.9989
MIP1 B62qmLRLxC5Fx3cRmHDwKGq6psCbmXAYE1UsS4Z1foqrXCTtJuvTbbL 2262176.7802148107
MIP1 B62qrsCqquyu7DoLTdZMzZcBCW6xqt5zvVrPP7LojtwLVEpv7SjXN2r 0.3896
MIP1 B62qqYgjPA3VwKEnmWy7Cwp9fVPsZskTXQTKQdmw8qqKgznzarSEfXM 1054670.898275397
MIP1 B62qoE6byEu2xrD3ZiWzciKfpC3vAi4xR1rtViSNneovzcAMzcidbgb 49.999
noMIP1 B62qqNUt1QBC1KgCyzhKr1Q95wkEvZXWEnSH4CLvUSHZC7XEM7RtDuK 2.019
Counted votes: 70
MIP1: 66 224148426.55565
no MIP1: 4 3465078.85474

@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