Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pussygift #56

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,96 @@ Since the main Gift cannot be unlocked until we reach the goal (of 100k citizens
Soon each citizen who claims the gift will receive 1A and 1V for each claimed address.
This will enable your contribution to the development of a bootloader for superintelligence immediately.
[Small Birthday Gift](small_birthday_gift_A&V.ipynb)

# pussyGift

## Gift per Segment

- Bostrom Stakers: 10e16 PUSSY
- Desmos Stakers: 10e16 PUSSY
- ChiHuaHua, CosmosHub, Evmos, Gravity, Juno, Osmosis, Stargaze, Terra and Umee Stakers: 75e16 PUSSY

## Rules

<table style="text-align: left">
<thead style="text-align: center">
<tr>
<th rowspan=2>Rule</th>
<th colspan=3>Level</th>
<th rowspan=2>Calculations</th>
</tr>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
<tbody style="text-align: center">
<tr>
<td style="text-align: left"> Bostrom Staking Balance </td>
<td style="text-align: center"> > 10,000 BOOT </td>
<td style="text-align: center"> > 1,383,480,819 BOOT </td>
<td style="text-align: center"> > 144,305,883,038 BOOT </td>
<td rowspan=11 style="text-align: center"> <a href="pussygift.ipynb">Pussy Gift. BOOT, ATOM, OSMO, LUNA, HUAHUA, JUNO, DSM, STARS, UMEE, GRAV and EVMOS Analysis</a> </td>
</tr>
<tr>
<td style="text-align: left"> ChiHuaHua Staking Balance </td>
<td style="text-align: center"> > 10,000 HUAHUA </td>
<td style="text-align: center"> > 1,805,215 HUAHUA </td>
<td style="text-align: center"> > 25,590,943 HUAHUA </td>
</tr>
<tr>
<td style="text-align: left"> CosmosHub Staking Balance </td>
<td style="text-align: center"> > 0.1 ATOM </td>
<td style="text-align: center"> > 164 ATOM </td>
<td style="text-align: center"> > 2,711 ATOM </td>
</tr>
<tr>
<td style="text-align: left"> Desmos Staking Balance </td>
<td style="text-align: center"> > 30 DSM </td>
<td style="text-align: center"> > 2,125 DSM </td>
<td style="text-align: center"> > 142,856 DSM </td>
</tr>
<tr>
<td style="text-align: left"> Evmos Staking Balance </td>
<td style="text-align: center"> > 2 EVMOS </td>
<td style="text-align: center"> > 760 EVMOS </td>
<td style="text-align: center"> > 8,865 EVMOS </td>
</tr>
<tr>
<td style="text-align: left"> Gravity Staking Balance </td>
<td style="text-align: center"> > 100 GRAV </td>
<td style="text-align: center"> > 14,240 GRAV </td>
<td style="text-align: center"> > 930,754 GRAV </td>
</tr>
<tr>
<td style="text-align: left"> Juno Staking Balance </td>
<td style="text-align: center"> > 0.5 JUNO </td>
<td style="text-align: center"> > 201 JUNO </td>
<td style="text-align: center"> > 4,136 JUNO </td>
</tr>
<tr>
<td style="text-align: left"> Osmosis Staking and Liquidity Balance</td>
<td style="text-align: center"> > 1 OSMO </td>
<td style="text-align: center"> > 1,498 OSMO </td>
<td style="text-align: center"> > 38,098 OSMO </td>
</tr>
<tr>
<td style="text-align: left"> Stargaze Staking Balance </td>
<td style="text-align: center"> > 20 STAR </td>
<td style="text-align: center"> > 6,147 STAR </td>
<td style="text-align: center"> > 125,126 STAR </td>
</tr>
<tr>
<td style="text-align: left"> Terra Balance </td>
<td style="text-align: center"> > 1 LUNA </td>
<td style="text-align: center"> > 387 LUNA </td>
<td style="text-align: center"> > 6,397 LUNA </td>
</tr>
<tr>
<td style="text-align: left"> Umee Staking Balance </td>
<td style="text-align: center"> > 100 UMEE </td>
<td style="text-align: center"> > 10,571 UMEE </td>
<td style="text-align: center"> > 65,552 UMEE </td>
</tr>
</table>
1,178 changes: 1,178 additions & 0 deletions pussygift.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions small_birthday_gift_A&V.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
{
"cell_type": "markdown",
"source": [
"## small gift for birthday\n",
"## Small Gift for Bostrom's Birthday\n",
"\n",
"dear friends!\n",
"\n",
"recently bostrom had his first birthday!\n",
"\n",
"since the main gift cannot be unlocked until we reach the goal, the cybercongress decided to make a small gift\n",
"since the main Gift cannot be unlocked until we reach the goal (of 100k citizens), the cyber~congress decided to give a small gift.\n",
"\n",
"soon each citizen who claims the gift will receive 1A and 1V for each claimed address\n",
"soon each citizen who claims the gift will receive 1A and 1V for each claimed address.\n",
"\n",
"this will enable your contribution to the development of a bootloader for superintelligence right now\n",
"this will enable your contribution to the development of a bootloader for superintelligence immediately.\n",
"\n",
"we thank everyone for participating"
],
Expand Down
96 changes: 53 additions & 43 deletions src/extractor_cosmos_sdk_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pandas as pd
import json
from math import floor
from math import floor, log10
from typing import Optional


def get_coin_balance(balance: list, coin: str = 'uatom', decimals: int = 6) -> float:
def get_coin_balance(balance: list, coin: str, decimals: int) -> float:
for _balance_item in balance:
if _balance_item['denom'] == coin:
return float(_balance_item['amount']) / 10 ** decimals
Expand All @@ -13,22 +14,22 @@ def get_coin_balance(balance: list, coin: str = 'uatom', decimals: int = 6) -> f
def get_osmo_prices(genesis_snapshot: json) -> [dict, pd.DataFrame]:
# Get pools data and all denoms from snapshot
_pools = genesis_snapshot["app_state"]['gamm']['pools']
_pool_denoms = [pool['totalShares']['denom'] for pool in _pools]
_token_denoms = [token['token']['denom'] for pool in _pools for token in pool['poolAssets']]
_pool_denoms = [pool['total_shares']['denom'] for pool in _pools]
_token_denoms = [token['token']['denom'] for pool in _pools for token in pool['pool_assets']]
_denoms = set(_token_denoms + _pool_denoms)

_price_df = pd.DataFrame(columns=_denoms, index=_denoms)
_osmo_price_dict = {}

for _pool in _pools:
_pool_denom = _pool['totalShares']['denom']
_pool_supply = int(_pool['totalShares']['amount'])
_pool_assets = _pool['poolAssets']
_pool_denom = _pool['total_shares']['denom']
_pool_supply = int(_pool['total_shares']['amount'])
_pool_assets = _pool['pool_assets']
_item_denoms = [token['token']['denom'] for token in _pool_assets]
_item_amounts = [int(token['token']['amount']) for token in _pool_assets]

for _denom1, _amount1 in zip(_item_denoms, _item_amounts):
_price_df.loc[_pool_denom, _denom1] = _amount1 / _pool_supply * 2
_price_df.loc[_pool_denom, _denom1] = _amount1 / _pool_supply * 2 if _pool_supply > 0 else 0
_price_df.loc[_denom1, _pool_denom] = _pool_supply / _amount1 / 2
for _denom2, _amount2 in zip(_item_denoms, _item_amounts):
_price_df.loc[_denom2, _denom1] = _amount1 / _amount2
Expand Down Expand Up @@ -57,27 +58,27 @@ def get_osmo_prices(genesis_snapshot: json) -> [dict, pd.DataFrame]:
return _osmo_price_dict, _price_df


def get_liquidity_from_balance(balances: list, price_dict: dict, decimals: int = 6) -> float:
def get_liquidity_from_balance(balances: list, price_dict: dict, decimals: int) -> float:
_amount = 0.0
for _balance in balances:
if _balance['denom'][:10] == 'gamm/pool/':
_amount += int(_balance['amount']) * price_dict[_balance['denom']]
return _amount / 10 ** decimals


def get_liquidity(genesis_snapshot: json) -> pd.DataFrame:
def get_liquidity(genesis_snapshot: json, decimals: int) -> pd.DataFrame:
_osmo_price_dict, _ = get_osmo_prices(genesis_snapshot=genesis_snapshot)

# Get balance of unstaked pools coins
_available_balances_df = pd.DataFrame(genesis_snapshot["app_state"]['bank']['balances'])
_available_balances_df['unstaked_liquidity'] = _available_balances_df['coins'].map(
lambda x: get_liquidity_from_balance(balances=x, price_dict=_osmo_price_dict))
lambda x: get_liquidity_from_balance(balances=x, price_dict=_osmo_price_dict, decimals=decimals))
_available_balances_df = _available_balances_df.groupby('address')['unstaked_liquidity'].agg(sum).reset_index()

# Get balance of staked pools coins
_lockup_df = pd.DataFrame(genesis_snapshot["app_state"]['lockup']['locks'])
_lockup_df['staked_liquidity'] = _lockup_df['coins'].map(
lambda x: get_liquidity_from_balance(balances=x, price_dict=_osmo_price_dict))
lambda x: get_liquidity_from_balance(balances=x, price_dict=_osmo_price_dict, decimals=decimals))
_lockup_df.rename(columns={'owner': 'address'}, inplace=True)
_lockup_df = _lockup_df.groupby('address')['staked_liquidity'].agg(sum).reset_index()

Expand All @@ -90,16 +91,16 @@ def get_liquidity(genesis_snapshot: json) -> pd.DataFrame:
return _liquidity_df[_liquidity_df.liquidity > 0]


def get_available_balances(genesis_snapshot: json, coin: str) -> pd.DataFrame:
def get_available_balances(genesis_snapshot: json, coin: str, decimals: int) -> pd.DataFrame:
_available_balances_df = pd.DataFrame(genesis_snapshot["app_state"]['bank']['balances'])
_available_balances_df.loc[:, 'available_coin'] = _available_balances_df.coins.map(
lambda x: get_coin_balance(balance=x, coin=coin))
lambda x: get_coin_balance(balance=x, coin=coin, decimals=decimals))
_available_balances_df = _available_balances_df[_available_balances_df.available_coin != 0]
_available_balances_df['address'] = _available_balances_df['address'].map(lambda x: x.lower())
return _available_balances_df.groupby('address')['available_coin'].agg(sum).reset_index()


def get_delegated_balances(genesis_snapshot: json, decimals: int = 6) -> pd.DataFrame:
def get_delegated_balances(genesis_snapshot: json, decimals: int) -> pd.DataFrame:
_delegated_balances_df = \
pd.DataFrame(genesis_snapshot["app_state"]['staking']['delegations'])[['delegator_address', 'shares']] \
.rename(columns={'delegator_address': 'address'})
Expand All @@ -109,56 +110,65 @@ def get_delegated_balances(genesis_snapshot: json, decimals: int = 6) -> pd.Data
return _delegated_balances_df.groupby('address')['delegated_coin'].agg(sum).reset_index()


def get_unbonding_delegations(genesis_snapshot: json, decimals: int = 6) -> pd.DataFrame:
def get_unbonding_delegations(genesis_snapshot: json, decimals: int) -> pd.DataFrame:
return pd.DataFrame(
[[unbonding_delegation['delegator_address'].lower(),
sum([float(entry['balance']) for entry in unbonding_delegation['entries']]) / 10 ** decimals]
for unbonding_delegation in genesis_snapshot["app_state"]['staking']['unbonding_delegations']],
columns=['address', 'unbonding_coin']).groupby('address')['unbonding_coin'].agg(sum).reset_index()


def get_balances(snapshot_url: str, coin: str) -> pd.DataFrame:
def get_balances(snapshot_url: str, coin: str, decimals: int = 6, balances_items: Optional[list] = None,
rounded_function=None) -> pd.DataFrame:
if balances_items is None:
balances_items = ['available', 'delegated', 'unbonding', 'liquidity']
if rounded_function is None:
rounded_function = lambda x: floor(10 ** (
round(log10(x), 2)) * 10) / 10 if x > 0.1 else 0.05 # floor(10 ** (round(log10(x), 2))) if x > 1 else 0.5

with open(snapshot_url) as _f:
_genesis_snapshot = json.load(_f)

# Get Available, Delegated balances and Unbonding delegations
_available_balances_df = get_available_balances(genesis_snapshot=_genesis_snapshot, coin=coin)
_delegated_balances_df = get_delegated_balances(genesis_snapshot=_genesis_snapshot)
_unbonding_delegations_df = get_unbonding_delegations(genesis_snapshot=_genesis_snapshot)

# Get module and pool addresses
_module_addresses_list = \
[item['base_account']['address'] for item in _genesis_snapshot['app_state']['auth']['accounts']
if item['@type'] in ('/cosmos.auth.v1beta1.ModuleAccount', '/osmosis.gamm.v1beta1.Pool')]

# Merge Available and Delegated balances
_balances_df = \
_available_balances_df[['address', 'available_coin']].merge(
_balances_df = pd.DataFrame(columns=['address'])
if 'available' in balances_items:
_available_balances_df = get_available_balances(genesis_snapshot=_genesis_snapshot, coin=coin,
decimals=decimals)
_balances_df = _balances_df.merge(
_available_balances_df[['address', 'available_coin']],
how='outer',
on='address').fillna(0)
if 'delegated' in balances_items:
_delegated_balances_df = get_delegated_balances(genesis_snapshot=_genesis_snapshot, decimals=decimals)
_balances_df = _balances_df.merge(
_delegated_balances_df[['address', 'delegated_coin']],
how='outer',
on='address'
).merge(
on='address').fillna(0)
if 'unbonding' in balances_items:
_unbonding_delegations_df = get_unbonding_delegations(genesis_snapshot=_genesis_snapshot, decimals=decimals)
_balances_df = _balances_df.merge(
_unbonding_delegations_df[['address', 'unbonding_coin']],
how='outer',
on='address'
).fillna(0)

on='address').fillna(0)
# Add Osmosis liquidity
if coin == 'uosmo':
_liquidity_df = get_liquidity(genesis_snapshot=_genesis_snapshot)
if coin == 'uosmo' and 'liquidity' in balances_items:
_liquidity_df = get_liquidity(genesis_snapshot=_genesis_snapshot, decimals=decimals)
_balances_df = \
_balances_df.merge(
_liquidity_df,
how='outer',
on='address'
).fillna(0)
_balances_df.loc[:, 'balance_coin'] = _balances_df[
['available_coin', 'delegated_coin', 'unbonding_coin', 'liquidity']].sum(axis=1)
else:
_balances_df.loc[:, 'balance_coin'] = _balances_df[['available_coin', 'delegated_coin', 'unbonding_coin']].sum(
axis=1)

# Get module and pool addresses
_module_addresses_list = \
[item['base_account']['address'] for item in _genesis_snapshot['app_state']['auth']['accounts']
if item['@type'] in ('/cosmos.auth.v1beta1.ModuleAccount', '/osmosis.gamm.v1beta1.Pool')]

_balances_df.loc[:, 'balance_coin'] = \
_balances_df.drop(columns=['address']).sum(axis=1)

# Round balance and remove module, pool addresses
_balances_df.loc[:, 'balance_coin_rounded'] = \
_balances_df.balance_coin.map(lambda x: floor(x) + 0.5 if x > 1 else 0.5)
_balances_df.loc[:, 'balance_coin_rounded'] = _balances_df.balance_coin.map(rounded_function)

