From fcd614048e5ab77ed2b8fe91e3614c6ec2d92d6f Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:30:35 -0300 Subject: [PATCH 1/2] feat(wip): get batcher_payments lastest movements --- .../batcher_payment_service_manager.ex | 30 +++++++++++++++++++ .../lib/explorer_web/live/pages/home/index.ex | 2 ++ 2 files changed, 32 insertions(+) diff --git a/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex b/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex index 1926310fa..5ddd39ed2 100644 --- a/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex +++ b/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex @@ -68,4 +68,34 @@ defmodule BatcherPaymentServiceManager do raise("Unexpected response on fee per proof events.") end end + + def get_latest_activity() do + # event PaymentReceived(address indexed sender, uint256 amount); + # event FundsWithdrawn(address indexed recipient, uint256 amount); + # event BalanceLocked(address indexed user); + # event BalanceUnlocked(address indexed user, uint256 unlockBlockTime); + BatcherPaymentServiceManager.EventFilters.payment_received(nil) + |> Ethers.get_logs(fromBlock: @first_block) + |> case do + {:ok, []} -> + Logger.warning("No latest activity found.") + [] + + {:ok, events} -> dbg events + # events + # |> Enum.map(fn event -> + # merkle_root = event.topics[1] + # fee_per_proof = event.data |> hd() + # {merkle_root, fee_per_proof} + # end) + + {:error, reason} -> + Logger.error("Error getting latest activity: #{inspect(reason)}.") + raise("Error getting latest activity events.") + + other -> + Logger.error("Unexpected response on latest activity events: #{inspect(other)}") + raise("Unexpected response on latest activity events.") + end + end end diff --git a/explorer/lib/explorer_web/live/pages/home/index.ex b/explorer/lib/explorer_web/live/pages/home/index.ex index a28f1c937..916ffb4c5 100644 --- a/explorer/lib/explorer_web/live/pages/home/index.ex +++ b/explorer/lib/explorer_web/live/pages/home/index.ex @@ -46,6 +46,8 @@ defmodule ExplorerWeb.Home.Index do restaked_amount_eth = Restakings.get_restaked_amount_eth() restaked_amount_usd = Restakings.get_restaked_amount_usd() + latest_batcher_payment_movements = BatcherPaymentServiceManager.get_latest_activity() + if connected?(socket), do: Phoenix.PubSub.subscribe(Explorer.PubSub, "update_views") {:ok, From b0a572ccc24386fe57f8d2bd910b6e56417997a5 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:00:00 -0300 Subject: [PATCH 2/2] feat: get all relevant events from BatcherPayments --- .../batcher_payment_service_manager.ex | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex b/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex index 5ddd39ed2..8adf887f3 100644 --- a/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex +++ b/explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex @@ -70,32 +70,26 @@ defmodule BatcherPaymentServiceManager do end def get_latest_activity() do - # event PaymentReceived(address indexed sender, uint256 amount); - # event FundsWithdrawn(address indexed recipient, uint256 amount); - # event BalanceLocked(address indexed user); - # event BalanceUnlocked(address indexed user, uint256 unlockBlockTime); - BatcherPaymentServiceManager.EventFilters.payment_received(nil) - |> Ethers.get_logs(fromBlock: @first_block) - |> case do - {:ok, []} -> - Logger.warning("No latest activity found.") - [] - - {:ok, events} -> dbg events - # events - # |> Enum.map(fn event -> - # merkle_root = event.topics[1] - # fee_per_proof = event.data |> hd() - # {merkle_root, fee_per_proof} - # end) - - {:error, reason} -> - Logger.error("Error getting latest activity: #{inspect(reason)}.") - raise("Error getting latest activity events.") - - other -> - Logger.error("Unexpected response on latest activity events: #{inspect(other)}") - raise("Unexpected response on latest activity events.") - end + # event TaskCreated(bytes32 indexed batchMerkleRoot, uint256 feePerProof); + + event_filters = [ + BatcherPaymentServiceManager.EventFilters.payment_received(nil), + BatcherPaymentServiceManager.EventFilters.funds_withdrawn(nil), + BatcherPaymentServiceManager.EventFilters.balance_locked(nil), + BatcherPaymentServiceManager.EventFilters.balance_unlocked(nil) + # BatcherPaymentServiceManager.EventFilters.task_created(nil) // We don't need this event for this feature + ] + + events = + event_filters + |> Enum.map(fn filter -> + filter |> Ethers.get_logs(fromBlock: @first_block) + end) + |> Enum.flat_map(fn + {:ok, logs} -> logs + {:error, _} -> [] # Handle errors by skipping them + end) + + events |> dbg end end