diff --git a/alerts/sender_with_alert.sh b/alerts/sender_with_alert.sh index 3b70d57d7..64d372627 100755 --- a/alerts/sender_with_alert.sh +++ b/alerts/sender_with_alert.sh @@ -53,6 +53,22 @@ function fetch_tx_cost() { fi } +# Function to get the tx cost from the tx hash +# @param tx_hash +function get_number_proofs_in_batch_from_create_task_tx() { + if [[ -z "$1" ]]; then + echo 0 + else + # Get the tx receipt from the blockchain + calldata=$(cast tx $1 --rpc-url $RPC_URL input) + decoded_calldata=$(cast --calldata-decode --json "createNewTask(bytes32 batchMerkleRoot, string batchDataPointer, address[] proofSubmitters, uint256 feeForAggregator, uint256 feePerProof, uint256 respondToTaskFeeLimit)" $calldata) + # We count the number of proofSubmitters within the tx which corresponds to the number of proofs sent in the last batch + number_proofs_in_batch=$(echo $decoded_calldata | jq '.[2] | [ match(","; "g")] | length + 1') + + echo $number_proofs_in_batch + fi +} + # Function to send PagerDuty alert # @param message function send_pagerduty_alert() { @@ -94,7 +110,7 @@ do --rpc_url $RPC_URL \ --batcher_url $BATCHER_URL \ --network $NETWORK \ - --max_fee 4000000000000000 \ + --max_fee 0.004ether \ 2>&1) echo "$submit" @@ -113,6 +129,7 @@ do fi total_fee_in_wei=0 + total_number_proofs=0 batch_explorer_urls=() for batch_merkle_root in $batch_merkle_roots do @@ -127,12 +144,16 @@ do response_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }') # Calculate fees for transactions + number_proofs_in_batch=$(get_number_proofs_in_batch_from_create_task_tx $submission_tx_hash) submission_fee_in_wei=$(fetch_tx_cost $submission_tx_hash) response_fee_in_wei=$(fetch_tx_cost $response_tx_hash) batch_fee_in_wei=$((submission_fee_in_wei + response_fee_in_wei)) # Accumulate the fee total_fee_in_wei=$(($total_fee_in_wei + $batch_fee_in_wei)) + + # Accumulate proofs in batch + total_number_proofs=$(($total_number_proofs + $number_proofs_in_batch)) done # Calculate the spent amount by converting the fee to ETH @@ -168,9 +189,9 @@ do done if [ $verified -eq 1 ]; then - slack_message="$REPETITIONS Proofs submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" + slack_message="$total_number_proofs proofs submitted and verified. We sent $REPETITIONS proofs. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" else - slack_message="$REPETITIONS Proofs submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" + slack_message="$total_number_proofs proofs submitted but not verified. We sent $REPETITIONS proofs. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" fi ## Send Update to Slack