diff --git a/models/staging/across/__across__sources.yml b/models/staging/across/__across__sources.yml index 5bb73f3f..cac34707 100644 --- a/models/staging/across/__across__sources.yml +++ b/models/staging/across/__across__sources.yml @@ -5,3 +5,4 @@ sources: tables: - name: raw_across_v2_zksync_events - name: raw_across_v3_zksync_events + - name: raw_across_v3_linea_events diff --git a/models/staging/across/fact_across_flows.sql b/models/staging/across/fact_across_flows.sql index aefb455e..7020840c 100644 --- a/models/staging/across/fact_across_flows.sql +++ b/models/staging/across/fact_across_flows.sql @@ -62,7 +62,7 @@ with from base_flipside.price.ez_hourly_token_prices where token_address in (select token_address from distinct_tokens where chain = 'base') ), - dim_zkSync_tokens as ( + dim_tokens as ( select symbol, address, chain, category from ( @@ -108,7 +108,7 @@ with ), - zksync_transfers as ( + zksync_linea_transfers as ( select version, contract_address, @@ -119,26 +119,26 @@ with depositor, recipient, destination_chain_id, - dim_zkSync_tokens.address as destination_token, + dim_tokens.address as destination_token, origin_chain_id, destination_token_symbol, destination_chain, source_chain, - dim_zkSync_tokens.category as destination_category + dim_tokens.category as destination_category from across_transfers_chain_mapping - left join dim_zkSync_tokens on lower(destination_token_symbol) = lower(symbol) - where destination_token_symbol is not null + left join dim_tokens on lower(destination_token_symbol) = lower(symbol) + where lower(contract_address) in (lower('0xE0B015E54d54fc84a6cB9B666099c46adE9335FF'), lower('0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75')) ), - zksync_prices as ( + zksync_linea_prices as ( select hour, token_address, decimals, avg(price) as price from ethereum_flipside.price.ez_hourly_token_prices - inner join dim_zkSync_tokens on lower(token_address) = lower(address) + inner join dim_tokens on lower(token_address) = lower(address) group by 1, 2, 3 ), - zksync_volume_by_chain_and_symbol as ( + zksync_linea_volume_by_chain_and_symbol as ( select date_trunc('hour', block_timestamp) as hour, source_chain, @@ -147,16 +147,16 @@ with sum( coalesce((amount / power(10, p.decimals)) * price, 0) ) as amount_usd - from zksync_transfers t + from zksync_linea_transfers t left join - zksync_prices p + zksync_linea_prices p on date_trunc('hour', t.block_timestamp) = p.hour and t.destination_token = p.token_address group by 1, 2, 3, 4 ), - non_zksync_volume_by_chain_and_symbol as ( + non_zksync_linea_volume_by_chain_and_symbol as ( select date_trunc('hour', block_timestamp) as hour, source_chain, @@ -171,7 +171,7 @@ with on date_trunc('hour', t.block_timestamp) = p.hour and t.destination_token = p.token_address where - t.destination_token_symbol is null + lower(t.contract_address) not in (lower('0xE0B015E54d54fc84a6cB9B666099c46adE9335FF'), lower('0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75')) group by 1, 2, 3, 4 ), @@ -185,12 +185,12 @@ with from ( select * - from zksync_volume_by_chain_and_symbol + from zksync_linea_volume_by_chain_and_symbol union select * - from non_zksync_volume_by_chain_and_symbol + from non_zksync_linea_volume_by_chain_and_symbol ) t group by 1, 2, 3, 4 diff --git a/models/staging/across/fact_across_v3_transfers.sql b/models/staging/across/fact_across_v3_transfers.sql index 546ceac9..0a6e9d35 100644 --- a/models/staging/across/fact_across_v3_transfers.sql +++ b/models/staging/across/fact_across_v3_transfers.sql @@ -195,8 +195,69 @@ with zksync_extraction t2 on t1.date = t2.date and t1.extraction_date = t2.extraction_date + ), + + linea_extraction as ( + select + date_trunc('day', flat_json.value:"block_timestamp"::timestamp) as date, + max(extraction_date) as extraction_date + from + {{ source("PROD_LANDING", "raw_across_v3_linea_events") }}, + lateral flatten(input => parse_json(source_json)) as flat_json + group by date + order by date + ), + + linea_flattened_json as ( + select + extraction_date, + date_trunc('day', flat_json.value:"block_timestamp"::timestamp) as date, + to_timestamp(flat_json.value:"block_timestamp"::varchar) as block_timestamp, + flat_json.value:"contract_address"::string as contract_address, + flat_json.value:"tx_hash"::string as tx_hash, + flat_json.value:"event_index"::integer as event_index, + flat_json.value:"amount"::double as amount, + flat_json.value:"depositor"::string as depositor, + flat_json.value:"recipient"::string as recipient, + flat_json.value:"destination_chain_id"::integer as destination_chain_id, + flat_json.value:"destination_token"::string as destination_token, + flat_json.value:"origin_chain_id"::integer as origin_chain_id, + flat_json.value:"input_amount"::float as input_amount, + flat_json.value:"input_token"::string as input_token, + flat_json.value:"destination_token_symbol"::string + as destination_token_symbol + from + {{ source("PROD_LANDING", "raw_across_v3_linea_events") }}, + lateral flatten(input => parse_json(source_json)) as flat_json + ), + + linea_transfers as ( + select + t1.contract_address, + t1.block_timestamp, + t1.tx_hash, + t1.event_index, + t1.amount, + t1.depositor, + t1.recipient, + t1.destination_chain_id, + t1.destination_token, + t1.origin_chain_id, + t1.input_amount, + t1.input_token, + t1.destination_token_symbol, + from linea_flattened_json t1 + left join + linea_extraction t2 + on t1.date = t2.date + and t1.extraction_date = t2.extraction_date ) + + + + + select contract_address, block_timestamp, @@ -230,3 +291,24 @@ select input_token, destination_token_symbol from zksync_transfers + +union + +select + contract_address, + block_timestamp, + tx_hash, + event_index, + amount, + depositor, + recipient, + destination_chain_id, + destination_token, + origin_chain_id, + input_amount, + input_token, + destination_token_symbol +from linea_transfers + + +