Skip to content

Instantly share code, notes, and snippets.

@benjaminion
Created September 12, 2025 11:06
Show Gist options
  • Select an option

  • Save benjaminion/962bb05e083edb558e03217a51c57ec6 to your computer and use it in GitHub Desktop.

Select an option

Save benjaminion/962bb05e083edb558e03217a51c57ec6 to your computer and use it in GitHub Desktop.
Megapot data download
#!/usr/bin/python3
import sys
import json
import urllib3
MEGAPOT = '0xbEDd4F2beBE9E3E636161E644759f3cbe3d51B95'
GET_ACTIVE = '0x92646c20'
GET_INFO = '0x470328b5'
NODE_API = 'https://open-platform.nodereal.io/<API_KEY>/base/'
USDC = 1 / 1000000
http = urllib3.PoolManager()
def eth_call(contract, method, data):
json_data = {
"method": "eth_call",
"params": [
{
"to": contract,
"data": method + data
},
"latest"
],
"id": 1,
"jsonrpc": "2.0"
}
response = http.request(
"POST",
NODE_API,
headers = {'Content-Type': 'application/json'},
body = json.dumps(json_data).encode('utf-8')
)
json_response = json.loads(response.data)
return None if 'error' in json_response else json_response['result']
for i in range(250):
# Accounts are numbered sequentially. This gets the address of account i.
r = eth_call(MEGAPOT, GET_ACTIVE, format(i, '064x'))
# We don't know in advance how many accounts there are, except that 250 is the max.
if (r == None):
sys.exit()
# Given an account's address, get its info.
s = eth_call(MEGAPOT, GET_INFO, r[-64:])
address = '0x' + r[-40:]
principal = int(s[2:66], 16) * USDC
stake = int(s[66:130], 16) * USDC
risk = int(s[130:194], 16)
print(f'{address},{principal:.6f},{stake:.6f},{principal+stake:.6f},{risk}')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment