Skip to content

FIP0081 Initial Pledge Change #38

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added mechafil/.DS_Store
Binary file not shown.
23 changes: 21 additions & 2 deletions mechafil/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def compute_day_delta_pledge(
baseline_power: float,
renewal_rate: float,
scheduled_pledge_release: float,
lock_target: float = 0.3,
lock_target: float,
gamma: float
) -> float:
onboards_delta = compute_new_pledge_for_added_power(
day_network_reward,
Expand All @@ -30,6 +31,7 @@ def compute_day_delta_pledge(
total_qa_power,
baseline_power,
lock_target,
gamma
)
renews_delta = compute_renewals_delta_pledge(
day_network_reward,
Expand All @@ -40,6 +42,7 @@ def compute_day_delta_pledge(
renewal_rate,
scheduled_pledge_release,
lock_target,
gamma
)
return onboards_delta + renews_delta

Expand All @@ -53,7 +56,8 @@ def compute_day_locked_pledge(
baseline_power: float,
renewal_rate: float,
scheduled_pledge_release: float,
lock_target: float = 0.3,
lock_target,
gamma: float
) -> float:
# Total locked from new onboards
onboards_locked = compute_new_pledge_for_added_power(
Expand All @@ -63,6 +67,7 @@ def compute_day_locked_pledge(
total_qa_power,
baseline_power,
lock_target,
gamma
)
# Total locked from renewals
original_pledge = renewal_rate * scheduled_pledge_release
Expand All @@ -73,6 +78,7 @@ def compute_day_locked_pledge(
total_qa_power,
baseline_power,
lock_target,
gamma
)
renews_locked = max(original_pledge, new_pledge)
# Total locked pledge
Expand All @@ -89,6 +95,7 @@ def compute_renewals_delta_pledge(
renewal_rate: float,
scheduled_pledge_release: float,
lock_target: float,
gamma
) -> float:
# Delta from sectors expiring
expire_delta = -(1 - renewal_rate) * scheduled_pledge_release
Expand All @@ -101,6 +108,7 @@ def compute_renewals_delta_pledge(
total_qa_power,
baseline_power,
lock_target,
gamma
)
renew_delta = max(0.0, new_pledge - original_pledge)
# Delta for all scheduled sectors
Expand All @@ -115,12 +123,23 @@ def compute_new_pledge_for_added_power(
total_qa_power: float,
baseline_power: float,
lock_target: float,
gamma
) -> float:
# storage collateral
storage_pledge = 20.0 * day_network_reward * (day_added_qa_power / total_qa_power)
# consensus collateral
normalized_qap_growth = day_added_qa_power / max(total_qa_power, baseline_power)
consensus_pledge = max(lock_target * prev_circ_supply * normalized_qap_growth, 0)

# compute simple and baseline pledge
simple_consensus_pledge = lock_target * prev_circ_supply * (day_added_qa_power/total_qa_power)
simple_consensus_pledge = np.maximum(simple_consensus_pledge, 0)

baseline_consensus_pledge = lock_target * prev_circ_supply * normalized_qap_growth
baseline_consensus_pledge = np.maximum(baseline_consensus_pledge, 0)

consensus_pledge = (1-gamma) * simple_consensus_pledge + gamma * baseline_consensus_pledge

# total added pledge
added_pledge = storage_pledge + consensus_pledge

Expand Down
30 changes: 28 additions & 2 deletions mechafil/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def validate_current_date(current_date: datetime.date):
if current_date > (datetime.date.today() - datetime.timedelta(days=2)):
raise ValueError("Current date must be at least 2 days in the past!")

def create_gamma_trajectory(current_date, forecast_length_days, fip81_activation_date, ramp_len_days=365):
gamma_target = 0.7
days_since_activation = (current_date - fip81_activation_date).days
gamma_slope = (1.0 - gamma_target) / ramp_len_days
current_gamma = 1.0 - gamma_slope * days_since_activation
print(f'current_gamma: {current_gamma}')
remaining_days = ramp_len_days - days_since_activation
v1 = np.linspace(current_gamma, gamma_target, remaining_days)
v2 = np.ones(forecast_length_days - remaining_days) * gamma_target
gamma_trajectory = np.concatenate([v1, v2])
#print(gamma_trajectory)

return gamma_trajectory

def run_simple_sim(
start_date: datetime.date,
current_date: datetime.date,
Expand All @@ -33,8 +47,8 @@ def run_simple_sim(
fil_plus_rate: Union[np.array, float],
duration: int,
bearer_token_or_cfg: str,
qap_method: str = 'basic' # can be set to tunable or basic
# see: https://hackmd.io/O6HmAb--SgmxkjLWSpbN_A?view
qap_method: str = 'basic', # can be set to tunable or basic
# see: https://hackmd.io/O6HmAb--SgmxkjLWSpbN_A?view
) -> pd.DataFrame:
validate_qap_method(qap_method)
setup_data_access(bearer_token_or_cfg)
Expand Down Expand Up @@ -102,6 +116,16 @@ def run_simple_sim(
renewal_rate_vec = np.concatenate(
[past_renewal_rate_vec, forecast_renewal_rate_vec]
)

#create gamma vector for FIP0081
fip81_activation_date = datetime.date(2024, 11, 21)
sim_len = end_date - start_date
gamma_smooth_1y = create_gamma_trajectory(start_date, forecast_length, fip81_activation_date, ramp_len_days=365)

print(gamma_smooth_1y)
#print("forecast length is" + str(forecast_length))
#Non Configurable Lock_Target for now
lock_target = 0.3
cil_df = forecast_circulating_supply_df(
start_date,
current_date,
Expand All @@ -115,5 +139,7 @@ def run_simple_sim(
vest_df,
mint_df,
known_scheduled_pledge_release_full_vec,
lock_target,
gamma_smooth_1y
)
return cil_df
11 changes: 10 additions & 1 deletion mechafil/supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from .power import scalar_or_vector_to_vector
from .data import NETWORK_START

from numpy.typing import NDArray

"""
There is still a small discrepancy between the actual locked FIL and forecasted
locked FIL. We believe that it could be due to the following reasons:
Expand All @@ -35,7 +37,8 @@ def forecast_circulating_supply_df(
vest_df: pd.DataFrame,
mint_df: pd.DataFrame,
known_scheduled_pledge_release_vec: np.array,
lock_target: float = 0.3,
lock_target,
gamma: Union[np.array, NDArray]
) -> pd.DataFrame:
# we assume all stats started at main net launch, in 2020-10-15
start_day = (start_date - NETWORK_START.date()).days
Expand All @@ -54,6 +57,10 @@ def forecast_circulating_supply_df(
circ_supply = circ_supply_zero
sim_len = end_day - start_day
renewal_rate_vec = scalar_or_vector_to_vector(renewal_rate, sim_len)
gamma_converge = 0.7

#Note, this needs to be done because sim_len and forecast_length are different
gamma = np.concatenate([gamma, np.full(sim_len - len(gamma), gamma_converge)]) if len(gamma) < sim_len else gamma

# Simulation for loop
current_day_idx = current_day - start_day
Expand All @@ -77,6 +84,7 @@ def forecast_circulating_supply_df(
renewal_rate_vec[day_idx],
scheduled_pledge_release,
lock_target,
gamma[day_idx]
)
# Get total locked pledge (needed for future day_locked_pledge)
day_locked_pledge, day_renewed_pledge = compute_day_locked_pledge(
Expand All @@ -89,6 +97,7 @@ def forecast_circulating_supply_df(
renewal_rate_vec[day_idx],
scheduled_pledge_release,
lock_target,
gamma[day_idx]
)
# Compute daily change in block rewards collateral
day_locked_rewards = compute_day_locked_rewards(
Expand Down