Skip to content

Commit

Permalink
Merge pull request #347 from valory-xyz/develop
Browse files Browse the repository at this point in the history
Release 0.19.4
  • Loading branch information
jmoreira-valory authored Sep 4, 2024
2 parents 257d706 + 0df4627 commit 9ecc1a8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Services can become staked by invoking the `stake()` contract method, where serv
- Once a staking program is selected, you can reset your preference by stopping your agent by running ./stop_service.sh and then running the command

``` bash
cd trader; poetry run python ../scripts/choose_staking.py --reset; cd ..
./reset_staking.sh
```

Keep in mind that your service must stay for `minStakingDuration` in a staking program (typically 3 days) before you can change to a new program.
Expand Down
3 changes: 3 additions & 0 deletions reset_staking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cd trader; poetry run python ../scripts/choose_staking.py --reset; cd ..
11 changes: 7 additions & 4 deletions run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ensure_minimum_balance() {

if [ "$($PYTHON_CMD -c "print($balance < $minimum_balance)")" == "True" ]; then
echo ""
echo " Please, fund address $address with at least $(wei_to_dai "$minimum_balance") DAI."
echo " Please, ensure address $address has at least $(wei_to_dai "$minimum_balance") DAI."

local spin='-\|/'
local i=0
Expand Down Expand Up @@ -112,7 +112,7 @@ ensure_erc20_balance() {

if [ "$($PYTHON_CMD -c "print($balance < $minimum_balance)")" == "True" ]; then
echo ""
echo " Please, fund address $address with at least $(wei_to_dai "$minimum_balance") $token_name."
echo " Please, ensure address $address has at least $(wei_to_dai "$minimum_balance") $token_name."

local spin='-\|/'
local i=0
Expand Down Expand Up @@ -644,7 +644,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.18.0"
service_version="v0.18.2"

# Define constants for on-chain interaction
gnosis_chain_id=100
Expand Down 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: 6 additions & 4 deletions scripts/choose_staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@
"MIN_STAKING_DEPOSIT_OLAS": "0",
}

# Information stored in the "deployment" key is used only to retrieve "stakingTokenInstanceAddress" (proxy)
# and "stakingTokenAddress" (implementation). The rest of the parameters are read on-chain.
STAKING_PROGRAMS = {
NO_STAKING_PROGRAM_ID: ZERO_ADDRESS,
"quickstart_beta_hobbyist": "0x389B46c259631Acd6a69Bde8B6cEe218230bAE8C",
"quickstart_beta_hobbyist_2": "0x238EB6993b90a978ec6AAD7530d6429c949C08DA",
"quickstart_beta_expert": "0x5344B7DD311e5d3DdDd46A4f71481bD7b05AAA3e",
"quickstart_beta_expert_2": "0xb964e44c126410df341ae04B13aB10A985fE3513",
"quickstart_beta_expert_3": "0x80faD33Cadb5F53f9D29F02Db97D682E8b101618",
}

DEPRECATED_STAKING_PROGRAMS = {
Expand Down Expand Up @@ -264,7 +265,9 @@ def main() -> None:
print("Reset your staking program preference")
print("=====================================")
print("")
print(f"Your current staking program is set to '{staking_program}'")
print(f"Your current staking program preference is set to '{staking_program}'.")
print("You can reset your preference. However, your trader might not be able to switch between staking contracts until it has been staked for a minimum staking period in the current program.")
print("")
response = input("Do you want to reset your staking program preference? (yes/no): ").strip().lower()
if response not in ['yes', 'y']:
return
Expand All @@ -288,6 +291,5 @@ def main() -> None:
print("")
print("Finished populating the .env file.")


if __name__ == "__main__":
main()
25 changes: 19 additions & 6 deletions scripts/get_agent_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from typing import List
from web3 import Web3

ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"


def _get_abi(contract_address: str) -> List:
contract_abi_url = "https://gnosis.blockscout.com/api/v2/smart-contracts/{contract_address}"
Expand All @@ -45,23 +47,34 @@ 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('contract_address', type=str, help='Service registry token utility contract address')
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()

contract_address = args.contract_address
service_registry = args.service_registry
service_registry_token_utility = args.service_registry_token_utility
service_id = args.service_id
agent_id = args.agent_id
rpc = args.rpc

w3 = Web3(Web3.HTTPProvider(rpc))
abi = _get_abi(contract_address)
contract = w3.eth.contract(address=contract_address, abi=abi)
agent_bond = contract.functions.getAgentBond(service_id, agent_id).call()
abi = _get_abi(service_registry_token_utility)
contract = w3.eth.contract(address=service_registry_token_utility, abi=abi)
token = contract.functions.mapServiceIdTokenDeposit(service_id).call()[0]

print(agent_bond)
# 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:
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
10 changes: 8 additions & 2 deletions scripts/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ def _try_unstake_service(
) -> None:

staking_contract_address, staking_program = _get_current_staking_program(ledger_api, service_id)
print("")

# Exit if not staked
if staking_contract_address is None:
print(f"Service {service_id} is not staked in any active program.")
return
else:
print(f"Service {service_id} is staked on {staking_program}.")

env_file_vars = dotenv_values(DOTENV_PATH)
target_program = env_file_vars.get("STAKING_PROGRAM")
print(f"Target program is set to {target_program}.")
print("")

# Collect information
next_ts = get_next_checkpoint_ts(ledger_api, staking_contract_address)
Expand Down Expand Up @@ -186,7 +194,6 @@ def _try_unstake_service(
print(
f"Successfully unstaked service {service_id} from {staking_program}."
)
sys.exit(0)


def _try_stake_service(
Expand Down Expand Up @@ -228,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."
Expand Down

0 comments on commit 9ecc1a8

Please sign in to comment.