Skip to content

Commit

Permalink
Merge pull request #130 from valory-xyz/develop
Browse files Browse the repository at this point in the history
Release v0.9.9.post1
  • Loading branch information
jmoreira-valory authored Nov 23, 2023
2 parents 63b7e0b + 3a926c3 commit a999086
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.trader_runner*
trader
*.DS_Store
*.DS_Store
__pycache__
21 changes: 10 additions & 11 deletions run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions scripts/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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],
)


Expand Down

0 comments on commit a999086

Please sign in to comment.