diff --git a/.gitignore b/.gitignore index 019e83d..3eb0c67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .trader_runner* trader -*.DS_Store \ No newline at end of file +*.DS_Store +__pycache__ \ No newline at end of file diff --git a/run_service.sh b/run_service.sh index 60848a1..e122602 100755 --- a/run_service.sh +++ b/run_service.sh @@ -347,7 +347,7 @@ prompt_use_staking() { while true; do echo "Use staking?" echo "------------" - read -p "Do you want to use this service in a staking program? (yes/no): " use_staking + read -p "Do you want to stake this service? (yes/no): " use_staking case "$use_staking" in [Yy]|[Yy][Ee][Ss]) @@ -761,23 +761,22 @@ operator_address=$(get_address "../$operator_keys_file") if [ "$local_service_hash" != "$remote_service_hash" ]; then echo "" - echo "WARNING: Your on-chain service is out-of-date" - echo "---------------------------------------------" - echo "Your currently minted on-chain service (id $service_id) mismatches the fetched trader service ($service_version):" + echo "WARNING: Your on-chain service configuration is out-of-date" + echo "-----------------------------------------------------------" + echo "Your currently minted on-chain service (id $service_id) mismatches the local trader service ($service_version):" echo " - Local service hash ($service_version): $local_service_hash" echo " - On-chain service hash (id $service_id): $remote_service_hash" echo "" echo "This is most likely caused due to an update of the trader service code." echo "The script will proceed now to update the on-chain service." - echo "The operator and agent addresses need to have enough funds so that the process is not interrupted." + echo "The operator and agent addresses need to have enough funds to complete the process." echo "" response="y" if [ "${USE_STAKING}" = true ]; then - echo "WARNING: Your on-chain service is staked" - echo "----------------------------------------" - echo "Updating your on-chain service requires that it is unstaked." - echo "Continuing will automatically unstake your service if it is staked, which may affect your staking rewards." + echo "Your service is in a staking program. Updating your on-chain service requires that it is first unstaked." + echo "Unstaking your service will retrieve the accrued staking rewards." + echo "" echo "Do you want to continue updating your service? (yes/no)" read -r response echo "" @@ -904,9 +903,9 @@ if [ "$(get_on_chain_service_state "$service_id")" == "PRE_REGISTRATION" ]; then if [ "${USE_STAKING}" = true ]; then minimum_olas_balance=$($PYTHON_CMD -c "print(int($olas_balance_required_to_bond) + int($olas_balance_required_to_stake))") echo "Your service is using staking. Therefore, you need to provide a total of $(wei_to_dai "$minimum_olas_balance") OLAS to your owner/operator's address:" - echo " $(wei_to_dai "$olas_balance_required_to_bond") OLAS for bonding (service owner)" + echo " $(wei_to_dai "$olas_balance_required_to_bond") OLAS for security deposit (service owner)" echo " +" - echo " $(wei_to_dai "$olas_balance_required_to_stake") OLAS for staking (operator)." + echo " $(wei_to_dai "$olas_balance_required_to_stake") OLAS for slashable bond (operator)." echo "" ensure_erc20_balance "$operator_address" $minimum_olas_balance "owner/operator's address" $CUSTOM_OLAS_ADDRESS "OLAS" cmd+=" --token $CUSTOM_OLAS_ADDRESS" diff --git a/scripts/staking.py b/scripts/staking.py index 0dc50ce..7af5ff3 100644 --- a/scripts/staking.py +++ b/scripts/staking.py @@ -93,14 +93,14 @@ formatted_next_ts = datetime.utcfromtimestamp(next_ts).strftime('%Y-%m-%d %H:%M:%S UTC') print( - "WARNING: The liveness period has not been reached\n" - "-------------------------------------------------\n" + "WARNING: Staking checkpoint call not available yet\n" + "--------------------------------------------------\n" f"The liveness period ({liveness_period/3600} hours) has not passed since the last checkpoint call.\n" f" - {formatted_last_ts} - Last checkpoint call.\n" f" - {formatted_next_ts} - Next checkpoint call availability.\n" "\n" - "If you proceed with unstaking, you will lose any rewards accrued after the last checkpoint call.\n" - "Consider waiting until the liveness period has passed." + "If you proceed with unstaking, your agent's work done between the last checkpoint call until now will not be accounted for rewards.\n" + "(Note: To maximize agent work eligible for rewards, the recommended practice is to unstake shortly after a checkpoint has been called and stake again immediately after.)\n" ) user_input = input("Do you want to continue unstaking? (yes/no)\n").lower() @@ -148,7 +148,7 @@ print("No rewards available. The service cannot be staked.") sys.exit(0) - print(f"Rewards available: {available_rewards}. Staking the service...") + print(f"Rewards available: {available_rewards/10**18:.2f} OLAS. Staking the service...") stake_txs = get_stake_txs( ledger_api, args.service_id, diff --git a/trades.py b/trades.py index 10c67ad..c9a1074 100644 --- a/trades.py +++ b/trades.py @@ -426,9 +426,9 @@ def _is_redeemed(user_json: dict[str, Any], fpmmTrade: dict[str, Any]) -> bool: return False -def _compute_roi(investment: int, net_earnings: int) -> float: - if investment != 0: - roi = net_earnings / investment +def _compute_roi(initial_value: int, final_value: int) -> float: + if initial_value != 0: + roi = (final_value - initial_value) / initial_value else: roi = 0.0 @@ -456,16 +456,21 @@ def _compute_totals( for col in STATS_TABLE_COLS: # Omen deducts the fee from collateral_amount (INVESTMENT) to compute outcomes_tokens_traded (EARNINGS). - # Therefore, we do not need to deduct the fees again here to compute NET_EARNINGS. + table[MarketAttribute.INVESTMENT][col] = ( + table[MarketAttribute.INVESTMENT][col] - table[MarketAttribute.FEES][col] + ) table[MarketAttribute.NET_EARNINGS][col] = ( table[MarketAttribute.EARNINGS][col] - table[MarketAttribute.INVESTMENT][col] + - table[MarketAttribute.FEES][col] - table[MarketAttribute.MECH_FEES][col] ) # ROI is recomputed here for all columns, including TOTAL. table[MarketAttribute.ROI][col] = _compute_roi( - table[MarketAttribute.INVESTMENT][col], - table[MarketAttribute.NET_EARNINGS][col], + table[MarketAttribute.INVESTMENT][col] + + table[MarketAttribute.FEES][col] + + table[MarketAttribute.MECH_FEES][col], + table[MarketAttribute.EARNINGS][col], )