-
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-1569 & OCT-1567 Change overhaul formulas (#165)
- Loading branch information
Showing
25 changed files
with
281 additions
and
81 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
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
26 changes: 26 additions & 0 deletions
26
backend/app/engine/octant_rewards/matched/percentage_from_staking.py
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,26 @@ | ||
from app.engine.octant_rewards.matched import MatchedRewards, MatchedRewardsPayload | ||
from dataclasses import dataclass | ||
from decimal import Decimal | ||
|
||
from app.exceptions import InvalidMatchedRewardsStrategy | ||
|
||
|
||
@dataclass | ||
class PercentageMatchedRewards(MatchedRewards): | ||
MATCHED_REWARDS_PERCENT: Decimal | ||
|
||
def calculate_matched_rewards(self, payload: MatchedRewardsPayload) -> int: | ||
if payload.locked_ratio > payload.tr_percent: | ||
raise InvalidMatchedRewardsStrategy() | ||
|
||
if payload.locked_ratio < payload.ire_percent: | ||
return int( | ||
self.MATCHED_REWARDS_PERCENT * payload.staking_proceeds | ||
+ payload.patrons_rewards | ||
) | ||
elif payload.ire_percent <= payload.locked_ratio < payload.tr_percent: | ||
return int( | ||
(payload.tr_percent - payload.locked_ratio) * payload.staking_proceeds | ||
+ payload.patrons_rewards | ||
) | ||
return payload.patrons_rewards |
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
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,11 +1,12 @@ | ||
from app.engine.octant_rewards.ppf import PPFCalculator, PPFPayload | ||
from decimal import Decimal | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class PPFCalculatorPercent(PPFCalculator): | ||
PPF_PERCENT: Decimal | ||
|
||
class PPFCalculatorFromRewards(PPFCalculator): | ||
def calculate_ppf(self, payload: PPFPayload) -> int: | ||
return int(self.PPF_PERCENT * payload.eth_proceeds) | ||
if payload.locked_ratio < payload.ire_percent: | ||
return int( | ||
payload.individual_rewards_equilibrium - payload.all_individual_rewards | ||
) | ||
return 0 |
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
13 changes: 8 additions & 5 deletions
13
...s/total_and_individual/tr_from_staking.py → ...s/total_and_individual/tr_percent_calc.py
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,19 +1,22 @@ | ||
from dataclasses import dataclass | ||
|
||
from app.engine.octant_rewards.total_and_individual import ( | ||
TotalAndAllIndividualRewards, | ||
TotalAndAllIndividualPayload, | ||
) | ||
from decimal import Decimal | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class PercentTotalAndAllIndividualRewards(TotalAndAllIndividualRewards): | ||
TR_PERCENT: Decimal | ||
|
||
def calculate_total_rewards(self, payload: TotalAndAllIndividualPayload) -> int: | ||
return int(payload.eth_proceeds * self.TR_PERCENT) | ||
return int(self.TR_PERCENT * payload.eth_proceeds) | ||
|
||
def calculate_all_individual_rewards( | ||
self, payload: TotalAndAllIndividualPayload | ||
) -> int: | ||
return int(payload.eth_proceeds * payload.locked_ratio) | ||
|
||
def calculate_individual_rewards_equilibrium( | ||
self, payload: TotalAndAllIndividualPayload | ||
) -> int: | ||
return int(self.IRE_PERCENT * payload.eth_proceeds) |
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
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
37 changes: 37 additions & 0 deletions
37
backend/migrations/versions/8e72b01c43a7_update_ppf_after_invalid_calculations_.py
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,37 @@ | ||
"""Update PPF after invalid calculations for Epoch3 | ||
Revision ID: 8e72b01c43a7 | ||
Revises: fc7a01c20be5 | ||
Create Date: 2024-04-19 00:48:12.133033 | ||
""" | ||
from alembic import op | ||
from decimal import Decimal | ||
|
||
revision = "8e72b01c43a7" | ||
down_revision = "fc7a01c20be5" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
individual_rewards = Decimal( | ||
"146655862334541166188" | ||
) # Got directly from the database for Pending Snapshot in Epoch3 | ||
staking_proceeds = Decimal( | ||
"959848624830407629247" | ||
) # Got directly from the database for Pending Snapshot in Epoch3 | ||
ppf = int(staking_proceeds * Decimal("0.35") - individual_rewards) | ||
|
||
|
||
def upgrade(): | ||
query = f"UPDATE pending_epoch_snapshots SET ppf = '{ppf}' WHERE epoch = 3 AND all_individual_rewards = '{individual_rewards}' AND eth_proceeds = '{staking_proceeds}';" | ||
op.execute(query) | ||
|
||
|
||
def downgrade(): | ||
old_ppf = "335947018690642670236" | ||
|
||
query = f"UPDATE pending_epoch_snapshots SET ppf = '{old_ppf}' WHERE epoch = 3 AND all_individual_rewards = '{individual_rewards}' AND eth_proceeds = '{staking_proceeds}' AND ppf = '{ppf}';" | ||
|
||
print(query, flush=True) | ||
|
||
op.execute(query) |
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
Oops, something went wrong.