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

[RELEASE] 0.13.0 #618

Merged
merged 15 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 11 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
15 changes: 9 additions & 6 deletions backend/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,13 +992,16 @@
]

GTC_STAKING_STAMP_PROVIDERS_AND_SCORES = {
"SelfStakingBronze": 1.0,
"SelfStakingSilver": 2.0,
"SelfStakingGold": 3.0,
"BeginnerCommunityStaker": 1.5,
"ExperiencedCommunityStaker": 2.5,
"TrustedCitizen": 4.0,
"SelfStakingBronze": 0.897,
"SelfStakingSilver": 2.066,
"SelfStakingGold": 2.7,
"BeginnerCommunityStaker": 0.673,
"ExperiencedCommunityStaker": 2.161,
"TrustedCitizen": 4.009,
}

SABLIER_SENDER_ADDRESS_SEPOLIA = "0xf86fD85672683c220709B9ED80bAD7a51800206a"
SABLIER_TOKEN_ADDRESS_SEPOLIA = "0x71432dd1ae7db41706ee6a22148446087bdd0906"

SABLIER_UNLOCK_GRACE_PERIOD_24_HRS = 24 * 60 * 60
TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN = 15 * 60
9 changes: 2 additions & 7 deletions backend/app/engine/epochs_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def register_epoch_settings():
),
user=UserSettings(
budget=PreliminaryUserBudget(),
effective_deposit=DefaultWeightedAverageEffectiveDeposit(),
),
project=ProjectSettings(
rewards=PreliminaryProjectRewards(
Expand All @@ -95,10 +94,6 @@ def register_epoch_settings():
user=UserSettings(effective_deposit=DefaultWeightedAverageEffectiveDeposit()),
project=ProjectSettings(rewards=PreliminaryProjectRewards()),
)
SETTINGS[4] = EpochSettings(
user=UserSettings(effective_deposit=DefaultWeightedAverageEffectiveDeposit())
)
SETTINGS[5] = EpochSettings(
user=UserSettings(effective_deposit=DefaultWeightedAverageEffectiveDeposit())
)
SETTINGS[4] = EpochSettings()
SETTINGS[5] = EpochSettings()
SETTINGS[6] = EpochSettings()
6 changes: 3 additions & 3 deletions backend/app/engine/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from app.engine.user.budget import UserBudget
from app.engine.user.budget.with_ppf import UserBudgetWithPPF
from app.engine.user.effective_deposit import UserEffectiveDeposit
from app.engine.user.effective_deposit.weighted_average.default_with_sablier_timebox import (
DefaultWeightedAverageWithSablierTimebox,
from app.engine.user.effective_deposit.weighted_average.default import (
DefaultWeightedAverageEffectiveDeposit,
)


@dataclass
class UserSettings:
effective_deposit: UserEffectiveDeposit = field(
default_factory=DefaultWeightedAverageWithSablierTimebox
default_factory=DefaultWeightedAverageEffectiveDeposit
)
budget: UserBudget = field(default_factory=UserBudgetWithPPF)

This file was deleted.

14 changes: 11 additions & 3 deletions backend/app/modules/modules_factory/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
UQ_THRESHOLD_NOT_MAINNET,
TIMEOUT_LIST_NOT_MAINNET,
TIMEOUT_LIST,
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS,
TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN,
)
from app.modules.projects.details.service.projects_details import (
StaticProjectsDetailsService,
Expand Down Expand Up @@ -95,12 +97,18 @@ def _prepare_simulation_data(

@staticmethod
def create(chain_id: int) -> "CurrentServices":
is_mainnet = compare_blockchain_types(chain_id, ChainTypes.MAINNET)
sablier_unlock_grace_period = (
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS
if is_mainnet
else TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN
)
user_deposits = CalculatedUserDeposits(
events_generator=DbAndGraphEventsGenerator()
events_generator=DbAndGraphEventsGenerator(
sablier_unlock_grace_period=sablier_unlock_grace_period
)
)

is_mainnet = compare_blockchain_types(chain_id, ChainTypes.MAINNET)

octant_rewards = CurrentServices._prepare_simulation_data(
is_mainnet, user_deposits
)
Expand Down
13 changes: 12 additions & 1 deletion backend/app/modules/modules_factory/pre_pending.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import app.modules.staking.proceeds.service.aggregated as aggregated
import app.modules.staking.proceeds.service.contract_balance as contract_balance
from app.constants import (
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS,
TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN,
)
from app.modules.modules_factory.protocols import (
AllUserEffectiveDeposits,
OctantRewards,
Expand Down Expand Up @@ -48,9 +52,16 @@ class PrePendingServices(Model):
@staticmethod
def create(chain_id: int) -> "PrePendingServices":
is_mainnet = compare_blockchain_types(chain_id, ChainTypes.MAINNET)
sablier_unlock_grace_period = (
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS
if is_mainnet
else TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN
)

user_deposits = CalculatedUserDeposits(
events_generator=DbAndGraphEventsGenerator()
events_generator=DbAndGraphEventsGenerator(
sablier_unlock_grace_period=sablier_unlock_grace_period
)
)
octant_rewards = CalculatedOctantRewards(
staking_proceeds=(
Expand Down
25 changes: 24 additions & 1 deletion backend/app/modules/user/budgets/controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import List

from app.constants import (
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS,
TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN,
)
from app.context.epoch_state import EpochState
from app.context.manager import state_context, epoch_context
from app.exceptions import NotImplementedForGivenEpochState
Expand All @@ -12,6 +16,8 @@
from app.modules.modules_factory.protocols import UserBudgets, UpcomingUserBudgets
from app.modules.registry import get_services
from app.modules.user.budgets import core
from app.shared.blockchain_types import compare_blockchain_types, ChainTypes
from flask import current_app as app


def get_budgets(epoch_num: int) -> List[AccountFundsDTO]:
Expand Down Expand Up @@ -47,13 +53,20 @@ def estimate_budget(lock_duration_sec: int, glm_amount: int) -> int:
future_rewards_service = get_services(EpochState.FUTURE).octant_rewards_service
future_rewards = future_rewards_service.get_octant_rewards(future_context)

sablier_unlock_grace_period = (
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS
if compare_blockchain_types(app.config["CHAIN_ID"], ChainTypes.MAINNET)
else TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN
)

return core.estimate_budget(
current_context,
future_context,
current_rewards,
future_rewards,
lock_duration_sec,
glm_amount,
sablier_unlock_grace_period,
)


Expand All @@ -73,8 +86,18 @@ def estimate_epochs_budget(no_epochs: int, glm_amount: int) -> int:

epoch_duration = future_context.epoch_details.duration_sec

sablier_unlock_grace_period = (
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS
if compare_blockchain_types(app.config["CHAIN_ID"], ChainTypes.MAINNET)
else TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN
)

return no_epochs * core.estimate_epoch_budget(
future_context, future_rewards, epoch_duration, glm_amount
future_context,
future_rewards,
epoch_duration,
glm_amount,
sablier_unlock_grace_period,
)


Expand Down
5 changes: 5 additions & 0 deletions backend/app/modules/user/budgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def estimate_epoch_budget(
rewards: OctantRewardsDTO,
lock_duration: int,
glm_amount: int,
sablier_unlock_grace_period: int = None,
) -> int:
epoch_details = context.epoch_details
epoch_settings = context.epoch_settings
Expand Down Expand Up @@ -72,13 +73,15 @@ def estimate_budget(
future_rewards: OctantRewardsDTO,
lock_duration_sec: int,
glm_amount: int,
sablier_unlock_grace_period: int = None,
) -> int:
remaining_lock_duration = lock_duration_sec
budget = estimate_epoch_budget(
current_context,
current_rewards,
remaining_lock_duration,
glm_amount,
sablier_unlock_grace_period,
)
remaining_lock_duration -= current_context.epoch_details.remaining_sec

Expand All @@ -92,6 +95,7 @@ def estimate_budget(
future_rewards,
epoch_duration,
glm_amount,
sablier_unlock_grace_period,
)
remaining_lock_duration = remaining_future_epoch_sec

Expand All @@ -101,6 +105,7 @@ def estimate_budget(
future_rewards,
remaining_lock_duration,
glm_amount,
sablier_unlock_grace_period,
)

return budget
Expand Down
72 changes: 59 additions & 13 deletions backend/app/modules/user/events_generator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from app.engine.user.effective_deposit import DepositEvent, EventType, DepositSource


def unify_deposit_balances(events: List[DepositEvent]) -> List[DepositEvent]:
def unify_deposit_balances(
events: List[DepositEvent], sablier_unlock_grace_period: int
) -> List[DepositEvent]:
"""
Unify deposit balance for each event in the list of events. Events are expected to be sorted by timestamp.
The first event is taken from deposits, but it already includes deposit from Sablier from the past.
Expand All @@ -17,23 +19,67 @@ def unify_deposit_balances(events: List[DepositEvent]) -> List[DepositEvent]:
acc_balance_sablier = 0
acc_balance_octant = events[0].deposit_before # balance from previous epoch

for event in modified_events[1:]:
i = 0
while i < len(modified_events) - 1:
current_event = modified_events[i]
next_event = modified_events[i + 1]

if current_event.type == EventType.UNLOCK and next_event.type == EventType.LOCK:
if (
current_event.source == DepositSource.SABLIER
and next_event.source == DepositSource.OCTANT
and next_event.timestamp - current_event.timestamp
< sablier_unlock_grace_period
):
unlocked_amount = current_event.amount
locked_amount = next_event.amount

if locked_amount == unlocked_amount:
# Scenario 1: Transparent unlock and lock
del modified_events[i : i + 2]
continue
elif locked_amount > unlocked_amount:
# Scenario 3: Transparent unlock, only record the excess lock
excess_amount = locked_amount - unlocked_amount
next_event.amount = excess_amount
next_event.deposit_before = acc_balance_sablier + acc_balance_octant
next_event.deposit_after = next_event.deposit_before + excess_amount
del modified_events[i] # Remove the unlock event
continue

# Update balances for normal event processing
combined_balance = acc_balance_sablier + acc_balance_octant
event.deposit_before = combined_balance
current_event.deposit_before = combined_balance

if event.type == EventType.LOCK:
if event.source == DepositSource.SABLIER:
acc_balance_sablier += event.amount
if current_event.type == EventType.LOCK:
if current_event.source == DepositSource.SABLIER:
acc_balance_sablier += current_event.amount
else:
acc_balance_octant += event.amount
acc_balance_octant += current_event.amount

event.deposit_after = event.deposit_before + event.amount
elif event.type == EventType.UNLOCK:
if event.source == DepositSource.SABLIER:
acc_balance_sablier -= event.amount
current_event.deposit_after = (
current_event.deposit_before + current_event.amount
)
elif current_event.type == EventType.UNLOCK:
if current_event.source == DepositSource.SABLIER:
acc_balance_sablier -= current_event.amount
else:
acc_balance_octant -= event.amount
acc_balance_octant -= current_event.amount

event.deposit_after = event.deposit_before - event.amount
current_event.deposit_after = (
current_event.deposit_before - current_event.amount
)

i += 1

# Process the last event
if modified_events:
last_event = modified_events[-1]
combined_balance = acc_balance_sablier + acc_balance_octant
last_event.deposit_before = combined_balance
if last_event.type == EventType.LOCK:
last_event.deposit_after = last_event.deposit_before + last_event.amount
elif last_event.type == EventType.UNLOCK:
last_event.deposit_after = last_event.deposit_before - last_event.amount

return modified_events
Loading
Loading