A Pen by mertcanaltin on CodePen.
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 subprocess | |
import json | |
LAMPORTS_PER_SOL = 1_000_000_000 | |
print("Running the Solana stakes command...") | |
result = subprocess.run(['solana', 'stakes', '--withdraw-authority', '4ZJhPQAgUseCsWhKvJLTmmRRUV74fdoTpQLNfKoekbPY', '--output', 'json'], capture_output=True, text=True) | |
print("Finished Running the Solana stakes command...") | |
# Load the captured JSON output | |
if result.returncode == 0: |
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 | |
from collections import defaultdict | |
# weights should sum to 100 | |
def HHI(weights): | |
return sum([x**2 for x in weights]) | |
MAX_HHI_SCORE = 10000 | |
#NE is the number of nodes with a perfectly even distribution with an equivalent HHI score. | |
def NE(HHI_score): | |
return 1 / (HHI_score / MAX_HHI_SCORE) |
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
## Must have solana CLI installed for this to work | |
import json | |
import subprocess | |
command_output = subprocess.check_output(["solana", "stakes", "--output", "json"]) | |
stakes = json.loads(command_output) | |
total_sfdp_stake = 0 | |
for stake in stakes: |