Skip to content

Commit a810589

Browse files
authored
Pull fixes from testnet (#1718)
2 parents e7adde6 + a25f012 commit a810589

File tree

11 files changed

+81
-8
lines changed

11 files changed

+81
-8
lines changed

alerts/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ EXPRESSION=<GREP_EXPRESSION>
1919
RPC_URL=<YOUR_RPC_URL>
2020
PAYMENT_CONTRACT_ADDRESS=<YOUR_PAYMENT_CONTRACT_ADDRESS>
2121
BALANCE_THRESHOLD=<YOUR_BALANCE_THRESHOLD_IN_ETH>
22+
WALLET_NAME=<YOUR_WALLET_NAME> # Example: "Task sender"
2223
WALLET_ADDRESS=<YOUR_WALLET_ADDRESS>
24+
NETWORK=<MAINNET|HOLESKY|STAGE>
2325

2426
# Variables for sender_with_alert.sh
2527
REPETITIONS=<REPETITIONS>

alerts/balance_alerts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ balance_alert=false
2525

2626
while :
2727
do
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"

explorer/lib/explorer/models/batches.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

explorer/lib/explorer_web/live/eth_converter.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

explorer/lib/explorer_web/live/pages/batches/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
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"

explorer/lib/explorer_web/live/pages/home/index.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff 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

explorer/lib/explorer_web/live/pages/home/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
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
>

explorer/lib/explorer_web/live/utils.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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"

0 commit comments

Comments
 (0)