diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11c3177..a61d347 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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: diff --git a/indy_rewards/cli.py b/indy_rewards/cli.py index 41cb399..60e10c9 100644 --- a/indy_rewards/cli.py +++ b/indy_rewards/cli.py @@ -19,6 +19,7 @@ LiquidityPool, LiquidityPoolReward, ) +from indy_rewards.sp.distribution import sp_epoch_emission @click.group() @@ -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", @@ -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 @@ -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) @@ -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, ) @@ -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.", ) @@ -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, @@ -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 ) diff --git a/indy_rewards/config.py b/indy_rewards/config.py index 53095e5..ab0d581 100644 --- a/indy_rewards/config.py +++ b/indy_rewards/config.py @@ -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 diff --git a/indy_rewards/sp/distribution.py b/indy_rewards/sp/distribution.py index 5b08c04..47002a9 100644 --- a/indy_rewards/sp/distribution.py +++ b/indy_rewards/sp/distribution.py @@ -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, 6): + 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] = {} @@ -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 >= 447: + return 22431 + + return 28768 diff --git a/requirements-dev.txt b/requirements-dev.txt index f84407b..448b102 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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.*