diff --git a/run_service.sh b/run_service.sh index f636e0d..ad9c1ae 100755 --- a/run_service.sh +++ b/run_service.sh @@ -887,7 +887,7 @@ operator_address=$(get_address "../$operator_keys_file") on_chain_agent_id=$(get_on_chain_agent_ids "$service_id") # On-chain agent bond for the expected agent ID ($AGENT_ID) -on_chain_agent_bond=$(poetry run python "../scripts/get_agent_bond.py" "$CUSTOM_SERVICE_REGISTRY_TOKEN_UTILITY_ADDRESS" "$service_id" "$AGENT_ID" "$rpc") +on_chain_agent_bond=$(poetry run python "../scripts/get_agent_bond.py" "$CUSTOM_SERVICE_REGISTRY_ADDRESS" "$CUSTOM_SERVICE_REGISTRY_TOKEN_UTILITY_ADDRESS" "$service_id" "$AGENT_ID" "$rpc") if [ "${USE_STAKING}" = true ]; then cost_of_bonding=$MIN_STAKING_BOND_OLAS @@ -895,6 +895,9 @@ else cost_of_bonding=$MIN_STAKING_BOND_XDAI fi +# TODO Also compare if service-secured token matches. Currently this check is implicit due to the +# difference between bonds forn on-staking services (0.01 XDAI) and staking services (> 10 XDAI). + if [ "$local_service_hash" != "$remote_service_hash" ] || [ "$on_chain_agent_id" != "$AGENT_ID" ] || [ "$on_chain_agent_bond" != "$cost_of_bonding" ]; then echo "" echo "WARNING: Your on-chain service configuration is out-of-date" diff --git a/scripts/get_agent_bond.py b/scripts/get_agent_bond.py index 5982ab3..21f9b6c 100644 --- a/scripts/get_agent_bond.py +++ b/scripts/get_agent_bond.py @@ -47,12 +47,14 @@ def _get_abi(contract_address: str) -> List: def main() -> None: parser = argparse.ArgumentParser(description="Get agent bond from service registry token utility contract.") + parser.add_argument('service_registry', type=str, help='Service registry contract address') parser.add_argument('service_registry_token_utility', type=str, help='Service registry token utility contract address') parser.add_argument('service_id', type=int, help='Service ID') parser.add_argument('agent_id', type=int, help='Agent ID') parser.add_argument('rpc', type=str, help='RPC') args = parser.parse_args() + service_registry = args.service_registry service_registry_token_utility = args.service_registry_token_utility service_id = args.service_id agent_id = args.agent_id @@ -63,12 +65,16 @@ def main() -> None: contract = w3.eth.contract(address=service_registry_token_utility, abi=abi) token = contract.functions.mapServiceIdTokenDeposit(service_id).call()[0] + # If service is token-secured, retrieve bond from Service Registry Token Utility if token != ZERO_ADDRESS: agent_bond = contract.functions.getAgentBond(service_id, agent_id).call() print(agent_bond) + # Otherwise, retrieve bond from Service Registry else: - # TODO read from service registry - print(10000000000000000) + abi = _get_abi(service_registry) + contract = w3.eth.contract(address=service_registry, abi=abi) + agent_bond = contract.functions.getService(service_id).call()[0] + print(agent_bond) if __name__ == "__main__": diff --git a/scripts/staking.py b/scripts/staking.py index 77afbfb..b2a739e 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -194,7 +194,6 @@ def _try_unstake_service( print( f"Successfully unstaked service {service_id} from {staking_program}." ) - sys.exit(0) def _try_stake_service( @@ -236,7 +235,6 @@ def _try_stake_service( send_tx_and_wait_for_receipt(ledger_api, owner_crypto, tx) print(f"Service {service_id} staked successfully on {staking_program}.") - sys.exit(0) else: print( f"All staking slots for contract {staking_contract_address} are taken. Service {service_id} cannot be staked."