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

#697 - Automatically claim payouts for previous epochs #698

Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
da762a0
Add s_start_payouts into ppss.yaml
trizin Feb 29, 2024
dfbe061
Add s_start_payouts into predictoor_ss
trizin Feb 29, 2024
465730d
220
trizin Feb 29, 2024
7f57598
Auto claim payout
trizin Feb 29, 2024
58e8628
Fix import path
trizin Feb 29, 2024
08464e0
Formatting
trizin Feb 29, 2024
fbcad15
Merge branch 'main' into issue697-predictoor-automatically-claim-payo…
trizin Feb 29, 2024
a2ca31b
Merge branch 'main' into issue697-predictoor-automatically-claim-payo…
trizin Feb 29, 2024
5ee1dad
Add missing import
trizin Feb 29, 2024
c47b26d
Fixes nad more logging
trizin Feb 29, 2024
e65d2da
Merge branch 'issue697-predictoor-automatically-claim-payouts-for-pre…
trizin Feb 29, 2024
9485abf
Fix check
trizin Feb 29, 2024
ce414ed
Formatting
trizin Feb 29, 2024
25659d4
Update mock
trizin Feb 29, 2024
71d6ac4
Remove unnecessary keys
trizin Feb 29, 2024
221ad74
Merge branch 'issue697-predictoor-automatically-claim-payouts-for-pre…
trizin Feb 29, 2024
dead917
Formatting
trizin Feb 29, 2024
3fb1a12
Linter
trizin Feb 29, 2024
0b76a24
Linter
trizin Feb 29, 2024
65957a6
Add missing param
trizin Feb 29, 2024
753e5e3
Move logic to get_payout function
trizin Mar 1, 2024
e371276
Merge branch 'main' into issue697-predictoor-automatically-claim-payo…
trizin Mar 1, 2024
ff5dabe
Move everything to `get_payout`
trizin Mar 1, 2024
fb88ff9
Add test_s_start_payouts
trizin Mar 1, 2024
d65b82d
Update key
trizin Mar 1, 2024
5b13f32
Formatting
trizin Mar 2, 2024
2e38286
Merge branch 'main' into issue697-predictoor-automatically-claim-payo…
trizin Mar 2, 2024
e918be7
Remove unnecesary mock
trizin Mar 3, 2024
47f10a4
Move under existing test_predictoor_ss_test_dict test
trizin Mar 3, 2024
e419348
Correct import order
trizin Mar 3, 2024
75fc3ab
Merge branch 'main' into issue697-predictoor-automatically-claim-payo…
trizin Mar 3, 2024
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: 6 additions & 0 deletions pdr_backend/ppss/predictoor_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def revenue(self) -> Eth:
"""
return Eth(self.d["sim_only"]["revenue"])

@property
def s_start_payouts(self) -> int:
if "s_start_payouts" not in self.d["bot_only"]:
return 0
return self.d["bot_only"]["s_start_payouts"]

@property
def s_until_epoch_end(self) -> int:
return self.d["bot_only"]["s_until_epoch_end"]
Expand Down
3 changes: 3 additions & 0 deletions pdr_backend/ppss/web3_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ def get_current_epoch(self) -> int:
def set_token(self, web3_pp):
pass

def s_start_payouts(self) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's an addition to a mock predictoor_contract object. Not the correct place. If it were to be added, it should be an addition to a mock predictoor_ss object

return 0 # disabled

def get_current_epoch_ts(self) -> UnixTimeS:
"""Returns a timestamp"""
return UnixTimeS(self._w3.eth.timestamp // self.s_per_epoch * self.s_per_epoch)
Expand Down
29 changes: 28 additions & 1 deletion pdr_backend/predictoor/predictoor_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
from pdr_backend.util.logutil import logging_has_stdout
from pdr_backend.util.time_types import UnixTimeS
from pdr_backend.util.web3_config import Web3Config
from pdr_backend.payout.payout import do_ocean_payout
trentmc marked this conversation as resolved.
Show resolved Hide resolved
from pdr_backend.util.currency_types import Eth


logger = logging.getLogger("predictoor_agent")


# pylint: disable=too-many-public-methods
class PredictoorAgent:
"""
What it does
Expand Down Expand Up @@ -92,6 +93,7 @@ def __init__(self, ppss: PPSS):
self.prev_block_timestamp: UnixTimeS = UnixTimeS(0)
self.prev_block_number: UnixTimeS = UnixTimeS(0)
self.prev_submit_epochs: List[int] = []
self.prev_submit_payouts: List[int] = []

