Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniswap block month partitioning #4119

Merged
merged 6 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions models/uniswap/arbitrum/uniswap_arbitrum_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ models:
- &blockchain
name: blockchain
description: "Blockchain which the DEX is deployed"
- &project
- &project
name: project
description: "Project name of the DEX"
description: "Project name of the DEX"
- &version
name: version
description: "Version of the contract built and deployed by the DEX project"
- &block_month
name: block_month
description: "UTC event block month of each DEX trade"
- &block_date
name: block_date
description: "UTC event block date of each DEX trade"
Expand Down Expand Up @@ -105,7 +108,8 @@ models:
columns:
- *blockchain
- *project
- *version
- *version
- *block_month
- *block_date
- *block_time
- *token_bought_symbol
Expand Down
7 changes: 4 additions & 3 deletions models/uniswap/arbitrum/uniswap_arbitrum_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}}

{% set uniswap_models = [
'uniswap_v3_arbitrum_trades'
ref('uniswap_v3_arbitrum_trades')
] %}


Expand All @@ -15,6 +15,7 @@ FROM (
blockchain,
project,
version,
block_month,
block_date,
block_time,
token_bought_symbol,
Expand All @@ -33,9 +34,9 @@ FROM (
tx_hash,
tx_from,
tx_to,

evt_index
FROM {{ ref(dex_model) }}
FROM {{ dex_model }}
{% if not loop.last %}
UNION ALL
{% endif %}
Expand Down
15 changes: 8 additions & 7 deletions models/uniswap/arbitrum/uniswap_v3_arbitrum_trades.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(tags=['dunesql'],
schema = 'uniswap_v3_arbitrum',
alias = alias('trades'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand Down Expand Up @@ -29,11 +29,11 @@ WITH dexs AS
,CASE WHEN amount0 < INT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address
,t.contract_address as project_contract_address
,t.evt_tx_hash AS tx_hash

,t.evt_index
FROM
{{ source('uniswap_v3_arbitrum', 'Pair_evt_Swap') }} t
INNER JOIN
INNER JOIN
{{ source('uniswap_v3_arbitrum', 'Factory_evt_PoolCreated') }} f
ON f.pool = t.contract_address
{% if is_incremental() %}
Expand All @@ -44,7 +44,8 @@ SELECT DISTINCT
'arbitrum' AS blockchain
,'uniswap' AS project
,'3' AS version
,TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,dexs.block_time
,erc20a.symbol AS token_bought_symbol
,erc20b.symbol AS token_sold_symbol
Expand All @@ -69,10 +70,10 @@ SELECT DISTINCT
,dexs.tx_hash
,tx."from" AS tx_from
,tx.to AS tx_to

,dexs.evt_index
FROM dexs
INNER JOIN
INNER JOIN
{{ source('arbitrum', 'transactions') }} tx
ON tx.hash = dexs.tx_hash
{% if not is_incremental() %}
Expand All @@ -82,7 +83,7 @@ INNER JOIN
AND tx.block_time >= date_trunc('day', now() - interval '7' day)
{% endif %}
LEFT JOIN {{ ref('tokens_erc20') }} erc20a
ON erc20a.contract_address = dexs.token_bought_address
ON erc20a.contract_address = dexs.token_bought_address
AND erc20a.blockchain = 'arbitrum'
LEFT JOIN {{ ref('tokens_erc20') }} erc20b
ON erc20b.contract_address = dexs.token_sold_address
Expand Down
10 changes: 7 additions & 3 deletions models/uniswap/bnb/uniswap_bnb_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ models:
- &blockchain
name: blockchain
description: "Blockchain which the DEX is deployed"
- &project
- &project
name: project
description: "Project name of the DEX"
description: "Project name of the DEX"
- &version
name: version
description: "Version of the contract built and deployed by the DEX project"
- &block_month
name: block_date
description: "UTC event block month of each DEX trade"
- &block_date
name: block_date
description: "UTC event block date of each DEX trade"
Expand Down Expand Up @@ -105,7 +108,8 @@ models:
columns:
- *blockchain
- *project
- *version
- *version
- *block_month
- *block_date
- *block_time
- *token_bought_symbol
Expand Down
1 change: 1 addition & 0 deletions models/uniswap/bnb/uniswap_bnb_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ FROM (
blockchain,
project,
version,
block_month,
block_date,
block_time,
token_bought_symbol,
Expand Down
15 changes: 8 additions & 7 deletions models/uniswap/bnb/uniswap_v3_bnb_trades.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(tags=['dunesql'],
schema = 'uniswap_v3_bnb',
alias = alias('trades'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand Down Expand Up @@ -29,11 +29,11 @@ WITH dexs AS
,CASE WHEN amount0 < INT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address
,t.contract_address as project_contract_address
,t.evt_tx_hash AS tx_hash

,t.evt_index
FROM
{{ source('uniswap_v3_bnb', 'Pair_evt_Swap') }} t
INNER JOIN
INNER JOIN
{{ source('uniswap_v3_bnb', 'Factory_evt_PoolCreated') }} f
ON f.pool = t.contract_address
{% if is_incremental() %}
Expand All @@ -44,7 +44,8 @@ SELECT
'bnb' AS blockchain
,'uniswap' AS project
,'3' AS version
,TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,dexs.block_time
,erc20a.symbol AS token_bought_symbol
,erc20b.symbol AS token_sold_symbol
Expand All @@ -69,10 +70,10 @@ SELECT
,dexs.tx_hash
,tx."from" AS tx_from
,tx.to AS tx_to

,dexs.evt_index
FROM dexs
INNER JOIN
INNER JOIN
{{ source('bnb', 'transactions') }} tx
ON tx.hash = dexs.tx_hash
{% if not is_incremental() %}
Expand All @@ -82,7 +83,7 @@ INNER JOIN
AND tx.block_time >= date_trunc('day', now() - interval '7' day)
{% endif %}
LEFT JOIN {{ ref('tokens_erc20') }} erc20a
ON erc20a.contract_address = dexs.token_bought_address
ON erc20a.contract_address = dexs.token_bought_address
AND erc20a.blockchain = 'bnb'
LEFT JOIN {{ ref('tokens_erc20') }} erc20b
ON erc20b.contract_address = dexs.token_sold_address
Expand Down
6 changes: 6 additions & 0 deletions models/uniswap/ethereum/uniswap_ethereum_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ models:
- &version
name: version
description: "Version of the contract built and deployed by the DEX project"
- &block_month
name: block_month
description: "UTC event block month of each DEX trade"
- &block_date
name: block_date
description: "UTC event block date of each DEX trade"
Expand Down Expand Up @@ -119,6 +122,7 @@ models:
- *blockchain
- *project
- *version
- *block_month
- *block_date
- *block_time
- *token_bought_symbol
Expand Down Expand Up @@ -166,6 +170,7 @@ models:
- *blockchain
- *project
- *version
- *block_month
- *block_date
- *block_time
- *token_bought_symbol
Expand Down Expand Up @@ -200,6 +205,7 @@ models:
- *blockchain
- *project
- *version
- *block_month
- *block_date
- *block_time
- *token_bought_symbol
Expand Down
10 changes: 5 additions & 5 deletions models/uniswap/ethereum/uniswap_ethereum_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
}}

{% set uniswap_models = [
'uniswap_v1_ethereum_trades'
,'uniswap_v2_ethereum_trades'
,'uniswap_v3_ethereum_trades'
ref('uniswap_v1_ethereum_trades')
,ref('uniswap_v2_ethereum_trades')
,ref('uniswap_v3_ethereum_trades')
] %}


Expand All @@ -17,6 +17,7 @@ FROM (
blockchain,
project,
version,
block_month,
block_date,
block_time,
token_bought_symbol,
Expand All @@ -35,9 +36,8 @@ FROM (
tx_hash,
tx_from,
tx_to,

evt_index
FROM {{ ref(dex_model) }}
FROM {{ dex_model }}
{% if not loop.last %}
UNION ALL
{% endif %}
Expand Down
11 changes: 6 additions & 5 deletions models/uniswap/ethereum/uniswap_v1_ethereum_trades.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(tags=['dunesql'],
schema = 'uniswap_v1_ethereum',
alias = alias('trades'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand Down Expand Up @@ -30,7 +30,7 @@ WITH dexs AS
,{{weth_address}} AS token_sold_address --Using WETH for easier joining with USD price table
,t.contract_address AS project_contract_address
,t.evt_tx_hash AS tx_hash

,t.evt_index
FROM
{{ source('uniswap_ethereum', 'Exchange_evt_TokenPurchase') }} t
Expand All @@ -54,7 +54,7 @@ WITH dexs AS
,f.token AS token_sold_address
,t.contract_address AS project_contract_address
,t.evt_tx_hash AS tx_hash

,t.evt_index
FROM
{{ source('uniswap_ethereum', 'Exchange_evt_EthPurchase') }} t
Expand All @@ -68,7 +68,8 @@ SELECT
'ethereum' AS blockchain
,'uniswap' AS project
,'1' AS version
,TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,dexs.block_time
,erc20a.symbol AS token_bought_symbol
,erc20b.symbol AS token_sold_symbol
Expand All @@ -93,7 +94,7 @@ SELECT
,dexs.tx_hash
,tx."from" AS tx_from
,tx.to AS tx_to

,dexs.evt_index
FROM dexs
INNER JOIN {{ source('ethereum', 'transactions') }} tx
Expand Down
9 changes: 5 additions & 4 deletions models/uniswap/ethereum/uniswap_v2_ethereum_trades.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(tags=['dunesql'],
schema = 'uniswap_v2_ethereum',
alias = alias('trades'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand Down Expand Up @@ -32,7 +32,7 @@ WITH dexs AS
,CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address
,t.contract_address as project_contract_address
,t.evt_tx_hash AS tx_hash

,t.evt_index
FROM
{{ source('uniswap_v2_ethereum', 'Pair_evt_Swap') }} t
Expand All @@ -50,7 +50,8 @@ SELECT
'ethereum' AS blockchain
,'uniswap' AS project
,'2' AS version
,TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,dexs.block_time
,erc20a.symbol AS token_bought_symbol
,erc20b.symbol AS token_sold_symbol
Expand All @@ -75,7 +76,7 @@ SELECT
,dexs.tx_hash
,tx."from" AS tx_from
,tx.to AS tx_to

,dexs.evt_index
FROM dexs
INNER JOIN {{ source('ethereum', 'transactions') }} tx
Expand Down
9 changes: 5 additions & 4 deletions models/uniswap/ethereum/uniswap_v3_ethereum_trades.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(tags=['dunesql'],
schema = 'uniswap_v3_ethereum',
alias = alias('trades'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand Down Expand Up @@ -30,7 +30,7 @@ WITH dexs AS
,t.contract_address as project_contract_address
,f.fee
,t.evt_tx_hash AS tx_hash

,t.evt_index
FROM
{{ source('uniswap_v3_ethereum', 'Pair_evt_Swap') }} t
Expand All @@ -44,7 +44,8 @@ SELECT
'ethereum' AS blockchain
,'uniswap' AS project
,'3' AS version
,TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date
,dexs.block_time
,erc20a.symbol AS token_bought_symbol
,erc20b.symbol AS token_sold_symbol
Expand All @@ -70,7 +71,7 @@ SELECT
,dexs.tx_hash
,tx."from" AS tx_from
,tx.to AS tx_to

,dexs.evt_index
FROM dexs
INNER JOIN {{ source('ethereum', 'transactions') }} tx
Expand Down
Loading