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

Update rewards to support poll 27 #13

Merged
merged 9 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
Expand All @@ -17,9 +17,11 @@ repos:
- id: mypy
additional_dependencies: ['types-requests']
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.2
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
37 changes: 31 additions & 6 deletions indy_rewards/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
LiquidityPool,
LiquidityPoolReward,
)
from indy_rewards.sp.distribution import sp_epoch_emission


@click.group()
Expand Down Expand Up @@ -51,6 +52,19 @@ def decorator(function: Callable):
return decorator


def sp_indy_option(name="--indy", help="INDY to distribute per epoch."):
def decorator(function: Callable):
return click.option(
name,
default=-1,
type=click.FLOAT,
help=help,
show_default=True,
)(function)

return decorator


def epoch_or_date_arg(function: Callable):
arg = click.argument(
"epoch_or_date",
Expand Down Expand Up @@ -178,7 +192,7 @@ def gov(indy: float, pkh: tuple[str], outfile: str, epoch: int):


@rewards.command()
@indy_option(config.SP_EPOCH_INDY)
@sp_indy_option()
@pkh_option
@outfile_option
@epoch_or_date_arg
Expand All @@ -191,22 +205,30 @@ def sp(
"""Print or save stability pool staking rewards."""
_load_polygon_api_key_or_fail(epoch_or_date)
if isinstance(epoch_or_date, int):
if indy == -1:
indy = sp_epoch_emission(epoch_or_date)
rewards = sp_module.get_epoch_rewards_per_staker(epoch_or_date, indy)
else:
if indy == -1:
indy = sp_epoch_emission(time_utils.date_to_epoch(epoch_or_date))
rewards = sp_module.get_rewards_per_staker(epoch_or_date, indy)
rewards = _pkh_filter(rewards, pkh)
_output(rewards, outfile)


@rewards.command()
@indy_option(config.SP_EPOCH_INDY)
@sp_indy_option()
@epoch_or_date_arg
def sp_apr(indy: float, epoch_or_date: int | datetime.date):
"""Print SP staking INDY-based APRs."""

if isinstance(epoch_or_date, int):
if indy == -1:
indy = sp_epoch_emission(epoch_or_date)
aprs = sp_module.get_epoch_aprs(epoch_or_date, indy)
else:
if indy == -1:
indy = sp_epoch_emission(time_utils.date_to_epoch(epoch_or_date))
aprs = sp_module.get_daily_aprs(epoch_or_date, indy)

sps = sorted(aprs.keys(), key=lambda x: x.iasset.name)
Expand All @@ -225,14 +247,14 @@ def all(pkh: tuple[str], outfile: str, epoch_or_date: int | datetime.date):
if isinstance(epoch_or_date, int):
rewards = summary.get_epoch_all_rewards(
epoch_or_date,
config.SP_EPOCH_INDY,
sp_epoch_emission(epoch_or_date),
config.LP_EPOCH_INDY,
config.GOV_EPOCH_INDY,
)
else:
rewards = summary.get_day_all_rewards(
epoch_or_date,
config.SP_EPOCH_INDY,
sp_epoch_emission(time_utils.date_to_epoch(epoch_or_date)),
config.LP_EPOCH_INDY,
config.GOV_EPOCH_INDY,
)
Expand All @@ -242,8 +264,7 @@ def all(pkh: tuple[str], outfile: str, epoch_or_date: int | datetime.date):


@rewards.command(name="summary")
@indy_option(
config.SP_EPOCH_INDY,
@sp_indy_option(
"--sp-indy",
"INDY to distribute to stability pool stakers per epoch.",
)
Expand All @@ -270,6 +291,8 @@ def summary_command(
_load_polygon_api_key_or_fail(epoch_or_date)

if isinstance(epoch_or_date, int):
if sp_indy == -1:
sp_indy = sp_epoch_emission(epoch_or_date)
epoch_rewards = summary.get_epoch_all_rewards(
epoch_or_date,
sp_indy,
Expand All @@ -279,6 +302,8 @@ def summary_command(
epoch_rewards = _pkh_filter(epoch_rewards, pkh)
sum_table = summary.get_summary(epoch_rewards)
else:
if sp_indy == -1:
sp_indy = sp_epoch_emission(time_utils.date_to_epoch(epoch_or_date))
day_rewards = summary.get_day_all_rewards(
epoch_or_date, sp_indy, lp_indy, gov_indy
)
Expand Down
1 change: 0 additions & 1 deletion indy_rewards/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .models import IAsset
from .time_utils import date_to_epoch

SP_EPOCH_INDY: Final[int] = 28768
LP_EPOCH_INDY: Final[int] = 4795
GOV_EPOCH_INDY: Final[int] = 2398

Expand Down
26 changes: 26 additions & 0 deletions indy_rewards/sp/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ def get_pool_weights(
day: datetime.date,
new_iassets: set[IAsset],
has_stakers: set[IAsset],
) -> dict[IAsset, float]:
if day >= datetime.date(2023, 11, 11):
return {
IAsset.from_str("ibtc"): (3668 / 22431),
IAsset.from_str("ieth"): (3188 / 22431),
IAsset.from_str("iusd"): (15574 / 22431),
}

return get_pool_weights_before_epoch_448(
saturations, market_caps, day, new_iassets, has_stakers
)


def get_pool_weights_before_epoch_448(
saturations: dict[IAsset, float],
market_caps: dict[IAsset, float],
day: datetime.date,
new_iassets: set[IAsset],
has_stakers: set[IAsset],
) -> dict[IAsset, float]:
weights: dict[IAsset, float] = {}

Expand Down Expand Up @@ -314,3 +333,10 @@ def _is_at_least_24h_old(account: dict, snapshot_day: datetime.date) -> bool:
tzinfo=datetime.timezone.utc
)
return open + datetime.timedelta(days=1) <= snap


def sp_epoch_emission(epoch: int) -> float:
if epoch >= 446:
return 22431

return 28768
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
black == 23.*
docformatter[tomli] == 1.*
flake8 == 6.*
docformatter[tomli] == 1.7.5
flake8 == 6.1.0
isort == 5.*
mypy == 1.*
pandas-stubs == 2.0.*
Expand Down