arbitrum-models/models/gold/core__ez_eth_transfers.sql
drethereum bc6332984b
AN-3534/arb-streamline-migration (#82)
* workflow changes

* models macro

* logs table docs

* gold layer changes

* silver legacy changes

* silver core tests

* timestamp cast type

* workflow changes schedule

* gas price column names
2023-07-11 10:54:30 -06:00

55 lines
1.2 KiB
SQL

{{ config(
materialized = 'view'
) }}
WITH eth_base AS (
SELECT
tx_hash,
block_number,
block_timestamp,
from_address,
to_address,
eth_value,
identifier,
input
FROM
{{ ref('core__fact_traces') }}
WHERE
TYPE = 'CALL'
AND eth_value > 0
AND tx_status = 'SUCCESS'
AND trace_status = 'SUCCESS'
),
eth_price AS (
SELECT
HOUR,
price AS eth_price
FROM
{{ ref('silver__prices_eth') }}
)
SELECT
A.tx_hash AS tx_hash,
A.block_number AS block_number,
A.block_timestamp AS block_timestamp,
A.identifier AS identifier,
tx.from_address AS origin_from_address,
tx.to_address AS origin_to_address,
tx.origin_function_signature AS origin_function_signature,
A.from_address AS eth_from_address,
A.to_address AS eth_to_address,
A.eth_value AS amount,
ROUND(
A.eth_value * eth_price,
2
) AS amount_usd
FROM
eth_base A
LEFT JOIN eth_price
ON DATE_TRUNC(
'hour',
block_timestamp
) = HOUR
JOIN {{ ref('silver__transactions') }}
tx
ON A.tx_hash = tx.tx_hash