Skip to content

Commit

Permalink
Merge branch 'duneanalytics:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpartida authored Aug 7, 2024
2 parents f11a6c6 + e742a6f commit 5ea0fd7
Show file tree
Hide file tree
Showing 237 changed files with 2,276 additions and 133 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.DS_Store
.vscode
manifest.json
macros/dune/create_views_of_dependencies.sql
macros/dune/alter_table_locations.sql
dbt_macros/dune/create_views_of_dependencies.sql
dbt_macros/dune/alter_table_locations.sql
scripts/integration_test/test_diffs_tokens/*
.vs

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dbt_subprojects/daily_spellbook/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vars:
model-paths: ["models", "../../sources"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros", "../../macros"]
macro-paths: ["macros", "../../dbt_macros"]

target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Adoption of `arrakis_` for macro names.

### Macro Usage Example

Below is an example of how to use the [`arrakis_compatible_v2_trades` macro](/macros/models/_sector/alm/arrakis_compatible_trades.sql) macro within our project. This macro is designed to standardize the trades data for projects compatible with Arrakis V2 on various blockchains.
Below is an example of how to use the [`arrakis_compatible_v2_trades` macro](/dbt_macros/models/_sector/alm/arrakis_compatible_trades.sql) macro within our project. This macro is designed to standardize the trades data for projects compatible with Arrakis V2 on various blockchains.

```sql
{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ version: 2
models:
- name: gas_fees
meta:
blockchain: ethereum, bnb, avalanche_c, optimism, arbitrum, zksync, zora, base, scroll
blockchain: ethereum, bnb, avalanche_c, optimism, arbitrum, zksync, zora, base, scroll, mantle
sector: gas
contributors: soispoke
contributors: soispoke, ilemi, 0xRob, jeff-dude
config:
tags: ['ethereum', 'bnb', 'avalanche_c', 'optimism', 'arbitrum','zksync','zora','scroll','gas', 'fees']
tags: ['ethereum', 'bnb', 'avalanche_c', 'optimism', 'arbitrum','zksync','zora','scroll','mantle','gas','fees']
description: >
Gas Fees across chains
columns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ SELECT
blocks.difficulty,
txns.type AS transaction_type
FROM {{ source('ethereum', 'transactions') }} txns
INNER JOIN {{ source('ethereum', 'blocks') }} blocks ON txns.block_number = blocks.number
LEFT JOIN {{ source('ethereum', 'blobs_submissions') }} blob ON txns.hash = blob.tx_hash
LEFT JOIN {{ source('prices', 'usd') }} p ON p.minute = date_trunc('minute', txns.block_time)
AND p.blockchain = 'ethereum'
AND p.symbol = 'WETH'
{% if is_incremental() %}
AND {{ incremental_predicate('p.minute') }}
WHERE {{ incremental_predicate('txns.block_time') }}
INNER JOIN {{ source('ethereum', 'blocks') }} blocks
ON txns.block_number = blocks.number
{% if is_incremental() %}
AND {{ incremental_predicate('blocks.time') }}
{% endif %}
LEFT JOIN {{ source('ethereum', 'blobs_submissions') }} blob
ON txns.hash = blob.tx_hash
{% if is_incremental() %}
AND {{ incremental_predicate('blob.block_time') }}
{% endif %}
LEFT JOIN {{ source('prices', 'usd') }} p
ON p.minute = date_trunc('minute', txns.block_time)
AND p.blockchain = 'ethereum'
AND p.symbol = 'WETH'
{% if is_incremental() %}
AND {{ incremental_predicate('p.minute') }}
{% endif %}
{% if is_incremental() %}
WHERE {{ incremental_predicate('txns.block_time') }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
{{ config(
schema = 'gas',
alias = 'fees',
post_hook='{{ expose_spells(\'["ethereum","bnb","avalanche_c","optimism","arbitrum","zksync","zora","base","scroll"]\',
post_hook='{{ expose_spells(\'["ethereum","bnb","avalanche_c","optimism","arbitrum","zksync","zora","base","scroll","mantle"]\',
"sector",
"gas",
\'["soispoke"]\') }}'
\'["soispoke", "ilemi", "0xRob", "jeff-dude"]\') }}'
)
}}

{% set gas_fees_models = [
'gas_ethereum_fees',
'gas_bnb_fees',
'gas_avalanche_c_fees',
'gas_optimism_fees',
'gas_arbitrum_fees',
'gas_zksync_fees',
'gas_zora_fees',
'gas_base_fees',
'gas_scroll_fees'
'gas_ethereum_fees',
'gas_bnb_fees',
'gas_avalanche_c_fees',
'gas_optimism_fees',
'gas_arbitrum_fees',
'gas_zksync_fees',
'gas_zora_fees',
'gas_base_fees',
'gas_scroll_fees'
] %}

--remove mantle for now:
--'gas_mantle_fees'

SELECT *
FROM (
{% for gas_model in gas_fees_models %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: 2

models:
- name: gas_mantle_fees
meta:
blockchain: mantle
sector: gas
contributors: soispoke, ilemi
config:
tags: ['mantle', 'gas', 'fees']
description: >
Gas Fees on mantle rollup Layer 2
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_number
- tx_hash
columns:
- &blockchain
name: blockchain
description: "Blockchain name"
- &block_time
name: block_time
description: "Timestamp for block event time in UTC"
- &block_number
name: block_number
description: "Block number"
- &tx_hash
name: tx_hash
description: "Primary key of the transaction"
- &tx_sender
name: tx_sender
description: "Initiated the transaction"
- &tx_receiver
name: tx_receiver
description: "Received the transaction"
- &native_token_symbol
name: native_token_symbol
description: "Symbol of native token (ETH) for the Ethereum Blockchain"
- &tx_amount_native
name: tx_amount_native
description: "Amount of native tokens (ETH) transferred from sender to recipient"
- &tx_amount_usd
name: tx_amount_usd
description: "Amount of $USD transferred from sender to recipient"
- &tx_fee_native
name: tx_fee_native
description: "Total amount of native tokens (ETH) paid in gas fees"
- &tx_fee_usd
name: tx_fee_usd
description: "Total amount of $USD paid in gas fees"
- &burned_native
name: burned_native
description: "Total amount of native tokens (ETH) burned for this transaction, not applicable to L2 because transactions only indirectly burn gas on L1"
- &burned_usd
name: burned_usd
description: "Total amount of $USD burned for this transaction, not applicable to L2 because transactions only indirectly burn gas on L1"
- &validator
name: validator
description: "Address of blockchain validator for this transaction within the block, also referred to as miner before the Merge when Ethereum's consensus mechanism was PoW"
- &gas_price_gwei
name: gas_price_gwei
description: "Gas price (per gas unit) denoted in gwei"
- &gas_price_usd
name: gas_price_usd
description: "Gas price (per gas unit) denoted in $USD"
- &gas_used
name: gas_used
description: "Amount of L2 gas units consumed by the transaction"
- &gas_limit
name: gas_limit
description: "Maximum amount of gas units that can be consumed by the transaction on zksync L2"
- &gas_usage_percent
name: gas_usage_percent
description: "Percentage of Gas Used relative to the gas limit on zksync L2"
- &type
name: type
description: "Legacy (Pre Typed-Transactions), AccessList (EIP-2930), DynamicFee (EIP-1559), EIP-712, or Priority (L1 -> L2 Transactions)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{ config(
tags = ['prod_exclude'],
schema = 'gas_mantle',
alias = 'fees',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy='merge',
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
unique_key = ['tx_hash','block_number']
)
}}

SELECT
'mantle' as blockchain,
date_trunc('day', block_time) AS block_date,
CAST(date_trunc('month', block_time) AS DATE) AS block_month,
block_number,
block_time,
txns.hash AS tx_hash,
txns."from" AS tx_sender,
txns.to AS tx_receiver,
'ETH' as native_token_symbol,
value/1e18 AS tx_amount_native,
value/1e18 * p.price AS tx_amount_usd,
(l1_fee/1e18 + ((txns.gas_used/1e18) * txns.gas_price)) as tx_fee_native,
(l1_fee/1e18 + ((txns.gas_used/1e18) * txns.gas_price)) * p.price AS tx_fee_usd,
cast(NULL as double) AS burned_native, -- Not applicable for L2s
cast(NULL as double) AS burned_usd, -- Not applicable for L2s
cast(NULL as VARBINARY) as validator, -- Not applicable for L2s
txns.gas_price/1e9 as gas_price_gwei,
txns.gas_price/1e18 * p.price as gas_price_usd,
txns.gas_used as gas_used,
txns.gas_limit as gas_limit,
CASE
WHEN txns.gas_limit = 0 THEN NULL
WHEN txns.gas_limit != 0 THEN txns.gas_used / txns.gas_limit * 100
END AS gas_usage_percent,
type as transaction_type
FROM {{ source('mantle','transactions') }} txns
INNER JOIN {{ source('mantle','blocks') }} blocks
ON blocks.number = txns.block_number
{% if is_incremental() %}
AND {{ incremental_predicate('blocks.time') }}
{% endif %}
LEFT JOIN {{ source('prices','usd') }} p
ON p.minute = date_trunc('minute', txns.block_time)
AND p.blockchain = 'mantle'
AND p.symbol = 'WETH'
{% if is_incremental() %}
AND {{ incremental_predicate('p.minute') }}
{% endif %}
{% if is_incremental() %}
WHERE {{ incremental_predicate('txns.block_time') }}
{% endif %}
2 changes: 1 addition & 1 deletion dbt_subprojects/daily_spellbook/models/contracts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Contract Mapping

Table models are defined in [`macros/models/_sector/contracts`](/macros/models/_sector/contracts)
Table models are defined in [`macros/models/_sector/contracts`](../macros/models/_sector/contracts)

This repository contains all the source code for `contracts.contract_mapping` that you can use to join contract addresses on each chain to pull our mapped project names in the `contract_project` field.

Expand Down
2 changes: 1 addition & 1 deletion dbt_subprojects/daily_spellbook/models/evms/evms_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FROM (
, (1088, 'metis_andromeda', 'Metis Andromeda', NULL, NULL, NULL, NULL, 'https://andromeda-explorer.metis.io/', timestamp '2021-11-18 22:19', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum')
, (5000, 'mantle', 'Mantle', 'Layer 2', 'Optimistic Rollup', 'MNT', NULL, 'https://explorer.mantle.xyz/', timestamp '2023-07-02 18:21', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum')
, (59144, 'linea', 'Linea', 'Layer 2', 'ZK Rollup', 'ETH', 0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, 'https://lineascan.build/', timestamp '2023-07-06 13:15', NULL, 'Ethereum Blobs', 'Ethereum')
, (42170, 'arbitrum_nova', 'Arbitrum Nova', 'Layer 2', 'Optimistic Rollup', 'ETH', NULL, 'https://nova-explorer.arbitrum.io/', timestamp '2022-06-25 04:01', 'Arbitrum', 'Ethereum', 'Ethereum')
, (42170, 'nova', 'Arbitrum Nova', 'Layer 2', 'Optimistic Rollup', 'ETH', NULL, 'https://nova-explorer.arbitrum.io/', timestamp '2022-06-25 04:01', 'Arbitrum', 'Ethereum', 'Ethereum')
, (288, 'boba', 'Boba Network', 'Layer 2', 'Optimistic Rollup', 'ETH', NULL, 'https://bobascan.com/', timestamp '2021-10-28 05:03', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum')
, (7700, 'canto', 'Canto', 'Layer 2', NULL, 'ETH', NULL, 'https://evm.explorer.canto.io/', timestamp '2022-07-26 19:27', NULL, 'Ethereum', 'Ethereum')
, (420, 'optimism_goerli', 'Optimism Goerli', 'Testnet', 'Optimistic Rollup', 'GTH', 0x4200000000000000000000000000000000000006, 'https://optimism-goerli.blockscout.com/', timestamp '2022-06-09 16:55', 'OP Stack', 'Goerli', 'Goerli')
Expand Down
2 changes: 1 addition & 1 deletion dbt_subprojects/dex/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ vars:
model-paths: ["models", "../../sources"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros", "../../macros"]
macro-paths: ["macros", "../../dbt_macros"]

target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ results_usd AS (
THEN varbinary_substring(taker_indicator_string, 18,20) ELSE taker END AS taker,
maker,
tag,
zid,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
,ref('zeroex_optimism_api_fills_deduped')
,ref('zeroex_polygon_api_fills_deduped')
,ref('zeroex_bnb_api_fills_deduped')
,ref('zeroex_ethereum_settler_trades')
] %}

{% set settler_models = [
ref('zeroex_ethereum_settler_trades')
,ref('zeroex_base_settler_trades')
,ref('zeroex_polygon_settler_trades')
,ref('zeroex_optimism_settler_trades')
Expand Down Expand Up @@ -56,6 +59,46 @@ FROM (
,tx_to
,trace_address
,evt_index
,affiliate_address
,null as zid
FROM {{ model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)

UNION ALL

SELECT *
FROM (
{% for model in settler_models %}
SELECT
blockchain
,version
,block_month
,block_date
,block_time
,maker_symbol
,taker_symbol
,token_pair
,maker_token_amount
,taker_token_amount
,maker_token_amount_raw
,taker_token_amount_raw
,volume_usd
,maker_token
,taker_token
,taker
,maker
,contract_address
,tx_hash
,tx_from
,tx_to
,trace_address
,evt_index
,tag as affiliate_address
,zid
FROM {{ model }}
{% if not loop.last %}
UNION ALL
Expand Down
Loading

0 comments on commit 5ea0fd7

Please sign in to comment.