Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 986ebc2

Browse files
authored
Merge pull request #262 from valory-xyz/develop
Release v0.14.0
2 parents 316d823 + 9f13206 commit 986ebc2

File tree

3 files changed

+70
-21
lines changed

3 files changed

+70
-21
lines changed

report.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
"contracts",
7878
"ServiceRegistryTokenUtility.json",
7979
)
80+
MECH_CONTRACT_ADDRESS = "0x77af31De935740567Cf4fF1986D04B2c964A786a"
81+
MECH_CONTRACT_JSON_PATH = Path(
82+
SCRIPT_PATH,
83+
"trader",
84+
"packages",
85+
"valory",
86+
"contracts",
87+
"mech",
88+
"build",
89+
"mech.json",
90+
)
8091

8192
SAFE_BALANCE_THRESHOLD = 500000000000000000
8293
AGENT_XDAI_BALANCE_THRESHOLD = 50000000000000000
@@ -277,6 +288,15 @@ def _parse_args() -> Any:
277288
abi=service_registry_token_utility_abi,
278289
)
279290

291+
with open(MECH_CONTRACT_JSON_PATH, "r", encoding="utf-8") as file:
292+
mech_contract_data = json.load(file)
293+
294+
mech_contract_abi = mech_contract_data.get("abi", [])
295+
296+
mech_contract = w3.eth.contract(
297+
address=MECH_CONTRACT_ADDRESS, abi=mech_contract_abi
298+
)
299+
280300
security_deposit = (
281301
service_registry_token_utility_contract.functions.getOperatorBalance(
282302
operator_address, service_id
@@ -320,9 +340,16 @@ def _parse_args() -> Any:
320340
service_staking_token_contract.functions.livenessPeriod().call()
321341
)
322342
last_checkpoint_ts = next_checkpoint_ts - liveness_period
323-
mech_requests_current_epoch = _get_mech_requests_count(
324-
mech_requests, last_checkpoint_ts
325-
)
343+
344+
mech_request_count = mech_contract.functions.getRequestsCount(safe_address).call()
345+
mech_request_count_on_last_checkpoint = (
346+
service_staking_token_contract.functions.getServiceInfo(service_id).call()
347+
)[2][1]
348+
mech_requests_since_last_cp = mech_request_count - mech_request_count_on_last_checkpoint
349+
# mech_requests_current_epoch = _get_mech_requests_count(
350+
# mech_requests, last_checkpoint_ts
351+
# )
352+
mech_requests_current_epoch = mech_requests_since_last_cp
326353
_print_status(
327354
"Num. Mech txs current epoch",
328355
f"{mech_requests_current_epoch} {_warning_message(mech_requests_current_epoch, mech_requests_24h_threshold, f'- Too low. Threshold is {mech_requests_24h_threshold}.')}",

run_service.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ directory="trader"
581581
service_repo=https://github.com/$org_name/$directory.git
582582
# This is a tested version that works well.
583583
# Feel free to replace this with a different version of the repo, but be careful as there might be breaking changes
584-
service_version="v0.13.1"
584+
service_version="v0.14.0"
585585

586586
# Define constants for on-chain interaction
587587
gnosis_chain_id=100
@@ -602,16 +602,20 @@ export CUSTOM_SERVICE_REGISTRY_TOKEN_UTILITY_ADDRESS="0xa45E64d13A30a51b91ae0eb1
602602
export CUSTOM_GNOSIS_SAFE_PROXY_FACTORY_ADDRESS="0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE"
603603
export CUSTOM_GNOSIS_SAFE_SAME_ADDRESS_MULTISIG_ADDRESS="0x6e7f594f680f7aBad18b7a63de50F0FeE47dfD06"
604604
export CUSTOM_MULTISEND_ADDRESS="0x40A2aCCbd92BCA938b02010E17A5b8929b49130D"
605-
export MECH_CONTRACT_ADDRESS="0x77af31De935740567Cf4fF1986D04B2c964A786a"
606605
export WXDAI_ADDRESS="0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"
606+
export MECH_CONTRACT_ADDRESS="0x77af31De935740567Cf4fF1986D04B2c964A786a"
607+
export MECH_WRAPPED_NATIVE_TOKEN_ADDRESS=$WXDAI_ADDRESS
608+
export DISABLE_TRADING=false
609+
export STOP_TRADING_IF_STAKING_KPI_MET=true
610+
export RESET_PAUSE_DURATION=300
607611

608612
# check if USE_NEVERMINED is set to true
609613
if [ "$USE_NEVERMINED" == "true" ];
610614
then
611615
echo "A Nevermined subscription will be used to pay for the mech requests."
612616
export MECH_CONTRACT_ADDRESS="0x327E26bDF1CfEa50BFAe35643B23D5268E41F7F9"
613617
export AGENT_REGISTRY_ADDRESS="0xAed729d4f4b895d8ca84ba022675bB0C44d2cD52"
614-
export REQUEST_PRICE=0
618+
export MECH_REQUEST_PRICE=0
615619
fi
616620

617621
sleep_duration=12

scripts/staking.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
)
4646

4747

48-
EVEREST_STAKING_CONTRACT_ADDRESS = "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"
48+
OLD_STAKING_PROGRAMS = {"Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"}
4949

5050

5151
def _format_duration(duration_seconds: int) -> str:
@@ -56,33 +56,51 @@ def _format_duration(duration_seconds: int) -> str:
5656
return formatted_duration
5757

5858

59-
def _unstake_everest(
60-
ledger_api: EthereumApi, service_id: int, owner_crypto: EthereumCrypto
59+
def _unstake(
60+
ledger_api: EthereumApi,
61+
service_id: int,
62+
staking_contract_address: str,
63+
staking_program: str,
64+
owner_crypto: EthereumCrypto,
6165
) -> None:
62-
print("Checking if service is staked on Everest...")
63-
staking_contract_address = EVEREST_STAKING_CONTRACT_ADDRESS
64-
65-
if service_id not in get_service_ids(ledger_api, staking_contract_address):
66-
print(f"Service {service_id} is not staked on Everest.")
67-
return
66+
print(f"Checking if service is staked on {staking_program}...")
67+
68+
# Check if service is staked
69+
if staking_program.startswith("Everest"):
70+
if service_id not in get_service_ids(ledger_api, staking_contract_address):
71+
print(f"Service {service_id} is not staked on {staking_program}.")
72+
return
73+
elif staking_program.startswith("Alpine"):
74+
if not is_service_staked(
75+
ledger_api, args.service_id, args.staking_contract_address
76+
):
77+
print(f"Service {args.service_id} is not staked on {staking_program}..")
78+
return
6879

6980
print(
70-
f"Service {service_id} is staked on Everest. To continue in a new staking program, first, it must be unstaked from Everest."
81+
f"Service {service_id} is staked on {staking_program}. To continue in a new staking program, first, it must be unstaked from {staking_program}."
7182
)
7283
user_input = input(
73-
"Do you want to continue unstaking from Everest? (yes/no)\n"
84+
"Do you want to continue unstaking from {staking_program}? (yes/no)\n"
7485
).lower()
7586
print()
7687

7788
if user_input not in ["yes", "y"]:
7889
print("Terminating script.")
7990
sys.exit(1)
8091

81-
print(f"Unstaking service {service_id} from Everest...")
92+
print(f"Unstaking service {service_id} from {staking_program}...")
8293
unstake_txs = get_unstake_txs(ledger_api, service_id, staking_contract_address)
8394
for tx in unstake_txs:
8495
send_tx_and_wait_for_receipt(ledger_api, owner_crypto, tx)
85-
print("Successfully unstaked from Everest.")
96+
print(f"Successfully unstaked service {args.service_id} from {staking_program}.")
97+
98+
99+
def _unstake_old_programs(
100+
ledger_api: EthereumApi, service_id: int, owner_crypto: EthereumCrypto
101+
) -> None:
102+
for program, address in OLD_STAKING_PROGRAMS.items():
103+
_unstake(ledger_api, service_id, address, program, owner_crypto)
86104

87105

88106
def _check_unstaking_availability(
@@ -184,7 +202,7 @@ def _try_stake_service(
184202
private_key_path=args.owner_private_key_path, password=args.password
185203
)
186204

187-
_unstake_everest(ledger_api, args.service_id, owner_crypto)
205+
_unstake_old_programs(ledger_api, args.service_id, owner_crypto)
188206

189207
# Collect information
190208
next_ts = get_next_checkpoint_ts(ledger_api, args.staking_contract_address)
@@ -208,7 +226,7 @@ def _try_stake_service(
208226
ledger_api, args.service_id, args.staking_contract_address
209227
):
210228
# the service is not staked, so we don't need to do anything
211-
print(f"Service {args.service_id} is not staked.")
229+
print(f"Service {args.service_id} is not staked on {staking_program}..")
212230
sys.exit(0)
213231

214232
if is_service_evicted(

0 commit comments

Comments
 (0)