Skip to content

Instantly share code, notes, and snippets.

@laboon
Created September 20, 2023 08:50
Show Gist options
  • Save laboon/54709b830dffc54ce5f6d5554b82767a to your computer and use it in GitHub Desktop.
Save laboon/54709b830dffc54ce5f6d5554b82767a to your computer and use it in GitHub Desktop.
Quick check of inflation
import json, os, sys
def plancks_to_dots(plancks):
return float(int(plancks) / 10_000_000_000)
def calculate_ideal_staking_rate(num_parachains):
p = min(num_parachains, 60) / 200
ideal_stake = 0.75 - p
return ideal_stake
# EXECUTION STARTS HERE
# Make sure we have a Subscan API key entered as a command line argument.
# If you don't have one, you can request one here: https://pro.subscan.io/
if (len(sys.argv) >= 3):
SUBSCAN_API_KEY = sys.argv[1]
NUM_PARACHAINS = int(sys.argv[2])
else:
sys.exit("You need to enter a Subscan API key and the number of non-system parachains.")
NUM_ERAS = 1
# Call Subscan and get the last 10 eras worth of staking data
SUBSCAN_CURL_COMMAND = """curl -X POST 'https://polkadot.api.subscan.io/api/scan/events' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: """ + SUBSCAN_API_KEY + """' \
--data-raw '{
"row": """ + str(NUM_ERAS) + """,
"page": 1,
"module": "staking",
"call": "EraPaid"
}'
"""
s = os.popen(SUBSCAN_CURL_COMMAND)
staking_data = json.loads(s.read())
ideal_staking_rate = calculate_ideal_staking_rate(NUM_PARACHAINS)
print("The ideal staking rate is: " + str(ideal_staking_rate * 100) + "%.\n")
# Feel free to turn this into a loop to get more eras of staking data
# It can then be averaged out etc.
params_data = json.loads(str(staking_data["data"]["events"][0]["params"]))
era = params_data[0]["value"]
payout = params_data[1]["value"]
remainder = params_data[2]["value"]
print("Actual data last era ( " + str(era) + " ) :")
print("\tPayout : " + str(plancks_to_dots(payout)))
print("\tRemainder : " + str(plancks_to_dots(remainder)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment