pub use clickhouse_mod::*;
#[rustfmt::skip]
mod clickhouse_mod {
#[allow(dead_code)]
pub const CEX_SYMBOLS: &str = r#"SELECT DISTINCT
s.exchange AS exchange,
upper(replaceAll(replaceAll(replaceAll(s.pair, '/', ''), '-', ''), '_', '')) AS symbol_pair,
(toString(p1.address), toString(p2.address)) AS address_pair
FROM cex.trading_pairs s
INNER JOIN cex.address_symbols AS p1 ON p1.symbol = s.base_asset OR p1.unwrapped_symbol = s.base_asset
INNER JOIN cex.address_symbols AS p2 ON p2.symbol = s.quote_asset OR p2.unwrapped_symbol = s.quote_asset
and not (s.exchange = 'okex' and s.trading_type = 'FUTURES')
"#;
#[allow(dead_code)]
pub const RAW_CEX_TRADES: &str = r#"SELECT
c.exchange AS exchange,
'Taker' AS trade_type,
upper(replaceAll(replaceAll(replaceAll(c.symbol, '/', ''), '-', ''), '_', '')) AS symbol,
c.timestamp AS timestamp,
c.side AS side,
c.price AS price,
c.amount AS amount
FROM cex.normalized_trades AS c
WHERE c.timestamp >= ? AND c.timestamp < ?
ORDER BY timestamp "#;
#[allow(dead_code)]
pub const MOST_VOLUME_PAIR_EXCHANGE: &str = r#"WITH ranked_symbols AS
(
SELECT
month,
upper(replaceAll(replaceAll(replaceAll(symbol, '/', ''), '-', ''), '_', '')) AS symbol,
exchange,
sum(sum_volume) AS total_volume
FROM cex.trading_volume_by_month
WHERE (month >= toStartOfMonth(toDateTime(? / 1000000) - toIntervalMonth(1))) AND (month <= toStartOfMonth(toDateTime(? / 1000000) + toIntervalMonth(1)))
GROUP BY month, symbol, exchange
),
aggregated_exchanges AS
(
SELECT
symbol,
month,
groupArray((exchange, total_volume)) AS exchanges_volumes
FROM ranked_symbols
GROUP BY symbol, month
)
SELECT
symbol,
arrayMap(x -> x.1, arraySort(v -> -v.2, exchanges_volumes)) AS exchanges,
toUnixTimestamp(month) * 1000000 AS timestamp
FROM aggregated_exchanges
ORDER BY timestamp
"#;
#[allow(dead_code)]
pub const P2P_OBSERVATIONS: &str = r#"SELECT
CAST(round(min(timestamp) / 1000), 'UInt64') AS first_observation
FROM ethereum.`chainbound.block_observations`
WHERE block_number = ? AND block_hash = ?"#;
#[allow(dead_code)]
pub const RAW_CEX_QUOTES: &str = r#"WITH
grouped_time AS (
SELECT
c.exchange as exchange,
upper(replaceAll(replaceAll(replaceAll(c.symbol, '/', ''), '-', ''), '_', '')) AS symbol,
toUnixTimestamp(toDateTime(round(c.timestamp / 1000000), 'UTC')) * 1000000 AS timestamp_sec,
argMin(c.timestamp, abs(CAST(c.timestamp, 'Int64') - CAST(timestamp_sec, 'Int64'))) as timestamp,
argMin(c.ask_amount, abs(CAST(c.timestamp, 'Int64') - CAST(timestamp_sec, 'Int64'))) as ask_amount,
argMin(c.ask_price, abs(CAST(c.timestamp, 'Int64') - CAST(timestamp_sec, 'Int64'))) as ask_price,
argMin(c.bid_price, abs(CAST(c.timestamp, 'Int64') - CAST(timestamp_sec, 'Int64'))) as bid_price,
argMin(c.bid_amount, abs(CAST(c.timestamp, 'Int64') - CAST(timestamp_sec, 'Int64'))) as bid_amount
FROM cex.normalized_quotes as c
WHERE c.timestamp >= ? AND c.timestamp < ?
GROUP BY exchange, symbol, timestamp_sec
)
SELECT
exchange,
symbol,
timestamp,
ask_amount,
ask_price,
bid_price,
bid_amount
FROM grouped_time
ORDER BY timestamp
"#;
#[allow(dead_code)]
pub const CRIT_INIT_TABLES: &str = r#"with
pools as (
select cast(count(), 'UInt64') as pool_creation from ( select init_block from ethereum.pools group by init_block )
),
address_to_protocol as (
select cast(count(distinct address), 'UInt64') as address_to_protocol from ethereum.pools
WHERE length(pools.tokens) >= 2
),
tokens as (
select cast(count(distinct address), 'UInt64') as tokens from brontes.token_info
),
builder as (
select cast(count(), 'UInt64') as builder from brontes_api.builder_info
),
address_meta as(
select cast(count(), 'UInt64') as address_meta from brontes_api.address_meta
)
select
p.*,
a.*,
t.*,
b.*,
am.*
from pools as p
cross join address_to_protocol as a
cross join tokens as t
cross join builder as b
cross join address_meta as am
"#;
#[allow(dead_code)]
pub const BLOCK_TIMES: &str = r#"SELECT
CAST(block_number, 'UInt64') AS block_number,
CAST(block_timestamp * 1000000, 'UInt64') AS block_timestamp
FROM ethereum.blocks
WHERE block_number >= ? AND block_number < ?
ORDER BY block_number"#;
#[allow(dead_code)]
pub const PRIVATE_FLOW: &str = r#"SELECT DISTINCT
tx_hash
FROM ethereum.`chainbound.mempool`
WHERE tx_hash IN (
SELECT arrayJoin(?) AS tx_hash
)"#;
}