Skip to content

Commit

Permalink
Merge pull request #271 from valory-xyz/develop
Browse files Browse the repository at this point in the history
Release v0.14.2
  • Loading branch information
DavidMinarsch authored Apr 23, 2024
2 parents 6e940a5 + 7a58bba commit 1af3242
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 40 deletions.
2 changes: 1 addition & 1 deletion report.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
OPERATOR_KEYS_JSON_PATH = Path(STORE_PATH, "operator_keys.json")
SAFE_ADDRESS_PATH = Path(STORE_PATH, "service_safe_address.txt")
SERVICE_ID_PATH = Path(STORE_PATH, "service_id.txt")
SERVICE_STAKING_CONTRACT_ADDRESS = "0x2Ef503950Be67a98746F484DA0bBAdA339DF3326"
SERVICE_STAKING_CONTRACT_ADDRESS = "0x43fB32f25dce34EB76c78C7A42C8F40F84BCD237"
SERVICE_STAKING_TOKEN_JSON_PATH = Path(
SCRIPT_PATH,
"trader",
Expand Down
4 changes: 2 additions & 2 deletions run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ export RPC_RETRIES=40
export RPC_TIMEOUT_SECONDS=120
export CUSTOM_SERVICE_MANAGER_ADDRESS="0x04b0007b2aFb398015B76e5f22993a1fddF83644"
export CUSTOM_SERVICE_REGISTRY_ADDRESS="0x9338b5153AE39BB89f50468E608eD9d764B755fD"
export CUSTOM_STAKING_ADDRESS="0x2Ef503950Be67a98746F484DA0bBAdA339DF3326"
export CUSTOM_STAKING_ADDRESS="0x43fB32f25dce34EB76c78C7A42C8F40F84BCD237"
export CUSTOM_OLAS_ADDRESS="0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f"
export CUSTOM_SERVICE_REGISTRY_TOKEN_UTILITY_ADDRESS="0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8"
export CUSTOM_GNOSIS_SAFE_PROXY_FACTORY_ADDRESS="0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE"
Expand Down Expand Up @@ -1064,7 +1064,7 @@ export OMEN_CREATORS='["0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"]'
export BET_THRESHOLD=100000000000000000
export TRADING_STRATEGY=kelly_criterion
export PROMPT_TEMPLATE="Please take over the role of a Data Scientist to evaluate the given question. With the given question \"@{question}\" and the \`yes\` option represented by \`@{yes}\` and the \`no\` option represented by \`@{no}\`, what are the respective probabilities of \`p_yes\` and \`p_no\` occurring?"
export IRRELEVANT_TOOLS='["prediction-offline-sme", "openai-gpt-3.5-turbo-instruct", "prediction-online-summarized-info", "prediction-online-sum-url-content", "prediction-online", "openai-text-davinci-002", "openai-text-davinci-003", "openai-gpt-3.5-turbo", "openai-gpt-4", "stabilityai-stable-diffusion-v1-5", "stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1", "stabilityai-stable-diffusion-768-v2-1", "deepmind-optimization-strong", "deepmind-optimization", "claude-prediction-offline"]'
export IRRELEVANT_TOOLS='["claude-prediction-online","prediction-request-reasoning","prediction-online","prediction-offline","prediction-offline-sme","deepmind-optimization", "deepmind-optimization-strong", "openai-gpt-3.5-turbo", "openai-gpt-3.5-turbo-instruct", "openai-gpt-4", "openai-text-davinci-002", "openai-text-davinci-003", "prediction-online-sum-url-content", "prediction-online-summarized-info", "stabilityai-stable-diffusion-512-v2-1", "stabilityai-stable-diffusion-768-v2-1", "stabilityai-stable-diffusion-v1-5", "stabilityai-stable-diffusion-xl-beta-v2-2-2"]'

service_dir="trader_service"
build_dir="abci_build"
Expand Down
108 changes: 72 additions & 36 deletions scripts/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
)


OLD_STAKING_PROGRAMS = {"Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"}
OLD_STAKING_PROGRAMS = {
"Everest": "0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C",
"Alpine": "0x2Ef503950Be67a98746F484DA0bBAdA339DF3326"
}


def _format_duration(duration_seconds: int) -> str:
Expand All @@ -56,7 +59,7 @@ def _format_duration(duration_seconds: int) -> str:
return formatted_duration


