From 4cffbab0281b9333dd39c7c42269f3ae1d0d38fc Mon Sep 17 00:00:00 2001 From: trizin <25263018+trizin@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:51:37 +0300 Subject: [PATCH] [predictoor] Use float instead of int for stake amount (#259) * Use float instead of int * Fix stake calculation in approach 2 * Add comment * Update envvars readme * Black * Fix linter error * Blackl --- READMEs/envvars.md | 4 ++++ pdr_backend/predictoor/approach2/main2.py | 2 +- pdr_backend/predictoor/base_predictoor_config.py | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/READMEs/envvars.md b/READMEs/envvars.md index 96c806d88..81a6b7a0c 100644 --- a/READMEs/envvars.md +++ b/READMEs/envvars.md @@ -38,6 +38,10 @@ These are envvars that are specific to a given agent. ### Predictoor Agent - **SECONDS_TILL_EPOCH_END**: Determines how soon to start predicting. Example: if value is `60` then it will start submitting predictions 60 seconds before. It will continue to periodically submit predictions until there's no time left. +- **STAKE_AMOUNT**: The amount to stake in units of Eth. + - For approach 1 stake amount is randomly determined this has no effect. + - For approach 2 stake amount is determined by: `STAKE_AMOUNT * confidence` where confidence is between 0 and 1. + - For approach 3 this is the stake amount. ### DFBuyer Agent diff --git a/pdr_backend/predictoor/approach2/main2.py b/pdr_backend/predictoor/approach2/main2.py index 9d4f0d6ba..9b82c0fd8 100644 --- a/pdr_backend/predictoor/approach2/main2.py +++ b/pdr_backend/predictoor/approach2/main2.py @@ -95,7 +95,7 @@ def process_block(block, model, main_pd): if predicted_value is not None and predicted_confidence > 0: # We have a prediction, let's submit it stake_amount = ( - int(getenv("STAKE_AMOUNT", "1")) * predicted_confidence / 100 + int(getenv("STAKE_AMOUNT", "1")) * predicted_confidence ) # TO DO have a customizable function to handle this print( f"Contract:{predictoor_contract.contract_address} - " diff --git a/pdr_backend/predictoor/base_predictoor_config.py b/pdr_backend/predictoor/base_predictoor_config.py index f77bb92a8..926237b05 100644 --- a/pdr_backend/predictoor/base_predictoor_config.py +++ b/pdr_backend/predictoor/base_predictoor_config.py @@ -37,4 +37,9 @@ class BasePredictoorConfig(BaseConfig, ABC): def __init__(self): super().__init__() self.s_until_epoch_end = int(getenv("SECONDS_TILL_EPOCH_END", "60")) - self.stake_amount = int(getenv("STAKE_AMOUNT", "1")) + + # For approach 1 stake amount is randomly determined this has no effect. + # For approach 2 stake amount is determined by: + # `STAKE_AMOUNT * confidence` where confidence is between 0 and 1. + # For approach 3 this is the stake amount. + self.stake_amount = float(getenv("STAKE_AMOUNT", "1")) # stake amount in eth