From eb2315cffd3fd598e4a1d9b4c85bb32cbc3bef29 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 23 Nov 2023 15:01:31 +0200 Subject: [PATCH] Migrate TopHolders to use labeling framework v2 --- .../clickhouse/top_holders/top_holders.ex | 12 +++++++----- lib/sanbase/run_examples.ex | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/sanbase/clickhouse/top_holders/top_holders.ex b/lib/sanbase/clickhouse/top_holders/top_holders.ex index 37ac8347f8..daa085f4ea 100644 --- a/lib/sanbase/clickhouse/top_holders/top_holders.ex +++ b/lib/sanbase/clickhouse/top_holders/top_holders.ex @@ -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 @@ -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) """ @@ -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 @@ -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 diff --git a/lib/sanbase/run_examples.ex b/lib/sanbase/run_examples.ex index 32c90a977a..ecc279791f 100644 --- a/lib/sanbase/run_examples.ex +++ b/lib/sanbase/run_examples.ex @@ -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 <- [ @@ -225,7 +235,7 @@ defmodule Sanbase.RunExamples do metric, %{slug: "ethereum"}, @from, - @to, + @closer_to, "1d", [] )