Skip to content

Commit 9c84d6f

Browse files
authored
Merge branch 'main' into enhance_evms_event_tables
2 parents f5e93ff + 24463e4 commit 9c84d6f

File tree

12 files changed

+142
-31
lines changed

12 files changed

+142
-31
lines changed

dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/apechain/gas_apechain_fees.sql

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,83 @@
1111
,incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
1212
)
1313
}}
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 %}

dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/mantle/gas_mantle_fees.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ WITH base_model as (
3535
)
3636
end
3737
) as tx_fee_breakdown_raw
38-
,{{var('ETH_ERC20_ADDRESS')}} as tx_fee_currency
38+
,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000 as tx_fee_currency
3939
,blocks.miner AS block_proposer
4040
,txns.max_fee_per_gas
4141
,txns.priority_fee_per_gas

dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/polygon/gas_polygon_fees.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ WITH base_model as (
3434
)
3535
end
3636
) as tx_fee_breakdown_raw
37-
,{{var('ETH_ERC20_ADDRESS')}} as tx_fee_currency
37+
,0x0000000000000000000000000000000000001010 as tx_fee_currency
3838
,blocks.miner AS block_proposer
3939
,txns.max_fee_per_gas
4040
,txns.priority_fee_per_gas

dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/zksync/gas_zksync_fees.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ WITH base_model as (
2828
map()
2929
,map(array['base_fee'], array[(cast(gas_price as uint256) * cast(txns.gas_used as uint256))])
3030
) as tx_fee_breakdown_raw
31-
,{{var('ETH_ERC20_ADDRESS')}} as tx_fee_currency
31+
,0x000000000000000000000000000000000000800a as tx_fee_currency
3232
,blocks.miner AS block_proposer
3333
,txns.max_fee_per_gas
3434
,txns.priority_fee_per_gas

dbt_subprojects/hourly_spellbook/models/_sector/prices/prices_schema.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,38 @@ models:
101101
description: "daily minimum USD price of a token"
102102
- name: price_close
103103
description: "daily closing USD price of a token"
104+
105+
- name: prices_usd_native
106+
description: "Native token prices in USD"
107+
contributors: krishhh
108+
columns:
109+
- name: blockchain
110+
description: "The blockchain name"
111+
tests:
112+
- not_null
113+
- name: contract_address
114+
description: "The token contract address"
115+
tests:
116+
- not_null
117+
- name: symbol
118+
description: "The token symbol"
119+
tests:
120+
- not_null
121+
- name: decimals
122+
description: "The token decimals"
123+
tests:
124+
- not_null
125+
- name: minute
126+
description: "The timestamp of the price"
127+
tests:
128+
- not_null
129+
- name: price
130+
description: "The price in USD"
131+
tests:
132+
- not_null
133+
data_tests:
134+
- dbt_utils.unique_combination_of_columns:
135+
combination_of_columns:
136+
- blockchain
137+
- contract_address
138+
- minute

dbt_subprojects/hourly_spellbook/models/_sector/prices/prices_usd_native.sql

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@
66
-- this is a TEMPORARY spell that should be incorporated in the general prices models.
77
-- more discussion here: https://github.com/duneanalytics/spellbook/issues/6577
88

9-
WITH blockchains as
10-
(
11-
select
12-
evm.blockchain
13-
,evm.native_token_symbol as symbol
14-
,{{var('ETH_ERC20_ADDRESS')}} as contract_address -- 0x00..00
15-
,18 as decimals
16-
from {{source('evms','info')}} evm
17-
inner join {{source('prices_native','tokens')}} p
18-
on native_token_symbol = p.symbol
9+
with native_prices as (
10+
select
11+
*
12+
from
13+
{{ source('prices', 'usd') }}
14+
where
15+
blockchain is null
16+
)
17+
18+
, native_tokens as (
19+
select
20+
*
21+
FROM {{ source('dune', 'blockchains') }}
1922
)
2023

21-
SELECT
22-
b.blockchain
23-
, b.contract_address
24-
, b.decimals
25-
, b.symbol
26-
, p.minute
27-
, p.price
28-
FROM {{ source('prices', 'usd') }} p
29-
INNER JOIN blockchains b
30-
ON b.symbol = p.symbol
31-
and p.blockchain is null
24+
select
25+
t.name as blockchain
26+
, t.token_address as contract_address
27+
, t.token_decimals as decimals
28+
, t.token_symbol as symbol
29+
, p.minute
30+
, p.price
31+
from native_tokens as t
32+
inner join native_prices as p
33+
on t.token_symbol = p.symbol

dbt_subprojects/hourly_spellbook/models/_sector/prices/prices_usd_with_native.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ select
2222
,decimals
2323
,symbol
2424
,price
25-
from {{ref('prices_usd_native')}}
25+
from {{ref('prices_usd_native')}}

dbt_subprojects/tokens/models/prices/abstract/prices_abstract_tokens.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ FROM
2121
('weth-weth', 'WETH', 0x3439153EB7AF838Ad19d56E1571FBD09333C2809, 18)
2222
, ('usdc-usd-coin', 'USDC.e', 0x84a71ccd554cc1b02749b35d22f684cc8ec987e1, 6)
2323
, ('pengu-pudgy-penguins', 'PENGU', 0x9ebe3a824ca958e4b3da772d2065518f009cba62, 18)
24-
, ('eth-ethereum', 'ETH', 0x000000000000000000000000000000000000800a, 18)
2524
) as temp (token_id, symbol, contract_address, decimals)

