Skip to content

Commit

Permalink
Merge pull request #88 from Artemis-xyz/sm-update-across
Browse files Browse the repository at this point in the history
Updating across to support Linea
  • Loading branch information
SebMelendez01 authored May 17, 2024
2 parents 22dcc98 + 204c211 commit 17eb024
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 15 deletions.
1 change: 1 addition & 0 deletions models/staging/across/__across__sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sources:
tables:
- name: raw_across_v2_zksync_events
- name: raw_across_v3_zksync_events
- name: raw_across_v3_linea_events
30 changes: 15 additions & 15 deletions models/staging/across/fact_across_flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down Expand Up @@ -108,7 +108,7 @@ with
),


zksync_transfers as (
zksync_linea_transfers as (
select
version,
contract_address,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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

),
Expand All @@ -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
Expand Down
82 changes: 82 additions & 0 deletions models/staging/across/fact_across_v3_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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



0 comments on commit 17eb024

Please sign in to comment.