Skip to content

Commit

Permalink
Predictoor 5X Boost (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
trizin authored Mar 27, 2024
1 parent 83b7eb1 commit 789f9b3
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
1 change: 1 addition & 0 deletions df_py/util/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
PREDICTOOR_RELEASE_WEEK = 62
PREDICTOOR_OCEAN_BUDGET = 37_500
PREDICTOOR_DF_FIRST_DATE = datetime(2023, 11, 9)
SAPPHIRE_MAINNET_CHAINID = 23294

# volume
# Weekly Percent Yield needs to be 1.5717%., for max APY of 125%
Expand Down
4 changes: 3 additions & 1 deletion df_py/util/dcv_multiplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def calc_dcv_multiplier(DF_week: int, is_predictoor: bool) -> float:
DCV_multiplier --
"""
if is_predictoor:
return PREDICTOOR_MULTIPLIER
if DF_week < 82:
return PREDICTOOR_MULTIPLIER
return PREDICTOOR_MULTIPLIER * 5

if DF_week < 9:
return np.inf
Expand Down
5 changes: 2 additions & 3 deletions df_py/util/dftool_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from df_py.util import blockrange, dispense, get_rate, networkutil, oceantestutil
from df_py.util.base18 import from_wei, to_wei
from df_py.util.blocktime import get_fin_block, timestr_to_timestamp
from df_py.util.constants import SAPPHIRE_MAINNET_CHAINID
from df_py.util.contract_base import ContractBase
from df_py.util.dftool_arguments import (
CHAINID_EXAMPLES,
Expand Down Expand Up @@ -437,12 +438,10 @@ def do_calc():
calc_volume_rewards_from_csvs(csv_dir, start_date, tot_ocean)

if arguments.SUBSTREAM == "predictoor_rose":
SAPPHIRE_MAINNET_ID = 23294

predictoor_data = load_predictoor_data_csv(csv_dir)
print("Loaded predictoor data:", predictoor_data)
predictoor_rewards = calc_predictoor_rewards(
predictoor_data, arguments.TOT_OCEAN, SAPPHIRE_MAINNET_ID
predictoor_data, arguments.TOT_OCEAN, SAPPHIRE_MAINNET_CHAINID
)
print("Calculated rewards:", predictoor_rewards)

Expand Down
3 changes: 2 additions & 1 deletion df_py/util/dispense.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from web3.main import Web3

from df_py.util.base18 import to_wei
from df_py.util.constants import SAPPHIRE_MAINNET_CHAINID
from df_py.util.contract_base import ContractBase
from df_py.util.logger import logger
from df_py.util.multisig import send_multisig_tx
Expand Down Expand Up @@ -63,7 +64,7 @@ def dispense(
sts = list(range(N))[::batch_size] # send in batches to avoid gas issues

LEGACY_TX = False
if web3.eth.chain_id == 23294:
if web3.eth.chain_id == SAPPHIRE_MAINNET_CHAINID:
LEGACY_TX = True

def approveAmt(amt):
Expand Down
5 changes: 4 additions & 1 deletion df_py/util/test/test_dcv_multiplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def test_calc_dcv_multiplier():
assert mult(100, False) == 0.001
assert mult(10000, False) == 0.001

# PREDICTOOR MULTIPLIERS
assert mult(-10, True) == 0.201
assert mult(9, True) == 0.201
assert mult(12, True) == 0.201
assert mult(10000, True) == 0.201
assert mult(81, True) == 0.201
assert mult(82, True) == 0.201 * 5
assert mult(10000, True) == 0.201 * 5
79 changes: 78 additions & 1 deletion df_py/volume/test/test_calc_rewards.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# pylint: disable=too-many-lines
from datetime import datetime
from unittest.mock import MagicMock, patch

import numpy as np
import pytest
from enforce_typing import enforce_types
from pytest import approx

from df_py.util.constants import ZERO_ADDRESS
from df_py.util.constants import (
SAPPHIRE_MAINNET_CHAINID,
ZERO_ADDRESS,
)
from df_py.volume import csvs
from df_py.volume.calc_rewards import calc_volume_rewards_from_csvs
from df_py.volume.reward_calculator import TARGET_WPY, RewardCalculator
Expand Down Expand Up @@ -752,3 +756,76 @@ def mock_multipliers(DF_week, is_predictoor): # pylint: disable=unused-argument
assert rewards_info[C1][NA][LP1] == approx(60.3, abs=1e-5)
assert rewards_info[C2][NB][LP2] == 300
assert rewards_info[C2][NB][LP3] == 300


@enforce_types
def test_volume_reward_calculator_pdr_mult_week81(tmp_path):
expected_rewards = 20.1
_test_volume_reward_calculator_pdr_mult(
tmp_path, DF_week=81, expected_rewards=expected_rewards
)


@enforce_types
def test_volume_reward_calculator_pdr_mult_week82(tmp_path):
expected_rewards = 20.1 * 5
_test_volume_reward_calculator_pdr_mult(
tmp_path, DF_week=82, expected_rewards=expected_rewards
)


@enforce_types
def _test_volume_reward_calculator_pdr_mult(tmp_path, DF_week, expected_rewards):
chain_id = SAPPHIRE_MAINNET_CHAINID
stakes = {
chain_id: {NA: {LP1: 1e8}},
}
locked_amts = {
chain_id: {NA: {LP1: 1e8}},
}
volumes = {
chain_id: {
OCN_ADDR: {
NA: 100,
}
},
}
owners = {chain_id: {NA: LP2}}
symbols = {chain_id: {OCN_ADDR: OCN_SYMB}}
rates = {OCN_SYMB: 1.0}

predictoor_contracts = {NA: {}, NB: {}}

OCEAN_reward = 1e24

with patch(
"df_py.volume.allocations.load_stakes",
return_value=(stakes, locked_amts),
), patch("df_py.volume.csvs.load_nftvols_csvs", return_value=volumes), patch(
"df_py.volume.csvs.load_owners_csvs", return_value=owners
), patch(
"df_py.volume.csvs.load_symbols_csvs", return_value=symbols
), patch(
"df_py.volume.csvs.load_rate_csvs", return_value=rates
), patch(
"df_py.volume.reward_calculator.query_predictoor_contracts",
return_value=predictoor_contracts,
), patch(
"df_py.volume.reward_calculator.DEPLOYER_ADDRS",
{chain_id: ""},
), patch(
"df_py.volume.calc_rewards.get_df_week_number", return_value=DF_week
), patch(
"df_py.volume.calc_rewards.wait_to_latest_block"
), patch(
"web3.main.Web3.to_checksum_address"
) as mock:
mock.side_effect = lambda value: value

calc_volume_rewards_from_csvs(
tmp_path, datetime.now(), OCEAN_reward, True, False
)

rewards_per_lp = csvs.load_volume_rewards_csv(str(tmp_path))

assert rewards_per_lp[chain_id][LP1] == approx(expected_rewards, 1e-6)

0 comments on commit 789f9b3

Please sign in to comment.