11
11
,incremental_predicates = [incremental_predicate(' DBT_INTERNAL_DEST.block_time' )]
12
12
)
13
13
}}
14
- {{ arbitrum_orbit_stack_gas_fees(blockchain) }}
14
+
15
+ WITH base_model as (
16
+ SELECT
17
+ txns .block_time
18
+ ,txns .block_number
19
+ ,txns .hash AS tx_hash
20
+ ,txns." from" AS tx_from
21
+ ,txns .to AS tx_to
22
+ ,cast(gas_price as uint256) as gas_price
23
+ ,txns .gas_used as gas_used
24
+ ,cast(base_fee_per_gas as uint256) * cast(txns .gas_used as uint256) as tx_fee_raw
25
+ ,map(array[' base_fee' ], array[cast(base_fee_per_gas as uint256) * cast(txns .gas_used as uint256)]) as tx_fee_breakdown_raw
26
+ ,0x7f9fbf9bdd3f4105c478b996b648fe6e828a1e98 as tx_fee_currency
27
+ ,blocks .miner AS block_proposer
28
+ ,txns .max_fee_per_gas
29
+ ,txns .priority_fee_per_gas
30
+ ,txns .max_priority_fee_per_gas
31
+ ,blocks .base_fee_per_gas
32
+ ,txns .gas_limit
33
+ ,CASE -- safe divide-by-zero
34
+ WHEN txns .gas_limit = 0 THEN NULL
35
+ WHEN txns .gas_limit != 0 THEN cast(txns .gas_used as double) / cast(txns .gas_limit as double)
36
+ END AS gas_limit_usage
37
+ {% if blockchain == ' apechain' %}
38
+ ,l1_gas_used
39
+ {% endif %}
40
+ FROM {{ source(blockchain, ' transactions' ) }} txns
41
+ INNER JOIN {{ source(blockchain, ' blocks' ) }} blocks
42
+ ON txns .block_number = blocks .number
43
+ {% if is_incremental() %}
44
+ AND {{ incremental_predicate(' blocks.time' ) }}
45
+ {% endif %}
46
+ {% if test_short_ci %}
47
+ WHERE {{ incremental_predicate(' txns.block_time' ) }}
48
+ OR txns .hash in (select tx_hash from {{ref(' evm_gas_fees' )}})
49
+ {% elif is_incremental() %}
50
+ WHERE {{ incremental_predicate(' txns.block_time' ) }}
51
+ {% endif %}
52
+ )
53
+
54
+ SELECT
55
+ ' {{blockchain}}' as blockchain
56
+ ,CAST(date_trunc(' month' , block_time) AS DATE ) AS block_month
57
+ ,CAST(date_trunc(' day' , block_time) AS DATE ) AS block_date
58
+ ,block_time
59
+ ,block_number
60
+ ,tx_hash
61
+ ,tx_from
62
+ ,tx_to
63
+ ,gas_price
64
+ ,gas_used
65
+ ,p .symbol as currency_symbol
66
+ ,coalesce(tx_fee_raw, 0 ) as tx_fee_raw
67
+ ,coalesce(tx_fee_raw, 0 ) / pow(10 ,p .decimals ) as tx_fee
68
+ ,coalesce(tx_fee_raw, 0 ) / pow(10 ,p .decimals ) * p .price as tx_fee_usd
69
+ ,transform_values(tx_fee_breakdown_raw,
70
+ (k,v) - > coalesce(v, cast(0 as uint256))) as tx_fee_breakdown_raw
71
+ ,transform_values(tx_fee_breakdown_raw,
72
+ (k,v) - > coalesce(v, cast(0 as uint256)) / pow(10 ,p .decimals ) ) as tx_fee_breakdown
73
+ ,transform_values(tx_fee_breakdown_raw,
74
+ (k,v) - > coalesce(v, cast(0 as uint256)) / pow(10 ,p .decimals ) * p .price ) as tx_fee_breakdown_usd
75
+ ,tx_fee_currency
76
+ ,block_proposer
77
+ ,max_fee_per_gas
78
+ ,priority_fee_per_gas
79
+ ,max_priority_fee_per_gas
80
+ ,base_fee_per_gas
81
+ ,gas_limit
82
+ ,gas_limit_usage
83
+ {% if blockchain == ' apechain' %}
84
+ ,l1_gas_used
85
+ {% endif %}
86
+ FROM base_model
87
+ LEFT JOIN {{ ref(' prices_usd_with_native' ) }} p
88
+ ON p .blockchain = ' {{blockchain}}'
89
+ AND p .contract_address = tx_fee_currency
90
+ AND p .minute = date_trunc(' minute' , block_time)
91
+ {% if is_incremental() %}
92
+ AND {{ incremental_predicate(' p.minute' ) }}
93
+ {% endif %}
0 commit comments