@enforce_types
def run(self):
Expand All @@ -118,6 +120,26 @@ def take_step(self):
self.prev_block_number = UnixTimeS(self.cur_block_number)
self.prev_block_timestamp = UnixTimeS(self.cur_timestamp)

trentmc marked this conversation as resolved.
Show resolved Hide resolved
# within the time window to run payout?
if (
self.s_start_payouts != 0
and self.cur_epoch_s_left < self.s_start_payouts
and self.cur_epoch not in self.prev_submit_payouts
):
trentmc marked this conversation as resolved.
Show resolved Hide resolved
# run payout
# pylint: disable=line-too-long
logger.info(
"Running payouts, set predictoor_ss.bot_only.s_start_payouts to 0 to disable auto payouts"
)
trentmc marked this conversation as resolved.
Show resolved Hide resolved
web3_config = self._updown_web3_config(True)
self.ppss.web3_pp.set_web3_config(web3_config)
do_ocean_payout(self.ppss, False)
web3_config = self._updown_web3_config(False)
self.ppss.web3_pp.set_web3_config(web3_config)
do_ocean_payout(self.ppss, False)
self.prev_submit_payouts.append(self.cur_epoch)
return

# within the time window to predict?
if self.cur_epoch_s_left > self.epoch_s_thr:
return
Expand Down Expand Up @@ -165,6 +187,11 @@ def cur_block_number(self) -> int:
def cur_timestamp(self) -> UnixTimeS:
return UnixTimeS(self.cur_block["timestamp"])

@property
def s_start_payouts(self) -> int:
"""Run payout when there's this seconds left"""
return self.ppss.predictoor_ss.s_start_payouts

trentmc marked this conversation as resolved.
Show resolved Hide resolved
@property
def epoch_s_thr(self):
"""Start predicting if there's > this time left"""
Expand Down
1 change: 1 addition & 0 deletions ppss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ predictoor_ss:

bot_only:
s_until_epoch_end: 60 # in s. Start predicting if there's > this time left
s_start_payouts: 220 # in s. Run payout when there's this seconds left, set to 0 to disable
s_cutoff: 20 # in s. Stop predicting if there's < this time left

aimodel_ss:
Expand Down
20 changes: 4 additions & 16 deletions system_tests/test_predictoor_system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
from unittest.mock import Mock, patch, MagicMock

Expand All @@ -20,6 +19,7 @@ def setup_mock_web3_pp(mock_feeds, mock_predictoor_contract):
mock_predictoor_ss = Mock()
mock_predictoor_ss.get_feed_from_candidates.return_value = mock_feeds["0x1"]
mock_predictoor_ss.s_until_epoch_end = 100
mock_predictoor_ss.s_start_payouts = 0

mock_web3_config = Mock(spec=Web3Config)
mock_web3_config.w3 = Mock()
Expand All @@ -30,13 +30,7 @@ def setup_mock_web3_pp(mock_feeds, mock_predictoor_contract):
return mock_web3_pp, mock_predictoor_ss


def _test_predictoor_system(
mock_feeds, mock_predictoor_contract, approach, caplog, monkeypatch
):
PRIV_KEY = str(os.getenv("PRIVATE_KEY"))
PRIV_KEY2 = str(PRIV_KEY[:-4] + "0000")
monkeypatch.setenv("PRIVATE_KEY2", PRIV_KEY2)

def _test_predictoor_system(mock_feeds, mock_predictoor_contract, approach, caplog):
mock_web3_pp, mock_predictoor_ss = setup_mock_web3_pp(
mock_feeds, mock_predictoor_contract
)
Expand Down Expand Up @@ -75,12 +69,9 @@ def test_predictoor_approach_1_system(
mock_feeds,
mock_predictoor_contract,
caplog,
monkeypatch,
):
_ = mock_verify_feed_dependencies
_test_predictoor_system(
mock_feeds, mock_predictoor_contract, 1, caplog, monkeypatch
)
_test_predictoor_system(mock_feeds, mock_predictoor_contract, 1, caplog)


@patch("pdr_backend.ppss.ppss.PPSS.verify_feed_dependencies")
Expand All @@ -89,9 +80,6 @@ def test_predictoor_approach_3_system(
mock_feeds,
mock_predictoor_contract,
caplog,
monkeypatch,
):
_ = mock_verify_feed_dependencies
_test_predictoor_system(
mock_feeds, mock_predictoor_contract, 3, caplog, monkeypatch
)
_test_predictoor_system(mock_feeds, mock_predictoor_contract, 3, caplog)
Loading