Skip to content

Commit

Permalink
Migrate TopHolders to use labeling framework v2
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Nov 23, 2023
1 parent 1121197 commit eb2315c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/sanbase/clickhouse/top_holders/top_holders.ex
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ defmodule Sanbase.Clickhouse.TopHolders do
balance2 * price_usd AS balance_usd,
(balance2 / (total_balance / decimals)) AS partOfTotal
FROM eth_balances_realtime
PREWHERE
WHERE
addressType = 'normal'
GROUP BY address
ORDER BY balance2 DESC
Expand Down Expand Up @@ -335,8 +335,8 @@ defmodule Sanbase.Clickhouse.TopHolders do
GLOBAL ANY INNER JOIN
(
SELECT address
FROM blockchain_address_labels
PREWHERE blockchain = 'ethereum' AND #{clause}
FROM current_label_addresses
WHERE blockchain = 'ethereum' AND label_id IN (SELECT label_id FROM label_metadata WHERE #{clause})
) USING (address)
"""

Expand All @@ -352,7 +352,8 @@ defmodule Sanbase.Clickhouse.TopHolders do
values ->
params_count = map_size(params)
owners_key = "owners_param_count_#{params_count}"
str = "JSONExtractString(metadata, 'owner') IN ({{#{owners_key}}})"
str = "(key = 'owner' AND value IN ({{#{owners_key}}}))"

{str, Map.put(params, owners_key, values)}
end
end
Expand All @@ -365,7 +366,8 @@ defmodule Sanbase.Clickhouse.TopHolders do
values ->
params_count = map_size(params)
labels_key = "labels_param_count_#{params_count}"
str = "label IN ({{#{labels_key}})"
str = "(key IN ({{#{labels_key}}}))"

{str, Map.put(params, labels_key, values)}
end
end
Expand Down
16 changes: 13 additions & 3 deletions lib/sanbase/run_examples.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,22 @@ defmodule Sanbase.RunExamples do
end

defp do_run(:top_holders) do
{:ok, _} =
Sanbase.Clickhouse.TopHolders.percent_of_total_supply(
"ethereum",
5,
@from,
@closer_to,
"1d"
)

{:ok, _} =
Sanbase.Clickhouse.TopHolders.top_holders(
"ethereum",
@from,
@to,
[]
@closer_to,
labels: ["centralized_exchange"],
owners: ["binance"]
)

for metric <- [
Expand All @@ -225,7 +235,7 @@ defmodule Sanbase.RunExamples do
metric,
%{slug: "ethereum"},
@from,
@to,
@closer_to,
"1d",
[]
)
Expand Down

0 comments on commit eb2315c

Please sign in to comment.