Skip to content

Commit

Permalink
Merge pull request #262 from valory-xyz/develop
Browse files Browse the repository at this point in the history
Release v0.14.0
  • Loading branch information
dagacha authored Apr 15, 2024
2 parents 316d823 + 9f13206 commit 986ebc2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 21 deletions.
33 changes: 30 additions & 3 deletions report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}.')}",
Expand Down
10 changes: 7 additions & 3 deletions run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.14.0"

# Define constants for on-chain interaction
gnosis_chain_id=100
Expand All @@ -602,16 +602,20 @@ 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

# check if USE_NEVERMINED is set to true
if [ "$USE_NEVERMINED" == "true" ];
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
Expand Down
48 changes: 33 additions & 15 deletions scripts/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)


EVEREST_STAKING_CONTRACT_ADDRESS = "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"
OLD_STAKING_PROGRAMS = {"Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"}


def _format_duration(duration_seconds: int) -> str:
Expand All @@ -56,33 +56,51 @@ 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.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.startswith("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()

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

print(f"Unstaking service {service_id} from Everest...")
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(
Expand Down Expand Up @@ -184,7 +202,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)
Expand All @@ -208,7 +226,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(
Expand Down

0 comments on commit 986ebc2

Please sign in to comment.