def _unstake(
def _unstake_old_program(
ledger_api: EthereumApi,
service_id: int,
staking_contract_address: str,
Expand All @@ -72,16 +75,34 @@ def _unstake(
return
elif staking_program.startswith("Alpine"):
if not is_service_staked(
ledger_api, args.service_id, args.staking_contract_address
ledger_api, service_id, staking_contract_address
):
print(f"Service {args.service_id} is not staked on {staking_program}..")
print(f"Service {service_id} is not staked on {staking_program}..")
return

can_unstake = _check_unstaking_availability(
ledger_api,
service_id,
staking_contract_address,
staking_program,
)
if not can_unstake:
print(
"\n"
"WARNING: Service cannot be unstaked yet\n"
"---------------------------------------\n"
f"Service {service_id} cannot be unstaked from {staking_program} at this time.\n"
f"You can still run your service, but it will stay staked in {staking_program}.\n"
"Please, try re-running this script again at a later time to try stake on a new program.\n"
)
input("Press Enter to continue...")
sys.exit(0)

print(
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 {staking_program}? (yes/no)\n"
f"Do you want to continue unstaking service {service_id} from {staking_program}? (yes/no)\n"
).lower()
print()

Expand All @@ -93,32 +114,42 @@ def _unstake(
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(f"Successfully unstaked service {args.service_id} from {staking_program}.")
print(f"Successfully unstaked service {service_id} from {staking_program}.")


def _unstake_old_programs(
def _unstake_all_old_programs(
ledger_api: EthereumApi, service_id: int, owner_crypto: EthereumCrypto
) -> None:
print("Unstaking from old programs...")
for program, address in OLD_STAKING_PROGRAMS.items():
_unstake(ledger_api, service_id, address, program, owner_crypto)
_unstake_old_program(ledger_api, service_id, address, program, owner_crypto)


def _check_unstaking_availability(
now: float,
ts_start: float,
minimum_staking_duration: int,
available_rewards: float,
ledger_api: EthereumApi,
service_id: int,
staking_contract_address: str,
staking_program: str,
) -> None:
) -> bool:

now = time.time()
ts_start = get_service_info(
ledger_api, service_id, staking_contract_address
)[3]
minimum_staking_duration = get_min_staking_duration(
ledger_api, staking_contract_address
)
available_rewards = get_available_rewards(ledger_api, staking_contract_address)
if (now - ts_start) < minimum_staking_duration and available_rewards > 0:
print(
f"WARNING: Your service has been staked on {staking_program} for {_format_duration(int(now - ts_start))}."
)
print(
f"You cannot unstake your service from {staking_program} until it has been staked for at least {_format_duration(minimum_staking_duration)}."
)
print("Terminating script.")
sys.exit(1)
return False

return True


def _try_stake_service(
Expand All @@ -127,6 +158,7 @@ def _try_stake_service(
owner_crypto: EthereumCrypto,
service_registry_address: str,
staking_contract_address: str,
staking_program: str,
) -> None:
if get_available_staking_slots(ledger_api, staking_contract_address) > 0:
print(
Expand Down Expand Up @@ -160,9 +192,9 @@ def _try_stake_service(
sys.exit(1)


if __name__ == "__main__":
def main() -> None:
try:
staking_program = "Alpine"
staking_program = "Coastal"
print(f"Starting {Path(__file__).name} script ({staking_program})...\n")

parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -202,21 +234,13 @@ def _try_stake_service(
private_key_path=args.owner_private_key_path, password=args.password
)

_unstake_old_programs(ledger_api, args.service_id, owner_crypto)
_unstake_all_old_programs(ledger_api, args.service_id, owner_crypto)

# Collect information
next_ts = get_next_checkpoint_ts(ledger_api, args.staking_contract_address)
ts_start = get_service_info(
ledger_api, args.service_id, args.staking_contract_address
)[3]

liveness_period = get_liveness_period(ledger_api, args.staking_contract_address)
last_ts = next_ts - liveness_period
now = time.time()

minimum_staking_duration = get_min_staking_duration(
ledger_api, args.staking_contract_address
)
available_rewards = get_available_rewards(
ledger_api, args.staking_contract_address
)
Expand All @@ -237,14 +261,17 @@ def _try_stake_service(
)
input("Press Enter to continue...")

_check_unstaking_availability(
now,
ts_start,
minimum_staking_duration,
available_rewards,
can_unstake = _check_unstaking_availability(
ledger_api,
args.service_id,
args.staking_contract_address,
staking_program,
)

if not can_unstake:
print("Terminating script.")
sys.exit(1)

if now < next_ts:
formatted_last_ts = datetime.utcfromtimestamp(last_ts).strftime(
"%Y-%m-%d %H:%M:%S UTC"
Expand Down Expand Up @@ -294,14 +321,17 @@ def _try_stake_service(
f"Service {args.service_id} has been evicted from the {staking_program} staking program due to inactivity. Unstaking..."
)

_check_unstaking_availability(
now,
ts_start,
minimum_staking_duration,
available_rewards,
can_unstake = _check_unstaking_availability(
ledger_api,
args.service_id,
args.staking_contract_address,
staking_program,
)

if not can_unstake:
print("Terminating script.")
sys.exit(1)

unstake_txs = get_unstake_txs(
ledger_api, args.service_id, args.staking_contract_address
)
Expand All @@ -318,6 +348,7 @@ def _try_stake_service(
owner_crypto=owner_crypto,
service_registry_address=args.service_registry_address,
staking_contract_address=args.staking_contract_address,
staking_program=staking_program,
)
sys.exit(0)

Expand Down Expand Up @@ -354,6 +385,7 @@ def _try_stake_service(
owner_crypto=owner_crypto,
service_registry_address=args.service_registry_address,
staking_contract_address=args.staking_contract_address,
staking_program=staking_program,
)

except Exception as e: # pylint: disable=broad-except
Expand All @@ -364,3 +396,7 @@ def _try_stake_service(
"\nPlease confirm whether your service is participating in a staking program, and then retry running the script."
)
sys.exit(1)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion terminate_on_chain_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export CUSTOM_CHAIN_RPC=$rpc
export CUSTOM_CHAIN_ID=$gnosis_chain_id
export CUSTOM_SERVICE_MANAGER_ADDRESS="0x04b0007b2aFb398015B76e5f22993a1fddF83644"
export CUSTOM_SERVICE_REGISTRY_ADDRESS="0x9338b5153AE39BB89f50468E608eD9d764B755fD"
export CUSTOM_STAKING_ADDRESS="0x2Ef503950Be67a98746F484DA0bBAdA339DF3326"
export CUSTOM_STAKING_ADDRESS="0x43fB32f25dce34EB76c78C7A42C8F40F84BCD237"
export CUSTOM_OLAS_ADDRESS="0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f"
export CUSTOM_SERVICE_REGISTRY_TOKEN_UTILITY_ADDRESS="0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8"
export CUSTOM_GNOSIS_SAFE_PROXY_FACTORY_ADDRESS="0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE"
Expand Down

0 comments on commit 1af3242

Please sign in to comment.