Skip to content

Instantly share code, notes, and snippets.

@ydm
Created January 18, 2024 13:59
Show Gist options
  • Save ydm/2d57568d9999206e81acb9b3464604f6 to your computer and use it in GitHub Desktop.
Save ydm/2d57568d9999206e81acb9b3464604f6 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 90,
"id": "b75c9c09-5b8c-49ba-b7b7-5c5c24dc456a",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from datetime import datetime, timedelta, timezone\n",
"from decimal import Decimal\n",
"from typing import Any\n",
"\n",
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 81,
"id": "abe4759c-0c64-4283-a906-428fac34416b",
"metadata": {},
"outputs": [],
"source": [
"with open('stakingRewardsSnapshots.json', 'r', encoding='ascii') as f:\n",
" xs = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 82,
"id": "7c7aea74-0e81-4bb8-829d-13b1cdce1996",
"metadata": {},
"outputs": [],
"source": [
"xs = pd.DataFrame(xs)"
]
},
{
"cell_type": "code",
"execution_count": 83,
"id": "26870d8a-8cce-47b0-a9d2-c6e9730e769c",
"metadata": {},
"outputs": [],
"source": [
"for c in xs.columns:\n",
" xs[c] = xs[c].map(Decimal)"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "b1f9adc1-6008-41ad-92d9-564e22d59605",
"metadata": {},
"outputs": [],
"source": [
"# def fromtimestamp(s: Any) -> datetime:\n",
"# return datetime.utcfromtimestamp(int(s)).replace(tzinfo=timezone.utc)\n",
"\n",
"# xs['date'] = pd.to_datetime(xs['createdAtTimestamp'].map(fromtimestamp))"
]
},
{
"cell_type": "code",
"execution_count": 84,
"id": "359d4865-e725-4c93-8a89-112a74d0d2a4",
"metadata": {},
"outputs": [],
"source": [
"xs['net'] = xs['periodTotalRewards'].sub(xs['periodProtocolRewards'])"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "ef2b1ed2-0d8d-4b83-804a-901cfcaeea1f",
"metadata": {},
"outputs": [],
"source": [
"xs = xs.drop(['id', 'periodProtocolRewards', 'createdAtBlock', 'createdAtTimestamp'], axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "82d3f33d-c8ca-4ba2-b302-0f0972f93bb0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>periodTotalRewards</th>\n",
" <th>periodDuration</th>\n",
" <th>totalStaked</th>\n",
" <th>net</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>9612479436968609145</td>\n",
" <td>263136</td>\n",
" <td>30452205383625944950861</td>\n",
" <td>8843481082011120414</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4199851054506396780</td>\n",
" <td>167832</td>\n",
" <td>30452205383625944950861</td>\n",
" <td>3863862970145885038</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2324144786224226178</td>\n",
" <td>87900</td>\n",
" <td>30452205383625944950861</td>\n",
" <td>2138213203326288084</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2105876454087991945</td>\n",
" <td>87852</td>\n",
" <td>30452205383625944950861</td>\n",
" <td>1937406337760952590</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2161213237022272776</td>\n",
" <td>88212</td>\n",
" <td>30452205383625944950861</td>\n",
" <td>1988316178060490954</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" periodTotalRewards periodDuration totalStaked \\\n",
"0 9612479436968609145 263136 30452205383625944950861 \n",
"1 4199851054506396780 167832 30452205383625944950861 \n",
"2 2324144786224226178 87900 30452205383625944950861 \n",
"3 2105876454087991945 87852 30452205383625944950861 \n",
"4 2161213237022272776 88212 30452205383625944950861 \n",
"\n",
" net \n",
"0 8843481082011120414 \n",
"1 3863862970145885038 \n",
"2 2138213203326288084 \n",
"3 1937406337760952590 \n",
"4 1988316178060490954 "
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs.head()"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "dcad83d7-af9b-40b3-98e9-0fdf190977d0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.14982814999456"
]
},
"execution_count": 93,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rate = xs['periodTotalRewards'].div(xs['totalStaked'])\n",
"d = int(xs['periodDuration'].sum()) / 60/60/24\n",
"y = float(rate.add(1).product())\n",
"(np.power(y, 365/d) - 1) * 100"
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "a8651605-8218-4655-993b-769f3e898c07",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.8942465871807377"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rate = xs['net'].div(xs['totalStaked'])\n",
"d = int(xs['periodDuration'].sum()) / 60/60/24\n",
"y = float(rate.add(1).product())\n",
"(np.power(y, 365/d) - 1) * 100"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment