File tree Expand file tree Collapse file tree 11 files changed +81
-8
lines changed
Expand file tree Collapse file tree 11 files changed +81
-8
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,9 @@ EXPRESSION=<GREP_EXPRESSION>
1919RPC_URL = <YOUR_RPC_URL>
2020PAYMENT_CONTRACT_ADDRESS = <YOUR_PAYMENT_CONTRACT_ADDRESS>
2121BALANCE_THRESHOLD = <YOUR_BALANCE_THRESHOLD_IN_ETH>
22+ WALLET_NAME = <YOUR_WALLET_NAME> # Example: "Task sender"
2223WALLET_ADDRESS = <YOUR_WALLET_ADDRESS>
24+ NETWORK = <MAINNET|HOLESKY|STAGE>
2325
2426# Variables for sender_with_alert.sh
2527REPETITIONS = <REPETITIONS>
Original file line number Diff line number Diff line change @@ -25,12 +25,12 @@ balance_alert=false
2525
2626while :
2727do
28- balance_wei=$( cast call --rpc-url $RPC_URL $PAYMENT_CONTRACT_ADDRESS " UserBalances (address)(uint256)" $WALLET_ADDRESS | cut -d' ' -f1)
28+ balance_wei=$( cast call --rpc-url $RPC_URL $PAYMENT_CONTRACT_ADDRESS " user_balances (address)(uint256)" $WALLET_ADDRESS | cut -d' ' -f1)
2929
3030 balance_eth=$( cast from-wei $balance_wei )
3131
3232 if [ 1 -eq " $( echo " $balance_eth < $BALANCE_THRESHOLD " | bc) " ]; then
33- message=" ⚠️ WARNING: Wallet $WALLET_ADDRESS balance ($balance_eth ETH) is below $BALANCE_THRESHOLD ETH"
33+ message=" ⚠️ WARNING: $WALLET_NAME ( $NETWORK ) Wallet ( $WALLET_ADDRESS ) balance ($balance_eth ETH) is below $BALANCE_THRESHOLD ETH"
3434 printf " $message \n"
3535 if [ " $balance_alert " = false ]; then
3636 send_slack_message " $message "
Original file line number Diff line number Diff line change @@ -164,6 +164,25 @@ defmodule Batches do
164164 end
165165 end
166166
167+ def get_last_24h_verified_proof_stats ( ) do
168+ minutes_in_a_day = 1440
169+ threshold_datetime = DateTime . utc_now ( ) |> DateTime . add ( - 1 * minutes_in_a_day , :minute ) # Last 24 hours
170+
171+ query = from ( b in Batches ,
172+ where: b . is_verified == true and b . submission_timestamp > ^ threshold_datetime ,
173+ select: { sum ( b . amount_of_proofs ) , avg ( b . fee_per_proof ) } )
174+
175+ { amount_of_proofs , avg_fee_per_proof } = case Explorer.Repo . one ( query ) do
176+ nil -> { 0 , 0.0 }
177+ result -> result
178+ end
179+
180+ % {
181+ amount_of_proofs: amount_of_proofs ,
182+ avg_fee_per_proof: avg_fee_per_proof
183+ }
184+ end
185+
167186 def insert_or_update ( batch_changeset , proofs ) do
168187 merkle_root = batch_changeset . changes . merkle_root
169188 stored_proofs = Proofs . get_proofs_from_batch ( % { merkle_root: merkle_root } )
Original file line number Diff line number Diff line change 1+ defmodule ExplorerWeb.DataController do
2+ use ExplorerWeb , :controller
3+
4+ def verified_proofs_in_last_24_hours ( conn , _params ) do
5+ % {
6+ amount_of_proofs: amount_of_proofs ,
7+ avg_fee_per_proof: avg_fee_per_proof
8+ } = Batches . get_last_24h_verified_proof_stats ( )
9+
10+ avg_fee_per_proof_usd =
11+ case EthConverter . wei_to_usd_sf ( avg_fee_per_proof , 2 ) do
12+ { :ok , value } -> value
13+ _ -> 0
14+ end
15+
16+ render ( conn , :show , % {
17+ amount_of_proofs: amount_of_proofs ,
18+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
19+ } )
20+ end
21+ end
Original file line number Diff line number Diff line change 1+ defmodule ExplorerWeb.DataJSON do
2+ def show ( % {
3+ amount_of_proofs: amount_of_proofs ,
4+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
5+ } ) do
6+ % {
7+ amount_of_proofs: amount_of_proofs ,
8+ avg_fee_per_proof_usd: avg_fee_per_proof_usd
9+ }
10+ end
11+ end
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ defmodule EthConverter do
5858 end
5959 end
6060
61+ defp round_to_sf ( % Decimal { coef: 0 } = _value , _sf ) , do: Decimal . new ( "0" )
62+
6163 defp round_to_sf ( value , significant_figures ) do
6264 # Convert the value to a float and calculate the magnitude
6365 value_float = Decimal . to_float ( value )
Original file line number Diff line number Diff line change 3434 type = "number "
3535 class = {
3636 classes ( [
37- "border border-foreground/20 text-muted-foreground w-20 focus:ring-primary" ,
37+ "text-center border border-foreground/20 text-muted-foreground w-20 focus:ring-primary" ,
3838 "phx-submit-loading:opacity-75 rounded-lg bg-card hover:bg-muted py-2 px-3" ,
3939 "text-sm font-semibold leading-6 text-foregound active:text-foregound/80" ,
4040 "[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
Original file line number Diff line number Diff line change @@ -42,13 +42,21 @@ defmodule ExplorerWeb.Home.Index do
4242 % {
4343 title: "Proofs verified" ,
4444 value: Helpers . convert_number_to_shorthand ( verified_proofs ) ,
45- tooltip_text: "= #{ Helpers . format_number ( verified_proofs ) } proofs" ,
45+ tooltip_text:
46+ case verified_proofs >= 1000 do
47+ true -> "= #{ Helpers . format_number ( verified_proofs ) } proofs"
48+ _ -> nil
49+ end ,
4650 link: nil
4751 } ,
4852 % {
4953 title: "Total batches" ,
5054 value: Helpers . convert_number_to_shorthand ( verified_batches ) ,
51- tooltip_text: "= #{ Helpers . format_number ( verified_batches ) } batches" ,
55+ tooltip_text:
56+ case verified_batches >= 1000 do
57+ true -> "= #{ Helpers . format_number ( verified_batches ) } batches"
58+ _ -> nil
59+ end ,
5260 link: nil
5361 } ,
5462 % {
@@ -146,7 +154,7 @@ defmodule ExplorerWeb.Home.Index do
146154 |> assign (
147155 stats: [ ] ,
148156 latest_batches: [ ] ,
149- cost_per_proof_data : % { points: [ ] , extra_data: % { } } ,
157+ cost_per_proof_chart : % { points: [ ] , extra_data: % { } } ,
150158 batch_size_chart_data: % { points: [ ] , extra_data: % { } }
151159 )
152160 end
Original file line number Diff line number Diff line change 3434 < div class = "flex flex-wrap md:flex-row flex-col gap-5 " >
3535 < . card
3636 title = "Cost per proof "
37- subtitle = "Cost of proving over time "
37+ subtitle = "Verification cost over time "
3838 class = "p-0 flex-1 "
3939 header_container_class = "px-10 pt-8 "
4040 >
Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ defmodule ExplorerWeb.Helpers do
77 end
88 end
99
10+ def convert_number_to_shorthand ( number ) when number >= 1_000_000_000 do
11+ formatted_number = Float . round ( number / 1_000_000_000 , 2 )
12+ "#{ remove_trailing_zeros ( formatted_number ) } B"
13+ end
14+
1015 def convert_number_to_shorthand ( number ) when number >= 1_000_000 do
1116 formatted_number = Float . round ( number / 1_000_000 , 2 )
1217 "#{ remove_trailing_zeros ( formatted_number ) } M"
You can’t perform that action at this time.
0 commit comments