Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read agent bond from registry when the service is not token secured #348

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,17 @@ 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
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"
Expand Down
10 changes: 8 additions & 2 deletions scripts/get_agent_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__":
Expand Down