return _balances_df[~_balances_df['address'].isin(_module_addresses_list)]
25 changes: 15 additions & 10 deletions src/utils_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def calculate_and_display_rules(
boundary_round: int,
max_boundary=None) -> list:
"""
Calculate rule boundaries in according with percentage levels
Calculate rule boundaries in according to percentage levels
:param distribution_df: Source DataFrame
:param initial_boundary: Minimum value of analyzed parameter that should be included in analysis
:param max_boundary: Maximum value of analyzed parameter that should be included in analysis
Expand Down Expand Up @@ -49,7 +49,7 @@ def calculate_and_display_rules(
boundary = distribution_slice_df.iloc[
distribution_slice_df[address_cumsum_perc_column].map(
lambda x: abs(x - percentage_level)).argmin()][value_column]
boundaries.append(float(round(boundary, boundary_round)))
boundaries.append(round(boundary, boundary_round))
# Calculate of address number by suggested grades
addresses_by_grade = [distribution_slice_df[
(distribution_slice_df[value_column] > boundaries[0]) & (
Expand All @@ -60,12 +60,12 @@ def calculate_and_display_rules(
distribution_slice_df[
distribution_slice_df[value_column] > boundaries[2]][address_column].sum()]
# Rules for displaying
rules = [f'{boundaries[0]} < {value_name} <= {boundaries[1]}',
f'{boundaries[1]} < {value_name} <= {boundaries[2]}',
f'{boundaries[2]} < {value_name}']
rules = [f'{boundaries[0]:>,} < {value_name} <= {boundaries[1]:>,.0f}',
f'{boundaries[1]:>,.0f} < {value_name} <= {boundaries[2]:>,.0f}',
f'{boundaries[2]:>,.0f} < {value_name}']
df_data = [[i + 1,
rule,
addresses_by_grade[i],
f'{addresses_by_grade[i]:>,}',
round(addresses_by_grade[i] / total_addresses * 100, 1)]
for i, rule in enumerate(rules)]

Expand All @@ -74,7 +74,7 @@ def calculate_and_display_rules(
HTML(
pd.DataFrame(df_data,
columns=['Grade', 'Rule', 'Addresses', 'Percentage of Addresses'])
.to_html(index=False, notebook=True, show_dimensions=False)))
.to_html(index=False, notebook=True, show_dimensions=False)))
return boundaries


Expand Down Expand Up @@ -121,7 +121,7 @@ def show_distribution_chart(
# Distribution bar chart
ax.plot(distribution_df[distribution_df[value_column] < max_show_value][value_transform_column],
distribution_df[distribution_df[value_column] < max_show_value][address_transform_column],
color='blue', marker='o', linestyle='dashed', linewidth=1, markersize=4)
color='blue', marker='o', linestyle='dashed', linewidth=0, markersize=4)

ax.set_title(chart_title, fontsize=18)
ax.set_ylabel(address_chart_label, fontsize=16)
Expand All @@ -139,6 +139,7 @@ def grade_boundaries_analysis(
distribution_df: pd.DataFrame,
chart_title: str,
value_column: str,
chart_value_column: str,
value_name: str,
value_chart_label: str,
value_transform_func=lambda x: log10(x) if x > 1 else 0.1,
Expand All @@ -156,6 +157,7 @@ def grade_boundaries_analysis(
:param distribution_df: Source DataFrame
:param chart_title: Chart title
:param value_column: Column name of analyzed parameter
:param chart_value_column: Column name of analyzed parameter for chart
:param value_name: Name of analyzed parameter for inserting in the rules
:param value_chart_label: Name of analyzed parameter for the chart
:param value_transform_func: Transformation function for analyzed parameter column
Expand Down Expand Up @@ -184,12 +186,15 @@ def grade_boundaries_analysis(
address_column=address_column,
boundary_round=boundary_round)

distribution_chart_df = distribution_df.groupby(chart_value_column).agg(
{'number_of_addresses': np.sum}).sort_values([chart_value_column]).reset_index()

show_distribution_chart(
distribution_df=distribution_df,
distribution_df=distribution_chart_df,
boundaries=boundaries,
level_line_shift=level_line_shift,
max_show_value=max_show_value,
value_column=value_column,
value_column=chart_value_column,
value_chart_label=value_chart_label,
value_transform_func=value_transform_func,
address_column=address_column,
Expand Down