-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCT-815: Double Total Rewards for Epoch 1
- Loading branch information
Showing
17 changed files
with
188 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.env | ||
.idea/ | ||
.vscode/ | ||
.yarn/ | ||
node_modules/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from dataclasses import dataclass | ||
|
||
from app.core.rewards.rewards_strategy import RewardsStrategy | ||
from app.core.rewards.standard_rewards_strategy import StandardRewardsStrategy | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EpochSettings: | ||
rewardsStrategy: RewardsStrategy = StandardRewardsStrategy() | ||
|
||
|
||
class EpochsRegistry: | ||
rewards_registry: dict[int, EpochSettings] = {} | ||
|
||
@classmethod | ||
def register_epoch_settings( | ||
cls, epoch_number: int, rewardsStrategy: RewardsStrategy | ||
): | ||
cls.rewards_registry[epoch_number] = EpochSettings(rewardsStrategy) | ||
|
||
@classmethod | ||
def get_epoch_settings(cls, epoch_number: int) -> EpochSettings: | ||
return cls.rewards_registry.setdefault(epoch_number, EpochSettings()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from app.core.epochs.epochs_registry import EpochsRegistry | ||
from app.core.rewards.double_rewards_strategy import DoubleRewardsStrategy | ||
|
||
EpochsRegistry.register_epoch_settings(1, DoubleRewardsStrategy()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from decimal import Decimal | ||
from app.core.rewards.rewards_strategy import RewardsStrategy | ||
|
||
|
||
class DoubleRewardsStrategy(RewardsStrategy): | ||
DOUBLING_GLM_SUPPLY_LIMIT = 0.25 | ||
REWARDS_MULTIPLY_RATIO_LIMIT = 0.5 | ||
REWARDS_MULTIPLY_FACTOR = 2 | ||
|
||
def calculate_total_rewards(self, eth_proceeds: int, locked_ratio: Decimal) -> int: | ||
if locked_ratio < self.DOUBLING_GLM_SUPPLY_LIMIT: | ||
return ( | ||
int(eth_proceeds * locked_ratio.sqrt()) * self.REWARDS_MULTIPLY_FACTOR | ||
) | ||
else: | ||
return eth_proceeds | ||
|
||
def calculate_all_individual_rewards( | ||
self, eth_proceeds: int, locked_ratio: Decimal | ||
) -> int: | ||
if locked_ratio < self.DOUBLING_GLM_SUPPLY_LIMIT: | ||
return int(eth_proceeds * locked_ratio) * self.REWARDS_MULTIPLY_FACTOR | ||
else: | ||
return int(eth_proceeds * self.REWARDS_MULTIPLY_RATIO_LIMIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from decimal import Decimal | ||
|
||
from app import database | ||
from app.database.models import PendingEpochSnapshot | ||
|
||
from app.core.epochs.epochs_registry import EpochsRegistry | ||
|
||
|
||
def calculate_total_rewards( | ||
eth_proceeds: int, locked_ratio: Decimal, pending_epoch: int | ||
) -> int: | ||
registry = EpochsRegistry.get_epoch_settings(pending_epoch) | ||
return registry.rewardsStrategy.calculate_total_rewards(eth_proceeds, locked_ratio) | ||
|
||
|
||
def calculate_all_individual_rewards( | ||
eth_proceeds: int, locked_ratio: Decimal, pending_epoch: int | ||
) -> int: | ||
registry = EpochsRegistry.get_epoch_settings(pending_epoch) | ||
return registry.rewardsStrategy.calculate_all_individual_rewards( | ||
eth_proceeds, locked_ratio | ||
) | ||
|
||
|
||
def calculate_matched_rewards(snapshot: PendingEpochSnapshot) -> int: | ||
return int(snapshot.total_rewards) - int(snapshot.all_individual_rewards) | ||
|
||
|
||
def get_matched_rewards_from_epoch(epoch: int) -> int: | ||
snapshot = database.pending_epoch_snapshot.get_by_epoch_num(epoch) | ||
|
||
return calculate_matched_rewards(snapshot) | ||
|
||
|
||
def calculate_matched_rewards_threshold( | ||
total_allocated: int, proposals_count: int | ||
) -> int: | ||
return int(total_allocated / (proposals_count * 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from decimal import Decimal | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class RewardsStrategy(ABC): | ||
@abstractmethod | ||
def calculate_total_rewards(self, eth_proceeds: int, locked_ratio: Decimal) -> int: | ||
pass | ||
|
||
@abstractmethod | ||
def calculate_all_individual_rewards( | ||
self, eth_proceeds: int, locked_ratio: Decimal | ||
) -> int: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from decimal import Decimal | ||
from app.core.rewards.rewards_strategy import RewardsStrategy | ||
|
||
|
||
class StandardRewardsStrategy(RewardsStrategy): | ||
def calculate_total_rewards(self, eth_proceeds: int, locked_ratio: Decimal) -> int: | ||
return int(eth_proceeds * locked_ratio.sqrt()) | ||
|
||
def calculate_all_individual_rewards( | ||
self, eth_proceeds: int, locked_ratio: Decimal | ||
) -> int: | ||
return int(eth_proceeds * locked_ratio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters