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

Migrate TopHolders to use labeling framework v2 #3993

Merged
merged 1 commit into from
Nov 23, 2023
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
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