From 99b0690c55406648549cd82ef0199b5c00abe49c Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 17:43:50 +0200 Subject: [PATCH 01/86] recover working version of mass decoding --- .../uniswap_v2_factory_mass_decoding.sql | 55 +++++++++++++++ .../uniswap_v2_pool_mass_decoding.sql | 70 +++++++++++++++++++ .../in-flight-decoding/uniswap_v2_trades.sql | 60 ++++++++++++++++ .../ethereum/decoded-in-flight/_schema.yml | 51 ++++++++++++++ .../uniswap_v2_factory_decoding_ethereum.sql | 17 +++++ .../uniswap_v2_fork_mapping_ethereum.sql | 51 ++++++++++++++ .../uniswap_v2_forks_base_trades.sql | 21 ++++++ .../uniswap_v2_pool_decoding_ethereum.sql | 16 +++++ 8 files changed, 341 insertions(+) create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql new file mode 100644 index 00000000000..980272728be --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -0,0 +1,55 @@ +{% macro uniswap_v2_factory_mass_decoding( + logs = null + ) +%} + + +SELECT +token0 +,token1 +,pair +,block_time +,block_number +FROM TABLE ( + decode_evm_event ( + abi => '{ + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "pair", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "PairCreated", + "type": "event" + }', + input => TABLE ( + SELECT l.* + FROM {{logs}} l + WHERE topic0 = 0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9 + and block_date > now() - interval '90' day -- take out limit if you want to use in prod + ) + ) + ) + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql new file mode 100644 index 00000000000..8a1f1261dd6 --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql @@ -0,0 +1,70 @@ +{% macro uniswap_v2_pool_mass_decoding( + logs = null + ) +%} + + +SELECT +block_time +,block_number +,to +,contract_address +,amount0Out +,amount0In +,amount1Out +,amount1In +FROM TABLE ( + decode_evm_event ( + abi => '{ + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Swap", + "type": "event" + }', + input => TABLE ( + SELECT l.* + FROM {{logs}} l + WHERE topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 + and block_date > now() - interval '90' day -- take out limit if you want to use in prod + ) + ) + ) + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql new file mode 100644 index 00000000000..9f20ff41e2f --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -0,0 +1,60 @@ +{% macro uniswap_v2_forks_trades( + blockchain = null + , project = null + , version = null + , Pair_evt_Swap = null + , Factory_evt_PairCreated = null + , pair_column_name = 'pair' + , Fork_Mapping = null + ) +%} +WITH dexs AS +( + SELECT + block_number + block_time + , t.to AS taker + , t.contract_address AS maker + , CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw + , CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN amount1In ELSE amount0In END AS token_sold_amount_raw + , CASE WHEN amount0Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_bought_address + , 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 + , tx_hash + , t.index AS evt_index + , m.project_name + FROM + {{ Pair_evt_Swap }} t + INNER JOIN + {{ Factory_evt_PairCreated }} f + ON f.{{ pair_column_name }} = t.contract_address + INNER JOIN + {{Fork_Mapping}} m + ON m.factory_address = f.contract_address + {% if is_incremental() %} + WHERE + {{ incremental_predicate('t.block_time') }} + {% endif %} +) + +SELECT + '{{ blockchain }}' AS blockchain + , project_name AS project + , '{{ version }}' AS version + , 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 + , dexs.block_number + , dexs.token_bought_amount_raw + , dexs.token_sold_amount_raw + , dexs.token_bought_address + , dexs.token_sold_address + , dexs.taker + , dexs.maker + , dexs.project_contract_address + , dexs.tx_hash + , dexs.evt_index +FROM + dexs + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml new file mode 100644 index 00000000000..ddbefd7abb7 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml @@ -0,0 +1,51 @@ +version: 2 + +models: + - name: uniswap_v2_factory_decoding_ethereum + description: > + mass decoding of all forks of uniswap v2 factory contract on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + + - name: uniswap_v2_pool_decoding_ethereum + description: > + mass decoding of all forks of uniswap v2 pool contracts on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + + - name: uniswap_v2_fork_mapping_ethereum + description: > + mapping of all forks of uniswap v2 factory contract on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - factory_address + columns: + - name: factory_address + description: "address of the factory contract" + - name: project_name + description: "name of the project associated with the factory" + + - name: uniswap_v2_forks_base_trades + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2', 'forks' ] + description: "base trades for all forks of uniswap v2 on ethereum" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql new file mode 100644 index 00000000000..eadc2fee430 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql @@ -0,0 +1,17 @@ +{{ config( + + schema = 'mass_decoding_ethereum', + alias = 'uniswap_v2_factory_evt_PairCreated', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_factory_mass_decoding( + logs = source('ethereum', 'logs') +)}} + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql new file mode 100644 index 00000000000..e5d1c80b196 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql @@ -0,0 +1,51 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v2_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') + , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') + , (0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73, 'PancakeSwap') + , (0x9Ad32bf5DaFe152Cbe027398219611DB4E8753B3, 'NomiSwap') + , (0x98813bD470A3BA8Da3D16488c58374e8dBc2FF22, 'DigiSwap') + , (0x5B9f88Ee10413e764BEFACa083fB290c4f25F720, 'Broccoli') + , (0x858E3312ed3A876947EA49d572A7C42DE08af7EE, 'BiSwap') + , (0x01bF7C66c6BD861915CdaaE475042d3c4BaE16A7, 'BakerySwap') + , (0x0841BD0B734E4F5853f0dD8d7Ea041c241fb0Da6, 'ApeSwap') + , (0x4d05D0045df5562D6D52937e93De6Ec1FECDAd21, 'SafeSwap') + , (0xf1B735685416253A8F7c8a6686970cA2B0cceCce, 'CoSwap') + , (0x8BA1a4C24DE655136DEd68410e222cCA80d43444, 'Sphynx') + , (0x1e895bFe59E3A5103e8B7dA3897d1F2391476f3c, 'DooarSwap') + , (0x31aFfd875e9f68cd6Cd12Cee8943566c9A4bBA13, 'Elk') + , (0x1A04Afe9778f95829017741bF46C9524B91433fB, 'Orbital') + , (0x9A272d734c5a0d7d84E0a892e891a553e8066dce, 'FstSwap') + , (0xD04A80baeeF12fD7b1D1ee6b1f8ad354f81bc4d7, 'W3Swap') + , (0xCe8fd65646F2a2a897755A1188C04aCe94D2B8D0, 'BSCswap') + , (0x8b6Ca4B3E08c9f80209e66436187088C99C9C2AC, 'BSCswap') + , (0xdd538E4Fd1b69B7863E1F741213276A6Cf1EfB3B, 'CheeseSwap') + , (0x3CD1C46068dAEa5Ebb0d3f55F6915B10648062B8, 'Mdex') + , (0x86407bEa2078ea5f5EB5A52B2caA963bC1F889Da, 'BabySwap') + , (0xBCfCcbde45cE874adCB698cC183deBcF17952812, 'PancakeSwap') + , (0x59DA12BDc470C8e85cA26661Ee3DCD9B85247C88, 'FastSwap') + , (0x79C342FddBBF376cA6B4EFAc7aaA457D6063F8Cb, 'Winery') + , (0xB42E3FE71b7E0673335b3331B3e1053BD9822570, 'WaultSwap') + , (0x3e708FdbE3ADA63fc94F8F61811196f1302137AD, 'CafeSwap') + , (0x4E66Fda7820c53C1a2F601F84918C375205Eac3E, 'Twindex') + , (0xC7a506ab3ac668EAb6bF9eCf971433D6CFeF05D9, 'Alita') + , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') + , (0x03407772f5ebfb9b10df007a2dd6fff4ede47b53 ,'capitaldex') + , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') + , (0xF028F723ED1D0fE01cC59973C49298AA95c57472, 'SashimiSwap') + , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'BTswap') + , (0x35113a300ca0D7621374890ABFEAC30E88f214b1, 'SaitaSwap') + , (0xA40ec8A93293A3179D4b544239916C1B68cB47B6, 'SunflowerSwap') + , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') + +) AS t (factory_address, project) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql new file mode 100644 index 00000000000..a37903c6707 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql @@ -0,0 +1,21 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v2_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_forks_trades( + blockchain = ethereum + , version = 'unknown' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') + , pair_column_name = 'pair' + , Fork_Mapping = ref('uniswap_v2_fork_mapping_ethereum') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql new file mode 100644 index 00000000000..d91c01a77f7 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v2_pool_evt_Swap', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_pool_mass_decoding( + logs = source('ethereum', 'logs') +)}} \ No newline at end of file From f7f34ca237569dde7d637d9eebd6007c685943e3 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 17:54:33 +0200 Subject: [PATCH 02/86] fix run errors --- .../in-flight-decoding/uniswap_v2_factory_mass_decoding.sql | 1 + .../in-flight-decoding/uniswap_v2_pool_mass_decoding.sql | 1 + .../decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql | 2 +- .../decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql | 2 +- .../decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql index 980272728be..b8204d52fc5 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -10,6 +10,7 @@ token0 ,pair ,block_time ,block_number +,block_date FROM TABLE ( decode_evm_event ( abi => '{ diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql index 8a1f1261dd6..51293325de4 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql @@ -13,6 +13,7 @@ block_time ,amount0In ,amount1Out ,amount1In +,block_date FROM TABLE ( decode_evm_event ( abi => '{ diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql index eadc2fee430..c45df19b093 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql @@ -2,7 +2,7 @@ schema = 'mass_decoding_ethereum', alias = 'uniswap_v2_factory_evt_PairCreated', - partition_by = ['block_month'], + partition_by = ['block_date'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql index e5d1c80b196..9b2438ea40a 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql @@ -48,4 +48,4 @@ FROM , (0xA40ec8A93293A3179D4b544239916C1B68cB47B6, 'SunflowerSwap') , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') -) AS t (factory_address, project) \ No newline at end of file +) AS t (factory_address, project_name) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql index d91c01a77f7..7d6be994c90 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql @@ -2,7 +2,7 @@ schema = 'dex_mass_decoding_ethereum', alias = 'uniswap_v2_pool_evt_Swap', - partition_by = ['block_month'], + partition_by = ['block_date'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', From 9ce028dd73973c2b5e3dcc7b8f00fa46efa8a5c3 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 18:00:32 +0200 Subject: [PATCH 03/86] fix run error --- .../in-flight-decoding/uniswap_v2_factory_mass_decoding.sql | 1 + .../dex/models/trades/ethereum/dex_ethereum_base_trades.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql index b8204d52fc5..5526e80b83a 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -8,6 +8,7 @@ SELECT token0 ,token1 ,pair +,contract_address ,block_time ,block_number ,block_date diff --git a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql index 45260e99033..800e4126e93 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql @@ -37,6 +37,7 @@ , ref('curvefi_ethereum_base_trades') , ref('solidly_v3_ethereum_base_trades') , ref('swaap_v2_ethereum_base_trades') + , ref('uniswap_v2_ethereum_base_trades') ] %} WITH base_union AS ( From 3fa37a071dded188bc84a88c6214f2989cb6e871 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 18:24:20 +0200 Subject: [PATCH 04/86] fix run error --- .../_project/in-flight-decoding/uniswap_v2_trades.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 9f20ff41e2f..ff695d8dc30 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -11,8 +11,8 @@ WITH dexs AS ( SELECT - block_number - block_time + t.block_number + t.block_time , t.to AS taker , t.contract_address AS maker , CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw @@ -20,7 +20,7 @@ WITH dexs AS , CASE WHEN amount0Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_bought_address , 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 - , tx_hash + , t.tx_hash , t.index AS evt_index , m.project_name FROM From c0337c40eb0b4d1f2a3a26bc7d1e9dcbe1ac8a0d Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 18:30:30 +0200 Subject: [PATCH 05/86] add comma --- .../models/_project/in-flight-decoding/uniswap_v2_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index ff695d8dc30..17f434712cf 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -12,7 +12,7 @@ WITH dexs AS ( SELECT t.block_number - t.block_time + , t.block_time , t.to AS taker , t.contract_address AS maker , CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw From 0a0d53c7c09581a9b59e9965cd861eb93ffa8785 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 18:39:50 +0200 Subject: [PATCH 06/86] add missing column from upstream --- .../in-flight-decoding/uniswap_v2_factory_mass_decoding.sql | 2 ++ .../in-flight-decoding/uniswap_v2_pool_mass_decoding.sql | 2 ++ .../dex/models/trades/ethereum/dex_ethereum_base_trades.sql | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql index 5526e80b83a..8fd1fa36f8e 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -12,6 +12,8 @@ token0 ,block_time ,block_number ,block_date +,tx_hash +,index FROM TABLE ( decode_evm_event ( abi => '{ diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql index 51293325de4..dc1f104583b 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql @@ -14,6 +14,8 @@ block_time ,amount1Out ,amount1In ,block_date +,tx_hash +,index FROM TABLE ( decode_evm_event ( abi => '{ diff --git a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql index 800e4126e93..45260e99033 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql @@ -37,7 +37,6 @@ , ref('curvefi_ethereum_base_trades') , ref('solidly_v3_ethereum_base_trades') , ref('swaap_v2_ethereum_base_trades') - , ref('uniswap_v2_ethereum_base_trades') ] %} WITH base_union AS ( From 23a2a4fc10a33e68fee6b68281159c010055b86f Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 18:45:00 +0200 Subject: [PATCH 07/86] fix test columns --- .../dex/models/trades/ethereum/decoded-in-flight/_schema.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml index ddbefd7abb7..8ab1be1810b 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml @@ -8,7 +8,7 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - tx_hash - - evt_index + - index - name: uniswap_v2_pool_decoding_ethereum description: > @@ -17,7 +17,7 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - tx_hash - - evt_index + - index - name: uniswap_v2_fork_mapping_ethereum description: > From 936db77e44fd4b05aff7cdb24dab53b1f0c5dd0f Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 19:51:47 +0200 Subject: [PATCH 08/86] fix some logic errors and remove inner join --- .../uniswap_v2_factory_mass_decoding.sql | 4 +++- .../_project/in-flight-decoding/uniswap_v2_trades.sql | 10 +++++++--- .../uniswap_v2_fork_mapping_ethereum.sql | 2 ++ .../decoded-in-flight/uniswap_v2_forks_base_trades.sql | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql index 8fd1fa36f8e..2483b51ae39 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -14,6 +14,8 @@ token0 ,block_date ,tx_hash ,index + +-- could grab abi from our database instead to make this more dynamic FROM TABLE ( decode_evm_event ( abi => '{ @@ -51,7 +53,7 @@ FROM TABLE ( SELECT l.* FROM {{logs}} l WHERE topic0 = 0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9 - and block_date > now() - interval '90' day -- take out limit if you want to use in prod + and block_date > (Select min(block_date) from {{logs}} where topic0 = 0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9) -- take out limit if you want to use in prod ) ) ) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 17f434712cf..1df95820f7a 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -6,6 +6,7 @@ , Factory_evt_PairCreated = null , pair_column_name = 'pair' , Fork_Mapping = null + , contracts = null ) %} WITH dexs AS @@ -28,9 +29,12 @@ WITH dexs AS INNER JOIN {{ Factory_evt_PairCreated }} f ON f.{{ pair_column_name }} = t.contract_address - INNER JOIN + LEFT JOIN {{Fork_Mapping}} m - ON m.factory_address = f.contract_address + ON f.factory_address = f.contract_address + LEFT JOIN + {{contracts}} c + ON f.contract_address = f.contract_address {% if is_incremental() %} WHERE {{ incremental_predicate('t.block_time') }} @@ -39,7 +43,7 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain - , project_name AS project + , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(l.contract_address, 1, 3) as varchar),'-unidentified-fork')) AS project , '{{ version }}' AS version , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month , CAST(date_trunc('day', dexs.block_time) AS date) AS block_date diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql index 9b2438ea40a..8a35b45de10 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql @@ -47,5 +47,7 @@ FROM , (0x35113a300ca0D7621374890ABFEAC30E88f214b1, 'SaitaSwap') , (0xA40ec8A93293A3179D4b544239916C1B68cB47B6, 'SunflowerSwap') , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') + , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') + , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') ) AS t (factory_address, project_name) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql index a37903c6707..212c5ed0854 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql @@ -18,4 +18,5 @@ , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') , pair_column_name = 'pair' , Fork_Mapping = ref('uniswap_v2_fork_mapping_ethereum') + , contracts = source('ethereum', 'contracts') )}} \ No newline at end of file From 9c48f1041c4a9e88e975a91a47d27ea430b1f7e8 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 20:02:33 +0200 Subject: [PATCH 09/86] add missing column --- .../in-flight-decoding/uniswap_v2_factory_mass_decoding.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql index 2483b51ae39..e60b3fb6a44 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -14,6 +14,7 @@ token0 ,block_date ,tx_hash ,index +,contract_address -- could grab abi from our database instead to make this more dynamic FROM TABLE ( From 7594d3e7243fb7cdcabf117e13c52eb272a5ed62 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 20:11:36 +0200 Subject: [PATCH 10/86] add factory address --- .../in-flight-decoding/uniswap_v2_factory_mass_decoding.sql | 1 - .../models/_project/in-flight-decoding/uniswap_v2_trades.sql | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql index e60b3fb6a44..2483b51ae39 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql @@ -14,7 +14,6 @@ token0 ,block_date ,tx_hash ,index -,contract_address -- could grab abi from our database instead to make this more dynamic FROM TABLE ( diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 1df95820f7a..54e701f765c 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -24,6 +24,7 @@ WITH dexs AS , t.tx_hash , t.index AS evt_index , m.project_name + , f.contract_address as factory_address FROM {{ Pair_evt_Swap }} t INNER JOIN @@ -31,7 +32,7 @@ WITH dexs AS ON f.{{ pair_column_name }} = t.contract_address LEFT JOIN {{Fork_Mapping}} m - ON f.factory_address = f.contract_address + ON m.factory_address = f.contract_address LEFT JOIN {{contracts}} c ON f.contract_address = f.contract_address @@ -43,7 +44,7 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain - , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(l.contract_address, 1, 3) as varchar),'-unidentified-fork')) AS project + , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(factory_address, 1, 3) as varchar),'-unidentified-fork')) AS project , '{{ version }}' AS version , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month , CAST(date_trunc('day', dexs.block_time) AS date) AS block_date From 3565dd66fff03d9150498db399e02c33ea97dd79 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 20:23:31 +0200 Subject: [PATCH 11/86] move join into downstream cte --- .../in-flight-decoding/uniswap_v2_trades.sql | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 54e701f765c..3e6145422dc 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -23,19 +23,12 @@ WITH dexs AS , t.contract_address AS project_contract_address , t.tx_hash , t.index AS evt_index - , m.project_name , f.contract_address as factory_address FROM {{ Pair_evt_Swap }} t INNER JOIN {{ Factory_evt_PairCreated }} f ON f.{{ pair_column_name }} = t.contract_address - LEFT JOIN - {{Fork_Mapping}} m - ON m.factory_address = f.contract_address - LEFT JOIN - {{contracts}} c - ON f.contract_address = f.contract_address {% if is_incremental() %} WHERE {{ incremental_predicate('t.block_time') }} @@ -44,7 +37,7 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain - , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(factory_address, 1, 3) as varchar),'-unidentified-fork')) AS project + , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project , '{{ version }}' AS version , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month , CAST(date_trunc('day', dexs.block_time) AS date) AS block_date @@ -61,5 +54,11 @@ SELECT , dexs.evt_index FROM dexs + LEFT JOIN + {{Fork_Mapping}} m + ON dexs.factory_address = m.factory_address + LEFT JOIN + {{contracts}} c + ON dexs.factory_address = c.contract_address {% endmacro %} \ No newline at end of file From 47350af58e966bffe3160e7a53ac7e206b57d7ae Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 9 Aug 2024 20:32:47 +0200 Subject: [PATCH 12/86] fix col name --- .../models/_project/in-flight-decoding/uniswap_v2_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 3e6145422dc..8fa65a333fb 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -59,6 +59,6 @@ FROM ON dexs.factory_address = m.factory_address LEFT JOIN {{contracts}} c - ON dexs.factory_address = c.contract_address + ON dexs.factory_address = c.address {% endmacro %} \ No newline at end of file From 30e0010d1468220257e61f15c6bd832fcbc6e888 Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 00:04:39 +0200 Subject: [PATCH 13/86] add extra factory address to base_trades --- .../_project/in-flight-decoding/uniswap_v2_trades.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 8fa65a333fb..9b13fc49f2f 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -1,6 +1,5 @@ {% macro uniswap_v2_forks_trades( - blockchain = null - , project = null + blockchain = 'ethereum' , version = null , Pair_evt_Swap = null , Factory_evt_PairCreated = null @@ -38,6 +37,7 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project + , dexs.factory_address , '{{ version }}' AS version , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month , CAST(date_trunc('day', dexs.block_time) AS date) AS block_date @@ -60,5 +60,7 @@ FROM LEFT JOIN {{contracts}} c ON dexs.factory_address = c.address + + {% endmacro %} \ No newline at end of file From f24a745f5bbe2040c50abdddac95e94b78dcf3a0 Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 00:51:22 +0200 Subject: [PATCH 14/86] push down to dex.trades --- .../in-flight-decoding/uniswap_v2_trades.sql | 6 +- .../ethereum/decoded-in-flight/_schema.yml | 1 + .../uniswap_v2_fork_mapping_ethereum.sql | 44 ++++++++++++- .../ethereum/dex_ethereum_base_trades.sql | 66 ++++++++++--------- 4 files changed, 81 insertions(+), 36 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index 9b13fc49f2f..e1882583c0d 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -54,12 +54,10 @@ SELECT , dexs.evt_index FROM dexs - LEFT JOIN + INNER JOIN {{Fork_Mapping}} m ON dexs.factory_address = m.factory_address - LEFT JOIN - {{contracts}} c - ON dexs.factory_address = c.address + -- easy to spoof swap events so we use an allowlist of known forks diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml index 8ab1be1810b..ccf3dacdd77 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml @@ -46,6 +46,7 @@ models: combination_of_columns: - tx_hash - evt_index + - project_contract_address \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql index 8a35b45de10..bffa7cee5a9 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql @@ -49,5 +49,47 @@ FROM , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') + , (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') + , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') + , (0x9deb29c9a4c7a88a3c0257393b7f3335338d9a9d, 'crodefi') + , (0x1097053fd2ea711dad45caccc45eff7548fcb362, 'pancakeswap_v2') + , (0x43ec799eadd63848443e2347c49f5f52e8fe0f6f, 'fraxswap') + , (0xee3e9e46e34a27dc755a63e2849c9913ee1a06e2, 'verse_dex') + , (0xc480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6, 'integral_size') + , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') + , (0x4eef5746ed22a2fd368629c1852365bf5dcb79f1, 'convergence') + , (0x1e895bfe59e3a5103e8b7da3897d1f2391476f3c, 'DooarSwap') + , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') + , (0x75e48c954594d64ef9613aeef97ad85370f13807, 'sakeswap') + , (0x696708db871b77355d6c2be7290b27cf0bb9b24b, 'linkswap_v1') + , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') + , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') + , (0x0388c1e0f210abae597b7de712b9510c6c36c857, 'luaswap') + , (0xa40ec8a93293a3179d4b544239916c1b68cb47b6, 'SunflowerSwap') + , (0x460b2005b3318982feada99f7ebf13e1d6f6effe, 'pepedex') + , (0x1264f802364e0776b9a9e3d161b43c7333ac08b2, 'rhino_fi') + , (0x7de800467afce442019884f51a4a1b9143a34fac, 'xchange') + , (0xd87ad19db2c4ccbf897106de034d52e3dd90ea60, 'plasmaswap') + , (0x46adc1c052fafd590f56c42e379d7d16622835a2, 'yape') + , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') + , (0xd34971bab6e5e356fd250715f5de0492bb070452, 'swapr') + , (0x35113a300ca0d7621374890abfeac30e88f214b1, 'SaitaSwap') + , (0xb076b06f669e682609fb4a8c6646d2619717be4b, 'fraxswap') + , (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') + , (0x5fbe219e88f6c6f214ce6f5b1fcaa0294f31ae1b, 'gammaswap') + , (0xbae5dc9b19004883d0377419fef3c2c8832d7d7b, 'apeswap') + , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'btswap') + , (0x26f53fbadeeb777fb2a122dc703433d79241b64e, 'light_dao') + , (0x08e7974cacf66c5a92a37c221a15d3c30c7d97e0, 'unifi') + , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') + , (0xf028f723ed1d0fe01cc59973c49298aa95c57472, 'SashimiSwap') + , (0x54f454d747e037da288db568d4121117eab34e79, 'bbb') + , (0x2d723f60ad8da76286b2ac120498a5ea6babc792, 'neopin') + , (0x91fAe1bc94A9793708fbc66aDcb59087C46dEe10, 'radioshack') + , (0xe185e5335d68c2a18564b4b43bdf4ed86337ee70, 'quantoswap') +) AS t (factory_address, project_name) + -) AS t (factory_address, project_name) \ No newline at end of file + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql index 45260e99033..d8fe6898170 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql @@ -6,37 +6,7 @@ }} {% set base_models = [ - ref('defiswap_ethereum_base_trades') - , ref('uniswap_v1_ethereum_base_trades') - , ref('uniswap_v2_ethereum_base_trades') - , ref('uniswap_v3_ethereum_base_trades') - , ref('apeswap_ethereum_base_trades') - , ref('carbon_defi_ethereum_base_trades') - , ref('airswap_ethereum_base_trades') - , ref('sushiswap_v1_ethereum_base_trades') - , ref('sushiswap_v2_ethereum_base_trades') - , ref('pancakeswap_v2_ethereum_base_trades') - , ref('pancakeswap_v3_ethereum_base_trades') - , ref('shibaswap_v1_ethereum_base_trades') - , ref('balancer_v1_ethereum_base_trades') - , ref('balancer_v2_ethereum_base_trades') - , ref('fraxswap_ethereum_base_trades') - , ref('bancor_ethereum_base_trades') - , ref('verse_dex_ethereum_base_trades') - , ref('swapr_ethereum_base_trades') - , ref('mauve_ethereum_base_trades') - , ref('dfx_ethereum_base_trades') - , ref('dodo_ethereum_base_trades') - , ref('integral_ethereum_base_trades') - , ref('maverick_ethereum_base_trades') - , ref('maverick_v2_ethereum_base_trades') - , ref('kyberswap_ethereum_base_trades') - , ref('clipper_ethereum_base_trades') - , ref('mstable_ethereum_base_trades') - , ref('xchange_ethereum_base_trades') - , ref('curvefi_ethereum_base_trades') - , ref('solidly_v3_ethereum_base_trades') - , ref('swaap_v2_ethereum_base_trades') + ref('uniswap_v2_forks_base_trades') ] %} WITH base_union AS ( @@ -76,3 +46,37 @@ WITH base_union AS ( , columns = ['from', 'to', 'index'] ) }} + +/* all current implmentations, just want to test the above approach +ref('defiswap_ethereum_base_trades') + , ref('uniswap_v1_ethereum_base_trades') + , ref('uniswap_v2_ethereum_base_trades') + , ref('uniswap_v3_ethereum_base_trades') + , ref('apeswap_ethereum_base_trades') + , ref('carbon_defi_ethereum_base_trades') + , ref('airswap_ethereum_base_trades') + , ref('sushiswap_v1_ethereum_base_trades') + , ref('sushiswap_v2_ethereum_base_trades') + , ref('pancakeswap_v2_ethereum_base_trades') + , ref('pancakeswap_v3_ethereum_base_trades') + , ref('shibaswap_v1_ethereum_base_trades') + , ref('balancer_v1_ethereum_base_trades') + , ref('balancer_v2_ethereum_base_trades') + , ref('fraxswap_ethereum_base_trades') + , ref('bancor_ethereum_base_trades') + , ref('verse_dex_ethereum_base_trades') + , ref('swapr_ethereum_base_trades') + , ref('mauve_ethereum_base_trades') + , ref('dfx_ethereum_base_trades') + , ref('dodo_ethereum_base_trades') + , ref('integral_ethereum_base_trades') + , ref('maverick_ethereum_base_trades') + , ref('maverick_v2_ethereum_base_trades') + , ref('kyberswap_ethereum_base_trades') + , ref('clipper_ethereum_base_trades') + , ref('mstable_ethereum_base_trades') + , ref('xchange_ethereum_base_trades') + , ref('curvefi_ethereum_base_trades') + , ref('solidly_v3_ethereum_base_trades') + , ref('swaap_v2_ethereum_base_trades') +*/ \ No newline at end of file From 0b69938821a194cdea82314e38131df854f239be Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 00:59:25 +0200 Subject: [PATCH 15/86] fix macro --- .../_project/in-flight-decoding/uniswap_v2_trades.sql | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql index e1882583c0d..20ab068ebe0 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql @@ -36,7 +36,7 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain - , coalesce(c.namespace, m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project + , coalesce(m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project , dexs.factory_address , '{{ version }}' AS version , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month @@ -57,8 +57,6 @@ FROM INNER JOIN {{Fork_Mapping}} m ON dexs.factory_address = m.factory_address - -- easy to spoof swap events so we use an allowlist of known forks + -- easy to spoof swap events so we use an allowlist - - {% endmacro %} \ No newline at end of file From 39e133283cd04bd87be912b9a932c045355770fc Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 01:10:11 +0200 Subject: [PATCH 16/86] trigger dex.trades run --- .../dex/models/trades/dex_trades.sql | 2 +- .../uniswap_v2_fork_mapping_ethereum.sql | 39 ------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/dex_trades.sql b/dbt_subprojects/dex/models/trades/dex_trades.sql index bc0306a45e1..1e235e20149 100644 --- a/dbt_subprojects/dex/models/trades/dex_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_trades.sql @@ -112,7 +112,7 @@ WITH curve AS ( , tx_hash , tx_from , tx_to - , evt_index + , evt_index FROM {{ cte }} {% if not loop.last %} diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql index bffa7cee5a9..881b6ec5032 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql @@ -10,45 +10,6 @@ SELECT factory_address, project_name FROM (VALUES - (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') - , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') - , (0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73, 'PancakeSwap') - , (0x9Ad32bf5DaFe152Cbe027398219611DB4E8753B3, 'NomiSwap') - , (0x98813bD470A3BA8Da3D16488c58374e8dBc2FF22, 'DigiSwap') - , (0x5B9f88Ee10413e764BEFACa083fB290c4f25F720, 'Broccoli') - , (0x858E3312ed3A876947EA49d572A7C42DE08af7EE, 'BiSwap') - , (0x01bF7C66c6BD861915CdaaE475042d3c4BaE16A7, 'BakerySwap') - , (0x0841BD0B734E4F5853f0dD8d7Ea041c241fb0Da6, 'ApeSwap') - , (0x4d05D0045df5562D6D52937e93De6Ec1FECDAd21, 'SafeSwap') - , (0xf1B735685416253A8F7c8a6686970cA2B0cceCce, 'CoSwap') - , (0x8BA1a4C24DE655136DEd68410e222cCA80d43444, 'Sphynx') - , (0x1e895bFe59E3A5103e8B7dA3897d1F2391476f3c, 'DooarSwap') - , (0x31aFfd875e9f68cd6Cd12Cee8943566c9A4bBA13, 'Elk') - , (0x1A04Afe9778f95829017741bF46C9524B91433fB, 'Orbital') - , (0x9A272d734c5a0d7d84E0a892e891a553e8066dce, 'FstSwap') - , (0xD04A80baeeF12fD7b1D1ee6b1f8ad354f81bc4d7, 'W3Swap') - , (0xCe8fd65646F2a2a897755A1188C04aCe94D2B8D0, 'BSCswap') - , (0x8b6Ca4B3E08c9f80209e66436187088C99C9C2AC, 'BSCswap') - , (0xdd538E4Fd1b69B7863E1F741213276A6Cf1EfB3B, 'CheeseSwap') - , (0x3CD1C46068dAEa5Ebb0d3f55F6915B10648062B8, 'Mdex') - , (0x86407bEa2078ea5f5EB5A52B2caA963bC1F889Da, 'BabySwap') - , (0xBCfCcbde45cE874adCB698cC183deBcF17952812, 'PancakeSwap') - , (0x59DA12BDc470C8e85cA26661Ee3DCD9B85247C88, 'FastSwap') - , (0x79C342FddBBF376cA6B4EFAc7aaA457D6063F8Cb, 'Winery') - , (0xB42E3FE71b7E0673335b3331B3e1053BD9822570, 'WaultSwap') - , (0x3e708FdbE3ADA63fc94F8F61811196f1302137AD, 'CafeSwap') - , (0x4E66Fda7820c53C1a2F601F84918C375205Eac3E, 'Twindex') - , (0xC7a506ab3ac668EAb6bF9eCf971433D6CFeF05D9, 'Alita') - , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') - , (0x03407772f5ebfb9b10df007a2dd6fff4ede47b53 ,'capitaldex') - , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') - , (0xF028F723ED1D0fE01cC59973C49298AA95c57472, 'SashimiSwap') - , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'BTswap') - , (0x35113a300ca0D7621374890ABFEAC30E88f214b1, 'SaitaSwap') - , (0xA40ec8A93293A3179D4b544239916C1B68cB47B6, 'SunflowerSwap') - , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') - , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') - , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') , (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') From 1f4f653a94e57f84b04c1a493e18e8f72e00b382 Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 01:15:37 +0200 Subject: [PATCH 17/86] fix mapping --- dbt_subprojects/dex/models/trades/dex_base_trades.sql | 2 +- dbt_subprojects/dex/models/trades/dex_trades.sql | 2 +- .../decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/dex_base_trades.sql b/dbt_subprojects/dex/models/trades/dex_base_trades.sql index 0a8bc7e9f7e..02326064b65 100644 --- a/dbt_subprojects/dex/models/trades/dex_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_base_trades.sql @@ -71,6 +71,6 @@ with base_union as ( duplicates_rank = 1 ) select - * + * from base_union diff --git a/dbt_subprojects/dex/models/trades/dex_trades.sql b/dbt_subprojects/dex/models/trades/dex_trades.sql index 1e235e20149..bc0306a45e1 100644 --- a/dbt_subprojects/dex/models/trades/dex_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_trades.sql @@ -112,7 +112,7 @@ WITH curve AS ( , tx_hash , tx_from , tx_to - , evt_index + , evt_index FROM {{ cte }} {% if not loop.last %} diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql index 881b6ec5032..236a66c5342 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql @@ -10,7 +10,7 @@ SELECT factory_address, project_name FROM (VALUES - , (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') From 0e92b7fd5a6f6315e21497dfa6770022683dba21 Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 11:46:46 +0200 Subject: [PATCH 18/86] build paralell dex trades --- .../ethereum/decoded-in-flight/_schema.yml | 9 ++- .../mass_decoded_dex_trades_ethereum.sql | 50 ++++++++++++++ .../uniswap_v2_factory_decoding_ethereum.sql | 0 .../uniswap_v2_fork_mapping_ethereum.sql | 0 .../uniswap_v2_forks_base_trades.sql | 0 .../uniswap_v2_pool_decoding_ethereum.sql | 0 .../ethereum/dex_ethereum_base_trades.sql | 66 +++++++++---------- .../mass-decoded/mass_decoded_dex_trades.sql | 27 ++++++++ .../dex/models/trades/mass-decoded/schema.yml | 18 +++++ 9 files changed, 134 insertions(+), 36 deletions(-) create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql rename dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/{ => uniswap-v2}/uniswap_v2_factory_decoding_ethereum.sql (100%) rename dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/{ => uniswap-v2}/uniswap_v2_fork_mapping_ethereum.sql (100%) rename dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/{ => uniswap-v2}/uniswap_v2_forks_base_trades.sql (100%) rename dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/{ => uniswap-v2}/uniswap_v2_pool_decoding_ethereum.sql (100%) create mode 100644 dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/mass-decoded/schema.yml diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml index ccf3dacdd77..fdfb5930f67 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml @@ -48,5 +48,12 @@ models: - evt_index - project_contract_address - + - name: mass_decoded_dex_trades_ethereum + description: "all dex trades on ethereum, mass decoded" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql new file mode 100644 index 00000000000..314516a617a --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -0,0 +1,50 @@ +{{ config( + schema = 'dex_ethereum' + , alias = 'mass_decoded_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + + ref('uniswap_v2_forks_base_trades') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'ethereum' + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_factory_decoding_ethereum.sql rename to dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_fork_mapping_ethereum.sql rename to dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_forks_base_trades.sql rename to dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap_v2_pool_decoding_ethereum.sql rename to dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql index d8fe6898170..45260e99033 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/dex_ethereum_base_trades.sql @@ -6,7 +6,37 @@ }} {% set base_models = [ - ref('uniswap_v2_forks_base_trades') + ref('defiswap_ethereum_base_trades') + , ref('uniswap_v1_ethereum_base_trades') + , ref('uniswap_v2_ethereum_base_trades') + , ref('uniswap_v3_ethereum_base_trades') + , ref('apeswap_ethereum_base_trades') + , ref('carbon_defi_ethereum_base_trades') + , ref('airswap_ethereum_base_trades') + , ref('sushiswap_v1_ethereum_base_trades') + , ref('sushiswap_v2_ethereum_base_trades') + , ref('pancakeswap_v2_ethereum_base_trades') + , ref('pancakeswap_v3_ethereum_base_trades') + , ref('shibaswap_v1_ethereum_base_trades') + , ref('balancer_v1_ethereum_base_trades') + , ref('balancer_v2_ethereum_base_trades') + , ref('fraxswap_ethereum_base_trades') + , ref('bancor_ethereum_base_trades') + , ref('verse_dex_ethereum_base_trades') + , ref('swapr_ethereum_base_trades') + , ref('mauve_ethereum_base_trades') + , ref('dfx_ethereum_base_trades') + , ref('dodo_ethereum_base_trades') + , ref('integral_ethereum_base_trades') + , ref('maverick_ethereum_base_trades') + , ref('maverick_v2_ethereum_base_trades') + , ref('kyberswap_ethereum_base_trades') + , ref('clipper_ethereum_base_trades') + , ref('mstable_ethereum_base_trades') + , ref('xchange_ethereum_base_trades') + , ref('curvefi_ethereum_base_trades') + , ref('solidly_v3_ethereum_base_trades') + , ref('swaap_v2_ethereum_base_trades') ] %} WITH base_union AS ( @@ -46,37 +76,3 @@ WITH base_union AS ( , columns = ['from', 'to', 'index'] ) }} - -/* all current implmentations, just want to test the above approach -ref('defiswap_ethereum_base_trades') - , ref('uniswap_v1_ethereum_base_trades') - , ref('uniswap_v2_ethereum_base_trades') - , ref('uniswap_v3_ethereum_base_trades') - , ref('apeswap_ethereum_base_trades') - , ref('carbon_defi_ethereum_base_trades') - , ref('airswap_ethereum_base_trades') - , ref('sushiswap_v1_ethereum_base_trades') - , ref('sushiswap_v2_ethereum_base_trades') - , ref('pancakeswap_v2_ethereum_base_trades') - , ref('pancakeswap_v3_ethereum_base_trades') - , ref('shibaswap_v1_ethereum_base_trades') - , ref('balancer_v1_ethereum_base_trades') - , ref('balancer_v2_ethereum_base_trades') - , ref('fraxswap_ethereum_base_trades') - , ref('bancor_ethereum_base_trades') - , ref('verse_dex_ethereum_base_trades') - , ref('swapr_ethereum_base_trades') - , ref('mauve_ethereum_base_trades') - , ref('dfx_ethereum_base_trades') - , ref('dodo_ethereum_base_trades') - , ref('integral_ethereum_base_trades') - , ref('maverick_ethereum_base_trades') - , ref('maverick_v2_ethereum_base_trades') - , ref('kyberswap_ethereum_base_trades') - , ref('clipper_ethereum_base_trades') - , ref('mstable_ethereum_base_trades') - , ref('xchange_ethereum_base_trades') - , ref('curvefi_ethereum_base_trades') - , ref('solidly_v3_ethereum_base_trades') - , ref('swaap_v2_ethereum_base_trades') -*/ \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql new file mode 100644 index 00000000000..2a4ece808b8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql @@ -0,0 +1,27 @@ +{{ config( + schema = 'mass_decoded_dex_trades' + , alias = 'trades' + , partition_by = ['block_month', 'blockchain', 'project'] + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "blast", "bnb", "celo", "ethereum", "fantom", "gnosis", "linea", "optimism", "polygon", "scroll", "zkevm", "zksync", "zora"]\', + "sector", + "dex", + \'["hosuke", "0xrob", "jeff-dude", "tomfutago"]\') }}') +}} + + +with dexs AS ( + {{ + enrich_dex_trades( + base_trades = ref('dex_base_trades') + , filter = "project != 'curve'" + , tokens_erc20_model = source('tokens', 'erc20') + ) + }} +) + +Select * from dexs \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/mass-decoded/schema.yml b/dbt_subprojects/dex/models/trades/mass-decoded/schema.yml new file mode 100644 index 00000000000..cc2a50c5568 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/mass-decoded/schema.yml @@ -0,0 +1,18 @@ +version: 2 + +models: + - name: mass_decoded_dex_trades + meta: + blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, optimism, polygon, scroll, zksync, linea, blast, sei + sector: dex + contributors: 0xRob, hosuke, jeff-dude, tomfutago + config: + tags: [ 'dex', 'trades', 'beta' ] + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - project + - version + - tx_hash + - evt_index \ No newline at end of file From af3e3bab38ffb6ed86195fc63dd16a80a38e75ab Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 14:07:31 +0200 Subject: [PATCH 19/86] change model name --- .../dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql index 2a4ece808b8..67af988843c 100644 --- a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql @@ -17,7 +17,7 @@ with dexs AS ( {{ enrich_dex_trades( - base_trades = ref('dex_base_trades') + base_trades = ref('mass_decoded_dex_trades_ethereum') , filter = "project != 'curve'" , tokens_erc20_model = source('tokens', 'erc20') ) From 5a0e4f09964f3f1279b5646047a121f5ccaaf55b Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 15:35:39 +0200 Subject: [PATCH 20/86] fix blockchain column --- .../uniswap-v2/uniswap_v2_forks_base_trades.sql | 2 +- .../dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql index 212c5ed0854..6d4dff2f4b7 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql @@ -12,7 +12,7 @@ }} {{uniswap_v2_forks_trades( - blockchain = ethereum + blockchain = 'ethereum' , version = 'unknown' , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') diff --git a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql index 67af988843c..f12b9b4f3a5 100644 --- a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql @@ -18,7 +18,7 @@ with dexs AS ( {{ enrich_dex_trades( base_trades = ref('mass_decoded_dex_trades_ethereum') - , filter = "project != 'curve'" + , filter = "1=1" , tokens_erc20_model = source('tokens', 'erc20') ) }} From 31858cbfb211d2662ab8d4f6b1fc51d3028e12ee Mon Sep 17 00:00:00 2001 From: Boxer Date: Sat, 10 Aug 2024 15:58:06 +0200 Subject: [PATCH 21/86] take out date filter --- .../in-flight-decoding/uniswap_v2_pool_mass_decoding.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql index dc1f104583b..a24d2864cfe 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql @@ -65,7 +65,7 @@ FROM TABLE ( SELECT l.* FROM {{logs}} l WHERE topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 - and block_date > now() - interval '90' day -- take out limit if you want to use in prod + and block_date > (Select min(block_date) from {{logs}} where topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822) ) ) ) From 75a8a32ac9b8e79c883268e1a057e44dac8ff300 Mon Sep 17 00:00:00 2001 From: Boxer Date: Thu, 29 Aug 2024 15:08:07 +0200 Subject: [PATCH 22/86] change approach to be more dynamic --- .../in-flight-decoding/decoding_base.sql | 23 +++++++ .../uniswap_v2_factory_mass_decoding.sql | 39 ++++++++++++ .../uniswap_v2_pool_mass_decoding.sql | 51 +++++++++++++++ .../{ => uniswap_v2}/uniswap_v2_trades.sql | 0 .../uniswap_v3_factory_mass_decoding.sql} | 2 +- .../uniswap_v3_pool_mass_decoding.sql} | 2 +- .../uniswap_v3/uniswap_v3_trades.sql | 62 +++++++++++++++++++ .../uniswap_v2_factory_decoding_ethereum.sql | 1 - .../uniswap_v3_factory_decoding_ethereum.sql | 17 +++++ .../uniswap_v3_fork_mapping_ethereum.sql | 19 ++++++ .../uniswap_v3_forks_base_trades.sql | 22 +++++++ .../uniswap_v3_pool_decoding_ethereum.sql | 16 +++++ 12 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_pool_mass_decoding.sql rename dbt_subprojects/dex/macros/models/_project/in-flight-decoding/{ => uniswap_v2}/uniswap_v2_trades.sql (100%) rename dbt_subprojects/dex/macros/models/_project/in-flight-decoding/{uniswap_v2_factory_mass_decoding.sql => uniswap_v3/uniswap_v3_factory_mass_decoding.sql} (97%) rename dbt_subprojects/dex/macros/models/_project/in-flight-decoding/{uniswap_v2_pool_mass_decoding.sql => uniswap_v3/uniswap_v3_pool_mass_decoding.sql} (97%) create mode 100644 dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql new file mode 100644 index 00000000000..2a0f82486b2 --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql @@ -0,0 +1,23 @@ +{% macro evm_event_decoding_base( + logs = null, + abi = null, + topic0 = null + ) +%} + +SELECT +* + +FROM TABLE ( + decode_evm_event ( + abi => '{{abi}}', + input => TABLE ( + SELECT l.* + FROM {{logs}} l + WHERE topic0 = {{topic0}} + and block_date > (Select min(block_date) from {{logs}} where topic0 = {{topic0}}) + ) + ) + ) + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql new file mode 100644 index 00000000000..b3b0b516155 --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql @@ -0,0 +1,39 @@ +{% macro uniswap_v2_factory_mass_decoding(logs) %} + +{% set abi = '{ + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "pair", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "PairCreated", + "type": "event" +}' %} + +{% set topic0 = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' %} + +{{ evm_event_decoding_base(logs, abi, topic0) }} + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_pool_mass_decoding.sql new file mode 100644 index 00000000000..22115a69e6f --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_pool_mass_decoding.sql @@ -0,0 +1,51 @@ +{% macro uniswap_v2_pool_mass_decoding(logs) %} + +{% set abi = '{ + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Swap", + "type": "event" +}' %} + +{% set topic0 = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' %} + +{{ evm_event_decoding_base(logs, abi, topic0) }} + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql similarity index 100% rename from dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_trades.sql rename to dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql similarity index 97% rename from dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql rename to dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql index 2483b51ae39..13a340331b3 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql @@ -1,4 +1,4 @@ -{% macro uniswap_v2_factory_mass_decoding( +{% macro uniswap_v3_factory_mass_decoding( logs = null ) %} diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql similarity index 97% rename from dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql rename to dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql index a24d2864cfe..c5da20c5fd5 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2_pool_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql @@ -1,4 +1,4 @@ -{% macro uniswap_v2_pool_mass_decoding( +{% macro uniswap_v3_pool_mass_decoding( logs = null ) %} diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql new file mode 100644 index 00000000000..11a0f3724b8 --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -0,0 +1,62 @@ +{% macro uniswap_v3_forks_trades( + blockchain = 'ethereum' + , version = null + , Pair_evt_Swap = null + , Factory_evt_PairCreated = null + , pair_column_name = 'pair' + , Fork_Mapping = null + , contracts = null + ) +%} +WITH dexs AS +( + SELECT + t.block_number + , t.block_time + , t.to AS taker + , t.contract_address AS maker + , CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw + , CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN amount1In ELSE amount0In END AS token_sold_amount_raw + , CASE WHEN amount0Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_bought_address + , 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.tx_hash + , t.index AS evt_index + , f.contract_address as factory_address + FROM + {{ Pair_evt_Swap }} t + INNER JOIN + {{ Factory_evt_PairCreated }} f + ON f.{{ pair_column_name }} = t.contract_address + {% if is_incremental() %} + WHERE + {{ incremental_predicate('t.block_time') }} + {% endif %} +) + +SELECT + '{{ blockchain }}' AS blockchain + , coalesce(m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project + , dexs.factory_address + , '{{ version }}' AS version + , 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 + , dexs.block_number + , dexs.token_bought_amount_raw + , dexs.token_sold_amount_raw + , dexs.token_bought_address + , dexs.token_sold_address + , dexs.taker + , dexs.maker + , dexs.project_contract_address + , dexs.tx_hash + , dexs.evt_index +FROM + dexs + INNER JOIN + {{Fork_Mapping}} m + ON dexs.factory_address = m.factory_address + -- easy to spoof swap events so we use an allowlist + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql index c45df19b093..adbdc9fdcc4 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql @@ -14,4 +14,3 @@ {{uniswap_v2_factory_mass_decoding( logs = source('ethereum', 'logs') )}} - diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql new file mode 100644 index 00000000000..5f77de40f22 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql @@ -0,0 +1,17 @@ +{{ config( + + schema = 'mass_decoding_ethereum', + alias = 'uniswap_v3_factory_evt_PoolCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_factory_mass_decoding( + logs = source('ethereum', 'logs') +)}} + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql new file mode 100644 index 00000000000..79021547194 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql @@ -0,0 +1,19 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v3_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql new file mode 100644 index 00000000000..b8c328b0637 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql @@ -0,0 +1,22 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v3_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_forks_trades( + blockchain = 'ethereum' + , version = 'unknown' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') + , Factory_evt_PairCreated = ref('uniswap_v3_factory_decoding_ethereum') + , pair_column_name = 'pair' + , Fork_Mapping = ref('uniswap_v3_fork_mapping_ethereum') + , contracts = source('ethereum', 'contracts') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql new file mode 100644 index 00000000000..53931819cbc --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v3_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_pool_mass_decoding( + logs = source('ethereum', 'logs') +)}} \ No newline at end of file From fc2ebf7fc7573a2877d85572bd5c64ef83c304d8 Mon Sep 17 00:00:00 2001 From: Boxer Date: Thu, 29 Aug 2024 17:33:38 +0200 Subject: [PATCH 23/86] add univ3 --- .../uniswap_v2/uniswap_v2_trades.sql | 13 +-- .../uniswap_v3_factory_mass_decoding.sql | 65 ++------------- .../uniswap_v3_pool_mass_decoding.sql | 79 +++---------------- .../uniswap_v3/uniswap_v3_trades.sql | 57 ++++++------- .../dex/models/trades/dex_base_trades.sql | 2 +- .../uniswap_v2_forks_base_trades.sql | 4 +- .../uniswap_v2_pool_decoding_ethereum.sql | 2 +- .../uniswap_v3_forks_base_trades.sql | 17 ++-- 8 files changed, 62 insertions(+), 177 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 20ab068ebe0..9c7e9f2f292 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -1,13 +1,13 @@ {% macro uniswap_v2_forks_trades( - blockchain = 'ethereum' + blockchain = null + , dex_type = 'uni-v2' , version = null , Pair_evt_Swap = null , Factory_evt_PairCreated = null , pair_column_name = 'pair' - , Fork_Mapping = null - , contracts = null ) %} + WITH dexs AS ( SELECT @@ -36,8 +36,6 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain - , coalesce(m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project - , dexs.factory_address , '{{ version }}' AS version , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month , CAST(date_trunc('day', dexs.block_time) AS date) AS block_date @@ -52,11 +50,8 @@ SELECT , dexs.project_contract_address , dexs.tx_hash , dexs.evt_index + , dexs.factory_address FROM dexs - INNER JOIN - {{Fork_Mapping}} m - ON dexs.factory_address = m.factory_address - -- easy to spoof swap events so we use an allowlist {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql index 13a340331b3..2de3ca7e173 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_factory_mass_decoding.sql @@ -1,61 +1,12 @@ -{% macro uniswap_v3_factory_mass_decoding( - logs = null - ) -%} +{% macro uniswap_v3_factory_mass_decoding(logs) %} +{% set abi = ' +{"name":"PoolCreated","type":"event","inputs":[{"name":"token0","type":"address","indexed":true,"internalType":"address"},{"name":"token1","type":"address","indexed":true,"internalType":"address"},{"name":"fee","type":"uint24","indexed":true,"internalType":"uint24"},{"name":"tickSpacing","type":"int24","indexed":false,"internalType":"int24"},{"name":"pool","type":"address","indexed":false,"internalType":"address"}],"anonymous":false} +' %} -SELECT -token0 -,token1 -,pair -,contract_address -,block_time -,block_number -,block_date -,tx_hash -,index +{% set topic0 = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' %} --- could grab abi from our database instead to make this more dynamic -FROM TABLE ( - decode_evm_event ( - abi => '{ - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "pair", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "PairCreated", - "type": "event" - }', - input => TABLE ( - SELECT l.* - FROM {{logs}} l - WHERE topic0 = 0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9 - and block_date > (Select min(block_date) from {{logs}} where topic0 = 0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9) -- take out limit if you want to use in prod - ) - ) - ) +{{ evm_event_decoding_base(logs, abi, topic0) }} + +{% endmacro %} -{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql index c5da20c5fd5..ae65a142eea 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_pool_mass_decoding.sql @@ -1,73 +1,12 @@ -{% macro uniswap_v3_pool_mass_decoding( - logs = null - ) -%} +{% macro uniswap_v3_pool_mass_decoding(logs) %} +{% set abi = ' +{"name":"Swap","type":"event","inputs":[{"name":"sender","type":"address","indexed":true,"internalType":"address"},{"name":"recipient","type":"address","indexed":true,"internalType":"address"},{"name":"amount0","type":"int256","indexed":false,"internalType":"int256"},{"name":"amount1","type":"int256","indexed":false,"internalType":"int256"},{"name":"sqrtPriceX96","type":"uint160","indexed":false,"internalType":"uint160"},{"name":"liquidity","type":"uint128","indexed":false,"internalType":"uint128"},{"name":"tick","type":"int24","indexed":false,"internalType":"int24"}],"anonymous":false} +' %} -SELECT -block_time -,block_number -,to -,contract_address -,amount0Out -,amount0In -,amount1Out -,amount1In -,block_date -,tx_hash -,index -FROM TABLE ( - decode_evm_event ( - abi => '{ - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0In", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1In", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount0Out", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount1Out", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "Swap", - "type": "event" - }', - input => TABLE ( - SELECT l.* - FROM {{logs}} l - WHERE topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 - and block_date > (Select min(block_date) from {{logs}} where topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822) - ) - ) - ) +{% set topic0 = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' %} + +{{ evm_event_decoding_base(logs, abi, topic0) }} + +{% endmacro %} -{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 11a0f3724b8..ff8624a5165 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -1,50 +1,57 @@ + {% macro uniswap_v3_forks_trades( - blockchain = 'ethereum' + blockchain = null + , project = null + , dex_type = 'uni-v3' , version = null , Pair_evt_Swap = null - , Factory_evt_PairCreated = null - , pair_column_name = 'pair' - , Fork_Mapping = null - , contracts = null + , Factory_evt_PoolCreated = null + , taker_column_name = 'recipient' + , maker_column_name = null + , pair_column_name = 'pool' ) %} WITH dexs AS ( SELECT - t.block_number - , t.block_time - , t.to AS taker - , t.contract_address AS maker - , CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw - , CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN amount1In ELSE amount0In END AS token_sold_amount_raw - , CASE WHEN amount0Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_bought_address - , 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.tx_hash - , t.index AS evt_index + t.evt_block_number AS block_number + , t.evt_block_time AS block_time + , t.{{ taker_column_name }} AS taker + , {% if maker_column_name %} + t.{{ maker_column_name }} + {% else %} + cast(null as varbinary) + {% endif %} as maker + , CASE WHEN amount0 < INT256 '0' THEN abs(amount0) ELSE abs(amount1) END AS token_bought_amount_raw -- when amount0 is negative it means trader_a is buying token0 from the pool + , CASE WHEN amount0 < INT256 '0' THEN abs(amount1) ELSE abs(amount0) END AS token_sold_amount_raw + , CASE WHEN amount0 < INT256 '0' THEN f.token0 ELSE f.token1 END AS token_bought_address + , 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 , f.contract_address as factory_address FROM {{ Pair_evt_Swap }} t INNER JOIN - {{ Factory_evt_PairCreated }} f + {{ Factory_evt_PoolCreated }} f ON f.{{ pair_column_name }} = t.contract_address {% if is_incremental() %} WHERE - {{ incremental_predicate('t.block_time') }} + {{ incremental_predicate('t.evt_block_time') }} {% endif %} ) SELECT '{{ blockchain }}' AS blockchain - , coalesce(m.project_name, concat(cast(varbinary_substring(dexs.factory_address, 1, 3) as varchar),'-unidentified-univ2-fork')) AS project - , dexs.factory_address + , '{{ project }}' AS project , '{{ version }}' AS version + , '{{dex_type}}' AS dex_type , 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 , dexs.block_number - , dexs.token_bought_amount_raw - , dexs.token_sold_amount_raw + , CAST(dexs.token_bought_amount_raw AS UINT256) AS token_bought_amount_raw + , CAST(dexs.token_sold_amount_raw AS UINT256) AS token_sold_amount_raw , dexs.token_bought_address , dexs.token_sold_address , dexs.taker @@ -52,11 +59,7 @@ SELECT , dexs.project_contract_address , dexs.tx_hash , dexs.evt_index + , dexs.factory_address FROM dexs - INNER JOIN - {{Fork_Mapping}} m - ON dexs.factory_address = m.factory_address - -- easy to spoof swap events so we use an allowlist - {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/dex_base_trades.sql b/dbt_subprojects/dex/models/trades/dex_base_trades.sql index daf7c8b9f32..73e06a66dc2 100644 --- a/dbt_subprojects/dex/models/trades/dex_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_base_trades.sql @@ -73,6 +73,6 @@ with base_union as ( duplicates_rank = 1 ) select - * + * from base_union diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql index 6d4dff2f4b7..8b85bec81b5 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql @@ -13,10 +13,8 @@ {{uniswap_v2_forks_trades( blockchain = 'ethereum' - , version = 'unknown' + , version = null , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') , pair_column_name = 'pair' - , Fork_Mapping = ref('uniswap_v2_fork_mapping_ethereum') - , contracts = source('ethereum', 'contracts') )}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql index 7d6be994c90..e817fe8d2f3 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql @@ -1,6 +1,6 @@ {{ config( - schema = 'dex_mass_decoding_ethereum', + schema = 'mass_decoding_ethereum', alias = 'uniswap_v2_pool_evt_Swap', partition_by = ['block_date'], materialized = 'incremental', diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql index b8c328b0637..f5bbd4a1ed1 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql @@ -11,12 +11,11 @@ ) }} -{{uniswap_v2_forks_trades( - blockchain = 'ethereum' - , version = 'unknown' - , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') - , Factory_evt_PairCreated = ref('uniswap_v3_factory_decoding_ethereum') - , pair_column_name = 'pair' - , Fork_Mapping = ref('uniswap_v3_fork_mapping_ethereum') - , contracts = source('ethereum', 'contracts') -)}} \ No newline at end of file +{{uniswap_v3_forks_trades( + blockchain = 'ethereum' + , project = 'null' + , version = 'unknown' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') + , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_ethereum') +)}} + From 9afc3df878117f681f456fe5908e8d535b6775ae Mon Sep 17 00:00:00 2001 From: Boxer Date: Thu, 29 Aug 2024 17:35:01 +0200 Subject: [PATCH 24/86] add to union --- .../decoded-in-flight/mass_decoded_dex_trades_ethereum.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql index 314516a617a..728b2a1f252 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -8,6 +8,7 @@ {% set base_models = [ ref('uniswap_v2_forks_base_trades') + , ref('uniswap_v3_forks_base_trades') ] %} WITH base_union AS ( From 0a4615592ab93b9343a8f295ad93d4721b33ef82 Mon Sep 17 00:00:00 2001 From: Boxer Date: Thu, 29 Aug 2024 18:05:45 +0200 Subject: [PATCH 25/86] fix compile error --- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index ff8624a5165..761790e348f 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -14,8 +14,8 @@ WITH dexs AS ( SELECT - t.evt_block_number AS block_number - , t.evt_block_time AS block_time + block_number + block_time AS block_time , t.{{ taker_column_name }} AS taker , {% if maker_column_name %} t.{{ maker_column_name }} @@ -27,8 +27,8 @@ WITH dexs AS , CASE WHEN amount0 < INT256 '0' THEN f.token0 ELSE f.token1 END AS token_bought_address , 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 + , t.tx_hash AS tx_hash + , t.index as evt_index , f.contract_address as factory_address FROM {{ Pair_evt_Swap }} t From fd1ca4a16e22bd64dff88bbbdf1bc92d3666237a Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 11:08:50 +0200 Subject: [PATCH 26/86] fix columns --- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 761790e348f..45b7fc97af8 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -14,8 +14,8 @@ WITH dexs AS ( SELECT - block_number - block_time AS block_time + t.block_number + ,t.block_time , t.{{ taker_column_name }} AS taker , {% if maker_column_name %} t.{{ maker_column_name }} @@ -27,7 +27,7 @@ WITH dexs AS , CASE WHEN amount0 < INT256 '0' THEN f.token0 ELSE f.token1 END AS token_bought_address , CASE WHEN amount0 < INT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address , t.contract_address as project_contract_address - , t.tx_hash AS tx_hash + , t.tx_hash , t.index as evt_index , f.contract_address as factory_address FROM From b3cc67e9d85c64c5001ece85aa462aae7776d272 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 11:27:18 +0200 Subject: [PATCH 27/86] fix lineage --- .../uniswap_v2/uniswap_v2_trades.sql | 3 ++ .../uniswap_v3/uniswap_v3_trades.sql | 4 +- .../mass_decoded_dex_trades_ethereum.sql | 51 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 9c7e9f2f292..6801eb12554 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -1,6 +1,7 @@ {% macro uniswap_v2_forks_trades( blockchain = null , dex_type = 'uni-v2' + , project = null , version = null , Pair_evt_Swap = null , Factory_evt_PairCreated = null @@ -36,7 +37,9 @@ WITH dexs AS SELECT '{{ blockchain }}' AS blockchain + , '{{project}}' AS project , '{{ version }}' AS version + , '{{dex_type}}' AS dex_type , 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 diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 45b7fc97af8..08e1207547a 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -1,14 +1,14 @@ {% macro uniswap_v3_forks_trades( blockchain = null - , project = null , dex_type = 'uni-v3' + , project = null , version = null , Pair_evt_Swap = null , Factory_evt_PoolCreated = null + , pair_column_name = 'pool' , taker_column_name = 'recipient' , maker_column_name = null - , pair_column_name = 'pool' ) %} WITH dexs AS diff --git a/dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql new file mode 100644 index 00000000000..d65958500d2 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -0,0 +1,51 @@ +{{ config( + schema = 'dex_mode' + , alias = 'mass_decoded_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + + ref('uniswap_v2_forks_base_trades_mode') + , ref('uniswap_v3_forks_base_trades_mode') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'mode' + , columns = ['from', 'to', 'index'] + ) +}} + From 504c1b8b29a59c486f70e39814320c7617ff56ed Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 11:43:23 +0200 Subject: [PATCH 28/86] add project column --- .../decoded-in-flight/mass_decoded_dex_trades_ethereum.sql | 3 ++- .../uniswap-v2/uniswap_v2_forks_base_trades.sql | 6 +++--- .../uniswap-v3/uniswap_v3_forks_base_trades.sql | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql index 728b2a1f252..43968243a6c 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -7,7 +7,7 @@ {% set base_models = [ - ref('uniswap_v2_forks_base_trades') + ref('uniswap_v2_forks_base_trades') , ref('uniswap_v3_forks_base_trades') ] %} @@ -32,6 +32,7 @@ WITH base_union AS ( , project_contract_address , tx_hash , evt_index + , factory_address FROM {{ base_model }} {% if not loop.last %} diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql index 8b85bec81b5..85b4d53fd84 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql @@ -2,7 +2,7 @@ schema = 'dex_mass_decoding_ethereum', alias = 'uniswap_v2_base_trades', - partition_by = ['block_month'], + partition_by = ['block_month', 'factory_address'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', @@ -13,8 +13,8 @@ {{uniswap_v2_forks_trades( blockchain = 'ethereum' - , version = null + , version = 'null' + , project = 'null' , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') - , pair_column_name = 'pair' )}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql index f5bbd4a1ed1..021b9780038 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql @@ -2,7 +2,7 @@ schema = 'dex_mass_decoding_ethereum', alias = 'uniswap_v3_base_trades', - partition_by = ['block_month'], + partition_by = ['block_month', 'factory_address'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', @@ -13,8 +13,8 @@ {{uniswap_v3_forks_trades( blockchain = 'ethereum' + , version = 'null' , project = 'null' - , version = 'unknown' , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_ethereum') )}} From 493cb6a05375c7d8a3f0b1e564a347f53892bbc0 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 11:47:42 +0200 Subject: [PATCH 29/86] fi --- .../mass_decoded_dex_trades_ethereum.sql | 4 +- ...uniswap_v2_forks_base_trades_ethereum.sql} | 0 ...uniswap_v3_forks_base_trades_ethereum.sql} | 0 .../mass_decoded_dex_trades_ethereum.sql | 51 ------------------- 4 files changed, 2 insertions(+), 53 deletions(-) rename dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/{uniswap_v2_forks_base_trades.sql => uniswap_v2_forks_base_trades_ethereum.sql} (100%) rename dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/{uniswap_v3_forks_base_trades.sql => uniswap_v3_forks_base_trades_ethereum.sql} (100%) delete mode 100644 dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql index 43968243a6c..017906daa0a 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -7,8 +7,8 @@ {% set base_models = [ - ref('uniswap_v2_forks_base_trades') - , ref('uniswap_v3_forks_base_trades') + ref('uniswap_v2_forks_base_trades_ethereum') + , ref('uniswap_v3_forks_base_trades_ethereum') ] %} WITH base_union AS ( diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades.sql rename to dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades.sql rename to dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql deleted file mode 100644 index d65958500d2..00000000000 --- a/dbt_subprojects/dex/models/trades/mode/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ /dev/null @@ -1,51 +0,0 @@ -{{ config( - schema = 'dex_mode' - , alias = 'mass_decoded_trades' - , materialized = 'view' - ) -}} - -{% set base_models = [ - - ref('uniswap_v2_forks_base_trades_mode') - , ref('uniswap_v3_forks_base_trades_mode') -] %} - -WITH base_union AS ( - SELECT * - FROM ( - {% for base_model in base_models %} - SELECT - blockchain - , project - , version - , block_month - , block_date - , block_time - , block_number - , token_bought_amount_raw - , token_sold_amount_raw - , token_bought_address - , token_sold_address - , taker - , maker - , project_contract_address - , tx_hash - , evt_index - FROM - {{ base_model }} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} - ) -) - -{{ - add_tx_columns( - model_cte = 'base_union' - , blockchain = 'mode' - , columns = ['from', 'to', 'index'] - ) -}} - From cb0f7478bd59a1ee1cc51e24c2c19a7784939782 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 11:50:43 +0200 Subject: [PATCH 30/86] edit yml --- .../ethereum/decoded-in-flight/_schema.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml index fdfb5930f67..eda94470c32 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml @@ -32,7 +32,7 @@ models: - name: project_name description: "name of the project associated with the factory" - - name: uniswap_v2_forks_base_trades + - name: uniswap_v2_forks_base_trades_ethereum meta: blockchain: ethereum sector: dex @@ -47,6 +47,22 @@ models: - tx_hash - evt_index - project_contract_address + + - name: uniswap_v3_forks_base_trades_ethereum + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3', 'forks' ] + description: "base trades for all forks of uniswap v3 on ethereum" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address - name: mass_decoded_dex_trades_ethereum description: "all dex trades on ethereum, mass decoded" From 450db877aec58888a072da6d6ecdef38a5891433 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 11:58:29 +0200 Subject: [PATCH 31/86] remove factory_address from partition_by in uniswap_v2 and uniswap_v3 base trades SQL files --- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 85b4d53fd84..dae82d4239f 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -2,7 +2,7 @@ schema = 'dex_mass_decoding_ethereum', alias = 'uniswap_v2_base_trades', - partition_by = ['block_month', 'factory_address'], + partition_by = ['block_month'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 021b9780038..074296af85b 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -2,7 +2,7 @@ schema = 'dex_mass_decoding_ethereum', alias = 'uniswap_v3_base_trades', - partition_by = ['block_month', 'factory_address'], + partition_by = ['block_month'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', From d7ea43fc04b4648aeb37bfc0c1092c6ffcd23248 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 12:37:18 +0200 Subject: [PATCH 32/86] construct full lineage --- .../models/log_decoded_enrich_dex_trades.sql | 101 +++ .../models/_log_decoded_trades/_schema.yml | 136 ++++ .../_log_decoded_trades/ethereum/_schema.yml | 44 ++ .../ethereum/decoded-in-flight/_schema.yml | 0 .../mass_decoded_dex_trades_ethereum.sql | 0 .../uniswap_v2_factory_decoding_ethereum.sql | 0 .../uniswap_v2_fork_mapping_ethereum.sql | 0 .../uniswap_v2_forks_base_trades_ethereum.sql | 0 .../uniswap_v2_pool_decoding_ethereum.sql | 0 .../uniswap_v3_factory_decoding_ethereum.sql | 0 .../uniswap_v3_fork_mapping_ethereum.sql | 0 .../uniswap_v3_forks_base_trades_ethereum.sql | 0 .../uniswap_v3_pool_decoding_ethereum.sql | 0 .../airswap_ethereum_base_trades.sql | 0 .../apeswap_ethereum_base_trades.sql | 0 .../balancer_v1_ethereum_base_trades.sql | 0 .../balancer_v2_ethereum_base_trades.sql | 0 .../platforms/bancor_ethereum_base_trades.sql | 0 .../carbon_defi_ethereum_base_trades.sql | 0 .../clipper_ethereum_base_trades.sql | 0 .../platforms/curve_ethereum_base_trades.sql | 0 .../defiswap_ethereum_base_trades.sql | 0 .../platforms/dfx_ethereum_base_trades.sql | 0 .../platforms/dodo_ethereum_base_trades.sql | 0 .../fraxswap_ethereum_base_trades.sql | 0 .../integral_ethereum_base_trades.sql | 0 .../kyberswap_ethereum_base_trades.sql | 0 .../platforms/mauve_ethereum_base_trades.sql | 0 .../maverick_ethereum_base_trades.sql | 0 .../maverick_v2_ethereum_base_trades.sql | 0 .../mstable_ethereum_base_trades.sql | 0 .../pancakeswap_v2_ethereum_base_trades.sql | 0 .../pancakeswap_v3_ethereum_base_trades.sql | 0 .../shibaswap_v1_ethereum_base_trades.sql | 0 .../solidly_v3_ethereum_base_trades.sql | 0 .../sushiswap_v1_ethereum_base_trades.sql | 0 .../sushiswap_v2_ethereum_base_trades.sql | 0 .../swaap_v2_ethereum_base_trades.sql | 0 .../platforms/swapr_ethereum_base_trades.sql | 0 .../uniswap_v1_ethereum_base_trades.sql | 0 .../uniswap_v2_ethereum_base_trades.sql | 0 .../uniswap_v3_ethereum_base_trades.sql | 0 .../verse_dex_ethereum_base_trades.sql | 0 .../xchange_ethereum_base_trades.sql | 0 .../log_decoded_dex_base_trades.sql | 62 ++ .../log_decoded_dex_docs_block.md | 22 + .../log_decoded_dex_trades.sql | 45 ++ .../dex/models/trades/ethereum/_schema.yml | 601 ------------------ dbt_subprojects/dex/package-lock.yml | 6 +- 49 files changed, 413 insertions(+), 604 deletions(-) create mode 100644 dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/_schema.yml (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/airswap_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/apeswap_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/balancer_v1_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/balancer_v2_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/bancor_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/carbon_defi_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/clipper_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/curve_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/defiswap_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/dfx_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/dodo_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/fraxswap_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/integral_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/kyberswap_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/mauve_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/maverick_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/maverick_v2_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/mstable_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/solidly_v3_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/swaap_v2_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/swapr_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/verse_dex_ethereum_base_trades.sql (100%) rename dbt_subprojects/dex/models/{trades => _log_decoded_trades}/ethereum/platforms/xchange_ethereum_base_trades.sql (100%) create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_docs_block.md create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/_schema.yml diff --git a/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql b/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql new file mode 100644 index 00000000000..74bcbd98c9d --- /dev/null +++ b/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql @@ -0,0 +1,101 @@ +{% macro enrich_dex_trades( + base_trades = null + , filter = null + , tokens_erc20_model = null + ) +%} + +WITH base_trades as ( + SELECT + * + FROM + {{ base_trades }} + WHERE + {{ filter }} + {% if is_incremental() %} + AND + {{ incremental_predicate('block_time') }} + {% endif %} +) + +, enrichments AS ( + SELECT + base_trades.blockchain + , base_trades.project + , base_trades.version + , base_trades.factory_address + , base_trades.dex_type + , base_trades.block_month + , base_trades.block_date + , base_trades.block_time + , base_trades.block_number + , erc20_bought.symbol AS token_bought_symbol + , erc20_sold.symbol AS token_sold_symbol + , case + when lower(erc20_bought.symbol) > lower(erc20_sold.symbol) then concat(erc20_sold.symbol, '-', erc20_bought.symbol) + else concat(erc20_bought.symbol, '-', erc20_sold.symbol) + end AS token_pair + , base_trades.token_bought_amount_raw / power(10, erc20_bought.decimals) AS token_bought_amount + , base_trades.token_sold_amount_raw / power(10, erc20_sold.decimals) AS token_sold_amount + , base_trades.token_bought_amount_raw + , base_trades.token_sold_amount_raw + , base_trades.token_bought_address + , base_trades.token_sold_address + , coalesce(base_trades.taker, base_trades.tx_from) AS taker + , base_trades.maker + , base_trades.project_contract_address + , base_trades.tx_hash + , base_trades.tx_from + , base_trades.tx_to + , base_trades.evt_index + FROM + base_trades + LEFT JOIN + {{ tokens_erc20_model }} as erc20_bought + ON erc20_bought.contract_address = base_trades.token_bought_address + AND erc20_bought.blockchain = base_trades.blockchain + LEFT JOIN + {{ tokens_erc20_model }} as erc20_sold + ON erc20_sold.contract_address = base_trades.token_sold_address + AND erc20_sold.blockchain = base_trades.blockchain +) + +, enrichments_with_prices AS ( + {{ + add_amount_usd( + trades_cte = 'enrichments' + ) + }} +) + +SELECT + blockchain + , project + , version + , factory_address + , dex_type + , block_month + , block_date + , block_time + , block_number + , token_bought_symbol + , token_sold_symbol + , token_pair + , token_bought_amount + , token_sold_amount + , token_bought_amount_raw + , token_sold_amount_raw + , amount_usd + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , tx_from + , tx_to + , evt_index +FROM + enrichments_with_prices + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml new file mode 100644 index 00000000000..7219aba1853 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml @@ -0,0 +1,136 @@ +version: 2 + +models: + - name: log_decoded_dex_trades + meta: + docs_slug: /curated/trading/DEX/dex-trades + blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, optimism, polygon, scroll, zksync, linea, blast, sei + sector: dex + short_description: The `dex.trades` table captures detailed data on trades executed via decentralized exchanges (DEXs). This table contains a detailed breakdown of trade execution containing one or many trades per transaction. + contributors: 0xRob, hosuke, jeff-dude, tomfutago + config: + tags: [ 'dex', 'trades'] + description: '{{ doc("dex_trades_doc") }}' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - project + - version + - tx_hash + - evt_index + columns: + - &blockchain + name: blockchain + description: "Blockchain on which this trade occurred" + - &project + name: project + description: "Name of the dex on which the trade occurred" + tests: + - relationships: + to: ref('dex_info') + field: project + - &version + name: version + description: "Version of the DEX protocol/contract" + - &block_month + name: block_month + description: "UTC event block month" + - &block_date + name: block_date + description: "UTC event block date" + - &block_time + name: block_time + description: "UTC event block time" + - &block_number + name: block_number + description: "Block number of the block in which the trade occurred" + - &token_bought_symbol + name: token_bought_symbol + description: "Symbol of the token bought in the trade" + - &token_sold_symbol + name: token_sold_symbol + description: "Symbol of the token sold in the trade" + - &token_pair + name: token_pair + description: "symbol pair for the tokens involved in the trade. e.g. 'ETH/USDC'. Always alphabetical order, not trade order." + - &token_bought_amount + name: token_bought_amount + description: "Amount of the token bought in the display unit" + - &token_sold_amount + name: token_sold_amount + description: "Amount of the token sold in the display unit" + - &token_bought_amount_raw + name: token_bought_amount_raw + description: "Amount of the token bought in the base unit" + - &token_sold_amount_raw + name: token_sold_amount_raw + description: "Amount of the token sold in the base unit" + - &amount_usd + name: amount_usd + description: "USD value of the trade at time of execution. Can be null if we don't have enough data to calculate the value." + tests: + - dbt_utils.accepted_range: + max_value: 1000000000 # $1b is an arbitrary number, intended to flag outlier amounts early + - &token_bought_address + name: token_bought_address + description: "Contract address of the token bought" + - &token_sold_address + name: token_sold_address + description: "Contract address of the token sold" + - &taker + name: taker + description: "Address of account which purchased tokens. Can be contracts or EOA addresses. " + - &maker + name: maker + description: "Address of account which sold tokens. Can be contracts or EOA addresses." + - &project_contract_address + name: project_contract_address + description: "Smart contract address which emitted the event associated with this trade. Can be the a Pool Contract, Router Contract, or other contract associated with the DEX." + - &tx_hash + name: tx_hash + description: "The hash of the transaction that this trade was included in" + - &tx_from + name: tx_from + description: "EOA address that sent the trade transaction, usually the trader's address, but can also be keeper bots, arbitrage bots, etc." + - &tx_to + name: tx_to + description: "Address that got called in the first call of this transaction" + - &evt_index + name: evt_index + description: "Index of the event in the transaction. Can be used to uniquely identify the order of trades within in a transaction" + + - name: log_decoded_dex_base_trades + meta: + blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, optimism, polygon, scroll, zksync, linea, blast, sei + sector: dex + contributors: 0xRob, hosuke, jeff-dude, tomfutago, viniabussafi + config: + tags: [ 'dex' ] + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - project + - version + - tx_hash + - evt_index + columns: + - *blockchain + - *project + - *version + - *block_month + - *block_date + - *block_time + - *block_number + - *token_bought_amount_raw + - *token_sold_amount_raw + - *token_bought_address + - *token_sold_address + - *taker + - *maker + - *project_contract_address + - *tx_hash + - *evt_index + - *tx_from + - *tx_to \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml new file mode 100644 index 00000000000..340772338ef --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml @@ -0,0 +1,44 @@ +version: 2 + +models: + + - name: uniswap_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: jeff-dude, masquot, soispoke, hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2' ] + description: "uniswap ethereum v2 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('uniswap_ethereum_base_trades_seed') + filter: + version: 2 + + - name: uniswap_v3_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: jeff-dude, masquot, soispoke, hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3' ] + description: "uniswap ethereum v3 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('uniswap_ethereum_base_trades_seed') + filter: + version: 3 + + + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/airswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/airswap_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/airswap_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/airswap_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/apeswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/apeswap_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/apeswap_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/apeswap_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/bancor_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/bancor_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/bancor_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/bancor_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/clipper_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/clipper_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/clipper_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/clipper_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/curve_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/curve_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/curve_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/curve_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/defiswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/defiswap_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/defiswap_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/defiswap_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/dfx_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dfx_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/dfx_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dfx_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dodo_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dodo_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/integral_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/integral_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/integral_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/integral_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/mauve_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mauve_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/mauve_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mauve_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/mstable_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mstable_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/mstable_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mstable_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/swapr_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swapr_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/swapr_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swapr_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/xchange_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/xchange_ethereum_base_trades.sql similarity index 100% rename from dbt_subprojects/dex/models/trades/ethereum/platforms/xchange_ethereum_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/xchange_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql new file mode 100644 index 00000000000..403d08e648a --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql @@ -0,0 +1,62 @@ +{{ config( + schema = 'dex' + , alias = 'log_decoded_dex_base_trades' + , partition_by = ['block_month', 'blockchain', 'project'] + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set models = [ + ref('mass_decoded_dex_trades_ethereum') +] %} + +with base_union as ( + SELECT * + FROM + ( + {% for model in models %} + SELECT + blockchain + , project + , version + , factory_address + , dex_type + , block_month + , block_date + , block_time + , block_number + , cast(token_bought_amount_raw as uint256) as token_bought_amount_raw + , cast(token_sold_amount_raw as uint256) as token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + , tx_from + , tx_to + , row_number() over (partition by tx_hash, evt_index order by tx_hash) as duplicates_rank + FROM + {{ model }} + WHERE + token_sold_amount_raw >= 0 and token_bought_amount_raw >= 0 + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) + WHERE + duplicates_rank = 1 +) +select + * +from + base_union diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_docs_block.md b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_docs_block.md new file mode 100644 index 00000000000..f282e88c5d4 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_docs_block.md @@ -0,0 +1,22 @@ +{% docs log_decoded_dex_trades_doc %} + +## Table Description + +The `dex.trades` table captures detailed data on trades executed via decentralized exchanges (DEXs). This table captures all trade events that happen across different liqudity sources. + +## Functional Overview + +The `dex.trades` table provides an in-depth view of trades on decentralized exchanges like uniswap or curve. This table includes entries for each segment of a trade that passes through different liquidity pools, as well as single-step trades. For example, a user may initiate a trade to swap USDC for PEPE. If this trade is executed through multiple liquidity pools, such as USDC-WETH and WETH-PEPE, the `dex.trades` table will record each segment of the trade as a separate entry. Conversely, a single-step trade, such as directly swapping USDC for ETH, will be recorded as a single entry. + +This detailed approach allows for granular analysis of trade execution paths, enabling users to: + +- **Analyze Liquidity Sources**: Understand which liquidity pools are used and how they interact in both single-step and multi-step trades. +- **Track Trade Execution Paths**: Follow the exact route a trade takes across different DEXs and liquidity pools. +- **Assess Slippage and Execution Quality**: Evaluate the impact of each step on the overall trade execution, including slippage and price changes. +- **Monitor Market Dynamics**: Gain insights into the behavior and dynamics of different liquidity pools and DEXs over time. + +By providing comprehensive trade details, the `dex.trades` table supports advanced analytics and research into DEX trading behavior and liquidity management. + +Complimentary tables include `dex_aggregator.trades`, in which trade-intents that are routed through aggregators are recorded. The volume routed through aggregators is also recorded in the dex.trades table, one row in dex_aggregator trades corresponds to one or more rows in dex.trades. + +{% enddocs %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql new file mode 100644 index 00000000000..35c0e191c76 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql @@ -0,0 +1,45 @@ +{{ config( + schema = 'dex' + , alias = 'log_decoded_trades' + , partition_by = ['block_month', 'blockchain', 'project'] + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + , post_hook='{{ expose_spells(\'[ + "arbitrum" + , "avalanche_c" + , "base" + , "blast" + , "bnb" + , "celo" + , "ethereum" + , "fantom" + , "gnosis" + , "linea" + , "mantle" + , "nova" + , "optimism" + , "polygon" + , "scroll" + , "sei" + , "zkevm" + , "zksync" + , "zora" + ]\', + "sector", + "dex", + \'["hosuke", "0xrob", "jeff-dude", "tomfutago"]\') }}') +}} + +with dexs AS ( + {{ + enrich_dex_trades( + base_trades = ref('log_decoded_dex_base_trades') + , filter = "project != 'curve'" + , tokens_erc20_model = source('tokens', 'erc20') + ) + }} +) + diff --git a/dbt_subprojects/dex/models/trades/ethereum/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/_schema.yml deleted file mode 100644 index fba051b0a13..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/_schema.yml +++ /dev/null @@ -1,601 +0,0 @@ -version: 2 - -models: - - name: dex_ethereum_base_trades - tests: - - check_dex_info_relationship - - - name: uniswap_v1_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: jeff-dude, masquot, soispoke, hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v1'] - description: "uniswap ethereum v1 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('uniswap_ethereum_base_trades_seed') - filter: - version: 1 - - - name: uniswap_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: jeff-dude, masquot, soispoke, hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2' ] - description: "uniswap ethereum v2 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('uniswap_ethereum_base_trades_seed') - filter: - version: 2 - - - name: uniswap_v3_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: jeff-dude, masquot, soispoke, hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3' ] - description: "uniswap ethereum v3 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('uniswap_ethereum_base_trades_seed') - filter: - version: 3 - - - - name: defiswap_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: defiswap - contributors: pandajackson42, 0xRob, hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'defiswap' ] - description: "Defiswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('defiswap_ethereum_base_trades_seed') - - - - name: airswap_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: airswap - contributors: hosuke, jeff-dude, ivigamberdiev, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'airswap' ] - description: "Defiswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('airswap_ethereum_base_trades_seed') - - - - name: sushiswap_v1_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: sushiswap - contributors: pandajackson42, 0xRob, hosuke, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'sushiswap', 'v1' ] - description: "sushiswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('sushiswap_ethereum_base_trades_seed') - filter: - version: 1 - - - - name: sushiswap_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: sushiswap - contributors: pandajackson42, 0xRob, hosuke, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'sushiswap', 'v2' ] - description: "sushiswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('sushiswap_ethereum_base_trades_seed') - filter: - version: 2 - - - - name: carbon_defi_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: carbon_defi - contributors: tiagofilipenunes, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'carbon_defi' ] - description: "Carbon_defi ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('carbon_defi_ethereum_base_trades_seed') - - - - name: apeswap_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: apeswap - contributors: hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'apeswap' ] - description: apeswap base trades - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('apeswap_ethereum_base_trades_seed') - - - name: pancakeswap_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: pancakeswap - contributors: chef_seaweed, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'pancakeswap', 'uniswap', 'v2' ] - description: "Pancakeswap Ethereum v2 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('pancakeswap_ethereum_base_trades_seed') - filter: - version: - - 2 - - mmpool - - - name: shibaswap_v1_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: shibaswap - contributors: 0xRob, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'shibaswap', 'uniswap', 'v2' ] - description: "sushiswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('shibaswap_ethereum_base_trades_seed') - filter: - version: 1 - - - name: pancakeswap_v3_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: pancakeswap - contributors: chef_seaweed, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'pancakeswap', 'uniswap', 'v3' ] - description: "Pancakeswap Ethereum v3 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('pancakeswap_ethereum_base_trades_seed') - filter: - version: 3 - - - name: balancer_v1_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: balancer - contributors: bizzyvinci, thetroyharris, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'balancer' ] - description: "Balancer v1 ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('balancer_ethereum_base_trades_seed') - filter: - version: 1 - - - name: balancer_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: balancer - contributors: bizzyvinci, thetroyharris, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'balancer' ] - description: "Balancer v2 ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('balancer_ethereum_base_trades_seed') - filter: - version: 2 - - - name: fraxswap_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: fraxswap - contributors: kndlexi, tomfutago - config: - tags: ['ethereum', 'dex', 'trades', 'fraxswap', 'uniswap', 'v2'] - description: "Fraxswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('fraxswap_ethereum_base_trades_seed') - filter: - version: 1 - - - name: bancor_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: bancor - contributors: tian7, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'bancor' ] - description: "Bancor ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('bancor_ethereum_base_trades_seed') - - - name: verse_dex_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: verse_dex - contributors: Henrystats, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'verse_dex' ] - description: "Verse ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('verse_dex_ethereum_base_trades_seed') - - - name: swapr_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: swapr - contributors: cryptoleishen, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'swapr', 'uniswap', 'v2' ] - description: "Verse ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('swapr_ethereum_base_trades_seed') - - - name: mauve_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: mauve - contributors: jeff-dude, masquot, soispoke, raphaelr, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'mauve' ] - description: "Mauve ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('mauve_ethereum_base_trades_seed') - - - name: dfx_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: dfx - contributors: Henrystats, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'dfx' ] - description: "DFX ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('dfx_ethereum_base_trades_seed') - - - name: dodo_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: dodo - contributors: owen05, scoffie, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'dodo' ] - description: "Dodo ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('dodo_ethereum_base_trades_seed') - filter: - version: - - 1 - - 2_dvm - - 2_dpp - - 2_dsp - - - - name: integral_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: integral - contributors: integralhq, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'integral', 'uniswap', 'v2' ] - description: "Integral ethereum v3 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('integral_ethereum_base_trades_seed') - - - - name: maverick_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: maverick - contributors: get620v, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'maverick' ] - description: "Maverick ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('maverick_ethereum_base_trades_seed') - filter: - version: 1 - - - name: maverick_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: maverick - contributors: get620v - config: - tags: [ 'ethereum', 'dex', 'trades', 'maverick' ] - description: "Maverick ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('maverick_ethereum_base_trades_seed') - filter: - version: 2 - - - name: clipper_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: clipper - contributors: 0xRob, amalashkevich, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'clipper' ] - description: "clipper ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('clipper_ethereum_base_trades_seed') - filter: - version: - - 1 - - 2 - - 3 - - 4 - - - - name: mstable_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: mstable - contributors: ripple3, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'mstable' ] - description: "mstable ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('mstable_ethereum_base_trades_seed') - filter: - version: - - masset - - feederpool - - - name: kyberswap_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: kyberswap - contributors: ppclunghe, gregshestakovlido, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'kyberswap', 'uniswap', 'v2' ] - description: "kyberswap ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('kyberswap_ethereum_base_trades_seed') - filter: - version: - - classic - - elastic - - elastic_2 - - - name: xchange_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: xchange - contributors: mike-x7f, tomfutago - config: - tags: [ 'ethereum', 'dex', 'trades', 'xchange', 'uniswap', 'v2' ] - description: "xchange ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('xchange_ethereum_base_trades_seed') - - - name: curve_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: curve - contributors: dsalv, yulesa, ilemi, jeff-dude, tomfutago - config: - tags: ['ethereum', 'dex', 'trades', 'curve'] - description: "Curve ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('curvefi_ethereum_base_trades_seed') - filter: - version: - - Factory V1 Meta - - Factory V1 Plain - - Factory V1 Stableswap Plain - - Factory V2 - - Factory V2 updated - - Regular - - - name: solidly_v3_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: solidly - contributors: SolidlyLabs - config: - tags: [ 'ethereum', 'dex', 'trades', 'solidly' ] - description: "solidly v3 ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('solidly_v3_ethereum_base_trades_seed') - - - name: swaap_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: swaap - contributors: borelien - config: - tags: [ 'ethereum', 'dex', 'trades', 'swaap', 'v2'] - description: "swaap v2 ethereum base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('swaap_ethereum_base_trades_seed') - filter: - version: 2 diff --git a/dbt_subprojects/dex/package-lock.yml b/dbt_subprojects/dex/package-lock.yml index 709885d7a0b..5e486a0dde8 100644 --- a/dbt_subprojects/dex/package-lock.yml +++ b/dbt_subprojects/dex/package-lock.yml @@ -1,4 +1,4 @@ packages: -- package: dbt-labs/dbt_utils - version: 1.2.0 -sha1_hash: eb1031c07e7c89332527e572f2e44613ce5b62bf + - package: dbt-labs/dbt_utils + version: 1.2.0 +sha1_hash: d4f259856543b0ef301e0b3b0bbc94ccb6b12a54 From 7e301be13ea66c08ec7ad2dd7aa81189a0b8fff0 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 12:41:37 +0200 Subject: [PATCH 33/86] rename macro --- .../dex/models/_log_decoded_trades/log_decoded_dex_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql index 35c0e191c76..83c2552f8cf 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql @@ -35,7 +35,7 @@ with dexs AS ( {{ - enrich_dex_trades( + log_decoded_enrich_dex_trades( base_trades = ref('log_decoded_dex_base_trades') , filter = "project != 'curve'" , tokens_erc20_model = source('tokens', 'erc20') From 7cbd330247c518459441faf4bc95812f5d7e2597 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 12:59:05 +0200 Subject: [PATCH 34/86] rename enrich_dex_trades macro to log_decoded_enrich_dex_trades for clarity and consistency --- .../dex/macros/models/log_decoded_enrich_dex_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql b/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql index 74bcbd98c9d..4edaf818d37 100644 --- a/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql +++ b/dbt_subprojects/dex/macros/models/log_decoded_enrich_dex_trades.sql @@ -1,4 +1,4 @@ -{% macro enrich_dex_trades( +{% macro log_decoded_enrich_dex_trades( base_trades = null , filter = null , tokens_erc20_model = null From ae8d63f52fb927a3bd21d1b4c16656a42ee3f1ea Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:13:23 +0200 Subject: [PATCH 35/86] add name to pair_index in Uniswap V2 factory mass decoding and join creation traces for accurate factory resolution --- .../uniswap_v2/uniswap_v2_factory_mass_decoding.sql | 2 +- .../in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql | 4 ++++ .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql index b3b0b516155..f164a8bbd68 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_factory_mass_decoding.sql @@ -24,7 +24,7 @@ { "indexed": false, "internalType": "uint256", - "name": "", + "name": "pair_index", "type": "uint256" } ], diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 6801eb12554..d1e4b342b7b 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -29,6 +29,10 @@ WITH dexs AS INNER JOIN {{ Factory_evt_PairCreated }} f ON f.{{ pair_column_name }} = t.contract_address + --some scammers emitted events with established pair addresses, joining in the the creation trace to resolve correct factory + INNER JOIN {{ source('ethereum', 'creation_traces') }} ct + ON f.{{ pair_column_name }} = ct.address + AND f.contract_address = ct."from" {% if is_incremental() %} WHERE {{ incremental_predicate('t.block_time') }} diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 08e1207547a..56e1ce2581f 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -35,6 +35,10 @@ WITH dexs AS INNER JOIN {{ Factory_evt_PoolCreated }} f ON f.{{ pair_column_name }} = t.contract_address + --some scammers emitted events with established pair addresses, joining in the the creation trace to resolve to correct factory + INNER JOIN {{ source('ethereum', 'creation_traces') }} ct + ON f.{{ pair_column_name }} = ct.address + AND f.contract_address = ct."from" {% if is_incremental() %} WHERE {{ incremental_predicate('t.evt_block_time') }} From 549657a8722b37cf61803950c9fdf1557cb02bcf Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:17:14 +0200 Subject: [PATCH 36/86] trigger run --- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 56e1ce2581f..0d6b5a17828 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -31,7 +31,7 @@ WITH dexs AS , t.index as evt_index , f.contract_address as factory_address FROM - {{ Pair_evt_Swap }} t + {{ Pair_evt_Swap }} t INNER JOIN {{ Factory_evt_PoolCreated }} f ON f.{{ pair_column_name }} = t.contract_address From 30bef8ef9a8176fe9dba1adf5ad23af0a0cf9972 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:36:22 +0200 Subject: [PATCH 37/86] add factory address --- .../decoded-in-flight/mass_decoded_dex_trades_ethereum.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql index 017906daa0a..b66dc73198d 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -19,6 +19,8 @@ WITH base_union AS ( blockchain , project , version + , dex_type + , factory_address , block_month , block_date , block_time From 0245c6596efeb4b7b4ac672e71ba4481b5f2bd21 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:46:08 +0200 Subject: [PATCH 38/86] Restored accidentally deleted folder --- .../dex/models/trades/ethereum/_schema.yml | 601 ++++++++++++++++++ .../ethereum/decoded-in-flight/_schema.yml | 75 +++ .../mass_decoded_dex_trades_ethereum.sql | 52 ++ .../uniswap_v2_factory_decoding_ethereum.sql | 16 + .../uniswap_v2_fork_mapping_ethereum.sql | 56 ++ .../uniswap_v2_forks_base_trades_ethereum.sql | 20 + .../uniswap_v2_pool_decoding_ethereum.sql | 16 + .../uniswap_v3_factory_decoding_ethereum.sql | 17 + .../uniswap_v3_fork_mapping_ethereum.sql | 19 + .../uniswap_v3_forks_base_trades_ethereum.sql | 21 + .../uniswap_v3_pool_decoding_ethereum.sql | 16 + .../airswap_ethereum_base_trades.sql | 29 + .../apeswap_ethereum_base_trades.sql | 20 + .../balancer_v1_ethereum_base_trades.sql | 19 + .../balancer_v2_ethereum_base_trades.sql | 19 + .../platforms/bancor_ethereum_base_trades.sql | 106 +++ .../carbon_defi_ethereum_base_trades.sql | 22 + .../clipper_ethereum_base_trades.sql | 28 + .../platforms/curve_ethereum_base_trades.sql | 115 ++++ .../defiswap_ethereum_base_trades.sql | 20 + .../platforms/dfx_ethereum_base_trades.sql | 49 ++ .../platforms/dodo_ethereum_base_trades.sql | 54 ++ .../fraxswap_ethereum_base_trades.sql | 21 + .../integral_ethereum_base_trades.sql | 21 + .../kyberswap_ethereum_base_trades.sql | 89 +++ .../platforms/mauve_ethereum_base_trades.sql | 21 + .../maverick_ethereum_base_trades.sql | 21 + .../maverick_v2_ethereum_base_trades.sql | 21 + .../mstable_ethereum_base_trades.sql | 70 ++ .../pancakeswap_v2_ethereum_base_trades.sql | 87 +++ .../pancakeswap_v3_ethereum_base_trades.sql | 21 + .../shibaswap_v1_ethereum_base_trades.sql | 21 + .../solidly_v3_ethereum_base_trades.sql | 21 + .../sushiswap_v1_ethereum_base_trades.sql | 21 + .../sushiswap_v2_ethereum_base_trades.sql | 21 + .../swaap_v2_ethereum_base_trades.sql | 19 + .../platforms/swapr_ethereum_base_trades.sql | 21 + .../uniswap_v1_ethereum_base_trades.sql | 83 +++ .../uniswap_v2_ethereum_base_trades.sql | 38 ++ .../uniswap_v3_ethereum_base_trades.sql | 20 + .../verse_dex_ethereum_base_trades.sql | 21 + .../xchange_ethereum_base_trades.sql | 21 + 42 files changed, 2069 insertions(+) create mode 100644 dbt_subprojects/dex/models/trades/ethereum/_schema.yml create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/airswap_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/apeswap_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/bancor_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/clipper_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/curve_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/defiswap_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/dfx_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/integral_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/mauve_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/mstable_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/swapr_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/ethereum/platforms/xchange_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/_schema.yml new file mode 100644 index 00000000000..fba051b0a13 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/_schema.yml @@ -0,0 +1,601 @@ +version: 2 + +models: + - name: dex_ethereum_base_trades + tests: + - check_dex_info_relationship + + - name: uniswap_v1_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: jeff-dude, masquot, soispoke, hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v1'] + description: "uniswap ethereum v1 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('uniswap_ethereum_base_trades_seed') + filter: + version: 1 + + - name: uniswap_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: jeff-dude, masquot, soispoke, hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2' ] + description: "uniswap ethereum v2 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('uniswap_ethereum_base_trades_seed') + filter: + version: 2 + + - name: uniswap_v3_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: jeff-dude, masquot, soispoke, hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3' ] + description: "uniswap ethereum v3 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('uniswap_ethereum_base_trades_seed') + filter: + version: 3 + + + - name: defiswap_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: defiswap + contributors: pandajackson42, 0xRob, hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'defiswap' ] + description: "Defiswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('defiswap_ethereum_base_trades_seed') + + + - name: airswap_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: airswap + contributors: hosuke, jeff-dude, ivigamberdiev, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'airswap' ] + description: "Defiswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('airswap_ethereum_base_trades_seed') + + + - name: sushiswap_v1_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: sushiswap + contributors: pandajackson42, 0xRob, hosuke, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'sushiswap', 'v1' ] + description: "sushiswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('sushiswap_ethereum_base_trades_seed') + filter: + version: 1 + + + - name: sushiswap_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: sushiswap + contributors: pandajackson42, 0xRob, hosuke, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'sushiswap', 'v2' ] + description: "sushiswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('sushiswap_ethereum_base_trades_seed') + filter: + version: 2 + + + - name: carbon_defi_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: carbon_defi + contributors: tiagofilipenunes, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'carbon_defi' ] + description: "Carbon_defi ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('carbon_defi_ethereum_base_trades_seed') + + + - name: apeswap_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: apeswap + contributors: hosuke + config: + tags: [ 'ethereum', 'dex', 'trades', 'apeswap' ] + description: apeswap base trades + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('apeswap_ethereum_base_trades_seed') + + - name: pancakeswap_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: pancakeswap + contributors: chef_seaweed, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'pancakeswap', 'uniswap', 'v2' ] + description: "Pancakeswap Ethereum v2 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('pancakeswap_ethereum_base_trades_seed') + filter: + version: + - 2 + - mmpool + + - name: shibaswap_v1_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: shibaswap + contributors: 0xRob, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'shibaswap', 'uniswap', 'v2' ] + description: "sushiswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('shibaswap_ethereum_base_trades_seed') + filter: + version: 1 + + - name: pancakeswap_v3_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: pancakeswap + contributors: chef_seaweed, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'pancakeswap', 'uniswap', 'v3' ] + description: "Pancakeswap Ethereum v3 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('pancakeswap_ethereum_base_trades_seed') + filter: + version: 3 + + - name: balancer_v1_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: balancer + contributors: bizzyvinci, thetroyharris, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'balancer' ] + description: "Balancer v1 ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('balancer_ethereum_base_trades_seed') + filter: + version: 1 + + - name: balancer_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: balancer + contributors: bizzyvinci, thetroyharris, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'balancer' ] + description: "Balancer v2 ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('balancer_ethereum_base_trades_seed') + filter: + version: 2 + + - name: fraxswap_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: fraxswap + contributors: kndlexi, tomfutago + config: + tags: ['ethereum', 'dex', 'trades', 'fraxswap', 'uniswap', 'v2'] + description: "Fraxswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('fraxswap_ethereum_base_trades_seed') + filter: + version: 1 + + - name: bancor_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: bancor + contributors: tian7, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'bancor' ] + description: "Bancor ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('bancor_ethereum_base_trades_seed') + + - name: verse_dex_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: verse_dex + contributors: Henrystats, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'verse_dex' ] + description: "Verse ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('verse_dex_ethereum_base_trades_seed') + + - name: swapr_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: swapr + contributors: cryptoleishen, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'swapr', 'uniswap', 'v2' ] + description: "Verse ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('swapr_ethereum_base_trades_seed') + + - name: mauve_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: mauve + contributors: jeff-dude, masquot, soispoke, raphaelr, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'mauve' ] + description: "Mauve ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('mauve_ethereum_base_trades_seed') + + - name: dfx_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: dfx + contributors: Henrystats, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'dfx' ] + description: "DFX ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('dfx_ethereum_base_trades_seed') + + - name: dodo_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: dodo + contributors: owen05, scoffie, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'dodo' ] + description: "Dodo ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('dodo_ethereum_base_trades_seed') + filter: + version: + - 1 + - 2_dvm + - 2_dpp + - 2_dsp + + + - name: integral_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: integral + contributors: integralhq, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'integral', 'uniswap', 'v2' ] + description: "Integral ethereum v3 base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('integral_ethereum_base_trades_seed') + + + - name: maverick_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: maverick + contributors: get620v, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'maverick' ] + description: "Maverick ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('maverick_ethereum_base_trades_seed') + filter: + version: 1 + + - name: maverick_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: maverick + contributors: get620v + config: + tags: [ 'ethereum', 'dex', 'trades', 'maverick' ] + description: "Maverick ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('maverick_ethereum_base_trades_seed') + filter: + version: 2 + + - name: clipper_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: clipper + contributors: 0xRob, amalashkevich, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'clipper' ] + description: "clipper ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('clipper_ethereum_base_trades_seed') + filter: + version: + - 1 + - 2 + - 3 + - 4 + + + - name: mstable_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: mstable + contributors: ripple3, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'mstable' ] + description: "mstable ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('mstable_ethereum_base_trades_seed') + filter: + version: + - masset + - feederpool + + - name: kyberswap_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: kyberswap + contributors: ppclunghe, gregshestakovlido, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'kyberswap', 'uniswap', 'v2' ] + description: "kyberswap ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('kyberswap_ethereum_base_trades_seed') + filter: + version: + - classic + - elastic + - elastic_2 + + - name: xchange_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: xchange + contributors: mike-x7f, tomfutago + config: + tags: [ 'ethereum', 'dex', 'trades', 'xchange', 'uniswap', 'v2' ] + description: "xchange ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('xchange_ethereum_base_trades_seed') + + - name: curve_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: curve + contributors: dsalv, yulesa, ilemi, jeff-dude, tomfutago + config: + tags: ['ethereum', 'dex', 'trades', 'curve'] + description: "Curve ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('curvefi_ethereum_base_trades_seed') + filter: + version: + - Factory V1 Meta + - Factory V1 Plain + - Factory V1 Stableswap Plain + - Factory V2 + - Factory V2 updated + - Regular + + - name: solidly_v3_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: solidly + contributors: SolidlyLabs + config: + tags: [ 'ethereum', 'dex', 'trades', 'solidly' ] + description: "solidly v3 ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('solidly_v3_ethereum_base_trades_seed') + + - name: swaap_v2_ethereum_base_trades + meta: + blockchain: ethereum + sector: dex + project: swaap + contributors: borelien + config: + tags: [ 'ethereum', 'dex', 'trades', 'swaap', 'v2'] + description: "swaap v2 ethereum base trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('swaap_ethereum_base_trades_seed') + filter: + version: 2 diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml new file mode 100644 index 00000000000..eda94470c32 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml @@ -0,0 +1,75 @@ +version: 2 + +models: + - name: uniswap_v2_factory_decoding_ethereum + description: > + mass decoding of all forks of uniswap v2 factory contract on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + + - name: uniswap_v2_pool_decoding_ethereum + description: > + mass decoding of all forks of uniswap v2 pool contracts on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + + - name: uniswap_v2_fork_mapping_ethereum + description: > + mapping of all forks of uniswap v2 factory contract on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - factory_address + columns: + - name: factory_address + description: "address of the factory contract" + - name: project_name + description: "name of the project associated with the factory" + + - name: uniswap_v2_forks_base_trades_ethereum + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2', 'forks' ] + description: "base trades for all forks of uniswap v2 on ethereum" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + + - name: uniswap_v3_forks_base_trades_ethereum + meta: + blockchain: ethereum + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3', 'forks' ] + description: "base trades for all forks of uniswap v3 on ethereum" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + + - name: mass_decoded_dex_trades_ethereum + description: "all dex trades on ethereum, mass decoded" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql new file mode 100644 index 00000000000..017906daa0a --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -0,0 +1,52 @@ +{{ config( + schema = 'dex_ethereum' + , alias = 'mass_decoded_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + + ref('uniswap_v2_forks_base_trades_ethereum') + , ref('uniswap_v3_forks_base_trades_ethereum') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + , factory_address + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'ethereum' + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql new file mode 100644 index 00000000000..adbdc9fdcc4 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'mass_decoding_ethereum', + alias = 'uniswap_v2_factory_evt_PairCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_factory_mass_decoding( + logs = source('ethereum', 'logs') +)}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql new file mode 100644 index 00000000000..236a66c5342 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql @@ -0,0 +1,56 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v2_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') + , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') + , (0x9deb29c9a4c7a88a3c0257393b7f3335338d9a9d, 'crodefi') + , (0x1097053fd2ea711dad45caccc45eff7548fcb362, 'pancakeswap_v2') + , (0x43ec799eadd63848443e2347c49f5f52e8fe0f6f, 'fraxswap') + , (0xee3e9e46e34a27dc755a63e2849c9913ee1a06e2, 'verse_dex') + , (0xc480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6, 'integral_size') + , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') + , (0x4eef5746ed22a2fd368629c1852365bf5dcb79f1, 'convergence') + , (0x1e895bfe59e3a5103e8b7da3897d1f2391476f3c, 'DooarSwap') + , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') + , (0x75e48c954594d64ef9613aeef97ad85370f13807, 'sakeswap') + , (0x696708db871b77355d6c2be7290b27cf0bb9b24b, 'linkswap_v1') + , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') + , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') + , (0x0388c1e0f210abae597b7de712b9510c6c36c857, 'luaswap') + , (0xa40ec8a93293a3179d4b544239916c1b68cb47b6, 'SunflowerSwap') + , (0x460b2005b3318982feada99f7ebf13e1d6f6effe, 'pepedex') + , (0x1264f802364e0776b9a9e3d161b43c7333ac08b2, 'rhino_fi') + , (0x7de800467afce442019884f51a4a1b9143a34fac, 'xchange') + , (0xd87ad19db2c4ccbf897106de034d52e3dd90ea60, 'plasmaswap') + , (0x46adc1c052fafd590f56c42e379d7d16622835a2, 'yape') + , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') + , (0xd34971bab6e5e356fd250715f5de0492bb070452, 'swapr') + , (0x35113a300ca0d7621374890abfeac30e88f214b1, 'SaitaSwap') + , (0xb076b06f669e682609fb4a8c6646d2619717be4b, 'fraxswap') + , (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') + , (0x5fbe219e88f6c6f214ce6f5b1fcaa0294f31ae1b, 'gammaswap') + , (0xbae5dc9b19004883d0377419fef3c2c8832d7d7b, 'apeswap') + , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'btswap') + , (0x26f53fbadeeb777fb2a122dc703433d79241b64e, 'light_dao') + , (0x08e7974cacf66c5a92a37c221a15d3c30c7d97e0, 'unifi') + , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') + , (0xf028f723ed1d0fe01cc59973c49298aa95c57472, 'SashimiSwap') + , (0x54f454d747e037da288db568d4121117eab34e79, 'bbb') + , (0x2d723f60ad8da76286b2ac120498a5ea6babc792, 'neopin') + , (0x91fAe1bc94A9793708fbc66aDcb59087C46dEe10, 'radioshack') + , (0xe185e5335d68c2a18564b4b43bdf4ed86337ee70, 'quantoswap') +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql new file mode 100644 index 00000000000..dae82d4239f --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -0,0 +1,20 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v2_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_forks_trades( + blockchain = 'ethereum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql new file mode 100644 index 00000000000..e817fe8d2f3 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'mass_decoding_ethereum', + alias = 'uniswap_v2_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_pool_mass_decoding( + logs = source('ethereum', 'logs') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql new file mode 100644 index 00000000000..5f77de40f22 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql @@ -0,0 +1,17 @@ +{{ config( + + schema = 'mass_decoding_ethereum', + alias = 'uniswap_v3_factory_evt_PoolCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_factory_mass_decoding( + logs = source('ethereum', 'logs') +)}} + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql new file mode 100644 index 00000000000..79021547194 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql @@ -0,0 +1,19 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v3_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql new file mode 100644 index 00000000000..074296af85b --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -0,0 +1,21 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v3_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_forks_trades( + blockchain = 'ethereum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') + , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_ethereum') +)}} + diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql new file mode 100644 index 00000000000..53931819cbc --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'dex_mass_decoding_ethereum', + alias = 'uniswap_v3_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_pool_mass_decoding( + logs = source('ethereum', 'logs') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/airswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/airswap_ethereum_base_trades.sql new file mode 100644 index 00000000000..3828b9ac0e8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/airswap_ethereum_base_trades.sql @@ -0,0 +1,29 @@ +{{ + config( + schema = 'airswap_ethereum', + alias ='base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% + set config_sources = [ + {'version': 'light', 'source': 'Light_evt_Swap'}, + {'version': 'light_v0', 'source': 'Light_v0_evt_Swap'}, + {'version': 'swap', 'source': 'swap_evt_Swap'}, + {'version': 'swap_v3', 'source': 'Swap_v3_evt_Swap'}, + {'version': 'swap_erc20_v4', 'source': 'SwapERC20_v4_evt_SwapERC20'}, + ] +%} + +{{ + airswap_compatible_trades( + blockchain = 'ethereum', + project = 'airswap', + sources = config_sources + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/apeswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/apeswap_ethereum_base_trades.sql new file mode 100644 index 00000000000..1a60edd1b7a --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/apeswap_ethereum_base_trades.sql @@ -0,0 +1,20 @@ +{{ config( + schema = 'apeswap_ethereum' + , alias = 'base_trades' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'apeswap', + version = '1', + Pair_evt_Swap = source('apeswap_ethereum', 'ApePair_evt_Swap'), + Factory_evt_PairCreated = source('apeswap_ethereum', 'ApeFactory_evt_PairCreated') + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql new file mode 100644 index 00000000000..845d9a91dda --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql @@ -0,0 +1,19 @@ +{{ + config( + schema = 'balancer_v1_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + balancer_compatible_v1_trades( + blockchain = 'ethereum', + project = 'balancer', + version = '1' + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql new file mode 100644 index 00000000000..da29d9dea1d --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql @@ -0,0 +1,19 @@ +{{ + config( + schema = 'balancer_v2_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + balancer_compatible_v2_trades( + blockchain = 'ethereum', + project = 'balancer', + version = '2' + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/bancor_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/bancor_ethereum_base_trades.sql new file mode 100644 index 00000000000..0d887105d71 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/bancor_ethereum_base_trades.sql @@ -0,0 +1,106 @@ +{{ + config( + schema = 'bancor_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} + +WITH conversions AS ( + {% for n in range(6,11) %} + SELECT + t.evt_block_number, + t.evt_block_time, + t._trader, + t._toAmount, + t._fromAmount, + t._toToken, + t._fromToken, + t.contract_address, + t.evt_tx_hash, + t.evt_index + FROM {{ source('bancornetwork_ethereum', 'BancorNetwork_v' ~ n ~ '_evt_Conversion' )}} t + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +), + +dexs AS ( + SELECT + '1' AS version, + t.evt_block_number AS block_number, + t.evt_block_time AS block_time, + t._trader AS taker, + CAST(NULL AS VARBINARY) AS maker, + t._toAmount AS token_bought_amount_raw, + t._fromAmount AS token_sold_amount_raw, + CAST(NULL as double) AS amount_usd, + CASE + WHEN t._toToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} + ELSE t._toToken + END AS token_bought_address, + CASE + WHEN t._fromToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} + ELSE t._fromToken + END AS token_sold_address, + t.contract_address AS project_contract_address, + t.evt_tx_hash AS tx_hash, + t.evt_index + FROM conversions t + + UNION ALL + + SELECT + '3' AS version, + t.evt_block_number AS block_number, + t.evt_block_time AS block_time, + t.trader AS taker, + CAST(NULL AS VARBINARY) AS maker, + t.targetAmount AS token_bought_amount_raw, + t.sourceAmount AS token_sold_amount_raw, + CAST(NULL as double) AS amount_usd, + CASE + WHEN t.targetToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} + ELSE t.targetToken + END AS token_bought_address, + CASE + WHEN t.sourceToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} + ELSE t.sourceToken + END AS token_sold_address, + t.contract_address AS project_contract_address, + t.evt_tx_hash AS tx_hash, + t.evt_index + FROM {{ source('bancor3_ethereum', 'BancorNetwork_evt_TokensTraded') }} t + {% if is_incremental() %} + WHERE {{ incremental_predicate('t.evt_block_time') }} + {% endif %} +) + +SELECT + 'ethereum' AS blockchain, + 'bancor' AS project, + dexs.version, + 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, + dexs.block_number, + dexs.token_bought_amount_raw, + dexs.token_sold_amount_raw, + dexs.token_bought_address, + dexs.token_sold_address, + dexs.taker, + dexs.maker, + dexs.project_contract_address, + dexs.tx_hash, + dexs.evt_index +FROM dexs diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql new file mode 100644 index 00000000000..21c713d48c8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql @@ -0,0 +1,22 @@ +{{ + config( + schema = 'carbon_defi_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} + +{{ + carbon_defi_compatible_trades( + blockchain = 'ethereum', + project = 'carbon_defi', + CarbonController_evt_TokensTraded = source('carbon_defi_ethereum', 'CarbonController_evt_TokensTraded'), + wrapped_native_token = weth_address + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/clipper_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/clipper_ethereum_base_trades.sql new file mode 100644 index 00000000000..b949b48af5d --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/clipper_ethereum_base_trades.sql @@ -0,0 +1,28 @@ +{{ + config( + schema = 'clipper_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% + set config_sources = [ + {'version': '1', 'source': 'ClipperExchangeInterface_evt_Swapped'}, + {'version': '2', 'source': 'ClipperCaravelExchange_evt_Swapped'}, + {'version': '3', 'source': 'ClipperVerifiedCaravelExchange_evt_Swapped'}, + {'version': '4', 'source': 'ClipperApproximateCaravelExchange_evt_Swapped'}, + ] +%} + +{{ + clipper_compatible_trades( + blockchain = 'ethereum', + project = 'clipper', + sources = config_sources + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/curve_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/curve_ethereum_base_trades.sql new file mode 100644 index 00000000000..74d36ba14bf --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/curve_ethereum_base_trades.sql @@ -0,0 +1,115 @@ +{{ + config( + schema = 'curve_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +--see curvefi readme for more info on the logic below. +WITH dexs AS +( + --factory v1 and regular pools + SELECT + l.block_number + , l.block_time + , p.version as version + , bytearray_substring(l.topic1, 13, 20) as taker + , CAST(NULL as VARBINARY) as maker + , case + when l.topic0 = 0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b + AND cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) = 0 + then 'underlying_exchange_base' + else 'normal_exchange' + end as swap_type + , bytearray_to_uint256(bytearray_substring(l.data, 97, 32)) as token_bought_amount_raw + , bytearray_to_uint256(bytearray_substring(l.data, 33, 32)) as token_sold_amount_raw + , cast(NULL as double) AS amount_usd + , case + when l.topic0 = 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 + and cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1 <= CARDINALITY(p.coins) + then p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1] + when l.topic0 != 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 + and cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1 <= CARDINALITY(p.undercoins) + then p.undercoins[cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1] + else NULL + end as token_bought_address + , case + when l.topic0 = 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 + and cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1 <= CARDINALITY(p.coins) + then p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1] + when l.topic0 != 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 + and cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1 <= CARDINALITY(p.undercoins) + then p.undercoins[cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1] + else NULL + end as token_sold_address + , l.contract_address as project_contract_address --pool address + , l.tx_hash + , l.index as evt_index + FROM {{ source('ethereum', 'logs') }} l + JOIN {{ ref('curve_ethereum_view_pools') }} p + ON l.contract_address = p.pool_address + AND p.version IN ('Factory V1 Meta', 'Factory V1 Plain', 'Regular', 'Factory V1 Stableswap Plain', 'Factory V1 Stableswap Meta', 'Factory V1 Stableswap Plain NG') --note Plain only has TokenExchange. + WHERE l.topic0 IN + ( + 0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b -- TokenExchangeUnderlying + , 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 -- TokenExchange + ) + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% endif %} + + UNION ALL + + --factory v2 pools and v1 plain pools have same logic + SELECT + l.block_number + , l.block_time + , p.version as version + , bytearray_substring(l.topic1, 13, 20) as taker + , CAST(NULL as VARBINARY) as maker + , 'normal_exchange' as swap_type + , bytearray_to_uint256(bytearray_substring(l.data, 97, 32)) as token_bought_amount_raw + , bytearray_to_uint256(bytearray_substring(l.data, 33, 32)) as token_sold_amount_raw + , cast(NULL as double) AS amount_usd + , p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1] as token_bought_address + , p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1] as token_sold_address + , l.contract_address as project_contract_address --pool address + , l.tx_hash + , l.index as evt_index + FROM {{ source('ethereum', 'logs') }} l + JOIN {{ ref('curve_ethereum_view_pools') }} p + ON l.contract_address = p.pool_address + AND (p.version = 'Factory V2' or p.version = 'Factory V2 updated' or p.version = 'Regular' or p.version = 'Factory Twocrypto') --some Regular pools are new and use the below topic instead + WHERE (l.topic0 = 0xb2e76ae99761dc136e598d4a629bb347eccb9532a5f8bbd72e18467c3c34cc98 --TokenExchange + OR l.topic0 = 0x143f1f8e861fbdeddd5b46e844b7d3ac7b86a122f36e8c463859ee6811b1f29c) --TokenExchange (v2 updated pool, has some other variables included after old ones so topic hash is changed.) + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% endif %} +) + +SELECT + 'ethereum' AS blockchain + ,'curve' AS project + ,dexs.version AS version + ,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date + ,CAST(date_trunc('MONTH', dexs.block_time) AS date) AS block_month + ,dexs.block_time + ,dexs.block_number + ,dexs.token_bought_amount_raw + ,dexs.token_sold_amount_raw + ,dexs.token_bought_address + ,dexs.token_sold_address + ,dexs.taker + ,dexs.maker + ,dexs.project_contract_address + ,dexs.tx_hash + ,dexs.evt_index + + --unique to curve in dex lineage, pull extra columns to calculate amount / amount_usd downstream in enrichment phase + ,dexs.swap_type +FROM dexs \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/defiswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/defiswap_ethereum_base_trades.sql new file mode 100644 index 00000000000..0961f4590f8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/defiswap_ethereum_base_trades.sql @@ -0,0 +1,20 @@ +{{ config( + schema = 'defiswap_ethereum' + , alias ='base_trades' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum' + , project = 'defiswap' + , version = '1' + , Pair_evt_Swap = source('defiswap_ethereum', 'CroDefiSwapPair_evt_Swap') + , Factory_evt_PairCreated = source('crodefi_ethereum', 'CroDefiSwapFactory_evt_PairCreated') + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/dfx_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/dfx_ethereum_base_trades.sql new file mode 100644 index 00000000000..ee52447eb10 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/dfx_ethereum_base_trades.sql @@ -0,0 +1,49 @@ +{{ + config( + schema = 'dfx_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +WITH dexs AS ( + SELECT + t.evt_block_number AS block_number, + t.evt_block_time AS block_time, + t.trader AS taker, + CAST(NULL as VARBINARY) as maker, + t.originAmount as token_sold_amount_raw, + t.targetAmount as token_bought_amount_raw, + t.origin as token_sold_address, + t.target as token_bought_address, + t.contract_address as project_contract_address, + t.evt_tx_hash as tx_hash, + t.evt_index + FROM {{ source('dfx_finance_ethereum', 'Curve_evt_Trade') }} t + {% if is_incremental() %} + WHERE {{incremental_predicate('t.evt_block_time')}} + {% endif %} +) + +SELECT + 'ethereum' AS blockchain, + 'dfx' AS project, + '0.5' AS version, + 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, + dexs.block_number, + dexs.token_bought_amount_raw, + dexs.token_sold_amount_raw, + dexs.token_bought_address, + dexs.token_sold_address, + dexs.taker, + dexs.maker, + dexs.project_contract_address, + dexs.tx_hash, + dexs.evt_index +FROM dexs diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql new file mode 100644 index 00000000000..12ad69bdead --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql @@ -0,0 +1,54 @@ +{{ + config( + schema = 'dodo_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set config_markets %} + WITH dodo_view_markets (market_contract_address, base_token_symbol, quote_token_symbol, base_token_address, quote_token_address) AS + ( + VALUES + (0x75c23271661d9d143dcb617222bc4bec783eff34, 'WETH', 'USDC', 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0x562c0b218cc9ba06d9eb42f3aef54c54cc5a4650, 'LINK', 'USDC', 0x514910771af9ca656af840dff83e8264ecf986ca, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0x0d04146b2fe5d267629a7eb341fb4388dcdbd22f, 'COMP', 'USDC', 0xc00e94cb662c3520282e6f5717214004a7f26888, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0xca7b0632bd0e646b0f823927d3d2e61b00fe4d80, 'SNX', 'USDC', 0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0xc226118fcd120634400ce228d61e1538fb21755f, 'LEND', 'USDC', 0x80fb784b7ed66730e8b1dbd9820afd29931aab03, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0x2109f78b46a789125598f5ad2b7f243751c2934d, 'WBTC', 'USDC', 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0x1b7902a66f133d899130bf44d7d879da89913b2e, 'YFI', 'USDC', 0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0x1a7fe5d6f0bb2d071e16bdd52c863233bbfd38e9, 'WETH', 'USDT', 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, 0xdac17f958d2ee523a2206206994597c13d831ec7), + (0xc9f93163c99695c6526b799ebca2207fdf7d61ad, 'USDT', 'USDC', 0xdac17f958d2ee523a2206206994597c13d831ec7, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0xd4a36b0acfe2931cf922ea3d91063ddfe4aff01f, 'sUSD', 'USDT', 0x57ab1ec28d129707052df4df418d58a2d46d5f51, 0xdac17f958d2ee523a2206206994597c13d831ec7), + (0x8876819535b48b551c9e97ebc07332c7482b4b2d, 'DODO', 'USDT', 0x43dfc4159d86f3a37a5a4b3d4580b888ad7d4ddd, 0xdac17f958d2ee523a2206206994597c13d831ec7), + (0x9d9793e1e18cdee6cf63818315d55244f73ec006, 'FIN', 'USDT', 0x054f76beed60ab6dbeb23502178c52d6c5debe40, 0xdac17f958d2ee523a2206206994597c13d831ec7), + (0x94512fd4fb4feb63a6c0f4bedecc4a00ee260528, 'AAVE', 'USDC', 0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), + (0x85f9569b69083c3e6aeffd301bb2c65606b5d575, 'wCRESt','USDT',0xa0afaa285ce85974c3c881256cb7f225e3a1178a, 0xdac17f958d2ee523a2206206994597c13d831ec7), + (0x181D93EA28023bf40C8bB94796c55138719803B4, 'WOO','USDT', 0x4691937a7508860F876c9c0a2a617E7d9E945D4B, 0xdAC17F958D2ee523a2206206994597C13D831ec7), + (0xd48c86156D53c0F775f40883391a113fC0D690d0, 'ibEUR','USDT', 0x96E61422b6A9bA0e068B6c5ADd4fFaBC6a4aae27, 0xdAC17F958D2ee523a2206206994597C13D831ec7) + ) + SELECT * FROM dodo_view_markets +{% endset %} + +{% + set config_other_sources = [ + {'version': '2_dvm', 'source': 'DVM_evt_DODOSwap'}, + {'version': '2_dpp', 'source': 'DPP_evt_DODOSwap'}, + {'version': '2_dsp', 'source': 'DSP_evt_DODOSwap'}, + ] +%} + +{{ + dodo_compatible_trades( + blockchain = 'ethereum', + project = 'dodo', + markets = config_markets, + sell_base_token_source = 'DODO_evt_SellBaseToken', + buy_base_token_source = 'DODO_evt_BuyBaseToken', + other_sources = config_other_sources + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql new file mode 100644 index 00000000000..5d55c770b89 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'fraxswap_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'fraxswap', + version = '1', + Pair_evt_Swap = source('fraxswap_ethereum', 'FraxswapPair_evt_Swap'), + Factory_evt_PairCreated = source('fraxswap_ethereum', 'FraxswapFactory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/integral_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/integral_ethereum_base_trades.sql new file mode 100644 index 00000000000..ad7105aafe5 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/integral_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'integral_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'integral', + version = 'size', + Pair_evt_Swap = source('integral_size_ethereum', 'Pair_evt_Swap'), + Factory_evt_PairCreated = source('integral_size_ethereum', 'Factory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql new file mode 100644 index 00000000000..7bbc0fe0e22 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql @@ -0,0 +1,89 @@ +{{ + config( + schema = 'kyberswap_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% + set config_sources = [ + { + 'version': 'elastic', + 'source_evt_swap': 'Elastic_Pool_evt_swap', + 'source_evt_factory': 'Elastic_Factory_evt_PoolCreated' + }, + { + 'version': 'elastic_2', + 'source_evt_swap': 'ElasticPoolV2_evt_Swap', + 'source_evt_factory': 'ElasticFactoryV2_evt_PoolCreated' + }, + ] +%} + +WITH + +dexs_classic AS ( + {{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'kyberswap', + version = 'classic', + Pair_evt_Swap = source('kyber_ethereum', 'DMMPool_evt_Swap'), + Factory_evt_PairCreated = source('kyber_ethereum', 'DMMFactory_evt_PoolCreated'), + pair_column_name = 'pool' + ) + }} +), + +dexs_elastic AS ( + {{ + kyberswap_compatible_trades( + blockchain = 'ethereum', + project = 'kyberswap', + sources = config_sources + ) + }} +) + +SELECT + dexs_classic.blockchain, + dexs_classic.project, + dexs_classic.version, + dexs_classic.block_month, + dexs_classic.block_date, + dexs_classic.block_time, + dexs_classic.block_number, + dexs_classic.token_bought_amount_raw, + dexs_classic.token_sold_amount_raw, + dexs_classic.token_bought_address, + dexs_classic.token_sold_address, + dexs_classic.taker, + dexs_classic.maker, + dexs_classic.project_contract_address, + dexs_classic.tx_hash, + dexs_classic.evt_index +FROM dexs_classic +UNION ALL +SELECT + dexs_elastic.blockchain, + dexs_elastic.project, + dexs_elastic.version, + dexs_elastic.block_month, + dexs_elastic.block_date, + dexs_elastic.block_time, + dexs_elastic.block_number, + dexs_elastic.token_bought_amount_raw, + dexs_elastic.token_sold_amount_raw, + dexs_elastic.token_bought_address, + dexs_elastic.token_sold_address, + dexs_elastic.taker, + dexs_elastic.maker, + dexs_elastic.project_contract_address, + dexs_elastic.tx_hash, + dexs_elastic.evt_index +FROM dexs_elastic diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/mauve_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/mauve_ethereum_base_trades.sql new file mode 100644 index 00000000000..4137a899b64 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/mauve_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'mauve_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v3_trades( + blockchain = 'ethereum', + project = 'mauve', + version = '1', + Pair_evt_Swap = source('mauve_ethereum', 'MauvePool_evt_Swap'), + Factory_evt_PoolCreated = source('mauve_ethereum', 'MauveFactory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_ethereum_base_trades.sql new file mode 100644 index 00000000000..7995b60c3d0 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'maverick_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + maverick_compatible_trades( + blockchain = 'ethereum', + project = 'maverick', + version = '1', + source_evt_swap = source('maverick_v1_ethereum', 'pool_evt_Swap'), + source_evt_pool = source('maverick_v1_ethereum', 'factory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql new file mode 100644 index 00000000000..825d528f2fb --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'maverick_v2_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + maverick_compatible_v2_trades( + blockchain = 'ethereum', + project = 'maverick', + version = '2', + source_evt_swap = source('maverick_v2_ethereum', 'V2Pool_evt_PoolSwap'), + source_evt_pool = source('maverick_v2_ethereum', 'V2Factory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/mstable_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/mstable_ethereum_base_trades.sql new file mode 100644 index 00000000000..7d83842712c --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/mstable_ethereum_base_trades.sql @@ -0,0 +1,70 @@ +{{ + config( + schema = 'mstable_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} + +{% + set sources = [ + {'version': 'masset', 'source': 'Masset_evt_Swapped'}, + {'version': 'feederpool', 'source': 'FeederPool_evt_Swapped'}, + ] +%} + +WITH dexs AS ( + {% for src in sources %} + SELECT + '{{ src["version"] }}' as version, + t.evt_block_number AS block_number, + t.evt_block_time AS block_time, + t.swapper AS taker, + CAST(NULL as VARBINARY) as maker, + t.outputAmount AS token_bought_amount_raw, + CAST(NULL AS UINT256) AS token_sold_amount_raw, + CASE + WHEN t.output = 0x0000000000000000000000000000000000000000 THEN {{ weth_address }} + ELSE t.output + END AS token_bought_address, + CASE + WHEN t.input = 0x0000000000000000000000000000000000000000 THEN {{ weth_address }} + ELSE t.input + END AS token_sold_address, + t.contract_address AS project_contract_address, + t.evt_tx_hash AS tx_hash, + t.evt_index + FROM {{ source('mstable_ethereum', src["source"] )}} t + {% if is_incremental() %} + WHERE {{ incremental_predicate('t.evt_block_time') }} + {% endif %} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) + +SELECT + 'ethereum' AS blockchain, + 'mstable' AS project, + dexs.version, + 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, + dexs.block_number, + dexs.token_bought_amount_raw, + dexs.token_sold_amount_raw, + dexs.token_bought_address, + dexs.token_sold_address, + dexs.taker, + dexs.maker, + dexs.project_contract_address, + dexs.tx_hash, + dexs.evt_index +FROM dexs diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql new file mode 100644 index 00000000000..dbd16edafe3 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql @@ -0,0 +1,87 @@ +{{ + config( + schema = 'pancakeswap_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +WITH + +dexs_macro AS ( + -- PancakeSwap v2 + {{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'pancakeswap', + version = '2', + Pair_evt_Swap = source('pancakeswap_v2_ethereum', 'PancakePair_evt_Swap'), + Factory_evt_PairCreated = source('pancakeswap_v2_ethereum', 'PancakeFactory_evt_PairCreated') + ) + }} +), + +dexs AS ( + -- PancakeSwap v2 MMPool + SELECT + 'mmpool' AS version, + t.evt_block_number AS block_number, + t.evt_block_time AS block_time, + t.user AS taker, + t.mm AS maker, + quoteTokenAmount AS token_bought_amount_raw, + baseTokenAmount AS token_sold_amount_raw, + CASE WHEN quotetoken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee + THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 ELSE quotetoken END AS token_bought_address, + CASE WHEN basetoken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee + THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 ELSE basetoken END AS token_sold_address, + t.contract_address AS project_contract_address, + t.evt_tx_hash AS tx_hash, + t.evt_index + FROM {{ source('pancakeswap_v2_ethereum', 'PancakeSwapMMPool_evt_Swap') }} t + {% if is_incremental() %} + WHERE {{ incremental_predicate('t.evt_block_time') }} + {% endif %} +) + +SELECT + dexs_macro.blockchain, + dexs_macro.project, + dexs_macro.version, + dexs_macro.block_month, + dexs_macro.block_date, + dexs_macro.block_time, + dexs_macro.block_number, + dexs_macro.token_bought_amount_raw, + dexs_macro.token_sold_amount_raw, + dexs_macro.token_bought_address, + dexs_macro.token_sold_address, + dexs_macro.taker, + dexs_macro.maker, + dexs_macro.project_contract_address, + dexs_macro.tx_hash, + dexs_macro.evt_index +FROM dexs_macro +UNION ALL +SELECT + 'ethereum' AS blockchain, + 'pancakeswap' AS project, + dexs.version, + 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, + dexs.block_number, + dexs.token_bought_amount_raw, + dexs.token_sold_amount_raw, + dexs.token_bought_address, + dexs.token_sold_address, + dexs.taker, + dexs.maker, + dexs.project_contract_address, + dexs.tx_hash, + dexs.evt_index +FROM dexs diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql new file mode 100644 index 00000000000..4af1ab5c005 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'pancakeswap_v3_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v3_trades( + blockchain = 'ethereum', + project = 'pancakeswap', + version = '3', + Pair_evt_Swap = source('pancakeswap_v3_ethereum', 'PancakeV3Pool_evt_Swap'), + Factory_evt_PoolCreated = source('pancakeswap_v3_ethereum', 'PancakeV3Factory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql new file mode 100644 index 00000000000..d2dc92b8db8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'shibaswap_v1_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'shibaswap', + version = '1', + Pair_evt_Swap = source('shibaswap_ethereum', 'UniswapV2Pair_evt_Swap'), + Factory_evt_PairCreated = source('shibaswap_ethereum', 'UniswapV2Factory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql new file mode 100644 index 00000000000..0d583563c50 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'solidly_v3_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v3_trades( + blockchain = 'ethereum', + project = 'solidly', + version = '3', + Pair_evt_Swap = source('solidly_ethereum', 'SolidlyV3Pool_evt_Swap'), + Factory_evt_PoolCreated = source('solidly_v3_ethereum', 'SolidlyV3Factory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql new file mode 100644 index 00000000000..16257d38f5e --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'sushiswap_v1_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'sushiswap', + version = '1', + Pair_evt_Swap = source('sushi_ethereum', 'Pair_evt_Swap'), + Factory_evt_PairCreated = source('sushi_ethereum', 'Factory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql new file mode 100644 index 00000000000..a596898c21d --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'sushiswap_v2_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v3_trades( + blockchain = 'ethereum', + project = 'sushiswap', + version = '2', + Pair_evt_Swap = source('sushiswap_v3_ethereum', 'UniswapV3Pool_evt_Swap'), + Factory_evt_PoolCreated = source('sushiswap_v3_ethereum', 'UniswapV3Factory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql new file mode 100644 index 00000000000..b12f8685cbb --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql @@ -0,0 +1,19 @@ +{{ + config( + schema = 'swaap_v2_ethereum', + alias ='base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + swaap_v2_compatible_trades( + blockchain = 'ethereum', + project = 'swaap', + version = '2' + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/swapr_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/swapr_ethereum_base_trades.sql new file mode 100644 index 00000000000..178918a1b62 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/swapr_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'swapr_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'swapr', + version = '1', + Pair_evt_Swap = source('swapr_ethereum', 'DXswapPair_evt_Swap'), + Factory_evt_PairCreated = source('swapr_ethereum', 'DXswapFactory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql new file mode 100644 index 00000000000..847bc1a333d --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql @@ -0,0 +1,83 @@ +{{ config( + schema = 'uniswap_v1_ethereum' + , alias = 'base_trades' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} + +WITH dexs AS +( + -- Uniswap v1 TokenPurchase + SELECT + t.evt_block_number AS block_number + , t.evt_block_time AS block_time + , t.buyer AS taker + , CAST(NULL as VARBINARY) AS maker + , t.tokens_bought AS token_bought_amount_raw + , t.eth_sold AS token_sold_amount_raw + , f.token AS token_bought_address + , {{weth_address}} 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_TokenPurchase') }} t + INNER JOIN + {{ source('uniswap_ethereum', 'Factory_evt_NewExchange') }} f + ON f.exchange = t.contract_address + {% if is_incremental() %} + WHERE + {{incremental_predicate('t.evt_block_time')}} + {% endif %} + + UNION ALL + + -- Uniswap v1 EthPurchase + SELECT + t.evt_block_number AS block_number + , t.evt_block_time AS block_time + , t.buyer AS taker + , CAST(NULL as VARBINARY) AS maker + , t.eth_bought AS token_bought_amount_raw + , t.tokens_sold AS token_sold_amount_raw + , {{weth_address}} AS token_bought_address + , 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 + INNER JOIN + {{ source('uniswap_ethereum', 'Factory_evt_NewExchange') }} f + ON f.exchange = t.contract_address + {% if is_incremental() %} + WHERE + {{incremental_predicate('t.evt_block_time')}} + {% endif %} +) + +SELECT + 'ethereum' AS blockchain + , 'uniswap' AS project + , '1' AS version + , 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 + , dexs.block_number + , dexs.token_bought_amount_raw + , dexs.token_sold_amount_raw + , dexs.token_bought_address + , dexs.token_sold_address + , dexs.taker + , dexs.maker + , dexs.project_contract_address + , dexs.tx_hash + , dexs.evt_index +FROM + dexs \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql new file mode 100644 index 00000000000..ee09e49f22e --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'uniswap_v2_ethereum' + , alias = 'base_trades' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set weth_ubomb_wash_trading_pair = '0xed9c854cb02de75ce4c9bba992828d6cb7fd5c71' %} +{% set weth_weth_wash_trading_pair = '0xf9c1fa7d41bf44ade1dd08d37cc68f67ae75bf92' %} +{% set feg_eth_wash_trading_pair = '0x854373387e41371ac6e307a1f29603c6fa10d872' %} + +WITH dexs AS +( + {{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum' + , project = 'uniswap' + , version = '2' + , Pair_evt_Swap = source('uniswap_v2_ethereum', 'Pair_evt_Swap') + , Factory_evt_PairCreated = source('uniswap_v2_ethereum', 'Factory_evt_PairCreated') + ) + }} +) + +SELECT + * +FROM + dexs +WHERE + project_contract_address NOT IN ( + {{weth_ubomb_wash_trading_pair}} + , {{weth_weth_wash_trading_pair}} + , {{feg_eth_wash_trading_pair}} + ) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql new file mode 100644 index 00000000000..7ee56b5f041 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql @@ -0,0 +1,20 @@ +{{ config( + schema = 'uniswap_v3_ethereum' + , alias = 'base_trades' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['tx_hash', 'evt_index'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v3_trades( + blockchain = 'ethereum' + , project = 'uniswap' + , version = '3' + , Pair_evt_Swap = source('uniswap_v3_ethereum', 'Pair_evt_Swap') + , Factory_evt_PoolCreated = source('uniswap_v3_ethereum', 'Factory_evt_PoolCreated') + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql new file mode 100644 index 00000000000..d6b57b7a9e4 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'verse_dex_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'verse_dex', + version = '1', + Pair_evt_Swap = source('verse_dex_ethereum', 'SwapsPair_evt_Swap'), + Factory_evt_PairCreated = source('verse_dex_ethereum', 'Factory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/xchange_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/xchange_ethereum_base_trades.sql new file mode 100644 index 00000000000..4ceb2bd84eb --- /dev/null +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/xchange_ethereum_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'xchange_ethereum', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'ethereum', + project = 'xchange', + version = '1', + Pair_evt_Swap = source('xchange_ethereum', 'XchangePair_evt_Swap'), + Factory_evt_PairCreated = source('xchange_ethereum', 'XchangeFactory_evt_PairCreated') + ) +}} From af18ba7a0124195f290262441c02b1052c229b4b Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:47:01 +0200 Subject: [PATCH 39/86] delete files too many --- .../ethereum/decoded-in-flight/_schema.yml | 75 ------------------- .../mass_decoded_dex_trades_ethereum.sql | 52 ------------- .../uniswap_v2_factory_decoding_ethereum.sql | 16 ---- .../uniswap_v2_fork_mapping_ethereum.sql | 56 -------------- .../uniswap_v2_forks_base_trades_ethereum.sql | 20 ----- .../uniswap_v2_pool_decoding_ethereum.sql | 16 ---- .../uniswap_v3_factory_decoding_ethereum.sql | 17 ----- .../uniswap_v3_fork_mapping_ethereum.sql | 19 ----- .../uniswap_v3_forks_base_trades_ethereum.sql | 21 ------ .../uniswap_v3_pool_decoding_ethereum.sql | 16 ---- 10 files changed, 308 deletions(-) delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql delete mode 100644 dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml deleted file mode 100644 index eda94470c32..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/_schema.yml +++ /dev/null @@ -1,75 +0,0 @@ -version: 2 - -models: - - name: uniswap_v2_factory_decoding_ethereum - description: > - mass decoding of all forks of uniswap v2 factory contract on ethereum - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - index - - - name: uniswap_v2_pool_decoding_ethereum - description: > - mass decoding of all forks of uniswap v2 pool contracts on ethereum - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - index - - - name: uniswap_v2_fork_mapping_ethereum - description: > - mapping of all forks of uniswap v2 factory contract on ethereum - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - factory_address - columns: - - name: factory_address - description: "address of the factory contract" - - name: project_name - description: "name of the project associated with the factory" - - - name: uniswap_v2_forks_base_trades_ethereum - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: 0xboxer - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2', 'forks' ] - description: "base trades for all forks of uniswap v2 on ethereum" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - project_contract_address - - - name: uniswap_v3_forks_base_trades_ethereum - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: 0xboxer - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3', 'forks' ] - description: "base trades for all forks of uniswap v3 on ethereum" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - project_contract_address - - - name: mass_decoded_dex_trades_ethereum - description: "all dex trades on ethereum, mass decoded" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - project_contract_address - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql deleted file mode 100644 index 017906daa0a..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ /dev/null @@ -1,52 +0,0 @@ -{{ config( - schema = 'dex_ethereum' - , alias = 'mass_decoded_trades' - , materialized = 'view' - ) -}} - -{% set base_models = [ - - ref('uniswap_v2_forks_base_trades_ethereum') - , ref('uniswap_v3_forks_base_trades_ethereum') -] %} - -WITH base_union AS ( - SELECT * - FROM ( - {% for base_model in base_models %} - SELECT - blockchain - , project - , version - , block_month - , block_date - , block_time - , block_number - , token_bought_amount_raw - , token_sold_amount_raw - , token_bought_address - , token_sold_address - , taker - , maker - , project_contract_address - , tx_hash - , evt_index - , factory_address - FROM - {{ base_model }} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} - ) -) - -{{ - add_tx_columns( - model_cte = 'base_union' - , blockchain = 'ethereum' - , columns = ['from', 'to', 'index'] - ) -}} - diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql deleted file mode 100644 index adbdc9fdcc4..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config( - - schema = 'mass_decoding_ethereum', - alias = 'uniswap_v2_factory_evt_PairCreated', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v2_factory_mass_decoding( - logs = source('ethereum', 'logs') -)}} diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql deleted file mode 100644 index 236a66c5342..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_ethereum.sql +++ /dev/null @@ -1,56 +0,0 @@ --- this should probably live somewhere else, just for testing purposes for now - -{{ config( - schema = 'dex_mass_decoding_ethereum', - alias = 'uniswap_v2_fork_mapping', - tags = ['static'], - unique_key = ['factory_address']) -}} - -SELECT factory_address, project_name -FROM -(VALUES - (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') - , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') - , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') - , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') - , (0x9deb29c9a4c7a88a3c0257393b7f3335338d9a9d, 'crodefi') - , (0x1097053fd2ea711dad45caccc45eff7548fcb362, 'pancakeswap_v2') - , (0x43ec799eadd63848443e2347c49f5f52e8fe0f6f, 'fraxswap') - , (0xee3e9e46e34a27dc755a63e2849c9913ee1a06e2, 'verse_dex') - , (0xc480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6, 'integral_size') - , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') - , (0x4eef5746ed22a2fd368629c1852365bf5dcb79f1, 'convergence') - , (0x1e895bfe59e3a5103e8b7da3897d1f2391476f3c, 'DooarSwap') - , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') - , (0x75e48c954594d64ef9613aeef97ad85370f13807, 'sakeswap') - , (0x696708db871b77355d6c2be7290b27cf0bb9b24b, 'linkswap_v1') - , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') - , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') - , (0x0388c1e0f210abae597b7de712b9510c6c36c857, 'luaswap') - , (0xa40ec8a93293a3179d4b544239916c1b68cb47b6, 'SunflowerSwap') - , (0x460b2005b3318982feada99f7ebf13e1d6f6effe, 'pepedex') - , (0x1264f802364e0776b9a9e3d161b43c7333ac08b2, 'rhino_fi') - , (0x7de800467afce442019884f51a4a1b9143a34fac, 'xchange') - , (0xd87ad19db2c4ccbf897106de034d52e3dd90ea60, 'plasmaswap') - , (0x46adc1c052fafd590f56c42e379d7d16622835a2, 'yape') - , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') - , (0xd34971bab6e5e356fd250715f5de0492bb070452, 'swapr') - , (0x35113a300ca0d7621374890abfeac30e88f214b1, 'SaitaSwap') - , (0xb076b06f669e682609fb4a8c6646d2619717be4b, 'fraxswap') - , (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') - , (0x5fbe219e88f6c6f214ce6f5b1fcaa0294f31ae1b, 'gammaswap') - , (0xbae5dc9b19004883d0377419fef3c2c8832d7d7b, 'apeswap') - , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'btswap') - , (0x26f53fbadeeb777fb2a122dc703433d79241b64e, 'light_dao') - , (0x08e7974cacf66c5a92a37c221a15d3c30c7d97e0, 'unifi') - , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') - , (0xf028f723ed1d0fe01cc59973c49298aa95c57472, 'SashimiSwap') - , (0x54f454d747e037da288db568d4121117eab34e79, 'bbb') - , (0x2d723f60ad8da76286b2ac120498a5ea6babc792, 'neopin') - , (0x91fAe1bc94A9793708fbc66aDcb59087C46dEe10, 'radioshack') - , (0xe185e5335d68c2a18564b4b43bdf4ed86337ee70, 'quantoswap') -) AS t (factory_address, project_name) - - - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql deleted file mode 100644 index dae82d4239f..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ /dev/null @@ -1,20 +0,0 @@ -{{ config( - - schema = 'dex_mass_decoding_ethereum', - alias = 'uniswap_v2_base_trades', - partition_by = ['block_month'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v2_forks_trades( - blockchain = 'ethereum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') - , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') -)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql deleted file mode 100644 index e817fe8d2f3..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config( - - schema = 'mass_decoding_ethereum', - alias = 'uniswap_v2_pool_evt_Swap', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v2_pool_mass_decoding( - logs = source('ethereum', 'logs') -)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql deleted file mode 100644 index 5f77de40f22..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql +++ /dev/null @@ -1,17 +0,0 @@ -{{ config( - - schema = 'mass_decoding_ethereum', - alias = 'uniswap_v3_factory_evt_PoolCreated', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v3_factory_mass_decoding( - logs = source('ethereum', 'logs') -)}} - diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql deleted file mode 100644 index 79021547194..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql +++ /dev/null @@ -1,19 +0,0 @@ --- this should probably live somewhere else, just for testing purposes for now - -{{ config( - schema = 'dex_mass_decoding_ethereum', - alias = 'uniswap_v3_fork_mapping', - tags = ['static'], - unique_key = ['factory_address']) -}} - -SELECT factory_address, project_name -FROM -(VALUES - (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') - , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') - -) AS t (factory_address, project_name) - - - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql deleted file mode 100644 index 074296af85b..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ config( - - schema = 'dex_mass_decoding_ethereum', - alias = 'uniswap_v3_base_trades', - partition_by = ['block_month'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v3_forks_trades( - blockchain = 'ethereum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') - , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_ethereum') -)}} - diff --git a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql deleted file mode 100644 index 53931819cbc..00000000000 --- a/dbt_subprojects/dex/models/trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config( - - schema = 'dex_mass_decoding_ethereum', - alias = 'uniswap_v3_pool_evt_Swap', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v3_pool_mass_decoding( - logs = source('ethereum', 'logs') -)}} \ No newline at end of file From e3889220ac57e5e7e1fcecab1049c5426df3f466 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:50:52 +0200 Subject: [PATCH 40/86] remove copies --- .../airswap_ethereum_base_trades.sql | 29 ----- .../apeswap_ethereum_base_trades.sql | 20 --- .../balancer_v1_ethereum_base_trades.sql | 19 --- .../balancer_v2_ethereum_base_trades.sql | 19 --- .../platforms/bancor_ethereum_base_trades.sql | 106 ---------------- .../carbon_defi_ethereum_base_trades.sql | 22 ---- .../clipper_ethereum_base_trades.sql | 28 ----- .../platforms/curve_ethereum_base_trades.sql | 115 ------------------ .../defiswap_ethereum_base_trades.sql | 20 --- .../platforms/dfx_ethereum_base_trades.sql | 49 -------- .../platforms/dodo_ethereum_base_trades.sql | 54 -------- .../fraxswap_ethereum_base_trades.sql | 21 ---- .../integral_ethereum_base_trades.sql | 21 ---- .../kyberswap_ethereum_base_trades.sql | 89 -------------- .../platforms/mauve_ethereum_base_trades.sql | 21 ---- .../maverick_ethereum_base_trades.sql | 21 ---- .../maverick_v2_ethereum_base_trades.sql | 21 ---- .../mstable_ethereum_base_trades.sql | 70 ----------- .../pancakeswap_v2_ethereum_base_trades.sql | 87 ------------- .../pancakeswap_v3_ethereum_base_trades.sql | 21 ---- .../shibaswap_v1_ethereum_base_trades.sql | 21 ---- .../solidly_v3_ethereum_base_trades.sql | 21 ---- .../sushiswap_v1_ethereum_base_trades.sql | 21 ---- .../sushiswap_v2_ethereum_base_trades.sql | 21 ---- .../swaap_v2_ethereum_base_trades.sql | 19 --- .../platforms/swapr_ethereum_base_trades.sql | 21 ---- .../uniswap_v1_ethereum_base_trades.sql | 83 ------------- .../uniswap_v2_ethereum_base_trades.sql | 38 ------ .../uniswap_v3_ethereum_base_trades.sql | 20 --- .../verse_dex_ethereum_base_trades.sql | 21 ---- .../xchange_ethereum_base_trades.sql | 21 ---- 31 files changed, 1160 deletions(-) delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/airswap_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/apeswap_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/bancor_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/clipper_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/curve_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/defiswap_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dfx_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dodo_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/integral_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mauve_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mstable_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swapr_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/xchange_ethereum_base_trades.sql diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/airswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/airswap_ethereum_base_trades.sql deleted file mode 100644 index 3828b9ac0e8..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/airswap_ethereum_base_trades.sql +++ /dev/null @@ -1,29 +0,0 @@ -{{ - config( - schema = 'airswap_ethereum', - alias ='base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% - set config_sources = [ - {'version': 'light', 'source': 'Light_evt_Swap'}, - {'version': 'light_v0', 'source': 'Light_v0_evt_Swap'}, - {'version': 'swap', 'source': 'swap_evt_Swap'}, - {'version': 'swap_v3', 'source': 'Swap_v3_evt_Swap'}, - {'version': 'swap_erc20_v4', 'source': 'SwapERC20_v4_evt_SwapERC20'}, - ] -%} - -{{ - airswap_compatible_trades( - blockchain = 'ethereum', - project = 'airswap', - sources = config_sources - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/apeswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/apeswap_ethereum_base_trades.sql deleted file mode 100644 index 1a60edd1b7a..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/apeswap_ethereum_base_trades.sql +++ /dev/null @@ -1,20 +0,0 @@ -{{ config( - schema = 'apeswap_ethereum' - , alias = 'base_trades' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['tx_hash', 'evt_index'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'apeswap', - version = '1', - Pair_evt_Swap = source('apeswap_ethereum', 'ApePair_evt_Swap'), - Factory_evt_PairCreated = source('apeswap_ethereum', 'ApeFactory_evt_PairCreated') - ) -}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql deleted file mode 100644 index 845d9a91dda..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v1_ethereum_base_trades.sql +++ /dev/null @@ -1,19 +0,0 @@ -{{ - config( - schema = 'balancer_v1_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - balancer_compatible_v1_trades( - blockchain = 'ethereum', - project = 'balancer', - version = '1' - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql deleted file mode 100644 index da29d9dea1d..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/balancer_v2_ethereum_base_trades.sql +++ /dev/null @@ -1,19 +0,0 @@ -{{ - config( - schema = 'balancer_v2_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - balancer_compatible_v2_trades( - blockchain = 'ethereum', - project = 'balancer', - version = '2' - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/bancor_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/bancor_ethereum_base_trades.sql deleted file mode 100644 index 0d887105d71..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/bancor_ethereum_base_trades.sql +++ /dev/null @@ -1,106 +0,0 @@ -{{ - config( - schema = 'bancor_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} - -WITH conversions AS ( - {% for n in range(6,11) %} - SELECT - t.evt_block_number, - t.evt_block_time, - t._trader, - t._toAmount, - t._fromAmount, - t._toToken, - t._fromToken, - t.contract_address, - t.evt_tx_hash, - t.evt_index - FROM {{ source('bancornetwork_ethereum', 'BancorNetwork_v' ~ n ~ '_evt_Conversion' )}} t - {% if is_incremental() %} - WHERE {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} -), - -dexs AS ( - SELECT - '1' AS version, - t.evt_block_number AS block_number, - t.evt_block_time AS block_time, - t._trader AS taker, - CAST(NULL AS VARBINARY) AS maker, - t._toAmount AS token_bought_amount_raw, - t._fromAmount AS token_sold_amount_raw, - CAST(NULL as double) AS amount_usd, - CASE - WHEN t._toToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} - ELSE t._toToken - END AS token_bought_address, - CASE - WHEN t._fromToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} - ELSE t._fromToken - END AS token_sold_address, - t.contract_address AS project_contract_address, - t.evt_tx_hash AS tx_hash, - t.evt_index - FROM conversions t - - UNION ALL - - SELECT - '3' AS version, - t.evt_block_number AS block_number, - t.evt_block_time AS block_time, - t.trader AS taker, - CAST(NULL AS VARBINARY) AS maker, - t.targetAmount AS token_bought_amount_raw, - t.sourceAmount AS token_sold_amount_raw, - CAST(NULL as double) AS amount_usd, - CASE - WHEN t.targetToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} - ELSE t.targetToken - END AS token_bought_address, - CASE - WHEN t.sourceToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth_address }} - ELSE t.sourceToken - END AS token_sold_address, - t.contract_address AS project_contract_address, - t.evt_tx_hash AS tx_hash, - t.evt_index - FROM {{ source('bancor3_ethereum', 'BancorNetwork_evt_TokensTraded') }} t - {% if is_incremental() %} - WHERE {{ incremental_predicate('t.evt_block_time') }} - {% endif %} -) - -SELECT - 'ethereum' AS blockchain, - 'bancor' AS project, - dexs.version, - 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, - dexs.block_number, - dexs.token_bought_amount_raw, - dexs.token_sold_amount_raw, - dexs.token_bought_address, - dexs.token_sold_address, - dexs.taker, - dexs.maker, - dexs.project_contract_address, - dexs.tx_hash, - dexs.evt_index -FROM dexs diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql deleted file mode 100644 index 21c713d48c8..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/carbon_defi_ethereum_base_trades.sql +++ /dev/null @@ -1,22 +0,0 @@ -{{ - config( - schema = 'carbon_defi_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} - -{{ - carbon_defi_compatible_trades( - blockchain = 'ethereum', - project = 'carbon_defi', - CarbonController_evt_TokensTraded = source('carbon_defi_ethereum', 'CarbonController_evt_TokensTraded'), - wrapped_native_token = weth_address - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/clipper_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/clipper_ethereum_base_trades.sql deleted file mode 100644 index b949b48af5d..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/clipper_ethereum_base_trades.sql +++ /dev/null @@ -1,28 +0,0 @@ -{{ - config( - schema = 'clipper_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% - set config_sources = [ - {'version': '1', 'source': 'ClipperExchangeInterface_evt_Swapped'}, - {'version': '2', 'source': 'ClipperCaravelExchange_evt_Swapped'}, - {'version': '3', 'source': 'ClipperVerifiedCaravelExchange_evt_Swapped'}, - {'version': '4', 'source': 'ClipperApproximateCaravelExchange_evt_Swapped'}, - ] -%} - -{{ - clipper_compatible_trades( - blockchain = 'ethereum', - project = 'clipper', - sources = config_sources - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/curve_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/curve_ethereum_base_trades.sql deleted file mode 100644 index 74d36ba14bf..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/curve_ethereum_base_trades.sql +++ /dev/null @@ -1,115 +0,0 @@ -{{ - config( - schema = 'curve_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - ---see curvefi readme for more info on the logic below. -WITH dexs AS -( - --factory v1 and regular pools - SELECT - l.block_number - , l.block_time - , p.version as version - , bytearray_substring(l.topic1, 13, 20) as taker - , CAST(NULL as VARBINARY) as maker - , case - when l.topic0 = 0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b - AND cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) = 0 - then 'underlying_exchange_base' - else 'normal_exchange' - end as swap_type - , bytearray_to_uint256(bytearray_substring(l.data, 97, 32)) as token_bought_amount_raw - , bytearray_to_uint256(bytearray_substring(l.data, 33, 32)) as token_sold_amount_raw - , cast(NULL as double) AS amount_usd - , case - when l.topic0 = 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 - and cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1 <= CARDINALITY(p.coins) - then p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1] - when l.topic0 != 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 - and cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1 <= CARDINALITY(p.undercoins) - then p.undercoins[cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1] - else NULL - end as token_bought_address - , case - when l.topic0 = 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 - and cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1 <= CARDINALITY(p.coins) - then p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1] - when l.topic0 != 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 - and cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1 <= CARDINALITY(p.undercoins) - then p.undercoins[cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1] - else NULL - end as token_sold_address - , l.contract_address as project_contract_address --pool address - , l.tx_hash - , l.index as evt_index - FROM {{ source('ethereum', 'logs') }} l - JOIN {{ ref('curve_ethereum_view_pools') }} p - ON l.contract_address = p.pool_address - AND p.version IN ('Factory V1 Meta', 'Factory V1 Plain', 'Regular', 'Factory V1 Stableswap Plain', 'Factory V1 Stableswap Meta', 'Factory V1 Stableswap Plain NG') --note Plain only has TokenExchange. - WHERE l.topic0 IN - ( - 0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b -- TokenExchangeUnderlying - , 0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140 -- TokenExchange - ) - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% endif %} - - UNION ALL - - --factory v2 pools and v1 plain pools have same logic - SELECT - l.block_number - , l.block_time - , p.version as version - , bytearray_substring(l.topic1, 13, 20) as taker - , CAST(NULL as VARBINARY) as maker - , 'normal_exchange' as swap_type - , bytearray_to_uint256(bytearray_substring(l.data, 97, 32)) as token_bought_amount_raw - , bytearray_to_uint256(bytearray_substring(l.data, 33, 32)) as token_sold_amount_raw - , cast(NULL as double) AS amount_usd - , p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) as int) + 1] as token_bought_address - , p.coins[cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) as int) + 1] as token_sold_address - , l.contract_address as project_contract_address --pool address - , l.tx_hash - , l.index as evt_index - FROM {{ source('ethereum', 'logs') }} l - JOIN {{ ref('curve_ethereum_view_pools') }} p - ON l.contract_address = p.pool_address - AND (p.version = 'Factory V2' or p.version = 'Factory V2 updated' or p.version = 'Regular' or p.version = 'Factory Twocrypto') --some Regular pools are new and use the below topic instead - WHERE (l.topic0 = 0xb2e76ae99761dc136e598d4a629bb347eccb9532a5f8bbd72e18467c3c34cc98 --TokenExchange - OR l.topic0 = 0x143f1f8e861fbdeddd5b46e844b7d3ac7b86a122f36e8c463859ee6811b1f29c) --TokenExchange (v2 updated pool, has some other variables included after old ones so topic hash is changed.) - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% endif %} -) - -SELECT - 'ethereum' AS blockchain - ,'curve' AS project - ,dexs.version AS version - ,CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date - ,CAST(date_trunc('MONTH', dexs.block_time) AS date) AS block_month - ,dexs.block_time - ,dexs.block_number - ,dexs.token_bought_amount_raw - ,dexs.token_sold_amount_raw - ,dexs.token_bought_address - ,dexs.token_sold_address - ,dexs.taker - ,dexs.maker - ,dexs.project_contract_address - ,dexs.tx_hash - ,dexs.evt_index - - --unique to curve in dex lineage, pull extra columns to calculate amount / amount_usd downstream in enrichment phase - ,dexs.swap_type -FROM dexs \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/defiswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/defiswap_ethereum_base_trades.sql deleted file mode 100644 index 0961f4590f8..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/defiswap_ethereum_base_trades.sql +++ /dev/null @@ -1,20 +0,0 @@ -{{ config( - schema = 'defiswap_ethereum' - , alias ='base_trades' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['tx_hash', 'evt_index'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum' - , project = 'defiswap' - , version = '1' - , Pair_evt_Swap = source('defiswap_ethereum', 'CroDefiSwapPair_evt_Swap') - , Factory_evt_PairCreated = source('crodefi_ethereum', 'CroDefiSwapFactory_evt_PairCreated') - ) -}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dfx_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dfx_ethereum_base_trades.sql deleted file mode 100644 index ee52447eb10..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dfx_ethereum_base_trades.sql +++ /dev/null @@ -1,49 +0,0 @@ -{{ - config( - schema = 'dfx_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -WITH dexs AS ( - SELECT - t.evt_block_number AS block_number, - t.evt_block_time AS block_time, - t.trader AS taker, - CAST(NULL as VARBINARY) as maker, - t.originAmount as token_sold_amount_raw, - t.targetAmount as token_bought_amount_raw, - t.origin as token_sold_address, - t.target as token_bought_address, - t.contract_address as project_contract_address, - t.evt_tx_hash as tx_hash, - t.evt_index - FROM {{ source('dfx_finance_ethereum', 'Curve_evt_Trade') }} t - {% if is_incremental() %} - WHERE {{incremental_predicate('t.evt_block_time')}} - {% endif %} -) - -SELECT - 'ethereum' AS blockchain, - 'dfx' AS project, - '0.5' AS version, - 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, - dexs.block_number, - dexs.token_bought_amount_raw, - dexs.token_sold_amount_raw, - dexs.token_bought_address, - dexs.token_sold_address, - dexs.taker, - dexs.maker, - dexs.project_contract_address, - dexs.tx_hash, - dexs.evt_index -FROM dexs diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dodo_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dodo_ethereum_base_trades.sql deleted file mode 100644 index 6797ecffdd9..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/dodo_ethereum_base_trades.sql +++ /dev/null @@ -1,54 +0,0 @@ -{{ - config( - schema = 'dodo_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set config_markets %} - WITH dodo_view_markets (market_contract_address, base_token_symbol, quote_token_symbol, base_token_address, quote_token_address) AS - ( - VALUES - (0x75c23271661d9d143dcb617222bc4bec783eff34, 'WETH', 'USDC', 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0x562c0b218cc9ba06d9eb42f3aef54c54cc5a4650, 'LINK', 'USDC', 0x514910771af9ca656af840dff83e8264ecf986ca, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0x0d04146b2fe5d267629a7eb341fb4388dcdbd22f, 'COMP', 'USDC', 0xc00e94cb662c3520282e6f5717214004a7f26888, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0xca7b0632bd0e646b0f823927d3d2e61b00fe4d80, 'SNX', 'USDC', 0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0xc226118fcd120634400ce228d61e1538fb21755f, 'LEND', 'USDC', 0x80fb784b7ed66730e8b1dbd9820afd29931aab03, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0x2109f78b46a789125598f5ad2b7f243751c2934d, 'WBTC', 'USDC', 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0x1b7902a66f133d899130bf44d7d879da89913b2e, 'YFI', 'USDC', 0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0x1a7fe5d6f0bb2d071e16bdd52c863233bbfd38e9, 'WETH', 'USDT', 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, 0xdac17f958d2ee523a2206206994597c13d831ec7), - (0xc9f93163c99695c6526b799ebca2207fdf7d61ad, 'USDT', 'USDC', 0xdac17f958d2ee523a2206206994597c13d831ec7, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0xd4a36b0acfe2931cf922ea3d91063ddfe4aff01f, 'sUSD', 'USDT', 0x57ab1ec28d129707052df4df418d58a2d46d5f51, 0xdac17f958d2ee523a2206206994597c13d831ec7), - (0x8876819535b48b551c9e97ebc07332c7482b4b2d, 'DODO', 'USDT', 0x43dfc4159d86f3a37a5a4b3d4580b888ad7d4ddd, 0xdac17f958d2ee523a2206206994597c13d831ec7), - (0x9d9793e1e18cdee6cf63818315d55244f73ec006, 'FIN', 'USDT', 0x054f76beed60ab6dbeb23502178c52d6c5debe40, 0xdac17f958d2ee523a2206206994597c13d831ec7), - (0x94512fd4fb4feb63a6c0f4bedecc4a00ee260528, 'AAVE', 'USDC', 0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), - (0x85f9569b69083c3e6aeffd301bb2c65606b5d575, 'wCRESt','USDT',0xa0afaa285ce85974c3c881256cb7f225e3a1178a, 0xdac17f958d2ee523a2206206994597c13d831ec7), - (0x181D93EA28023bf40C8bB94796c55138719803B4, 'WOO','USDT', 0x4691937a7508860F876c9c0a2a617E7d9E945D4B, 0xdAC17F958D2ee523a2206206994597C13D831ec7), - (0xd48c86156D53c0F775f40883391a113fC0D690d0, 'ibEUR','USDT', 0x96E61422b6A9bA0e068B6c5ADd4fFaBC6a4aae27, 0xdAC17F958D2ee523a2206206994597C13D831ec7) - ) - SELECT * FROM dodo_view_markets -{% endset %} - -{% - set config_other_sources = [ - {'version': '2', 'source': 'DVM_evt_DODOSwap'}, - {'version': '2', 'source': 'DPP_evt_DODOSwap'}, - {'version': '2', 'source': 'DSP_evt_DODOSwap'}, - ] -%} - -{{ - dodo_compatible_trades( - blockchain = 'ethereum', - project = 'dodo', - markets = config_markets, - sell_base_token_source = 'DODO_evt_SellBaseToken', - buy_base_token_source = 'DODO_evt_BuyBaseToken', - other_sources = config_other_sources - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql deleted file mode 100644 index 5d55c770b89..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/fraxswap_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'fraxswap_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'fraxswap', - version = '1', - Pair_evt_Swap = source('fraxswap_ethereum', 'FraxswapPair_evt_Swap'), - Factory_evt_PairCreated = source('fraxswap_ethereum', 'FraxswapFactory_evt_PairCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/integral_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/integral_ethereum_base_trades.sql deleted file mode 100644 index ad7105aafe5..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/integral_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'integral_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'integral', - version = 'size', - Pair_evt_Swap = source('integral_size_ethereum', 'Pair_evt_Swap'), - Factory_evt_PairCreated = source('integral_size_ethereum', 'Factory_evt_PairCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql deleted file mode 100644 index 7bbc0fe0e22..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/kyberswap_ethereum_base_trades.sql +++ /dev/null @@ -1,89 +0,0 @@ -{{ - config( - schema = 'kyberswap_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% - set config_sources = [ - { - 'version': 'elastic', - 'source_evt_swap': 'Elastic_Pool_evt_swap', - 'source_evt_factory': 'Elastic_Factory_evt_PoolCreated' - }, - { - 'version': 'elastic_2', - 'source_evt_swap': 'ElasticPoolV2_evt_Swap', - 'source_evt_factory': 'ElasticFactoryV2_evt_PoolCreated' - }, - ] -%} - -WITH - -dexs_classic AS ( - {{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'kyberswap', - version = 'classic', - Pair_evt_Swap = source('kyber_ethereum', 'DMMPool_evt_Swap'), - Factory_evt_PairCreated = source('kyber_ethereum', 'DMMFactory_evt_PoolCreated'), - pair_column_name = 'pool' - ) - }} -), - -dexs_elastic AS ( - {{ - kyberswap_compatible_trades( - blockchain = 'ethereum', - project = 'kyberswap', - sources = config_sources - ) - }} -) - -SELECT - dexs_classic.blockchain, - dexs_classic.project, - dexs_classic.version, - dexs_classic.block_month, - dexs_classic.block_date, - dexs_classic.block_time, - dexs_classic.block_number, - dexs_classic.token_bought_amount_raw, - dexs_classic.token_sold_amount_raw, - dexs_classic.token_bought_address, - dexs_classic.token_sold_address, - dexs_classic.taker, - dexs_classic.maker, - dexs_classic.project_contract_address, - dexs_classic.tx_hash, - dexs_classic.evt_index -FROM dexs_classic -UNION ALL -SELECT - dexs_elastic.blockchain, - dexs_elastic.project, - dexs_elastic.version, - dexs_elastic.block_month, - dexs_elastic.block_date, - dexs_elastic.block_time, - dexs_elastic.block_number, - dexs_elastic.token_bought_amount_raw, - dexs_elastic.token_sold_amount_raw, - dexs_elastic.token_bought_address, - dexs_elastic.token_sold_address, - dexs_elastic.taker, - dexs_elastic.maker, - dexs_elastic.project_contract_address, - dexs_elastic.tx_hash, - dexs_elastic.evt_index -FROM dexs_elastic diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mauve_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mauve_ethereum_base_trades.sql deleted file mode 100644 index 4137a899b64..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mauve_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'mauve_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v3_trades( - blockchain = 'ethereum', - project = 'mauve', - version = '1', - Pair_evt_Swap = source('mauve_ethereum', 'MauvePool_evt_Swap'), - Factory_evt_PoolCreated = source('mauve_ethereum', 'MauveFactory_evt_PoolCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_ethereum_base_trades.sql deleted file mode 100644 index 7995b60c3d0..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'maverick_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - maverick_compatible_trades( - blockchain = 'ethereum', - project = 'maverick', - version = '1', - source_evt_swap = source('maverick_v1_ethereum', 'pool_evt_Swap'), - source_evt_pool = source('maverick_v1_ethereum', 'factory_evt_PoolCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql deleted file mode 100644 index 825d528f2fb..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/maverick_v2_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'maverick_v2_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - maverick_compatible_v2_trades( - blockchain = 'ethereum', - project = 'maverick', - version = '2', - source_evt_swap = source('maverick_v2_ethereum', 'V2Pool_evt_PoolSwap'), - source_evt_pool = source('maverick_v2_ethereum', 'V2Factory_evt_PoolCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mstable_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mstable_ethereum_base_trades.sql deleted file mode 100644 index 7d83842712c..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/mstable_ethereum_base_trades.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ - config( - schema = 'mstable_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} - -{% - set sources = [ - {'version': 'masset', 'source': 'Masset_evt_Swapped'}, - {'version': 'feederpool', 'source': 'FeederPool_evt_Swapped'}, - ] -%} - -WITH dexs AS ( - {% for src in sources %} - SELECT - '{{ src["version"] }}' as version, - t.evt_block_number AS block_number, - t.evt_block_time AS block_time, - t.swapper AS taker, - CAST(NULL as VARBINARY) as maker, - t.outputAmount AS token_bought_amount_raw, - CAST(NULL AS UINT256) AS token_sold_amount_raw, - CASE - WHEN t.output = 0x0000000000000000000000000000000000000000 THEN {{ weth_address }} - ELSE t.output - END AS token_bought_address, - CASE - WHEN t.input = 0x0000000000000000000000000000000000000000 THEN {{ weth_address }} - ELSE t.input - END AS token_sold_address, - t.contract_address AS project_contract_address, - t.evt_tx_hash AS tx_hash, - t.evt_index - FROM {{ source('mstable_ethereum', src["source"] )}} t - {% if is_incremental() %} - WHERE {{ incremental_predicate('t.evt_block_time') }} - {% endif %} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} -) - -SELECT - 'ethereum' AS blockchain, - 'mstable' AS project, - dexs.version, - 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, - dexs.block_number, - dexs.token_bought_amount_raw, - dexs.token_sold_amount_raw, - dexs.token_bought_address, - dexs.token_sold_address, - dexs.taker, - dexs.maker, - dexs.project_contract_address, - dexs.tx_hash, - dexs.evt_index -FROM dexs diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql deleted file mode 100644 index dbd16edafe3..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v2_ethereum_base_trades.sql +++ /dev/null @@ -1,87 +0,0 @@ -{{ - config( - schema = 'pancakeswap_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -WITH - -dexs_macro AS ( - -- PancakeSwap v2 - {{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'pancakeswap', - version = '2', - Pair_evt_Swap = source('pancakeswap_v2_ethereum', 'PancakePair_evt_Swap'), - Factory_evt_PairCreated = source('pancakeswap_v2_ethereum', 'PancakeFactory_evt_PairCreated') - ) - }} -), - -dexs AS ( - -- PancakeSwap v2 MMPool - SELECT - 'mmpool' AS version, - t.evt_block_number AS block_number, - t.evt_block_time AS block_time, - t.user AS taker, - t.mm AS maker, - quoteTokenAmount AS token_bought_amount_raw, - baseTokenAmount AS token_sold_amount_raw, - CASE WHEN quotetoken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 ELSE quotetoken END AS token_bought_address, - CASE WHEN basetoken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 ELSE basetoken END AS token_sold_address, - t.contract_address AS project_contract_address, - t.evt_tx_hash AS tx_hash, - t.evt_index - FROM {{ source('pancakeswap_v2_ethereum', 'PancakeSwapMMPool_evt_Swap') }} t - {% if is_incremental() %} - WHERE {{ incremental_predicate('t.evt_block_time') }} - {% endif %} -) - -SELECT - dexs_macro.blockchain, - dexs_macro.project, - dexs_macro.version, - dexs_macro.block_month, - dexs_macro.block_date, - dexs_macro.block_time, - dexs_macro.block_number, - dexs_macro.token_bought_amount_raw, - dexs_macro.token_sold_amount_raw, - dexs_macro.token_bought_address, - dexs_macro.token_sold_address, - dexs_macro.taker, - dexs_macro.maker, - dexs_macro.project_contract_address, - dexs_macro.tx_hash, - dexs_macro.evt_index -FROM dexs_macro -UNION ALL -SELECT - 'ethereum' AS blockchain, - 'pancakeswap' AS project, - dexs.version, - 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, - dexs.block_number, - dexs.token_bought_amount_raw, - dexs.token_sold_amount_raw, - dexs.token_bought_address, - dexs.token_sold_address, - dexs.taker, - dexs.maker, - dexs.project_contract_address, - dexs.tx_hash, - dexs.evt_index -FROM dexs diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql deleted file mode 100644 index 4af1ab5c005..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/pancakeswap_v3_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'pancakeswap_v3_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v3_trades( - blockchain = 'ethereum', - project = 'pancakeswap', - version = '3', - Pair_evt_Swap = source('pancakeswap_v3_ethereum', 'PancakeV3Pool_evt_Swap'), - Factory_evt_PoolCreated = source('pancakeswap_v3_ethereum', 'PancakeV3Factory_evt_PoolCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql deleted file mode 100644 index d2dc92b8db8..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/shibaswap_v1_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'shibaswap_v1_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'shibaswap', - version = '1', - Pair_evt_Swap = source('shibaswap_ethereum', 'UniswapV2Pair_evt_Swap'), - Factory_evt_PairCreated = source('shibaswap_ethereum', 'UniswapV2Factory_evt_PairCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql deleted file mode 100644 index 0d583563c50..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/solidly_v3_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'solidly_v3_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v3_trades( - blockchain = 'ethereum', - project = 'solidly', - version = '3', - Pair_evt_Swap = source('solidly_ethereum', 'SolidlyV3Pool_evt_Swap'), - Factory_evt_PoolCreated = source('solidly_v3_ethereum', 'SolidlyV3Factory_evt_PoolCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql deleted file mode 100644 index 16257d38f5e..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v1_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'sushiswap_v1_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'sushiswap', - version = '1', - Pair_evt_Swap = source('sushi_ethereum', 'Pair_evt_Swap'), - Factory_evt_PairCreated = source('sushi_ethereum', 'Factory_evt_PairCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql deleted file mode 100644 index a596898c21d..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/sushiswap_v2_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'sushiswap_v2_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v3_trades( - blockchain = 'ethereum', - project = 'sushiswap', - version = '2', - Pair_evt_Swap = source('sushiswap_v3_ethereum', 'UniswapV3Pool_evt_Swap'), - Factory_evt_PoolCreated = source('sushiswap_v3_ethereum', 'UniswapV3Factory_evt_PoolCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql deleted file mode 100644 index b12f8685cbb..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swaap_v2_ethereum_base_trades.sql +++ /dev/null @@ -1,19 +0,0 @@ -{{ - config( - schema = 'swaap_v2_ethereum', - alias ='base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - swaap_v2_compatible_trades( - blockchain = 'ethereum', - project = 'swaap', - version = '2' - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swapr_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swapr_ethereum_base_trades.sql deleted file mode 100644 index 178918a1b62..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/swapr_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'swapr_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'swapr', - version = '1', - Pair_evt_Swap = source('swapr_ethereum', 'DXswapPair_evt_Swap'), - Factory_evt_PairCreated = source('swapr_ethereum', 'DXswapFactory_evt_PairCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql deleted file mode 100644 index 847bc1a333d..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v1_ethereum_base_trades.sql +++ /dev/null @@ -1,83 +0,0 @@ -{{ config( - schema = 'uniswap_v1_ethereum' - , alias = 'base_trades' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['tx_hash', 'evt_index'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} - -WITH dexs AS -( - -- Uniswap v1 TokenPurchase - SELECT - t.evt_block_number AS block_number - , t.evt_block_time AS block_time - , t.buyer AS taker - , CAST(NULL as VARBINARY) AS maker - , t.tokens_bought AS token_bought_amount_raw - , t.eth_sold AS token_sold_amount_raw - , f.token AS token_bought_address - , {{weth_address}} 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_TokenPurchase') }} t - INNER JOIN - {{ source('uniswap_ethereum', 'Factory_evt_NewExchange') }} f - ON f.exchange = t.contract_address - {% if is_incremental() %} - WHERE - {{incremental_predicate('t.evt_block_time')}} - {% endif %} - - UNION ALL - - -- Uniswap v1 EthPurchase - SELECT - t.evt_block_number AS block_number - , t.evt_block_time AS block_time - , t.buyer AS taker - , CAST(NULL as VARBINARY) AS maker - , t.eth_bought AS token_bought_amount_raw - , t.tokens_sold AS token_sold_amount_raw - , {{weth_address}} AS token_bought_address - , 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 - INNER JOIN - {{ source('uniswap_ethereum', 'Factory_evt_NewExchange') }} f - ON f.exchange = t.contract_address - {% if is_incremental() %} - WHERE - {{incremental_predicate('t.evt_block_time')}} - {% endif %} -) - -SELECT - 'ethereum' AS blockchain - , 'uniswap' AS project - , '1' AS version - , 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 - , dexs.block_number - , dexs.token_bought_amount_raw - , dexs.token_sold_amount_raw - , dexs.token_bought_address - , dexs.token_sold_address - , dexs.taker - , dexs.maker - , dexs.project_contract_address - , dexs.tx_hash - , dexs.evt_index -FROM - dexs \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql deleted file mode 100644 index ee09e49f22e..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql +++ /dev/null @@ -1,38 +0,0 @@ -{{ config( - schema = 'uniswap_v2_ethereum' - , alias = 'base_trades' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['tx_hash', 'evt_index'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set weth_ubomb_wash_trading_pair = '0xed9c854cb02de75ce4c9bba992828d6cb7fd5c71' %} -{% set weth_weth_wash_trading_pair = '0xf9c1fa7d41bf44ade1dd08d37cc68f67ae75bf92' %} -{% set feg_eth_wash_trading_pair = '0x854373387e41371ac6e307a1f29603c6fa10d872' %} - -WITH dexs AS -( - {{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum' - , project = 'uniswap' - , version = '2' - , Pair_evt_Swap = source('uniswap_v2_ethereum', 'Pair_evt_Swap') - , Factory_evt_PairCreated = source('uniswap_v2_ethereum', 'Factory_evt_PairCreated') - ) - }} -) - -SELECT - * -FROM - dexs -WHERE - project_contract_address NOT IN ( - {{weth_ubomb_wash_trading_pair}} - , {{weth_weth_wash_trading_pair}} - , {{feg_eth_wash_trading_pair}} - ) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql deleted file mode 100644 index 7ee56b5f041..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/uniswap_v3_ethereum_base_trades.sql +++ /dev/null @@ -1,20 +0,0 @@ -{{ config( - schema = 'uniswap_v3_ethereum' - , alias = 'base_trades' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['tx_hash', 'evt_index'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v3_trades( - blockchain = 'ethereum' - , project = 'uniswap' - , version = '3' - , Pair_evt_Swap = source('uniswap_v3_ethereum', 'Pair_evt_Swap') - , Factory_evt_PoolCreated = source('uniswap_v3_ethereum', 'Factory_evt_PoolCreated') - ) -}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql deleted file mode 100644 index d6b57b7a9e4..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/verse_dex_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'verse_dex_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'verse_dex', - version = '1', - Pair_evt_Swap = source('verse_dex_ethereum', 'SwapsPair_evt_Swap'), - Factory_evt_PairCreated = source('verse_dex_ethereum', 'Factory_evt_PairCreated') - ) -}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/xchange_ethereum_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/xchange_ethereum_base_trades.sql deleted file mode 100644 index 4ceb2bd84eb..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/platforms/xchange_ethereum_base_trades.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - schema = 'xchange_ethereum', - alias = 'base_trades', - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{ - uniswap_compatible_v2_trades( - blockchain = 'ethereum', - project = 'xchange', - version = '1', - Pair_evt_Swap = source('xchange_ethereum', 'XchangePair_evt_Swap'), - Factory_evt_PairCreated = source('xchange_ethereum', 'XchangeFactory_evt_PairCreated') - ) -}} From e097619a051aa8968f6386a53b496c2f3ff2e3c4 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 14:52:35 +0200 Subject: [PATCH 41/86] fix dbt compile --- .../_log_decoded_trades/ethereum/_schema.yml | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml index 340772338ef..22817d2a9c7 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/_schema.yml @@ -1,44 +1 @@ version: 2 - -models: - - - name: uniswap_v2_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: jeff-dude, masquot, soispoke, hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v2' ] - description: "uniswap ethereum v2 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('uniswap_ethereum_base_trades_seed') - filter: - version: 2 - - - name: uniswap_v3_ethereum_base_trades - meta: - blockchain: ethereum - sector: dex - project: uniswap - contributors: jeff-dude, masquot, soispoke, hosuke - config: - tags: [ 'ethereum', 'dex', 'trades', 'uniswap', 'v3' ] - description: "uniswap ethereum v3 base trades" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - check_dex_base_trades_seed: - seed_file: ref('uniswap_ethereum_base_trades_seed') - filter: - version: 3 - - - From f47df164f0d6cd81a470990962c873d58099a506 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 15:11:04 +0200 Subject: [PATCH 42/86] remove factory_address duplicate from mass_decoded_dex_trades_ethereum.sql --- .../decoded-in-flight/mass_decoded_dex_trades_ethereum.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql index b66dc73198d..b21a9584bb2 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/mass_decoded_dex_trades_ethereum.sql @@ -34,7 +34,6 @@ WITH base_union AS ( , project_contract_address , tx_hash , evt_index - , factory_address FROM {{ base_model }} {% if not loop.last %} From 436dcb429e28f7a11a5acf415dcebffa91cdfbb9 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 15:33:21 +0200 Subject: [PATCH 43/86] add final select to dex_trades --- .../dex/models/_log_decoded_trades/log_decoded_dex_trades.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql index 83c2552f8cf..e89935b49f9 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql @@ -43,3 +43,5 @@ with dexs AS ( }} ) +Select * from dexs + From 55a17cb47adb52387a6d98eb7b5b8dd6e04dc792 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 16:58:54 +0200 Subject: [PATCH 44/86] remove duplicate dex_trades --- .../log_decoded_dex_trades.sql | 1 + .../mass-decoded/mass_decoded_dex_trades.sql | 27 ------------------- .../dex/models/trades/mass-decoded/schema.yml | 18 ------------- 3 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql delete mode 100644 dbt_subprojects/dex/models/trades/mass-decoded/schema.yml diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql index e89935b49f9..8e7e8950e64 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql @@ -44,4 +44,5 @@ with dexs AS ( ) Select * from dexs +where block_date > now() - interval '10' day diff --git a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql b/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql deleted file mode 100644 index f12b9b4f3a5..00000000000 --- a/dbt_subprojects/dex/models/trades/mass-decoded/mass_decoded_dex_trades.sql +++ /dev/null @@ -1,27 +0,0 @@ -{{ config( - schema = 'mass_decoded_dex_trades' - , alias = 'trades' - , partition_by = ['block_month', 'blockchain', 'project'] - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "blast", "bnb", "celo", "ethereum", "fantom", "gnosis", "linea", "optimism", "polygon", "scroll", "zkevm", "zksync", "zora"]\', - "sector", - "dex", - \'["hosuke", "0xrob", "jeff-dude", "tomfutago"]\') }}') -}} - - -with dexs AS ( - {{ - enrich_dex_trades( - base_trades = ref('mass_decoded_dex_trades_ethereum') - , filter = "1=1" - , tokens_erc20_model = source('tokens', 'erc20') - ) - }} -) - -Select * from dexs \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/mass-decoded/schema.yml b/dbt_subprojects/dex/models/trades/mass-decoded/schema.yml deleted file mode 100644 index cc2a50c5568..00000000000 --- a/dbt_subprojects/dex/models/trades/mass-decoded/schema.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: 2 - -models: - - name: mass_decoded_dex_trades - meta: - blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, optimism, polygon, scroll, zksync, linea, blast, sei - sector: dex - contributors: 0xRob, hosuke, jeff-dude, tomfutago - config: - tags: [ 'dex', 'trades', 'beta' ] - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - project - - version - - tx_hash - - evt_index \ No newline at end of file From 1ee90adefdd27449d6e237c76a0030f8a82c18c5 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 17:20:55 +0200 Subject: [PATCH 45/86] add mode --- .../log_decoded_dex_base_trades.sql | 1 + .../log_decoded_dex_trades.sql | 1 - .../_log_decoded_trades/mode/_schema.yml | 1 + .../mode/decoded-in-flight/_schema.yml | 75 +++++++++++++++++++ .../mass_decoded_dex_trades_mode.sql | 53 +++++++++++++ .../uniswap_v2_factory_decoding_mode.sql | 16 ++++ .../uniswap_v2_fork_mapping_mode.sql | 56 ++++++++++++++ .../uniswap_v2_forks_base_trades_mode.sql | 20 +++++ .../uniswap_v2_pool_decoding_mode.sql | 16 ++++ .../uniswap_v3_factory_decoding_mode.sql | 17 +++++ .../uniswap_v3_fork_mapping_mode.sql | 19 +++++ .../uniswap_v3_forks_base_trades_mode.sql | 21 ++++++ .../uniswap_v3_pool_decoding_mode.sql | 16 ++++ 13 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql index 403d08e648a..09518714e42 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql @@ -12,6 +12,7 @@ {% set models = [ ref('mass_decoded_dex_trades_ethereum') + , ref('mass_decoded_dex_trades_mode') ] %} with base_union as ( diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql index 8e7e8950e64..e89935b49f9 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql @@ -44,5 +44,4 @@ with dexs AS ( ) Select * from dexs -where block_date > now() - interval '10' day diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml new file mode 100644 index 00000000000..22817d2a9c7 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml @@ -0,0 +1 @@ +version: 2 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml new file mode 100644 index 00000000000..1423879f562 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml @@ -0,0 +1,75 @@ +version: 2 + +models: + - name: uniswap_v2_factory_decoding_mode + description: > + mass decoding of all forks of uniswap v2 factory contract on mode + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + + - name: uniswap_v2_pool_decoding_mode + description: > + mass decoding of all forks of uniswap v2 pool contracts on mode + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + + - name: uniswap_v2_fork_mapping_mode + description: > + mapping of all forks of uniswap v2 factory contract on mode + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - factory_address + columns: + - name: factory_address + description: "address of the factory contract" + - name: project_name + description: "name of the project associated with the factory" + + - name: uniswap_v2_forks_base_trades_mode + meta: + blockchain: mode + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'mode', 'dex', 'trades', 'uniswap', 'v2', 'forks' ] + description: "base trades for all forks of uniswap v2 on mode" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + + - name: uniswap_v3_forks_base_trades_mode + meta: + blockchain: mode + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'mode', 'dex', 'trades', 'uniswap', 'v3', 'forks' ] + description: "base trades for all forks of uniswap v3 on mode" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + + - name: mass_decoded_dex_trades_mode + description: "all dex trades on mode, mass decoded" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql new file mode 100644 index 00000000000..195b50beb3a --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql @@ -0,0 +1,53 @@ +{{ config( + schema = 'dex_mode' + , alias = 'mass_decoded_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + + ref('uniswap_v2_forks_base_trades_mode') + , ref('uniswap_v3_forks_base_trades_mode') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , dex_type + , factory_address + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'mode' + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql new file mode 100644 index 00000000000..bfe4c451138 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'mass_decoding_mode', + alias = 'uniswap_v2_factory_evt_PairCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_factory_mass_decoding( + logs = source('mode', 'logs') +)}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql new file mode 100644 index 00000000000..e964499d4a1 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql @@ -0,0 +1,56 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_mode', + alias = 'uniswap_v2_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') + , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') + , (0x9deb29c9a4c7a88a3c0257393b7f3335338d9a9d, 'crodefi') + , (0x1097053fd2ea711dad45caccc45eff7548fcb362, 'pancakeswap_v2') + , (0x43ec799eadd63848443e2347c49f5f52e8fe0f6f, 'fraxswap') + , (0xee3e9e46e34a27dc755a63e2849c9913ee1a06e2, 'verse_dex') + , (0xc480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6, 'integral_size') + , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') + , (0x4eef5746ed22a2fd368629c1852365bf5dcb79f1, 'convergence') + , (0x1e895bfe59e3a5103e8b7da3897d1f2391476f3c, 'DooarSwap') + , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') + , (0x75e48c954594d64ef9613aeef97ad85370f13807, 'sakeswap') + , (0x696708db871b77355d6c2be7290b27cf0bb9b24b, 'linkswap_v1') + , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') + , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') + , (0x0388c1e0f210abae597b7de712b9510c6c36c857, 'luaswap') + , (0xa40ec8a93293a3179d4b544239916c1b68cb47b6, 'SunflowerSwap') + , (0x460b2005b3318982feada99f7ebf13e1d6f6effe, 'pepedex') + , (0x1264f802364e0776b9a9e3d161b43c7333ac08b2, 'rhino_fi') + , (0x7de800467afce442019884f51a4a1b9143a34fac, 'xchange') + , (0xd87ad19db2c4ccbf897106de034d52e3dd90ea60, 'plasmaswap') + , (0x46adc1c052fafd590f56c42e379d7d16622835a2, 'yape') + , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') + , (0xd34971bab6e5e356fd250715f5de0492bb070452, 'swapr') + , (0x35113a300ca0d7621374890abfeac30e88f214b1, 'SaitaSwap') + , (0xb076b06f669e682609fb4a8c6646d2619717be4b, 'fraxswap') + , (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') + , (0x5fbe219e88f6c6f214ce6f5b1fcaa0294f31ae1b, 'gammaswap') + , (0xbae5dc9b19004883d0377419fef3c2c8832d7d7b, 'apeswap') + , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'btswap') + , (0x26f53fbadeeb777fb2a122dc703433d79241b64e, 'light_dao') + , (0x08e7974cacf66c5a92a37c221a15d3c30c7d97e0, 'unifi') + , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') + , (0xf028f723ed1d0fe01cc59973c49298aa95c57472, 'SashimiSwap') + , (0x54f454d747e037da288db568d4121117eab34e79, 'bbb') + , (0x2d723f60ad8da76286b2ac120498a5ea6babc792, 'neopin') + , (0x91fAe1bc94A9793708fbc66aDcb59087C46dEe10, 'radioshack') + , (0xe185e5335d68c2a18564b4b43bdf4ed86337ee70, 'quantoswap') +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql new file mode 100644 index 00000000000..2cadfbf6de1 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql @@ -0,0 +1,20 @@ +{{ config( + + schema = 'dex_mass_decoding_mode', + alias = 'uniswap_v2_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_forks_trades( + blockchain = 'mode' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_mode') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_mode') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql new file mode 100644 index 00000000000..8aba35e0594 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'mass_decoding_mode', + alias = 'uniswap_v2_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_pool_mass_decoding( + logs = source('mode', 'logs') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql new file mode 100644 index 00000000000..bc2567a559e --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql @@ -0,0 +1,17 @@ +{{ config( + + schema = 'mass_decoding_mode', + alias = 'uniswap_v3_factory_evt_PoolCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_factory_mass_decoding( + logs = source('mode', 'logs') +)}} + diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql new file mode 100644 index 00000000000..a774793c48d --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql @@ -0,0 +1,19 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_mode', + alias = 'uniswap_v3_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql new file mode 100644 index 00000000000..204d965cd27 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql @@ -0,0 +1,21 @@ +{{ config( + + schema = 'dex_mass_decoding_mode', + alias = 'uniswap_v3_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_forks_trades( + blockchain = 'mode' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_mode') + , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_mode') +)}} + diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql new file mode 100644 index 00000000000..031ec51eeca --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'dex_mass_decoding_mode', + alias = 'uniswap_v3_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_pool_mass_decoding( + logs = source('mode', 'logs') +)}} \ No newline at end of file From 4a326a157df86a1f21f44494fc105695e6c6e03d Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 18:46:44 +0200 Subject: [PATCH 46/86] add arbitrum files --- .../_log_decoded_trades/arbitrum/_schema.yml | 1 + .../arbitrum/decoded-in-flight/_schema.yml | 75 +++++++++++++++++++ .../mass_decoded_dex_trades_arbitrum.sql | 53 +++++++++++++ .../uniswap_v2_factory_decoding_arbitrum.sql | 16 ++++ .../uniswap_v2_fork_mapping_arbitrum.sql | 56 ++++++++++++++ .../uniswap_v2_forks_base_trades_arbitrum.sql | 20 +++++ .../uniswap_v2_pool_decoding_arbitrum.sql | 16 ++++ .../uniswap_v3_factory_decoding_arbitrum.sql | 17 +++++ .../uniswap_v3_fork_mapping_arbitrum.sql | 19 +++++ .../uniswap_v3_forks_base_trades_arbitrum.sql | 21 ++++++ .../uniswap_v3_pool_decoding_arbitrum.sql | 16 ++++ .../log_decoded_dex_base_trades.sql | 1 + 12 files changed, 311 insertions(+) create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/_schema.yml create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/mass_decoded_dex_trades_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql create mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/_schema.yml new file mode 100644 index 00000000000..22817d2a9c7 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/_schema.yml @@ -0,0 +1 @@ +version: 2 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml new file mode 100644 index 00000000000..c360184cf2f --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml @@ -0,0 +1,75 @@ +version: 2 + +models: + - name: uniswap_v2_factory_decoding_arbitrum + description: > + mass decoding of all forks of uniswap v2 factory contract on arbitrum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + + - name: uniswap_v2_pool_decoding_arbitrum + description: > + mass decoding of all forks of uniswap v2 pool contracts on arbitrum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + + - name: uniswap_v2_fork_mapping_arbitrum + description: > + mapping of all forks of uniswap v2 factory contract on arbitrum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - factory_address + columns: + - name: factory_address + description: "address of the factory contract" + - name: project_name + description: "name of the project associated with the factory" + + - name: uniswap_v2_forks_base_trades_arbitrum + meta: + blockchain: arbitrum + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'arbitrum', 'dex', 'trades', 'uniswap', 'v2', 'forks' ] + description: "base trades for all forks of uniswap v2 on arbitrum" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + + - name: uniswap_v3_forks_base_trades_arbitrum + meta: + blockchain: arbitrum + sector: dex + project: uniswap + contributors: 0xboxer + config: + tags: [ 'arbitrum', 'dex', 'trades', 'uniswap', 'v3', 'forks' ] + description: "base trades for all forks of uniswap v3 on arbitrum" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + + - name: mass_decoded_dex_trades_arbitrum + description: "all dex trades on arbitrum, mass decoded" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - project_contract_address + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/mass_decoded_dex_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/mass_decoded_dex_trades_arbitrum.sql new file mode 100644 index 00000000000..f301ebad5a2 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/mass_decoded_dex_trades_arbitrum.sql @@ -0,0 +1,53 @@ +{{ config( + schema = 'dex_arbitrum' + , alias = 'mass_decoded_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + + ref('uniswap_v2_forks_base_trades_arbitrum') + , ref('uniswap_v3_forks_base_trades_arbitrum') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , dex_type + , factory_address + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'arbitrum' + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql new file mode 100644 index 00000000000..471188a21f0 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'mass_decoding_arbitrum', + alias = 'uniswap_v2_factory_evt_PairCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_factory_mass_decoding( + logs = source('arbitrum', 'logs') +)}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_arbitrum.sql new file mode 100644 index 00000000000..4eb5ef668ea --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_arbitrum.sql @@ -0,0 +1,56 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_arbitrum', + alias = 'uniswap_v2_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') + , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') + , (0x9deb29c9a4c7a88a3c0257393b7f3335338d9a9d, 'crodefi') + , (0x1097053fd2ea711dad45caccc45eff7548fcb362, 'pancakeswap_v2') + , (0x43ec799eadd63848443e2347c49f5f52e8fe0f6f, 'fraxswap') + , (0xee3e9e46e34a27dc755a63e2849c9913ee1a06e2, 'verse_dex') + , (0xc480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6, 'integral_size') + , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') + , (0x4eef5746ed22a2fd368629c1852365bf5dcb79f1, 'convergence') + , (0x1e895bfe59e3a5103e8b7da3897d1f2391476f3c, 'DooarSwap') + , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') + , (0x75e48c954594d64ef9613aeef97ad85370f13807, 'sakeswap') + , (0x696708db871b77355d6c2be7290b27cf0bb9b24b, 'linkswap_v1') + , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') + , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') + , (0x0388c1e0f210abae597b7de712b9510c6c36c857, 'luaswap') + , (0xa40ec8a93293a3179d4b544239916c1b68cb47b6, 'SunflowerSwap') + , (0x460b2005b3318982feada99f7ebf13e1d6f6effe, 'pepedex') + , (0x1264f802364e0776b9a9e3d161b43c7333ac08b2, 'rhino_fi') + , (0x7de800467afce442019884f51a4a1b9143a34fac, 'xchange') + , (0xd87ad19db2c4ccbf897106de034d52e3dd90ea60, 'plasmaswap') + , (0x46adc1c052fafd590f56c42e379d7d16622835a2, 'yape') + , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') + , (0xd34971bab6e5e356fd250715f5de0492bb070452, 'swapr') + , (0x35113a300ca0d7621374890abfeac30e88f214b1, 'SaitaSwap') + , (0xb076b06f669e682609fb4a8c6646d2619717be4b, 'fraxswap') + , (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') + , (0x5fbe219e88f6c6f214ce6f5b1fcaa0294f31ae1b, 'gammaswap') + , (0xbae5dc9b19004883d0377419fef3c2c8832d7d7b, 'apeswap') + , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'btswap') + , (0x26f53fbadeeb777fb2a122dc703433d79241b64e, 'light_dao') + , (0x08e7974cacf66c5a92a37c221a15d3c30c7d97e0, 'unifi') + , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') + , (0xf028f723ed1d0fe01cc59973c49298aa95c57472, 'SashimiSwap') + , (0x54f454d747e037da288db568d4121117eab34e79, 'bbb') + , (0x2d723f60ad8da76286b2ac120498a5ea6babc792, 'neopin') + , (0x91fAe1bc94A9793708fbc66aDcb59087C46dEe10, 'radioshack') + , (0xe185e5335d68c2a18564b4b43bdf4ed86337ee70, 'quantoswap') +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql new file mode 100644 index 00000000000..09dccfc9de0 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -0,0 +1,20 @@ +{{ config( + + schema = 'dex_mass_decoding_arbitrum', + alias = 'uniswap_v2_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_forks_trades( + blockchain = 'arbitrum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_arbitrum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_arbitrum') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql new file mode 100644 index 00000000000..a4ada2fbc01 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'mass_decoding_arbitrum', + alias = 'uniswap_v2_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v2_pool_mass_decoding( + logs = source('arbitrum', 'logs') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql new file mode 100644 index 00000000000..bae110079f1 --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql @@ -0,0 +1,17 @@ +{{ config( + + schema = 'mass_decoding_arbitrum', + alias = 'uniswap_v3_factory_evt_PoolCreated', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_factory_mass_decoding( + logs = source('arbitrum', 'logs') +)}} + diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql new file mode 100644 index 00000000000..2338f30836f --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql @@ -0,0 +1,19 @@ +-- this should probably live somewhere else, just for testing purposes for now + +{{ config( + schema = 'dex_mass_decoding_arbitrum', + alias = 'uniswap_v3_fork_mapping', + tags = ['static'], + unique_key = ['factory_address']) +}} + +SELECT factory_address, project_name +FROM +(VALUES + (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') + , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + +) AS t (factory_address, project_name) + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql new file mode 100644 index 00000000000..553e70e232c --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -0,0 +1,21 @@ +{{ config( + + schema = 'dex_mass_decoding_arbitrum', + alias = 'uniswap_v3_base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_forks_trades( + blockchain = 'arbitrum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_arbitrum') + , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_arbitrum') +)}} + diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql new file mode 100644 index 00000000000..73b7774ea3a --- /dev/null +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql @@ -0,0 +1,16 @@ +{{ config( + + schema = 'dex_mass_decoding_arbitrum', + alias = 'uniswap_v3_pool_evt_Swap', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{uniswap_v3_pool_mass_decoding( + logs = source('arbitrum', 'logs') +)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql index 09518714e42..53a6c8adbb3 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql @@ -13,6 +13,7 @@ {% set models = [ ref('mass_decoded_dex_trades_ethereum') , ref('mass_decoded_dex_trades_mode') + , ref('mass_decoded_dex_trades_arbitrum') ] %} with base_union as ( From e50e4e612762aeda9d2abdea8d3898d20d3da840 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 22:26:04 +0200 Subject: [PATCH 47/86] fixing creation traces --- .../in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql | 2 +- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index d1e4b342b7b..1f4aee86a5c 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -30,7 +30,7 @@ WITH dexs AS {{ Factory_evt_PairCreated }} f ON f.{{ pair_column_name }} = t.contract_address --some scammers emitted events with established pair addresses, joining in the the creation trace to resolve correct factory - INNER JOIN {{ source('ethereum', 'creation_traces') }} ct + INNER JOIN {{ source(blockchain, 'creation_traces') }} ct ON f.{{ pair_column_name }} = ct.address AND f.contract_address = ct."from" {% if is_incremental() %} diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 0d6b5a17828..e4fcf12709e 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -36,7 +36,7 @@ WITH dexs AS {{ Factory_evt_PoolCreated }} f ON f.{{ pair_column_name }} = t.contract_address --some scammers emitted events with established pair addresses, joining in the the creation trace to resolve to correct factory - INNER JOIN {{ source('ethereum', 'creation_traces') }} ct + INNER JOIN {{ source(blockchain, 'creation_traces') }} ct ON f.{{ pair_column_name }} = ct.address AND f.contract_address = ct."from" {% if is_incremental() %} From 72d94ac0622cd10ff37b07cbb1bc87a1e2bb9bfb Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 22:26:45 +0200 Subject: [PATCH 48/86] remove mode because no creation traces --- .../_log_decoded_trades/mode/_schema.yml | 1 - .../mode/decoded-in-flight/_schema.yml | 75 ------------------- .../mass_decoded_dex_trades_mode.sql | 53 ------------- .../uniswap_v2_factory_decoding_mode.sql | 16 ---- .../uniswap_v2_fork_mapping_mode.sql | 56 -------------- .../uniswap_v2_forks_base_trades_mode.sql | 20 ----- .../uniswap_v2_pool_decoding_mode.sql | 16 ---- .../uniswap_v3_factory_decoding_mode.sql | 17 ----- .../uniswap_v3_fork_mapping_mode.sql | 19 ----- .../uniswap_v3_forks_base_trades_mode.sql | 21 ------ .../uniswap_v3_pool_decoding_mode.sql | 16 ---- 11 files changed, 310 deletions(-) delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql delete mode 100644 dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml deleted file mode 100644 index 22817d2a9c7..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/_schema.yml +++ /dev/null @@ -1 +0,0 @@ -version: 2 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml deleted file mode 100644 index 1423879f562..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/_schema.yml +++ /dev/null @@ -1,75 +0,0 @@ -version: 2 - -models: - - name: uniswap_v2_factory_decoding_mode - description: > - mass decoding of all forks of uniswap v2 factory contract on mode - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - index - - - name: uniswap_v2_pool_decoding_mode - description: > - mass decoding of all forks of uniswap v2 pool contracts on mode - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - index - - - name: uniswap_v2_fork_mapping_mode - description: > - mapping of all forks of uniswap v2 factory contract on mode - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - factory_address - columns: - - name: factory_address - description: "address of the factory contract" - - name: project_name - description: "name of the project associated with the factory" - - - name: uniswap_v2_forks_base_trades_mode - meta: - blockchain: mode - sector: dex - project: uniswap - contributors: 0xboxer - config: - tags: [ 'mode', 'dex', 'trades', 'uniswap', 'v2', 'forks' ] - description: "base trades for all forks of uniswap v2 on mode" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - project_contract_address - - - name: uniswap_v3_forks_base_trades_mode - meta: - blockchain: mode - sector: dex - project: uniswap - contributors: 0xboxer - config: - tags: [ 'mode', 'dex', 'trades', 'uniswap', 'v3', 'forks' ] - description: "base trades for all forks of uniswap v3 on mode" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - project_contract_address - - - name: mass_decoded_dex_trades_mode - description: "all dex trades on mode, mass decoded" - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - tx_hash - - evt_index - - project_contract_address - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql deleted file mode 100644 index 195b50beb3a..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/mass_decoded_dex_trades_mode.sql +++ /dev/null @@ -1,53 +0,0 @@ -{{ config( - schema = 'dex_mode' - , alias = 'mass_decoded_trades' - , materialized = 'view' - ) -}} - -{% set base_models = [ - - ref('uniswap_v2_forks_base_trades_mode') - , ref('uniswap_v3_forks_base_trades_mode') -] %} - -WITH base_union AS ( - SELECT * - FROM ( - {% for base_model in base_models %} - SELECT - blockchain - , project - , version - , dex_type - , factory_address - , block_month - , block_date - , block_time - , block_number - , token_bought_amount_raw - , token_sold_amount_raw - , token_bought_address - , token_sold_address - , taker - , maker - , project_contract_address - , tx_hash - , evt_index - FROM - {{ base_model }} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} - ) -) - -{{ - add_tx_columns( - model_cte = 'base_union' - , blockchain = 'mode' - , columns = ['from', 'to', 'index'] - ) -}} - diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql deleted file mode 100644 index bfe4c451138..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_mode.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config( - - schema = 'mass_decoding_mode', - alias = 'uniswap_v2_factory_evt_PairCreated', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v2_factory_mass_decoding( - logs = source('mode', 'logs') -)}} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql deleted file mode 100644 index e964499d4a1..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_fork_mapping_mode.sql +++ /dev/null @@ -1,56 +0,0 @@ --- this should probably live somewhere else, just for testing purposes for now - -{{ config( - schema = 'dex_mass_decoding_mode', - alias = 'uniswap_v2_fork_mapping', - tags = ['static'], - unique_key = ['factory_address']) -}} - -SELECT factory_address, project_name -FROM -(VALUES - (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') - , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') - , (0xb8900621b03892c2d030e05cb9e01f6474814f6a, 'sweepnflip') - , (0x115934131916c8b277dd010ee02de363c09d037c, 'shibaswap') - , (0x9deb29c9a4c7a88a3c0257393b7f3335338d9a9d, 'crodefi') - , (0x1097053fd2ea711dad45caccc45eff7548fcb362, 'pancakeswap_v2') - , (0x43ec799eadd63848443e2347c49f5f52e8fe0f6f, 'fraxswap') - , (0xee3e9e46e34a27dc755a63e2849c9913ee1a06e2, 'verse_dex') - , (0xc480b33ee5229de3fbdfad1d2dcd3f3bad0c56c6, 'integral_size') - , (0xcbae5c3f8259181eb7e2309bc4c72fdf02dd56d8, '9inch') - , (0x4eef5746ed22a2fd368629c1852365bf5dcb79f1, 'convergence') - , (0x1e895bfe59e3a5103e8b7da3897d1f2391476f3c, 'DooarSwap') - , (0x5fa0060fcfea35b31f7a5f6025f0ff399b98edf1, 'OrionProtocol') - , (0x75e48c954594d64ef9613aeef97ad85370f13807, 'sakeswap') - , (0x696708db871b77355d6c2be7290b27cf0bb9b24b, 'linkswap_v1') - , (0x52fba58f936833f8b643e881ad308b2e37713a86, 'pepex') - , (0x25393bb68c89a894b5e20fa3fc3b3b34f843c672, 'SaitaSwap') - , (0x0388c1e0f210abae597b7de712b9510c6c36c857, 'luaswap') - , (0xa40ec8a93293a3179d4b544239916c1b68cb47b6, 'SunflowerSwap') - , (0x460b2005b3318982feada99f7ebf13e1d6f6effe, 'pepedex') - , (0x1264f802364e0776b9a9e3d161b43c7333ac08b2, 'rhino_fi') - , (0x7de800467afce442019884f51a4a1b9143a34fac, 'xchange') - , (0xd87ad19db2c4ccbf897106de034d52e3dd90ea60, 'plasmaswap') - , (0x46adc1c052fafd590f56c42e379d7d16622835a2, 'yape') - , (0x6c565c5bbdc7f023cae8a2495105a531caac6e54, 'groveswap') - , (0xd34971bab6e5e356fd250715f5de0492bb070452, 'swapr') - , (0x35113a300ca0d7621374890abfeac30e88f214b1, 'SaitaSwap') - , (0xb076b06f669e682609fb4a8c6646d2619717be4b, 'fraxswap') - , (0xfb1eb9a45feb7269f3277233af513482bc04ea63, 'Swapos') - , (0x5fbe219e88f6c6f214ce6f5b1fcaa0294f31ae1b, 'gammaswap') - , (0xbae5dc9b19004883d0377419fef3c2c8832d7d7b, 'apeswap') - , (0x1fed2e360a5afb2ac4b047102a7012a57f3c8cab, 'btswap') - , (0x26f53fbadeeb777fb2a122dc703433d79241b64e, 'light_dao') - , (0x08e7974cacf66c5a92a37c221a15d3c30c7d97e0, 'unifi') - , (0xfae6a4370a3499f363461647fd54d110b3c8dc64, 'CelSwap') - , (0xf028f723ed1d0fe01cc59973c49298aa95c57472, 'SashimiSwap') - , (0x54f454d747e037da288db568d4121117eab34e79, 'bbb') - , (0x2d723f60ad8da76286b2ac120498a5ea6babc792, 'neopin') - , (0x91fAe1bc94A9793708fbc66aDcb59087C46dEe10, 'radioshack') - , (0xe185e5335d68c2a18564b4b43bdf4ed86337ee70, 'quantoswap') -) AS t (factory_address, project_name) - - - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql deleted file mode 100644 index 2cadfbf6de1..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_mode.sql +++ /dev/null @@ -1,20 +0,0 @@ -{{ config( - - schema = 'dex_mass_decoding_mode', - alias = 'uniswap_v2_base_trades', - partition_by = ['block_month'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v2_forks_trades( - blockchain = 'mode' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_mode') - , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_mode') -)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql deleted file mode 100644 index 8aba35e0594..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_mode.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config( - - schema = 'mass_decoding_mode', - alias = 'uniswap_v2_pool_evt_Swap', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v2_pool_mass_decoding( - logs = source('mode', 'logs') -)}} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql deleted file mode 100644 index bc2567a559e..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_mode.sql +++ /dev/null @@ -1,17 +0,0 @@ -{{ config( - - schema = 'mass_decoding_mode', - alias = 'uniswap_v3_factory_evt_PoolCreated', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v3_factory_mass_decoding( - logs = source('mode', 'logs') -)}} - diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql deleted file mode 100644 index a774793c48d..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_mode.sql +++ /dev/null @@ -1,19 +0,0 @@ --- this should probably live somewhere else, just for testing purposes for now - -{{ config( - schema = 'dex_mass_decoding_mode', - alias = 'uniswap_v3_fork_mapping', - tags = ['static'], - unique_key = ['factory_address']) -}} - -SELECT factory_address, project_name -FROM -(VALUES - (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') - , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') - -) AS t (factory_address, project_name) - - - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql deleted file mode 100644 index 204d965cd27..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_mode.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ config( - - schema = 'dex_mass_decoding_mode', - alias = 'uniswap_v3_base_trades', - partition_by = ['block_month'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v3_forks_trades( - blockchain = 'mode' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_mode') - , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_mode') -)}} - diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql b/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql deleted file mode 100644 index 031ec51eeca..00000000000 --- a/dbt_subprojects/dex/models/_log_decoded_trades/mode/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_mode.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config( - - schema = 'dex_mass_decoding_mode', - alias = 'uniswap_v3_pool_evt_Swap', - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{{uniswap_v3_pool_mass_decoding( - logs = source('mode', 'logs') -)}} \ No newline at end of file From 43cd31bda05b6cb5978ff7063b6b0f2d953ad127 Mon Sep 17 00:00:00 2001 From: Boxer Date: Fri, 30 Aug 2024 22:35:33 +0200 Subject: [PATCH 49/86] fix --- .../models/_log_decoded_trades/log_decoded_dex_base_trades.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql index 53a6c8adbb3..504b53ec611 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql @@ -12,7 +12,6 @@ {% set models = [ ref('mass_decoded_dex_trades_ethereum') - , ref('mass_decoded_dex_trades_mode') , ref('mass_decoded_dex_trades_arbitrum') ] %} From 63d39a602411921502d0223caa2c313598fb88a8 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 03:52:46 +0800 Subject: [PATCH 50/86] Exclude unknown factory addresses --- .../uniswap_v2_forks_base_trades_ethereum.sql | 25 +++++++++++++------ .../uniswap_v3_forks_base_trades_ethereum.sql | 24 ++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index dae82d4239f..f59fe6d6c3d 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -11,10 +11,21 @@ ) }} -{{uniswap_v2_forks_trades( - blockchain = 'ethereum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') - , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') -)}} \ No newline at end of file +WITH all_decoded_trades( + {{ + uniswap_v2_forks_trades( + blockchain = 'ethereum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') + ) + }} +) + +SELECT + fork_mapping.project_name as project + , all_decoded_trades.* +FROM all_decoded_trades +INNER JOIN {{ ref('uniswap_v2_fork_mapping') }} AS fork_mapping +USING (factory_address) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 074296af85b..ba854681113 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -11,11 +11,21 @@ ) }} -{{uniswap_v3_forks_trades( - blockchain = 'ethereum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') - , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_ethereum') -)}} +WITH all_decoded_trades( + {{ + uniswap_v3_forks_trades( + blockchain = 'ethereum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_ethereum') + , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_ethereum') + ) + }} +) +SELECT + fork_mapping.project_name as project + , all_decoded_trades.* +FROM all_decoded_trades +INNER JOIN {{ ref('uniswap_v3_fork_mapping') }} AS fork_mapping +USING (factory_address) \ No newline at end of file From 5099ff85cd2924a53672fe0706d9be23c51ad6ee Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 04:06:12 +0800 Subject: [PATCH 51/86] Update schema --- .../ethereum/decoded-in-flight/_schema.yml | 13 +++++++++++++ .../uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml index eda94470c32..a626619a751 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml @@ -63,6 +63,19 @@ models: - tx_hash - evt_index - project_contract_address + + - name: uniswap_v3_fork_mapping_ethereum + description: > + mapping of all forks of uniswap v3 factory contract on ethereum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - factory_address + columns: + - name: factory_address + description: "address of the factory contract" + - name: project_name + description: "name of the project associated with the factory" - name: mass_decoded_dex_trades_ethereum description: "all dex trades on ethereum, mass decoded" diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index f59fe6d6c3d..488bd164b3a 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -27,5 +27,5 @@ SELECT fork_mapping.project_name as project , all_decoded_trades.* FROM all_decoded_trades -INNER JOIN {{ ref('uniswap_v2_fork_mapping') }} AS fork_mapping +INNER JOIN {{ ref('uniswap_v2_fork_mapping_ethereum') }} AS fork_mapping USING (factory_address) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index ba854681113..083375d0a11 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -27,5 +27,5 @@ SELECT fork_mapping.project_name as project , all_decoded_trades.* FROM all_decoded_trades -INNER JOIN {{ ref('uniswap_v3_fork_mapping') }} AS fork_mapping +INNER JOIN {{ ref('uniswap_v3_fork_mapping_ethereum') }} AS fork_mapping USING (factory_address) \ No newline at end of file From 2e998970e89aaeab9525c834716191412191d431 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 09:01:09 +0800 Subject: [PATCH 52/86] Fix typo --- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 488bd164b3a..c250d4849b0 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -11,7 +11,7 @@ ) }} -WITH all_decoded_trades( +WITH all_decoded_trades AS ( {{ uniswap_v2_forks_trades( blockchain = 'ethereum' diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 083375d0a11..22d086ff79c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -11,7 +11,7 @@ ) }} -WITH all_decoded_trades( +WITH all_decoded_trades AS ( {{ uniswap_v3_forks_trades( blockchain = 'ethereum' From 2f1bf779769a554d4cfd360ff32320cccf265b5b Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 09:16:34 +0800 Subject: [PATCH 53/86] List all column --- .../uniswap_v2_forks_base_trades_ethereum.sql | 20 +++++++++++++++++-- .../uniswap_v3_forks_base_trades_ethereum.sql | 20 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index c250d4849b0..00a2b00d9bf 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -24,8 +24,24 @@ WITH all_decoded_trades AS ( ) SELECT - fork_mapping.project_name as project - , all_decoded_trades.* + all_decoded_trades.blockchain + , fork_mapping.project_name as project + , all_decoded_trades.version + , all_decoded_trades.dex_type + , all_decoded_trades.factory_address + , all_decoded_trades.block_month + , all_decoded_trades.block_date + , all_decoded_trades.block_time + , all_decoded_trades.block_number + , all_decoded_trades.token_bought_amount_raw + , all_decoded_trades.token_sold_amount_raw + , all_decoded_trades.token_bought_address + , all_decoded_trades.token_sold_address + , all_decoded_trades.taker + , all_decoded_trades.maker + , all_decoded_trades.project_contract_address + , all_decoded_trades.tx_hash + , all_decoded_trades.evt_index FROM all_decoded_trades INNER JOIN {{ ref('uniswap_v2_fork_mapping_ethereum') }} AS fork_mapping USING (factory_address) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 22d086ff79c..5711c88e748 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -24,8 +24,24 @@ WITH all_decoded_trades AS ( ) SELECT - fork_mapping.project_name as project - , all_decoded_trades.* + all_decoded_trades.blockchain + , fork_mapping.project_name as project + , all_decoded_trades.version + , all_decoded_trades.dex_type + , all_decoded_trades.factory_address + , all_decoded_trades.block_month + , all_decoded_trades.block_date + , all_decoded_trades.block_time + , all_decoded_trades.block_number + , all_decoded_trades.token_bought_amount_raw + , all_decoded_trades.token_sold_amount_raw + , all_decoded_trades.token_bought_address + , all_decoded_trades.token_sold_address + , all_decoded_trades.taker + , all_decoded_trades.maker + , all_decoded_trades.project_contract_address + , all_decoded_trades.tx_hash + , all_decoded_trades.evt_index FROM all_decoded_trades INNER JOIN {{ ref('uniswap_v3_fork_mapping_ethereum') }} AS fork_mapping USING (factory_address) \ No newline at end of file From ffc0679b415ddf1f84c64099150a55f394d4b86a Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 09:26:03 +0800 Subject: [PATCH 54/86] Fix --- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 00a2b00d9bf..6a3d218ac01 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -28,7 +28,7 @@ SELECT , fork_mapping.project_name as project , all_decoded_trades.version , all_decoded_trades.dex_type - , all_decoded_trades.factory_address + , factory_address , all_decoded_trades.block_month , all_decoded_trades.block_date , all_decoded_trades.block_time diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 5711c88e748..d33206b13f5 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -28,7 +28,7 @@ SELECT , fork_mapping.project_name as project , all_decoded_trades.version , all_decoded_trades.dex_type - , all_decoded_trades.factory_address + , factory_address , all_decoded_trades.block_month , all_decoded_trades.block_date , all_decoded_trades.block_time From 9cb081305c110edba06830cf28d2538964677d3b Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 19:47:31 +0800 Subject: [PATCH 55/86] Update arbitrum decoding trades --- .../arbitrum/decoded-in-flight/_schema.yml | 13 ++++++ .../uniswap_v2_forks_base_trades_arbitrum.sql | 41 +++++++++++++++---- .../uniswap_v3_forks_base_trades_arbitrum.sql | 40 ++++++++++++++---- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml index c360184cf2f..c7c44fc3006 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml @@ -63,6 +63,19 @@ models: - tx_hash - evt_index - project_contract_address + + - name: uniswap_v3_fork_mapping_arbitrum + description: > + mapping of all forks of uniswap v3 factory contract on arbitrum + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - factory_address + columns: + - name: factory_address + description: "address of the factory contract" + - name: project_name + description: "name of the project associated with the factory" - name: mass_decoded_dex_trades_arbitrum description: "all dex trades on arbitrum, mass decoded" diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 09dccfc9de0..1f00f2333e0 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -11,10 +11,37 @@ ) }} -{{uniswap_v2_forks_trades( - blockchain = 'arbitrum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_arbitrum') - , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_arbitrum') -)}} \ No newline at end of file +WITH all_decoded_trades AS ( + {{ + uniswap_v2_forks_trades( + blockchain = 'arbitrum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_arbitrum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_arbitrum') + ) + }} +) + +SELECT + all_decoded_trades.blockchain + , fork_mapping.project_name as project + , all_decoded_trades.version + , all_decoded_trades.dex_type + , factory_address + , all_decoded_trades.block_month + , all_decoded_trades.block_date + , all_decoded_trades.block_time + , all_decoded_trades.block_number + , all_decoded_trades.token_bought_amount_raw + , all_decoded_trades.token_sold_amount_raw + , all_decoded_trades.token_bought_address + , all_decoded_trades.token_sold_address + , all_decoded_trades.taker + , all_decoded_trades.maker + , all_decoded_trades.project_contract_address + , all_decoded_trades.tx_hash + , all_decoded_trades.evt_index +FROM all_decoded_trades +INNER JOIN {{ ref('uniswap_v2_fork_mapping_arbitrum') }} AS fork_mapping +USING (factory_address) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 553e70e232c..af939639569 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -11,11 +11,37 @@ ) }} -{{uniswap_v3_forks_trades( - blockchain = 'arbitrum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_arbitrum') - , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_arbitrum') -)}} +WITH all_decoded_trades AS ( + {{ + uniswap_v3_forks_trades( + blockchain = 'arbitrum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v3_pool_decoding_arbitrum') + , Factory_evt_PoolCreated = ref('uniswap_v3_factory_decoding_arbitrum') + ) + }} +) +SELECT + all_decoded_trades.blockchain + , fork_mapping.project_name as project + , all_decoded_trades.version + , all_decoded_trades.dex_type + , factory_address + , all_decoded_trades.block_month + , all_decoded_trades.block_date + , all_decoded_trades.block_time + , all_decoded_trades.block_number + , all_decoded_trades.token_bought_amount_raw + , all_decoded_trades.token_sold_amount_raw + , all_decoded_trades.token_bought_address + , all_decoded_trades.token_sold_address + , all_decoded_trades.taker + , all_decoded_trades.maker + , all_decoded_trades.project_contract_address + , all_decoded_trades.tx_hash + , all_decoded_trades.evt_index +FROM all_decoded_trades +INNER JOIN {{ ref('uniswap_v3_fork_mapping_arbitrum') }} AS fork_mapping +USING (factory_address) \ No newline at end of file From 8bd225fbd6f8661bceb8328eb051d45da410f057 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 20:30:34 +0800 Subject: [PATCH 56/86] Recover dodo_ethereum_base_trades --- .../ethereum/platforms/dodo_ethereum_base_trades.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql b/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql index 12ad69bdead..6797ecffdd9 100644 --- a/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/ethereum/platforms/dodo_ethereum_base_trades.sql @@ -11,7 +11,7 @@ }} {% set config_markets %} - WITH dodo_view_markets (market_contract_address, base_token_symbol, quote_token_symbol, base_token_address, quote_token_address) AS + WITH dodo_view_markets (market_contract_address, base_token_symbol, quote_token_symbol, base_token_address, quote_token_address) AS ( VALUES (0x75c23271661d9d143dcb617222bc4bec783eff34, 'WETH', 'USDC', 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), @@ -36,9 +36,9 @@ {% set config_other_sources = [ - {'version': '2_dvm', 'source': 'DVM_evt_DODOSwap'}, - {'version': '2_dpp', 'source': 'DPP_evt_DODOSwap'}, - {'version': '2_dsp', 'source': 'DSP_evt_DODOSwap'}, + {'version': '2', 'source': 'DVM_evt_DODOSwap'}, + {'version': '2', 'source': 'DPP_evt_DODOSwap'}, + {'version': '2', 'source': 'DSP_evt_DODOSwap'}, ] %} From 716b14d1eb9f54f8714a95f973afdfde036daaf2 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 12 Sep 2024 23:00:44 +0800 Subject: [PATCH 57/86] Update uni-v3 mapping --- .../uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql | 3 +-- .../uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql index 2338f30836f..4cbc3686102 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_arbitrum.sql @@ -10,8 +10,7 @@ SELECT factory_address, project_name FROM (VALUES - (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') - , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + (0x1F98431c8aD98523631AE4a59f267346ea31F984, 'uniswap_v3') ) AS t (factory_address, project_name) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql index 79021547194..935097a523a 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_fork_mapping_ethereum.sql @@ -10,8 +10,7 @@ SELECT factory_address, project_name FROM (VALUES - (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f, 'uniswap_v2') - , (0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac, 'sushi') + (0x1F98431c8aD98523631AE4a59f267346ea31F984, 'uniswap_v3') ) AS t (factory_address, project_name) From f528b41fa2037fef1c7d048e98d4d9fd0ec2a837 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 13 Sep 2024 00:11:51 +0800 Subject: [PATCH 58/86] Rename dex_automation_beta_trades --- .../dex/models/_log_decoded_trades/_schema.yml | 8 ++++---- ...ase_trades.sql => dex_automation_beta_base_trades.sql} | 4 ++-- ...oded_dex_trades.sql => dex_automation_beta_trades.sql} | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) rename dbt_subprojects/dex/models/_log_decoded_trades/{log_decoded_dex_base_trades.sql => dex_automation_beta_base_trades.sql} (96%) rename dbt_subprojects/dex/models/_log_decoded_trades/{log_decoded_dex_trades.sql => dex_automation_beta_trades.sql} (93%) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml index 7219aba1853..ade0e76cc33 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml @@ -1,13 +1,13 @@ version: 2 models: - - name: log_decoded_dex_trades + - name: dex_automation_beta_trades meta: docs_slug: /curated/trading/DEX/dex-trades blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, optimism, polygon, scroll, zksync, linea, blast, sei sector: dex short_description: The `dex.trades` table captures detailed data on trades executed via decentralized exchanges (DEXs). This table contains a detailed breakdown of trade execution containing one or many trades per transaction. - contributors: 0xRob, hosuke, jeff-dude, tomfutago + contributors: 0xBoxer, hosuke config: tags: [ 'dex', 'trades'] description: '{{ doc("dex_trades_doc") }}' @@ -100,11 +100,11 @@ models: name: evt_index description: "Index of the event in the transaction. Can be used to uniquely identify the order of trades within in a transaction" - - name: log_decoded_dex_base_trades + - name: dex_automation_beta_base_trades meta: blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, optimism, polygon, scroll, zksync, linea, blast, sei sector: dex - contributors: 0xRob, hosuke, jeff-dude, tomfutago, viniabussafi + contributors: 0xBoxer, hosuke config: tags: [ 'dex' ] tests: diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/dex_automation_beta_base_trades.sql similarity index 96% rename from dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/dex_automation_beta_base_trades.sql index 504b53ec611..1b79269ec35 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_base_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/dex_automation_beta_base_trades.sql @@ -1,6 +1,6 @@ {{ config( - schema = 'dex' - , alias = 'log_decoded_dex_base_trades' + schema = 'dex_automation_beta' + , alias = 'base_trades' , partition_by = ['block_month', 'blockchain', 'project'] , materialized = 'incremental' , file_format = 'delta' diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql b/dbt_subprojects/dex/models/_log_decoded_trades/dex_automation_beta_trades.sql similarity index 93% rename from dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql rename to dbt_subprojects/dex/models/_log_decoded_trades/dex_automation_beta_trades.sql index e89935b49f9..e6e7a4eefdc 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/log_decoded_dex_trades.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/dex_automation_beta_trades.sql @@ -1,6 +1,6 @@ {{ config( - schema = 'dex' - , alias = 'log_decoded_trades' + schema = 'dex_automation_beta' + , alias = 'trades' , partition_by = ['block_month', 'blockchain', 'project'] , materialized = 'incremental' , file_format = 'delta' @@ -36,7 +36,7 @@ with dexs AS ( {{ log_decoded_enrich_dex_trades( - base_trades = ref('log_decoded_dex_base_trades') + base_trades = ref('dex_automation_beta_base_trades') , filter = "project != 'curve'" , tokens_erc20_model = source('tokens', 'erc20') ) From 9e6263eaac888fa51612cf95718dc30f5b8eeab8 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 13 Sep 2024 00:39:44 +0800 Subject: [PATCH 59/86] Remove dex_info test --- .../dex/models/_log_decoded_trades/_schema.yml | 8 ++++---- .../uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml index ade0e76cc33..5fbe486995d 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/_schema.yml @@ -26,10 +26,10 @@ models: - &project name: project description: "Name of the dex on which the trade occurred" - tests: - - relationships: - to: ref('dex_info') - field: project +# tests: +# - relationships: +# to: ref('dex_info') +# field: project - &version name: version description: "Version of the DEX protocol/contract" diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql index adbdc9fdcc4..19ab640eea6 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql @@ -1,5 +1,4 @@ {{ config( - schema = 'mass_decoding_ethereum', alias = 'uniswap_v2_factory_evt_PairCreated', partition_by = ['block_date'], From b36b3e2d542e6d7c6da5b0abdfcbafcb1886784b Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 13 Sep 2024 01:29:45 +0800 Subject: [PATCH 60/86] Fix unique_key --- .../uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql | 2 +- .../uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql | 1 - .../uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql | 2 +- .../uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql index a4ada2fbc01..d263190421c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_arbitrum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql index bae110079f1..7b37d023ffa 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql @@ -1,5 +1,4 @@ {{ config( - schema = 'mass_decoding_arbitrum', alias = 'uniswap_v3_factory_evt_PoolCreated', partition_by = ['block_date'], diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql index 73b7774ea3a..cb4d3d66b72 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_arbitrum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql index e817fe8d2f3..2ad2e058760 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_pool_decoding_ethereum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql index 53931819cbc..3fa2c7807cb 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_pool_decoding_ethereum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} From 04cf0c531ebcb9e13e9c359c42881ce210d63434 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 13 Sep 2024 01:31:14 +0800 Subject: [PATCH 61/86] Fix unique_key --- .../uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql | 2 +- .../uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql | 2 +- .../uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql index 471188a21f0..83ca00fa4f3 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_arbitrum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql index 7b37d023ffa..a8a5811504a 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_arbitrum.sql @@ -5,7 +5,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql index 19ab640eea6..16a440b393c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_factory_decoding_ethereum.sql @@ -5,7 +5,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql index 5f77de40f22..8bb9114ed3b 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_factory_decoding_ethereum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], + unique_key = ['tx_hash', 'index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} From 2ba354a3dc63c50ec055d5fae750efd198131bbf Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Sat, 21 Sep 2024 03:01:11 +0800 Subject: [PATCH 62/86] Remove inner join to show all uni-v2 forks --- .../uniswap_v2_forks_base_trades_ethereum.sql | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 6a3d218ac01..376a3ab917f 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -11,8 +11,7 @@ ) }} -WITH all_decoded_trades AS ( - {{ +{{ uniswap_v2_forks_trades( blockchain = 'ethereum' , version = 'null' @@ -20,28 +19,4 @@ WITH all_decoded_trades AS ( , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') ) - }} -) - -SELECT - all_decoded_trades.blockchain - , fork_mapping.project_name as project - , all_decoded_trades.version - , all_decoded_trades.dex_type - , factory_address - , all_decoded_trades.block_month - , all_decoded_trades.block_date - , all_decoded_trades.block_time - , all_decoded_trades.block_number - , all_decoded_trades.token_bought_amount_raw - , all_decoded_trades.token_sold_amount_raw - , all_decoded_trades.token_bought_address - , all_decoded_trades.token_sold_address - , all_decoded_trades.taker - , all_decoded_trades.maker - , all_decoded_trades.project_contract_address - , all_decoded_trades.tx_hash - , all_decoded_trades.evt_index -FROM all_decoded_trades -INNER JOIN {{ ref('uniswap_v2_fork_mapping_ethereum') }} AS fork_mapping -USING (factory_address) \ No newline at end of file +}} From 5c30919a96b23129b4529824563f1884eaf49de1 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Mon, 23 Sep 2024 22:44:05 +0800 Subject: [PATCH 63/86] Exclude cetain factory addresses --- .../uniswap_v2_forks_base_trades_ethereum.sql | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 376a3ab917f..9cb0ff4d5c4 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -11,12 +11,24 @@ ) }} -{{ - uniswap_v2_forks_trades( - blockchain = 'ethereum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') - , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') - ) -}} +WITH all_decoded_trades AS ( + {{ + uniswap_v2_forks_trades( + blockchain = 'ethereum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') + ) + }} +) + +SELECT * +FROM all_decoded_trades +WHERE contract_address NOT IN ( + -- 1inch LOP trades related + 0x9a27cb5ae0b2cee0bb71f9a85c0d60f3920757b4 + , 0x43ec799eadd63848443e2347c49f5f52e8fe0f6f + , 0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f + , 0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac +) \ No newline at end of file From 5a511d993724df2878e911b8c5d0a373f75d7dcf Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Mon, 23 Sep 2024 23:09:15 +0800 Subject: [PATCH 64/86] Update column name --- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 9cb0ff4d5c4..76b51dc688e 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -25,7 +25,7 @@ WITH all_decoded_trades AS ( SELECT * FROM all_decoded_trades -WHERE contract_address NOT IN ( +WHERE factory_address NOT IN ( -- 1inch LOP trades related 0x9a27cb5ae0b2cee0bb71f9a85c0d60f3920757b4 , 0x43ec799eadd63848443e2347c49f5f52e8fe0f6f From 24cacf6c86a7973d13dc5cd26e7b818ec9bb297a Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Mon, 23 Sep 2024 23:58:06 +0800 Subject: [PATCH 65/86] Update exlude logic --- .../uniswap_v2_forks_base_trades_ethereum.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 76b51dc688e..f1e35f00324 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -23,12 +23,12 @@ WITH all_decoded_trades AS ( }} ) -SELECT * -FROM all_decoded_trades +SELECT uniswap_v2_base_trades.* +FROM all_decoded_trades AS uniswap_v2_base_trades +LEFT JOIN {{ ref('oneinch_lop_own_trades') }} AS oneinch_lop_own_trades +USING (tx_hash, evt_index) WHERE factory_address NOT IN ( - -- 1inch LOP trades related - 0x9a27cb5ae0b2cee0bb71f9a85c0d60f3920757b4 - , 0x43ec799eadd63848443e2347c49f5f52e8fe0f6f - , 0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f - , 0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac -) \ No newline at end of file + -- token mismatched pool + 0x558e40f696c61c30f99f03e017840232f8c595e5 + ) + AND oneinch_lop_own_trades.tx_hash IS NULL \ No newline at end of file From 439d5204fa8e50715bde665139e2a6f62812820a Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 00:10:49 +0800 Subject: [PATCH 66/86] Update exlude logic --- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index f1e35f00324..9209a0b291b 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -26,7 +26,8 @@ WITH all_decoded_trades AS ( SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades LEFT JOIN {{ ref('oneinch_lop_own_trades') }} AS oneinch_lop_own_trades -USING (tx_hash, evt_index) + ON uniswap_v2_base_trades.tx_hash = oneinch_lop_own_trades.tx_hash + AND uniswap_v2_base_trades.evt_index = oneinch_lop_own_trades.evt_index WHERE factory_address NOT IN ( -- token mismatched pool 0x558e40f696c61c30f99f03e017840232f8c595e5 From e8b18f4fac93ec01f8a921c62b11ffe469197156 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 00:49:14 +0800 Subject: [PATCH 67/86] Update exlude logic --- .../uniswap_v2_forks_base_trades_ethereum.sql | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 9209a0b291b..3b196571cb8 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -25,11 +25,7 @@ WITH all_decoded_trades AS ( SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades -LEFT JOIN {{ ref('oneinch_lop_own_trades') }} AS oneinch_lop_own_trades - ON uniswap_v2_base_trades.tx_hash = oneinch_lop_own_trades.tx_hash - AND uniswap_v2_base_trades.evt_index = oneinch_lop_own_trades.evt_index -WHERE factory_address NOT IN ( - -- token mismatched pool - 0x558e40f696c61c30f99f03e017840232f8c595e5 - ) - AND oneinch_lop_own_trades.tx_hash IS NULL \ No newline at end of file +LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps + ON uniswap_v2_base_trades.tx_hash = oneinch_swaps.tx_hash + AND oneinch_swaps.blockchain = 'ethereum' +WHERE oneinch_swaps.tx_hash IS NULL \ No newline at end of file From 91855c8f0102af69fd75d7c70128a2a934cc2d67 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 16:17:34 +0800 Subject: [PATCH 68/86] Update base_trades --- .../uniswap_v2_forks_base_trades_arbitrum.sql | 28 ++++--------------- .../uniswap_v3_forks_base_trades_arbitrum.sql | 28 ++++--------------- .../uniswap_v3_forks_base_trades_ethereum.sql | 28 ++++--------------- 3 files changed, 18 insertions(+), 66 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 1f00f2333e0..cab59ec329c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -23,25 +23,9 @@ WITH all_decoded_trades AS ( }} ) -SELECT - all_decoded_trades.blockchain - , fork_mapping.project_name as project - , all_decoded_trades.version - , all_decoded_trades.dex_type - , factory_address - , all_decoded_trades.block_month - , all_decoded_trades.block_date - , all_decoded_trades.block_time - , all_decoded_trades.block_number - , all_decoded_trades.token_bought_amount_raw - , all_decoded_trades.token_sold_amount_raw - , all_decoded_trades.token_bought_address - , all_decoded_trades.token_sold_address - , all_decoded_trades.taker - , all_decoded_trades.maker - , all_decoded_trades.project_contract_address - , all_decoded_trades.tx_hash - , all_decoded_trades.evt_index -FROM all_decoded_trades -INNER JOIN {{ ref('uniswap_v2_fork_mapping_arbitrum') }} AS fork_mapping -USING (factory_address) \ No newline at end of file +SELECT uniswap_v2_base_trades.* +FROM all_decoded_trades AS uniswap_v2_base_trades +LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps + ON uniswap_v2_base_trades.tx_hash = oneinch_swaps.tx_hash + AND oneinch_swaps.blockchain = 'arbitrum' +WHERE oneinch_swaps.tx_hash IS NULL \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index af939639569..83bb161eaf6 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -23,25 +23,9 @@ WITH all_decoded_trades AS ( }} ) -SELECT - all_decoded_trades.blockchain - , fork_mapping.project_name as project - , all_decoded_trades.version - , all_decoded_trades.dex_type - , factory_address - , all_decoded_trades.block_month - , all_decoded_trades.block_date - , all_decoded_trades.block_time - , all_decoded_trades.block_number - , all_decoded_trades.token_bought_amount_raw - , all_decoded_trades.token_sold_amount_raw - , all_decoded_trades.token_bought_address - , all_decoded_trades.token_sold_address - , all_decoded_trades.taker - , all_decoded_trades.maker - , all_decoded_trades.project_contract_address - , all_decoded_trades.tx_hash - , all_decoded_trades.evt_index -FROM all_decoded_trades -INNER JOIN {{ ref('uniswap_v3_fork_mapping_arbitrum') }} AS fork_mapping -USING (factory_address) \ No newline at end of file +SELECT uniswap_v3_base_trades.* +FROM all_decoded_trades AS uniswap_v3_base_trades +LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps + ON uniswap_v3_base_trades.tx_hash = oneinch_swaps.tx_hash + AND oneinch_swaps.blockchain = 'arbitrum' +WHERE oneinch_swaps.tx_hash IS NULL diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index d33206b13f5..e693e8a7c28 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -23,25 +23,9 @@ WITH all_decoded_trades AS ( }} ) -SELECT - all_decoded_trades.blockchain - , fork_mapping.project_name as project - , all_decoded_trades.version - , all_decoded_trades.dex_type - , factory_address - , all_decoded_trades.block_month - , all_decoded_trades.block_date - , all_decoded_trades.block_time - , all_decoded_trades.block_number - , all_decoded_trades.token_bought_amount_raw - , all_decoded_trades.token_sold_amount_raw - , all_decoded_trades.token_bought_address - , all_decoded_trades.token_sold_address - , all_decoded_trades.taker - , all_decoded_trades.maker - , all_decoded_trades.project_contract_address - , all_decoded_trades.tx_hash - , all_decoded_trades.evt_index -FROM all_decoded_trades -INNER JOIN {{ ref('uniswap_v3_fork_mapping_ethereum') }} AS fork_mapping -USING (factory_address) \ No newline at end of file +SELECT uniswap_v3_base_trades.* +FROM all_decoded_trades AS uniswap_v3_base_trades +LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps + ON uniswap_v3_base_trades.tx_hash = oneinch_swaps.tx_hash + AND oneinch_swaps.blockchain = 'ethereum' +WHERE oneinch_swaps.tx_hash IS NULL From b2906484e0e74a6bf000e1fe8f01aa7d40aa5d1b Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 19:42:55 +0800 Subject: [PATCH 69/86] Fix incremental parts --- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 2 +- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index e4fcf12709e..d4473991034 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -41,7 +41,7 @@ WITH dexs AS AND f.contract_address = ct."from" {% if is_incremental() %} WHERE - {{ incremental_predicate('t.evt_block_time') }} + {{ incremental_predicate('t.block_time') }} {% endif %} ) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index cab59ec329c..8595b794064 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + unique_key = ['tx_hash', 'evt_index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 83bb161eaf6..83db5f36f32 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + unique_key = ['tx_hash', 'evt_index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 3b196571cb8..a00935161bc 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + unique_key = ['tx_hash', 'evt_index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index e693e8a7c28..addf039c7c0 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -6,7 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_bought_address', 'token_sold_address'], + unique_key = ['tx_hash', 'evt_index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} From cd1b9d1b7578256ee6d9070a2eb5b45fe9cca2f2 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 20:38:46 +0800 Subject: [PATCH 70/86] Update _schema.yml --- .../arbitrum/decoded-in-flight/_schema.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml index c7c44fc3006..ad5ddeb4157 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/_schema.yml @@ -46,7 +46,6 @@ models: combination_of_columns: - tx_hash - evt_index - - project_contract_address - name: uniswap_v3_forks_base_trades_arbitrum meta: @@ -62,7 +61,6 @@ models: combination_of_columns: - tx_hash - evt_index - - project_contract_address - name: uniswap_v3_fork_mapping_arbitrum description: > @@ -84,5 +82,4 @@ models: combination_of_columns: - tx_hash - evt_index - - project_contract_address - \ No newline at end of file + From 760ec5992a333ed17a1cfb48d53866e96d772fb8 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 20:39:25 +0800 Subject: [PATCH 71/86] Update _schema.yml --- .../ethereum/decoded-in-flight/_schema.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml index a626619a751..e92c70ce379 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/_schema.yml @@ -46,7 +46,6 @@ models: combination_of_columns: - tx_hash - evt_index - - project_contract_address - name: uniswap_v3_forks_base_trades_ethereum meta: @@ -62,7 +61,6 @@ models: combination_of_columns: - tx_hash - evt_index - - project_contract_address - name: uniswap_v3_fork_mapping_ethereum description: > @@ -84,5 +82,4 @@ models: combination_of_columns: - tx_hash - evt_index - - project_contract_address - \ No newline at end of file + From 7c519ebaa3b52f144e8c9842b389f3e27cad53af Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 24 Sep 2024 23:15:37 +0800 Subject: [PATCH 72/86] Try to fix incremental error --- .../uniswap_v2/uniswap_v2_trades.sql | 25 ++++++++++++++----- .../uniswap_v3/uniswap_v3_trades.sql | 24 +++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 1f4aee86a5c..163d4fda6a1 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -9,7 +9,24 @@ ) %} -WITH dexs AS +WITH evt_swap AS ( + SELECT block_number + , block_time + , to + , contract_address + , tx_hash + , index + , amount0In + , amount0Out + , amount1In + , amount1Out + FROM {{ Pair_evt_Swap }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('block_time') }} + {% endif %} +) + +, dexs AS ( SELECT t.block_number @@ -25,7 +42,7 @@ WITH dexs AS , t.index AS evt_index , f.contract_address as factory_address FROM - {{ Pair_evt_Swap }} t + {{ evt_swap }} t INNER JOIN {{ Factory_evt_PairCreated }} f ON f.{{ pair_column_name }} = t.contract_address @@ -33,10 +50,6 @@ WITH dexs AS INNER JOIN {{ source(blockchain, 'creation_traces') }} ct ON f.{{ pair_column_name }} = ct.address AND f.contract_address = ct."from" - {% if is_incremental() %} - WHERE - {{ incremental_predicate('t.block_time') }} - {% endif %} ) SELECT diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index d4473991034..253aea2086e 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -11,7 +11,23 @@ , maker_column_name = null ) %} -WITH dexs AS + +WITH evt_swap AS ( + SELECT block_number + , block_time + , {{ taker_column_name }} + , {{ maker_column_name }} + , amount0 + , amount1 + , contract_address + , tx_hash + , index + FROM {{ Pair_evt_Swap }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('block_time') }} + {% endif %} +) +, dexs AS ( SELECT t.block_number @@ -31,7 +47,7 @@ WITH dexs AS , t.index as evt_index , f.contract_address as factory_address FROM - {{ Pair_evt_Swap }} t + {{ evt_swap }} t INNER JOIN {{ Factory_evt_PoolCreated }} f ON f.{{ pair_column_name }} = t.contract_address @@ -39,10 +55,6 @@ WITH dexs AS INNER JOIN {{ source(blockchain, 'creation_traces') }} ct ON f.{{ pair_column_name }} = ct.address AND f.contract_address = ct."from" - {% if is_incremental() %} - WHERE - {{ incremental_predicate('t.block_time') }} - {% endif %} ) SELECT From f59386a40e7a541723f6e54f9ae57152335f55ba Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Wed, 25 Sep 2024 16:40:16 +0800 Subject: [PATCH 73/86] Fix CTE name --- .../in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql | 2 +- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 163d4fda6a1..2464289ab64 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -42,7 +42,7 @@ WITH evt_swap AS ( , t.index AS evt_index , f.contract_address as factory_address FROM - {{ evt_swap }} t + evt_swap t INNER JOIN {{ Factory_evt_PairCreated }} f ON f.{{ pair_column_name }} = t.contract_address diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 253aea2086e..cb43e855cc2 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -47,7 +47,7 @@ WITH evt_swap AS ( , t.index as evt_index , f.contract_address as factory_address FROM - {{ evt_swap }} t + evt_swap t INNER JOIN {{ Factory_evt_PoolCreated }} f ON f.{{ pair_column_name }} = t.contract_address From 86a1fbda817b5bd5770a63654868cac0010938d6 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Wed, 25 Sep 2024 18:25:21 +0800 Subject: [PATCH 74/86] Implement boxer's proposal --- .../uniswap_v3/uniswap_v3_trades.sql | 3 ++ .../uniswap_v2_forks_base_trades_arbitrum.sql | 16 +++++++--- .../uniswap_v3_forks_base_trades_arbitrum.sql | 16 +++++++--- .../uniswap_v2_forks_base_trades_ethereum.sql | 30 ++++++++++++------- .../uniswap_v3_forks_base_trades_ethereum.sql | 17 ++++++++--- 5 files changed, 59 insertions(+), 23 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index cb43e855cc2..5e9d867c0e8 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -16,7 +16,9 @@ WITH evt_swap AS ( SELECT block_number , block_time , {{ taker_column_name }} + {% if maker_column_name %} , {{ maker_column_name }} + {% endif %} , amount0 , amount1 , contract_address @@ -27,6 +29,7 @@ WITH evt_swap AS ( WHERE {{ incremental_predicate('block_time') }} {% endif %} ) + , dexs AS ( SELECT diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 8595b794064..e36158bc5ea 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -25,7 +25,15 @@ WITH all_decoded_trades AS ( SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades -LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps - ON uniswap_v2_base_trades.tx_hash = oneinch_swaps.tx_hash - AND oneinch_swaps.blockchain = 'arbitrum' -WHERE oneinch_swaps.tx_hash IS NULL \ No newline at end of file +INNER JOIN ( + SELECT + count(*) as transfer_count, + contract_address, + tx_hash + FROM arbitrum.transfers + GROUP BY contract_address, tx_hash + HAVING count(*) > 1 +) AS transfers +ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) + AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address + OR transfers.contract_address = uniswap_v2_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 83db5f36f32..a941d8cd5b8 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -25,7 +25,15 @@ WITH all_decoded_trades AS ( SELECT uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades -LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps - ON uniswap_v3_base_trades.tx_hash = oneinch_swaps.tx_hash - AND oneinch_swaps.blockchain = 'arbitrum' -WHERE oneinch_swaps.tx_hash IS NULL +INNER JOIN ( + SELECT + count(*) as transfer_count, + contract_address, + tx_hash + FROM arbitrum.transfers + GROUP BY contract_address, tx_hash + HAVING count(*) > 1 +) AS transfers +ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) + AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address + OR transfers.contract_address = uniswap_v3_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index a00935161bc..e181450f6e3 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -13,19 +13,27 @@ WITH all_decoded_trades AS ( {{ - uniswap_v2_forks_trades( - blockchain = 'ethereum' - , version = 'null' - , project = 'null' - , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') - , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') - ) + uniswap_v2_forks_trades( + blockchain = 'ethereum' + , version = 'null' + , project = 'null' + , Pair_evt_Swap = ref('uniswap_v2_pool_decoding_ethereum') + , Factory_evt_PairCreated = ref('uniswap_v2_factory_decoding_ethereum') + ) }} ) SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades -LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps - ON uniswap_v2_base_trades.tx_hash = oneinch_swaps.tx_hash - AND oneinch_swaps.blockchain = 'ethereum' -WHERE oneinch_swaps.tx_hash IS NULL \ No newline at end of file +INNER JOIN ( + SELECT + count(*) as transfer_count, + contract_address, + tx_hash + FROM ethereum.transfers + GROUP BY contract_address, tx_hash + HAVING count(*) > 1 +) AS transfers +ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) + AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address + OR transfers.contract_address = uniswap_v2_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index addf039c7c0..54b6fcd4e4b 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -25,7 +25,16 @@ WITH all_decoded_trades AS ( SELECT uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades -LEFT JOIN {{ ref('oneinch_swaps') }} AS oneinch_swaps - ON uniswap_v3_base_trades.tx_hash = oneinch_swaps.tx_hash - AND oneinch_swaps.blockchain = 'ethereum' -WHERE oneinch_swaps.tx_hash IS NULL +INNER JOIN ( + SELECT + count(*) as transfer_count, + contract_address, + tx_hash + FROM ethereum.transfers + GROUP BY contract_address, tx_hash + HAVING count(*) > 1 +) AS transfers +ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) + AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address + OR transfers.contract_address = uniswap_v3_base_trades.token_sold_address) + From 6ee7fcc2f697f22ad0a80640fb105d14349fb6cf Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 26 Sep 2024 00:35:53 +0800 Subject: [PATCH 75/86] Update filter condition and transfers source table --- .../uniswap_v2_forks_base_trades_arbitrum.sql | 16 ++++++++-------- .../uniswap_v3_forks_base_trades_arbitrum.sql | 16 ++++++++-------- .../uniswap_v2_forks_base_trades_ethereum.sql | 5 +++-- .../uniswap_v3_forks_base_trades_ethereum.sql | 5 +++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index e36158bc5ea..8f2a3a49744 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -28,12 +28,12 @@ FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT count(*) as transfer_count, - contract_address, - tx_hash - FROM arbitrum.transfers - GROUP BY contract_address, tx_hash - HAVING count(*) > 1 + token_address, + evt_tx_hash + FROM transfers_arbitrum.erc20 + GROUP BY token_address, evt_tx_hash + HAVING count(*) >= 1 ) AS transfers -ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) - AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address - OR transfers.contract_address = uniswap_v2_base_trades.token_sold_address) +ON (transfers.evt_tx_hash = uniswap_v2_base_trades.tx_hash) + AND (transfers.token_address = uniswap_v2_base_trades.token_bought_address + OR transfers.token_address = uniswap_v2_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index a941d8cd5b8..4f2dc7874f5 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -28,12 +28,12 @@ FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT count(*) as transfer_count, - contract_address, - tx_hash - FROM arbitrum.transfers - GROUP BY contract_address, tx_hash - HAVING count(*) > 1 + token_address, + evt_tx_hash + FROM transfers_arbitrum.erc20 + GROUP BY token_address, evt_tx_hash + HAVING count(*) >= 1 ) AS transfers -ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) - AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address - OR transfers.contract_address = uniswap_v3_base_trades.token_sold_address) +ON (transfers.evt_tx_hash = uniswap_v3_base_trades.tx_hash) + AND (transfers.token_address = uniswap_v3_base_trades.token_bought_address + OR transfers.token_address = uniswap_v3_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index e181450f6e3..0537a7a0da0 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -30,9 +30,10 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM ethereum.transfers + FROM tokens.transfers + WHERE blockchain = 'ethereum' GROUP BY contract_address, tx_hash - HAVING count(*) > 1 + HAVING count(*) >= 1 ) AS transfers ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 54b6fcd4e4b..ff873ea0abb 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -30,9 +30,10 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM ethereum.transfers + FROM tokens.transfers + WHERE blockchain = 'ethereum' GROUP BY contract_address, tx_hash - HAVING count(*) > 1 + HAVING count(*) >= 1 ) AS transfers ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address From 974b002ed0a1c91f6d749ab6d9e445382ec430ac Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 26 Sep 2024 00:39:29 +0800 Subject: [PATCH 76/86] Fix ref --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 8f2a3a49744..296ada006c8 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, token_address, evt_tx_hash - FROM transfers_arbitrum.erc20 + FROM {{ ref('transfers_arbitrum_erc20') }} GROUP BY token_address, evt_tx_hash HAVING count(*) >= 1 ) AS transfers diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 4f2dc7874f5..cd1b3e624ab 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, token_address, evt_tx_hash - FROM transfers_arbitrum.erc20 + FROM {{ ref('transfers_arbitrum_erc20') }} GROUP BY token_address, evt_tx_hash HAVING count(*) >= 1 ) AS transfers diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 0537a7a0da0..72155a08427 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM tokens.transfers + FROM {{ ref('tokens_transfers')}} WHERE blockchain = 'ethereum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index ff873ea0abb..cbbcaec13b3 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM tokens.transfers + FROM {{ ref('tokens_transfers')}} WHERE blockchain = 'ethereum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 From 82a880aa8ee91f0050df2ba7590e22a03431c93e Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 26 Sep 2024 16:52:02 +0800 Subject: [PATCH 77/86] Update source --- .../uniswap_v2_forks_base_trades_arbitrum.sql | 15 ++++++++------- .../uniswap_v3_forks_base_trades_arbitrum.sql | 16 +++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 296ada006c8..462bab911fc 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -28,12 +28,13 @@ FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT count(*) as transfer_count, - token_address, - evt_tx_hash - FROM {{ ref('transfers_arbitrum_erc20') }} - GROUP BY token_address, evt_tx_hash + contract_address, + tx_hash + FROM {{ ref('tokens_transfers')}} + WHERE blockchain = 'ethereum' + GROUP BY contract_address, tx_hash HAVING count(*) >= 1 ) AS transfers -ON (transfers.evt_tx_hash = uniswap_v2_base_trades.tx_hash) - AND (transfers.token_address = uniswap_v2_base_trades.token_bought_address - OR transfers.token_address = uniswap_v2_base_trades.token_sold_address) +ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) + AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address + OR transfers.contract_address = uniswap_v2_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index cd1b3e624ab..1e418c4adec 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -28,12 +28,14 @@ FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT count(*) as transfer_count, - token_address, - evt_tx_hash - FROM {{ ref('transfers_arbitrum_erc20') }} - GROUP BY token_address, evt_tx_hash + contract_address, + tx_hash + FROM {{ ref('tokens_transfers')}} + WHERE blockchain = 'ethereum' + GROUP BY contract_address, tx_hash HAVING count(*) >= 1 ) AS transfers -ON (transfers.evt_tx_hash = uniswap_v3_base_trades.tx_hash) - AND (transfers.token_address = uniswap_v3_base_trades.token_bought_address - OR transfers.token_address = uniswap_v3_base_trades.token_sold_address) +ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) + AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address + OR transfers.contract_address = uniswap_v3_base_trades.token_sold_address) + From 0afe9c4ee249abe10d08fecdfb18cd0f87b5113a Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 26 Sep 2024 16:52:39 +0800 Subject: [PATCH 78/86] Fix blockchain --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 462bab911fc..d8be7840b76 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -31,7 +31,7 @@ INNER JOIN ( contract_address, tx_hash FROM {{ ref('tokens_transfers')}} - WHERE blockchain = 'ethereum' + WHERE blockchain = 'arbitrum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 ) AS transfers diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 1e418c4adec..fb69711a228 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -31,7 +31,7 @@ INNER JOIN ( contract_address, tx_hash FROM {{ ref('tokens_transfers')}} - WHERE blockchain = 'ethereum' + WHERE blockchain = 'arbitrum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 ) AS transfers From d405e185dfbac2396753c04842dda4197532df23 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Thu, 26 Sep 2024 20:30:50 +0800 Subject: [PATCH 79/86] Fix source --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 2 +- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 2 +- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index d8be7840b76..f8ca51669c0 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM {{ ref('tokens_transfers')}} + FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'arbitrum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index fb69711a228..920234a75f3 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM {{ ref('tokens_transfers')}} + FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'arbitrum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 72155a08427..686595adf77 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM {{ ref('tokens_transfers')}} + FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'ethereum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index cbbcaec13b3..1d88b606b66 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -30,7 +30,7 @@ INNER JOIN ( count(*) as transfer_count, contract_address, tx_hash - FROM {{ ref('tokens_transfers')}} + FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'ethereum' GROUP BY contract_address, tx_hash HAVING count(*) >= 1 From 4d218d80218614a9030b489dbbe6ba22c2228875 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Sun, 29 Sep 2024 20:43:19 +0800 Subject: [PATCH 80/86] Update filter logics --- .../uniswap_v2_forks_base_trades_arbitrum.sql | 14 ++++++-------- .../uniswap_v3_forks_base_trades_arbitrum.sql | 15 ++++++--------- .../uniswap_v2_forks_base_trades_ethereum.sql | 14 ++++++-------- .../uniswap_v3_forks_base_trades_ethereum.sql | 14 ++++++-------- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index f8ca51669c0..b5ab841a1a7 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -27,14 +27,12 @@ SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT - count(*) as transfer_count, - contract_address, - tx_hash + tx_hash, + array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'arbitrum' - GROUP BY contract_address, tx_hash - HAVING count(*) >= 1 + GROUP BY tx_hash ) AS transfers -ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) - AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address - OR transfers.contract_address = uniswap_v2_base_trades.token_sold_address) +ON transfers.tx_hash = uniswap_v2_base_trades.tx_hash + AND contains(transfers.contract_addresses, uniswap_v2_base_trades.token_bought_address) + AND contains(transfers.contract_addresses, uniswap_v2_base_trades.token_sold_address) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 920234a75f3..bdd8d9963d2 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -27,15 +27,12 @@ SELECT uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT - count(*) as transfer_count, - contract_address, - tx_hash + tx_hash, + array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'arbitrum' - GROUP BY contract_address, tx_hash - HAVING count(*) >= 1 + GROUP BY tx_hash ) AS transfers -ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) - AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address - OR transfers.contract_address = uniswap_v3_base_trades.token_sold_address) - +ON transfers.tx_hash = uniswap_v3_base_trades.tx_hash + AND contains(transfers.contract_addresses, uniswap_v3_base_trades.token_bought_address) + AND contains(transfers.contract_addresses, uniswap_v3_base_trades.token_sold_address) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 686595adf77..f27350fcb11 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -27,14 +27,12 @@ SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT - count(*) as transfer_count, - contract_address, - tx_hash + tx_hash, + array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'ethereum' - GROUP BY contract_address, tx_hash - HAVING count(*) >= 1 + GROUP BY tx_hash ) AS transfers -ON (transfers.tx_hash = uniswap_v2_base_trades.tx_hash) - AND (transfers.contract_address = uniswap_v2_base_trades.token_bought_address - OR transfers.contract_address = uniswap_v2_base_trades.token_sold_address) +ON transfers.tx_hash = uniswap_v2_base_trades.tx_hash + AND contains(transfers.contract_addresses, uniswap_v2_base_trades.token_bought_address) + AND contains(transfers.contract_addresses, uniswap_v2_base_trades.token_sold_address) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 1d88b606b66..a8a834e9a0c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -27,15 +27,13 @@ SELECT uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT - count(*) as transfer_count, - contract_address, - tx_hash + tx_hash, + array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'ethereum' - GROUP BY contract_address, tx_hash - HAVING count(*) >= 1 + GROUP BY tx_hash ) AS transfers -ON (transfers.tx_hash = uniswap_v3_base_trades.tx_hash) - AND (transfers.contract_address = uniswap_v3_base_trades.token_bought_address - OR transfers.contract_address = uniswap_v3_base_trades.token_sold_address) +ON transfers.tx_hash = uniswap_v3_base_trades.tx_hash + AND contains(transfers.contract_addresses, uniswap_v3_base_trades.token_bought_address) + AND contains(transfers.contract_addresses, uniswap_v3_base_trades.token_sold_address) From f70131eb191f6d71e77215ab4e108f5e5623f925 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Sun, 29 Sep 2024 21:51:47 +0800 Subject: [PATCH 81/86] Remove incremental predicates --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 3 +-- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 3 +-- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 3 +-- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index b5ab841a1a7..6e889e6acb7 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -6,8 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + unique_key = ['tx_hash', 'evt_index'] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index bdd8d9963d2..ebcc79c9fb4 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -6,8 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + unique_key = ['tx_hash', 'evt_index'] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index f27350fcb11..7564514ad07 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -6,8 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + unique_key = ['tx_hash', 'evt_index'] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index a8a834e9a0c..424c7c6eff1 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -6,8 +6,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'], - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + unique_key = ['tx_hash', 'evt_index'] ) }} From f2deff7ae2de748774ed45a06c8d5f71042136fc Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Mon, 30 Sep 2024 17:02:52 +0800 Subject: [PATCH 82/86] Revert "Remove incremental predicates" This reverts commit f70131eb191f6d71e77215ab4e108f5e5623f925. --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 3 ++- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 3 ++- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 3 ++- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 6e889e6acb7..b5ab841a1a7 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -6,7 +6,8 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'] + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index ebcc79c9fb4..bdd8d9963d2 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -6,7 +6,8 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'] + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 7564514ad07..f27350fcb11 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -6,7 +6,8 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'] + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 424c7c6eff1..a8a834e9a0c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -6,7 +6,8 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index'] + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} From 9596e20bf9f85f6013886d65c7a2704cde708b34 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 1 Oct 2024 19:28:17 +0800 Subject: [PATCH 83/86] Add distinct incremental selection --- .../in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql | 6 +++++- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 2464289ab64..54e43a76918 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -10,7 +10,11 @@ %} WITH evt_swap AS ( - SELECT block_number + SELECT + {% if is_incremental() %} + DISTINCT + {% endif %} + block_number , block_time , to , contract_address diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index 5e9d867c0e8..c259889c964 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -13,7 +13,11 @@ %} WITH evt_swap AS ( - SELECT block_number + SELECT + {% if is_incremental() %} + DISTINCT + {% endif %} + block_number , block_time , {{ taker_column_name }} {% if maker_column_name %} From 175c2c6ba657b2ff0361e5540475d42ec430f1bd Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 1 Oct 2024 20:42:03 +0800 Subject: [PATCH 84/86] Fix incremental --- .../in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql | 3 --- .../in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql | 3 --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 8 +++++++- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 8 +++++++- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 8 +++++++- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 8 +++++++- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql index 54e43a76918..10b9bd2e72f 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v2/uniswap_v2_trades.sql @@ -11,9 +11,6 @@ WITH evt_swap AS ( SELECT - {% if is_incremental() %} - DISTINCT - {% endif %} block_number , block_time , to diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql index c259889c964..b8ccd1963e3 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/uniswap_v3/uniswap_v3_trades.sql @@ -14,9 +14,6 @@ WITH evt_swap AS ( SELECT - {% if is_incremental() %} - DISTINCT - {% endif %} block_number , block_time , {{ taker_column_name }} diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index b5ab841a1a7..55896d66130 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -23,7 +23,10 @@ WITH all_decoded_trades AS ( }} ) -SELECT uniswap_v2_base_trades.* +SELECT {% if is_incremental() %} + DISTINCT + {% endif %} + uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT @@ -31,6 +34,9 @@ INNER JOIN ( array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'arbitrum' + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} GROUP BY tx_hash ) AS transfers ON transfers.tx_hash = uniswap_v2_base_trades.tx_hash diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index bdd8d9963d2..0d1eacb68ae 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -23,7 +23,10 @@ WITH all_decoded_trades AS ( }} ) -SELECT uniswap_v3_base_trades.* +SELECT {% if is_incremental() %} + DISTINCT + {% endif %} + uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT @@ -31,6 +34,9 @@ INNER JOIN ( array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'arbitrum' + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} GROUP BY tx_hash ) AS transfers ON transfers.tx_hash = uniswap_v3_base_trades.tx_hash diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index f27350fcb11..1e6c445977c 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -23,7 +23,10 @@ WITH all_decoded_trades AS ( }} ) -SELECT uniswap_v2_base_trades.* +SELECT {% if is_incremental() %} + DISTINCT + {% endif %} + uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT @@ -31,6 +34,9 @@ INNER JOIN ( array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'ethereum' + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} GROUP BY tx_hash ) AS transfers ON transfers.tx_hash = uniswap_v2_base_trades.tx_hash diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index a8a834e9a0c..9339352f222 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -23,7 +23,10 @@ WITH all_decoded_trades AS ( }} ) -SELECT uniswap_v3_base_trades.* +SELECT {% if is_incremental() %} + DISTINCT + {% endif %} + uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT @@ -31,6 +34,9 @@ INNER JOIN ( array_agg(DISTINCT contract_address) as contract_addresses FROM {{ source('tokens', 'transfers') }} WHERE blockchain = 'ethereum' + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} GROUP BY tx_hash ) AS transfers ON transfers.tx_hash = uniswap_v3_base_trades.tx_hash From dff0105537b6116ecf7ec849547a11b7a3add2b3 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 1 Oct 2024 22:28:54 +0800 Subject: [PATCH 85/86] Fix incremental in decode_evm_event function --- .../models/_project/in-flight-decoding/decoding_base.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql index 2a0f82486b2..59650b7e2fb 100644 --- a/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql +++ b/dbt_subprojects/dex/macros/models/_project/in-flight-decoding/decoding_base.sql @@ -15,7 +15,11 @@ FROM TABLE ( SELECT l.* FROM {{logs}} l WHERE topic0 = {{topic0}} - and block_date > (Select min(block_date) from {{logs}} where topic0 = {{topic0}}) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_date >= (SELECT MIN(block_date) FROM {{logs}} WHERE topic0 = {{topic0}}) + {% endif %} ) ) ) From 5ec5988c47134c966e812abb0ef355ee6b23e57f Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Tue, 1 Oct 2024 23:58:01 +0800 Subject: [PATCH 86/86] Remove distinct selection --- .../uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql | 5 +---- .../uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql | 5 +---- .../uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql | 5 +---- .../uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql index 55896d66130..2a755d8ada6 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_arbitrum.sql @@ -23,10 +23,7 @@ WITH all_decoded_trades AS ( }} ) -SELECT {% if is_incremental() %} - DISTINCT - {% endif %} - uniswap_v2_base_trades.* +SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql index 0d1eacb68ae..87cad297c13 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/arbitrum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_arbitrum.sql @@ -23,10 +23,7 @@ WITH all_decoded_trades AS ( }} ) -SELECT {% if is_incremental() %} - DISTINCT - {% endif %} - uniswap_v3_base_trades.* +SELECT uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql index 1e6c445977c..0cab29a333a 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v2/uniswap_v2_forks_base_trades_ethereum.sql @@ -23,10 +23,7 @@ WITH all_decoded_trades AS ( }} ) -SELECT {% if is_incremental() %} - DISTINCT - {% endif %} - uniswap_v2_base_trades.* +SELECT uniswap_v2_base_trades.* FROM all_decoded_trades AS uniswap_v2_base_trades INNER JOIN ( SELECT diff --git a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql index 9339352f222..f64648b4c2a 100644 --- a/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql +++ b/dbt_subprojects/dex/models/_log_decoded_trades/ethereum/decoded-in-flight/uniswap-v3/uniswap_v3_forks_base_trades_ethereum.sql @@ -23,10 +23,7 @@ WITH all_decoded_trades AS ( }} ) -SELECT {% if is_incremental() %} - DISTINCT - {% endif %} - uniswap_v3_base_trades.* +SELECT uniswap_v3_base_trades.* FROM all_decoded_trades AS uniswap_v3_base_trades INNER JOIN ( SELECT