dbt_subprojects/tokens/models/prices/celo/prices_celo_tokens.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ SELECT
1616
FROM
1717
(
1818
VALUES
19-
('celo-celo', 'celo', 'CELO', 0x471ece3750da237f93b8e339c536989b8978a438, 18),
2019
('cusd-celo-dollar', 'celo', 'cUSD', 0x765de816845861e75a25fca122bb6898b8b1282a, 18),
2120
('ceur-celo-euro', 'celo', 'cEUR', 0xd8763cba276a3738e6de85b4b3bf5fded6d6ca73, 18), --requested add to coinPaprika 2023-08-10
2221
('creal-celo-brazilian-real', 'celo', 'cREAL', 0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787, 18),

dbt_subprojects/tokens/models/prices/mantle/prices_mantle_tokens.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ SELECT
1616
FROM
1717
(
1818
VALUES
19-
('mnt-mantle', 'mantle', 'MNT', 0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000, 18),
2019
('mnt-mantle', 'mantle', 'WMNT', 0x78c1b0c915c4faa5fffa6cabf0219da63d7f4cb8, 18),
2120
('joe-trader-joe', 'mantle', 'JOE', 0x371c7ec6d8039ff7933a2aa28eb827ffe1f52f07, 18),
2221
('usdc-usd-coin', 'mantle', 'USDC', 0x09bc4e0d864854c6afb6eb9a9cdf58ac190d0df9, 6),

dbt_subprojects/tokens/models/prices/polygon/prices_polygon_tokens.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ FROM
2222
('bal-balancer','polygon','BAL',0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3,18),
2323
('dpi-defi-pulse-index', 'polygon', 'DPI', 0x85955046df4668e1dd369d2de9f3aeb98dd2a369, 18),
2424
('eurs-stasis-eurs','polygon','EURS',0xe111178a87a3bff0c8d18decba5798827539ae99,2),
25-
('matic-polygon', 'polygon', 'POL', 0x0000000000000000000000000000000000001010, 18),
2625
('dai-dai', 'polygon', 'DAI', 0x8f3cf7ad23cd3cadbd9735aff958023239c6a063, 18),
2726
('dquick-dragon-quick', 'polygon', 'dQUICK', 0x958d208Cdf087843e9AD98d23823d32E17d723A1, 18),
2827
('usdc-usd-coin', 'polygon', 'USDC', 0x2791bca1f2de4661ed88a30c99a7a9449aa84174, 6),

dbt_subprojects/tokens/models/prices/zksync/prices_zksync_tokens.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ FROM
1717
VALUES
1818

1919
('busd-binance-usd', 'zksync', 'BUSD', 0x2039bb4116b4efc145ec4f0e2ea75012d6c0f181, 18),
20-
('eth-ethereum', 'zksync', 'ETH', 0x000000000000000000000000000000000000800a, 18),
2120
('izi-izumi-finance', 'zksync', 'iZi', 0x16a9494e257703797d747540f01683952547ee5b, 18),
2221
('mav-maverick-token', 'zksync', 'MAV', 0x787c09494ec8bcb24dcaf8659e7d5d69979ee508, 18),
2322
('mute-mute', 'zksync', 'MUTE', 0x0e97c7a0f8b2c9885c8ac9fc6136e829cbc21d42, 18),

0 commit comments

Comments
 (0)