Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 ..
6 changes: 3 additions & 3 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
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()
19 changes: 13 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,28 @@ 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_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_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 token != ZERO_ADDRESS:
agent_bond = contract.functions.getAgentBond(service_id, agent_id).call()
print(agent_bond)
else:
# TODO read from service registry
print(10000000000000000)


if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 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