Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); fix(explorer): count only active operators for weight by uri-99 · Pull Request #934 · yetanotherco/aligned_layer · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,7 +151,7 @@ operator_register_with_eigen_layer:

operator_mint_mock_tokens:
@echo "Minting tokens"
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 1000
. ./scripts/mint_mock_token.sh $(CONFIG_FILE) 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_whitelist_devnet:
@echo "Whitelisting operator"
Expand All@@ -170,7 +170,7 @@ operator_deposit_into_mock_strategy:
@go run operator/cmd/main.go deposit-into-strategy \
--config $(CONFIG_FILE) \
--strategy-address $(STRATEGY_ADDRESS) \
--amount 1000
--amount 100000000000000000
Comment thread
uri-99 marked this conversation as resolved.

operator_deposit_into_strategy:
@echo "Depositing into strategy"
Expand Down
3 changes: 3 additions & 0 deletions docs/3_guides/6_setup_aligned.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,6 +534,9 @@ to run it using the following documentation:
- [Erlang 26](https://github.com/asdf-vm/asdf-erlang)
- [Elixir 1.16.2](https://elixir-ko.github.io/install.html), compiled with OTP 26
- [Docker](https://docs.docker.com/get-docker/)
- [NodeJS](https://nodejs.org/en/download/package-manager)
- Tested with node 20 and 22
- [pnpm](https://pnpm.io/installation)

### DB Setup

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,8 +25,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.name(token_address) do
{:ok, name} -> %{strategy | name: name}
error ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | name: "‎"} # token has no Name (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token name for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_name({:error, error}) do
Expand All@@ -37,8 +41,12 @@ defmodule StrategyInterfaceManager do
case ERC20InterfaceManager.symbol(token_address) do
{:ok, symbol} -> %{strategy | symbol: symbol}
error ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
case error do
{:error, %{"code" => 3, "data" => "0x", "message" => "execution reverted"}} -> %{strategy | symbol: "‎"} # token has no Symbol (empty char), not a common practice but still an ERC20
_ ->
"Error fetching token symbol for #{token_address}: #{inspect(error)}" |> Logger.error()
error
end
end
end
def fetch_token_symbol({:error, error}) do
Expand Down
28 changes: 24 additions & 4 deletions explorer/lib/explorer/models/operators.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,15 @@ defmodule Operators do
Operators.changeset(%Operators{}, Map.from_struct(operator))
end

def generate_new_total_stake_changeset(%{operator_address: operator_address}) do
new_total_stake = StakeRegistryManager.get_stake_of_quorum_for_operator(%Restakings{operator_address: operator_address})

query = from(o in Operators, where: o.address == ^operator_address, select: o)
operator = Explorer.Repo.one(query)

Operators.changeset(operator, %{total_stake: new_total_stake})
end

def get_operator_by_address(address) do
query = from(o in Operators, where: o.address == ^address, select: o)
Explorer.Repo.one(query)
Expand All@@ -48,13 +57,23 @@ defmodule Operators do
end

def get_operators_with_their_weights() do
total_stake = Explorer.Repo.one(from(o in Operators, select: sum(o.total_stake)))
total_stake = Explorer.Repo.one(
from(
o in Operators,
where: o.is_active == true,
select: sum(o.total_stake))
)

get_operators() |>
Enum.map(
fn operator ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
case operator.is_active do
false ->
Map.from_struct(operator) |> Map.put(:weight, 0)
true ->
weight = Decimal.div(operator.total_stake, total_stake)
Map.from_struct(operator) |> Map.put(:weight, weight)
end
end
)
end
Expand DownExpand Up@@ -115,7 +134,8 @@ defmodule Operators do

def unregister_operator(%Operators{address: address}) do
query = from(o in Operators, where: o.address == ^address)
Explorer.Repo.update_all(query, set: [is_active: false])
Explorer.Repo.update_all(query, set: [is_active: false, total_stake: 0])
Restakings.remove_restakes_of_operator(%{operator_address: address})
end

def get_total_stake(%Operators{} = operator) do
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer/models/quorums.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ defmodule Quorums do
def handle_quorum(%Quorums{} = quorum) do
strategy_addresses = StakeRegistryManager.get_strategies_of_quorum(quorum.id)

insert_quorum_if_not_present(quorum)
insert_quorum_if_not_present(quorum) # Only for new Quorums inserted by running Quorums.handle_quorum(%Quorums{id: 0})

Enum.each(strategy_addresses,
fn strategy_address ->
Expand Down
15 changes: 14 additions & 1 deletion explorer/lib/explorer/models/restakings.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ defmodule Restakings do
Operators.get_operators()
|> Enum.map(fn operator -> StakeRegistryManager.has_operator_changed_staking(%{fromBlock: from_block, operator_id: operator.id, operator_address: operator.address}) end)
|> Enum.reject(fn {_operator_id, _operator_address, has_changed_stake} -> not has_changed_stake end)
|> Enum.reject(fn {operator_id, _operator_address, _has_changed_stake} -> not Operators.get_operator_by_id(operator_id).is_active end)
Comment thread
uri-99 marked this conversation as resolved.
|> Enum.map(fn {operator_id, operator_address, _has_changed_stake} -> DelegationManager.get_operator_all_strategies_shares(%Operators{id: operator_id, address: operator_address}) end)
|> Enum.each(&insert_or_update_restakings/1)
end
Expand All@@ -54,6 +55,9 @@ defmodule Restakings do
|> Ecto.Multi.update(:update_strategy_total_staked, Strategies.generate_update_total_staked_changeset(%{new_restaking: restaking}))
end

multi = multi
|> Ecto.Multi.update(:update_operator_total_stake, Operators.generate_new_total_stake_changeset(%{operator_address: restaking.operator_address}))

case Explorer.Repo.transaction(multi) do
{:ok, _} ->
"Restaking inserted or updated" |> Logger.debug()
Expand All@@ -64,7 +68,16 @@ defmodule Restakings do
end
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
def remove_restakes_of_operator(%{operator_address: operator_address}) do
Logger.debug("Removing restakes of operator")
query = from(r in Restakings, where: r.operator_address == ^operator_address)
restakings = Explorer.Repo.all(query)

Explorer.Repo.delete_all(query)
Enum.each(restakings, &Strategies.discount_restaking/1)
end

def get_by_operator_and_strategy(%Restakings{operator_address: operator_address, strategy_address: strategy_address}) do
query = from(
r in Restakings,
where: r.operator_address == ^operator_address and r.strategy_address == ^strategy_address,
Expand Down
14 changes: 14 additions & 0 deletions explorer/lib/explorer/models/strategies.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,4 +99,18 @@ defmodule Strategies do
Strategies.changeset(strategy, %{total_staked: new_stake})
end

def discount_restaking(restaking) do
query = from(s in Strategies,
where: s.strategy_address == ^restaking.strategy_address,
select: s)
strategy = Explorer.Repo.one(query)

new_stake =
strategy.total_staked
|> Decimal.sub(restaking.stake)
|> (fn stake -> if Decimal.compare(stake, 0) == :lt, do: Decimal.new(0), else: stake end).()

Strategies.changeset(strategy, %{total_staked: new_stake}) |> Explorer.Repo.update()

end
end
6 changes: 5 additions & 1 deletion explorer/lib/explorer_web/live/pages/restakes/index.ex
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,11 @@ defmodule ExplorerWeb.Restakes.Index do
alt={asset.name}
class="size-5 rounded-full object-scale-down text-xs truncate text-center"
/>
<%= asset.name %>
<%= if asset.name != "‎" do %>
<%= asset.name %>
<% else %>
<%= asset.strategy_address %>
<% end %>
<p class="text-muted-foreground text-sm">
<%= asset.symbol %>
</p>
Expand Down