From ce851a66de9babf4d5fa27e9629d592f0f84a933 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Thu, 20 Jun 2024 15:43:58 +0300 Subject: [PATCH 01/18] fix: also account for the redeemed invalid markets --- trades.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/trades.py b/trades.py index 80585a72..0005f4ab 100644 --- a/trades.py +++ b/trades.py @@ -720,6 +720,15 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements earnings = collateral_amount output += " Final answer: Market has been declared invalid.\n" output += f" Earnings: {wei_to_xdai(earnings)}\n" + redeemed = _is_redeemed(user_json, fpmmTrade) + if redeemed: + statistics_table[MarketAttribute.NUM_REDEEMED][ + market_status + ] += 1 + statistics_table[MarketAttribute.REDEMPTIONS][ + market_status + ] += earnings + elif outcome_index == current_answer: earnings = outcomes_tokens_traded output += f" Final answer: {fpmm['outcomes'][current_answer]!r} - Congrats! The trade was for the winner answer.\n" From b65f2fb1f11e77b4bf073946182ccf036577605c Mon Sep 17 00:00:00 2001 From: Adamantios Date: Fri, 21 Jun 2024 18:35:05 +0300 Subject: [PATCH 02/18] feat: add information about the invalid markets --- trades.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/trades.py b/trades.py index 0005f4ab..d5dd0db5 100644 --- a/trades.py +++ b/trades.py @@ -171,11 +171,13 @@ class MarketAttribute(Enum): NUM_TRADES = "Num_trades" WINNER_TRADES = "Winner_trades" NUM_REDEEMED = "Num_redeemed" + NUM_INVALID = "Num_invalid" INVESTMENT = "Investment" FEES = "Fees" MECH_CALLS = "Mech_calls" MECH_FEES = "Mech_fees" EARNINGS = "Earnings" + INVALID_PAYBACK = "Invalid_payback" NET_EARNINGS = "Net_earnings" REDEMPTIONS = "Redemptions" ROI = "ROI" @@ -476,6 +478,7 @@ def _compute_totals( ) table[MarketAttribute.NET_EARNINGS][col] = ( table[MarketAttribute.EARNINGS][col] + + table[MarketAttribute.INVALID_PAYBACK][col] - table[MarketAttribute.INVESTMENT][col] - table[MarketAttribute.FEES][col] - table[MarketAttribute.MECH_FEES][col] @@ -485,7 +488,8 @@ def _compute_totals( table[MarketAttribute.INVESTMENT][col] + table[MarketAttribute.FEES][col] + table[MarketAttribute.MECH_FEES][col], - table[MarketAttribute.EARNINGS][col], + table[MarketAttribute.EARNINGS][col] + + table[MarketAttribute.INVALID_PAYBACK][col], ) @@ -555,6 +559,16 @@ def _format_table(table: Dict[Any, Dict[Any, Any]]) -> str: ) + "\n" ) + table_str += ( + f"{MarketAttribute.NUM_INVALID:<{column_width}}" + + "".join( + [ + f"{table[MarketAttribute.NUM_INVALID][c]:>{column_width}}" + for c in STATS_TABLE_COLS + ] + ) + + "\n" + ) table_str += ( f"{MarketAttribute.MECH_CALLS:<{column_width}}" + "".join( @@ -595,6 +609,16 @@ def _format_table(table: Dict[Any, Dict[Any, Any]]) -> str: ) + "\n" ) + table_str += ( + f"{MarketAttribute.INVALID_PAYBACK:<{column_width}}" + + "".join( + [ + f"{wei_to_xdai(table[MarketAttribute.INVALID_PAYBACK][c]):>{column_width}}" + for c in STATS_TABLE_COLS + ] + ) + + "\n" + ) table_str += ( f"{MarketAttribute.EARNINGS:<{column_width}}" + "".join( @@ -700,18 +724,19 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements is_invalid = current_answer == INVALID_ANSWER if is_invalid: - earnings = collateral_amount + payback = collateral_amount output += "Current answer: Market has been declared invalid.\n" + statistics_table[MarketAttribute.INVALID_PAYBACK][market_status] += payback elif outcome_index == current_answer: earnings = outcomes_tokens_traded output += f"Current answer: {fpmm['outcomes'][current_answer]!r}\n" statistics_table[MarketAttribute.WINNER_TRADES][market_status] += 1 + statistics_table[MarketAttribute.EARNINGS][ + market_status + ] += earnings else: - earnings = 0 output += f"Current answer: {fpmm['outcomes'][current_answer]!r}\n" - statistics_table[MarketAttribute.EARNINGS][market_status] += earnings - elif market_status == MarketState.CLOSED: current_answer = int(fpmm["currentAnswer"], 16) # type: ignore is_invalid = current_answer == INVALID_ANSWER @@ -722,12 +747,15 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements output += f" Earnings: {wei_to_xdai(earnings)}\n" redeemed = _is_redeemed(user_json, fpmmTrade) if redeemed: - statistics_table[MarketAttribute.NUM_REDEEMED][ + statistics_table[MarketAttribute.NUM_INVALID][ market_status ] += 1 statistics_table[MarketAttribute.REDEMPTIONS][ market_status ] += earnings + statistics_table[MarketAttribute.INVALID_PAYBACK][ + market_status + ] += earnings elif outcome_index == current_answer: earnings = outcomes_tokens_traded @@ -748,7 +776,10 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements earnings = 0 output += f" Final answer: {fpmm['outcomes'][current_answer]!r} - The trade was for the loser answer.\n" - statistics_table[MarketAttribute.EARNINGS][market_status] += earnings + if not is_invalid: + statistics_table[MarketAttribute.EARNINGS][ + market_status + ] += earnings if 0 < earnings < DUST_THRESHOLD: output += "Earnings are dust.\n" From 166d870de3e0f125296a50ec72a03d64939352b9 Mon Sep 17 00:00:00 2001 From: Adamantios Zaras Date: Fri, 21 Jun 2024 18:42:51 +0300 Subject: [PATCH 03/18] style: rename to a more descriptive name Co-authored-by: jmoreira-valory <96571377+jmoreira-valory@users.noreply.github.com> --- trades.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trades.py b/trades.py index d5dd0db5..24198833 100644 --- a/trades.py +++ b/trades.py @@ -724,9 +724,9 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements is_invalid = current_answer == INVALID_ANSWER if is_invalid: - payback = collateral_amount + invalid_payback = collateral_amount output += "Current answer: Market has been declared invalid.\n" - statistics_table[MarketAttribute.INVALID_PAYBACK][market_status] += payback + statistics_table[MarketAttribute.INVALID_PAYBACK][market_status] += invalid_payback elif outcome_index == current_answer: earnings = outcomes_tokens_traded output += f"Current answer: {fpmm['outcomes'][current_answer]!r}\n" From 4433d50156fa8250357a118fbc2b009fd795ee04 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Fri, 21 Jun 2024 18:45:14 +0300 Subject: [PATCH 04/18] chore: bump trader version --- run_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index 363dbc54..37a00803 100755 --- a/run_service.sh +++ b/run_service.sh @@ -611,7 +611,7 @@ directory="trader" service_repo=https://github.com/$org_name/$directory.git # This is a tested version that works well. # Feel free to replace this with a different version of the repo, but be careful as there might be breaking changes -service_version="v0.16.1" +service_version="v0.16.2" # Define constants for on-chain interaction gnosis_chain_id=100 From 0fb6d41a7432c598a796eadfe2eac53fcfbe5017 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Fri, 21 Jun 2024 19:12:10 +0300 Subject: [PATCH 05/18] feat: remove `INVALID_PAYBACK` and rename `NUM_INVALID` --- trades.py | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/trades.py b/trades.py index 24198833..3da58e28 100644 --- a/trades.py +++ b/trades.py @@ -171,13 +171,12 @@ class MarketAttribute(Enum): NUM_TRADES = "Num_trades" WINNER_TRADES = "Winner_trades" NUM_REDEEMED = "Num_redeemed" - NUM_INVALID = "Num_invalid" + NUM_INVALID_MARKET = "Num_invalid_market" INVESTMENT = "Investment" FEES = "Fees" MECH_CALLS = "Mech_calls" MECH_FEES = "Mech_fees" EARNINGS = "Earnings" - INVALID_PAYBACK = "Invalid_payback" NET_EARNINGS = "Net_earnings" REDEMPTIONS = "Redemptions" ROI = "ROI" @@ -478,7 +477,6 @@ def _compute_totals( ) table[MarketAttribute.NET_EARNINGS][col] = ( table[MarketAttribute.EARNINGS][col] - + table[MarketAttribute.INVALID_PAYBACK][col] - table[MarketAttribute.INVESTMENT][col] - table[MarketAttribute.FEES][col] - table[MarketAttribute.MECH_FEES][col] @@ -488,8 +486,7 @@ def _compute_totals( table[MarketAttribute.INVESTMENT][col] + table[MarketAttribute.FEES][col] + table[MarketAttribute.MECH_FEES][col], - table[MarketAttribute.EARNINGS][col] - + table[MarketAttribute.INVALID_PAYBACK][col], + table[MarketAttribute.EARNINGS][col], ) @@ -519,7 +516,7 @@ def _get_market_state(market: Dict[str, Any]) -> MarketState: def _format_table(table: Dict[Any, Dict[Any, Any]]) -> str: - column_width = 14 + column_width = 18 table_str = " " * column_width @@ -560,10 +557,10 @@ def _format_table(table: Dict[Any, Dict[Any, Any]]) -> str: + "\n" ) table_str += ( - f"{MarketAttribute.NUM_INVALID:<{column_width}}" + f"{MarketAttribute.NUM_INVALID_MARKET:<{column_width}}" + "".join( [ - f"{table[MarketAttribute.NUM_INVALID][c]:>{column_width}}" + f"{table[MarketAttribute.NUM_INVALID_MARKET][c]:>{column_width}}" for c in STATS_TABLE_COLS ] ) @@ -609,16 +606,6 @@ def _format_table(table: Dict[Any, Dict[Any, Any]]) -> str: ) + "\n" ) - table_str += ( - f"{MarketAttribute.INVALID_PAYBACK:<{column_width}}" - + "".join( - [ - f"{wei_to_xdai(table[MarketAttribute.INVALID_PAYBACK][c]):>{column_width}}" - for c in STATS_TABLE_COLS - ] - ) - + "\n" - ) table_str += ( f"{MarketAttribute.EARNINGS:<{column_width}}" + "".join( @@ -724,19 +711,18 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements is_invalid = current_answer == INVALID_ANSWER if is_invalid: - invalid_payback = collateral_amount + earnings = collateral_amount output += "Current answer: Market has been declared invalid.\n" - statistics_table[MarketAttribute.INVALID_PAYBACK][market_status] += invalid_payback elif outcome_index == current_answer: earnings = outcomes_tokens_traded output += f"Current answer: {fpmm['outcomes'][current_answer]!r}\n" statistics_table[MarketAttribute.WINNER_TRADES][market_status] += 1 - statistics_table[MarketAttribute.EARNINGS][ - market_status - ] += earnings else: + earnings = 0 output += f"Current answer: {fpmm['outcomes'][current_answer]!r}\n" + statistics_table[MarketAttribute.EARNINGS][market_status] += earnings + elif market_status == MarketState.CLOSED: current_answer = int(fpmm["currentAnswer"], 16) # type: ignore is_invalid = current_answer == INVALID_ANSWER @@ -747,15 +733,12 @@ def parse_user( # pylint: disable=too-many-locals,too-many-statements output += f" Earnings: {wei_to_xdai(earnings)}\n" redeemed = _is_redeemed(user_json, fpmmTrade) if redeemed: - statistics_table[MarketAttribute.NUM_INVALID][ + statistics_table[MarketAttribute.NUM_INVALID_MARKET][ market_status ] += 1 statistics_table[MarketAttribute.REDEMPTIONS][ market_status ] += earnings - statistics_table[MarketAttribute.INVALID_PAYBACK][ - market_status - ] += earnings elif outcome_index == current_answer: earnings = outcomes_tokens_traded From 62ffbcffde432c94a5edf83fc84505a0992c78ae Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 15:52:51 +0200 Subject: [PATCH 06/18] fix: realitio endpoint --- run_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index 37a00803..4e366328 100755 --- a/run_service.sh +++ b/run_service.sh @@ -1102,7 +1102,7 @@ if [ -n "$SUBGRAPH_API_KEY" ]; then export CONDITIONAL_TOKENS_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/7s9rGBffUTL8kDZuxvvpuc46v44iuDarbrADBFw5uVp2" export NETWORK_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/FxV6YUix58SpYmLBwc9gEHkwjfkqwe1X5FJQjn8nKPyA" export OMEN_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz" - export REALITIO_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/E7ymrCnNcQdAAgLbdFWzGE5mvr5" + export REALITIO_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/E7ymrCnNcQdAAgLbdFWzGE5mvr5Mb5T9VfT43FqA7bNh" export TRADES_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz" fi From 6081b1b701554733fd9fb1b6b695a2139fd516a8 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:03:02 +0200 Subject: [PATCH 07/18] chore: typo --- scripts/staking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/staking.py b/scripts/staking.py index e86ab0d1..55f95589 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -353,7 +353,7 @@ def main() -> None: sys.exit(0) print( - f"Service {args.service_id} is already staked on {staking_program}." + f"Service {args.service_id} is already staked on {staking_program}. " f"Checking if the staking contract has any rewards..." ) available_rewards = get_available_rewards( From 45028f40f8f9fa6d4bcfa24b6e5e0409cf5c5780 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:03:49 +0200 Subject: [PATCH 08/18] fix: correct data type --- scripts/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/utils.py b/scripts/utils.py index b3589844..90f7d89e 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -179,6 +179,10 @@ def is_service_staked( service_staking_state = staking_contract.get_service_staking_state( ledger_api, staking_contract_address, service_id ).pop("data") + + if isinstance(service_staking_state, int): + service_staking_state = StakingState(service_staking_state) + is_staked = service_staking_state == StakingState.STAKED or service_staking_state == StakingState.EVICTED return is_staked @@ -191,6 +195,9 @@ def is_service_evicted( ledger_api, staking_contract_address, service_id ).pop("data") + if isinstance(service_staking_state, int): + service_staking_state = StakingState(service_staking_state) + is_evicted = service_staking_state == StakingState.EVICTED return is_evicted From 65efe7940bd45f8b7dd90a4a0e242f0529fbb4ed Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:04:10 +0200 Subject: [PATCH 09/18] fix: ensure Safe has the correct owner --- run_service.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/run_service.sh b/run_service.sh index 4e366328..5c588bb6 100755 --- a/run_service.sh +++ b/run_service.sh @@ -1055,6 +1055,17 @@ if [ "${USE_STAKING}" = true ]; then perform_staking_ops fi + +# ensure Safe owner is agent +# (This may occur if update flow was interrupted) +service_safe_address=$(<"../$service_safe_address_path") +current_safe_owners=$(poetry run python "../scripts/get_safe_owners.py" "$service_safe_address" "../$agent_pkey_path" "$rpc" $password_argument | awk '{gsub(/"/, "\047", $0); print $0}') +if [[ "$current_safe_owners" == "['$operator_address']" ]]; then + echo "[Operator] Swapping Safe owner..." + poetry run python "../scripts/swap_safe_owner.py" "$service_safe_address" "../$operator_pkey_path" "$agent_address" "$rpc" $password_argument +fi + + echo "" echo "Finished checking Autonolas Protocol service $service_id state." From 0f317a3c4f53fe477c33f5f832cb04e554f7aefd Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:08:12 +0200 Subject: [PATCH 10/18] chore: force ask if defined blank --- run_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index 5c588bb6..5478a84f 100755 --- a/run_service.sh +++ b/run_service.sh @@ -574,7 +574,7 @@ try_read_storage() { fi # INFO: This is a fix to avoid corrupting already-created stores - if [ -z "${SUBGRAPH_API_KEY+x}" ]; then + if [ -z "${SUBGRAPH_API_KEY}" ]; then prompt_subgraph_api_key dotenv_set_key "$env_file_path" "SUBGRAPH_API_KEY" "$SUBGRAPH_API_KEY" true fi From ed8bd2b7cace7be2cc129ff2dbddc056590d9cdb Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:10:15 +0200 Subject: [PATCH 11/18] fix: staking data type --- scripts/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/utils.py b/scripts/utils.py index b3589844..90f7d89e 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -179,6 +179,10 @@ def is_service_staked( service_staking_state = staking_contract.get_service_staking_state( ledger_api, staking_contract_address, service_id ).pop("data") + + if isinstance(service_staking_state, int): + service_staking_state = StakingState(service_staking_state) + is_staked = service_staking_state == StakingState.STAKED or service_staking_state == StakingState.EVICTED return is_staked @@ -191,6 +195,9 @@ def is_service_evicted( ledger_api, staking_contract_address, service_id ).pop("data") + if isinstance(service_staking_state, int): + service_staking_state = StakingState(service_staking_state) + is_evicted = service_staking_state == StakingState.EVICTED return is_evicted From efaf5b63ff10c9b585e5f910f3a9f8d61320033d Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:11:37 +0200 Subject: [PATCH 12/18] chore: revert --- scripts/staking.py | 2 +- scripts/utils.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/scripts/staking.py b/scripts/staking.py index 55f95589..e86ab0d1 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -353,7 +353,7 @@ def main() -> None: sys.exit(0) print( - f"Service {args.service_id} is already staked on {staking_program}. " + f"Service {args.service_id} is already staked on {staking_program}." f"Checking if the staking contract has any rewards..." ) available_rewards = get_available_rewards( diff --git a/scripts/utils.py b/scripts/utils.py index 90f7d89e..b3589844 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -179,10 +179,6 @@ def is_service_staked( service_staking_state = staking_contract.get_service_staking_state( ledger_api, staking_contract_address, service_id ).pop("data") - - if isinstance(service_staking_state, int): - service_staking_state = StakingState(service_staking_state) - is_staked = service_staking_state == StakingState.STAKED or service_staking_state == StakingState.EVICTED return is_staked @@ -195,9 +191,6 @@ def is_service_evicted( ledger_api, staking_contract_address, service_id ).pop("data") - if isinstance(service_staking_state, int): - service_staking_state = StakingState(service_staking_state) - is_evicted = service_staking_state == StakingState.EVICTED return is_evicted From ef19b676981c1db66bb1d8b8822b6c213b5ca0b1 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:12:46 +0200 Subject: [PATCH 13/18] chore: typo --- scripts/staking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/staking.py b/scripts/staking.py index e86ab0d1..55f95589 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -353,7 +353,7 @@ def main() -> None: sys.exit(0) print( - f"Service {args.service_id} is already staked on {staking_program}." + f"Service {args.service_id} is already staked on {staking_program}. " f"Checking if the staking contract has any rewards..." ) available_rewards = get_available_rewards( From ea21fa4a5646e2705b93bc4b9c2e71a1ac2605a8 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:16:55 +0200 Subject: [PATCH 14/18] chore: revert --- run_service.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/run_service.sh b/run_service.sh index 5478a84f..48ba4f28 100755 --- a/run_service.sh +++ b/run_service.sh @@ -1055,17 +1055,6 @@ if [ "${USE_STAKING}" = true ]; then perform_staking_ops fi - -# ensure Safe owner is agent -# (This may occur if update flow was interrupted) -service_safe_address=$(<"../$service_safe_address_path") -current_safe_owners=$(poetry run python "../scripts/get_safe_owners.py" "$service_safe_address" "../$agent_pkey_path" "$rpc" $password_argument | awk '{gsub(/"/, "\047", $0); print $0}') -if [[ "$current_safe_owners" == "['$operator_address']" ]]; then - echo "[Operator] Swapping Safe owner..." - poetry run python "../scripts/swap_safe_owner.py" "$service_safe_address" "../$operator_pkey_path" "$agent_address" "$rpc" $password_argument -fi - - echo "" echo "Finished checking Autonolas Protocol service $service_id state." From 825cd0fa615009ef1745dd03a010a126c5f06c83 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:17:55 +0200 Subject: [PATCH 15/18] feat: ensure Safe owner is agent --- run_service.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/run_service.sh b/run_service.sh index 37a00803..524aefeb 100755 --- a/run_service.sh +++ b/run_service.sh @@ -1055,6 +1055,17 @@ if [ "${USE_STAKING}" = true ]; then perform_staking_ops fi + +# ensure Safe owner is agent +# (This may occur if update flow was interrupted) +service_safe_address=$(<"../$service_safe_address_path") +current_safe_owners=$(poetry run python "../scripts/get_safe_owners.py" "$service_safe_address" "../$agent_pkey_path" "$rpc" $password_argument | awk '{gsub(/"/, "\047", $0); print $0}') +if [[ "$current_safe_owners" == "['$operator_address']" ]]; then + echo "[Operator] Swapping Safe owner..." + poetry run python "../scripts/swap_safe_owner.py" "$service_safe_address" "../$operator_pkey_path" "$agent_address" "$rpc" $password_argument +fi + + echo "" echo "Finished checking Autonolas Protocol service $service_id state." From 7d011393dfe311820793db41766dc29789142b2e Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 17:34:15 +0200 Subject: [PATCH 16/18] chore: don't allow blank api keys --- run_service.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/run_service.sh b/run_service.sh index 48ba4f28..a07e4c8b 100755 --- a/run_service.sh +++ b/run_service.sh @@ -400,15 +400,17 @@ prompt_use_staking() { # Prompt user for subgraph API key prompt_subgraph_api_key() { - echo "Please provide a Subgraph API key" - echo "---------------------------------" + echo "Provide a Subgraph API key" + echo "--------------------------" echo "Since June 12, 2024, you need a Subgraph API key that can be obtained at The Graph https://thegraph.com/studio/apikeys/" echo "" - echo "If you set your Subgraph API key to blank, the script will use the deprecated Subgraph endpoints (hosted services)." - echo "These deprecated endpoints might stop working, and you will need to manually edit the .trader_runner/.env file to provide your API key." - echo "" - read -rsp "Enter a Subgraph API key [hidden input]: " SUBGRAPH_API_KEY + read -rsp "Please, enter a Subgraph API key [hidden input]: " SUBGRAPH_API_KEY echo "" + while [ -z "${SUBGRAPH_API_KEY}" ]; do + echo "You cannot enter a blank API key." + read -rsp "Please, enter a Subgraph API key [hidden input]: " SUBGRAPH_API_KEY + echo "" + done } # Verify if there are enough slots for staking this service From 761f60bcfdc1b48e9835bf8ab873b5ce2682a012 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 18:10:27 +0200 Subject: [PATCH 17/18] fix: script subgraph endpoints --- trades.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/trades.py b/trades.py index 3da58e28..b99feae9 100644 --- a/trades.py +++ b/trades.py @@ -21,9 +21,11 @@ """This script queries the OMEN subgraph to obtain the trades of a given address.""" import datetime +import os import re from argparse import Action, ArgumentError, ArgumentParser, Namespace from collections import defaultdict +from dotenv import load_dotenv from enum import Enum from pathlib import Path from string import Template @@ -57,12 +59,16 @@ SCRIPT_PATH = Path(__file__).resolve().parent STORE_PATH = Path(SCRIPT_PATH, ".trader_runner") RPC_PATH = Path(STORE_PATH, "rpc.txt") +ENV_FILE = Path(STORE_PATH, ".env") WXDAI_CONTRACT_ADDRESS = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" SCRIPT_PATH = Path(__file__).resolve().parent STORE_PATH = Path(SCRIPT_PATH, ".trader_runner") SAFE_ADDRESS_PATH = Path(STORE_PATH, "service_safe_address.txt") +load_dotenv(ENV_FILE) + + headers = { "Accept": "application/json, multipart/mixed", "Content-Type": "application/json", @@ -323,7 +329,8 @@ def _query_omen_xdai_subgraph( # pylint: disable=too-many-locals fpmm_to_timestamp: float = DEFAULT_TO_TIMESTAMP, ) -> Dict[str, Any]: """Query the subgraph.""" - url = "https://api.thegraph.com/subgraphs/name/protofire/omen-xdai" + subgraph_api_key = os.getenv('SUBGRAPH_API_KEY') + url = f"https://gateway-arbitrum.network.thegraph.com/api/{subgraph_api_key}/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz" grouped_results = defaultdict(list) creationTimestamp_gt = "0" @@ -368,7 +375,8 @@ def _query_omen_xdai_subgraph( # pylint: disable=too-many-locals def _query_conditional_tokens_gc_subgraph(creator: str) -> Dict[str, Any]: """Query the subgraph.""" - url = "https://api.thegraph.com/subgraphs/name/gnosis/conditional-tokens-gc" + subgraph_api_key = os.getenv('SUBGRAPH_API_KEY') + url = f"https://gateway-arbitrum.network.thegraph.com/api/{subgraph_api_key}/subgraphs/id/7s9rGBffUTL8kDZuxvvpuc46v44iuDarbrADBFw5uVp2" all_results: Dict[str, Any] = {"data": {"user": {"userPositions": []}}} userPositions_id_gt = "" From d743b74367b742169c20d51d866b69fb263580b9 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 26 Jun 2024 18:18:20 +0200 Subject: [PATCH 18/18] fix: omen endpoint on script --- rank_traders.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rank_traders.py b/rank_traders.py index 699b8f07..d9f087a8 100644 --- a/rank_traders.py +++ b/rank_traders.py @@ -21,9 +21,12 @@ """This script queries the OMEN subgraph to obtain the trades of a given address.""" import datetime +import os import sys from argparse import ArgumentParser from collections import defaultdict +from dotenv import load_dotenv +from pathlib import Path from string import Template from typing import Any @@ -38,6 +41,11 @@ FPMM_CREATOR = "0x89c5cc945dd550bcffb72fe42bff002429f46fec" DEFAULT_FROM_DATE = "1970-01-01T00:00:00" DEFAULT_TO_DATE = "2038-01-19T03:14:07" +SCRIPT_PATH = Path(__file__).resolve().parent +STORE_PATH = Path(SCRIPT_PATH, ".trader_runner") +ENV_FILE = Path(STORE_PATH, ".env") + +load_dotenv(ENV_FILE) headers = { @@ -167,7 +175,8 @@ def _query_omen_xdai_subgraph( fpmm_to_timestamp: float, ) -> dict[str, Any]: """Query the subgraph.""" - url = "https://api.thegraph.com/subgraphs/name/protofire/omen-xdai" + subgraph_api_key = os.getenv('SUBGRAPH_API_KEY') + url = f"https://gateway-arbitrum.network.thegraph.com/api/{subgraph_api_key}/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz" grouped_results = defaultdict(list) id_gt = ""