Skip to content
Snippets Groups Projects

Implement `Power up` part of hive power management

Merged Jakub Ziebinski requested to merge jziebinski/prepare-hp-management into develop
Compare and Show latest version
8 files
+ 167
63
Compare changes
  • Side-by-side
  • Inline
Files
8
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Final
from clive.__private.core.calcluate_hive_power import calculate_hive_power
from clive.__private.core.commands.abc.command_data_retrieval import CommandDataRetrieval
@@ -43,8 +43,8 @@ class HivePowerData:
delegated_balance: SharesBalance
next_vesting_withdrawal: datetime
to_withdraw: SharesBalance
withdraw_routes: int
reward_percent: int
next_power_down: int
current_hp_apr: str
@dataclass(kw_only=True)
@@ -78,8 +78,8 @@ class HivePowerDataRetrieval(CommandDataRetrieval[HarvestedDataRaw, SanitizedDat
delegated_balance=self._create_balance_representation(data.dgpo, delegated_shares),
next_vesting_withdrawal=data.core_account.next_vesting_withdrawal,
to_withdraw=self._create_balance_representation(data.dgpo, Asset.vests(data.core_account.to_withdraw)),
withdraw_routes=data.core_account.withdraw_routes,
reward_percent=data.dgpo.vesting_reward_percent,
next_power_down=int(data.core_account.vesting_withdraw_rate.amount),
current_hp_apr=self._calculate_current_hp_apr(data.dgpo),
)
def _assert_gdpo(self, data: DynamicGlobalProperties | None) -> DynamicGlobalProperties:
@@ -96,3 +96,32 @@ class HivePowerDataRetrieval(CommandDataRetrieval[HarvestedDataRaw, SanitizedDat
def _create_balance_representation(self, dgdpo: DynamicGlobalProperties, vests_value: Asset.Vests) -> SharesBalance:
return SharesBalance(hp_balance=calculate_hive_power(dgdpo, vests_value), vests_balance=vests_value)
def _calculate_current_hp_apr(self, gdpo: DynamicGlobalProperties) -> str:
# The inflation was set to 9.5% at block 7m
initial_inflation_rate: Final[float] = 9.5
initial_block: Final[int] = 7000000
# It decreases by 0.01% every 250k blocks
decrease_rate: Final[int] = 250000
decrease_percent_per_increment: Final[float] = 0.01
# How many increments have happened since block 7m?
head_block = gdpo.head_block_number
delta_blocks = head_block - initial_block
decrease_increments = delta_blocks / decrease_rate
current_inflation_rate = initial_inflation_rate - decrease_increments * decrease_percent_per_increment
# Cannot go lower than 0.95 %
minimum_inflation_rate: Final[float] = 0.95
if current_inflation_rate < minimum_inflation_rate:
current_inflation_rate = 0.95
# Calculate the APR
vesting_reward_percent = gdpo.vesting_reward_percent / 10000
virtual_supply = int(gdpo.virtual_supply.amount) / 10**gdpo.virtual_supply.precision
total_vesting_funds = int(gdpo.total_vesting_fund_hive.amount) / 10**gdpo.total_vesting_fund_hive.precision
return f"{virtual_supply * current_inflation_rate * vesting_reward_percent / total_vesting_funds :.2f}"
Loading