From 850a1666a5a7e2671ad6515f51c0f1dcc71e1df0 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 10 Apr 2024 17:39:40 +0200 Subject: [PATCH 1/9] feat: update trader --- run_service.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index 0a6e93a..05fe3b8 100755 --- a/run_service.sh +++ b/run_service.sh @@ -581,7 +581,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.13.1" +service_version="v0.13.2" # Define constants for on-chain interaction gnosis_chain_id=100 @@ -604,6 +604,9 @@ export CUSTOM_GNOSIS_SAFE_SAME_ADDRESS_MULTISIG_ADDRESS="0x6e7f594f680f7aBad18b7 export CUSTOM_MULTISEND_ADDRESS="0x40A2aCCbd92BCA938b02010E17A5b8929b49130D" export MECH_CONTRACT_ADDRESS="0x77af31De935740567Cf4fF1986D04B2c964A786a" export WXDAI_ADDRESS="0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" +export DISABLE_TRADING=false +export STOP_TRADING_IF_STAKING_KPI_MET=true +export RESET_PAUSE_DURATION=300 # check if USE_NEVERMINED is set to true if [ "$USE_NEVERMINED" == "true" ]; From fcede63c658a6b5fe358f9a7c6816b9098ddff68 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 10 Apr 2024 17:43:14 +0200 Subject: [PATCH 2/9] chore: update version --- run_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index 05fe3b8..8368c1e 100755 --- a/run_service.sh +++ b/run_service.sh @@ -581,7 +581,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.13.2" +service_version="feat/stop_trading_conditions_2" # Define constants for on-chain interaction gnosis_chain_id=100 From 67553a3acff73db110bcc031e1e02d942737f043 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 10 Apr 2024 18:53:51 +0200 Subject: [PATCH 3/9] feat: unstake old contracts --- scripts/staking.py | 53 +++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/scripts/staking.py b/scripts/staking.py index 5934938..0396e29 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -45,8 +45,9 @@ ) -EVEREST_STAKING_CONTRACT_ADDRESS = "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C" - +OLD_STAKING_PROGRAMS = { + "Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C" +} def _format_duration(duration_seconds: int) -> str: days, remainder = divmod(duration_seconds, 86400) @@ -56,21 +57,28 @@ def _format_duration(duration_seconds: int) -> str: return formatted_duration -def _unstake_everest( - ledger_api: EthereumApi, service_id: int, owner_crypto: EthereumCrypto +def _unstake( + ledger_api: EthereumApi, service_id: int, staking_contract_address: str, staking_program: str, owner_crypto: EthereumCrypto ) -> None: - print("Checking if service is staked on Everest...") - staking_contract_address = EVEREST_STAKING_CONTRACT_ADDRESS - - if service_id not in get_service_ids(ledger_api, staking_contract_address): - print(f"Service {service_id} is not staked on Everest.") - return + print(f"Checking if service is staked on {staking_program}...") + + # Check if service is staked + if staking_program == "Everest": + if service_id not in get_service_ids(ledger_api, staking_contract_address): + print(f"Service {service_id} is not staked on {staking_program}.") + return + elif staking_program == "Alpine": + if not is_service_staked( + ledger_api, args.service_id, args.staking_contract_address + ): + print(f"Service {args.service_id} is not staked on {staking_program}..") + return print( - f"Service {service_id} is staked on Everest. To continue in a new staking program, first, it must be unstaked from Everest." + f"Service {service_id} is staked on {staking_program}. To continue in a new staking program, first, it must be unstaked from {staking_program}." ) user_input = input( - "Do you want to continue unstaking from Everest? (yes/no)\n" + "Do you want to continue unstaking from {staking_program}? (yes/no)\n" ).lower() print() @@ -78,11 +86,22 @@ def _unstake_everest( print("Terminating script.") sys.exit(1) - print(f"Unstaking service {service_id} from Everest...") - unstake_txs = get_unstake_txs(ledger_api, service_id, staking_contract_address) + print(f"Unstaking service {service_id} from {staking_program}...") + unstake_txs = get_unstake_txs( + ledger_api, service_id, staking_contract_address + ) for tx in unstake_txs: send_tx_and_wait_for_receipt(ledger_api, owner_crypto, tx) - print("Successfully unstaked from Everest.") + print( + f"Successfully unstaked service {args.service_id} from {staking_program}." + ) + + +def _unstake_old_programs( + ledger_api: EthereumApi, service_id: int, owner_crypto: EthereumCrypto +) -> None: + for program, address in OLD_STAKING_PROGRAMS.items(): + _unstake(ledger_api, service_id, address, program, owner_crypto) def _check_unstaking_availability( @@ -184,7 +203,7 @@ def _try_stake_service( private_key_path=args.owner_private_key_path, password=args.password ) - _unstake_everest(ledger_api, args.service_id, owner_crypto) + _unstake_old_programs(ledger_api, args.service_id, owner_crypto) # Collect information next_ts = get_next_checkpoint_ts(ledger_api, args.staking_contract_address) @@ -208,7 +227,7 @@ def _try_stake_service( ledger_api, args.service_id, args.staking_contract_address ): # the service is not staked, so we don't need to do anything - print(f"Service {args.service_id} is not staked.") + print(f"Service {args.service_id} is not staked on {staking_program}..") sys.exit(0) if is_service_evicted( From f4a532d417c82832cee372173377b17721f707c1 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 10 Apr 2024 18:57:01 +0200 Subject: [PATCH 4/9] chore: format code --- scripts/staking.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/staking.py b/scripts/staking.py index 0396e29..dcbe209 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -45,9 +45,8 @@ ) -OLD_STAKING_PROGRAMS = { - "Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C" -} +OLD_STAKING_PROGRAMS = {"Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"} + def _format_duration(duration_seconds: int) -> str: days, remainder = divmod(duration_seconds, 86400) @@ -58,7 +57,11 @@ def _format_duration(duration_seconds: int) -> str: def _unstake( - ledger_api: EthereumApi, service_id: int, staking_contract_address: str, staking_program: str, owner_crypto: EthereumCrypto + ledger_api: EthereumApi, + service_id: int, + staking_contract_address: str, + staking_program: str, + owner_crypto: EthereumCrypto, ) -> None: print(f"Checking if service is staked on {staking_program}...") @@ -87,14 +90,10 @@ def _unstake( sys.exit(1) print(f"Unstaking service {service_id} from {staking_program}...") - unstake_txs = get_unstake_txs( - ledger_api, service_id, staking_contract_address - ) + unstake_txs = get_unstake_txs(ledger_api, service_id, staking_contract_address) for tx in unstake_txs: send_tx_and_wait_for_receipt(ledger_api, owner_crypto, tx) - print( - f"Successfully unstaked service {args.service_id} from {staking_program}." - ) + print(f"Successfully unstaked service {args.service_id} from {staking_program}.") def _unstake_old_programs( From 12296757a3e2dbbf04f7d6b5b76e53b40be302b7 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Wed, 10 Apr 2024 19:02:21 +0200 Subject: [PATCH 5/9] chore: minor update --- scripts/staking.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/staking.py b/scripts/staking.py index dcbe209..1dd910b 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -66,11 +66,11 @@ def _unstake( print(f"Checking if service is staked on {staking_program}...") # Check if service is staked - if staking_program == "Everest": + if staking_program.startswith("Everest"): if service_id not in get_service_ids(ledger_api, staking_contract_address): print(f"Service {service_id} is not staked on {staking_program}.") return - elif staking_program == "Alpine": + elif staking_program.startswith("Alpine"): if not is_service_staked( ledger_api, args.service_id, args.staking_contract_address ): From bb8243b1bd154c0a505b88890a87efefda42e2e5 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Fri, 12 Apr 2024 12:25:05 +0200 Subject: [PATCH 6/9] chore: update variables --- run_service.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/run_service.sh b/run_service.sh index 8368c1e..378df5b 100755 --- a/run_service.sh +++ b/run_service.sh @@ -602,8 +602,9 @@ export CUSTOM_SERVICE_REGISTRY_TOKEN_UTILITY_ADDRESS="0xa45E64d13A30a51b91ae0eb1 export CUSTOM_GNOSIS_SAFE_PROXY_FACTORY_ADDRESS="0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE" export CUSTOM_GNOSIS_SAFE_SAME_ADDRESS_MULTISIG_ADDRESS="0x6e7f594f680f7aBad18b7a63de50F0FeE47dfD06" export CUSTOM_MULTISEND_ADDRESS="0x40A2aCCbd92BCA938b02010E17A5b8929b49130D" -export MECH_CONTRACT_ADDRESS="0x77af31De935740567Cf4fF1986D04B2c964A786a" export WXDAI_ADDRESS="0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" +export MECH_CONTRACT_ADDRESS="0x77af31De935740567Cf4fF1986D04B2c964A786a" +export MECH_WRAPPED_NATIVE_TOKEN_ADDRESS=$WXDAI_ADDRESS export DISABLE_TRADING=false export STOP_TRADING_IF_STAKING_KPI_MET=true export RESET_PAUSE_DURATION=300 @@ -614,7 +615,7 @@ then echo "A Nevermined subscription will be used to pay for the mech requests." export MECH_CONTRACT_ADDRESS="0x327E26bDF1CfEa50BFAe35643B23D5268E41F7F9" export AGENT_REGISTRY_ADDRESS="0xAed729d4f4b895d8ca84ba022675bB0C44d2cD52" - export REQUEST_PRICE=0 + export MECH_REQUEST_PRICE=0 fi sleep_duration=12 From ec444dc23b1fa143465c558d4bec9f2e94b90f62 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Fri, 12 Apr 2024 15:16:25 +0200 Subject: [PATCH 7/9] fix: version --- run_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index 378df5b..be8418e 100755 --- a/run_service.sh +++ b/run_service.sh @@ -581,7 +581,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="feat/stop_trading_conditions_2" +service_version="v0.13.2" # Define constants for on-chain interaction gnosis_chain_id=100 From 5eeafdafd470d4c9e90d936c81f4f885fd407f70 Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Fri, 12 Apr 2024 18:12:44 +0200 Subject: [PATCH 8/9] chore: update report --- report.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/report.py b/report.py index 0ef2ac7..7c6e441 100644 --- a/report.py +++ b/report.py @@ -77,6 +77,17 @@ "contracts", "ServiceRegistryTokenUtility.json", ) +MECH_CONTRACT_ADDRESS = "0x77af31De935740567Cf4fF1986D04B2c964A786a" +MECH_CONTRACT_JSON_PATH = Path( + SCRIPT_PATH, + "trader", + "packages", + "valory", + "contracts", + "mech", + "build", + "mech.json", +) SAFE_BALANCE_THRESHOLD = 500000000000000000 AGENT_XDAI_BALANCE_THRESHOLD = 50000000000000000 @@ -277,6 +288,15 @@ def _parse_args() -> Any: abi=service_registry_token_utility_abi, ) + with open(MECH_CONTRACT_JSON_PATH, "r", encoding="utf-8") as file: + mech_contract_data = json.load(file) + + mech_contract_abi = mech_contract_data.get("abi", []) + + mech_contract = w3.eth.contract( + address=MECH_CONTRACT_ADDRESS, abi=mech_contract_abi + ) + security_deposit = ( service_registry_token_utility_contract.functions.getOperatorBalance( operator_address, service_id @@ -320,9 +340,16 @@ def _parse_args() -> Any: service_staking_token_contract.functions.livenessPeriod().call() ) last_checkpoint_ts = next_checkpoint_ts - liveness_period - mech_requests_current_epoch = _get_mech_requests_count( - mech_requests, last_checkpoint_ts - ) + + mech_request_count = mech_contract.functions.getRequestsCount(safe_address).call() + mech_request_count_on_last_checkpoint = ( + service_staking_token_contract.functions.getServiceInfo(service_id).call() + )[2][1] + mech_requests_since_last_cp = mech_request_count - mech_request_count_on_last_checkpoint + # mech_requests_current_epoch = _get_mech_requests_count( + # mech_requests, last_checkpoint_ts + # ) + mech_requests_current_epoch = mech_requests_since_last_cp _print_status( "Num. Mech txs current epoch", f"{mech_requests_current_epoch} {_warning_message(mech_requests_current_epoch, mech_requests_24h_threshold, f'- Too low. Threshold is {mech_requests_24h_threshold}.')}", From f2bd34361c7a2793cac44b901da584bba2cc580d Mon Sep 17 00:00:00 2001 From: jmoreira-valory Date: Mon, 15 Apr 2024 15:02:12 +0200 Subject: [PATCH 9/9] chore: update trader --- run_service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.sh b/run_service.sh index be8418e..fb45a32 100755 --- a/run_service.sh +++ b/run_service.sh @@ -581,7 +581,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.13.2" +service_version="v0.14.0" # Define constants for on-chain interaction gnosis_chain_id=100