Snapshot Code

This is a draft of the Python script that will be run to create a whitelist of eligible addresses for early minting. If it is changed we will update it here.

This script should produce a list of addresses that have at least 5 Luna staked to bonded validators.

import requests
import json

# Returns array of validators operator addresses filtered by status.
# string[]
def get_validators(status = None):
    r = requests.get('https://fcd.terra.dev/v1/staking/validators')
    validators = r.json()
    if status:
        return [validator['operatorAddress'] for validator in validators if validator['status'] == status]
    return [validator['operatorAddress'] for validator in validators]


# Returns array of delegators for a given validators operator address.
# [
#     {
#         "address": string,
#         "amount": string,
#         "weight": string
#     }
#     ...
# ]
def get_validator_delegators(operator_address, limit=5000):
    newDelegates = None
    allDelegates = []
    page = 1
    while newDelegates == None or len(newDelegates) == limit:
        print('Page {}...'.format(page))
        r = requests.get('https://fcd.terra.dev/v1/staking/validators/{0}/delegators'.format(operator_address), {'limit': limit, 'page': page})
        newDelegates = r.json()['delegators']
        allDelegates.extend(newDelegates)
        page += 1
    print('Total delegators: {}'.format(len(allDelegates)))
    return allDelegates


# Finds all delegators and total luna staked.
def main(stake_limit_uluna, validator_status = None):
    address_staked_luna = {}
    op_addresses = get_validators(validator_status)
    print('Found {} validators...'.format(len(op_addresses)))
    for i in range(len(op_addresses)):
        op_address = op_addresses[i]
        print('Gathering {} delegators...'.format(op_address))
        delegators = get_validator_delegators(op_address)
        for delegator in delegators:
            delegator_address = delegator['address']
            staked_luna = float(delegator['amount'])
            if delegator_address in address_staked_luna:
                address_staked_luna[delegator_address] += staked_luna
            else:
                address_staked_luna[delegator_address] = staked_luna
        print('Complete {0}/{1}'.format(i+1, len(op_addresses)))
    
    print('Total Terra Delegators: {}'.format(len(address_staked_luna)))

    staked_n_luna = []
    for key in address_staked_luna:
        if address_staked_luna[key] > stake_limit_uluna:
            staked_n_luna.append(key)
    print('Staked over {0} uluna: {1}'.format(stake_limit_uluna, len(staked_n_luna)))

    json_data = []
    for key in address_staked_luna:
        if address_staked_luna[key] > stake_limit_uluna:
            json_data.append({
                'address': key,
                'uluna_staked': address_staked_luna[key]
            })
    with open('snapshot.json', 'w') as f:
        f.write(json.dumps(json_data, indent=4))

if __name__ == '__main__':
    main(5000000, 'active')

Last updated