Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(explorer): add operator version via tracker api #879

Merged
merged 30 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f53a43d
feat(operators): add tracker api integration
glpecile Aug 27, 2024
40dc599
fix: nit detail view
glpecile Aug 28, 2024
a6370bf
refactor: make start script more dynamic
glpecile Aug 28, 2024
214e7e0
docs(local-setup): fix broken links and update env
glpecile Aug 28, 2024
047645c
fix: show same text as home
glpecile Aug 28, 2024
dcdd735
fix: replace amount for number
glpecile Aug 28, 2024
d8972d4
fix: error handling
glpecile Aug 28, 2024
6be9f54
feat: add badge for operator version
glpecile Aug 28, 2024
8f15a66
fix: handle empty env tracker url variable
glpecile Aug 28, 2024
a86cc58
fix: remove trakcer from dev example
glpecile Aug 28, 2024
15780ef
fix: add new_batch_v2 compatibility
glpecile Aug 28, 2024
4465157
fix: handle empty events from batcher payment system
glpecile Aug 28, 2024
f0729c1
Merge branch 'explorer/885-fix-add-new_batch_v2-compatibility' into e…
glpecile Aug 28, 2024
df6df6d
Merge branch 'explorer/886-fix-handle-empty-event-from-batcher-paymen…
glpecile Aug 28, 2024
34b7d9c
feat: handle empty card state with new component
glpecile Aug 28, 2024
f8535b9
fix: use warning instead of error on log
glpecile Aug 28, 2024
c6d66fd
fix: add missing type for attr
glpecile Aug 28, 2024
4f3d914
fix: improve error messages
glpecile Aug 28, 2024
af2b415
fix: add missing inner text class
glpecile Aug 28, 2024
3a95ee1
fix: add missing order by
glpecile Aug 28, 2024
9b0981b
style: operator detail stake order
glpecile Aug 29, 2024
931cd62
fix: better tracker error logging
uri-99 Aug 29, 2024
fac67a9
fix: operator_tracker_url works with or without / at the end
uri-99 Aug 29, 2024
6646bfd
Merge branch 'main' into explorer/878-feat-add-operator-version-via-t…
glpecile Aug 29, 2024
f731d7a
fix: add other missing trim_trailing
glpecile Aug 29, 2024
5a1cda3
fix: remove tls from example
glpecile Aug 29, 2024
b7ee07f
Merge branch 'main' into explorer/878-feat-add-operator-version-via-t…
glpecile Sep 3, 2024
7275de4
Merge branch 'main' into explorer/878-feat-add-operator-version-via-t…
glpecile Sep 5, 2024
f7a04de
Merge branch 'main' into explorer/878-feat-add-operator-version-via-t…
glpecile Sep 9, 2024
6542e7c
feat(explorer): add aligned latest version in nav (#922)
glpecile Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ The `.env` file needs to contain the following variables:
| `DB_HOST` | The host URL where the postgres database will be running. |
| `ELIXIR_HOSTNAME` | The hostname of your running elixir. |
| `DEBUG_ERRORS` | If you want to enable phoenix errors on your browser instead of a 500 page, set this to `true`. |
| `TRACKER_API_URL` | The URL of the aligned version each operator is running. |

Then you can run the explorer with this env file config by entering the following command:

Expand Down
3 changes: 3 additions & 0 deletions explorer/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ ALIGNED_CONFIG_FILE="../contracts/script/output/devnet/alignedlayer_deployment_o

# Debug
DEBUG_ERRORS=true

# Operator version tracker API
TRACKER_API_URL=http://localhost:3030
3 changes: 3 additions & 0 deletions explorer/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ ALIGNED_CONFIG_FILE="<aligned_config_file>"

# Debug
DEBUG_ERRORS=<true|false>

# Tracker API
TRACKER_API_URL=<tracker_api_url>
3 changes: 2 additions & 1 deletion explorer/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Config

config :explorer,
generators: [timestamp_type: :utc_datetime]
generators: [timestamp_type: :utc_datetime],
tracker_api_url: System.get_env("TRACKER_API_URL")

host = System.get_env("PHX_HOST") || "localhost"

Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/abi/AlignedLayerServiceManager.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytecode changes only

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ defmodule AlignedLayerServiceManager do
|> Ethers.get_logs(fromBlock: fromBlock, toBlock: toBlock)

case events do
{:ok, []} -> []
{:ok, list} -> Enum.map(list, &extract_new_batch_event_info/1)
{:error, reason} -> raise("Error fetching events: #{Map.get(reason, "message")}")
{:ok, []} ->
[]

{:ok, list} ->
Enum.map(list, &extract_new_batch_event_info/1)

{:error, reason} ->
raise("Error fetching events: #{Map.get(reason, "message")}")
end
end

Expand Down Expand Up @@ -94,8 +99,9 @@ defmodule AlignedLayerServiceManager do

def is_batch_responded(merkle_root) do
event =
AlignedLayerServiceManager.EventFilters.batch_verified(Utils.string_to_bytes32(merkle_root))
|> Ethers.get_logs(fromBlock: @first_block)
Utils.string_to_bytes32(merkle_root)
|> AlignedLayerServiceManager.EventFilters.batch_verified()
|> Ethers.get_logs(fromBlock: @first_block)

case event do
{:error, reason} -> {:error, reason}
Expand Down Expand Up @@ -189,7 +195,6 @@ defmodule AlignedLayerServiceManager do
batch_merkle_root = event |> Map.get(:topics_raw) |> Enum.at(1)
sender_address = event |> Map.get(:data) |> Enum.at(0)


{:ok,
%BatchVerifiedInfo{
address: event |> Map.get(:address),
Expand Down Expand Up @@ -228,5 +233,4 @@ defmodule AlignedLayerServiceManager do
raise("Error fetching restakeable strategies: #{error}")
end
end

end
1 change: 1 addition & 0 deletions explorer/lib/explorer/models/restakings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ defmodule Restakings do
query = from r in Restakings,
join: s in Strategies, on: r.strategy_address == s.strategy_address,
where: r.operator_id == ^operator_id,
order_by: [desc: r.stake],
select: %{
restaking: r,
strategy: %{
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer_web/components/assets_cta.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule AssetsCTAComponent do
<.link navigate={~p"/operators"} class="flex flex-col justify-start gap-0.5 group">
<div class="text-muted-foreground font-semibold flex gap-2 items-center">
<h2>
Total Active Operators
Registered Active Operators
</h2>
<.right_arrow />
</div>
Expand Down
113 changes: 79 additions & 34 deletions explorer/lib/explorer_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -388,32 +388,64 @@ defmodule ExplorerWeb.CoreComponents do
end

@doc """
Renders a dynamic badge compoent.
Renders a badge component.
"""
attr :class, :string, default: nil
attr :status, :boolean, default: true
attr :falsy_text, :string, default: "Pending"
attr :truthy_text, :string, default: "Verified"
attr :variant, :string, default: "accent"
slot :inner_block, default: nil

def dynamic_badge(assigns) do
def badge(assigns) do
~H"""
<span class={
classes([
"px-3 py-1 rounded-full",
case @status do
true -> "text-accent-foreground bg-accent group-hover:bg-primary/80"
false -> "text-background bg-foreground group-hover:bg-foreground/80"
"px-3 py-1 rounded-full font-semibold",
case @variant do
"accent" -> "text-accent-foreground bg-accent group-hover:bg-accent/80"
"primary" -> "text-primary-foreground bg-primary group-hover:bg-primary/80"
"secondary" -> "text-secondary-foreground bg-secondary group-hover:bg-secondary/80"
"destructive" -> "text-destructive-foreground bg-destructive group-hover:bg-destructive/80"
"foreground" -> "text-background bg-foreground group-hover:bg-foreground/80"
"card" -> "text-card-foreground bg-card group-hover:bg-card/80"
_ -> "text-accent-foreground bg-accent group-hover:bg-accent/80"
end,
@class
])
}>
<%= render_slot(@inner_block) %>
</span>
"""
end

@doc """
Renders a dynamic badge compoent.
"""
attr :class, :string, default: nil
attr :status, :boolean, default: true
attr :falsy_text, :string, default: "Pending"
attr :truthy_text, :string, default: "Verified"
slot :inner_block, default: nil

def dynamic_badge(assigns) do
~H"""
<.badge
variant={
case @status do
true -> "accent"
false -> "foreground"
end
}
class={
classes([
@class
])
}
>
<%= case @status do
true -> @truthy_text
false -> @falsy_text
end %>
<%= render_slot(@inner_block) %>
</span>
</.badge>
"""
end

Expand Down Expand Up @@ -708,6 +740,43 @@ defmodule ExplorerWeb.CoreComponents do
"""
end

@doc """
Renders an empty card background.

## Examples

<.empty_card_background text="No users found" />

"""
attr :class, :string, default: nil
attr :inner_text_class, :string, default: nil
attr :text, :string, default: nil
slot :inner_block

def empty_card_background(assigns) do
~H"""
<.card_background class={
classes([
"overflow-x-auto min-h-[38.45rem] flex flex-col items-center justify-center gap-2",
@class
])
}>
<p
:if={@text != nil}
class={
classes([
"text-lg text-muted-foreground",
@inner_text_class
])
}
>
<%= @text %>
</p>
<%= render_slot(@inner_block) %>
</.card_background>
"""
end

@doc """
Renders a data list.

Expand Down Expand Up @@ -735,30 +804,6 @@ defmodule ExplorerWeb.CoreComponents do
"""
end

@doc """
Renders a back navigation link.

## Examples

<.back navigate={~p"/posts"}>Back to posts</.back>
"""
attr :navigate, :any, required: true
slot :inner_block, required: true

def back(assigns) do
~H"""
<div class="mt-16">
<.link
navigate={@navigate}
class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
<.icon name="hero-arrow-left-solid" class="h-3 w-3" />
<%= render_slot(@inner_block) %>
</.link>
</div>
"""
end

@doc """
Renders a [Heroicon](https://heroicons.com).

Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer_web/live/pages/batch/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</div>
<div>
<h3>
Amount of Proofs in this Batch:
Number of Proofs in this Batch:
</h3>
<p><%= @current_batch.amount_of_proofs %></p>
</div>
Expand Down
4 changes: 1 addition & 3 deletions explorer/lib/explorer_web/live/pages/batches/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
</:col>
</.table>
<% else %>
<.card_background class="overflow-x-auto min-h-[38.45rem] flex flex-col items-center justify-center gap-2">
<p class="text-lg text-muted-foreground">No batches found.</p>
</.card_background>
<.empty_card_background text="No batches found." />
<% end %>
<div class="flex gap-x-2 items-center justify-center w-full">
<%= if @current_page >= 2 do %>
Expand Down
21 changes: 17 additions & 4 deletions explorer/lib/explorer_web/live/pages/operator/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ defmodule ExplorerWeb.Operator.Index do

weight = Operators.get_operator_weight(operator) |> Numbers.show_percentage()

operator_version = OperatorVersionTracker.get_operator_version(address)

if connected?(socket), do: Phoenix.PubSub.subscribe(Explorer.PubSub, "update_restakings")

{:ok,
Expand All @@ -36,6 +38,7 @@ defmodule ExplorerWeb.Operator.Index do
restaked_amount_eth: restaked_amount_eth,
restakes_by_operator: restakes_by_operator,
weight: weight,
operator_version: operator_version,
page_title: operator.name
)}
end
Expand Down Expand Up @@ -112,6 +115,16 @@ defmodule ExplorerWeb.Operator.Index do
/>
</p>
</div>
<%= if @operator_version != nil do %>
<div>
<h3>
Version:
</h3>
<.badge class="text-xs px-1.5 normal-case" variant="secondary">
<%= @operator_version %>
</.badge>
</div>
<% end %>
<div>
<h3>
Total Restaked:
Expand All @@ -135,14 +148,14 @@ defmodule ExplorerWeb.Operator.Index do
<%= if @restakes_by_operator != [] do %>
<div class="flex flex-col gap-y-2 basis-3/4">
<%= for %{strategy: strategy, restaking: restaking} <- @restakes_by_operator do %>
<div class="flex text-foreground gap-x-1 justify-between lg:pr-2">
<div class="flex text-foreground gap-x-3 lg:pr-2">
<p class="font-semibold md:basis-1/5">
<%= EthConverter.wei_to_eth(restaking.stake, 2) |> Helpers.format_number() %> ETH
</p>
<p>
<%= strategy.name %>
<span class="text-xs text-muted-foreground"><%= strategy.symbol %></span>
</p>
<p class="font-semibold">
<%= EthConverter.wei_to_eth(restaking.stake, 2) |> Helpers.format_number() %> ETH
</p>
</div>
<% end %>
</div>
Expand Down
Loading