Skip to content

Commit

Permalink
Zksync native bridge flows (duneanalytics#5247)
Browse files Browse the repository at this point in the history
* ERC-20 deposits

* Withdraw ETH

* Withdraw ERC-20

* remove chainID table join

* Update ERC-20 deposits

* Update ETH withdrawals

* Add ETH deposits

* add chains for ETH deposits

* misc

* misc

* Add schema and source yml files

* fix

* fix chain name

* fix columns

* add back `evt_index`

* update schema and alias

* update join logic

* update chain names

* update tx_from, tx_to, and more join logic

* Update file names to match new schema_alias names

* add more incremental logic

* fix `block_time`

* fix token/price joins

* handle ETH <> WETH pricing and symbol matching

* update ETH <> WETH matching again
  • Loading branch information
lgingerich authored Jan 26, 2024
1 parent f1146a8 commit e135bcf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions models/bridge/zksync/bridge_zksync_native_flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ SELECT
,tf.evt_index
,COALESCE(tf.sender_address,CAST(NULL as VARBINARY)) as sender_address
,COALESCE(tf.receiver_address, CAST(NULL as VARBINARY)) as receiver_address
,erc.symbol as token_symbol
,CAST(tf.bridged_token_amount_raw as double)/ POWER(10, erc.decimals) as token_amount
,CASE
WHEN bridged_token_address = 0x0000000000000000000000000000000000000000 THEN 'ETH'
ELSE erc.symbol
END AS token_symbol
,CAST(tf.bridged_token_amount_raw as double) / POWER(10, erc.decimals) as token_amount
,p.price * (CAST(tf.bridged_token_amount_raw as double) / POWER(10, erc.decimals) ) as token_amount_usd
,tf.bridged_token_amount_raw as token_amount_raw
,0 as fee_amount
Expand All @@ -187,13 +190,21 @@ SELECT
FROM bridge_events tf

LEFT JOIN {{ ref('tokens_erc20') }} erc
ON erc.blockchain = 'zksync'
AND erc.contract_address = tf.bridged_token_address
ON erc.contract_address =
CASE
WHEN tf.bridged_token_address = 0x0000000000000000000000000000000000000000 THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- When the token is ETH, match on WETH
ELSE tf.bridged_token_address
END
AND erc.blockchain IN ('ethereum', 'zksync')

LEFT JOIN {{ source('prices', 'usd') }} p
ON p.minute = DATE_TRUNC('minute', tf.block_time)
AND p.blockchain = 'zksync'
AND p.contract_address = tf.bridged_token_address
AND p.contract_address =
CASE
WHEN tf.bridged_token_address = 0x0000000000000000000000000000000000000000 THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- When the token is ETH, match on WETH
ELSE tf.bridged_token_address
END
AND p.blockchain IN ('ethereum', 'zksync')
{% if is_incremental() %}
AND {{ incremental_predicate('p.minute') }}
{% endif %}

0 comments on commit e135bcf

Please sign in to comment.