From 43beb17a4af6684039bcc62db26f8258d1532c49 Mon Sep 17 00:00:00 2001 From: darvin Date: Fri, 22 Nov 2024 18:16:12 +0700 Subject: [PATCH 01/68] batman --- .../ethereum/swell_rsweth_ethereum_schema.yml | 68 ++++++++++++++ .../swell_rsweth_ethereum_withdrawals.sql | 90 +++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml new file mode 100644 index 00000000000..00b5e083a70 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml @@ -0,0 +1,68 @@ +version: 2 + +models: + - name: swell_rsweth_ethereum_withdrawals + meta: + blockchain: ethereum + project: swell + contributors: maybeYonas + + config: + tags: ['swell', 'restaking', 'lrt', 'withdrawals'] + description: "rswETH withdrawals" + + columns: + - &request_block_time + name: request_block_time + description: "timestamp at withdrawal request" + - &request_tx_hash + name: request_tx_hash + description: "hash of tx at withdrawal request" + - &request_block_number + name: request_block_number + description: "block at withdrawal request" + - &request_index + name: request_index + description: "event index at at withdrawal request" + - &token_id + name: token_id + description: "unique id of withdrawal" + - &owner + name: owner + description: "owner of withdrawn eth" + - &rswETH_amount + name: rswETH_amount + description: "amount of rsweth burned" + - &rswETH_request_rate + name: rswETH_request_rate + description: "rsweth to eth rate at withdrawal request" + - &processed_block_time + name: processed_block_time + description: "timestamp at withdrawal ready for completion" + - &processed_tx_hash + name: processed_tx_hash + description: "hash of tx at withdrawal ready for completion" + - &processed_block_number + name: processed_block_number + description: "block at withdrawal ready for completion" + - &processed_index + name: processed_index + description: "event index at at withdrawal ready for completion" + - &rswETH_processed_rate + name: rswETH_processed_rate + description: "rsweth to eth rate at withdrawal completion" + - &claim_block_time + name: claim_block_time + description: "timestamp at withdrawal claimed" + - &claim_tx_hash + name: claim_tx_hash + description: "hash of tx at withdrawal claimed" + - &claim_block_number + name: claim_block_number + description: "block at withdrawal claimed" + - &claim_index + name: claim_index + description: "event index at at withdrawal claimed" + - Ð_amount + name: ETH_amount + description: "eth amount claimed by user" \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql new file mode 100644 index 00000000000..eabcf29230b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -0,0 +1,90 @@ +{{ config( + schema = 'swell_rsweth_ethereum', + alias = 'withdrawals', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['token_id'] + post_hook='{{ expose_spells(\'["ethereum"]\', + "project", + "swell", + \'["maybeYonas"]\') }}' + ) +}} + +{% set incremental = """ + {% if is_incremental() %} + where evt_block_time >= ( + select min(request_block_time) + from {{this}} + where claim_block_time is null + ) + {% endif %} +"""%} + +with +rsweth_decoded_withdrawal_requests as ( + select + evt_block_time, evt_tx_hash, evt_block_number, evt_index, + lastTokenIdProcessed, + owner, + tokenId, + amount, + timestamp, + rateWhenCreated + from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawRequestCreated')}} + -- from swell_v3_ethereum.RswEXIT_evt_WithdrawRequestCreated + {{incremental}} +), +rsweth_decoded_withdrawal_claimed as ( + select + evt_block_time, evt_tx_hash, evt_block_number, evt_index, + owner, + tokenId, + exitClaimedETH + from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalClaimed')}} + -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalClaimed + {{incremental}} + +), +rsweth_decoded_withdrawal_processed as ( + select + evt_block_time, evt_tx_hash, evt_block_number, evt_index, + fromTokenId, + toTokenId, + processedRate, + processedExitingETH, + processedExitedETH + from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalsProcessed')}} + -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalsProcessed + {{incremental}} +) + +select + r.evt_block_time as request_block_time, + r.evt_tx_hash as request_tx_hash, + r.evt_block_number as request_block_number, + r.evt_index as request_index, + r.tokenId as token_id, + r.owner as owner, + r.amount as rswETH_amount, + r.rateWhenCreated as rswETH_request_rate, + + p.evt_block_time as processed_block_time, + p.evt_tx_hash as processed_tx_hash, + p.evt_block_number as processed_block_number, + p.evt_index as processed_index, + p.processedRate as rswETH_processed_rate, + + c.evt_block_time as claim_block_time, + c.evt_tx_hash as claim_tx_hash, + c.evt_block_number as claim_block_number, + c.evt_index as claim_index, + c.exitClaimedETH as ETH_amount +from rsweth_decoded_withdrawal_requests r + left join rsweth_decoded_withdrawal_processed p + on r.tokenId >= p.fromTokenId + and r.tokenId <= p.toTokenId + left join rsweth_decoded_withdrawal_claimed c + on r.tokenId = c.tokenId +order by 1 desc \ No newline at end of file From 05d7934bfcefac247eb0d025af4164efefa848dd Mon Sep 17 00:00:00 2001 From: darvin Date: Fri, 22 Nov 2024 18:36:14 +0700 Subject: [PATCH 02/68] sources for withdrawal --- .../swell_rsweth_ethereum_sources.yml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml diff --git a/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml b/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml new file mode 100644 index 00000000000..4323e31c0fb --- /dev/null +++ b/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml @@ -0,0 +1,70 @@ +version: 2 + +sources: + - name: swell_v3_ethereum + description: "swell decoded tables of ethereum contract" + tables: + - name: RswEXIT_evt_WithdrawRequestCreated + description: decoded table on `WithdrawRequestCreated` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064` + columns: + - &rswexit_contract_address + name: contract_address + description: 'RswExit contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'transaction hash of event' + - &evt_index + name: evt_index + description: 'index of event within block' + - &evt_block_time + name: evt_block_time + description: 'timestamp of blocktime in UTC' + - &evt_block_number + name: evt_block_number + description: 'block number containing transaction' + - name: lastTokenIdProcessed + description: 'last processed withdrawal' + - &rswexit_owner + name: owner + description: 'owner of rsweth burned' + - &rswexit_tokenid + name: tokenId + description: 'unique id for withdrawal processing' + - name: amount + description: 'amount of rsweth burned' + - name: timestamp + description: 'timestamp of withdrawal request' + - name: rateWhenCreated + description: 'rsweth-eth rate at withdrawal request' + + - name: RswEXIT_evt_WithdrawalsProcessed + description: decoded table on `WithdrawalsProcessed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064` + columns: + - *rswexit_contract_address + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: fromTokenId + description: 'first token_id of withdrawals processed in this batch' + - name: toTokenId + description: 'last token_id of withdrawals processed in this batch' + - name: processedRate + description: 'rsweth-eth rate at which withdrawal is processed' + - name: processedExitingETH + description: 'amount of eth exiting in current batch' + - name: processedExitedETH + description: 'amount of eth exited' + + - name: RswEXIT_evt_WithdrawalClaimed + description: decoded table on `WithdrawalClaimed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064` + columns: + - *rswexit_contract_address + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *rswexit_owner + - *rswexit_tokenid + - name: exitClaimedETH + description: 'amout of eth claimed' \ No newline at end of file From 932bcdbb2e3a9303b3619bb0c8991b918569607e Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 17:32:39 +0700 Subject: [PATCH 03/68] updating descriptions --- .../swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml b/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml index 4323e31c0fb..d0e05fded47 100644 --- a/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml +++ b/sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml @@ -5,7 +5,7 @@ sources: description: "swell decoded tables of ethereum contract" tables: - name: RswEXIT_evt_WithdrawRequestCreated - description: decoded table on `WithdrawRequestCreated` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064` + description: 'decoded table on `WithdrawRequestCreated` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064`. event emitted when a user initiates a new withdrawal request' columns: - &rswexit_contract_address name: contract_address @@ -38,7 +38,7 @@ sources: description: 'rsweth-eth rate at withdrawal request' - name: RswEXIT_evt_WithdrawalsProcessed - description: decoded table on `WithdrawalsProcessed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064` + description: 'decoded table on `WithdrawalsProcessed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064`. event emitted when the protocol processes the withdrawal from beaconchain and make it available for user to claim' columns: - *rswexit_contract_address - *evt_tx_hash @@ -57,7 +57,7 @@ sources: description: 'amount of eth exited' - name: RswEXIT_evt_WithdrawalClaimed - description: decoded table on `WithdrawalClaimed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064` + description: 'decoded table on `WithdrawalClaimed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064`. event emitted when a user claims the ETH withdrawn' columns: - *rswexit_contract_address - *evt_tx_hash From 8c939830e0db5f90b6aeae3071e3f6205202c771 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 18:20:53 +0700 Subject: [PATCH 04/68] add unique test and comma fix --- .../swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml | 4 ++++ .../rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml index 00b5e083a70..c995f39e804 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml @@ -10,6 +10,10 @@ models: config: tags: ['swell', 'restaking', 'lrt', 'withdrawals'] description: "rswETH withdrawals" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - token_id columns: - &request_block_time diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index eabcf29230b..22c8e457b85 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -4,7 +4,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['token_id'] + unique_key = ['token_id'], post_hook='{{ expose_spells(\'["ethereum"]\', "project", "swell", From e30afa0cb3d0e0dc2d7e0e854d3e5d85391eb192 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 18:33:11 +0700 Subject: [PATCH 05/68] code fixes --- .../ethereum/swell_rsweth_ethereum_withdrawals.sql | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index 22c8e457b85..2e9e07de040 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -13,13 +13,11 @@ }} {% set incremental = """ - {% if is_incremental() %} where evt_block_time >= ( select min(request_block_time) from {{this}} where claim_block_time is null ) - {% endif %} """%} with @@ -34,7 +32,10 @@ rsweth_decoded_withdrawal_requests as ( rateWhenCreated from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawRequestCreated')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawRequestCreated + + {% if is_incremental() %} {{incremental}} + {% endif %} ), rsweth_decoded_withdrawal_claimed as ( select @@ -44,7 +45,9 @@ rsweth_decoded_withdrawal_claimed as ( exitClaimedETH from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalClaimed')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalClaimed + {% if is_incremental() %} {{incremental}} + {% endif %} ), rsweth_decoded_withdrawal_processed as ( @@ -57,7 +60,9 @@ rsweth_decoded_withdrawal_processed as ( processedExitedETH from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalsProcessed')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalsProcessed + {% if is_incremental() %} {{incremental}} + {% endif %} ) select From 0d2ad4ce2f9ba912f41b79299aa94aed9eb7d6c3 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 18:44:58 +0700 Subject: [PATCH 06/68] attempt fix for incremental --- .../swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index 2e9e07de040..145d0c24540 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -15,7 +15,7 @@ {% set incremental = """ where evt_block_time >= ( select min(request_block_time) - from {{this}} + from """{this}""" where claim_block_time is null ) """%} From bf82c2d4c5e9faa838f0b05bebfe893ff464dd56 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 18:49:06 +0700 Subject: [PATCH 07/68] another incremental fix attempt --- .../swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index 145d0c24540..b3f42606d81 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -15,7 +15,7 @@ {% set incremental = """ where evt_block_time >= ( select min(request_block_time) - from """{this}""" + from """this""" where claim_block_time is null ) """%} From f3f2e358fa49569c5ac9ab97e079b6fc0afec90f Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 18:51:37 +0700 Subject: [PATCH 08/68] fuck it we ball ? --- .../swell_rsweth_ethereum_withdrawals.sql | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index b3f42606d81..f1742428dc0 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -12,14 +12,6 @@ ) }} -{% set incremental = """ - where evt_block_time >= ( - select min(request_block_time) - from """this""" - where claim_block_time is null - ) -"""%} - with rsweth_decoded_withdrawal_requests as ( select @@ -33,9 +25,13 @@ rsweth_decoded_withdrawal_requests as ( from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawRequestCreated')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawRequestCreated - {% if is_incremental() %} - {{incremental}} - {% endif %} + {% set incremental %} + where evt_block_time >= ( + select min(request_block_time) + from {{ this }} + where claim_block_time is null + ) + {% endset %} ), rsweth_decoded_withdrawal_claimed as ( select @@ -45,9 +41,13 @@ rsweth_decoded_withdrawal_claimed as ( exitClaimedETH from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalClaimed')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalClaimed - {% if is_incremental() %} - {{incremental}} - {% endif %} + {% set incremental %} + where evt_block_time >= ( + select min(request_block_time) + from {{ this }} + where claim_block_time is null + ) + {% endset %} ), rsweth_decoded_withdrawal_processed as ( @@ -60,9 +60,13 @@ rsweth_decoded_withdrawal_processed as ( processedExitedETH from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalsProcessed')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalsProcessed - {% if is_incremental() %} - {{incremental}} - {% endif %} + {% set incremental %} + where evt_block_time >= ( + select min(request_block_time) + from {{ this }} + where claim_block_time is null + ) + {% endset %} ) select From db077f1fda048dc9358376e860cd950c3b7b12e1 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 18:55:56 +0700 Subject: [PATCH 09/68] dont think the previous incremental balled --- .../swell_rsweth_ethereum_withdrawals.sql | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index f1742428dc0..17c2c377fba 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -12,6 +12,14 @@ ) }} +{% set incremental %} + where evt_block_time >= ( + select min(request_block_time) + from {{ this }} + where claim_block_time is null + ) +{% endset %} + with rsweth_decoded_withdrawal_requests as ( select @@ -24,14 +32,9 @@ rsweth_decoded_withdrawal_requests as ( rateWhenCreated from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawRequestCreated')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawRequestCreated - - {% set incremental %} - where evt_block_time >= ( - select min(request_block_time) - from {{ this }} - where claim_block_time is null - ) - {% endset %} + {% if is_incremental() %} + {{incremental}} + {% endif %} ), rsweth_decoded_withdrawal_claimed as ( select @@ -41,13 +44,9 @@ rsweth_decoded_withdrawal_claimed as ( exitClaimedETH from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalClaimed')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalClaimed - {% set incremental %} - where evt_block_time >= ( - select min(request_block_time) - from {{ this }} - where claim_block_time is null - ) - {% endset %} + {% if is_incremental() %} + {{incremental}} + {% endif %} ), rsweth_decoded_withdrawal_processed as ( @@ -60,13 +59,9 @@ rsweth_decoded_withdrawal_processed as ( processedExitedETH from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalsProcessed')}} -- from swell_v3_ethereum.RswEXIT_evt_WithdrawalsProcessed - {% set incremental %} - where evt_block_time >= ( - select min(request_block_time) - from {{ this }} - where claim_block_time is null - ) - {% endset %} + {% if is_incremental() %} + {{incremental}} + {% endif %} ) select From a1ad39f077bb97bea4afb4f21cc8803af9c03006 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 19:01:49 +0700 Subject: [PATCH 10/68] adding seed --- .../ethereum/swell_rsweth_ethereum_schema.yml | 18 ++++++++++++++ .../seeds/swell/rsweth/ethereum/schema.yml | 24 +++++++++++++++++++ ...swell_rsweth_ethereum_withdrawals_seed.csv | 3 +++ 3 files changed, 45 insertions(+) create mode 100644 dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml create mode 100644 dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml index c995f39e804..6d825cc569f 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml @@ -14,6 +14,24 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - token_id + - check_seed: + seed_file: ref('swell_rsweth_ethereum_withdrawals_seed') + match_columns: + - request_tx_hash + - request_block_number + - request_index + - token_id + - owner + - rswETH_amount + - rswETH_request_rate + - processed_tx_hash + - processed_block_number + - processed_index + - rswETH_processed_rate + - claim_tx_hash + - claim_block_number + - claim_index + - ETH_amount columns: - &request_block_time diff --git a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml new file mode 100644 index 00000000000..2aa060f0fc7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml @@ -0,0 +1,24 @@ +version: 2 + +seeds: + - name: swell_rsweth_ethereum_withdrawals_seed + config: + column_types: + request_block_time: timestamp + request_tx_hash: varbinary + request_block_number: bigint + request_index: integer + token_id: integer + owner: varbinary + rswETH_amount: uint256 + rswETH_request_rate: uint256 + processed_block_time: timestamp + processed_tx_hash: varbinary + processed_block_number: bigint + processed_index: integer + rswETH_processed_rate: uint256 + claim_block_time: timestamp + claim_tx_hash: varbinary + claim_block_number: bigint + claim_index: integer + ETH_amount: uint256 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv new file mode 100644 index 00000000000..ee2e625b0c2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv @@ -0,0 +1,3 @@ +request_block_time,request_tx_hash,request_block_number,request_index,token_id,owner,rswETH_amount,rswETH_request_rate,processed_block_time,processed_tx_hash,processed_block_number,processed_index,rswETH_processed_rate,claim_block_time,claim_tx_hash,claim_block_number,claim_index,ETH_amount +2024-11-12 06:57:47.000 UTC,0x978742baca60c9f02eec6f8328ee77abb85716eb111d340497315f077f049388,21169958,227,3007,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500000000000000000000,1023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1024494608040389206,2024-11-22 02:55:11.000 UTC,0x0fd5c4551eda43ad93f6833e0f5463afac8e88d30e3263cabcf4da9477b81fbf,21240420,274,511738321051450796000 +2024-11-12 06:56:47.000 UTC,0xd0a7cd3f2f67cca12f2fe22ef7a5f0df922c1716d2f894a8c20406fdf01fd9dd,21169953,461,3006,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500000000000000000000,1023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1024494608040389206,2024-11-22 02:54:35.000 UTC,0xf4aa4a769d39d6aadc54591eca47f59e688487580ef55f5bf4b21880bce16d3e,21240417,322,511738321051450796000 \ No newline at end of file From 4623ca84b12c493a55a71576e62c954b4602bd98 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 19:16:16 +0700 Subject: [PATCH 11/68] trying to fix seed testing --- .../ethereum/swell_rsweth_ethereum_schema.yml | 16 ++++++++++++++++ .../rsweth/ethereum/{schema.yml => _schema.yml} | 0 2 files changed, 16 insertions(+) rename dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/{schema.yml => _schema.yml} (100%) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml index 6d825cc569f..f3e8e6c14aa 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml @@ -32,6 +32,22 @@ models: - claim_block_number - claim_index - ETH_amount + check_columns: + - request_tx_hash + - request_block_number + - request_index + - token_id + - owner + - rswETH_amount + - rswETH_request_rate + - processed_tx_hash + - processed_block_number + - processed_index + - rswETH_processed_rate + - claim_tx_hash + - claim_block_number + - claim_index + - ETH_amount columns: - &request_block_time diff --git a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/_schema.yml similarity index 100% rename from dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml rename to dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/_schema.yml From e909364fea3424053eef5276c0cce4fa8dcf1516 Mon Sep 17 00:00:00 2001 From: darvin Date: Sat, 23 Nov 2024 19:23:42 +0700 Subject: [PATCH 12/68] lets try this --- .../ethereum/swell_rsweth_ethereum_schema.yml | 15 --------------- .../rsweth/ethereum/{_schema.yml => schema.yml} | 0 2 files changed, 15 deletions(-) rename dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/{_schema.yml => schema.yml} (100%) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml index f3e8e6c14aa..2ac88a66d10 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_schema.yml @@ -17,26 +17,11 @@ models: - check_seed: seed_file: ref('swell_rsweth_ethereum_withdrawals_seed') match_columns: - - request_tx_hash - - request_block_number - - request_index - token_id - - owner - - rswETH_amount - - rswETH_request_rate - - processed_tx_hash - - processed_block_number - - processed_index - - rswETH_processed_rate - - claim_tx_hash - - claim_block_number - - claim_index - - ETH_amount check_columns: - request_tx_hash - request_block_number - request_index - - token_id - owner - rswETH_amount - rswETH_request_rate diff --git a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/_schema.yml b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml similarity index 100% rename from dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/_schema.yml rename to dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml From ec763b4e766ca9127a29bb4ab78c68665294ddab Mon Sep 17 00:00:00 2001 From: darvin Date: Tue, 26 Nov 2024 18:22:32 +0530 Subject: [PATCH 13/68] decimal fixes --- .../ethereum/swell_rsweth_ethereum_withdrawals.sql | 10 +++++----- .../seeds/swell/rsweth/ethereum/schema.yml | 8 ++++---- .../swell_rsweth_ethereum_withdrawals_seed.csv | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql index 17c2c377fba..1f0a6730ae6 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals.sql @@ -9,7 +9,7 @@ "project", "swell", \'["maybeYonas"]\') }}' - ) + ) }} {% set incremental %} @@ -71,20 +71,20 @@ select r.evt_index as request_index, r.tokenId as token_id, r.owner as owner, - r.amount as rswETH_amount, - r.rateWhenCreated as rswETH_request_rate, + r.amount/1e18 as rswETH_amount, + r.rateWhenCreated/1e18 as rswETH_request_rate, p.evt_block_time as processed_block_time, p.evt_tx_hash as processed_tx_hash, p.evt_block_number as processed_block_number, p.evt_index as processed_index, - p.processedRate as rswETH_processed_rate, + p.processedRate/1e18 as rswETH_processed_rate, c.evt_block_time as claim_block_time, c.evt_tx_hash as claim_tx_hash, c.evt_block_number as claim_block_number, c.evt_index as claim_index, - c.exitClaimedETH as ETH_amount + c.exitClaimedETH/1e18 as ETH_amount from rsweth_decoded_withdrawal_requests r left join rsweth_decoded_withdrawal_processed p on r.tokenId >= p.fromTokenId diff --git a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml index 2aa060f0fc7..84344e87d47 100644 --- a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml +++ b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/schema.yml @@ -10,15 +10,15 @@ seeds: request_index: integer token_id: integer owner: varbinary - rswETH_amount: uint256 - rswETH_request_rate: uint256 + rswETH_amount: double + rswETH_request_rate: double processed_block_time: timestamp processed_tx_hash: varbinary processed_block_number: bigint processed_index: integer - rswETH_processed_rate: uint256 + rswETH_processed_rate: double claim_block_time: timestamp claim_tx_hash: varbinary claim_block_number: bigint claim_index: integer - ETH_amount: uint256 \ No newline at end of file + ETH_amount: double \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv index ee2e625b0c2..c46f8111e3e 100644 --- a/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv +++ b/dbt_subprojects/daily_spellbook/seeds/swell/rsweth/ethereum/swell_rsweth_ethereum_withdrawals_seed.csv @@ -1,3 +1,3 @@ request_block_time,request_tx_hash,request_block_number,request_index,token_id,owner,rswETH_amount,rswETH_request_rate,processed_block_time,processed_tx_hash,processed_block_number,processed_index,rswETH_processed_rate,claim_block_time,claim_tx_hash,claim_block_number,claim_index,ETH_amount -2024-11-12 06:57:47.000 UTC,0x978742baca60c9f02eec6f8328ee77abb85716eb111d340497315f077f049388,21169958,227,3007,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500000000000000000000,1023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1024494608040389206,2024-11-22 02:55:11.000 UTC,0x0fd5c4551eda43ad93f6833e0f5463afac8e88d30e3263cabcf4da9477b81fbf,21240420,274,511738321051450796000 -2024-11-12 06:56:47.000 UTC,0xd0a7cd3f2f67cca12f2fe22ef7a5f0df922c1716d2f894a8c20406fdf01fd9dd,21169953,461,3006,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500000000000000000000,1023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1024494608040389206,2024-11-22 02:54:35.000 UTC,0xf4aa4a769d39d6aadc54591eca47f59e688487580ef55f5bf4b21880bce16d3e,21240417,322,511738321051450796000 \ No newline at end of file +2024-11-12 06:57:47.000 UTC,0x978742baca60c9f02eec6f8328ee77abb85716eb111d340497315f077f049388,21169958,227,3007,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500.00,1.023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1.024494608040389206,2024-11-22 02:55:11.000 UTC,0x0fd5c4551eda43ad93f6833e0f5463afac8e88d30e3263cabcf4da9477b81fbf,21240420,274,511.738321051450796 +2024-11-12 06:56:47.000 UTC,0xd0a7cd3f2f67cca12f2fe22ef7a5f0df922c1716d2f894a8c20406fdf01fd9dd,21169953,461,3006,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500.00,1.023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1.024494608040389206,2024-11-22 02:54:35.000 UTC,0xf4aa4a769d39d6aadc54591eca47f59e688487580ef55f5bf4b21880bce16d3e,21240417,322,511.738321051450796 \ No newline at end of file From b6016202b7c7fb53ee8e0ecd28ede6efb26993b3 Mon Sep 17 00:00:00 2001 From: darvin Date: Tue, 26 Nov 2024 18:53:00 +0530 Subject: [PATCH 14/68] adding core asset balances --- .../swell_balances_ethereum_core_assets.sql | 58 +++++++++++++++++++ .../swell_balances_ethereum_schema.yml | 53 +++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql create mode 100644 dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_schema.yml diff --git a/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql b/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql new file mode 100644 index 00000000000..cc05eca57bd --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql @@ -0,0 +1,58 @@ +{{ + config( + schema = 'swell_balances_ethereum', + alias = 'core_assets', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['day', 'address', 'token_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')], + post_hook='{{ expose_spells(\'["ethereum"]\', + "project", + "swell", + \'["maybeYonas"]\') }}' + ) +}} + +with +tokens as ( + select * from (values + (0xf951E335afb289353dc249e82926178EaC7DEd78, 'swETH', 'Swell LRT'), + (0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0, 'rswETH', 'Swell LRT'), + (0x0a6E7Ba5042B38349e437ec6Db6214AEC7B35676, 'SWELL', 'Swell LRT'), + (0x358d94b5b2F147D741088803d932Acb566acB7B6, 'rSWELL', 'Swell LRT'), + (0x9Ed15383940CC380fAEF0a75edacE507cC775f22, 'earnETH', 'Swell LRT'), + (0x66E47E6957B85Cf62564610B76dD206BB04d831a, 'earnBTC', 'Swell LRT'), + (0x8DB2350D78aBc13f5673A411D4700BCF87864dDE, 'swBTC', 'Swell LRT') + ) as t( + token_address, + symbol, + name + ) +), +balances as ( + {{ + balances_incremental_subset_daily( + blockchain = 'ethereum', + token_list = 'tokens', + start_date = '2023-04-12' + ) + }} +) + +select + -- t.name, + b.blockchain, + b.day, + b.address as wallet_address, + b.token_symbol, + b.token_address, + b.token_standard, + b.token_id, + b.balance, + b.balance_usd, + b.last_updated, + b.next_update +from balances b +-- left join tokens t +-- on b.token_address = t.token_address diff --git a/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_schema.yml b/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_schema.yml new file mode 100644 index 00000000000..997abdb2663 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_schema.yml @@ -0,0 +1,53 @@ +version: 2 + +models: + - name: swell_balances_ethereum_core_assets + + meta: + blockchain: ethereum + project: swell + contributors: maybeYonas + + config: + tags: ['swell', 'restaking', 'lrt', 'lst', 'vaults', 'balances'] + description: "balances of swell asset holders" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - wallet_address + - token_address + columns: + - &blockchain + name: blockchain + description: "blockchain" + - &day + name: day + description: "date on which the token balance is logged" + - &wallet_address + name: wallet_address + description: "wallet address of the holder" + - &token_symbol + name: token_symbol + description: "token symbol" + - &token_address + name: token_address + description: "token address" + - &token_standard + name: token_standard + description: "standard of the token (erc20)" + - &token_id + name: token_id + description: "ID of the token" + - &balance + name: balance + description: "asset balance of the wallet" + - &balance_usd + name: balance_usd + description: "usd value of token balance of the wallet" + - &last_updated + name: last_updated + description: "UTC timestamp when balance was last updated" + - &next_update + name: next_update + description: "UTC timestamp when balance is next updated" From a3350ca80be967a410ca43de6cf28e14b5792126 Mon Sep 17 00:00:00 2001 From: darvin Date: Tue, 26 Nov 2024 19:41:37 +0530 Subject: [PATCH 15/68] fix unique key --- .../balances/ethereum/swell_balances_ethereum_core_assets.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql b/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql index cc05eca57bd..66bf403601c 100644 --- a/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql +++ b/dbt_subprojects/daily_spellbook/models/swell/balances/ethereum/swell_balances_ethereum_core_assets.sql @@ -5,7 +5,7 @@ materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['day', 'address', 'token_address'], + unique_key = ['day', 'wallet_address', 'token_address'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')], post_hook='{{ expose_spells(\'["ethereum"]\', "project", From 260aaa3515fb93123d82e3e75f689d6fbc2c302c Mon Sep 17 00:00:00 2001 From: hildobby Date: Mon, 25 Nov 2024 23:23:34 +0700 Subject: [PATCH 16/68] update cex addresses (#7126) * update cex addresses * add addresses --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../addresses/chains/cex_evms_addresses.sql | 107 +----------------- 1 file changed, 3 insertions(+), 104 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql b/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql index 399647ca897..dacb8ab17e9 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql @@ -97,7 +97,7 @@ FROM (VALUES , (0x3931dab967c3e2dbb492fe12460a66d0fe4cc857, 'Binance', 'Binance 89', 'hildobby', date '2024-10-06') , (0x25681ab599b4e2ceea31f8b498052c53fc2d74db, 'Binance', 'Binance 90', 'hildobby', date '2024-10-06') , (0x29fe6c66097f7972d8e47c4f691576327fcf9a12, 'Binance', 'Binance 91', 'hildobby', date '2024-10-14') - , (0xb587dbd25d7576b94922370d116226c155608a14, 'Binance', 'Binance 92', 'hildobby', date '2024-10-14') + , (0xfdd2ba77db02caa6a9869735dac577d809cadd11, 'Binance', 'Binance 92', 'hildobby', date '2024-11-08') , (0xef7fb88f709ac6148c07d070bc71d252e8e13b92, 'Binance', 'Binance Internal', 'hildobby', date '2023-11-22') , (0x8b99f3660622e21f2910ecca7fbe51d654a1517d, 'Binance', 'Binance Charity', 'hildobby', date '2022-08-28') , (0xab83d182f3485cf1d6ccdd34c7cfef95b4c08da4, 'Binance', 'Binance JEX', 'hildobby', date '2022-08-28') @@ -260,108 +260,6 @@ FROM (VALUES , (0x3dd87411a3754deea8cc52c4cf57e2fc254924cc, 'Coinbase', 'Coinbase 56', 'hildobby', date '2024-05-04') , (0x441cacfd43856409b163b90e094bb42aeb70a70e, 'Coinbase', 'Coinbase 57', 'hildobby', date '2024-05-25') , (0xa14d57f5ea867572b0d239798d2c1dde13153902, 'Coinbase', 'Coinbase 58', 'hildobby', date '2024-05-25') - , (0x56e43d4f29a62a835aacd36db2725151874acca6, 'Coinbase', 'Coinbase 59', 'hildobby', date '2024-10-06') - , (0xc5b3a7675e2818c0c6943a2d9ea9a407cbe70f40, 'Coinbase', 'Coinbase 60', 'hildobby', date '2024-10-06') - , (0xdc3937008ff58f991e97e218e0aeaf9e9374a48a, 'Coinbase', 'Coinbase 61', 'hildobby', date '2024-10-06') - , (0xa102a06fa1abd8105a6e9965281539099adc7d7c, 'Coinbase', 'Coinbase 62', 'hildobby', date '2024-10-06') - , (0xca3ac4f946b997db24515a7ae7779f2e587d5a26, 'Coinbase', 'Coinbase 63', 'hildobby', date '2024-10-06') - , (0x7453cdce4d98e8aac6bcb7ada980467ad1c3a5fa, 'Coinbase', 'Coinbase 64', 'hildobby', date '2024-10-06') - , (0x36b0ca172da5a33201efdc398acf9dde8f29d69a, 'Coinbase', 'Coinbase 65', 'hildobby', date '2024-10-06') - , (0x7c5fcf4a9ae8fb8570ddea073457c9855d9c1cf5, 'Coinbase', 'Coinbase 66', 'hildobby', date '2024-10-06') - , (0x4b8a6a3a657ba4568bd582fffe776a325a8616af, 'Coinbase', 'Coinbase 67', 'hildobby', date '2024-10-06') - , (0xe62240a57f0efbf549e278e8058f632af3ea5206, 'Coinbase', 'Coinbase 68', 'hildobby', date '2024-10-06') - , (0x860424e9e243a53383257d152d422b6f59c933a4, 'Coinbase', 'Coinbase 69', 'hildobby', date '2024-10-06') - , (0xb7eb5f43c1b45ce98a197a6bd975a076ec02a003, 'Coinbase', 'Coinbase 70', 'hildobby', date '2024-10-06') - , (0x05613ea65680e6076d1490dd2e90a68e71fe734b, 'Coinbase', 'Coinbase 71', 'hildobby', date '2024-10-06') - , (0x569940d32cbcadff9e003235e86536871051abaf, 'Coinbase', 'Coinbase 72', 'hildobby', date '2024-10-06') - , (0x6cd5dab3abac9d884ba31270ae0d559e60ee703e, 'Coinbase', 'Coinbase 73', 'hildobby', date '2024-10-06') - , (0x190a3fc38f82d07eca99592a5427eff331e8e62f, 'Coinbase', 'Coinbase 74', 'hildobby', date '2024-10-06') - , (0x6fb626b622fe5956e3925fc72352f6b0047138ac, 'Coinbase', 'Coinbase 75', 'hildobby', date '2024-10-06') - , (0x714e4559f5488d6c0abde6fa88a64e0b269f25c0, 'Coinbase', 'Coinbase 76', 'hildobby', date '2024-10-06') - , (0x0b44611b8ae632be05f24ffe64651f050402ae01, 'Coinbase', 'Coinbase 77', 'hildobby', date '2024-10-06') - , (0xc4ca777b37259824a0ce6a97f7b59caf000a301a, 'Coinbase', 'Coinbase 78', 'hildobby', date '2024-10-06') - , (0xd2ca6c830bf11f72fcb64f43880c23dbdcb43705, 'Coinbase', 'Coinbase 79', 'hildobby', date '2024-10-12') - , (0xe3387b356207b3e8758b6c9a1b7cc9e41c978f22, 'Coinbase', 'Coinbase 80', 'hildobby', date '2024-10-06') - , (0x299cc8e603077b2bdcf265b600cf004c2cf77401, 'Coinbase', 'Coinbase 81', 'hildobby', date '2024-10-06') - , (0x6fd72c7a8d1e521b17f321ec6bfc4f83ff58c1e2, 'Coinbase', 'Coinbase 82', 'hildobby', date '2024-10-06') - , (0xb19d4c6a270b5e737483588da1b943b01e59dc47, 'Coinbase', 'Coinbase 83', 'hildobby', date '2024-10-06') - , (0x211b8d2eb72dbb6382bf08acd1328099f962ff6f, 'Coinbase', 'Coinbase 84', 'hildobby', date '2024-10-06') - , (0x4eb9548132c1bcb02fbdddde5d946d558864f76d, 'Coinbase', 'Coinbase 86', 'hildobby', date '2024-10-06') - , (0x7aa85c264a613925a756a9d901c31c7e25979537, 'Coinbase', 'Coinbase 87', 'hildobby', date '2024-10-06') - , (0xd356e0857bd5711be2155b3d352d5699d555d9ce, 'Coinbase', 'Coinbase 88', 'hildobby', date '2024-10-06') - , (0x0b9eda13de765fff1e3bbda113e815adf93aed7b, 'Coinbase', 'Coinbase 89', 'hildobby', date '2024-10-06') - , (0x0efb879e9cc0ed546c487df0a150be8fffd0608e, 'Coinbase', 'Coinbase 90', 'hildobby', date '2024-10-06') - , (0xcd9f1f99bd51ed5a35c9342fbbc96bd6f17f0891, 'Coinbase', 'Coinbase 91', 'hildobby', date '2024-10-06') - , (0x18701bc17d54b38b71023b0510f9765985fdb53c, 'Coinbase', 'Coinbase 92', 'hildobby', date '2024-10-06') - , (0x804cbb1fe6d4152059b0336f9e62b5d118d9c608, 'Coinbase', 'Coinbase 93', 'hildobby', date '2024-10-06') - , (0xaf80e81ded234d229c0e60237f2d0c97ca315178, 'Coinbase', 'Coinbase 94', 'hildobby', date '2024-10-06') - , (0x1ff9e1818688daf19c673b7e29f6acead7e987a9, 'Coinbase', 'Coinbase 95', 'hildobby', date '2024-10-06') - , (0x5c70b6d4d2ee0ce6edafed66e71db0ee1e91461f, 'Coinbase', 'Coinbase 96', 'hildobby', date '2024-10-06') - , (0x3c73ef921cfa5ce70831f360f978bd197f6a1771, 'Coinbase', 'Coinbase 97', 'hildobby', date '2024-10-06') - , (0x069d07e9ff579c9c478af4878fcb87f17bf2733f, 'Coinbase', 'Coinbase 98', 'hildobby', date '2024-10-06') - , (0xba594c942110627675322cf994cbffa5b3b07451, 'Coinbase', 'Coinbase 99', 'hildobby', date '2024-10-06') - , (0xd58fbd9ed67bd84dd8154761147173b52ed55308, 'Coinbase', 'Coinbase 100', 'hildobby', date '2024-10-06') - , (0x01967789fc29f6cd6d7b5caa9b81ca1c0119bfd9, 'Coinbase', 'Coinbase 101', 'hildobby', date '2024-10-06') - , (0xbf5501587128acee17a0b0e7774aa2c954a343e2, 'Coinbase', 'Coinbase 102', 'hildobby', date '2024-10-06') - , (0x0f71dcff39ab3a817d02b6b3b808ffa21d3f67c1, 'Coinbase', 'Coinbase 103', 'hildobby', date '2024-10-06') - , (0x20ed4ef14cce5c4c064c3858f557f1422dd156e3, 'Coinbase', 'Coinbase 104', 'hildobby', date '2024-10-06') - , (0x7d69fd776b727e74857d4857a7dd5e3967887208, 'Coinbase', 'Coinbase 105', 'hildobby', date '2024-10-06') - , (0x87cd2828979817757b4a7607dd04def4957ef437, 'Coinbase', 'Coinbase 106', 'hildobby', date '2024-10-06') - , (0x8914019d12628cce16bc652c39207b604d91d975, 'Coinbase', 'Coinbase 107', 'hildobby', date '2024-10-06') - , (0x07837cebe3e35d2bd176bef88b537cb2fda6ace8, 'Coinbase', 'Coinbase 108', 'hildobby', date '2024-10-06') - , (0x34cbd2bf0c0b89af3b66ea44f62554bb656b3ad1, 'Coinbase', 'Coinbase 109', 'hildobby', date '2024-10-06') - , (0x3caf154ef6178c1c87e0df411913bb0ef2c3b228, 'Coinbase', 'Coinbase 110', 'hildobby', date '2024-10-06') - , (0x6ad18dd6682e99b0201a3b18f403ae566a51ce28, 'Coinbase', 'Coinbase 111', 'hildobby', date '2024-10-06') - , (0xc141279e7168984c99dbc079a86d18605c30901e, 'Coinbase', 'Coinbase 112', 'hildobby', date '2024-10-06') - , (0x8bcbf517b67b9d1ab8ff6dddaa743df98d7498a6, 'Coinbase', 'Coinbase 113', 'hildobby', date '2024-10-06') - , (0x2bc7c910c3ff28c2725128078ecc6412638de45b, 'Coinbase', 'Coinbase 114', 'hildobby', date '2024-10-06') - , (0x335ec2eaf64526bc8bba5030459ed703b71b1c03, 'Coinbase', 'Coinbase 115', 'hildobby', date '2024-10-06') - , (0x80a7d049189ed345c56ba2ef4949aa40b136ccbf, 'Coinbase', 'Coinbase 116', 'hildobby', date '2024-10-06') - , (0x0835e9777d3080be33382566c8eb303c59c24759, 'Coinbase', 'Coinbase 117', 'hildobby', date '2024-10-06') - , (0x46a359199c302aac6b680634551b5c0a6ffcdeac, 'Coinbase', 'Coinbase 118', 'hildobby', date '2024-10-06') - , (0x9a7b843e4892e22319e2494097d4e72e8d928921, 'Coinbase', 'Coinbase 119', 'hildobby', date '2024-10-06') - , (0xf586704c4a00088d5bf128aba0244409bb849677, 'Coinbase', 'Coinbase 122', 'hildobby', date '2024-10-06') - , (0xdccbc0644b0a204780fc8aa21693f81444770c83, 'Coinbase', 'Coinbase 123', 'hildobby', date '2024-10-06') - , (0x9cf674f00b6bf61012393174913b7818cd2fc508, 'Coinbase', 'Coinbase 124', 'hildobby', date '2024-10-06') - , (0x81257264ace1e9923cf87e58176987d0b4fe0892, 'Coinbase', 'Coinbase 125', 'hildobby', date '2024-10-06') - , (0x8b413e9550505bd7efa4380659793d59d8b11389, 'Coinbase', 'Coinbase 126', 'hildobby', date '2024-10-06') - , (0x69e2f5cc36b788c35b4a8fb1a827f3fd32d62469, 'Coinbase', 'Coinbase 127', 'hildobby', date '2024-10-06') - , (0xb6fe66f4f56f3aaf60c4e814887af5064ec934f5, 'Coinbase', 'Coinbase 128', 'hildobby', date '2024-10-06') - , (0x9e91e341d2c4342f74d142896c4407e65def0c68, 'Coinbase', 'Coinbase 129', 'hildobby', date '2024-10-06') - , (0x6e5d44060fac77c126a75fa1f7bfaf224ab52c1e, 'Coinbase', 'Coinbase 130', 'hildobby', date '2024-10-06') - , (0x8c2dd8cbad62b5ced00855c6291744f0216ac58c, 'Coinbase', 'Coinbase 131', 'hildobby', date '2024-10-06') - , (0x0e50f766368ee5cd9286c1d29299766c471b8072, 'Coinbase', 'Coinbase 132', 'hildobby', date '2024-10-06') - , (0x18bc4ee79785142f3aa8a893e9153cfded03637b, 'Coinbase', 'Coinbase 133', 'hildobby', date '2024-10-06') - , (0x2577ecc5146fcc398118da363218140f8720c30a, 'Coinbase', 'Coinbase 134', 'hildobby', date '2024-10-06') - , (0xd010d97be4d7be278872e25d02cd6534b0499d17, 'Coinbase', 'Coinbase 135', 'hildobby', date '2024-10-06') - , (0xc31e0545fe3de0ed4283e3213a5fc9e5006adc62, 'Coinbase', 'Coinbase 136', 'hildobby', date '2024-10-06') - , (0x784c1fb954ad66b7070ba71ab74d29745676151c, 'Coinbase', 'Coinbase 137', 'hildobby', date '2024-10-06') - , (0x3a050132d1dd00efe8da01b072b7b04c3801ebde, 'Coinbase', 'Coinbase 138', 'hildobby', date '2024-10-06') - , (0x1e281846fdaa56819d7ff0203bfdee6c2ef75fa9, 'Coinbase', 'Coinbase 139', 'hildobby', date '2024-10-06') - , (0x37cb1d0367788046a6208e461f8f621154626359, 'Coinbase', 'Coinbase 140', 'hildobby', date '2024-10-06') - , (0xac89df060b1a9598d7b33e48f0af523926f36759, 'Coinbase', 'Coinbase 141', 'hildobby', date '2024-10-06') - , (0x5fe3a42e27efe8ece2ed029021ea77b4fa4782d4, 'Coinbase', 'Coinbase 142', 'hildobby', date '2024-10-06') - , (0x1953fe2eae011d9a25ca90a0d76655150b010fa2, 'Coinbase', 'Coinbase 143', 'hildobby', date '2024-10-06') - , (0x7090e61545bd0a295a1f11532eea7fd9f1784325, 'Coinbase', 'Coinbase 144', 'hildobby', date '2024-10-16') - , (0x3a46ae89425716c149cc88676b07525b8184de58, 'Coinbase', 'Coinbase 145', 'hildobby', date '2024-10-06') - , (0x5ccdd1bc112279f93fa364c40e8a5716d2daf666, 'Coinbase', 'Coinbase 146', 'hildobby', date '2024-10-06') - , (0x87a80a12dc5a565dcec4939ebdea1b81bc073658, 'Coinbase', 'Coinbase 147', 'hildobby', date '2024-10-06') - , (0x765e26f528ffb96c9d74097f585c201030eb62ed, 'Coinbase', 'Coinbase 148', 'hildobby', date '2024-10-06') - , (0xf4f9ef2d331194d2e8a840e77ddc9832dac2b4ab, 'Coinbase', 'Coinbase 149', 'hildobby', date '2024-10-06') - , (0x4a99c70850294a76eaf2583cb006d17e2abf5ce8, 'Coinbase', 'Coinbase 150', 'hildobby', date '2024-10-06') - , (0xb803c454247bd4f1eb08f9843e7fdc55436a28fd, 'Coinbase', 'Coinbase 151', 'hildobby', date '2024-10-06') - , (0xdcc168ecf35aecbb570eb46f884225c80dc44031, 'Coinbase', 'Coinbase 152', 'hildobby', date '2024-10-06') - , (0x4acaeac37793e52d298b6cf28f8411c0185b794e, 'Coinbase', 'Coinbase 153', 'hildobby', date '2024-10-06') - , (0x34b0f263168bd375c6a258eade652f47eb920c15, 'Coinbase', 'Coinbase 154', 'hildobby', date '2024-10-06') - , (0x48ffe213fa4c657c3d534d586a95ea33549dd142, 'Coinbase', 'Coinbase 155', 'hildobby', date '2024-10-06') - , (0x0fa2415a6e34168c600a2c3dbc893fbf82f4180a, 'Coinbase', 'Coinbase 156', 'hildobby', date '2024-10-06') - , (0xad3cf3909ad0cf4e9cb2eab0fbc61f1e90833cbb, 'Coinbase', 'Coinbase 157', 'hildobby', date '2024-10-06') - , (0x417404de28e4b3d75a2340ff95a749b84deddc6f, 'Coinbase', 'Coinbase 158', 'hildobby', date '2024-10-06') - , (0x5d4a1f65a7b354e35749620200aeb2d5d8ce4867, 'Coinbase', 'Coinbase 159', 'hildobby', date '2024-10-06') - , (0xcfb7ac41dcc8c575b93e9085ef496cd2ca0be55e, 'Coinbase', 'Coinbase 160', 'hildobby', date '2024-10-06') - , (0xc841b57520101282a42441aca955adcb168786b2, 'Coinbase', 'Coinbase 161', 'hildobby', date '2024-10-06') - , (0xad7be7ab77e4e3ef9c18df32d2f71c98d715f129, 'Coinbase', 'Coinbase 162', 'hildobby', date '2024-10-06') - , (0x54d4f4932a68c8f90806c09518d7b5a4f8d36e73, 'Coinbase', 'Coinbase 163', 'hildobby', date '2024-10-06') , (0xa090e606e30bd747d4e6245a1517ebe430f0057e, 'Coinbase', 'Coinbase Miscellaneous', 'hildobby', date '2022-08-28') , (0xf6874c88757721a02f47592140905c4336dfbc61, 'Coinbase', 'Coinbase Commerce', 'hildobby', date '2022-08-28') , (0x881d4032abe4188e2237efcd27ab435e81fc6bb1, 'Coinbase', 'Coinbase Commerce 2', 'hildobby', date '2022-08-28') @@ -1788,7 +1686,7 @@ FROM (VALUES , (0x714d7321fe17acbcf1d64fd3a48ac22d3d214204, 'ShapeShift', 'ShapeShift Gas Supplier 21', 'hildobby', date '2024-10-06') , (0x5d089c8141e58773bc88fba973198b3ec95aa501, 'ShapeShift', 'ShapeShift Gas Supplier 22', 'hildobby', date '2024-10-06') , (0x5aa107c71a314cada39db8fe7f9b591f67521c14, 'ShapeShift', 'ShapeShift Gas Supplier 23', 'hildobby', date '2024-10-12') - + , (0x7b9bc474667db2ffe5b08d000f1acc285b2ae47d, 'ShapeShift', 'ShapeShift Gas Supplier 24', 'hildobby', date '2024-11-08') -- Shakepay , (0x912fd21d7a69678227fe6d08c64222db41477ba0, 'Shakepay', 'Shakepay 1', 'hildobby', date '2023-11-17') , (0x000f422887ea7d370ff31173fd3b46c8f66a5b1c, 'Shakepay', 'Shakepay 2', 'hildobby', date '2023-11-17') @@ -2478,6 +2376,7 @@ FROM (VALUES , (0x6efb20f61b80f6a7ebe7a107bace58288a51fb34, 'BiKi', 'BiKi 2', 'hildobby', date '2023-11-23') , (0xf71cbf6758aaaaf06ebcca5447019c31bb145782, 'BiKi', 'BiKi Gas Supplier 1', 'hildobby', date '2023-11-23') , (0xfd736faa01073d35c148b61093e6ae562b2f8544, 'BiKi', 'BiKi Gas Supplier 2', 'hildobby', date '2023-11-23') + , (0x06ba294d190b5f9788ffca86ce19a43cd746d36a, 'BiKi', 'BiKi Gas Supplier 3', 'hildobby', date '2024-11-08') -- Coindelta , (0xb6ba1931e4e74fd080587688f6db10e830f810d5, 'Coindelta', 'Coindelta 1', 'hildobby', date '2023-04-06') -- Gamdom From 4e9100c13f9fc7579ecea948f7920c3fd3354960 Mon Sep 17 00:00:00 2001 From: silointern Date: Mon, 25 Nov 2024 16:24:00 +0000 Subject: [PATCH 17/68] Add sei to dex.atomic_arbitrages and sandwiches (#7171) * Add sei to dex.atomic_arbitrages * Add sandwiches for sei * Reformat * Add missing schema --------- Co-authored-by: silointern Co-authored-by: Huang Geyang --- .../dex/models/arbitrages/_schema.yml | 45 +++++++++- .../arbitrages/dex_atomic_arbitrages.sql | 3 +- .../sei/dex_sei_atomic_arbitrages.sql | 20 +++++ .../dex/models/sandwiches/_schema.yml | 82 +++++++++++++++++++ .../dex/models/sandwiches/dex_sandwiched.sql | 3 +- .../dex/models/sandwiches/dex_sandwiches.sql | 3 +- .../sandwiches/sei/dex_sei_sandwiched.sql | 21 +++++ .../sandwiches/sei/dex_sei_sandwiches.sql | 19 +++++ 8 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 dbt_subprojects/dex/models/arbitrages/sei/dex_sei_atomic_arbitrages.sql create mode 100644 dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiched.sql create mode 100644 dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiches.sql diff --git a/dbt_subprojects/dex/models/arbitrages/_schema.yml b/dbt_subprojects/dex/models/arbitrages/_schema.yml index d2832bd62b7..6ebec22ac67 100644 --- a/dbt_subprojects/dex/models/arbitrages/_schema.yml +++ b/dbt_subprojects/dex/models/arbitrages/_schema.yml @@ -3,7 +3,7 @@ version: 2 models: - name: dex_atomic_arbitrages meta: - blockchain: ethereum, bnb, avalanche_c, gnosis, optimism, arbitrum, fantom, polygon, base, celo, zksync, scroll, zora + blockchain: ethereum, bnb, avalanche_c, gnosis, optimism, arbitrum, fantom, polygon, base, celo, zksync, scroll, zora, sei sector: dex contributors: hildobby config: @@ -653,3 +653,46 @@ models: - *amount_usd - *evt_index + - name: dex_sei_atomic_arbitrages + meta: + blockchain: sei + sector: dex + contributors: silointern + config: + tags: ['dex', 'mev', 'atomic', 'arbitrages', 'sei'] + description: > + DEX MEV Arbitrage Trades on Sei + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - project_contract_address + - evt_index + columns: + - *blockchain + - *project + - *version + - *block_time + - *block_month + - *block_number + - *token_sold_address + - *token_bought_address + - *token_sold_symbol + - *token_bought_symbol + - *maker + - *taker + - *tx_hash + - *tx_from + - *tx_to + - *project_contract_address + - *trace_address + - *token_pair + - *tx_index + - *token_sold_amount_raw + - *token_bought_amount_raw + - *token_sold_amount + - *token_bought_amount + - *amount_usd + - *evt_index + diff --git a/dbt_subprojects/dex/models/arbitrages/dex_atomic_arbitrages.sql b/dbt_subprojects/dex/models/arbitrages/dex_atomic_arbitrages.sql index 72b8fde3c2c..fb52ea98530 100644 --- a/dbt_subprojects/dex/models/arbitrages/dex_atomic_arbitrages.sql +++ b/dbt_subprojects/dex/models/arbitrages/dex_atomic_arbitrages.sql @@ -7,7 +7,7 @@ incremental_strategy = 'merge', unique_key = ['blockchain', 'tx_hash', 'project_contract_address', 'evt_index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "fantom", "polygon", "base", "celo", "zksync", "scroll", "zora"]\', + post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "fantom", "polygon", "base", "celo", "zksync", "scroll", "zora", "sei"]\', "sector", "dex", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , (ref('dex_zksync_atomic_arbitrages')) , (ref('dex_scroll_atomic_arbitrages')) , (ref('dex_zora_atomic_arbitrages')) + , (ref('dex_sei_atomic_arbitrages')) ] %} SELECT * diff --git a/dbt_subprojects/dex/models/arbitrages/sei/dex_sei_atomic_arbitrages.sql b/dbt_subprojects/dex/models/arbitrages/sei/dex_sei_atomic_arbitrages.sql new file mode 100644 index 00000000000..971abb434b5 --- /dev/null +++ b/dbt_subprojects/dex/models/arbitrages/sei/dex_sei_atomic_arbitrages.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'sei' %} + +{{ config( + schema = 'dex_' + blockchain, + alias = 'atomic_arbitrages', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'project_contract_address', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +) +}} + +{{ + dex_atomic_arbitrages( + blockchain = blockchain + , transactions = source(blockchain,'transactions') + ) +}} diff --git a/dbt_subprojects/dex/models/sandwiches/_schema.yml b/dbt_subprojects/dex/models/sandwiches/_schema.yml index 01ad1503c6e..f19aa34c6ea 100644 --- a/dbt_subprojects/dex/models/sandwiches/_schema.yml +++ b/dbt_subprojects/dex/models/sandwiches/_schema.yml @@ -667,6 +667,47 @@ models: - *amount_usd - *evt_index + - name: dex_sei_sandwiches + meta: + blockchain: sei + sector: dex + contributors: hildobby, silointern + config: + tags: ["dex", "mev", "sandwiches", "sei"] + description: > + DEX MEV Sandwich Trades on SEI Network + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + columns: + - *blockchain + - *project + - *version + - *block_time + - *block_month + - *block_number + - *token_sold_address + - *token_bought_address + - *token_sold_symbol + - *token_bought_symbol + - *maker + - *taker + - *tx_hash + - *tx_from + - *tx_to + - *project_contract_address + - *token_pair + - *tx_index + - *token_sold_amount_raw + - *token_bought_amount_raw + - *token_sold_amount + - *token_bought_amount + - *amount_usd + - *evt_index + - name: dex_ethereum_sandwiched meta: blockchain: ethereum @@ -1174,6 +1215,47 @@ models: - blockchain - tx_hash - evt_index + columns: + - *blockchain + - *project + - *version + - *block_time + - *block_month + - *block_number + - *token_sold_address + - *token_bought_address + - *token_sold_symbol + - *token_bought_symbol + - *maker + - *taker + - *tx_hash + - *tx_from + - *tx_to + - *project_contract_address + - *token_pair + - *tx_index + - *token_sold_amount_raw + - *token_bought_amount_raw + - *token_sold_amount + - *token_bought_amount + - *amount_usd + - *evt_index + + - name: dex_sei_sandwiched + meta: + blockchain: sei + sector: dex + contributors: hildobby, silointern + config: + tags: ["dex", "mev", "sandwiched", "sei"] + description: > + DEX MEV Sandwiched Trades on SEI Network + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index columns: - *blockchain - *project diff --git a/dbt_subprojects/dex/models/sandwiches/dex_sandwiched.sql b/dbt_subprojects/dex/models/sandwiches/dex_sandwiched.sql index 947862f9785..ef2fd8f4674 100644 --- a/dbt_subprojects/dex/models/sandwiches/dex_sandwiched.sql +++ b/dbt_subprojects/dex/models/sandwiches/dex_sandwiched.sql @@ -8,7 +8,7 @@ incremental_strategy = 'merge', unique_key = ['blockchain', 'tx_hash', 'evt_index'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "fantom", "polygon", "base", "celo", "zksync", "scroll", "zora"]\', + post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "fantom", "polygon", "base", "celo", "zksync", "scroll", "zora", "sei"]\', "sector", "dex", \'["hildobby"]\') }}' @@ -29,6 +29,7 @@ , (ref('dex_zksync_sandwiched')) , (ref('dex_scroll_sandwiched')) , (ref('dex_zora_sandwiched')) + , (ref('dex_sei_sandwiched')) ] %} SELECT * diff --git a/dbt_subprojects/dex/models/sandwiches/dex_sandwiches.sql b/dbt_subprojects/dex/models/sandwiches/dex_sandwiches.sql index 83560830145..3feba11d293 100644 --- a/dbt_subprojects/dex/models/sandwiches/dex_sandwiches.sql +++ b/dbt_subprojects/dex/models/sandwiches/dex_sandwiches.sql @@ -7,7 +7,7 @@ file_format = 'delta', incremental_strategy = 'merge', unique_key = ['blockchain', 'tx_hash', 'project_contract_address', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "fantom", "polygon", "base", "celo", "zksync", "scroll", "zora"]\', + post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "fantom", "polygon", "base", "celo", "zksync", "scroll", "zora", "sei"]\', "sector", "dex", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , (ref('dex_zksync_sandwiches')) , (ref('dex_scroll_sandwiches')) , (ref('dex_zora_sandwiches')) + , (ref('dex_sei_sandwiches')) ] %} SELECT * diff --git a/dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiched.sql b/dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiched.sql new file mode 100644 index 00000000000..7eed2e5ee15 --- /dev/null +++ b/dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiched.sql @@ -0,0 +1,21 @@ +{% set blockchain = 'sei' %} + +{{ config( + schema = 'dex_' + blockchain, + alias = 'sandwiched', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['blockchain', 'tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +) +}} + +{{ + dex_sandwiched( + blockchain = blockchain + , transactions = source(blockchain,'transactions') + , sandwiches = ref('dex_' + blockchain + '_sandwiches') + ) +}} diff --git a/dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiches.sql b/dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiches.sql new file mode 100644 index 00000000000..5ff6da117e9 --- /dev/null +++ b/dbt_subprojects/dex/models/sandwiches/sei/dex_sei_sandwiches.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'sei' %} + +{{ config( + schema = 'dex_' + blockchain, + alias = 'sandwiches', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['blockchain','tx_hash', 'evt_index'] +) +}} + +{{ + dex_sandwiches( + blockchain = blockchain + , transactions = source(blockchain,'transactions') + ) +}} From b8f3dcfdf1520f779bcdc8b090c3a91f34aa726e Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 25 Nov 2024 08:24:39 -0800 Subject: [PATCH 18/68] zid selection update (#7178) --- .../models/_project/zeroex/zeroex_v2.sql | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql index 4589ba128b7..601061e71ba 100644 --- a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql +++ b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql @@ -1,15 +1,15 @@ {% macro zeroex_settler_txs_cte(blockchain, start_date) %} WITH tbl_addresses AS ( SELECT - token_id, - "to" AS settler_address, + varbinary_to_int256 (topic1) as token_id, + bytearray_substring(logs.topic3,13,20) as settler_address, block_time AS begin_block_time, block_number AS begin_block_number FROM - {{ source('nft', 'transfers') }} + {{ source( blockchain, 'logs') }} WHERE contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = '{{ blockchain }}' + and topic0 = 0xaa94c583a45742b26ac5274d230aea34ab334ed5722264aa5673010e612bc0b2 ), tbl_end_times AS ( @@ -38,7 +38,8 @@ settler_trace_data AS ( "to" AS contract_address, varbinary_substring(input,1,4) AS method_id, varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address + a.settler_address, + row_number() OVER (PARTITION BY tr.tx_hash ORDER BY trace_address) AS rn FROM {{ source(blockchain, 'traces') }} AS tr JOIN @@ -61,15 +62,14 @@ settler_txs AS ( method_id, contract_address, settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, + varbinary_substring(tracker,2,12) AS zid, CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + WHEN method_id = 0x1fff991f THEN varbinary_substring(tracker,14,3) + WHEN method_id = 0xfd3ad6d4 THEN varbinary_substring(tracker,13,3) END AS tag FROM settler_trace_data - GROUP BY - 1,2,3,4,5,6 + WHERE rn = 1 ) SELECT * FROM settler_txs @@ -171,30 +171,6 @@ prices AS ( {% endif %} ), -fills AS ( - WITH signatures AS ( - SELECT DISTINCT signature - FROM {{ source(blockchain, 'logs_decoded') }} l - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{start_date}}' - {% endif %} - ) - SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within - FROM {{ source(blockchain, 'logs') }} l - JOIN signatures ON signature = topic0 - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - {% if is_incremental() %} - WHERE {{ incremental_predicate('l.block_time') }} - {% else %} - WHERE l.block_time >= DATE '{{start_date}}' - {% endif %} - GROUP BY 1,2,3 -), - results AS ( SELECT '{{blockchain}}' AS blockchain, @@ -224,8 +200,7 @@ results AS ( maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS token_bought_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within + tag FROM tbl_trades trades JOIN @@ -235,8 +210,6 @@ results AS ( {% else %} AND tr.block_time >= DATE '{{start_date}}' {% endif %} - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number LEFT JOIN tokens tt ON tt.blockchain = '{{blockchain}}' AND tt.contract_address = taker_token LEFT JOIN @@ -296,4 +269,28 @@ order by block_time desc {% macro zeroex_v2_trades_indirect(blockchain, start_date) %} {{ zeroex_v2_trades(blockchain, start_date, false) }} +{% endmacro %} + +{% macro zeroex_v2_trades_fills_count(blockchain, start_date) %} + WITH signatures AS ( + SELECT DISTINCT signature + FROM {{ source(blockchain, 'logs_decoded') }} l + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{start_date}}' + {% endif %} + ) + SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within + FROM {{ source(blockchain, 'logs') }} l + JOIN signatures ON signature = topic0 + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + {% if is_incremental() %} + WHERE {{ incremental_predicate('l.block_time') }} + {% else %} + WHERE l.block_time >= DATE '{{start_date}}' + {% endif %} + GROUP BY 1,2,3 {% endmacro %} \ No newline at end of file From 538157ef4b0d35af35b739200611a47db3157826 Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 25 Nov 2024 08:26:10 -0800 Subject: [PATCH 19/68] zeroex - macro for v1 fills (#7161) * macro for v1 fills + eth model * add eth model * macro names * set blockchain * start_date in erc20bridgetranfser * start dates * univ3 date * sushi * uniV3 * blockchain * zeroex_v1_txs * remove table_name * comma * results_usd * replace old model * api_fills name * tbl_trade_details * revise zeroex_tx cte, add base model * true/false * revise zeroex_tx cte macro method * move table prefix to correct cte * Review v1 macro --------- Co-authored-by: Huang Geyang Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../_project/zeroex/zeroex_v1_api_fills.sql | 577 ++++++++++++++++++ .../zeroex/base/zeroex_base_api_fills.sql | 251 ++------ .../ethereum/zeroex_ethereum_api_fills.sql | 570 ++++------------- .../ethereum/zeroex_ethereum_schema.yml | 2 +- 4 files changed, 729 insertions(+), 671 deletions(-) create mode 100644 dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql new file mode 100644 index 00000000000..662d3bbd4cb --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql @@ -0,0 +1,577 @@ +{% macro zeroex_evt_fills_txs(blockchain,zeroex_v3_start_date) %} +{%- set table_prefix = 'zeroex_v3_' + blockchain -%} + +SELECT + v3.evt_tx_hash AS tx_hash, + CASE + WHEN takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc THEN takerAddress + ELSE NULL + END AS affiliate_address, + NULL AS is_gasless, + evt_block_time AS block_time +FROM {{ source(table_prefix, 'Exchange_evt_Fill') }} v3 +WHERE ( -- nuo + v3.takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc + OR -- contains a bridge order + ( + v3.feeRecipientAddress = 0x1000000000000000000000000000000000000011 + AND bytearray_substring(v3.makerAssetData, 1, 4) = 0xdc1600f3 + ) +) +{% if is_incremental() %} +AND {{ incremental_predicate('evt_block_time') }} +{% else %} +AND evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} +{% endmacro %} + + +{% macro zeroex_v1_txs(blockchain,zeroex_v3_start_date) %} +SELECT + tr.tx_hash, + CASE + WHEN bytearray_position(INPUT, 0x869584cd) <> 0 THEN + SUBSTRING(INPUT FROM (bytearray_position(INPUT, 0x869584cd) + 16) FOR 20) + WHEN bytearray_position(INPUT, 0xfbc019a7) <> 0 THEN + SUBSTRING(INPUT FROM (bytearray_position(INPUT, 0xfbc019a7) + 16) FOR 20) + END AS affiliate_address, + CASE + WHEN (varbinary_position(input, 0x3d8d4082) <> 0 OR varbinary_position(input, 0x4f948110) <> 0) + THEN 1 + END AS is_gasless, + block_time +FROM {{ source(blockchain, 'traces') }} tr +WHERE tr.to IN ( + 0x61935cbdd02287b511119ddb11aeb42f1593b7ef, -- exchange contract + 0x6958f5e95332d93d21af0d7b9ca85b8212fee0a5, -- forwarder address + 0x4aa817c6f383c8e8ae77301d18ce48efb16fd2be, -- forwarder address + 0x4ef40d1bf0983899892946830abf99eca2dbc5ce, -- forwarder address + 0xdef1c0ded9bec7f1a1670819833240f027b25eff -- exchange proxy +) +AND ( + bytearray_position(INPUT, 0x869584cd) <> 0 + OR bytearray_position(INPUT, 0xfbc019a7) <> 0 +) +{% if is_incremental() %} +AND {{ incremental_predicate('block_time') }} +{% else %} +AND block_time >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} +{% endmacro %} + + +{% macro v3_fills_no_bridge(blockchain,zeroex_v3_start_date) %} +{%- set table_prefix = 'zeroex_v3_' + blockchain -%} + +SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + evt_block_time AS block_time, + fills.makerAddress AS maker, + fills.takerAddress AS taker, + bytearray_substring(fills.takerAssetData, 17, 20) AS taker_token, + bytearray_substring(fills.makerAssetData, 17, 20) AS maker_token, + CAST(fills.takerAssetFilledAmount AS int256) AS taker_token_amount_raw, + CAST(fills.makerAssetFilledAmount AS int256) AS maker_token_amount_raw, + 'Fill' AS type, + COALESCE(zeroex_tx.affiliate_address, fills.feeRecipientAddress) AS affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + (fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed) AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'Exchange_evt_Fill') }} fills +INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash AND fills.evt_block_time = zeroex_tx.block_time +WHERE + -- Exclude bridge orders + (bytearray_substring(makerAssetData, 1, 4) <> 0xdc1600f3) + AND + ( + -- Include transactions with a matching tx_hash in zeroex_tx or specific feeRecipientAddress + zeroex_tx.tx_hash IS NOT NULL + OR fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed + ) + + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) + {% endif %} +{% endmacro %} + + +{% macro v4_rfq_fills_no_bridge(blockchain, zeroex_v4_start_date) %} +{%- set table_prefix = 'zeroex_' + blockchain -%} +SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + fills.evt_block_time AS block_time, + fills.maker, + fills.taker, + fills.takerToken AS taker_token, + fills.makerToken AS maker_token, + CAST(fills.takerTokenFilledAmount AS int256) AS taker_token_amount_raw, + CAST(fills.makerTokenFilledAmount AS int256) AS maker_token_amount_raw, + 'RfqOrderFilled' AS type, + zeroex_tx.affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'ExchangeProxy_evt_RfqOrderFilled') }} fills +LEFT JOIN zeroex_tx + ON zeroex_tx.tx_hash = fills.evt_tx_hash + AND fills.evt_block_time = zeroex_tx.block_time + +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% else %} +WHERE evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + + +{% macro v4_limit_fills_no_bridge(blockchain, zeroex_v4_start_date) %} +{%- set table_prefix = 'zeroex_' + blockchain -%} +SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + fills.evt_block_time AS block_time, + fills.maker, + fills.taker, + fills.takerToken AS taker_token, + fills.makerToken AS maker_token, + CAST(fills.takerTokenFilledAmount AS int256) AS taker_token_amount_raw, + CAST(fills.makerTokenFilledAmount AS int256) AS maker_token_amount_raw, + 'LimitOrderFilled' AS type, + COALESCE(zeroex_tx.affiliate_address, fills.feeRecipient) AS affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + (fills.feeRecipient IN ( + 0x9b858be6e3047d88820f439b240deac2418a2551, + 0x86003b044f70dac0abc80ac8957305b6370893ed, + 0x5bc2419a087666148bfbe1361ae6c06d240c6131 + )) AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'ExchangeProxy_evt_LimitOrderFilled') }} fills +LEFT JOIN zeroex_tx + ON zeroex_tx.tx_hash = fills.evt_tx_hash + AND fills.evt_block_time = zeroex_tx.block_time + +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% else %} +WHERE evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + +{% macro otc_fills(blockchain, zeroex_v4_start_date) %} +{%- set table_prefix = 'zeroex_' + blockchain -%} +SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + fills.evt_block_time AS block_time, + fills.maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + fills.takerToken AS taker_token, + fills.makerToken AS maker_token, + CAST(fills.takerTokenFilledAmount AS int256) AS taker_token_amount_raw, + CAST(fills.makerTokenFilledAmount AS int256) AS maker_token_amount_raw, + 'OtcOrderFilled' AS type, + zeroex_tx.affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'ExchangeProxy_evt_OtcOrderFilled') }} fills +LEFT JOIN zeroex_tx + ON zeroex_tx.tx_hash = fills.evt_tx_hash + AND fills.evt_block_time = zeroex_tx.block_time +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% else %} +WHERE evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + + +{% macro ERC20BridgeTransfer(blockchain, zeroex_v3_start_date) %} +SELECT + logs.tx_hash, + logs.index AS evt_index, + logs.contract_address, + logs.block_time, + bytearray_substring(data, 141, 20) AS maker, + bytearray_substring(data, 173, 20) AS taker, + bytearray_substring(data, 13, 20) AS taker_token, + bytearray_substring(data, 45, 20) AS maker_token, + bytearray_to_int256(bytearray_substring(data, 77, 20)) AS taker_token_amount_raw, + bytearray_to_int256(bytearray_substring(data, 109, 20)) AS maker_token_amount_raw, + 'ERC20BridgeTransfer' AS type, + zeroex_tx.affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(blockchain, 'logs') }} logs +JOIN zeroex_tx + ON zeroex_tx.tx_hash = logs.tx_hash + AND logs.block_time = zeroex_tx.block_time +WHERE topic0 = 0x349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9 + +{% if is_incremental() %} +AND {{ incremental_predicate('logs.block_time') }} +{% else %} +AND logs.block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + + +{% macro BridgeFill(blockchain, zeroex_v4_start_date) %} +SELECT + logs.tx_hash, + logs.index AS evt_index, + logs.contract_address, + logs.block_time, + bytearray_substring(data, 13, 20) AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + bytearray_substring(data, 45, 20) AS taker_token, + bytearray_substring(data, 77, 20) AS maker_token, + bytearray_to_int256(bytearray_substring(data, 109, 20)) AS taker_token_amount_raw, + bytearray_to_int256(bytearray_substring(data, 141, 20)) AS maker_token_amount_raw, + 'BridgeFill' AS type, + zeroex_tx.affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(blockchain, 'logs') }} logs +JOIN zeroex_tx + ON zeroex_tx.tx_hash = logs.tx_hash + AND logs.block_time = zeroex_tx.block_time +WHERE topic0 = 0xff3bc5e46464411f331d1b093e1587d2d1aa667f5618f98a95afc4132709d3a9 + AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 + +{% if is_incremental() %} +AND {{ incremental_predicate('logs.block_time') }} +{% else %} +AND logs.block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + +{% macro NewBridgeFill(blockchain, zeroex_v4_start_date) %} +SELECT + logs.tx_hash, + logs.index AS evt_index, + logs.contract_address, + logs.block_time, + bytearray_substring(data, 13, 20) AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + bytearray_substring(data, 45, 20) AS taker_token, + bytearray_substring(data, 77, 20) AS maker_token, + bytearray_to_int256(bytearray_substring(data, 109, 20)) AS taker_token_amount_raw, + bytearray_to_int256(bytearray_substring(data, 141, 20)) AS maker_token_amount_raw, + 'NewBridgeFill' AS type, + zeroex_tx.affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(blockchain, 'logs') }} logs +JOIN zeroex_tx + ON zeroex_tx.tx_hash = logs.tx_hash + AND logs.block_time = zeroex_tx.block_time +WHERE topic0 = 0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8 + AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 + +{% if is_incremental() %} +AND {{ incremental_predicate('logs.block_time') }} +{% else %} +AND logs.block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + +{% macro direct_PLP(blockchain, zeroex_v3_start_date) %} +{%- set table_prefix = 'zeroex_' + blockchain -%} +SELECT + plp.evt_tx_hash, + plp.evt_index AS evt_index, + plp.contract_address, + plp.evt_block_time AS block_time, + provider AS maker, + recipient AS taker, + inputToken AS taker_token, + outputToken AS maker_token, + CAST(inputTokenAmount AS int256) AS taker_token_amount_raw, + CAST(outputTokenAmount AS int256) AS maker_token_amount_raw, + 'LiquidityProviderSwap' AS type, + zeroex_tx.affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'ExchangeProxy_evt_LiquidityProviderSwap') }} plp +JOIN zeroex_tx + ON zeroex_tx.tx_hash = plp.evt_tx_hash + AND plp.evt_block_time = zeroex_tx.block_time + +{% if is_incremental() %} +WHERE {{ incremental_predicate('evt_block_time') }} +{% else %} +WHERE evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) +{% endif %} +{% endmacro %} + +{% macro direct_uniswapv2(blockchain, zeroex_v3_start_date) %} +{%- set table_prefix = 'uniswap_v2_' + blockchain -%} +SELECT + swap.evt_tx_hash AS tx_hash, + swap.evt_index, + swap.contract_address, + swap.evt_block_time AS block_time, + swap.contract_address AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + CASE + WHEN swap.amount0In > swap.amount0Out THEN pair.token0 + ELSE pair.token1 + END AS taker_token, + CASE + WHEN swap.amount0In > swap.amount0Out THEN pair.token1 + ELSE pair.token0 + END AS maker_token, + CASE + WHEN swap.amount0In > swap.amount0Out THEN + CASE + WHEN swap.amount0In >= swap.amount0Out THEN CAST(swap.amount0In - swap.amount0Out AS int256) + ELSE CAST(0 AS int256) + END + ELSE + CASE + WHEN swap.amount1In >= swap.amount1Out THEN CAST(swap.amount1In - swap.amount1Out AS int256) + ELSE CAST(0 AS int256) + END + END AS taker_token_amount_raw, + CASE + WHEN swap.amount0In > swap.amount0Out THEN + CASE + WHEN swap.amount1Out >= swap.amount1In THEN CAST(swap.amount1Out - swap.amount1In AS int256) + ELSE CAST(0 AS int256) + END + ELSE + CASE + WHEN swap.amount0Out >= swap.amount0In THEN CAST(swap.amount0Out - swap.amount0In AS int256) + ELSE CAST(0 AS int256) + END + END AS maker_token_amount_raw, + 'Uniswap V2 Direct' AS type, + zeroex_tx.affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'Pair_evt_Swap') }} swap +LEFT JOIN {{ source(table_prefix, 'Factory_evt_PairCreated') }} pair + ON pair.pair = swap.contract_address +JOIN zeroex_tx + ON zeroex_tx.tx_hash = swap.evt_tx_hash + AND swap.evt_block_time = zeroex_tx.block_time +WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff + {% if is_incremental() %} + AND {{ incremental_predicate('swap.evt_block_time') }} + {% else %} + AND swap.evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) + {% endif %} +{% endmacro %} + +{% macro direct_sushiswap(blockchain, zeroex_v3_start_date) %} +{%- set table_prefix = 'sushi_' + blockchain -%} +SELECT + swap.evt_tx_hash AS tx_hash, + swap.evt_index, + swap.contract_address, + swap.evt_block_time AS block_time, + swap.contract_address AS maker, + LAST_VALUE(swap.to) OVER (PARTITION BY swap.evt_tx_hash ORDER BY swap.evt_index) AS taker, + CASE + WHEN swap.amount0In > swap.amount0Out THEN pair.token0 + ELSE pair.token1 + END AS taker_token, + CASE + WHEN swap.amount0In > swap.amount0Out THEN pair.token1 + ELSE pair.token0 + END AS maker_token, + CASE + WHEN swap.amount0In > swap.amount0Out THEN + CASE + WHEN swap.amount0In >= swap.amount0Out THEN CAST(swap.amount0In - swap.amount0Out AS int256) + ELSE CAST(0 AS int256) + END + ELSE + CASE + WHEN swap.amount1In >= swap.amount1Out THEN CAST(swap.amount1In - swap.amount1Out AS int256) + ELSE CAST(0 AS int256) + END + END AS taker_token_amount_raw, + CASE + WHEN swap.amount0In > swap.amount0Out THEN + CASE + WHEN swap.amount1Out >= swap.amount1In THEN CAST(swap.amount1Out - swap.amount1In AS int256) + ELSE CAST(0 AS int256) + END + ELSE + CASE + WHEN swap.amount0Out >= swap.amount0In THEN CAST(swap.amount0Out - swap.amount0In AS int256) + ELSE CAST(0 AS int256) + END + END AS maker_token_amount_raw, + 'Sushiswap Direct' AS type, + zeroex_tx.affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless +FROM {{ source(table_prefix, 'Pair_evt_Swap') }} swap +LEFT JOIN {{ source(table_prefix, 'Factory_evt_PairCreated') }} pair + ON pair.pair = swap.contract_address +JOIN zeroex_tx + ON zeroex_tx.tx_hash = swap.evt_tx_hash + AND swap.evt_block_time = zeroex_tx.block_time +WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff + {% if is_incremental() %} + AND {{ incremental_predicate('swap.evt_block_time') }} + {% else %} + AND swap.evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) + {% endif %} +{% endmacro %} + + +{% macro direct_uniswapv3(blockchain,zeroex_v4_start_date) %} +{%- set table_prefix = 'uniswap_v3_' + blockchain -%} + SELECT + swap.evt_tx_hash AS tx_hash, + swap.evt_index, + swap.contract_address, + swap.evt_block_time AS block_time, + swap.contract_address AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + CASE + WHEN amount0 < CAST(0 AS int256) THEN pair.token1 + ELSE pair.token0 + END AS taker_token, + CASE + WHEN amount0 < CAST(0 AS int256) THEN pair.token0 + ELSE pair.token1 + END AS maker_token, + CASE + WHEN amount0 < CAST(0 AS int256) THEN ABS(swap.amount1) + ELSE ABS(swap.amount0) + END AS taker_token_amount_raw, + CASE + WHEN amount0 < CAST(0 AS int256) THEN ABS(swap.amount0) + ELSE ABS(swap.amount1) + END AS maker_token_amount_raw, + 'Uniswap V3 Direct' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source(table_prefix, 'Pair_evt_Swap') }} swap + LEFT JOIN {{ source(table_prefix, 'Factory_evt_PoolCreated') }} pair + ON pair.pool = swap.contract_address + JOIN zeroex_tx + ON zeroex_tx.tx_hash = swap.evt_tx_hash + AND swap.evt_block_time = zeroex_tx.block_time + WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff + {% if is_incremental() %} + AND {{ incremental_predicate('swap.evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND swap.evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) + {% endif %} +{% endmacro %} + +{% macro trade_details(blockchain, zeroex_v3_start_date) %} +WITH results AS ( + SELECT + all_tx.tx_hash, + tx.block_number, + all_tx.evt_index, + all_tx.contract_address, + all_tx.block_time, + CAST(DATE_TRUNC('day', all_tx.block_time) AS DATE) AS block_date, + CAST(DATE_TRUNC('month', all_tx.block_time) AS DATE) AS block_month, + maker, + CASE + WHEN is_gasless = 1 AND VARBINARY_POSITION(data, 0x3a46c4e1) <> 0 THEN VARBINARY_SUBSTRING(data, 81, 20) + WHEN is_gasless = 1 AND VARBINARY_POSITION(data, 0xa98fcbf1) <> 0 THEN VARBINARY_SUBSTRING(data, 81, 20) + WHEN is_gasless = 1 AND VARBINARY_POSITION(data, 0x3d8d4082) <> 0 THEN VARBINARY_SUBSTRING(data, 177, 20) + WHEN taker = 0xdef1c0ded9bec7f1a1670819833240f027b25eff THEN tx."from" + ELSE taker + END AS taker, + taker_token, + taker_token AS token_sold_address, + ts.symbol AS taker_symbol, + maker_token, + maker_token AS token_bought_address, + ms.symbol AS maker_symbol, + CASE + WHEN LOWER(ts.symbol) > LOWER(ms.symbol) THEN CONCAT(ms.symbol, '-', ts.symbol) + ELSE CONCAT(ts.symbol, '-', ms.symbol) + END AS token_pair, + taker_token_amount_raw / POW(10, tp.decimals) AS taker_token_amount, + taker_token_amount_raw / POW(10, tp.decimals) AS token_sold_amount, + CAST(taker_token_amount_raw AS UINT256) AS taker_token_amount_raw, + maker_token_amount_raw / POW(10, mp.decimals) AS maker_token_amount, + maker_token_amount_raw / POW(10, mp.decimals) AS token_bought_amount, + CAST(maker_token_amount_raw AS UINT256) AS maker_token_amount_raw, + all_tx.type, + MAX(affiliate_address) OVER (PARTITION BY all_tx.tx_hash) AS affiliate_address, + swap_flag, + matcha_limit_order_flag, + tx."from" AS tx_from, + tx.to AS tx_to, + '{{ blockchain }}' AS blockchain + FROM all_tx + INNER JOIN {{ source(blockchain, 'transactions') }} tx + ON all_tx.tx_hash = tx.hash AND all_tx.block_time = tx.block_time + {% if is_incremental() %} + AND {{ incremental_predicate('tx.block_time') }} + {% endif %} + {% if not is_incremental() %} + AND tx.block_time >= CAST('{{ zeroex_v3_start_date }}' AS DATE) + {% endif %} + LEFT JOIN {{ source('prices', 'usd') }} tp + ON DATE_TRUNC('minute', all_tx.block_time) = tp.minute + AND CASE + WHEN all_tx.taker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE all_tx.taker_token + END = tp.contract_address + AND tp.blockchain = '{{ blockchain }}' + {% if is_incremental() %} + AND {{ incremental_predicate('tp.minute') }} + {% endif %} + {% if not is_incremental() %} + AND tp.minute >= CAST('{{ zeroex_v3_start_date }}' AS DATE) + {% endif %} + LEFT JOIN {{ source('prices', 'usd') }} mp + ON DATE_TRUNC('minute', all_tx.block_time) = mp.minute + AND CASE + WHEN all_tx.maker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE all_tx.maker_token + END = mp.contract_address + AND mp.blockchain = '{{ blockchain }}' + {% if is_incremental() %} + AND {{ incremental_predicate('mp.minute') }} + {% endif %} + {% if not is_incremental() %} + AND mp.minute >= CAST('{{ zeroex_v3_start_date }}' AS DATE) + {% endif %} + LEFT JOIN {{ source('tokens', 'erc20') }} ts + ON ts.contract_address = taker_token AND ts.blockchain = '{{ blockchain }}' + LEFT JOIN {{ source('tokens', 'erc20') }} ms + ON ms.contract_address = maker_token AND ms.blockchain = '{{ blockchain }}' +), + +results_usd AS ( + {{ + add_amount_usd( + trades_cte = 'results' + ) + }} +) +select * from results_usd +{% endmacro %} diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql index fc3f6009fc9..c5c5d327ec1 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql @@ -19,228 +19,65 @@ {% set zeroex_v3_start_date = '2019-12-01' %} {% set zeroex_v4_start_date = '2021-01-06' %} - --- Test Query here: https://dune.com/queries/2834419 +{% set blockchain = 'base' %} WITH zeroex_tx AS ( - SELECT tx_hash, + SELECT tx_hash, + block_time as block_time, max(affiliate_address) as affiliate_address, - is_gasless + max(is_gasless) as is_gasless FROM ( - SELECT tr.tx_hash, - CASE - WHEN bytearray_position(INPUT, 0x869584cd ) <> 0 THEN SUBSTRING(INPUT - FROM (bytearray_position(INPUT, 0x869584cd) + 16) - FOR 20) - WHEN bytearray_position(INPUT, 0xfbc019a7) <> 0 THEN SUBSTRING(INPUT - FROM (bytearray_position(INPUT, 0xfbc019a7 ) + 16) - FOR 20) - END AS affiliate_address, - case when (varbinary_position(input,0x3d8d4082) <> 0 or varbinary_position(input,0x4f948110) <> 0 ) then 1 else 0 end as is_gasless - FROM {{ source('base', 'traces') }} tr - WHERE tr.to IN ( - -- exchange contract - 0xdef1c0ded9bec7f1a1670819833240f027b25eff, - -- forwarder addresses - 0x6958f5e95332d93d21af0d7b9ca85b8212fee0a5, - 0x4aa817c6f383c8e8ae77301d18ce48efb16fd2be, - 0x4ef40d1bf0983899892946830abf99eca2dbc5ce, - -- exchange proxy - 0xdef189deaef76e379df891899eb5a00a94cbc250 - ) - AND ( - bytearray_position(INPUT, 0x869584cd ) <> 0 - OR bytearray_position(INPUT, 0xfbc019a7 ) <> 0 - ) + {{ + zeroex_v1_txs( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date, + ) + }} - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% endif %} - {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} ) temp - group by tx_hash , is_gasless - + group by tx_hash, block_time ), - -ERC20BridgeTransfer AS ( - SELECT - logs.tx_hash, - logs.block_number AS block_number, - INDEX AS evt_index, - logs.contract_address, - block_time AS block_time, - bytearray_substring(DATA, 142, 20) AS maker, - bytearray_substring(DATA, 172, 20) AS taker, - bytearray_substring(DATA, 14, 20) AS taker_token, - bytearray_substring(DATA, 45, 20) AS maker_token, - bytearray_to_uint256(bytearray_substring(DATA, 77, 20)) AS taker_token_amount_raw, - bytearray_to_uint256(bytearray_substring(DATA, 110, 20)) AS maker_token_amount_raw, - 'ERC20BridgeTransfer' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('base', 'logs') }} logs - INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash - WHERE topic0 = 0x349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9 - - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% endif %} - {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} - +ERC20BridgeTransfer as ( + {{ + ERC20BridgeTransfer( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ), -BridgeFill AS ( - SELECT - logs.tx_hash, - logs.block_number AS block_number, - INDEX AS evt_index, - logs.contract_address, - block_time AS block_time, - bytearray_substring(DATA, 13, 20) AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - bytearray_substring(DATA, 45, 20) AS taker_token, - bytearray_substring(DATA, 77, 20) AS maker_token, - bytearray_to_uint256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, - bytearray_to_uint256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, - 'BridgeFill' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('base', 'logs') }} logs - INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash - WHERE topic0 = 0xff3bc5e46464411f331d1b093e1587d2d1aa667f5618f98a95afc4132709d3a9 - AND contract_address = 0xdb6f1920a889355780af7570773609bd8cb1f498 - - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% endif %} - {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} +BridgeFill as ( + {{ + BridgeFill( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), -NewBridgeFill AS ( - SELECT - logs.tx_hash as tx_hash, - logs.block_number AS block_number, - INDEX AS evt_index, - logs.contract_address, - block_time AS block_time, - bytearray_substring(DATA, 13, 20) AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - bytearray_substring(DATA, 45, 20) AS taker_token, - bytearray_substring(DATA, 77, 20) AS maker_token, - bytearray_to_uint256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, - bytearray_to_uint256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, - 'BridgeFill' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('base' ,'logs') }} logs - INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash - WHERE topic0 = 0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8 - AND contract_address = 0xdb6f1920a889355780af7570773609bd8cb1f498 - - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% endif %} - {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} +NewBridgeFill as ( + {{ + NewBridgeFill( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), - all_tx AS ( - SELECT * FROM ERC20BridgeTransfer - UNION ALL SELECT * + UNION ALL + SELECT * FROM BridgeFill UNION ALL SELECT * FROM NewBridgeFill - - +), +tbl_trade_details AS ( + {{ + trade_details( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ) - -SELECT - all_tx.tx_hash, - all_tx.block_number, - all_tx.evt_index, - all_tx.contract_address, - all_tx.block_time, - cast(date_trunc('day', all_tx.block_time) AS date) AS block_date, - cast(date_trunc('month', all_tx.block_time) AS date) AS block_month, - maker, - CASE - WHEN is_gasless = 1 then case when (varbinary_substring(data,177,19) ) = 0x00000000000000000000000000000000000000 then varbinary_substring(data,81,20) else (varbinary_substring(data,177,20) ) end - WHEN taker = 0xdef1c0ded9bec7f1a1670819833240f027b25eff THEN tx."from" - ELSE taker - END AS taker, -- fix the user masked by ProxyContract issue - taker_token, - ts.symbol AS taker_symbol, - maker_token, - ms.symbol AS maker_symbol, - CASE WHEN lower(ts.symbol) > lower(ms.symbol) THEN concat(ms.symbol, '-', ts.symbol) ELSE concat(ts.symbol, '-', ms.symbol) END AS token_pair, - taker_token_amount_raw / pow(10, tp.decimals) AS taker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw / pow(10, mp.decimals) AS maker_token_amount, - maker_token_amount_raw, - all_tx.type, - max(affiliate_address) over (partition by all_tx.tx_hash) as affiliate_address, - swap_flag, - matcha_limit_order_flag, - CASE WHEN maker_token IN (0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca,0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22,0xeb466342c4d449bc9f53a865d5cb90586f405215 ) - THEN (all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price - WHEN taker_token IN (0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca,0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22,0xeb466342c4d449bc9f53a865d5cb90586f405215,0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca ) - THEN (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price - ELSE COALESCE((all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price, (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price) - END AS volume_usd, - tx."from" AS tx_from, - tx.to AS tx_to, - 'base' AS blockchain -FROM all_tx -INNER JOIN {{ source('base', 'transactions')}} tx ON all_tx.tx_hash = tx.hash - -{% if is_incremental() %} -AND {{ incremental_predicate('tx.block_time') }} -{% endif %} -{% if not is_incremental() %} -AND tx.block_time >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} - -LEFT JOIN {{ source('prices', 'usd') }} tp ON date_trunc('minute', all_tx.block_time) = tp.minute -AND CASE - WHEN all_tx.taker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 - ELSE all_tx.taker_token - END = tp.contract_address -AND tp.blockchain = 'base' - -{% if is_incremental() %} -AND {{ incremental_predicate('tp.minute') }} -{% endif %} -{% if not is_incremental() %} -AND tp.minute >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} - -LEFT JOIN {{ source('prices', 'usd') }} mp ON DATE_TRUNC('minute', all_tx.block_time) = mp.minute -AND CASE - WHEN all_tx.maker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 - ELSE all_tx.maker_token - END = mp.contract_address -AND mp.blockchain = 'base' - -{% if is_incremental() %} -AND {{ incremental_predicate('mp.minute') }} -{% endif %} -{% if not is_incremental() %} -AND mp.minute >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} - -LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ts ON ts.contract_address = taker_token and ts.blockchain = 'base' -LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ms ON ms.contract_address = maker_token and ms.blockchain = 'base' \ No newline at end of file +select * from tbl_trade_details +order by block_time desc \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql index 814f58dca9c..459792679f8 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql @@ -13,405 +13,121 @@ {% set zeroex_v3_start_date = '2019-12-01' %} {% set zeroex_v4_start_date = '2021-01-06' %} +{% set blockchain = 'ethereum' %} --- Test Query here: https://dune.com/queries/1330551 WITH zeroex_tx AS ( - SELECT tx_hash, - block_time as block_time, + SELECT tx_hash, + block_time as block_time, max(affiliate_address) as affiliate_address, - max(is_gasless) as is_gasless - FROM ( - - SELECT v3.evt_tx_hash AS tx_hash, - CASE - WHEN takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc THEN takerAddress - ELSE NULL - END AS affiliate_address, - null as is_gasless, - evt_block_time as block_time - - FROM {{ source('zeroex_v3_ethereum', 'Exchange_evt_Fill') }} v3 - WHERE ( -- nuo - v3.takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc - OR -- contains a bridge order - ( - v3.feeRecipientAddress = 0x1000000000000000000000000000000000000011 - AND bytearray_substring(v3.makerAssetData, 1, 4) = 0xdc1600f3 - ) - ) + max(is_gasless) as is_gasless - {% if is_incremental() %} - AND {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} - - UNION ALL - SELECT tr.tx_hash, - CASE - WHEN bytearray_position(INPUT, 0x869584cd ) <> 0 THEN SUBSTRING(INPUT - FROM (bytearray_position(INPUT, 0x869584cd) + 16) - FOR 20) - WHEN bytearray_position(INPUT, 0xfbc019a7) <> 0 THEN SUBSTRING(INPUT - FROM (bytearray_position(INPUT, 0xfbc019a7 ) + 16) - FOR 20) - END AS affiliate_address, - case when (varbinary_position(input,0x3d8d4082) <> 0 or varbinary_position(input,0x4f948110) <> 0 ) then 1 end as is_gasless, - block_time - FROM {{ source('ethereum', 'traces') }} tr - WHERE tr.to IN ( - -- exchange contract - 0x61935cbdd02287b511119ddb11aeb42f1593b7ef, - -- forwarder addresses - 0x6958f5e95332d93d21af0d7b9ca85b8212fee0a5, - 0x4aa817c6f383c8e8ae77301d18ce48efb16fd2be, - 0x4ef40d1bf0983899892946830abf99eca2dbc5ce, - -- exchange proxy - 0xdef1c0ded9bec7f1a1670819833240f027b25eff - ) - AND ( - bytearray_position(INPUT, 0x869584cd ) <> 0 - OR bytearray_position(INPUT, 0xfbc019a7 ) <> 0 - ) + FROM ( + {{ + zeroex_evt_fills_txs( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date, + ) + }} + + union + + {{ + zeroex_v1_txs( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date, + ) + }} - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% endif %} - {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} ) temp group by tx_hash, block_time - ), -v3_fills_no_bridge AS ( - SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - evt_block_time AS block_time, - fills.makerAddress AS maker, - fills.takerAddress AS taker, - bytearray_substring(fills.takerAssetData, 17, 20) AS taker_token, - bytearray_substring(fills.makerAssetData, 17, 20) AS maker_token, - cast(fills.takerAssetFilledAmount as int256) AS taker_token_amount_raw, - cast(fills.makerAssetFilledAmount as int256)AS maker_token_amount_raw, - 'Fill' AS type, - COALESCE(zeroex_tx.affiliate_address, fills.feeRecipientAddress) AS affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - (fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed) AS matcha_limit_order_flag, - is_gasless - FROM {{ source('zeroex_v3_ethereum', 'Exchange_evt_Fill') }} fills - INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time - WHERE (bytearray_substring(makerAssetData, 1, 4) <> 0xdc1600f3) - AND (zeroex_tx.tx_hash IS NOT NULL - OR fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed) - - {% if is_incremental() %} - AND {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} - +v3_fills_no_bridge as ( + {{ + v3_fills_no_bridge( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ), -v4_rfq_fills_no_bridge AS ( - SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - fills.evt_block_time AS block_time, - fills.maker AS maker, - fills.taker AS taker, - fills.takerToken AS taker_token, - fills.makerToken AS maker_token, - cast(fills.takerTokenFilledAmount as int256) AS taker_token_amount_raw, - cast(fills.makerTokenFilledAmount as int256) AS maker_token_amount_raw, - 'RfqOrderFilled' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_RfqOrderFilled') }} fills - LEFT JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time - - {% if is_incremental() %} - WHERE {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - WHERE evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} +v4_rfq_fills_no_bridge as ( + {{ + v4_rfq_fills_no_bridge( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), -v4_limit_fills_no_bridge AS ( - SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - fills.evt_block_time AS block_time, - fills.maker AS maker, - fills.taker AS taker, - fills.takerToken AS taker_token, - fills.makerToken AS maker_token, - cast(fills.takerTokenFilledAmount as int256) AS taker_token_amount_raw, - cast(fills.makerTokenFilledAmount as int256) AS maker_token_amount_raw, - 'LimitOrderFilled' AS type, - COALESCE(zeroex_tx.affiliate_address, fills.feeRecipient) AS affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - (fills.feeRecipient in - (0x9b858be6e3047d88820f439b240deac2418a2551,0x86003b044f70dac0abc80ac8957305b6370893ed,0x5bc2419a087666148bfbe1361ae6c06d240c6131)) - AS matcha_limit_order_flag, - is_gasless - FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_LimitOrderFilled') }} fills - LEFT JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time - - {% if is_incremental() %} - WHERE {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - WHERE evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} +v4_limit_fills_no_bridge as ( + {{ + v4_limit_fills_no_bridge( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), -otc_fills AS ( - SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - fills.evt_block_time AS block_time, - fills.maker AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - fills.takerToken AS taker_token, - fills.makerToken AS maker_token, - cast(fills.takerTokenFilledAmount as int256) AS taker_token_amount_raw, - cast(fills.makerTokenFilledAmount as int256) AS maker_token_amount_raw, - 'OtcOrderFilled' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_OtcOrderFilled') }} fills - LEFT JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time - - {% if is_incremental() %} - WHERE {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - WHERE evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} - +otc_fills as ( + {{ + otc_fills( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), -ERC20BridgeTransfer AS ( - SELECT - logs.tx_hash, - INDEX AS evt_index, - logs.contract_address, - logs.block_time AS block_time, - bytearray_substring(DATA, 141, 20) AS maker, - bytearray_substring(DATA, 173, 20) AS taker, - bytearray_substring(DATA, 13, 20) AS taker_token, - bytearray_substring(DATA, 45, 20) AS maker_token, - bytearray_to_int256(bytearray_substring(DATA, 77, 20)) AS taker_token_amount_raw, - bytearray_to_int256(bytearray_substring(DATA, 109, 20)) AS maker_token_amount_raw, - 'ERC20BridgeTransfer' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('ethereum', 'logs') }} logs - JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash and logs.block_time = zeroex_tx.block_time - WHERE topic0 = 0x349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9 - - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% endif %} - {% if not is_incremental() %} - AND logs.block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} - +ERC20BridgeTransfer as ( + {{ + ERC20BridgeTransfer( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ), -BridgeFill AS ( - SELECT - logs.tx_hash, - INDEX AS evt_index, - logs.contract_address, - logs.block_time AS block_time, - bytearray_substring(DATA, 13, 20) AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - bytearray_substring(DATA, 45, 20) AS taker_token, - bytearray_substring(DATA, 77, 20) AS maker_token, - bytearray_to_int256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, - bytearray_to_int256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, - 'BridgeFill' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('ethereum', 'logs') }} logs - JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash and logs.block_time = zeroex_tx.block_time - WHERE topic0 = 0xff3bc5e46464411f331d1b093e1587d2d1aa667f5618f98a95afc4132709d3a9 - AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 - - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% endif %} - {% if not is_incremental() %} - AND logs.block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} +BridgeFill as ( + {{ + BridgeFill( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), -NewBridgeFill AS ( - SELECT - logs.tx_hash, - INDEX AS evt_index, - logs.contract_address, - logs.block_time AS block_time, - bytearray_substring(DATA, 13, 20) AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - bytearray_substring(DATA, 45, 20) AS taker_token, - bytearray_substring(DATA, 77, 20) AS maker_token, - bytearray_to_int256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, - bytearray_to_int256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, - 'NewBridgeFill' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('ethereum' ,'logs') }} logs - JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash and logs.block_time = zeroex_tx.block_time - WHERE topic0 = 0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8 - AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 - - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% endif %} - {% if not is_incremental() %} - AND logs.block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} +NewBridgeFill as ( + {{ + NewBridgeFill( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), -direct_PLP AS ( - SELECT - plp.evt_tx_hash, - plp.evt_index AS evt_index, - plp.contract_address, - plp.evt_block_time AS block_time, - provider AS maker, - recipient AS taker, - inputToken AS taker_token, - outputToken AS maker_token, - cast(inputTokenAmount as int256) AS taker_token_amount_raw, - cast(outputTokenAmount as int256)AS maker_token_amount_raw, - 'LiquidityProviderSwap' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_LiquidityProviderSwap') }} plp - JOIN zeroex_tx ON zeroex_tx.tx_hash = plp.evt_tx_hash and plp.evt_block_time = zeroex_tx.block_time - - {% if is_incremental() %} - WHERE {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - WHERE evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} - +direct_PLP as ( + {{ + direct_PLP( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ), -direct_uniswapv2 AS ( - SELECT - swap.evt_tx_hash AS tx_hash, - swap.evt_index, - swap.contract_address, - swap.evt_block_time AS block_time, - swap.contract_address AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff as taker, - CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token0 ELSE pair.token1 END AS taker_token, - CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token1 ELSE pair.token0 END AS maker_token, - CASE WHEN swap.amount0In > swap.amount0Out THEN - CASE WHEN swap.amount0In >= swap.amount0Out THEN cast(swap.amount0In - swap.amount0Out as int256) ELSE cast(0 as int256) END ELSE - CASE WHEN swap.amount1In >= swap.amount1Out THEN cast(swap.amount1In - swap.amount1Out as int256) ELSE cast(0 as int256) END END AS taker_token_amount_raw, - CASE WHEN swap.amount0In > swap.amount0Out THEN - CASE WHEN swap.amount1Out >= swap.amount1In THEN cast(swap.amount1Out - swap.amount1In as int256) ELSE cast(0 as int256) END ELSE - CASE WHEN swap.amount0Out >= swap.amount0In THEN cast(swap.amount0Out - swap.amount0In as int256) ELSE cast(0 as int256) END END AS maker_token_amount_raw, - 'Uniswap V2 Direct' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('uniswap_v2_ethereum', 'Pair_evt_Swap') }} swap - LEFT JOIN {{ source('uniswap_v2_ethereum', 'Factory_evt_PairCreated') }} pair ON pair.pair = swap.contract_address - JOIN zeroex_tx ON zeroex_tx.tx_hash = swap.evt_tx_hash and swap.evt_block_time = zeroex_tx.block_time - WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff - - {% if is_incremental() %} - AND {{ incremental_predicate('swap.evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND swap.evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} - +direct_uniswapv2 as ( + {{ + direct_uniswapv2( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ), -direct_sushiswap AS ( - SELECT - swap.evt_tx_hash AS tx_hash, - swap.evt_index, - swap.contract_address, - swap.evt_block_time AS block_time, - swap.contract_address AS maker, - LAST_VALUE(swap.to) OVER (PARTITION BY swap.evt_tx_hash ORDER BY swap.evt_index) AS taker, - CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token0 ELSE pair.token1 END AS taker_token, - CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token1 ELSE pair.token0 END AS maker_token, - CASE WHEN swap.amount0In > swap.amount0Out THEN - CASE WHEN swap.amount0In >= swap.amount0Out THEN cast(swap.amount0In - swap.amount0Out as int256) ELSE cast(0 as int256) END ELSE - CASE WHEN swap.amount1In >= swap.amount1Out THEN cast(swap.amount1In - swap.amount1Out as int256) ELSE cast(0 as int256) END END AS taker_token_amount_raw, - CASE WHEN swap.amount0In > swap.amount0Out THEN - CASE WHEN swap.amount1Out >= swap.amount1In THEN cast(swap.amount1Out - swap.amount1In as int256) ELSE cast(0 as int256) END ELSE - CASE WHEN swap.amount0Out >= swap.amount0In THEN cast(swap.amount0Out - swap.amount0In as int256) ELSE cast(0 as int256) END END AS maker_token_amount_raw, - - 'Sushiswap Direct' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('sushi_ethereum', 'Pair_evt_Swap') }} swap - LEFT JOIN {{ source('sushi_ethereum', 'Factory_evt_PairCreated') }} pair ON pair.pair = swap.contract_address - JOIN zeroex_tx ON zeroex_tx.tx_hash = swap.evt_tx_hash and swap.evt_block_time = zeroex_tx.block_time - WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff - - {% if is_incremental() %} - AND {{ incremental_predicate('swap.evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND swap.evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} +direct_sushiswap as ( + {{ + direct_sushiswap( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ), -direct_uniswapv3 AS ( - SELECT - swap.evt_tx_hash AS tx_hash, - swap.evt_index, - swap.contract_address, - swap.evt_block_time AS block_time, - swap.contract_address AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff as taker, - CASE WHEN amount0 < cast(0 as int256) THEN pair.token1 ELSE pair.token0 END AS taker_token, - CASE WHEN amount0 < cast(0 as int256) THEN pair.token0 ELSE pair.token1 END AS maker_token, - CASE WHEN amount0 < cast(0 as int256) THEN ABS(swap.amount1) ELSE ABS(swap.amount0) END AS taker_token_amount_raw, - CASE WHEN amount0 < cast(0 as int256) THEN ABS(swap.amount0) ELSE ABS(swap.amount1) END AS maker_token_amount_raw, - 'Uniswap V3 Direct' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source('uniswap_v3_ethereum', 'Pair_evt_Swap') }} swap - LEFT JOIN {{ source('uniswap_v3_ethereum', 'Factory_evt_PoolCreated') }} pair ON pair.pool = swap.contract_address - JOIN zeroex_tx ON zeroex_tx.tx_hash = swap.evt_tx_hash and swap.evt_block_time = zeroex_tx.block_time - WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff - - {% if is_incremental() %} - AND {{ incremental_predicate('swap.evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND swap.evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) - {% endif %} - +direct_uniswapv3 as ( + {{ + direct_uniswapv3( + blockchain = blockchain, + zeroex_v4_start_date = zeroex_v4_start_date + ) + }} ), all_tx AS ( SELECT * @@ -436,86 +152,14 @@ all_tx AS ( FROM v4_limit_fills_no_bridge UNION ALL SELECT * FROM otc_fills +), +tbl_trade_details AS ( + {{ + trade_details( + blockchain = blockchain, + zeroex_v3_start_date = zeroex_v3_start_date + ) + }} ) - -SELECT - all_tx.tx_hash, - tx.block_number, - all_tx.evt_index, - all_tx.contract_address, - all_tx.block_time, - cast(date_trunc('day', all_tx.block_time) AS date) AS block_date, - cast(date_trunc('month', all_tx.block_time) AS date) AS block_month, - maker, - CASE - when is_gasless = 1 and varbinary_position (data, 0x3a46c4e1) <> 0 then varbinary_substring(data,81,20) - when is_gasless = 1 and varbinary_position (data, 0xa98fcbf1) <> 0 then varbinary_substring(data,81,20) - when is_gasless = 1 and varbinary_position (data, 0x3d8d4082) <> 0 then varbinary_substring(data,177,20) - - WHEN taker = 0xdef1c0ded9bec7f1a1670819833240f027b25eff THEN tx."from" - ELSE taker - END AS taker, -- fix the user masked by ProxyContract issue - taker_token, - ts.symbol AS taker_symbol, - maker_token, - ms.symbol AS maker_symbol, - CASE WHEN lower(ts.symbol) > lower(ms.symbol) THEN concat(ms.symbol, '-', ts.symbol) ELSE concat(ts.symbol, '-', ms.symbol) END AS token_pair, - taker_token_amount_raw / pow(10, tp.decimals) AS taker_token_amount, - cast(taker_token_amount_raw as uint256) as taker_token_amount_raw, - maker_token_amount_raw / pow(10, mp.decimals) AS maker_token_amount, - cast(maker_token_amount_raw as uint256) as maker_token_amount_raw, - all_tx.type, - max(affiliate_address) over (partition by all_tx.tx_hash) as affiliate_address, - swap_flag, - matcha_limit_order_flag, - CASE WHEN maker_token IN (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xdac17f958d2ee523a2206206994597c13d831ec7, - 0x4fabb145d64652a948d72533023f6e7a623c7c53,0x6b175474e89094c44da98b954eedeac495271d0f,0xae7ab96520de3a18e5e111b5eaab095312d7fe84) AND mp.price IS NOT NULL - THEN (all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price - WHEN taker_token IN (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xdac17f958d2ee523a2206206994597c13d831ec7, - 0x4fabb145d64652a948d72533023f6e7a623c7c53,0x6b175474e89094c44da98b954eedeac495271d0f,0xae7ab96520de3a18e5e111b5eaab095312d7fe84) AND tp.price IS NOT NULL - THEN (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price - ELSE COALESCE((all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price, (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price) - END AS volume_usd, - tx."from" AS tx_from, - tx.to AS tx_to, - 'ethereum' AS blockchain -FROM all_tx -INNER JOIN {{ source('ethereum', 'transactions')}} tx ON all_tx.tx_hash = tx.hash and all_tx.block_time = tx.block_time - -{% if is_incremental() %} -AND {{ incremental_predicate('tx.block_time') }} -{% endif %} -{% if not is_incremental() %} -AND tx.block_time >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} - -LEFT JOIN {{ source('prices', 'usd') }} tp ON date_trunc('minute', all_tx.block_time) = tp.minute -AND CASE - WHEN all_tx.taker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 - ELSE all_tx.taker_token - END = tp.contract_address -AND tp.blockchain = 'ethereum' - -{% if is_incremental() %} -AND {{ incremental_predicate('tp.minute') }} -{% endif %} -{% if not is_incremental() %} -AND tp.minute >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} - -LEFT JOIN {{ source('prices', 'usd') }} mp ON DATE_TRUNC('minute', all_tx.block_time) = mp.minute -AND CASE - WHEN all_tx.maker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 - ELSE all_tx.maker_token - END = mp.contract_address -AND mp.blockchain = 'ethereum' - -{% if is_incremental() %} -AND {{ incremental_predicate('mp.minute') }} -{% endif %} -{% if not is_incremental() %} -AND mp.minute >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} - -LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ts ON ts.contract_address = taker_token and ts.blockchain = 'ethereum' -LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ms ON ms.contract_address = maker_token and ms.blockchain = 'ethereum' +select * from tbl_trade_details +order by block_time desc \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml index 1337fcc8435..161329dd166 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml @@ -5,7 +5,7 @@ models: meta: blockchain: ethereum project: zeroex - contributors: danning.sui, bakabhai993, hosuke + contributors: danning.sui, bakabhai993, hosuke, rantum config: tags: ['ethereum','0x','dex_aggregator','dex','aggregator'] description: > From cf705ffdde195b446c2097bb75e2ce3ed9da09dc Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 25 Nov 2024 08:27:25 -0800 Subject: [PATCH 20/68] zeroex - v2 macro model replacements (#7166) * update settler address cte in macro, add arb, avax * + add avax * replace old models in cross-chain model * update macro * update models * fix join * update blast model * add files * update/replace mantle model --------- Co-authored-by: Huang Geyang Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../arbitrum/zeroex_arbitrum_schema.yml | 4 +- .../zeroex_arbitrum_settler_trades.sql | 310 ------------------ .../arbitrum/zeroex_v2_arbitrum_trades.sql | 71 ++++ .../avalanche_c/zeroex_avalanche_c_schema.yml | 4 +- .../zeroex_avalanche_c_settler_trades.sql | 310 ------------------ .../zeroex_v2_avalanche_c_trades.sql | 70 ++++ .../zeroex/base/zeroex_v2_base_trades.sql | 13 +- .../zeroex/blast/zeroex_blast_schema.yml | 4 +- .../blast/zeroex_blast_settler_trades.sql | 301 ----------------- .../zeroex/blast/zeroex_v2_blast_trades.sql | 71 ++++ .../ethereum/zeroex_v2_ethereum_trades.sql | 13 +- .../zeroex/mantle/zeroex_mantle_schema.yml | 4 +- .../mantle/zeroex_mantle_settler_trades.sql | 296 ----------------- .../zeroex/mantle/zeroex_v2_mantle_trades.sql | 71 ++++ .../polygon/zeroex_v2_polygon_trades.sql | 13 +- .../zeroex/zeroex_api_fills_deduped.sql | 8 +- 16 files changed, 328 insertions(+), 1235 deletions(-) delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml index 3498e9df2ef..3ca18250dcb 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml @@ -206,7 +206,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_arbitrum_settler_trades + - name: zeroex_v2_arbitrum_trades meta: blockchain: arbitrum project: zeroex @@ -214,7 +214,7 @@ models: config: tags: ['arbitrum','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql deleted file mode 100644 index 815021d5009..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql +++ /dev/null @@ -1,310 +0,0 @@ -{{ config( - schema = 'zeroex_arbitrum', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'arbitrum' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('arbitrum', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'arbitrum' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address is not null or tr.to in (0x0000000000001fF3684f28c67538d4D072C22734)) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - then 1 end as valid, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('arbitrum', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash - AND logs.block_time = st.block_time - AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = bytearray_substring(logs.topic1,13,20) - or logs.tx_from = bytearray_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'arbitrum' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'arbitrum' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('arbitrum', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellarbitrumToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('arbitrum', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('arbitrum', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'arbitrum' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'arbitrum' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'arbitrum' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'arbitrum' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'arbitrum' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, - 0xaf88d065e77c8cc2239327c5edb3a432268e5831, - 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, - 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, - 0x912ce59144191c1204e64559fe8253a0e49e6548) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, - 0xaf88d065e77c8cc2239327c5edb3a432268e5831, - 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, - 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, - 0x912ce59144191c1204e64559fe8253a0e49e6548) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql new file mode 100644 index 00000000000..95cd5eec698 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_arbitrum', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'arbitrum' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml index 48deac58eea..98b01576297 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml @@ -150,7 +150,7 @@ models: name: fills_within description: "fills in then multihop, if present" - - name: zeroex_avalanche_c_settler_trades + - name: zeroex_v2_avalanche_c_trades meta: blockchain: avalanche_c project: zeroex @@ -158,7 +158,7 @@ models: config: tags: ['avalanche_c','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql deleted file mode 100644 index 4434aa4ad0c..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql +++ /dev/null @@ -1,310 +0,0 @@ -{{ config( - schema = 'zeroex_avalanche_c', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'avalanche_c' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('avalanche_c', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'avalanche_c' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000005E88410CcDFaDe4a5EfaE4b49562 ) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - then 1 end as valid, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('avalanche_c', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash - AND logs.block_time = st.block_time - AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = bytearray_substring(logs.topic1,13,20) - or logs.tx_from = bytearray_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by valid, index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'avalanche_c' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'avalanche_c' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('avalanche_c', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'Sellavalanche_cToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('avalanche_c', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('avalanche_c', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'avalanche_c' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'avalanche_c' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'avalanche_c' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'avalanche_c' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'avalanche_c' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, - 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, - 0x152b9d0fdc40c096757f570a51e494bd4b943e50, - 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, - 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, - 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, - 0x152b9d0fdc40c096757f570a51e494bd4b943e50, - 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, - 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql new file mode 100644 index 00000000000..a24523639a1 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql @@ -0,0 +1,70 @@ +{{ config( + schema = 'zeroex_v2_avalanche_c', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'avalanche_c' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql index d69c3174508..2dc75f30a85 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql @@ -46,6 +46,14 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), trade_details as ( {{ zeroex_v2_trades_detail( @@ -57,5 +65,6 @@ trade_details as ( ) select - * - from trade_details + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml index 598e21561d9..4361c49a24b 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_blast_settler_trades + - name: zeroex_v2_blast_trades meta: blockchain: blast project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['blast','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql deleted file mode 100644 index 9fe304e77ba..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql +++ /dev/null @@ -1,301 +0,0 @@ -{{ config( - schema = 'zeroex_blast', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'blast' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('blast', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'blast' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('blast', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = varbinary_substring(logs.topic1,13,20) - or logs.tx_from = varbinary_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where maker_token != taker_token - ) - select * from tbl_valid_logs - where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'blast' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'blast' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('blast', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellblastToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('blast', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('blast', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'blast' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'blast' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'blast' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'blast' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'blast' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql new file mode 100644 index 00000000000..c382761f69d --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_blast', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'blast' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql index ceea2b3d384..256d8476c7d 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql @@ -46,6 +46,14 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), trade_details as ( {{ zeroex_v2_trades_detail( @@ -57,5 +65,6 @@ trade_details as ( ) select - * - from trade_details + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml index bbbabcb2e22..418999bf150 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_mantle_settler_trades + - name: zeroex_v2_mantle_trades meta: blockchain: mantle project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['mantle','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql deleted file mode 100644 index 35bd8dc974e..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql +++ /dev/null @@ -1,296 +0,0 @@ -{{ config( - schema = 'zeroex_mantle', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'mantle' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('mantle', 'traces') }} AS tr - JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'mantle' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0xca11bde05977b3631167028862be2a173976ca11) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('mantle', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number - - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where maker_token != taker_token - ) - select * from tbl_valid_logs - where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'mantle' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'mantle' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('mantle', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellmantleToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('mantle', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('mantle', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'mantle' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'mantle' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'mantle' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'mantle' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'mantle' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql new file mode 100644 index 00000000000..88ba80757a3 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_mantle', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'mantle' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql index 1177284b18a..6c45e4fbcff 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql @@ -46,6 +46,14 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), trade_details as ( {{ zeroex_v2_trades_detail( @@ -57,5 +65,6 @@ trade_details as ( ) select - * - from trade_details + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 51563852cb7..6206697d4ed 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -27,12 +27,12 @@ ,ref('zeroex_v2_polygon_trades') ,ref('zeroex_optimism_settler_trades') ,ref('zeroex_bnb_settler_trades') - ,ref('zeroex_avalanche_c_settler_trades') - ,ref('zeroex_arbitrum_settler_trades') + ,ref('zeroex_v2_avalanche_c_trades') + ,ref('zeroex_v2_arbitrum_trades') ,ref('zeroex_scroll_settler_trades') ,ref('zeroex_linea_settler_trades') - ,ref('zeroex_blast_settler_trades') - ,ref('zeroex_mantle_settler_trades') + ,ref('zeroex_v2_blast_trades') + ,ref('zeroex_v2_mantle_trades') ] %} From b8baac055615213f8da4e50019e81126d661689a Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 25 Nov 2024 08:30:09 -0800 Subject: [PATCH 21/68] add zeroex_v2_mode trades (#7167) * add seed * add files * upset settler_address cte in macro * add mode to cross-chain * update schema * v2_mode_trades * fix fills_count_ cte * update macro for fills_within on mode * trade_details name, update eth + polygon * fills_within * update eth model for fills_within cte --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../zeroex/mode/zeroex_mode_schema.yml | 111 ++++++++++++++++++ .../zeroex/mode/zeroex_v2_mode_trades.sql | 61 ++++++++++ .../zeroex/zeroex_api_fills_deduped.sql | 3 +- .../models/_projects/zeroex/zeroex_schema.yml | 2 +- .../seeds/_project/zeroex/mode/_schema.yml | 11 ++ .../mode/zeroex_v2_mode_trades_sample.csv | 4 + 6 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql create mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml create mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml new file mode 100644 index 00000000000..080d07968bf --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml @@ -0,0 +1,111 @@ +version: 2 + +models: + - name: zeroex_v2_mode_trades + meta: + blockchain: mode + project: zeroex + contributors: rantum + config: + tags: ['mode','0x','dex_aggregator','dex','aggregator'] + description: > + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_month + - block_date + - tx_hash + - evt_index + - check_seed: + seed_file: ref('zeroex_v2_mode_trades_sample') + match_columns: + - tx_hash + check_columns: + - taker + - maker_token + - taker_token + columns: + - &blockchain + name: blockchain + description: "Blockchain which the aggregator project is deployed" + - &block_date + name: block_date + description: "UTC event block date of each trade" + - &block_month + name: block_month + description: "UTC event block month of each trade" + - &block_time + name: block_time + description: "UTC event block time of each trade" + - &taker_symbol + name: taker_symbol + description: "Symbol of the token taker sells" + - &maker_symbol + name: maker_symbol + description: "Symbol of the token taker buys" + - &token_pair + name: token_pair + description: "Token pair traded" + - &taker_token_amount + name: taker_token_amount + description: "The after-decimal amount of the token taker sells" + - &taker_token_amount_raw + name: taker_token_amount_raw + description: "The raw amount of the token taker sells" + - &maker_token_amount + name: maker_token_amount + description: "The after-decimal amount of the token taker buys" + - &maker_token_amount_raw + name: maker_token_amount_raw + description: "The raw amount of the token taker buys" + - &volume_usd + name: volume_usd + description: "Trading volume measured in USD value" + - &taker_token + name: taker_token + description: "Contract address of the token taker sells" + - &maker_token + name: maker_token + description: "Contract address of the token taker buys" + - &maker + name: maker + description: "buyer of the trade" + - &taker + name: taker + description: "seller of the trade" + - &affiliate_address + name: affiliate_address + description: "The recipient address of the affiliate, or the applications that is using 0x API, for receiving affiliate fee" + - &tx_hash + name: tx_hash + description: "Transaction hash of the fill" + - &tx_from + name: tx_from + description: "Address which initiated the trade" + - &tx_to + name: tx_to + description: "Address which received the trade" + - &evt_index + name: evt_index + description: "Index of the corresponding order filled event" + - &type + name: type + description: "The liquidity route the order went thru" + - &swap_flag + name: swap_flag + description: "If the swap was filled/consumed thru 0x API" + - &contract_address + name: contract_address + desctiption: "The address of the contract which fired the fill/swap event" + - &fills_within + name: fills_within + description: "fills in then multihop, if present" + + + + + + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql new file mode 100644 index 00000000000..03a74e6e745 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql @@ -0,0 +1,61 @@ +{{ config( + schema = 'zeroex_v2_mode', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'mode' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 6206697d4ed..07f52a7d2f9 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -1,7 +1,7 @@ {{ config( schema = 'zeroex' , alias = 'api_fills_deduped' - , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle"]\', + , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle","mode"]\', "project", "zeroex", \'["rantum","bakabhai993"]\') }}' @@ -31,6 +31,7 @@ ,ref('zeroex_v2_arbitrum_trades') ,ref('zeroex_scroll_settler_trades') ,ref('zeroex_linea_settler_trades') + ,ref('zeroex_v2_mode_trades') ,ref('zeroex_v2_blast_trades') ,ref('zeroex_v2_mantle_trades') ] %} diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml index c18ff3eb4d2..7cab763d18a 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml @@ -105,7 +105,7 @@ models: - name: zeroex_api_fills_deduped meta: - blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast, mantle + blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast, mantle, mode sector: dex project: zeroex contributors: rantum, bakabhai993 diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml b/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml new file mode 100644 index 00000000000..0f47baa5698 --- /dev/null +++ b/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml @@ -0,0 +1,11 @@ +version: 2 + +seeds: + - name: zeroex_v2_mode_trades_sample + config: + column_types: + tx_hash: varbinary + taker: varbinary + taker_token: varbinary + maker_token: varbinary + taker_token_amount: double \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv new file mode 100644 index 00000000000..0f4fc0c98d2 --- /dev/null +++ b/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv @@ -0,0 +1,4 @@ +tx_hash,taker,taker_token,maker_token,taker_token_amount +0xd7ace13835ceb119b071c508e8ee262fcecb5a0f2a1bfdd1b9b1f04afa73d94d,0x44c20316a06371ca5acb975974c18abfa7a14a5a,0xf0f161fda2712db8b566946122a5af183995e2ed,0x4200000000000000000000000000000000000006, +0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x6a660e56fa3b630a786cc4ae98859f8532d03de9,0x2416092f143378750bb29b79ed961ab195cceea5,238973 +0xd84a08f6d48b5c34cde908452602088cdb42beceef29074b8a8d5c7e45f2a3dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x4200000000000000000000000000000000000006,0x6a660e56fa3b630a786cc4ae98859f8532d03de9, From 641bfbe29b3c24644dbe2e7aa393b1f074a262bb Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 25 Nov 2024 08:31:02 -0800 Subject: [PATCH 22/68] zeroex - macro for deduped fills (#7156) * deduped macro * add eth model via macro * revise ref table name * cast to date * remove/replace old model * update source method * source name * source name * table name * update macro, add base model * update source --------- Co-authored-by: Huang Geyang Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../zeroex/zeroex_v1_deduped_trades.sql} | 30 ++---- .../base/zeroex_base_api_fills_deduped.sql | 102 ------------------ .../zeroex/base/zeroex_base_schema.yml | 2 +- .../base/zeroex_v1_base_deduped_trades.sql | 30 ++++++ .../ethereum/zeroex_ethereum_schema.yml | 4 +- .../zeroex_v1_ethereum_deduped_trades.sql | 30 ++++++ .../zeroex/zeroex_api_fills_deduped.sql | 4 +- 7 files changed, 73 insertions(+), 129 deletions(-) rename dbt_subprojects/dex/{models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql => macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql} (80%) delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql similarity index 80% rename from dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql rename to dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql index 9a23ab938c9..76f95860aaa 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql +++ b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql @@ -1,36 +1,20 @@ -{{ config( +{% macro zeroex_v1_deduped_trades(blockchain, start_date) %} - schema = 'zeroex_ethereum', - alias = 'api_fills_deduped', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set zeroex_v3_start_date = '2019-12-01' %} ---the code used to create the data for the insertion into the dex.trades table ---this code is also the deduped version for the fills tables. ---only the data for 0x API fills. ---dependent on:zeroex_ethereum.api_fills. +{% set table_name = 'zeroex_' ~ blockchain ~ '_api_fills' %} WITH fills_with_tx_fill_number AS ( SELECT row_number() OVER ( partition BY tx_hash ORDER BY evt_index ASC ) AS tx_fill_number , * - FROM {{ ref('zeroex_ethereum_api_fills') }} + FROM {{ ref(table_name) }} WHERE 1=1 AND swap_flag = true {% if is_incremental() %} AND {{ incremental_predicate('block_time') }} {% endif %} {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v3_start_date}}' as date) + AND block_time >= DATE '{{start_date}}' {% endif %} ) , fills_first_last @@ -66,7 +50,7 @@ AS , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token_amount_raw END) AS maker_token_amount_raw , COUNT(*) AS fills_within FROM fills_first_last a - GROUP BY tx_hash,hop_count + GROUP BY tx_hash ) SELECT a.blockchain , '0x API' as project @@ -98,4 +82,6 @@ SELECT a.blockchain , a.contract_address FROM fills_with_tx_fill_number a INNER JOIN deduped_bridge_fills b - ON a.tx_hash = b.tx_hash AND a.evt_index = b.evt_index \ No newline at end of file + ON a.tx_hash = b.tx_hash AND a.evt_index = b.evt_index +{% endmacro %} + diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql deleted file mode 100644 index e7f7dd0ddbd..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql +++ /dev/null @@ -1,102 +0,0 @@ -{{ config( - - schema = 'zeroex_base', - alias = 'api_fills_deduped', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set zeroex_v3_start_date = '2019-12-01' %} - -WITH fills_with_tx_fill_number -AS -( - SELECT row_number() OVER ( partition BY tx_hash ORDER BY evt_index ASC ) AS tx_fill_number - , * - FROM {{ ref('zeroex_base_api_fills') }} - WHERE 1=1 - AND swap_flag = true - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% endif %} - {% if not is_incremental() %} - AND block_time >= cast('{{zeroex_v3_start_date}}' as date) - {% endif %} -) -, fills_first_last -AS -( - SELECT CASE - WHEN a.taker_token = c.maker_token AND a.taker_token_amount_raw = c.maker_token_amount_raw THEN 0 - ELSE 1 END AS taker_consider_flag--from - , CASE - WHEN a.maker_token = b.taker_token AND a.maker_token_amount_raw = b.taker_token_amount_raw THEN 0 - ELSE 1 END AS maker_consider_flag - , SUM(CASE - WHEN a.maker_token = b.taker_token AND a.maker_token_amount_raw = b.taker_token_amount_raw THEN 0 - ELSE 1 END) OVER (PARTITION BY a.tx_hash ORDER BY a.evt_index DESC) hop_count - , a.* - FROM fills_with_tx_fill_number a - LEFT JOIN fills_with_tx_fill_number b ON (a.tx_hash = b.tx_hash AND a.tx_fill_number = b.tx_fill_number - 1) - LEFT JOIN fills_with_tx_fill_number c ON (a.tx_hash = c.tx_hash AND a.tx_fill_number = c.tx_fill_number + 1) -) -, deduped_bridge_fills -AS -( - SELECT tx_hash - , MAX(evt_index) AS evt_index - , MAX(affiliate_address) AS affiliate_address - , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_token END ) AS taker_token - , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token END ) AS maker_token - , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_symbol END ) AS taker_symbol - , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_symbol END ) AS maker_symbol - , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_token_amount END) AS taker_token_amount - , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token_amount END) AS maker_token_amount - , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_token_amount_raw END) AS taker_token_amount_raw - , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token_amount_raw END) AS maker_token_amount_raw - , COUNT(*) AS fills_within - FROM fills_first_last a - GROUP BY tx_hash,hop_count -) -SELECT a.blockchain - , '0x API' as project - , cast('1' as varchar(10)) as version - - , a.block_date - , a.block_month - , a.block_time - , b.taker_symbol AS taker_symbol - , b.maker_symbol AS maker_symbol - , CASE - WHEN LOWER(b.taker_symbol) > LOWER(b.maker_symbol) - THEN CONCAT(COALESCE(b.maker_symbol, ''), '-', COALESCE(b.taker_symbol, '')) - ELSE CONCAT(COALESCE(b.taker_symbol, ''), '-', COALESCE(b.maker_symbol, '')) - END AS token_pair - , b.taker_token_amount - , b.maker_token_amount - , b.taker_token_amount_raw AS taker_token_amount_raw - , b.maker_token_amount_raw AS maker_token_amount_raw - , a.volume_usd - , b.taker_token - , b.maker_token - , a.taker - , a.maker - , a.affiliate_address - , a.tx_hash - , a.tx_from - , a.tx_to - , b.evt_index - , ARRAY[-1] AS trace_address - , a.type - , a.swap_flag - , b.fills_within - , a.contract_address -FROM fills_with_tx_fill_number a -INNER JOIN deduped_bridge_fills b - ON a.tx_hash = b.tx_hash AND a.evt_index = b.evt_index \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml index a6c1b0f74b8..a0212b1a160 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml @@ -82,7 +82,7 @@ models: name: blockchain description: "Blockchain which the aggregator project is deployed" - - name: zeroex_base_api_fills_deduped + - name: zeroex_v1_base_deduped_trades meta: blockchain: base project: zeroex diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql new file mode 100644 index 00000000000..5713bc0b849 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql @@ -0,0 +1,30 @@ +{{ config( + schema = 'zeroex_v1_base', + alias = 'deduped_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set zeroex_v3_start_date = '2019-12-01' %} +{% set blockchain = 'base' %} + +WITH +deduped_trades as ( + {{ + zeroex_v1_deduped_trades( + blockchain = blockchain, + start_date = zeroex_v3_start_date + + ) + }} + +) +select + * +from deduped_trades diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml index 161329dd166..134e8bc863f 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml @@ -106,11 +106,11 @@ models: name: blockchain - - name: zeroex_ethereum_api_fills_deduped + - name: zeroex_v1_ethereum_deduped_trades meta: blockchain: ethereum project: zeroex - contributors: bakabhai993 + contributors: bakabhai993, rantum config: tags: ['ethereum','0x','dex_aggregator','dex','aggregator'] description: > diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql new file mode 100644 index 00000000000..5b0debbdab0 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql @@ -0,0 +1,30 @@ +{{ config( + schema = 'zeroex_v1_ethereum', + alias = 'deduped_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set zeroex_v3_start_date = '2019-12-01' %} +{% set blockchain = 'ethereum' %} + +WITH +deduped_trades as ( + {{ + zeroex_v1_deduped_trades( + blockchain = blockchain, + start_date = zeroex_v3_start_date + + ) + }} + +) +select + * +from deduped_trades diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 07f52a7d2f9..2b00a9a3f86 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -12,9 +12,9 @@ {% set zeroex_models = [ ref('zeroex_arbitrum_api_fills_deduped') ,ref('zeroex_avalanche_c_api_fills_deduped') - ,ref('zeroex_base_api_fills_deduped') + ,ref('zeroex_v1_base_deduped_trades') ,ref('zeroex_celo_api_fills_deduped') - ,ref('zeroex_ethereum_api_fills_deduped') + ,ref('zeroex_v1_ethereum_deduped_trades') ,ref('zeroex_fantom_api_fills_deduped') ,ref('zeroex_optimism_api_fills_deduped') ,ref('zeroex_polygon_api_fills_deduped') From 0a57292f092a3f18c055ffce04171ec44caded56 Mon Sep 17 00:00:00 2001 From: clizzard <145153355+clizzard7@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:35:10 +0100 Subject: [PATCH 23/68] autosniper bot (#7177) * autosniper bot add autosniper bot demo * push * fixed seed * fix: fix project name autosniper -> autosnipe * chore: add to dex_solana_bot_trades * fix: fix seed * fix typo in schema name --------- Co-authored-by: whale_hunter <143016036+whalehunting@users.noreply.github.com> Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../_sector/dex/bot_trades/solana/_schema.yml | 22 +++ .../solana/dex_solana_bot_trades.sql | 1 + .../platforms/autosnipe_solana_bot_trades.sql | 152 ++++++++++++++++++ .../autosnipe_solana_trades_seed.csv | 21 +++ 4 files changed, 196 insertions(+) create mode 100644 dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql create mode 100644 dbt_subprojects/solana/seeds/autosnipe/autosnipe_solana_trades_seed.csv diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml index c0e8744bf37..6e9faa06c60 100644 --- a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml @@ -621,4 +621,26 @@ models: - inner_instruction_index - check_bot_trades_seed: seed_file: ref('bloom_solana_trades_seed') + blockchain: solana + + - name: autosnipe_solana_bot_trades + meta: + blockchain: solana + sector: dex + project: autosnipe + contributors: whale_hunter + config: + tags: ["solana", "dex", "autosnipe", "trades"] + description: > + Autosnipe trades on Solana + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_id + - tx_index + - outer_instruction_index + - inner_instruction_index + - check_bot_trades_seed: + seed_file: ref('autosnipe_solana_trades_seed') blockchain: solana \ No newline at end of file diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql index 00d54040ed4..45a86ca4054 100644 --- a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql @@ -34,6 +34,7 @@ , ref('jupbot_solana_bot_trades') , ref('looter_solana_bot_trades') , ref('wifbot_solana_bot_trades') + , ref('autosnipe_solana_bot_trades') ] %} {% for bot in solana_trading_bot %} diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql new file mode 100644 index 00000000000..97d8d471ae9 --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql @@ -0,0 +1,152 @@ +{{ config( + alias = 'bot_trades', + schema = 'autosnipe_solana', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'tx_id', 'tx_index', 'outer_instruction_index', 'inner_instruction_index'] + ) +}} + +{% set project_start_date = '2024-11-13' %} +{% set fee_receiver_1 = 'CWEfC6fLi552zE2KFxhPiBAZUWdT78gMd8NGENik2zfE' %} +{% set wsol_token = 'So11111111111111111111111111111111111111112' %} + +WITH + allFeePayments AS ( + SELECT + tx_id, + 'SOL' AS feeTokenType, + balance_change / 1e9 AS fee_token_amount, + '{{wsol_token}}' AS fee_token_mint_address + FROM + {{ source('solana','account_activity') }} + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND tx_success + AND balance_change > 0 + AND address = '{{fee_receiver_1}}' + + ), + botTrades AS ( + SELECT + trades.block_time, + CAST(date_trunc('day', trades.block_time) AS date) AS block_date, + CAST(date_trunc('month', trades.block_time) AS date) AS block_month, + 'solana' AS blockchain, + amount_usd, + IF( + token_sold_mint_address = '{{wsol_token}}', + 'Buy', + 'Sell' + ) AS type, + token_bought_amount, + token_bought_symbol, + token_bought_mint_address AS token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_mint_address AS token_sold_address, + fee_token_amount * price AS fee_usd, + fee_token_amount, + IF(feeTokenType = 'SOL', 'SOL', symbol) AS fee_token_symbol, + fee_token_mint_address AS fee_token_address, + project, + version, + token_pair, + project_program_id AS project_contract_address, + trader_id AS user, + trades.tx_id, + tx_index, + outer_instruction_index, + inner_instruction_index + FROM + {{ ref('dex_solana_trades') }} AS trades + JOIN allFeePayments AS feePayments ON trades.tx_id = feePayments.tx_id + LEFT JOIN {{ source('prices', 'usd') }} AS feeTokenPrices ON ( + feeTokenPrices.blockchain = 'solana' + AND fee_token_mint_address = toBase58 (feeTokenPrices.contract_address) + AND date_trunc('minute', block_time) = minute + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + JOIN {{ source('solana','transactions') }} AS transactions ON ( + trades.tx_id = id + {% if is_incremental() %} + AND {{ incremental_predicate('transactions.block_time') }} + {% else %} + AND transactions.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + WHERE + trades.trader_id != '{{fee_receiver_1}}' -- Exclude trades signed by FeeWallet + AND transactions.signer != '{{fee_receiver_1}}' -- Exclude trades signed by FeeWallet + {% if is_incremental() %} + AND {{ incremental_predicate('trades.block_time') }} + {% else %} + AND trades.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ), + highestInnerInstructionIndexForEachTrade AS ( + SELECT + tx_id, + outer_instruction_index, + MAX(inner_instruction_index) AS highestInnerInstructionIndex + FROM + botTrades + GROUP BY + tx_id, + outer_instruction_index + ) +SELECT + block_time, + block_date, + block_month, + 'Autosnipe' as bot, + blockchain, + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + fee_usd, + fee_token_amount, + fee_token_symbol, + fee_token_address, + project, + version, + token_pair, + project_contract_address, + user, + botTrades.tx_id, + tx_index, + botTrades.outer_instruction_index, + COALESCE(inner_instruction_index, 0) AS inner_instruction_index, + IF( + inner_instruction_index = highestInnerInstructionIndex, + true, + false + ) AS is_last_trade_in_transaction +FROM + botTrades + JOIN highestInnerInstructionIndexForEachTrade ON ( + botTrades.tx_id = highestInnerInstructionIndexForEachTrade.tx_id + AND botTrades.outer_instruction_index = highestInnerInstructionIndexForEachTrade.outer_instruction_index + ) +ORDER BY + block_time DESC, + tx_index DESC, + outer_instruction_index DESC, + inner_instruction_index DESC + diff --git a/dbt_subprojects/solana/seeds/autosnipe/autosnipe_solana_trades_seed.csv b/dbt_subprojects/solana/seeds/autosnipe/autosnipe_solana_trades_seed.csv new file mode 100644 index 00000000000..7a54e3cdb5c --- /dev/null +++ b/dbt_subprojects/solana/seeds/autosnipe/autosnipe_solana_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_id,tx_index,outer_instruction_index,inner_instruction_index,is_last_trade_in_transaction +2024-11-13 10:10:03.000 UTC,2024-11-13,2024-11-01,Autosnipe,solana,1.89099878996,Sell,0.009148076,SOL,So11111111111111111111111111111111111111112,131375.682942,POE,BNLkSqJMM8xmekwQ8nReaHu87RXhohHxMwxPkSUQpump,0.027996388980000005,0.000135438,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-POE,ApgQg6gGBDq9ciKPFe38V2XYywHyPgXSwerVHLSL7fyQ,8GHHSremAExPrXPCcmtcwSCteEQ3sFsvn3x4smJEseev,2GxsTynwW8vrxwy3q4GiNmFGuqEwgjiJBT8qaL2Jnvo3chhmEJPjSAHUtQdit6RmZEJkbKuiraG48HsTCajRvBkM,1553,5,0,true +2024-11-19 05:23:49.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,75.04771682688,Buy,274694.326486,GRIFT,DdWs9oFuGBTFVRbhxNkKQYYYdA6X1D3H5ZMY5TZLjhfG,0.310988384,SOL,So11111111111111111111111111111111111111112,0.75047696556,0.003109883,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-GRIFT,E7iXbCTyae2V2PYiuJNTC7xeJVAoiYMHY8L5TpHX9VYF,Buj7TH93zSKE8W7WvamsHMzmLuYXTekwvH4QqpLMcRxe,4BY97vyp8r24Dnqu2tyHbmi9K8orqhEuia2SAQmANtExicM3wNS3VDB8UMsVdNDPgLS5M85dH5hYwhG9QsyPU8GM,782,6,0,true +2024-11-14 08:40:53.000 UTC,2024-11-14,2024-11-01,Autosnipe,solana,2.1915,Buy,362.045614,RobinPepe,6mW4U4AXge8drs3omUg7o3b87hYizsRbPcWydS7FdRJa,0.01,SOL,So11111111111111111111111111111111111111112,0.021915,0.0001,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-RobinPepe,r7WRtpReP4deeYpcUCcaJWdVCs2PX2iLVoZN42e19Bz,Bu1K6z6ZxbKc6pe6Fbzq4A9Up4nmPg7CudYq8iFkj6L3,eAko78YHHEmWXaYSVJpqXHTCPy9T3xzhXoaz3hdvGTERgExjiYtmk9bVfFa96eSLnw2cY34KXi4AHeT1kRManjC,926,6,0,true +2024-11-20 14:22:07.000 UTC,2024-11-20,2024-11-01,Autosnipe,solana,4.4605925127,Sell,0.018424587,SOL,So11111111111111111111111111111111111111112,7962.065451,lucy,Cy7Nyi89q2HCt4wwxyLLJERNdjwBJVHJCnC8xGSQpump,0.050146415099999994,0.000207131,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-lucy,2fKxw5AhN7R8B1pzrtYp8poe98WdHm8PoboK1qxx2sKz,Hf8biWQwnk2X4LEAEiUWv351FQ23ZgwysUvUkMMCPBCk,jFNj3ohhJtKVrP3ox8BQB5BBAQTdJ4NJ89rZcB3qKNL4AbQDAu2Xm34W3H83SzBVwHfqdB3KZSKSu1GbBT6SnMu,429,5,0,true +2024-11-21 14:10:11.000 UTC,2024-11-21,2024-11-01,Autosnipe,solana,0.85967529,Sell,0.003494615,SOL,So11111111111111111111111111111111111111112,2053.81599,Mercal,ESn52mvYR7Yo1XyUe1zJRqfe3VorGXwndFB14H93pump,0.014268491999999999,0.000058002,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Mercal,C2vF8E1xcAPp8Ly2rn4V1ySxyYFyT5JSvYXWSFdb1Rxg,HCnXthqj7hQWJ6YDSYLPcmTU6HpFvQYZ2EMiBVWr3WCb,5gg3vWDSNgDJHWjHftNP42vNvWoENvi9EYJdx6dq95Vs63eK6U5vVZHkmNJNW6W3GH4BBHq2N5cFDo2UUaKw8ms5,365,5,0,true +2024-11-19 07:17:35.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,0.19324405122,Sell,0.000792406,SOL,So11111111111111111111111111111111111111112,60.581306,DOGECAST,EwgD3xXdEEMfSqTKtWU8XJzpncbdi8oSQ5VJV75X2FsW,0.09793697265,0.000401595,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-DOGECAST,BMyVgWdDdWRDpkVyoxWnNsMsP1VfsZdbJFnJXetk6pgt,HWP1ia8ydkH69kXgzAKuZRvEtX1bgAirUk6c1GsMqgjA,K7SijRGwsVy6NeSrsD5dC6sFnm6HCFJBfkvM6thm1YFHD7C4PKUbDUxT9ThKu9Kx45fRfszGVjKF9ZdWovsp1Lc,257,5,0,true +2024-11-19 23:12:29.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,1.58160693071,Sell,0.006704281,SOL,So11111111111111111111111111111111111111112,164600.628572,ΔΘGΞ,EkMAYuktJDkiioBLUxn7ToWrv4tfY8c1QjvzHwrcpump,0.02500646,0.000106,SOL,So11111111111111111111111111111111111111112,raydium,4,ΔΘGΞ-SOL,5efupJYTonpmrgyAURkgP8HgRmwYdnVc4EwXoL7P5jnr,Fm3RkHsY3ZkXNtaFyUxuDTyo5LuSkCNPhBW6ndqMf9Yy,4gQxg29RjrYLfDwNeM93fzAKDd3SD2GeqQ1Ko6Hpa5UdSmNKmEXVd19ze4A98TUcqQmxhwVYuPNZhexuFgk6QyML,545,5,0,true +2024-11-14 12:17:06.000 UTC,2024-11-14,2024-11-01,Autosnipe,solana,13.935083723410001,Sell,0.064374203,SOL,So11111111111111111111111111111111111111112,1613.92806,LESTER,5z3iCe53hUANTiG8Js8RjHNE2Arjik7L2CXLyr2rpump,0.14572370754,0.000673182,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-LESTER,7TkVaEEG8CpMutTpkQMGDEdsRi1GxnjA1NzKiTPKbxnE,C4ZXEJWcJdu7HQGz6JhbRMGAHTnoYLaGMrGqgT2ojUFG,5woVu45pDVBjDnzmJsxD1aSJyBa69Zr7C82b5zLFULiz158ySdKuxPwbUDDe6nuTwXZjy26Trei8UAzc7Rhf8oTq,117,5,0,true +2024-11-20 08:58:17.000 UTC,2024-11-20,2024-11-01,Autosnipe,solana,2.3874,Buy,8510.344944,BADGUY,5JGi5RWDDjRNWBifuwavKGE7cPG8YhenDLxrTHAjpump,0.01,SOL,So11111111111111111111111111111111111111112,0.023874000000000003,0.0001,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-BADGUY,Dt8yduTbFykpGZCSse1AYFU4Dd6CvyGWKFixrjXMN5UB,GtPCTuUg5xECqRiBwtzxDAYxUt7s6icrKuevrFKbo5sv,4rWCwWHiyu5qpUgf3LUwo9KLaKu8QiPzgZschtb7DpMbZ2jfMmdkRu4LCffEhLq1NK3PeW511BcFuy5zSckzoXbz,2090,6,0,true +2024-11-20 13:15:55.000 UTC,2024-11-20,2024-11-01,Autosnipe,solana,4.970279410720001,Sell,0.020972528,SOL,So11111111111111111111111111111111111111112,70407.335715,THABO,9SBt1dVSVWchvSo3g5RAZswg8VDz1Se4K4YMzVBwpump,0.0543275876,0.00022924,SOL,So11111111111111111111111111111111111111112,raydium,4,THABO-SOL,7BwRNp2jKpSza3kEb2XtAoXCMLSL78ZNvT7R6Z7YtdGz,BZqTgDxDGpmzQH5iVoHUXR9XMjwEiQqRdQZYaKgh1y7L,2LHpYhNoTjcaixpb1e4s12a9qiNranbj9yTAziLa6R27NH5owKqNcwAa4ikTHt5RKeZmzcc2bNEM2gGFtL1p5ZMh,2023,5,0,true +2024-11-18 08:10:07.000 UTC,2024-11-18,2024-11-01,Autosnipe,solana,2.5683426732499997,Sell,0.010659235,SOL,So11111111111111111111111111111111111111112,162766.933535,AM,Bsa3w4EePHJcf3aTvynmoRH4Bs5TfJzQhGPmWxXapump,0.031899370499999996,0.00013239,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-AM,6EL4FSLU5RuTA2K14HK8JwS8cBhNTSp5Q43RHZkaaZHb,AofQXWAJMxJ7DomHEVxZ9nmKJ2WH4LkBXo2wtK3W66D1,4ktk9pnrKvnVAMR6RfJay5YTycyVgoYxYaKErZCuqBpQxdknNNcFesEvTF3WanG3JGQ8Yxi1365Czat8LB9H8BLv,832,5,0,true +2024-11-16 22:20:45.000 UTC,2024-11-16,2024-11-01,Autosnipe,solana,1.86737437986,Buy,89814,Legacy,CEBcNKkGqwYcnQWK72NZBGNVLNtJDXWHVG1eAd8hpump,0.008594718,SOL,So11111111111111111111111111111111111111112,0.021727000000000003,0.0001,SOL,So11111111111111111111111111111111111111112,pumpdotfun,1,SOL-Legacy,GnNMGBxxmQRHJ1bNPQXnW1Bmc5mAvvSj51pnw7QNtS9n,WnRP1tPZXFXMqYyhC1nftFLqmwffiNcVP113afRjBNQ,41qWs9e9NHr4mMGNGfbvCDEhPbU8h2ThvJfp85VKxPsWfBBasjCHQjQ2pGMW82xu5MhSbyD5nADEVGPqE1KDWfRz,1621,3,4,true +2024-11-13 06:37:26.000 UTC,2024-11-13,2024-11-01,Autosnipe,solana,2.0347,Buy,320.474911,PURE,E5DpUjFJtiyj8qK7eQtLVjiNxB9o2iHmQbMYVn93bfe4,0.01,SOL,So11111111111111111111111111111111111111112,0.020347,0.0001,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-PURE,HykbwqpzEsBkcDrAhvZzCVXVLRTYL2pewizYiTkn5Bxw,5RFyzum4ybsfDp8qfF8J9bGeCpxsEspkLEPuyYjYprd9,376RghWJ4YGa97RSdPLstF2vMimBsezRYrCeaZP72USEQLT7QB2swXB7ATMLxAr3e9kBqbDPL18B4omCj1ArxzSS,1781,6,0,true +2024-11-19 04:26:06.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,2.4002000000000003,Buy,306.113528431,TUCKER,BDbhJUMgQBQ1bJTKhSS9NsxZdfaiBG6Hgp8qNKpc3YSX,0.01,SOL,So11111111111111111111111111111111111111112,0.024002000000000002,0.0001,SOL,So11111111111111111111111111111111111111112,raydium,4,TUCKER-SOL,43dhe8zqSXUkgmANm23sf1nJ3eSr1Z4q9AYPXER4XAmg,C2WhoXZpKiL8mU4ARxGYR1DMftwkpm6jTwnzva1zkZ91,4XCaQ6PG1M2dbMagLDzDtTzPCsswcMg19QS4XoZP6N5ezLxowoQyAet7saNaa4bQdzhxUx1Bin2vZX9qrucZX1JR,596,5,0,true +2024-11-19 09:46:24.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,0.43912312249999996,Sell,0.001810817,SOL,So11111111111111111111111111111111111111112,5590.36462,neoai16z,7e3a94ZrwhCsVaZRYBzm9KxfFsVLr7F853yjrxP4pump,0.0184831075,0.000076219,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-neoai16z,4UjKGDoVvu1LJNxcRtkceER52QHzKAav1PAtL7rqLCPL,8VcYNCpY6vmk6sfv3AqVKWbTpicYb35fAEoFHuXJ3CeV,3HmFPziTKF2CQtczcSQ25eJ1it2sxr4tP1VCFYsENKvoffkCV2vSM9kLsuP9EELyoZ3XsK1CnUtn7NWzTe1M26Cq,1448,5,0,true +2024-11-19 05:06:35.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,9.76544122232,Sell,0.040682558,SOL,So11111111111111111111111111111111111111112,1426470,Faggot,5pxpvP8S35SmRuwJTVVWioUvp7VJ4zfZcaBKRoqKpump,0.09929902707999999,0.000413677,SOL,So11111111111111111111111111111111111111112,pumpdotfun,1,SOL-Faggot,5AnQ7GB795U5yCrgZi5AR2NWDSbu98S993mKzrJpB9gn,83nxnmuG2cMFXTobsZT6kEUbZySGgKryZ2tx7iouYoCE,24YW9bMpHmXbabW5sX6JMbKvwgNZaFY3fFKPd2uvkWjugbFzcpRpMWFUbXy4NvRxywJ1s6Jh35sLvsi2xaWCoMR7,107,3,2,true +2024-11-19 22:12:03.000 UTC,2024-11-19,2024-11-01,Autosnipe,solana,23.703000000000003,Buy,146116.568446,Rover,4uz44JLvsJahuk8LxJAinhRNpsNwB61UZCn4ygbeMGLK,0.1,SOL,So11111111111111111111111111111111111111112,0.23703000000000002,0.001,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Rover,2qcdnvYpajhbN8pXcRsqL5umddgd7yBVj97RzoAFnKc7,GwUGDuJ1aGQnbCaoXbv58TvVBmTbdiYRfxdXTHmN2uRS,5omxR5YPBrowTYhtPR3ShQ4Qd6YsHHqpZr8cVEC1UsiHvPFRH36iacsFd6tex9sNGWAH392wBpeyf77Ls55Ehogb,394,6,0,true +2024-11-15 19:40:28.000 UTC,2024-11-15,2024-11-01,Autosnipe,solana,32.07731663808,Sell,0.151087168,SOL,So11111111111111111111111111111111111111112,26776.416962,KENDROOK,3MJA1JZBpbPRXaCQLHFB6MGxfbzNSm8WPtUebwNhmphd,0.41221324053,0.001941563,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-KENDROOK,4oc6KXo3sRpVqz3ApNTZA2FW2FkLQEHyP3Ly7rf2eRcs,8aeuAMj1NLjPxBWKi8xNY2MsGc1tstFyrX8NX5rW6TBX,5jULAipB5jSSPMAH5TsLb2D6BdmXuN3yYkYfi1RwLMZvMsYypP77VvFpi53DnLArnxQW9Dxdghx3vfVVDUJV4W72,405,5,0,true +2024-11-13 19:26:47.000 UTC,2024-11-13,2024-11-01,Autosnipe,solana,1.287114624,Sell,0.005958864,SOL,So11111111111111111111111111111111111111112,35357.416118,Cedric,2ZAroijMWLZSUpBxSPAs5PL5HLdxHHPSomuenQCwpump,0.027981071999999996,0.000129542,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Cedric,FwxJhTG1Cphj6ZAzhdeFQDP4KdFHQhoM2pm3EqkhEEpz,2YR4j8Gk3povu3TSKF6RPyUvCKwUw9xy6JKduZyk5mPe,4dWcpjyUMxexXGGXFWHMxTLSLPdKWRyXZjwAV7NQrbFyNnaJAHnnmk3TwD2v3z4zgSiv8WXX1S8U9kMaBmHh6fdz,1737,5,0,true +2024-11-14 04:48:08.000 UTC,2024-11-14,2024-11-01,Autosnipe,solana,172.35345226364998,Sell,0.787181787,SOL,So11111111111111111111111111111111111111112,34189619.612266,FLIP,ABoVYKRK4Wvzijcxt6xxSzqxUFErFU4S1MvAY7MNpump,1.7279995984499998,0.007892211,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-FLIP,EE6y8vm1MyTtisBRo97rJ64GUnuWv61TFQwAcXNFKYMM,6fFyvyrfaJzmPvBGr4P6oFkVAvYH4RLuTa4fZ7J1qYsa,67NtPxcecLAoj3GdAHS7AzC7YsYn2T7MsuhVaig7yCYVQmThxRUTWW5hnUpndYpw59DzBAdJPSa7LsaprpsodqFQ,1396,5,0,true From 4828248402157caa52f2d8f0b30d59f061180144 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:45:35 -0500 Subject: [PATCH 24/68] revert 0x enhancements: v1 fills and deduped (#7186) * Revert "zeroex - macro for v1 fills (#7161)" This reverts commit 91241e616f5d77c7952d4723f3bebc583ffbfdea. * Revert "zeroex - macro for deduped fills (#7156)" This reverts commit 30b95c51798cd7c8da243cfad67e0f703449ae33. --- .../_project/zeroex/zeroex_v1_api_fills.sql | 577 ------------------ .../zeroex/base/zeroex_base_api_fills.sql | 251 ++++++-- .../base/zeroex_base_api_fills_deduped.sql | 102 ++++ .../zeroex/base/zeroex_base_schema.yml | 2 +- .../base/zeroex_v1_base_deduped_trades.sql | 30 - .../ethereum/zeroex_ethereum_api_fills.sql | 570 +++++++++++++---- .../zeroex_ethereum_api_fills_deduped.sql} | 30 +- .../ethereum/zeroex_ethereum_schema.yml | 6 +- .../zeroex_v1_ethereum_deduped_trades.sql | 30 - .../zeroex/zeroex_api_fills_deduped.sql | 4 +- 10 files changed, 800 insertions(+), 802 deletions(-) delete mode 100644 dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql rename dbt_subprojects/dex/{macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql => models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql} (80%) delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql deleted file mode 100644 index 662d3bbd4cb..00000000000 --- a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_api_fills.sql +++ /dev/null @@ -1,577 +0,0 @@ -{% macro zeroex_evt_fills_txs(blockchain,zeroex_v3_start_date) %} -{%- set table_prefix = 'zeroex_v3_' + blockchain -%} - -SELECT - v3.evt_tx_hash AS tx_hash, - CASE - WHEN takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc THEN takerAddress - ELSE NULL - END AS affiliate_address, - NULL AS is_gasless, - evt_block_time AS block_time -FROM {{ source(table_prefix, 'Exchange_evt_Fill') }} v3 -WHERE ( -- nuo - v3.takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc - OR -- contains a bridge order - ( - v3.feeRecipientAddress = 0x1000000000000000000000000000000000000011 - AND bytearray_substring(v3.makerAssetData, 1, 4) = 0xdc1600f3 - ) -) -{% if is_incremental() %} -AND {{ incremental_predicate('evt_block_time') }} -{% else %} -AND evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} -{% endmacro %} - - -{% macro zeroex_v1_txs(blockchain,zeroex_v3_start_date) %} -SELECT - tr.tx_hash, - CASE - WHEN bytearray_position(INPUT, 0x869584cd) <> 0 THEN - SUBSTRING(INPUT FROM (bytearray_position(INPUT, 0x869584cd) + 16) FOR 20) - WHEN bytearray_position(INPUT, 0xfbc019a7) <> 0 THEN - SUBSTRING(INPUT FROM (bytearray_position(INPUT, 0xfbc019a7) + 16) FOR 20) - END AS affiliate_address, - CASE - WHEN (varbinary_position(input, 0x3d8d4082) <> 0 OR varbinary_position(input, 0x4f948110) <> 0) - THEN 1 - END AS is_gasless, - block_time -FROM {{ source(blockchain, 'traces') }} tr -WHERE tr.to IN ( - 0x61935cbdd02287b511119ddb11aeb42f1593b7ef, -- exchange contract - 0x6958f5e95332d93d21af0d7b9ca85b8212fee0a5, -- forwarder address - 0x4aa817c6f383c8e8ae77301d18ce48efb16fd2be, -- forwarder address - 0x4ef40d1bf0983899892946830abf99eca2dbc5ce, -- forwarder address - 0xdef1c0ded9bec7f1a1670819833240f027b25eff -- exchange proxy -) -AND ( - bytearray_position(INPUT, 0x869584cd) <> 0 - OR bytearray_position(INPUT, 0xfbc019a7) <> 0 -) -{% if is_incremental() %} -AND {{ incremental_predicate('block_time') }} -{% else %} -AND block_time >= cast('{{zeroex_v3_start_date}}' as date) -{% endif %} -{% endmacro %} - - -{% macro v3_fills_no_bridge(blockchain,zeroex_v3_start_date) %} -{%- set table_prefix = 'zeroex_v3_' + blockchain -%} - -SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - evt_block_time AS block_time, - fills.makerAddress AS maker, - fills.takerAddress AS taker, - bytearray_substring(fills.takerAssetData, 17, 20) AS taker_token, - bytearray_substring(fills.makerAssetData, 17, 20) AS maker_token, - CAST(fills.takerAssetFilledAmount AS int256) AS taker_token_amount_raw, - CAST(fills.makerAssetFilledAmount AS int256) AS maker_token_amount_raw, - 'Fill' AS type, - COALESCE(zeroex_tx.affiliate_address, fills.feeRecipientAddress) AS affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - (fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed) AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'Exchange_evt_Fill') }} fills -INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash AND fills.evt_block_time = zeroex_tx.block_time -WHERE - -- Exclude bridge orders - (bytearray_substring(makerAssetData, 1, 4) <> 0xdc1600f3) - AND - ( - -- Include transactions with a matching tx_hash in zeroex_tx or specific feeRecipientAddress - zeroex_tx.tx_hash IS NOT NULL - OR fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed - ) - - {% if is_incremental() %} - AND {{ incremental_predicate('evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) - {% endif %} -{% endmacro %} - - -{% macro v4_rfq_fills_no_bridge(blockchain, zeroex_v4_start_date) %} -{%- set table_prefix = 'zeroex_' + blockchain -%} -SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - fills.evt_block_time AS block_time, - fills.maker, - fills.taker, - fills.takerToken AS taker_token, - fills.makerToken AS maker_token, - CAST(fills.takerTokenFilledAmount AS int256) AS taker_token_amount_raw, - CAST(fills.makerTokenFilledAmount AS int256) AS maker_token_amount_raw, - 'RfqOrderFilled' AS type, - zeroex_tx.affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'ExchangeProxy_evt_RfqOrderFilled') }} fills -LEFT JOIN zeroex_tx - ON zeroex_tx.tx_hash = fills.evt_tx_hash - AND fills.evt_block_time = zeroex_tx.block_time - -{% if is_incremental() %} -WHERE {{ incremental_predicate('evt_block_time') }} -{% else %} -WHERE evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - - -{% macro v4_limit_fills_no_bridge(blockchain, zeroex_v4_start_date) %} -{%- set table_prefix = 'zeroex_' + blockchain -%} -SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - fills.evt_block_time AS block_time, - fills.maker, - fills.taker, - fills.takerToken AS taker_token, - fills.makerToken AS maker_token, - CAST(fills.takerTokenFilledAmount AS int256) AS taker_token_amount_raw, - CAST(fills.makerTokenFilledAmount AS int256) AS maker_token_amount_raw, - 'LimitOrderFilled' AS type, - COALESCE(zeroex_tx.affiliate_address, fills.feeRecipient) AS affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - (fills.feeRecipient IN ( - 0x9b858be6e3047d88820f439b240deac2418a2551, - 0x86003b044f70dac0abc80ac8957305b6370893ed, - 0x5bc2419a087666148bfbe1361ae6c06d240c6131 - )) AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'ExchangeProxy_evt_LimitOrderFilled') }} fills -LEFT JOIN zeroex_tx - ON zeroex_tx.tx_hash = fills.evt_tx_hash - AND fills.evt_block_time = zeroex_tx.block_time - -{% if is_incremental() %} -WHERE {{ incremental_predicate('evt_block_time') }} -{% else %} -WHERE evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - -{% macro otc_fills(blockchain, zeroex_v4_start_date) %} -{%- set table_prefix = 'zeroex_' + blockchain -%} -SELECT - fills.evt_tx_hash AS tx_hash, - fills.evt_index, - fills.contract_address, - fills.evt_block_time AS block_time, - fills.maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - fills.takerToken AS taker_token, - fills.makerToken AS maker_token, - CAST(fills.takerTokenFilledAmount AS int256) AS taker_token_amount_raw, - CAST(fills.makerTokenFilledAmount AS int256) AS maker_token_amount_raw, - 'OtcOrderFilled' AS type, - zeroex_tx.affiliate_address, - (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'ExchangeProxy_evt_OtcOrderFilled') }} fills -LEFT JOIN zeroex_tx - ON zeroex_tx.tx_hash = fills.evt_tx_hash - AND fills.evt_block_time = zeroex_tx.block_time -{% if is_incremental() %} -WHERE {{ incremental_predicate('evt_block_time') }} -{% else %} -WHERE evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - - -{% macro ERC20BridgeTransfer(blockchain, zeroex_v3_start_date) %} -SELECT - logs.tx_hash, - logs.index AS evt_index, - logs.contract_address, - logs.block_time, - bytearray_substring(data, 141, 20) AS maker, - bytearray_substring(data, 173, 20) AS taker, - bytearray_substring(data, 13, 20) AS taker_token, - bytearray_substring(data, 45, 20) AS maker_token, - bytearray_to_int256(bytearray_substring(data, 77, 20)) AS taker_token_amount_raw, - bytearray_to_int256(bytearray_substring(data, 109, 20)) AS maker_token_amount_raw, - 'ERC20BridgeTransfer' AS type, - zeroex_tx.affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(blockchain, 'logs') }} logs -JOIN zeroex_tx - ON zeroex_tx.tx_hash = logs.tx_hash - AND logs.block_time = zeroex_tx.block_time -WHERE topic0 = 0x349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9 - -{% if is_incremental() %} -AND {{ incremental_predicate('logs.block_time') }} -{% else %} -AND logs.block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - - -{% macro BridgeFill(blockchain, zeroex_v4_start_date) %} -SELECT - logs.tx_hash, - logs.index AS evt_index, - logs.contract_address, - logs.block_time, - bytearray_substring(data, 13, 20) AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - bytearray_substring(data, 45, 20) AS taker_token, - bytearray_substring(data, 77, 20) AS maker_token, - bytearray_to_int256(bytearray_substring(data, 109, 20)) AS taker_token_amount_raw, - bytearray_to_int256(bytearray_substring(data, 141, 20)) AS maker_token_amount_raw, - 'BridgeFill' AS type, - zeroex_tx.affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(blockchain, 'logs') }} logs -JOIN zeroex_tx - ON zeroex_tx.tx_hash = logs.tx_hash - AND logs.block_time = zeroex_tx.block_time -WHERE topic0 = 0xff3bc5e46464411f331d1b093e1587d2d1aa667f5618f98a95afc4132709d3a9 - AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 - -{% if is_incremental() %} -AND {{ incremental_predicate('logs.block_time') }} -{% else %} -AND logs.block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - -{% macro NewBridgeFill(blockchain, zeroex_v4_start_date) %} -SELECT - logs.tx_hash, - logs.index AS evt_index, - logs.contract_address, - logs.block_time, - bytearray_substring(data, 13, 20) AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - bytearray_substring(data, 45, 20) AS taker_token, - bytearray_substring(data, 77, 20) AS maker_token, - bytearray_to_int256(bytearray_substring(data, 109, 20)) AS taker_token_amount_raw, - bytearray_to_int256(bytearray_substring(data, 141, 20)) AS maker_token_amount_raw, - 'NewBridgeFill' AS type, - zeroex_tx.affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(blockchain, 'logs') }} logs -JOIN zeroex_tx - ON zeroex_tx.tx_hash = logs.tx_hash - AND logs.block_time = zeroex_tx.block_time -WHERE topic0 = 0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8 - AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 - -{% if is_incremental() %} -AND {{ incremental_predicate('logs.block_time') }} -{% else %} -AND logs.block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - -{% macro direct_PLP(blockchain, zeroex_v3_start_date) %} -{%- set table_prefix = 'zeroex_' + blockchain -%} -SELECT - plp.evt_tx_hash, - plp.evt_index AS evt_index, - plp.contract_address, - plp.evt_block_time AS block_time, - provider AS maker, - recipient AS taker, - inputToken AS taker_token, - outputToken AS maker_token, - CAST(inputTokenAmount AS int256) AS taker_token_amount_raw, - CAST(outputTokenAmount AS int256) AS maker_token_amount_raw, - 'LiquidityProviderSwap' AS type, - zeroex_tx.affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'ExchangeProxy_evt_LiquidityProviderSwap') }} plp -JOIN zeroex_tx - ON zeroex_tx.tx_hash = plp.evt_tx_hash - AND plp.evt_block_time = zeroex_tx.block_time - -{% if is_incremental() %} -WHERE {{ incremental_predicate('evt_block_time') }} -{% else %} -WHERE evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) -{% endif %} -{% endmacro %} - -{% macro direct_uniswapv2(blockchain, zeroex_v3_start_date) %} -{%- set table_prefix = 'uniswap_v2_' + blockchain -%} -SELECT - swap.evt_tx_hash AS tx_hash, - swap.evt_index, - swap.contract_address, - swap.evt_block_time AS block_time, - swap.contract_address AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - CASE - WHEN swap.amount0In > swap.amount0Out THEN pair.token0 - ELSE pair.token1 - END AS taker_token, - CASE - WHEN swap.amount0In > swap.amount0Out THEN pair.token1 - ELSE pair.token0 - END AS maker_token, - CASE - WHEN swap.amount0In > swap.amount0Out THEN - CASE - WHEN swap.amount0In >= swap.amount0Out THEN CAST(swap.amount0In - swap.amount0Out AS int256) - ELSE CAST(0 AS int256) - END - ELSE - CASE - WHEN swap.amount1In >= swap.amount1Out THEN CAST(swap.amount1In - swap.amount1Out AS int256) - ELSE CAST(0 AS int256) - END - END AS taker_token_amount_raw, - CASE - WHEN swap.amount0In > swap.amount0Out THEN - CASE - WHEN swap.amount1Out >= swap.amount1In THEN CAST(swap.amount1Out - swap.amount1In AS int256) - ELSE CAST(0 AS int256) - END - ELSE - CASE - WHEN swap.amount0Out >= swap.amount0In THEN CAST(swap.amount0Out - swap.amount0In AS int256) - ELSE CAST(0 AS int256) - END - END AS maker_token_amount_raw, - 'Uniswap V2 Direct' AS type, - zeroex_tx.affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'Pair_evt_Swap') }} swap -LEFT JOIN {{ source(table_prefix, 'Factory_evt_PairCreated') }} pair - ON pair.pair = swap.contract_address -JOIN zeroex_tx - ON zeroex_tx.tx_hash = swap.evt_tx_hash - AND swap.evt_block_time = zeroex_tx.block_time -WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff - {% if is_incremental() %} - AND {{ incremental_predicate('swap.evt_block_time') }} - {% else %} - AND swap.evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) - {% endif %} -{% endmacro %} - -{% macro direct_sushiswap(blockchain, zeroex_v3_start_date) %} -{%- set table_prefix = 'sushi_' + blockchain -%} -SELECT - swap.evt_tx_hash AS tx_hash, - swap.evt_index, - swap.contract_address, - swap.evt_block_time AS block_time, - swap.contract_address AS maker, - LAST_VALUE(swap.to) OVER (PARTITION BY swap.evt_tx_hash ORDER BY swap.evt_index) AS taker, - CASE - WHEN swap.amount0In > swap.amount0Out THEN pair.token0 - ELSE pair.token1 - END AS taker_token, - CASE - WHEN swap.amount0In > swap.amount0Out THEN pair.token1 - ELSE pair.token0 - END AS maker_token, - CASE - WHEN swap.amount0In > swap.amount0Out THEN - CASE - WHEN swap.amount0In >= swap.amount0Out THEN CAST(swap.amount0In - swap.amount0Out AS int256) - ELSE CAST(0 AS int256) - END - ELSE - CASE - WHEN swap.amount1In >= swap.amount1Out THEN CAST(swap.amount1In - swap.amount1Out AS int256) - ELSE CAST(0 AS int256) - END - END AS taker_token_amount_raw, - CASE - WHEN swap.amount0In > swap.amount0Out THEN - CASE - WHEN swap.amount1Out >= swap.amount1In THEN CAST(swap.amount1Out - swap.amount1In AS int256) - ELSE CAST(0 AS int256) - END - ELSE - CASE - WHEN swap.amount0Out >= swap.amount0In THEN CAST(swap.amount0Out - swap.amount0In AS int256) - ELSE CAST(0 AS int256) - END - END AS maker_token_amount_raw, - 'Sushiswap Direct' AS type, - zeroex_tx.affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless -FROM {{ source(table_prefix, 'Pair_evt_Swap') }} swap -LEFT JOIN {{ source(table_prefix, 'Factory_evt_PairCreated') }} pair - ON pair.pair = swap.contract_address -JOIN zeroex_tx - ON zeroex_tx.tx_hash = swap.evt_tx_hash - AND swap.evt_block_time = zeroex_tx.block_time -WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff - {% if is_incremental() %} - AND {{ incremental_predicate('swap.evt_block_time') }} - {% else %} - AND swap.evt_block_time >= CAST('{{zeroex_v3_start_date}}' AS DATE) - {% endif %} -{% endmacro %} - - -{% macro direct_uniswapv3(blockchain,zeroex_v4_start_date) %} -{%- set table_prefix = 'uniswap_v3_' + blockchain -%} - SELECT - swap.evt_tx_hash AS tx_hash, - swap.evt_index, - swap.contract_address, - swap.evt_block_time AS block_time, - swap.contract_address AS maker, - 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, - CASE - WHEN amount0 < CAST(0 AS int256) THEN pair.token1 - ELSE pair.token0 - END AS taker_token, - CASE - WHEN amount0 < CAST(0 AS int256) THEN pair.token0 - ELSE pair.token1 - END AS maker_token, - CASE - WHEN amount0 < CAST(0 AS int256) THEN ABS(swap.amount1) - ELSE ABS(swap.amount0) - END AS taker_token_amount_raw, - CASE - WHEN amount0 < CAST(0 AS int256) THEN ABS(swap.amount0) - ELSE ABS(swap.amount1) - END AS maker_token_amount_raw, - 'Uniswap V3 Direct' AS type, - zeroex_tx.affiliate_address AS affiliate_address, - TRUE AS swap_flag, - FALSE AS matcha_limit_order_flag, - is_gasless - FROM {{ source(table_prefix, 'Pair_evt_Swap') }} swap - LEFT JOIN {{ source(table_prefix, 'Factory_evt_PoolCreated') }} pair - ON pair.pool = swap.contract_address - JOIN zeroex_tx - ON zeroex_tx.tx_hash = swap.evt_tx_hash - AND swap.evt_block_time = zeroex_tx.block_time - WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff - {% if is_incremental() %} - AND {{ incremental_predicate('swap.evt_block_time') }} - {% endif %} - {% if not is_incremental() %} - AND swap.evt_block_time >= CAST('{{zeroex_v4_start_date}}' AS DATE) - {% endif %} -{% endmacro %} - -{% macro trade_details(blockchain, zeroex_v3_start_date) %} -WITH results AS ( - SELECT - all_tx.tx_hash, - tx.block_number, - all_tx.evt_index, - all_tx.contract_address, - all_tx.block_time, - CAST(DATE_TRUNC('day', all_tx.block_time) AS DATE) AS block_date, - CAST(DATE_TRUNC('month', all_tx.block_time) AS DATE) AS block_month, - maker, - CASE - WHEN is_gasless = 1 AND VARBINARY_POSITION(data, 0x3a46c4e1) <> 0 THEN VARBINARY_SUBSTRING(data, 81, 20) - WHEN is_gasless = 1 AND VARBINARY_POSITION(data, 0xa98fcbf1) <> 0 THEN VARBINARY_SUBSTRING(data, 81, 20) - WHEN is_gasless = 1 AND VARBINARY_POSITION(data, 0x3d8d4082) <> 0 THEN VARBINARY_SUBSTRING(data, 177, 20) - WHEN taker = 0xdef1c0ded9bec7f1a1670819833240f027b25eff THEN tx."from" - ELSE taker - END AS taker, - taker_token, - taker_token AS token_sold_address, - ts.symbol AS taker_symbol, - maker_token, - maker_token AS token_bought_address, - ms.symbol AS maker_symbol, - CASE - WHEN LOWER(ts.symbol) > LOWER(ms.symbol) THEN CONCAT(ms.symbol, '-', ts.symbol) - ELSE CONCAT(ts.symbol, '-', ms.symbol) - END AS token_pair, - taker_token_amount_raw / POW(10, tp.decimals) AS taker_token_amount, - taker_token_amount_raw / POW(10, tp.decimals) AS token_sold_amount, - CAST(taker_token_amount_raw AS UINT256) AS taker_token_amount_raw, - maker_token_amount_raw / POW(10, mp.decimals) AS maker_token_amount, - maker_token_amount_raw / POW(10, mp.decimals) AS token_bought_amount, - CAST(maker_token_amount_raw AS UINT256) AS maker_token_amount_raw, - all_tx.type, - MAX(affiliate_address) OVER (PARTITION BY all_tx.tx_hash) AS affiliate_address, - swap_flag, - matcha_limit_order_flag, - tx."from" AS tx_from, - tx.to AS tx_to, - '{{ blockchain }}' AS blockchain - FROM all_tx - INNER JOIN {{ source(blockchain, 'transactions') }} tx - ON all_tx.tx_hash = tx.hash AND all_tx.block_time = tx.block_time - {% if is_incremental() %} - AND {{ incremental_predicate('tx.block_time') }} - {% endif %} - {% if not is_incremental() %} - AND tx.block_time >= CAST('{{ zeroex_v3_start_date }}' AS DATE) - {% endif %} - LEFT JOIN {{ source('prices', 'usd') }} tp - ON DATE_TRUNC('minute', all_tx.block_time) = tp.minute - AND CASE - WHEN all_tx.taker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 - ELSE all_tx.taker_token - END = tp.contract_address - AND tp.blockchain = '{{ blockchain }}' - {% if is_incremental() %} - AND {{ incremental_predicate('tp.minute') }} - {% endif %} - {% if not is_incremental() %} - AND tp.minute >= CAST('{{ zeroex_v3_start_date }}' AS DATE) - {% endif %} - LEFT JOIN {{ source('prices', 'usd') }} mp - ON DATE_TRUNC('minute', all_tx.block_time) = mp.minute - AND CASE - WHEN all_tx.maker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 - ELSE all_tx.maker_token - END = mp.contract_address - AND mp.blockchain = '{{ blockchain }}' - {% if is_incremental() %} - AND {{ incremental_predicate('mp.minute') }} - {% endif %} - {% if not is_incremental() %} - AND mp.minute >= CAST('{{ zeroex_v3_start_date }}' AS DATE) - {% endif %} - LEFT JOIN {{ source('tokens', 'erc20') }} ts - ON ts.contract_address = taker_token AND ts.blockchain = '{{ blockchain }}' - LEFT JOIN {{ source('tokens', 'erc20') }} ms - ON ms.contract_address = maker_token AND ms.blockchain = '{{ blockchain }}' -), - -results_usd AS ( - {{ - add_amount_usd( - trades_cte = 'results' - ) - }} -) -select * from results_usd -{% endmacro %} diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql index c5c5d327ec1..fc3f6009fc9 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills.sql @@ -19,65 +19,228 @@ {% set zeroex_v3_start_date = '2019-12-01' %} {% set zeroex_v4_start_date = '2021-01-06' %} -{% set blockchain = 'base' %} + +-- Test Query here: https://dune.com/queries/2834419 WITH zeroex_tx AS ( - SELECT tx_hash, - block_time as block_time, + SELECT tx_hash, max(affiliate_address) as affiliate_address, - max(is_gasless) as is_gasless + is_gasless FROM ( - {{ - zeroex_v1_txs( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date, - ) - }} + SELECT tr.tx_hash, + CASE + WHEN bytearray_position(INPUT, 0x869584cd ) <> 0 THEN SUBSTRING(INPUT + FROM (bytearray_position(INPUT, 0x869584cd) + 16) + FOR 20) + WHEN bytearray_position(INPUT, 0xfbc019a7) <> 0 THEN SUBSTRING(INPUT + FROM (bytearray_position(INPUT, 0xfbc019a7 ) + 16) + FOR 20) + END AS affiliate_address, + case when (varbinary_position(input,0x3d8d4082) <> 0 or varbinary_position(input,0x4f948110) <> 0 ) then 1 else 0 end as is_gasless + FROM {{ source('base', 'traces') }} tr + WHERE tr.to IN ( + -- exchange contract + 0xdef1c0ded9bec7f1a1670819833240f027b25eff, + -- forwarder addresses + 0x6958f5e95332d93d21af0d7b9ca85b8212fee0a5, + 0x4aa817c6f383c8e8ae77301d18ce48efb16fd2be, + 0x4ef40d1bf0983899892946830abf99eca2dbc5ce, + -- exchange proxy + 0xdef189deaef76e379df891899eb5a00a94cbc250 + ) + AND ( + bytearray_position(INPUT, 0x869584cd ) <> 0 + OR bytearray_position(INPUT, 0xfbc019a7 ) <> 0 + ) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not is_incremental() %} + AND block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} ) temp - group by tx_hash, block_time + group by tx_hash , is_gasless + ), -ERC20BridgeTransfer as ( - {{ - ERC20BridgeTransfer( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} + +ERC20BridgeTransfer AS ( + SELECT + logs.tx_hash, + logs.block_number AS block_number, + INDEX AS evt_index, + logs.contract_address, + block_time AS block_time, + bytearray_substring(DATA, 142, 20) AS maker, + bytearray_substring(DATA, 172, 20) AS taker, + bytearray_substring(DATA, 14, 20) AS taker_token, + bytearray_substring(DATA, 45, 20) AS maker_token, + bytearray_to_uint256(bytearray_substring(DATA, 77, 20)) AS taker_token_amount_raw, + bytearray_to_uint256(bytearray_substring(DATA, 110, 20)) AS maker_token_amount_raw, + 'ERC20BridgeTransfer' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('base', 'logs') }} logs + INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash + WHERE topic0 = 0x349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9 + + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not is_incremental() %} + AND block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} + ), -BridgeFill as ( - {{ - BridgeFill( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +BridgeFill AS ( + SELECT + logs.tx_hash, + logs.block_number AS block_number, + INDEX AS evt_index, + logs.contract_address, + block_time AS block_time, + bytearray_substring(DATA, 13, 20) AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + bytearray_substring(DATA, 45, 20) AS taker_token, + bytearray_substring(DATA, 77, 20) AS maker_token, + bytearray_to_uint256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, + bytearray_to_uint256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, + 'BridgeFill' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('base', 'logs') }} logs + INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash + WHERE topic0 = 0xff3bc5e46464411f331d1b093e1587d2d1aa667f5618f98a95afc4132709d3a9 + AND contract_address = 0xdb6f1920a889355780af7570773609bd8cb1f498 + + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not is_incremental() %} + AND block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} ), -NewBridgeFill as ( - {{ - NewBridgeFill( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +NewBridgeFill AS ( + SELECT + logs.tx_hash as tx_hash, + logs.block_number AS block_number, + INDEX AS evt_index, + logs.contract_address, + block_time AS block_time, + bytearray_substring(DATA, 13, 20) AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + bytearray_substring(DATA, 45, 20) AS taker_token, + bytearray_substring(DATA, 77, 20) AS maker_token, + bytearray_to_uint256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, + bytearray_to_uint256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, + 'BridgeFill' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('base' ,'logs') }} logs + INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash + WHERE topic0 = 0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8 + AND contract_address = 0xdb6f1920a889355780af7570773609bd8cb1f498 + + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not is_incremental() %} + AND block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} ), + all_tx AS ( + SELECT * FROM ERC20BridgeTransfer - UNION ALL - SELECT * + UNION ALL SELECT * FROM BridgeFill UNION ALL SELECT * FROM NewBridgeFill -), -tbl_trade_details AS ( - {{ - trade_details( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} + + ) -select * from tbl_trade_details -order by block_time desc \ No newline at end of file + +SELECT + all_tx.tx_hash, + all_tx.block_number, + all_tx.evt_index, + all_tx.contract_address, + all_tx.block_time, + cast(date_trunc('day', all_tx.block_time) AS date) AS block_date, + cast(date_trunc('month', all_tx.block_time) AS date) AS block_month, + maker, + CASE + WHEN is_gasless = 1 then case when (varbinary_substring(data,177,19) ) = 0x00000000000000000000000000000000000000 then varbinary_substring(data,81,20) else (varbinary_substring(data,177,20) ) end + WHEN taker = 0xdef1c0ded9bec7f1a1670819833240f027b25eff THEN tx."from" + ELSE taker + END AS taker, -- fix the user masked by ProxyContract issue + taker_token, + ts.symbol AS taker_symbol, + maker_token, + ms.symbol AS maker_symbol, + CASE WHEN lower(ts.symbol) > lower(ms.symbol) THEN concat(ms.symbol, '-', ts.symbol) ELSE concat(ts.symbol, '-', ms.symbol) END AS token_pair, + taker_token_amount_raw / pow(10, tp.decimals) AS taker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw / pow(10, mp.decimals) AS maker_token_amount, + maker_token_amount_raw, + all_tx.type, + max(affiliate_address) over (partition by all_tx.tx_hash) as affiliate_address, + swap_flag, + matcha_limit_order_flag, + CASE WHEN maker_token IN (0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca,0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22,0xeb466342c4d449bc9f53a865d5cb90586f405215 ) + THEN (all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price + WHEN taker_token IN (0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca,0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22,0xeb466342c4d449bc9f53a865d5cb90586f405215,0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca ) + THEN (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price + ELSE COALESCE((all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price, (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price) + END AS volume_usd, + tx."from" AS tx_from, + tx.to AS tx_to, + 'base' AS blockchain +FROM all_tx +INNER JOIN {{ source('base', 'transactions')}} tx ON all_tx.tx_hash = tx.hash + +{% if is_incremental() %} +AND {{ incremental_predicate('tx.block_time') }} +{% endif %} +{% if not is_incremental() %} +AND tx.block_time >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} + +LEFT JOIN {{ source('prices', 'usd') }} tp ON date_trunc('minute', all_tx.block_time) = tp.minute +AND CASE + WHEN all_tx.taker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE all_tx.taker_token + END = tp.contract_address +AND tp.blockchain = 'base' + +{% if is_incremental() %} +AND {{ incremental_predicate('tp.minute') }} +{% endif %} +{% if not is_incremental() %} +AND tp.minute >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} + +LEFT JOIN {{ source('prices', 'usd') }} mp ON DATE_TRUNC('minute', all_tx.block_time) = mp.minute +AND CASE + WHEN all_tx.maker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE all_tx.maker_token + END = mp.contract_address +AND mp.blockchain = 'base' + +{% if is_incremental() %} +AND {{ incremental_predicate('mp.minute') }} +{% endif %} +{% if not is_incremental() %} +AND mp.minute >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} + +LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ts ON ts.contract_address = taker_token and ts.blockchain = 'base' +LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ms ON ms.contract_address = maker_token and ms.blockchain = 'base' \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql new file mode 100644 index 00000000000..e7f7dd0ddbd --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_api_fills_deduped.sql @@ -0,0 +1,102 @@ +{{ config( + + schema = 'zeroex_base', + alias = 'api_fills_deduped', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set zeroex_v3_start_date = '2019-12-01' %} + +WITH fills_with_tx_fill_number +AS +( + SELECT row_number() OVER ( partition BY tx_hash ORDER BY evt_index ASC ) AS tx_fill_number + , * + FROM {{ ref('zeroex_base_api_fills') }} + WHERE 1=1 + AND swap_flag = true + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not is_incremental() %} + AND block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} +) +, fills_first_last +AS +( + SELECT CASE + WHEN a.taker_token = c.maker_token AND a.taker_token_amount_raw = c.maker_token_amount_raw THEN 0 + ELSE 1 END AS taker_consider_flag--from + , CASE + WHEN a.maker_token = b.taker_token AND a.maker_token_amount_raw = b.taker_token_amount_raw THEN 0 + ELSE 1 END AS maker_consider_flag + , SUM(CASE + WHEN a.maker_token = b.taker_token AND a.maker_token_amount_raw = b.taker_token_amount_raw THEN 0 + ELSE 1 END) OVER (PARTITION BY a.tx_hash ORDER BY a.evt_index DESC) hop_count + , a.* + FROM fills_with_tx_fill_number a + LEFT JOIN fills_with_tx_fill_number b ON (a.tx_hash = b.tx_hash AND a.tx_fill_number = b.tx_fill_number - 1) + LEFT JOIN fills_with_tx_fill_number c ON (a.tx_hash = c.tx_hash AND a.tx_fill_number = c.tx_fill_number + 1) +) +, deduped_bridge_fills +AS +( + SELECT tx_hash + , MAX(evt_index) AS evt_index + , MAX(affiliate_address) AS affiliate_address + , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_token END ) AS taker_token + , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token END ) AS maker_token + , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_symbol END ) AS taker_symbol + , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_symbol END ) AS maker_symbol + , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_token_amount END) AS taker_token_amount + , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token_amount END) AS maker_token_amount + , MAX(CASE WHEN taker_consider_flag = 0 THEN NULL ELSE taker_token_amount_raw END) AS taker_token_amount_raw + , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token_amount_raw END) AS maker_token_amount_raw + , COUNT(*) AS fills_within + FROM fills_first_last a + GROUP BY tx_hash,hop_count +) +SELECT a.blockchain + , '0x API' as project + , cast('1' as varchar(10)) as version + + , a.block_date + , a.block_month + , a.block_time + , b.taker_symbol AS taker_symbol + , b.maker_symbol AS maker_symbol + , CASE + WHEN LOWER(b.taker_symbol) > LOWER(b.maker_symbol) + THEN CONCAT(COALESCE(b.maker_symbol, ''), '-', COALESCE(b.taker_symbol, '')) + ELSE CONCAT(COALESCE(b.taker_symbol, ''), '-', COALESCE(b.maker_symbol, '')) + END AS token_pair + , b.taker_token_amount + , b.maker_token_amount + , b.taker_token_amount_raw AS taker_token_amount_raw + , b.maker_token_amount_raw AS maker_token_amount_raw + , a.volume_usd + , b.taker_token + , b.maker_token + , a.taker + , a.maker + , a.affiliate_address + , a.tx_hash + , a.tx_from + , a.tx_to + , b.evt_index + , ARRAY[-1] AS trace_address + , a.type + , a.swap_flag + , b.fills_within + , a.contract_address +FROM fills_with_tx_fill_number a +INNER JOIN deduped_bridge_fills b + ON a.tx_hash = b.tx_hash AND a.evt_index = b.evt_index \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml index a0212b1a160..a6c1b0f74b8 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_base_schema.yml @@ -82,7 +82,7 @@ models: name: blockchain description: "Blockchain which the aggregator project is deployed" - - name: zeroex_v1_base_deduped_trades + - name: zeroex_base_api_fills_deduped meta: blockchain: base project: zeroex diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql deleted file mode 100644 index 5713bc0b849..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v1_base_deduped_trades.sql +++ /dev/null @@ -1,30 +0,0 @@ -{{ config( - schema = 'zeroex_v1_base', - alias = 'deduped_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set zeroex_v3_start_date = '2019-12-01' %} -{% set blockchain = 'base' %} - -WITH -deduped_trades as ( - {{ - zeroex_v1_deduped_trades( - blockchain = blockchain, - start_date = zeroex_v3_start_date - - ) - }} - -) -select - * -from deduped_trades diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql index 459792679f8..814f58dca9c 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills.sql @@ -13,121 +13,405 @@ {% set zeroex_v3_start_date = '2019-12-01' %} {% set zeroex_v4_start_date = '2021-01-06' %} -{% set blockchain = 'ethereum' %} +-- Test Query here: https://dune.com/queries/1330551 WITH zeroex_tx AS ( - SELECT tx_hash, - block_time as block_time, + SELECT tx_hash, + block_time as block_time, max(affiliate_address) as affiliate_address, - max(is_gasless) as is_gasless - + max(is_gasless) as is_gasless FROM ( - {{ - zeroex_evt_fills_txs( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date, - ) - }} - - union - - {{ - zeroex_v1_txs( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date, - ) - }} + SELECT v3.evt_tx_hash AS tx_hash, + CASE + WHEN takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc THEN takerAddress + ELSE NULL + END AS affiliate_address, + null as is_gasless, + evt_block_time as block_time + + FROM {{ source('zeroex_v3_ethereum', 'Exchange_evt_Fill') }} v3 + WHERE ( -- nuo + v3.takerAddress = 0x63305728359c088a52b0b0eeec235db4d31a67fc + OR -- contains a bridge order + ( + v3.feeRecipientAddress = 0x1000000000000000000000000000000000000011 + AND bytearray_substring(v3.makerAssetData, 1, 4) = 0xdc1600f3 + ) + ) + + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} + + UNION ALL + SELECT tr.tx_hash, + CASE + WHEN bytearray_position(INPUT, 0x869584cd ) <> 0 THEN SUBSTRING(INPUT + FROM (bytearray_position(INPUT, 0x869584cd) + 16) + FOR 20) + WHEN bytearray_position(INPUT, 0xfbc019a7) <> 0 THEN SUBSTRING(INPUT + FROM (bytearray_position(INPUT, 0xfbc019a7 ) + 16) + FOR 20) + END AS affiliate_address, + case when (varbinary_position(input,0x3d8d4082) <> 0 or varbinary_position(input,0x4f948110) <> 0 ) then 1 end as is_gasless, + block_time + FROM {{ source('ethereum', 'traces') }} tr + WHERE tr.to IN ( + -- exchange contract + 0x61935cbdd02287b511119ddb11aeb42f1593b7ef, + -- forwarder addresses + 0x6958f5e95332d93d21af0d7b9ca85b8212fee0a5, + 0x4aa817c6f383c8e8ae77301d18ce48efb16fd2be, + 0x4ef40d1bf0983899892946830abf99eca2dbc5ce, + -- exchange proxy + 0xdef1c0ded9bec7f1a1670819833240f027b25eff + ) + AND ( + bytearray_position(INPUT, 0x869584cd ) <> 0 + OR bytearray_position(INPUT, 0xfbc019a7 ) <> 0 + ) + + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% endif %} + {% if not is_incremental() %} + AND block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} ) temp group by tx_hash, block_time + ), -v3_fills_no_bridge as ( - {{ - v3_fills_no_bridge( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} +v3_fills_no_bridge AS ( + SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + evt_block_time AS block_time, + fills.makerAddress AS maker, + fills.takerAddress AS taker, + bytearray_substring(fills.takerAssetData, 17, 20) AS taker_token, + bytearray_substring(fills.makerAssetData, 17, 20) AS maker_token, + cast(fills.takerAssetFilledAmount as int256) AS taker_token_amount_raw, + cast(fills.makerAssetFilledAmount as int256)AS maker_token_amount_raw, + 'Fill' AS type, + COALESCE(zeroex_tx.affiliate_address, fills.feeRecipientAddress) AS affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + (fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed) AS matcha_limit_order_flag, + is_gasless + FROM {{ source('zeroex_v3_ethereum', 'Exchange_evt_Fill') }} fills + INNER JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time + WHERE (bytearray_substring(makerAssetData, 1, 4) <> 0xdc1600f3) + AND (zeroex_tx.tx_hash IS NOT NULL + OR fills.feeRecipientAddress = 0x86003b044f70dac0abc80ac8957305b6370893ed) + + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} + ), -v4_rfq_fills_no_bridge as ( - {{ - v4_rfq_fills_no_bridge( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +v4_rfq_fills_no_bridge AS ( + SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + fills.evt_block_time AS block_time, + fills.maker AS maker, + fills.taker AS taker, + fills.takerToken AS taker_token, + fills.makerToken AS maker_token, + cast(fills.takerTokenFilledAmount as int256) AS taker_token_amount_raw, + cast(fills.makerTokenFilledAmount as int256) AS maker_token_amount_raw, + 'RfqOrderFilled' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_RfqOrderFilled') }} fills + LEFT JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time + + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} ), -v4_limit_fills_no_bridge as ( - {{ - v4_limit_fills_no_bridge( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +v4_limit_fills_no_bridge AS ( + SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + fills.evt_block_time AS block_time, + fills.maker AS maker, + fills.taker AS taker, + fills.takerToken AS taker_token, + fills.makerToken AS maker_token, + cast(fills.takerTokenFilledAmount as int256) AS taker_token_amount_raw, + cast(fills.makerTokenFilledAmount as int256) AS maker_token_amount_raw, + 'LimitOrderFilled' AS type, + COALESCE(zeroex_tx.affiliate_address, fills.feeRecipient) AS affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + (fills.feeRecipient in + (0x9b858be6e3047d88820f439b240deac2418a2551,0x86003b044f70dac0abc80ac8957305b6370893ed,0x5bc2419a087666148bfbe1361ae6c06d240c6131)) + AS matcha_limit_order_flag, + is_gasless + FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_LimitOrderFilled') }} fills + LEFT JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time + + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} ), -otc_fills as ( - {{ - otc_fills( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +otc_fills AS ( + SELECT + fills.evt_tx_hash AS tx_hash, + fills.evt_index, + fills.contract_address, + fills.evt_block_time AS block_time, + fills.maker AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + fills.takerToken AS taker_token, + fills.makerToken AS maker_token, + cast(fills.takerTokenFilledAmount as int256) AS taker_token_amount_raw, + cast(fills.makerTokenFilledAmount as int256) AS maker_token_amount_raw, + 'OtcOrderFilled' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + (zeroex_tx.tx_hash IS NOT NULL) AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_OtcOrderFilled') }} fills + LEFT JOIN zeroex_tx ON zeroex_tx.tx_hash = fills.evt_tx_hash and fills.evt_block_time = zeroex_tx.block_time + + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} + ), -ERC20BridgeTransfer as ( - {{ - ERC20BridgeTransfer( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} +ERC20BridgeTransfer AS ( + SELECT + logs.tx_hash, + INDEX AS evt_index, + logs.contract_address, + logs.block_time AS block_time, + bytearray_substring(DATA, 141, 20) AS maker, + bytearray_substring(DATA, 173, 20) AS taker, + bytearray_substring(DATA, 13, 20) AS taker_token, + bytearray_substring(DATA, 45, 20) AS maker_token, + bytearray_to_int256(bytearray_substring(DATA, 77, 20)) AS taker_token_amount_raw, + bytearray_to_int256(bytearray_substring(DATA, 109, 20)) AS maker_token_amount_raw, + 'ERC20BridgeTransfer' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('ethereum', 'logs') }} logs + JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash and logs.block_time = zeroex_tx.block_time + WHERE topic0 = 0x349fc08071558d8e3aa92dec9396e4e9f2dfecd6bb9065759d1932e7da43b8a9 + + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% endif %} + {% if not is_incremental() %} + AND logs.block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} + ), -BridgeFill as ( - {{ - BridgeFill( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +BridgeFill AS ( + SELECT + logs.tx_hash, + INDEX AS evt_index, + logs.contract_address, + logs.block_time AS block_time, + bytearray_substring(DATA, 13, 20) AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + bytearray_substring(DATA, 45, 20) AS taker_token, + bytearray_substring(DATA, 77, 20) AS maker_token, + bytearray_to_int256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, + bytearray_to_int256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, + 'BridgeFill' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('ethereum', 'logs') }} logs + JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash and logs.block_time = zeroex_tx.block_time + WHERE topic0 = 0xff3bc5e46464411f331d1b093e1587d2d1aa667f5618f98a95afc4132709d3a9 + AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 + + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% endif %} + {% if not is_incremental() %} + AND logs.block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} ), -NewBridgeFill as ( - {{ - NewBridgeFill( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +NewBridgeFill AS ( + SELECT + logs.tx_hash, + INDEX AS evt_index, + logs.contract_address, + logs.block_time AS block_time, + bytearray_substring(DATA, 13, 20) AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff AS taker, + bytearray_substring(DATA, 45, 20) AS taker_token, + bytearray_substring(DATA, 77, 20) AS maker_token, + bytearray_to_int256(bytearray_substring(DATA, 109, 20)) AS taker_token_amount_raw, + bytearray_to_int256(bytearray_substring(DATA, 141, 20)) AS maker_token_amount_raw, + 'NewBridgeFill' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('ethereum' ,'logs') }} logs + JOIN zeroex_tx ON zeroex_tx.tx_hash = logs.tx_hash and logs.block_time = zeroex_tx.block_time + WHERE topic0 = 0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8 + AND contract_address = 0x22f9dcf4647084d6c31b2765f6910cd85c178c18 + + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% endif %} + {% if not is_incremental() %} + AND logs.block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} ), -direct_PLP as ( - {{ - direct_PLP( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} +direct_PLP AS ( + SELECT + plp.evt_tx_hash, + plp.evt_index AS evt_index, + plp.contract_address, + plp.evt_block_time AS block_time, + provider AS maker, + recipient AS taker, + inputToken AS taker_token, + outputToken AS maker_token, + cast(inputTokenAmount as int256) AS taker_token_amount_raw, + cast(outputTokenAmount as int256)AS maker_token_amount_raw, + 'LiquidityProviderSwap' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('zeroex_ethereum', 'ExchangeProxy_evt_LiquidityProviderSwap') }} plp + JOIN zeroex_tx ON zeroex_tx.tx_hash = plp.evt_tx_hash and plp.evt_block_time = zeroex_tx.block_time + + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} + ), -direct_uniswapv2 as ( - {{ - direct_uniswapv2( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} +direct_uniswapv2 AS ( + SELECT + swap.evt_tx_hash AS tx_hash, + swap.evt_index, + swap.contract_address, + swap.evt_block_time AS block_time, + swap.contract_address AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff as taker, + CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token0 ELSE pair.token1 END AS taker_token, + CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token1 ELSE pair.token0 END AS maker_token, + CASE WHEN swap.amount0In > swap.amount0Out THEN + CASE WHEN swap.amount0In >= swap.amount0Out THEN cast(swap.amount0In - swap.amount0Out as int256) ELSE cast(0 as int256) END ELSE + CASE WHEN swap.amount1In >= swap.amount1Out THEN cast(swap.amount1In - swap.amount1Out as int256) ELSE cast(0 as int256) END END AS taker_token_amount_raw, + CASE WHEN swap.amount0In > swap.amount0Out THEN + CASE WHEN swap.amount1Out >= swap.amount1In THEN cast(swap.amount1Out - swap.amount1In as int256) ELSE cast(0 as int256) END ELSE + CASE WHEN swap.amount0Out >= swap.amount0In THEN cast(swap.amount0Out - swap.amount0In as int256) ELSE cast(0 as int256) END END AS maker_token_amount_raw, + 'Uniswap V2 Direct' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('uniswap_v2_ethereum', 'Pair_evt_Swap') }} swap + LEFT JOIN {{ source('uniswap_v2_ethereum', 'Factory_evt_PairCreated') }} pair ON pair.pair = swap.contract_address + JOIN zeroex_tx ON zeroex_tx.tx_hash = swap.evt_tx_hash and swap.evt_block_time = zeroex_tx.block_time + WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff + + {% if is_incremental() %} + AND {{ incremental_predicate('swap.evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND swap.evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} + ), -direct_sushiswap as ( - {{ - direct_sushiswap( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} +direct_sushiswap AS ( + SELECT + swap.evt_tx_hash AS tx_hash, + swap.evt_index, + swap.contract_address, + swap.evt_block_time AS block_time, + swap.contract_address AS maker, + LAST_VALUE(swap.to) OVER (PARTITION BY swap.evt_tx_hash ORDER BY swap.evt_index) AS taker, + CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token0 ELSE pair.token1 END AS taker_token, + CASE WHEN swap.amount0In > swap.amount0Out THEN pair.token1 ELSE pair.token0 END AS maker_token, + CASE WHEN swap.amount0In > swap.amount0Out THEN + CASE WHEN swap.amount0In >= swap.amount0Out THEN cast(swap.amount0In - swap.amount0Out as int256) ELSE cast(0 as int256) END ELSE + CASE WHEN swap.amount1In >= swap.amount1Out THEN cast(swap.amount1In - swap.amount1Out as int256) ELSE cast(0 as int256) END END AS taker_token_amount_raw, + CASE WHEN swap.amount0In > swap.amount0Out THEN + CASE WHEN swap.amount1Out >= swap.amount1In THEN cast(swap.amount1Out - swap.amount1In as int256) ELSE cast(0 as int256) END ELSE + CASE WHEN swap.amount0Out >= swap.amount0In THEN cast(swap.amount0Out - swap.amount0In as int256) ELSE cast(0 as int256) END END AS maker_token_amount_raw, + + 'Sushiswap Direct' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('sushi_ethereum', 'Pair_evt_Swap') }} swap + LEFT JOIN {{ source('sushi_ethereum', 'Factory_evt_PairCreated') }} pair ON pair.pair = swap.contract_address + JOIN zeroex_tx ON zeroex_tx.tx_hash = swap.evt_tx_hash and swap.evt_block_time = zeroex_tx.block_time + WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff + + {% if is_incremental() %} + AND {{ incremental_predicate('swap.evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND swap.evt_block_time >= cast('{{zeroex_v3_start_date}}' as date) + {% endif %} ), -direct_uniswapv3 as ( - {{ - direct_uniswapv3( - blockchain = blockchain, - zeroex_v4_start_date = zeroex_v4_start_date - ) - }} +direct_uniswapv3 AS ( + SELECT + swap.evt_tx_hash AS tx_hash, + swap.evt_index, + swap.contract_address, + swap.evt_block_time AS block_time, + swap.contract_address AS maker, + 0xdef1c0ded9bec7f1a1670819833240f027b25eff as taker, + CASE WHEN amount0 < cast(0 as int256) THEN pair.token1 ELSE pair.token0 END AS taker_token, + CASE WHEN amount0 < cast(0 as int256) THEN pair.token0 ELSE pair.token1 END AS maker_token, + CASE WHEN amount0 < cast(0 as int256) THEN ABS(swap.amount1) ELSE ABS(swap.amount0) END AS taker_token_amount_raw, + CASE WHEN amount0 < cast(0 as int256) THEN ABS(swap.amount0) ELSE ABS(swap.amount1) END AS maker_token_amount_raw, + 'Uniswap V3 Direct' AS type, + zeroex_tx.affiliate_address AS affiliate_address, + TRUE AS swap_flag, + FALSE AS matcha_limit_order_flag, + is_gasless + FROM {{ source('uniswap_v3_ethereum', 'Pair_evt_Swap') }} swap + LEFT JOIN {{ source('uniswap_v3_ethereum', 'Factory_evt_PoolCreated') }} pair ON pair.pool = swap.contract_address + JOIN zeroex_tx ON zeroex_tx.tx_hash = swap.evt_tx_hash and swap.evt_block_time = zeroex_tx.block_time + WHERE sender = 0xdef1c0ded9bec7f1a1670819833240f027b25eff + + {% if is_incremental() %} + AND {{ incremental_predicate('swap.evt_block_time') }} + {% endif %} + {% if not is_incremental() %} + AND swap.evt_block_time >= cast('{{zeroex_v4_start_date}}' as date) + {% endif %} + ), all_tx AS ( SELECT * @@ -152,14 +436,86 @@ all_tx AS ( FROM v4_limit_fills_no_bridge UNION ALL SELECT * FROM otc_fills -), -tbl_trade_details AS ( - {{ - trade_details( - blockchain = blockchain, - zeroex_v3_start_date = zeroex_v3_start_date - ) - }} ) -select * from tbl_trade_details -order by block_time desc \ No newline at end of file + +SELECT + all_tx.tx_hash, + tx.block_number, + all_tx.evt_index, + all_tx.contract_address, + all_tx.block_time, + cast(date_trunc('day', all_tx.block_time) AS date) AS block_date, + cast(date_trunc('month', all_tx.block_time) AS date) AS block_month, + maker, + CASE + when is_gasless = 1 and varbinary_position (data, 0x3a46c4e1) <> 0 then varbinary_substring(data,81,20) + when is_gasless = 1 and varbinary_position (data, 0xa98fcbf1) <> 0 then varbinary_substring(data,81,20) + when is_gasless = 1 and varbinary_position (data, 0x3d8d4082) <> 0 then varbinary_substring(data,177,20) + + WHEN taker = 0xdef1c0ded9bec7f1a1670819833240f027b25eff THEN tx."from" + ELSE taker + END AS taker, -- fix the user masked by ProxyContract issue + taker_token, + ts.symbol AS taker_symbol, + maker_token, + ms.symbol AS maker_symbol, + CASE WHEN lower(ts.symbol) > lower(ms.symbol) THEN concat(ms.symbol, '-', ts.symbol) ELSE concat(ts.symbol, '-', ms.symbol) END AS token_pair, + taker_token_amount_raw / pow(10, tp.decimals) AS taker_token_amount, + cast(taker_token_amount_raw as uint256) as taker_token_amount_raw, + maker_token_amount_raw / pow(10, mp.decimals) AS maker_token_amount, + cast(maker_token_amount_raw as uint256) as maker_token_amount_raw, + all_tx.type, + max(affiliate_address) over (partition by all_tx.tx_hash) as affiliate_address, + swap_flag, + matcha_limit_order_flag, + CASE WHEN maker_token IN (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xdac17f958d2ee523a2206206994597c13d831ec7, + 0x4fabb145d64652a948d72533023f6e7a623c7c53,0x6b175474e89094c44da98b954eedeac495271d0f,0xae7ab96520de3a18e5e111b5eaab095312d7fe84) AND mp.price IS NOT NULL + THEN (all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price + WHEN taker_token IN (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xdac17f958d2ee523a2206206994597c13d831ec7, + 0x4fabb145d64652a948d72533023f6e7a623c7c53,0x6b175474e89094c44da98b954eedeac495271d0f,0xae7ab96520de3a18e5e111b5eaab095312d7fe84) AND tp.price IS NOT NULL + THEN (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price + ELSE COALESCE((all_tx.maker_token_amount_raw / pow(10, mp.decimals)) * mp.price, (all_tx.taker_token_amount_raw / pow(10, tp.decimals)) * tp.price) + END AS volume_usd, + tx."from" AS tx_from, + tx.to AS tx_to, + 'ethereum' AS blockchain +FROM all_tx +INNER JOIN {{ source('ethereum', 'transactions')}} tx ON all_tx.tx_hash = tx.hash and all_tx.block_time = tx.block_time + +{% if is_incremental() %} +AND {{ incremental_predicate('tx.block_time') }} +{% endif %} +{% if not is_incremental() %} +AND tx.block_time >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} + +LEFT JOIN {{ source('prices', 'usd') }} tp ON date_trunc('minute', all_tx.block_time) = tp.minute +AND CASE + WHEN all_tx.taker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE all_tx.taker_token + END = tp.contract_address +AND tp.blockchain = 'ethereum' + +{% if is_incremental() %} +AND {{ incremental_predicate('tp.minute') }} +{% endif %} +{% if not is_incremental() %} +AND tp.minute >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} + +LEFT JOIN {{ source('prices', 'usd') }} mp ON DATE_TRUNC('minute', all_tx.block_time) = mp.minute +AND CASE + WHEN all_tx.maker_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE all_tx.maker_token + END = mp.contract_address +AND mp.blockchain = 'ethereum' + +{% if is_incremental() %} +AND {{ incremental_predicate('mp.minute') }} +{% endif %} +{% if not is_incremental() %} +AND mp.minute >= cast('{{zeroex_v3_start_date}}' as date) +{% endif %} + +LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ts ON ts.contract_address = taker_token and ts.blockchain = 'ethereum' +LEFT OUTER JOIN {{ source('tokens', 'erc20') }} ms ON ms.contract_address = maker_token and ms.blockchain = 'ethereum' diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql similarity index 80% rename from dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql rename to dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql index 76f95860aaa..9a23ab938c9 100644 --- a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v1_deduped_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_api_fills_deduped.sql @@ -1,20 +1,36 @@ -{% macro zeroex_v1_deduped_trades(blockchain, start_date) %} +{{ config( -{% set table_name = 'zeroex_' ~ blockchain ~ '_api_fills' %} + schema = 'zeroex_ethereum', + alias = 'api_fills_deduped', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{% set zeroex_v3_start_date = '2019-12-01' %} +--the code used to create the data for the insertion into the dex.trades table +--this code is also the deduped version for the fills tables. +--only the data for 0x API fills. +--dependent on:zeroex_ethereum.api_fills. WITH fills_with_tx_fill_number AS ( SELECT row_number() OVER ( partition BY tx_hash ORDER BY evt_index ASC ) AS tx_fill_number , * - FROM {{ ref(table_name) }} + FROM {{ ref('zeroex_ethereum_api_fills') }} WHERE 1=1 AND swap_flag = true {% if is_incremental() %} AND {{ incremental_predicate('block_time') }} {% endif %} {% if not is_incremental() %} - AND block_time >= DATE '{{start_date}}' + AND block_time >= cast('{{zeroex_v3_start_date}}' as date) {% endif %} ) , fills_first_last @@ -50,7 +66,7 @@ AS , MAX(CASE WHEN maker_consider_flag = 0 THEN NULL ELSE maker_token_amount_raw END) AS maker_token_amount_raw , COUNT(*) AS fills_within FROM fills_first_last a - GROUP BY tx_hash + GROUP BY tx_hash,hop_count ) SELECT a.blockchain , '0x API' as project @@ -82,6 +98,4 @@ SELECT a.blockchain , a.contract_address FROM fills_with_tx_fill_number a INNER JOIN deduped_bridge_fills b - ON a.tx_hash = b.tx_hash AND a.evt_index = b.evt_index -{% endmacro %} - + ON a.tx_hash = b.tx_hash AND a.evt_index = b.evt_index \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml index 134e8bc863f..1337fcc8435 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_schema.yml @@ -5,7 +5,7 @@ models: meta: blockchain: ethereum project: zeroex - contributors: danning.sui, bakabhai993, hosuke, rantum + contributors: danning.sui, bakabhai993, hosuke config: tags: ['ethereum','0x','dex_aggregator','dex','aggregator'] description: > @@ -106,11 +106,11 @@ models: name: blockchain - - name: zeroex_v1_ethereum_deduped_trades + - name: zeroex_ethereum_api_fills_deduped meta: blockchain: ethereum project: zeroex - contributors: bakabhai993, rantum + contributors: bakabhai993 config: tags: ['ethereum','0x','dex_aggregator','dex','aggregator'] description: > diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql deleted file mode 100644 index 5b0debbdab0..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v1_ethereum_deduped_trades.sql +++ /dev/null @@ -1,30 +0,0 @@ -{{ config( - schema = 'zeroex_v1_ethereum', - alias = 'deduped_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] - ) -}} - -{% set zeroex_v3_start_date = '2019-12-01' %} -{% set blockchain = 'ethereum' %} - -WITH -deduped_trades as ( - {{ - zeroex_v1_deduped_trades( - blockchain = blockchain, - start_date = zeroex_v3_start_date - - ) - }} - -) -select - * -from deduped_trades diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 2b00a9a3f86..07f52a7d2f9 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -12,9 +12,9 @@ {% set zeroex_models = [ ref('zeroex_arbitrum_api_fills_deduped') ,ref('zeroex_avalanche_c_api_fills_deduped') - ,ref('zeroex_v1_base_deduped_trades') + ,ref('zeroex_base_api_fills_deduped') ,ref('zeroex_celo_api_fills_deduped') - ,ref('zeroex_v1_ethereum_deduped_trades') + ,ref('zeroex_ethereum_api_fills_deduped') ,ref('zeroex_fantom_api_fills_deduped') ,ref('zeroex_optimism_api_fills_deduped') ,ref('zeroex_polygon_api_fills_deduped') From 5c6b0869d998d22a5053decb2e36518d1bbe5a2f Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:22:48 -0500 Subject: [PATCH 25/68] Revert 0x changes: downstream is broken (#7189) * Revert "zid selection update (#7178)" This reverts commit 11e45bbc1610577673823eb3df4b19a463ee683a. * Revert "zeroex - v2 macro model replacements (#7166)" This reverts commit 51d47e46dde928ddab907220749908365214da21. * Revert "add zeroex_v2_mode trades (#7167)" This reverts commit 241e6a344c87b35d756878bd1f541a2d57041dc0. --- .../models/_project/zeroex/zeroex_v2.sql | 73 +++-- .../arbitrum/zeroex_arbitrum_schema.yml | 4 +- .../zeroex_arbitrum_settler_trades.sql | 310 ++++++++++++++++++ .../arbitrum/zeroex_v2_arbitrum_trades.sql | 71 ---- .../avalanche_c/zeroex_avalanche_c_schema.yml | 4 +- .../zeroex_avalanche_c_settler_trades.sql | 310 ++++++++++++++++++ .../zeroex_v2_avalanche_c_trades.sql | 70 ---- .../zeroex/base/zeroex_v2_base_trades.sql | 13 +- .../zeroex/blast/zeroex_blast_schema.yml | 4 +- .../blast/zeroex_blast_settler_trades.sql | 301 +++++++++++++++++ .../zeroex/blast/zeroex_v2_blast_trades.sql | 71 ---- .../ethereum/zeroex_v2_ethereum_trades.sql | 13 +- .../zeroex/mantle/zeroex_mantle_schema.yml | 4 +- .../mantle/zeroex_mantle_settler_trades.sql | 296 +++++++++++++++++ .../zeroex/mantle/zeroex_v2_mantle_trades.sql | 71 ---- .../zeroex/mode/zeroex_mode_schema.yml | 111 ------- .../zeroex/mode/zeroex_v2_mode_trades.sql | 61 ---- .../polygon/zeroex_v2_polygon_trades.sql | 13 +- .../zeroex/zeroex_api_fills_deduped.sql | 11 +- .../models/_projects/zeroex/zeroex_schema.yml | 2 +- .../seeds/_project/zeroex/mode/_schema.yml | 11 - .../mode/zeroex_v2_mode_trades_sample.csv | 4 - 22 files changed, 1275 insertions(+), 553 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql delete mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml delete mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql index 601061e71ba..4589ba128b7 100644 --- a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql +++ b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql @@ -1,15 +1,15 @@ {% macro zeroex_settler_txs_cte(blockchain, start_date) %} WITH tbl_addresses AS ( SELECT - varbinary_to_int256 (topic1) as token_id, - bytearray_substring(logs.topic3,13,20) as settler_address, + token_id, + "to" AS settler_address, block_time AS begin_block_time, block_number AS begin_block_number FROM - {{ source( blockchain, 'logs') }} + {{ source('nft', 'transfers') }} WHERE contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - and topic0 = 0xaa94c583a45742b26ac5274d230aea34ab334ed5722264aa5673010e612bc0b2 + AND blockchain = '{{ blockchain }}' ), tbl_end_times AS ( @@ -38,8 +38,7 @@ settler_trace_data AS ( "to" AS contract_address, varbinary_substring(input,1,4) AS method_id, varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address, - row_number() OVER (PARTITION BY tr.tx_hash ORDER BY trace_address) AS rn + a.settler_address FROM {{ source(blockchain, 'traces') }} AS tr JOIN @@ -62,14 +61,15 @@ settler_txs AS ( method_id, contract_address, settler_address, - varbinary_substring(tracker,2,12) AS zid, + MAX(varbinary_substring(tracker,2,12)) AS zid, CASE - WHEN method_id = 0x1fff991f THEN varbinary_substring(tracker,14,3) - WHEN method_id = 0xfd3ad6d4 THEN varbinary_substring(tracker,13,3) + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) END AS tag FROM settler_trace_data - WHERE rn = 1 + GROUP BY + 1,2,3,4,5,6 ) SELECT * FROM settler_txs @@ -171,6 +171,30 @@ prices AS ( {% endif %} ), +fills AS ( + WITH signatures AS ( + SELECT DISTINCT signature + FROM {{ source(blockchain, 'logs_decoded') }} l + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{start_date}}' + {% endif %} + ) + SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within + FROM {{ source(blockchain, 'logs') }} l + JOIN signatures ON signature = topic0 + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + {% if is_incremental() %} + WHERE {{ incremental_predicate('l.block_time') }} + {% else %} + WHERE l.block_time >= DATE '{{start_date}}' + {% endif %} + GROUP BY 1,2,3 +), + results AS ( SELECT '{{blockchain}}' AS blockchain, @@ -200,7 +224,8 @@ results AS ( maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS token_bought_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag + tag, + fills_within FROM tbl_trades trades JOIN @@ -210,6 +235,8 @@ results AS ( {% else %} AND tr.block_time >= DATE '{{start_date}}' {% endif %} + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number LEFT JOIN tokens tt ON tt.blockchain = '{{blockchain}}' AND tt.contract_address = taker_token LEFT JOIN @@ -269,28 +296,4 @@ order by block_time desc {% macro zeroex_v2_trades_indirect(blockchain, start_date) %} {{ zeroex_v2_trades(blockchain, start_date, false) }} -{% endmacro %} - -{% macro zeroex_v2_trades_fills_count(blockchain, start_date) %} - WITH signatures AS ( - SELECT DISTINCT signature - FROM {{ source(blockchain, 'logs_decoded') }} l - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{start_date}}' - {% endif %} - ) - SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within - FROM {{ source(blockchain, 'logs') }} l - JOIN signatures ON signature = topic0 - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - {% if is_incremental() %} - WHERE {{ incremental_predicate('l.block_time') }} - {% else %} - WHERE l.block_time >= DATE '{{start_date}}' - {% endif %} - GROUP BY 1,2,3 {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml index 3ca18250dcb..3498e9df2ef 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml @@ -206,7 +206,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_v2_arbitrum_trades + - name: zeroex_arbitrum_settler_trades meta: blockchain: arbitrum project: zeroex @@ -214,7 +214,7 @@ models: config: tags: ['arbitrum','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql new file mode 100644 index 00000000000..815021d5009 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql @@ -0,0 +1,310 @@ +{{ config( + schema = 'zeroex_arbitrum', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'arbitrum' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('arbitrum', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'arbitrum' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address is not null or tr.to in (0x0000000000001fF3684f28c67538d4D072C22734)) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + then 1 end as valid, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('arbitrum', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash + AND logs.block_time = st.block_time + AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = bytearray_substring(logs.topic1,13,20) + or logs.tx_from = bytearray_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'arbitrum' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'arbitrum' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('arbitrum', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellarbitrumToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('arbitrum', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('arbitrum', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'arbitrum' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'arbitrum' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'arbitrum' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'arbitrum' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'arbitrum' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, + 0xaf88d065e77c8cc2239327c5edb3a432268e5831, + 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, + 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, + 0x912ce59144191c1204e64559fe8253a0e49e6548) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, + 0xaf88d065e77c8cc2239327c5edb3a432268e5831, + 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, + 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, + 0x912ce59144191c1204e64559fe8253a0e49e6548) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql deleted file mode 100644 index 95cd5eec698..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_arbitrum', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'arbitrum' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml index 98b01576297..48deac58eea 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml @@ -150,7 +150,7 @@ models: name: fills_within description: "fills in then multihop, if present" - - name: zeroex_v2_avalanche_c_trades + - name: zeroex_avalanche_c_settler_trades meta: blockchain: avalanche_c project: zeroex @@ -158,7 +158,7 @@ models: config: tags: ['avalanche_c','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql new file mode 100644 index 00000000000..4434aa4ad0c --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql @@ -0,0 +1,310 @@ +{{ config( + schema = 'zeroex_avalanche_c', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'avalanche_c' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('avalanche_c', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'avalanche_c' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000005E88410CcDFaDe4a5EfaE4b49562 ) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + then 1 end as valid, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('avalanche_c', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash + AND logs.block_time = st.block_time + AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = bytearray_substring(logs.topic1,13,20) + or logs.tx_from = bytearray_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by valid, index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'avalanche_c' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'avalanche_c' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('avalanche_c', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'Sellavalanche_cToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('avalanche_c', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('avalanche_c', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'avalanche_c' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'avalanche_c' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'avalanche_c' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'avalanche_c' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'avalanche_c' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, + 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, + 0x152b9d0fdc40c096757f570a51e494bd4b943e50, + 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, + 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, + 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, + 0x152b9d0fdc40c096757f570a51e494bd4b943e50, + 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, + 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql deleted file mode 100644 index a24523639a1..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - schema = 'zeroex_v2_avalanche_c', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'avalanche_c' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql index 2dc75f30a85..d69c3174508 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql @@ -46,14 +46,6 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), trade_details as ( {{ zeroex_v2_trades_detail( @@ -65,6 +57,5 @@ trade_details as ( ) select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml index 4361c49a24b..598e21561d9 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_v2_blast_trades + - name: zeroex_blast_settler_trades meta: blockchain: blast project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['blast','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql new file mode 100644 index 00000000000..9fe304e77ba --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql @@ -0,0 +1,301 @@ +{{ config( + schema = 'zeroex_blast', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'blast' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('blast', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'blast' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('blast', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = varbinary_substring(logs.topic1,13,20) + or logs.tx_from = varbinary_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where maker_token != taker_token + ) + select * from tbl_valid_logs + where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'blast' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'blast' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('blast', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellblastToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('blast', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('blast', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'blast' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'blast' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'blast' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'blast' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'blast' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql deleted file mode 100644 index c382761f69d..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_blast', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'blast' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql index 256d8476c7d..ceea2b3d384 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql @@ -46,14 +46,6 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), trade_details as ( {{ zeroex_v2_trades_detail( @@ -65,6 +57,5 @@ trade_details as ( ) select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml index 418999bf150..bbbabcb2e22 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_v2_mantle_trades + - name: zeroex_mantle_settler_trades meta: blockchain: mantle project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['mantle','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql new file mode 100644 index 00000000000..35bd8dc974e --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql @@ -0,0 +1,296 @@ +{{ config( + schema = 'zeroex_mantle', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'mantle' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('mantle', 'traces') }} AS tr + JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'mantle' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0xca11bde05977b3631167028862be2a173976ca11) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('mantle', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where maker_token != taker_token + ) + select * from tbl_valid_logs + where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'mantle' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'mantle' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('mantle', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellmantleToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('mantle', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('mantle', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'mantle' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'mantle' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'mantle' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'mantle' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'mantle' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql deleted file mode 100644 index 88ba80757a3..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_mantle', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'mantle' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml deleted file mode 100644 index 080d07968bf..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml +++ /dev/null @@ -1,111 +0,0 @@ -version: 2 - -models: - - name: zeroex_v2_mode_trades - meta: - blockchain: mode - project: zeroex - contributors: rantum - config: - tags: ['mode','0x','dex_aggregator','dex','aggregator'] - description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - block_month - - block_date - - tx_hash - - evt_index - - check_seed: - seed_file: ref('zeroex_v2_mode_trades_sample') - match_columns: - - tx_hash - check_columns: - - taker - - maker_token - - taker_token - columns: - - &blockchain - name: blockchain - description: "Blockchain which the aggregator project is deployed" - - &block_date - name: block_date - description: "UTC event block date of each trade" - - &block_month - name: block_month - description: "UTC event block month of each trade" - - &block_time - name: block_time - description: "UTC event block time of each trade" - - &taker_symbol - name: taker_symbol - description: "Symbol of the token taker sells" - - &maker_symbol - name: maker_symbol - description: "Symbol of the token taker buys" - - &token_pair - name: token_pair - description: "Token pair traded" - - &taker_token_amount - name: taker_token_amount - description: "The after-decimal amount of the token taker sells" - - &taker_token_amount_raw - name: taker_token_amount_raw - description: "The raw amount of the token taker sells" - - &maker_token_amount - name: maker_token_amount - description: "The after-decimal amount of the token taker buys" - - &maker_token_amount_raw - name: maker_token_amount_raw - description: "The raw amount of the token taker buys" - - &volume_usd - name: volume_usd - description: "Trading volume measured in USD value" - - &taker_token - name: taker_token - description: "Contract address of the token taker sells" - - &maker_token - name: maker_token - description: "Contract address of the token taker buys" - - &maker - name: maker - description: "buyer of the trade" - - &taker - name: taker - description: "seller of the trade" - - &affiliate_address - name: affiliate_address - description: "The recipient address of the affiliate, or the applications that is using 0x API, for receiving affiliate fee" - - &tx_hash - name: tx_hash - description: "Transaction hash of the fill" - - &tx_from - name: tx_from - description: "Address which initiated the trade" - - &tx_to - name: tx_to - description: "Address which received the trade" - - &evt_index - name: evt_index - description: "Index of the corresponding order filled event" - - &type - name: type - description: "The liquidity route the order went thru" - - &swap_flag - name: swap_flag - description: "If the swap was filled/consumed thru 0x API" - - &contract_address - name: contract_address - desctiption: "The address of the contract which fired the fill/swap event" - - &fills_within - name: fills_within - description: "fills in then multihop, if present" - - - - - - - - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql deleted file mode 100644 index 03a74e6e745..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql +++ /dev/null @@ -1,61 +0,0 @@ -{{ config( - schema = 'zeroex_v2_mode', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'mode' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - * - from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql index 6c45e4fbcff..1177284b18a 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql @@ -46,14 +46,6 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), trade_details as ( {{ zeroex_v2_trades_detail( @@ -65,6 +57,5 @@ trade_details as ( ) select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 07f52a7d2f9..51563852cb7 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -1,7 +1,7 @@ {{ config( schema = 'zeroex' , alias = 'api_fills_deduped' - , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle","mode"]\', + , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle"]\', "project", "zeroex", \'["rantum","bakabhai993"]\') }}' @@ -27,13 +27,12 @@ ,ref('zeroex_v2_polygon_trades') ,ref('zeroex_optimism_settler_trades') ,ref('zeroex_bnb_settler_trades') - ,ref('zeroex_v2_avalanche_c_trades') - ,ref('zeroex_v2_arbitrum_trades') + ,ref('zeroex_avalanche_c_settler_trades') + ,ref('zeroex_arbitrum_settler_trades') ,ref('zeroex_scroll_settler_trades') ,ref('zeroex_linea_settler_trades') - ,ref('zeroex_v2_mode_trades') - ,ref('zeroex_v2_blast_trades') - ,ref('zeroex_v2_mantle_trades') + ,ref('zeroex_blast_settler_trades') + ,ref('zeroex_mantle_settler_trades') ] %} diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml index 7cab763d18a..c18ff3eb4d2 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml @@ -105,7 +105,7 @@ models: - name: zeroex_api_fills_deduped meta: - blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast, mantle, mode + blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast, mantle sector: dex project: zeroex contributors: rantum, bakabhai993 diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml b/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml deleted file mode 100644 index 0f47baa5698..00000000000 --- a/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 - -seeds: - - name: zeroex_v2_mode_trades_sample - config: - column_types: - tx_hash: varbinary - taker: varbinary - taker_token: varbinary - maker_token: varbinary - taker_token_amount: double \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv deleted file mode 100644 index 0f4fc0c98d2..00000000000 --- a/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_v2_mode_trades_sample.csv +++ /dev/null @@ -1,4 +0,0 @@ -tx_hash,taker,taker_token,maker_token,taker_token_amount -0xd7ace13835ceb119b071c508e8ee262fcecb5a0f2a1bfdd1b9b1f04afa73d94d,0x44c20316a06371ca5acb975974c18abfa7a14a5a,0xf0f161fda2712db8b566946122a5af183995e2ed,0x4200000000000000000000000000000000000006, -0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x6a660e56fa3b630a786cc4ae98859f8532d03de9,0x2416092f143378750bb29b79ed961ab195cceea5,238973 -0xd84a08f6d48b5c34cde908452602088cdb42beceef29074b8a8d5c7e45f2a3dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x4200000000000000000000000000000000000006,0x6a660e56fa3b630a786cc4ae98859f8532d03de9, From 4f8f21105c2c0df71c4cd4cdbfc818ba32dff987 Mon Sep 17 00:00:00 2001 From: Rantum Date: Tue, 26 Nov 2024 09:44:25 -0800 Subject: [PATCH 26/68] add exclude tag to nft spells (#7196) --- .../_projects/zeroex/ethereum/zeroex_ethereum_nft_fills.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_nft_fills.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_nft_fills.sql index faf0b2ce872..862995c9162 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_nft_fills.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_ethereum_nft_fills.sql @@ -1,4 +1,5 @@ {{ config( + tags=['prod_exclude'], schema = 'zeroex_ethereum', alias = 'nft_fills', materialized='incremental', From bb5853322076986ed1a4ac9b062cb4ed3eac3e26 Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:55:56 +0100 Subject: [PATCH 27/68] Dune index: cleanup models (#7173) * clean up index and stats models * syntax * split out gas fees metrics by chain * syntax fix * syntax fix * split out transactions * setup evm macros * column ref * split out transfers * run CI incremental (revert this before merge) * fix compile * restore stats models * restore stats schemas * Revert "run CI incremental (revert this before merge)" This reverts commit d54411ca923ca766db63920c512c813ef0f8afd2. --- .../sector/metrics/metrics_fees_evm.sql | 18 ++ .../metrics/metrics_transactions_evm.sql | 19 ++ .../sector/metrics/metrics_transfers_evm.sql} | 18 +- .../models/_metrics/dune_index/_schema.yml | 7 +- .../dune_index/metrics_dune_index_daily.sql | 74 +++++- .../dune_index/metrics_dune_index_stats.sql | 2 +- .../models/_metrics/fees/_schema.yml | 20 +- .../_metrics/fees/chains/bitcoin/_schema.yml | 15 ++ .../metrics_bitcoin_gas_fees_daily.sql | 46 ++++ .../_metrics/fees/chains/evm/_schema.yml | 236 +++++++++++++++++ .../evm/metrics_arbitrum_gas_fees_daily.sql | 15 ++ .../metrics_avalanche_c_gas_fees_daily.sql | 15 ++ .../evm/metrics_base_gas_fees_daily.sql | 15 ++ .../evm/metrics_blast_gas_fees_daily.sql | 15 ++ .../chains/evm/metrics_bnb_gas_fees_daily.sql | 15 ++ .../evm/metrics_celo_gas_fees_daily.sql | 15 ++ .../evm/metrics_ethereum_gas_fees_daily.sql | 15 ++ .../evm/metrics_fantom_gas_fees_daily.sql | 15 ++ .../evm/metrics_gnosis_gas_fees_daily.sql | 15 ++ .../evm/metrics_linea_gas_fees_daily.sql | 15 ++ .../evm/metrics_mantle_gas_fees_daily.sql | 15 ++ .../evm/metrics_optimism_gas_fees_daily.sql | 15 ++ .../evm/metrics_polygon_gas_fees_daily.sql | 15 ++ .../evm/metrics_scroll_gas_fees_daily.sql | 15 ++ .../chains/evm/metrics_sei_gas_fees_daily.sql | 15 ++ .../evm/metrics_zkevm_gas_fees_daily.sql | 15 ++ .../evm/metrics_zksync_gas_fees_daily.sql | 15 ++ .../evm/metrics_zora_gas_fees_daily.sql | 15 ++ .../_metrics/fees/chains/solana/_schema.yml | 15 ++ .../solana/metrics_solana_gas_fees_daily.sql | 60 +++++ .../_metrics/fees/chains/tron/_schema.yml | 24 ++ .../tron/metrics_tron_gas_fees_daily.sql | 39 +++ .../{ => chains}/tron/tron_fee_correction.sql | 0 .../fees/metrics_fees_index_daily.sql | 38 --- .../_metrics/fees/metrics_gas_fees_daily.sql | 140 +++------- .../_metrics/fees/metrics_gas_fees_stats.sql | 2 +- .../models/_metrics/fees/tron/_schema.yml | 12 - .../models/_metrics/transactions/_schema.yml | 22 +- .../transactions/chains/bitcoin/_schema.yml | 15 ++ .../metrics_bitcoin_transactions_daily.sql | 26 ++ .../transactions/chains/evm/_schema.yml | 249 ++++++++++++++++++ .../metrics_arbitrum_transactions_daily.sql | 15 ++ ...metrics_avalanche_c_transactions_daily.sql | 15 ++ .../evm/metrics_base_transactions_daily.sql | 15 ++ .../evm/metrics_blast_transactions_daily.sql | 15 ++ .../evm/metrics_bnb_transactions_daily.sql | 15 ++ .../evm/metrics_celo_transactions_daily.sql | 15 ++ .../metrics_ethereum_transactions_daily.sql | 15 ++ .../evm/metrics_fantom_transactions_daily.sql | 15 ++ .../evm/metrics_gnosis_transactions_daily.sql | 15 ++ .../evm/metrics_linea_transactions_daily.sql | 15 ++ .../evm/metrics_mantle_transactions_daily.sql | 15 ++ .../metrics_optimism_transactions_daily.sql | 15 ++ .../metrics_polygon_transactions_daily.sql | 15 ++ .../evm/metrics_scroll_transactions_daily.sql | 15 ++ .../evm/metrics_sei_transactions_daily.sql | 15 ++ .../evm/metrics_tron_transactions_daily.sql | 15 ++ .../evm/metrics_zkevm_transactions_daily.sql | 15 ++ .../evm/metrics_zksync_transactions_daily.sql | 15 ++ .../evm/metrics_zora_transactions_daily.sql | 15 ++ .../transactions/chains/solana/_schema.yml | 15 ++ .../metrics_solana_transactions_daily.sql | 27 ++ .../metrics_transactions_daily.sql | 109 +++----- .../metrics_transactions_index_daily.sql | 38 --- .../metrics_transactions_stats.sql | 2 +- .../models/_metrics/transfers/_schema.yml | 51 +--- .../metrics_bitcoin_transfers_daily.sql} | 6 +- .../_metrics/transfers/chains/evm/_schema.yml | 249 ++++++++++++++++++ .../evm/metrics_arbitrum_transfers_daily.sql | 15 ++ .../metrics_avalanche_c_transfers_daily.sql | 15 ++ .../evm/metrics_base_transfers_daily.sql | 15 ++ .../evm/metrics_blast_transfers_daily.sql | 15 ++ .../evm/metrics_bnb_transfers_daily.sql | 15 ++ .../evm/metrics_celo_transfers_daily.sql | 15 ++ .../evm/metrics_ethereum_transfers_daily.sql | 15 ++ .../evm/metrics_fantom_transfers_daily.sql | 15 ++ .../evm/metrics_gnosis_transfers_daily.sql | 15 ++ .../evm/metrics_linea_transfers_daily.sql | 15 ++ .../evm/metrics_mantle_transfers_daily.sql | 15 ++ .../evm/metrics_optimism_transfers_daily.sql | 15 ++ .../evm/metrics_polygon_transfers_daily.sql | 15 ++ .../evm/metrics_scroll_transfers_daily.sql | 15 ++ .../evm/metrics_sei_transfers_daily.sql | 15 ++ .../evm/metrics_tron_transfers_daily.sql | 15 ++ .../evm/metrics_zkevm_transfers_daily.sql | 15 ++ .../evm/metrics_zksync_transfers_daily.sql | 15 ++ .../evm/metrics_zora_transfers_daily.sql | 15 ++ .../metrics_solana_transfers_daily.sql} | 6 +- .../transfers/metrics_transfers_daily.sql | 69 +++-- .../metrics_transfers_index_daily.sql | 38 --- .../transfers/metrics_transfers_stats.sql | 2 +- 91 files changed, 2103 insertions(+), 446 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_fees_evm.sql create mode 100644 dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transactions_evm.sql rename dbt_subprojects/daily_spellbook/{models/_metrics/transfers/metrics_net_transfers_daily.sql => macros/sector/metrics/metrics_transfers_evm.sql} (88%) create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/metrics_bitcoin_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_arbitrum_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_avalanche_c_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_base_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_blast_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_bnb_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_celo_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ethereum_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_fantom_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_gnosis_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_linea_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_mantle_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_optimism_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_polygon_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_scroll_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_sei_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zkevm_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zksync_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zora_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/metrics_solana_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/metrics_tron_gas_fees_daily.sql rename dbt_subprojects/daily_spellbook/models/_metrics/fees/{ => chains}/tron/tron_fee_correction.sql (100%) delete mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_fees_index_daily.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/tron/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/metrics_bitcoin_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_arbitrum_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_avalanche_c_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_base_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_blast_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_bnb_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_celo_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ethereum_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_fantom_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_gnosis_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_linea_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_mantle_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_optimism_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_polygon_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_scroll_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_sei_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_tron_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zkevm_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zksync_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zora_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/metrics_solana_transactions_daily.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_index_daily.sql rename dbt_subprojects/daily_spellbook/models/_metrics/transfers/{metrics_net_bitcoin_transfers_daily.sql => chains/bitcoin/metrics_bitcoin_transfers_daily.sql} (97%) create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_arbitrum_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_avalanche_c_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_base_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_blast_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_bnb_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_celo_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ethereum_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_fantom_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_gnosis_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_linea_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_mantle_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_optimism_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_polygon_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_scroll_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_sei_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_tron_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zkevm_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zksync_transfers_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zora_transfers_daily.sql rename dbt_subprojects/daily_spellbook/models/_metrics/transfers/{metrics_net_solana_transfers_daily.sql => chains/solana/metrics_solana_transfers_daily.sql} (96%) delete mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_index_daily.sql diff --git a/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_fees_evm.sql b/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_fees_evm.sql new file mode 100644 index 00000000000..412b4c7728d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_fees_evm.sql @@ -0,0 +1,18 @@ +{% macro metrics_fees_evm(blockchain) %} + +select + blockchain + , block_date + , sum(tx_fee_usd) as gas_fees_usd +from + {{ source('gas', 'fees') }} +where blockchain = '{{blockchain}}' +{% if is_incremental() %} +and + {{ incremental_predicate('block_date') }} +{% endif %} +group by + blockchain + ,block_date + +{% endmacro %} diff --git a/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transactions_evm.sql b/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transactions_evm.sql new file mode 100644 index 00000000000..1ac65276fb3 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transactions_evm.sql @@ -0,0 +1,19 @@ +{% macro metrics_transactions_evm(blockchain) %} + +select + blockchain + , block_date + , approx_distinct(tx_hash) as tx_count --max 2% error, which is fine +from + {{ source('tokens', 'transfers') }} +where + blockchain = '{{ blockchain }}' + and amount_usd >=1 + {% if is_incremental() %} + and {{ incremental_predicate('block_date') }} + {% endif %} +group by + blockchain + , block_date + +{% endmacro %} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_transfers_daily.sql b/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transfers_evm.sql similarity index 88% rename from dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_transfers_daily.sql rename to dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transfers_evm.sql index 584a68edc7a..f96fdd425c8 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_transfers_daily.sql +++ b/dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transfers_evm.sql @@ -1,13 +1,4 @@ -{{ config( - schema = 'metrics' - , alias = 'net_transfers_daily' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['blockchain', 'block_date'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] - ) -}} +{% macro metrics_transfers_evm(blockchain) %} with raw_transfers as ( select @@ -19,7 +10,7 @@ with raw_transfers as ( from {{ source('tokens', 'transfers') }} where - 1 = 1 + blockchain = '{{blockchain}}' {% if is_incremental() %} and {{ incremental_predicate('block_date') }} {% endif %} @@ -40,7 +31,7 @@ with raw_transfers as ( from {{ source('tokens', 'transfers') }} where - 1 = 1 + blockchain = '{{blockchain}}' {% if is_incremental() %} and {{ incremental_predicate('block_date') }} {% endif %} @@ -60,6 +51,7 @@ with raw_transfers as ( inner join {{ source('labels', 'owner_details') }} as od on oa.owner_key = od.owner_key + where oa.blockchain = '{{blockchain}}' ), transfers_amount as ( select t.blockchain @@ -108,3 +100,5 @@ where group by blockchain , block_date + +{% endmacro %} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/_schema.yml index 0c19c70acf8..eed04ce6a8c 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/_schema.yml @@ -4,7 +4,7 @@ models: - name: metrics_dune_index_daily meta: sector: metrics - contributors: jeff-dude + contributors: jeff-dude, 0xRob config: tags: ['metrics', 'dune', 'index', 'daily'] description: "Combine transactions, transfers and fees index values to get a daily dune index value" @@ -13,10 +13,11 @@ models: combination_of_columns: - blockchain - block_date + - name: metrics_dune_index_stats meta: sector: metrics contributors: jeff-dude config: - tags: ['metrics', 'dune', 'index', 'daily'] - description: "View containing various time aggregations of the dune index" \ No newline at end of file + tags: [ 'metrics', 'dune', 'index', 'daily' ] + description: "View containing various time aggregations of the dune index" diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_daily.sql index e5f68fe3345..593d5136189 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_daily.sql @@ -1,21 +1,71 @@ {{ config( schema = 'metrics' , alias = 'dune_index_daily' - , materialized = 'view' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] ) }} +{% set baseline_date = '2018-01-01' %} +{% set start_date = '2015-08-21' %} + +with +fees as ( + select + blockchain + , block_date + , gas_fees_usd + , (gas_fees_usd / (select sum(gas_fees_usd) from {{ ref('metrics_gas_fees_daily') }} where block_date = date '{{ baseline_date }}')) * 10 as fees_index + from + {{ ref('metrics_gas_fees_daily') }} + where + block_date >= date '{{ start_date }}' + {% if is_incremental() %} + and {{ incremental_predicate('block_date') }} + {% endif %} +), +transactions as ( + select + blockchain + , block_date + , tx_count + , (tx_count / cast((select sum(tx_count) from {{ ref('metrics_transactions_daily') }} where block_date = date '{{ baseline_date }}') as double)) * 10 as tx_index + from + {{ ref('metrics_transactions_daily') }} + where + block_date >= date '{{ start_date }}' + {% if is_incremental() %} + and {{ incremental_predicate('block_date') }} + {% endif %} +) +,transfers as ( + select + blockchain + , block_date + , net_transfer_amount_usd + , (net_transfer_amount_usd / cast((select sum(net_transfer_amount_usd) from {{ ref('metrics_transfers_daily') }} where block_date = date '{{ baseline_date }}') as double)) * 10 as transfers_index + from + {{ ref('metrics_transfers_daily') }} + where + block_date >= date '{{ start_date }}' + {% if is_incremental() %} + and {{ incremental_predicate('block_date') }} + {% endif %} +) + select blockchain , block_date - , coalesce(f.fees_index,0) as fees_index - , coalesce(tr.transfers_index,0) as transfers_index - , coalesce(tx.tx_index,0) as tx_index - , coalesce(f.fees_index,0)*0.45 + coalesce(tr.transfers_index,0)*0.45 + coalesce(tx.tx_index,0)*0.10 as dune_index -from {{ ref('metrics_fees_index_daily') }} as f -left join - {{ ref('metrics_transfers_index_daily') }} as tr - using (blockchain, block_date) -left join - {{ ref('metrics_transactions_index_daily') }} as tx - using (blockchain, block_date) \ No newline at end of file + , 0.45 * coalesce(fees_index,0) + 0.45 * coalesce(transfers_index,0) + 0.10 * coalesce(tx_index,0) as dune_index + , coalesce(fees_index,0) as fees_index + , coalesce(transfers_index,0) as transfers_index + , coalesce(tx_index,0) as tx_index + , gas_fees_usd + , tx_count + , net_transfer_amount_usd +from fees +left join transfers using (blockchain, block_date) +left join transactions using (blockchain, block_date) diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_stats.sql b/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_stats.sql index 7beb905d72b..c33a292b079 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_stats.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_stats.sql @@ -157,4 +157,4 @@ from inner join weekly_stats as w on d.blockchain = w.blockchain inner join monthly_stats as m - on d.blockchain = m.blockchain \ No newline at end of file + on d.blockchain = m.blockchain diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/_schema.yml index 19335852960..8a20c3dc635 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/_schema.yml @@ -8,27 +8,11 @@ models: config: tags: ['metrics', 'fees', 'gas', 'daily'] description: "Sum of total fees spent per day across all chains available in gas.fees and gas_solana.fees tables" - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date + - name: metrics_gas_fees_stats meta: sector: metrics contributors: jeff-dude config: tags: ['metrics', 'fees', 'gas'] - description: "View of gas fees per blockchain aggregated to various levels. The goal is to output one row per chain with stats availble for use in counter visuals." - - name: metrics_fees_index_daily - meta: - sector: metrics - contributors: jeff-dude - config: - tags: ['metrics', 'fees', 'gas', 'index', 'daily'] - description: "Each day, per chain, compare the adoption of activity based on total gas fees relative to the baseline expectation" - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date \ No newline at end of file + description: "View of gas fees per blockchain aggregated to various levels. The goal is to output one row per chain." diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/_schema.yml new file mode 100644 index 00000000000..fa94e015cd8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/_schema.yml @@ -0,0 +1,15 @@ +version: 2 + +models: + - name: metrics_bitcoin_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/metrics_bitcoin_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/metrics_bitcoin_gas_fees_daily.sql new file mode 100644 index 00000000000..89cd4f55b75 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/metrics_bitcoin_gas_fees_daily.sql @@ -0,0 +1,46 @@ +{{ config( + schema = 'metrics_bitcoin' + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + +with prices as ( + select + day + , price + from + {{ source('prices', 'usd_daily') }} + where + symbol = 'BTC' + and blockchain is null + {% if is_incremental() %} + and {{ incremental_predicate('day') }} + {% endif %} +) +, bitcoin_fees as ( + select + date as block_date + , sum(total_fees) as daily_fee + from + {{ source('bitcoin', 'blocks') }} + where + date < cast(date_trunc('day', now()) as date) --exclude current day to match prices.usd_daily + {% if is_incremental() %} + and {{ incremental_predicate('date') }} + {% endif %} + group by + date +) +select + 'bitcoin' as blockchain + , block_date + , (daily_fee * price) as gas_fees_usd +from + bitcoin_fees +inner join prices + on block_date = day diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml new file mode 100644 index 00000000000..58105e44cd9 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml @@ -0,0 +1,236 @@ +version: 2 + +models: + - name: metrics_arbitrum_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_avalanche_c_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_base_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_blast_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_bnb_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_celo_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_ethereum_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_fantom_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_gnosis_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_linea_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_mantle_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_optimism_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_polygon_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_scroll_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_sei_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zkevm_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zksync_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zora_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_arbitrum_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_arbitrum_gas_fees_daily.sql new file mode 100644 index 00000000000..2e939bf2771 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_arbitrum_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'arbitrum' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_avalanche_c_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_avalanche_c_gas_fees_daily.sql new file mode 100644 index 00000000000..f83d076533c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_avalanche_c_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'avalanche_c' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_base_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_base_gas_fees_daily.sql new file mode 100644 index 00000000000..082759b8855 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_base_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'base' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_blast_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_blast_gas_fees_daily.sql new file mode 100644 index 00000000000..632e8ebf4f4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_blast_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'blast' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_bnb_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_bnb_gas_fees_daily.sql new file mode 100644 index 00000000000..dec556a7b3c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_bnb_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'bnb' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_celo_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_celo_gas_fees_daily.sql new file mode 100644 index 00000000000..15da711d9f7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_celo_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'celo' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ethereum_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ethereum_gas_fees_daily.sql new file mode 100644 index 00000000000..b22fe1e34be --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ethereum_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'ethereum' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_fantom_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_fantom_gas_fees_daily.sql new file mode 100644 index 00000000000..92e6f7bb581 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_fantom_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'fantom' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_gnosis_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_gnosis_gas_fees_daily.sql new file mode 100644 index 00000000000..8cfd81990d9 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_gnosis_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'gnosis' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_linea_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_linea_gas_fees_daily.sql new file mode 100644 index 00000000000..a9c10dd0e13 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_linea_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'linea' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_mantle_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_mantle_gas_fees_daily.sql new file mode 100644 index 00000000000..3743c06acc8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_mantle_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'mantle' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_optimism_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_optimism_gas_fees_daily.sql new file mode 100644 index 00000000000..b96b6f9d60b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_optimism_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'optimism' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_polygon_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_polygon_gas_fees_daily.sql new file mode 100644 index 00000000000..8bcf90f4b01 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_polygon_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'polygon' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_scroll_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_scroll_gas_fees_daily.sql new file mode 100644 index 00000000000..eb6fbbd25fe --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_scroll_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'scroll' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_sei_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_sei_gas_fees_daily.sql new file mode 100644 index 00000000000..3df03b06885 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_sei_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'sei' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zkevm_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zkevm_gas_fees_daily.sql new file mode 100644 index 00000000000..c946fdd4c47 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zkevm_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zkevm' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zksync_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zksync_gas_fees_daily.sql new file mode 100644 index 00000000000..949e3ac28fb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zksync_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zksync' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zora_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zora_gas_fees_daily.sql new file mode 100644 index 00000000000..b22a703f410 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_zora_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zora' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/_schema.yml new file mode 100644 index 00000000000..44116ea0c4c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/_schema.yml @@ -0,0 +1,15 @@ +version: 2 + +models: + - name: metrics_solana_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/metrics_solana_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/metrics_solana_gas_fees_daily.sql new file mode 100644 index 00000000000..1eb0afcb862 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/solana/metrics_solana_gas_fees_daily.sql @@ -0,0 +1,60 @@ +{{ config( + schema = 'metrics_solana' + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + +with fees as ( + select + blockchain + , block_date + , sum(tx_fee_usd) as gas_fees_usd + from + {{ source('gas', 'fees') }} + where blockchain = 'solana' + {% if is_incremental() %} + and + {{ incremental_predicate('block_date') }} + {% endif %} + group by + blockchain + , block_date +), solana_vote_fees as ( + -- solana vote fees are stored in a different spell due to data volume & lack of value-add for materializing the fee breakdown + select + blockchain + , block_date + , sum(tx_fee_usd) as gas_fees_usd + from + {{ source('gas_solana', 'vote_fees') }} + {% if is_incremental() %} + where + {{ incremental_predicate('block_date') }} + {% endif %} + group by + blockchain + , block_date +), combined_fees as ( + select + fees.blockchain + , fees.block_date + , fees.gas_fees_usd + coalesce(solana_vote_fees.gas_fees_usd, 0) as gas_fees_usd + from + fees + left join + solana_vote_fees + on + fees.blockchain = solana_vote_fees.blockchain + and fees.block_date = solana_vote_fees.block_date +) + +select + blockchain + ,block_date + ,gas_fees_usd +from combined_fees diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/_schema.yml new file mode 100644 index 00000000000..30a48fd7599 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/_schema.yml @@ -0,0 +1,24 @@ +version: 2 + +models: + - name: tron_fee_correction + meta: + sector: metrics + contributors: 0xRob + description: "correction needed to compensate for subsized energy fees" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - name: metrics_tron_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/metrics_tron_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/metrics_tron_gas_fees_daily.sql new file mode 100644 index 00000000000..1de205e2724 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/metrics_tron_gas_fees_daily.sql @@ -0,0 +1,39 @@ +{{ config( + schema = 'metrics_tron' + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + +with fees as ( + select + blockchain + , block_date + , sum(tx_fee_usd) as gas_fees_usd + from + {{ source('gas', 'fees') }} + where blockchain = 'tron' + {% if is_incremental() %} + and + {{ incremental_predicate('block_date') }} + {% endif %} + group by + blockchain + , block_date +) + +select + blockchain + ,block_date + ,gas_fees_usd * coalesce(t.trx_fee_ratio,0.0) as gas_fees_usd -- apply correction to account for subsidized fees +from fees +left join {{ref('tron_fee_correction')}} t + on block_date = t.day + and blockchain = 'tron' + {% if is_incremental() %} + and {{ incremental_predicate('day') }} + {% endif %} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/tron/tron_fee_correction.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/tron_fee_correction.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/_metrics/fees/tron/tron_fee_correction.sql rename to dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/tron/tron_fee_correction.sql diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_fees_index_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_fees_index_daily.sql deleted file mode 100644 index dd777d49048..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_fees_index_daily.sql +++ /dev/null @@ -1,38 +0,0 @@ -{{ config( - schema = 'metrics' - , alias = 'fees_index_daily' - , materialized = 'view' - ) -}} - -{% set baseline_date = '2018-01-01' %} -{% set start_date = '2015-08-21' %} - -with baseline as ( - select - sum(gas_fees_usd) as baseline_gas_fees_usd -- sum is required due to blockchain being second unique key in source - from - {{ ref('metrics_gas_fees_daily') }} - where - block_date = date '{{ baseline_date }}' -), daily as ( - select - blockchain - , block_date - , gas_fees_usd - from - {{ ref('metrics_gas_fees_daily') }} - where - block_date >= date '{{ start_date }}' -) -select - d.blockchain - , d.block_date - , d.gas_fees_usd - , b.baseline_gas_fees_usd - , (d.gas_fees_usd / b.baseline_gas_fees_usd) * 10 as fees_index -from - daily as d -left join - baseline as b - on 1 = 1 diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql index 72c3c7ac935..4d577b17c5f 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql @@ -1,112 +1,44 @@ {{ config( schema = 'metrics' , alias = 'gas_fees_daily' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['blockchain', 'block_date'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + , materialized = 'view' ) }} -with fees as ( - select - blockchain - , block_date - , sum(tx_fee_usd) as gas_fees_usd - from - {{ source('gas', 'fees') }} - {% if is_incremental() %} - where - {{ incremental_predicate('block_date') }} - {% endif %} - group by - blockchain - , block_date -), solana_vote_fees as ( - -- solana vote fees are stored in a different spell due to data volume & lack of value-add for materializing the fee breakdown - select - blockchain - , block_date - , sum(tx_fee_usd) as gas_fees_usd - from - {{ source('gas_solana', 'vote_fees') }} - {% if is_incremental() %} - where - {{ incremental_predicate('block_date') }} - {% endif %} - group by +{% set chains = [ + 'arbitrum' + , 'avalanche_c' + , 'base' + , 'bitcoin' + , 'blast' + , 'bnb' + , 'celo' + , 'ethereum' + , 'fantom' + , 'gnosis' + , 'linea' + , 'mantle' + , 'optimism' + , 'polygon' + , 'scroll' + , 'sei' + , 'solana' + , 'tron' + , 'zkevm' + , 'zksync' + , 'zora' +] %} + +SELECT * +FROM ( + {% for blockchain in chains %} + SELECT blockchain - , block_date -), combined_fees as ( - select - fees.blockchain - , fees.block_date - , fees.gas_fees_usd + coalesce(solana_vote_fees.gas_fees_usd, 0) as gas_fees_usd - from - fees - left join - solana_vote_fees - on - fees.blockchain = solana_vote_fees.blockchain - and fees.block_date = solana_vote_fees.block_date -), bitcoin_fees as ( - with prices as ( - select - day - , price - from - {{ source('prices', 'usd_daily') }} - where - symbol = 'BTC' - and blockchain is null - {% if is_incremental() %} - and {{ incremental_predicate('day') }} - {% endif %} - ), btc as ( - select - date as block_date - , sum(total_fees) as daily_fee - from - {{ source('bitcoin', 'blocks') }} - where - date < cast(date_trunc('day', now()) as date) --exclude current day to match prices.usd_daily - {% if is_incremental() %} - and {{ incremental_predicate('date') }} - {% endif %} - group by - date - ) - select - 'bitcoin' as blockchain - , btc.block_date - , btc.daily_fee as gas_fees_raw - , prices.price as daily_price - , (btc.daily_fee * prices.price) as gas_fees_usd - from - btc - inner join - prices - on btc.block_date = prices.day + ,block_date + ,gas_fees_usd + FROM {{ ref('metrics_' + blockchain + '_gas_fees_daily') }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} ) -select - blockchain - ,block_date - ,case when blockchain = 'tron' - then gas_fees_usd * coalesce(t.trx_fee_ratio,0.0) -- apply correction to account for subsidized fees - else gas_fees_usd end - as gas_fees_usd -from combined_fees -left join {{ref('tron_fee_correction')}} t - on block_date = t.day - and blockchain = 'tron' - {% if is_incremental() %} - and {{ incremental_predicate('day') }} - {% endif %} -union all -select - blockchain - , block_date - , gas_fees_usd -from - bitcoin_fees \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_stats.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_stats.sql index ded73862c35..c1a860c28f5 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_stats.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_stats.sql @@ -155,4 +155,4 @@ from inner join weekly_stats as w on d.blockchain = w.blockchain inner join monthly_stats as m - on d.blockchain = m.blockchain \ No newline at end of file + on d.blockchain = m.blockchain diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/tron/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/tron/_schema.yml deleted file mode 100644 index cc3aa2a265b..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/tron/_schema.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: 2 - -models: - - name: tron_fee_correction - meta: - sector: metrics - contributors: 0xRob - description: "correction needed to compensate for subsized energy fees" - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - day diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/_schema.yml index 5f6e1f051ca..82c58a98985 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/_schema.yml @@ -8,27 +8,11 @@ models: config: tags: ['metrics', 'transactions', 'daily'] description: "Sum of total tx's per day across all chains" - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date + - name: metrics_transactions_stats meta: sector: metrics contributors: jeff-dude config: - tags: ['metrics', 'transactions'] - description: "View of tx's per blockchain aggregated to various levels. The goal is to output one row per chain with stats availble for use in counter visuals." - - name: metrics_transactions_index_daily - meta: - sector: metrics - contributors: jeff-dude - config: - tags: ['metrics', 'transactions', 'index', 'daily'] - description: "Each day, per chain, compare the adoption of total transactions relative to the baseline expectation" - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date \ No newline at end of file + tags: [ 'metrics', 'transactions' ] + description: "View of tx's per blockchain aggregated to various levels. The goal is to output one row per chain." diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/_schema.yml new file mode 100644 index 00000000000..aa54dcc9b6d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/_schema.yml @@ -0,0 +1,15 @@ +version: 2 + +models: + - name: metrics_bitcoin_transactions_daily + meta: + sector: metrics + contributors: jeff-dude + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/metrics_bitcoin_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/metrics_bitcoin_transactions_daily.sql new file mode 100644 index 00000000000..378c3e6b82d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/bitcoin/metrics_bitcoin_transactions_daily.sql @@ -0,0 +1,26 @@ +{{ config( + schema = 'metrics_bitcoin' + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + +select + blockchain + , block_date + , approx_distinct(tx_id) as tx_count +from + {{ source('transfers_bitcoin', 'satoshi') }} +where + 1 = 1 + and amount_transfer_usd > 1 + {% if is_incremental() %} + and {{ incremental_predicate('block_date') }} + {% endif %} +group by + blockchain + , block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml new file mode 100644 index 00000000000..aa0e43b7912 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml @@ -0,0 +1,249 @@ +version: 2 + +models: + - name: metrics_arbitrum_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_avalanche_c_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_base_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_blast_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_bnb_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_celo_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_ethereum_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_fantom_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_gnosis_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_linea_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_mantle_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_optimism_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_polygon_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_scroll_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_sei_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_tron_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zkevm_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zksync_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zora_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_arbitrum_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_arbitrum_transactions_daily.sql new file mode 100644 index 00000000000..0293fd2b2c8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_arbitrum_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'arbitrum' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_avalanche_c_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_avalanche_c_transactions_daily.sql new file mode 100644 index 00000000000..d2e90789069 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_avalanche_c_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'avalanche_c' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_base_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_base_transactions_daily.sql new file mode 100644 index 00000000000..9d3ee77d25b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_base_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'base' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_blast_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_blast_transactions_daily.sql new file mode 100644 index 00000000000..7c5046ea9c2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_blast_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'blast' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_bnb_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_bnb_transactions_daily.sql new file mode 100644 index 00000000000..c3feff1e770 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_bnb_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'bnb' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_celo_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_celo_transactions_daily.sql new file mode 100644 index 00000000000..94822b61bb1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_celo_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'celo' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ethereum_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ethereum_transactions_daily.sql new file mode 100644 index 00000000000..6f053536b70 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ethereum_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'ethereum' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_fantom_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_fantom_transactions_daily.sql new file mode 100644 index 00000000000..9d8043425fb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_fantom_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'fantom' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_gnosis_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_gnosis_transactions_daily.sql new file mode 100644 index 00000000000..b9f6ba8a83a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_gnosis_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'gnosis' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_linea_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_linea_transactions_daily.sql new file mode 100644 index 00000000000..05c80ad240a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_linea_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'linea' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_mantle_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_mantle_transactions_daily.sql new file mode 100644 index 00000000000..6e98f940369 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_mantle_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'mantle' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_optimism_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_optimism_transactions_daily.sql new file mode 100644 index 00000000000..766ea462934 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_optimism_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'optimism' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_polygon_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_polygon_transactions_daily.sql new file mode 100644 index 00000000000..e3cebf43868 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_polygon_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'polygon' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_scroll_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_scroll_transactions_daily.sql new file mode 100644 index 00000000000..59d31f62ab9 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_scroll_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'scroll' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_sei_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_sei_transactions_daily.sql new file mode 100644 index 00000000000..4fde7ded5d5 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_sei_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'sei' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_tron_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_tron_transactions_daily.sql new file mode 100644 index 00000000000..7a56a34abfe --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_tron_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'tron' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zkevm_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zkevm_transactions_daily.sql new file mode 100644 index 00000000000..bc1b4c9ba6b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zkevm_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zkevm' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zksync_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zksync_transactions_daily.sql new file mode 100644 index 00000000000..73bf7c01fc2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zksync_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zksync' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zora_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zora_transactions_daily.sql new file mode 100644 index 00000000000..cf28eb3b1d1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_zora_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zora' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/_schema.yml new file mode 100644 index 00000000000..e314dcbfb2a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/_schema.yml @@ -0,0 +1,15 @@ +version: 2 + +models: + - name: metrics_solana_transactions_daily + meta: + sector: metrics + contributors: jeff-dude + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/metrics_solana_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/metrics_solana_transactions_daily.sql new file mode 100644 index 00000000000..141f01f5824 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/solana/metrics_solana_transactions_daily.sql @@ -0,0 +1,27 @@ +{{ config( + schema = 'metrics_solana' + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + +select + 'solana' as blockchain + , block_date + , approx_distinct(tx_id) as tx_count +from + {{ source('tokens_solana', 'transfers') }} +where + 1 = 1 + and action != 'wrap' + and amount_usd > 1 + {% if is_incremental() %} + and {{ incremental_predicate('block_date') }} + {% endif %} +group by + 'solana' + , block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql index 62b6a2777aa..915451e5703 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql @@ -1,83 +1,44 @@ {{ config( schema = 'metrics' , alias = 'transactions_daily' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['blockchain', 'block_date'] - , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + , materialized = 'view' ) }} -with evm as ( - select - blockchain - , block_date - , approx_distinct(tx_hash) as tx_count --max 2% error, which is fine - from - {{ source('tokens', 'transfers') }} - where - 1 = 1 - and amount_usd >=1 - {% if is_incremental() %} - and {{ incremental_predicate('block_date') }} - {% endif %} - group by - blockchain - , block_date -) -, solana as ( - select - 'solana' as blockchain - , block_date - , approx_distinct(tx_id) as tx_count - from - {{ source('tokens_solana', 'transfers') }} - where - 1 = 1 - and action != 'wrap' - and amount_usd > 1 - {% if is_incremental() %} - and {{ incremental_predicate('block_date') }} - {% endif %} - group by - 'solana' - , block_date -) -, bitcoin as ( - select +{% set chains = [ + 'arbitrum' + , 'avalanche_c' + , 'base' + , 'bitcoin' + , 'blast' + , 'bnb' + , 'celo' + , 'ethereum' + , 'fantom' + , 'gnosis' + , 'linea' + , 'mantle' + , 'optimism' + , 'polygon' + , 'scroll' + , 'sei' + , 'solana' + , 'tron' + , 'zkevm' + , 'zksync' + , 'zora' +] %} + +SELECT * +FROM ( + {% for blockchain in chains %} + SELECT blockchain - , block_date - , approx_distinct(tx_id) as tx_count - from - {{ source('transfers_bitcoin', 'satoshi') }} - where - 1 = 1 - and amount_transfer_usd > 1 - {% if is_incremental() %} - and {{ incremental_predicate('block_date') }} + ,block_date + ,tx_count + FROM {{ ref('metrics_' + blockchain + '_transactions_daily') }} + {% if not loop.last %} + UNION ALL {% endif %} - group by - blockchain - , block_date + {% endfor %} ) -select - blockchain - , block_date - , tx_count -from - evm -union all -select - blockchain - , block_date - , tx_count -from - solana -union all -select - blockchain - , block_date - , tx_count -from - bitcoin \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_index_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_index_daily.sql deleted file mode 100644 index 194eb76b218..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_index_daily.sql +++ /dev/null @@ -1,38 +0,0 @@ -{{ config( - schema = 'metrics' - , alias = 'transactions_index_daily' - , materialized = 'view' - ) -}} - -{% set baseline_date = '2018-01-01' %} -{% set start_date = '2015-08-21' %} - -with baseline as ( - select - sum(tx_count) as baseline_tx_count -- sum is required due to blockchain being second unique key in source - from - {{ ref('metrics_transactions_daily') }} - where - block_date = date '{{ baseline_date }}' -), daily as ( - select - blockchain - , block_date - , tx_count - from - {{ ref('metrics_transactions_daily') }} - where - block_date >= date '{{ start_date }}' -) -select - d.blockchain - , d.block_date - , d.tx_count - , b.baseline_tx_count - , (cast(d.tx_count as double) / cast(b.baseline_tx_count as double)) * 10 as tx_index -from - daily as d -left join - baseline as b - on 1 = 1 diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_stats.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_stats.sql index a03620af097..39063698f34 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_stats.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_stats.sql @@ -155,4 +155,4 @@ from inner join weekly_stats as w on d.blockchain = w.blockchain inner join monthly_stats as m - on d.blockchain = m.blockchain \ No newline at end of file + on d.blockchain = m.blockchain diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/_schema.yml index e03f33be0d9..7330b573af4 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: metrics_net_transfers_daily + - name: metrics_transfers_daily meta: sector: metrics contributors: jeff-dude @@ -18,62 +18,35 @@ models: with the positive net received (aka received) it adds up to 0 since the net sent should equal the net received. For example, if I give you $1 that's -1 sent (from me) and +1 received (by you) which adds to 0. This query counts the received to show that $1 was effectively transfered." - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date - - name: metrics_net_solana_transfers_daily + + - name: metrics_transfers_stats meta: sector: metrics contributors: jeff-dude config: - tags: ['metrics', 'net_transfers', 'solana'] - description: *net_transfers_description - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date - - name: metrics_net_bitcoin_transfers_daily + tags: ['metrics', 'transfers'] + description: "View of transfers per blockchain aggregated to various levels. The goal is to output one row per chain." + + - name: metrics_solana_transfers_daily meta: sector: metrics contributors: jeff-dude config: - tags: ['metrics', 'net_transfers', 'bitcoin'] + tags: ['metrics', 'net_transfers', 'solana'] description: *net_transfers_description data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - blockchain - block_date - - name: metrics_transfers_daily - meta: - sector: metrics - contributors: jeff-dude - config: - tags: ['metrics', 'transfers', 'daily'] - description: | - "Sum of total transfer amount per day across all chain." - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - blockchain - - block_date - - name: metrics_transfers_stats - meta: - sector: metrics - contributors: jeff-dude - config: - tags: ['metrics', 'transfers'] - description: "View of transfers per blockchain aggregated to various levels. The goal is to output one row per chain with stats availble for use in counter visuals." - - name: metrics_transfers_index_daily + + - name: metrics_bitcoin_transfers_daily meta: sector: metrics contributors: jeff-dude config: - tags: ['metrics', 'transfers', 'index', 'daily'] - description: "Each day, per chain, compare the adoption of total transfers relative to the baseline expectation" + tags: ['metrics', 'net_transfers', 'bitcoin'] + description: *net_transfers_description data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_bitcoin_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/bitcoin/metrics_bitcoin_transfers_daily.sql similarity index 97% rename from dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_bitcoin_transfers_daily.sql rename to dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/bitcoin/metrics_bitcoin_transfers_daily.sql index f193edc8d53..711518ccf4b 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_bitcoin_transfers_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/bitcoin/metrics_bitcoin_transfers_daily.sql @@ -1,6 +1,6 @@ {{ config( - schema = 'metrics' - , alias = 'net_bitcoin_transfers_daily' + schema = 'metrics_bitcoin' + , alias = 'transfers_daily' , materialized = 'incremental' , file_format = 'delta' , incremental_strategy = 'merge' @@ -110,4 +110,4 @@ where net_transfer_amount_usd > 0 group by blockchain - , block_date \ No newline at end of file + , block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml new file mode 100644 index 00000000000..c4b82af4cbd --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml @@ -0,0 +1,249 @@ +version: 2 + +models: + - name: metrics_arbitrum_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_avalanche_c_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_base_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_blast_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_bnb_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_celo_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_ethereum_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_fantom_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_gnosis_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_linea_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_mantle_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_optimism_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_polygon_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_scroll_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_sei_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_tron_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zkevm_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zksync_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date + + - name: metrics_zora_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transfers', 'daily'] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_arbitrum_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_arbitrum_transfers_daily.sql new file mode 100644 index 00000000000..272c9cf2fcd --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_arbitrum_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'arbitrum' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_avalanche_c_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_avalanche_c_transfers_daily.sql new file mode 100644 index 00000000000..5d768c36edc --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_avalanche_c_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'avalanche_c' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_base_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_base_transfers_daily.sql new file mode 100644 index 00000000000..8b9099a6035 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_base_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'base' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_blast_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_blast_transfers_daily.sql new file mode 100644 index 00000000000..c35a554a42a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_blast_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'blast' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_bnb_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_bnb_transfers_daily.sql new file mode 100644 index 00000000000..0fd3b6a25b2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_bnb_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'bnb' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_celo_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_celo_transfers_daily.sql new file mode 100644 index 00000000000..3e9b393ccce --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_celo_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'celo' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ethereum_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ethereum_transfers_daily.sql new file mode 100644 index 00000000000..f1b7aa5c1d8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ethereum_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'ethereum' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_fantom_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_fantom_transfers_daily.sql new file mode 100644 index 00000000000..6acd73adc56 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_fantom_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'fantom' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_gnosis_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_gnosis_transfers_daily.sql new file mode 100644 index 00000000000..9b916f51eaf --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_gnosis_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'gnosis' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_linea_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_linea_transfers_daily.sql new file mode 100644 index 00000000000..d7aa7dab9e2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_linea_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'linea' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_mantle_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_mantle_transfers_daily.sql new file mode 100644 index 00000000000..035f2c1a820 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_mantle_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'mantle' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_optimism_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_optimism_transfers_daily.sql new file mode 100644 index 00000000000..7179d55e91a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_optimism_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'optimism' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_polygon_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_polygon_transfers_daily.sql new file mode 100644 index 00000000000..725a9236cee --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_polygon_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'polygon' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_scroll_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_scroll_transfers_daily.sql new file mode 100644 index 00000000000..9c3f5418d5c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_scroll_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'scroll' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_sei_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_sei_transfers_daily.sql new file mode 100644 index 00000000000..17d9ec4a367 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_sei_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'sei' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_tron_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_tron_transfers_daily.sql new file mode 100644 index 00000000000..035d9485a6c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_tron_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'tron' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zkevm_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zkevm_transfers_daily.sql new file mode 100644 index 00000000000..a77bc732309 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zkevm_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zkevm' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zksync_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zksync_transfers_daily.sql new file mode 100644 index 00000000000..a941a3965e2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zksync_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zksync' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zora_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zora_transfers_daily.sql new file mode 100644 index 00000000000..21bdfb3d180 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_zora_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'zora' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_solana_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/solana/metrics_solana_transfers_daily.sql similarity index 96% rename from dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_solana_transfers_daily.sql rename to dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/solana/metrics_solana_transfers_daily.sql index 5a2472b35bb..88b7e629e8d 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_net_solana_transfers_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/solana/metrics_solana_transfers_daily.sql @@ -1,6 +1,6 @@ {{ config( - schema = 'metrics' - , alias = 'net_solana_transfers_daily' + schema = 'metrics_solana' + , alias = 'transfers_daily' , materialized = 'incremental' , file_format = 'delta' , incremental_strategy = 'merge' @@ -92,4 +92,4 @@ where net_transfer_amount_usd > 0 group by blockchain - , block_date \ No newline at end of file + , block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql index 4a81fe41984..108611d314f 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql @@ -5,32 +5,43 @@ ) }} -select - blockchain - , block_date - , transfer_amount_usd_sent - , transfer_amount_usd_received - , transfer_amount_usd - , net_transfer_amount_usd -from - {{ ref('metrics_net_transfers_daily') }} -union all -select - blockchain - , block_date - , transfer_amount_usd_sent - , transfer_amount_usd_received - , transfer_amount_usd - , net_transfer_amount_usd -from - {{ ref('metrics_net_solana_transfers_daily') }} -union all -select - blockchain - , block_date - , transfer_amount_usd_sent - , transfer_amount_usd_received - , transfer_amount_usd - , net_transfer_amount_usd -from - {{ ref('metrics_net_bitcoin_transfers_daily') }} +{% set chains = [ + 'arbitrum' + , 'avalanche_c' + , 'base' + , 'bitcoin' + , 'blast' + , 'bnb' + , 'celo' + , 'ethereum' + , 'fantom' + , 'gnosis' + , 'linea' + , 'mantle' + , 'optimism' + , 'polygon' + , 'scroll' + , 'sei' + , 'solana' + , 'tron' + , 'zkevm' + , 'zksync' + , 'zora' +] %} + +SELECT * +FROM ( + {% for blockchain in chains %} + SELECT + blockchain + , block_date + , transfer_amount_usd_sent + , transfer_amount_usd_received + , transfer_amount_usd + , net_transfer_amount_usd + FROM {{ ref('metrics_' + blockchain + '_transfers_daily') }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_index_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_index_daily.sql deleted file mode 100644 index f13e4e1648c..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_index_daily.sql +++ /dev/null @@ -1,38 +0,0 @@ -{{ config( - schema = 'metrics' - , alias = 'transfers_index_daily' - , materialized = 'view' - ) -}} - -{% set baseline_date = '2018-01-01' %} -{% set start_date = '2015-08-21' %} - -with baseline as ( - select - sum(net_transfer_amount_usd) as baseline_net_transfer_amount_usd -- sum is required due to blockchain being second unique key in source - from - {{ ref('metrics_transfers_daily') }} - where - block_date = date '{{ baseline_date }}' -), daily as ( - select - blockchain - , block_date - , net_transfer_amount_usd - from - {{ ref('metrics_transfers_daily') }} - where - block_date >= date '{{ start_date }}' -) -select - d.blockchain - , d.block_date - , d.net_transfer_amount_usd - , b.baseline_net_transfer_amount_usd - , (d.net_transfer_amount_usd / b.baseline_net_transfer_amount_usd) * 10 as transfers_index -from - daily as d -left join - baseline as b - on 1 = 1 diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_stats.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_stats.sql index dfe6afb49b5..45d7124b597 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_stats.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_stats.sql @@ -155,4 +155,4 @@ from inner join weekly_stats as w on d.blockchain = w.blockchain inner join monthly_stats as m - on d.blockchain = m.blockchain \ No newline at end of file + on d.blockchain = m.blockchain From 1bb99fd2fd05c8a58623f0ecf6e70368bac4b3b2 Mon Sep 17 00:00:00 2001 From: maybeyonas Date: Thu, 28 Nov 2024 16:26:08 +0530 Subject: [PATCH 28/68] adding more rwa tokens and schema update (#7191) * adding more rwa tokens and schema update * column fixes --- .../rwa/arbitrum/rwa_arbitrum_schema.yml | 6 ++ .../rwa/arbitrum/rwa_arbitrum_tokens.sql | 86 +++++++++++++++++-- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_schema.yml b/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_schema.yml index 575bafe15c1..003910de111 100644 --- a/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_schema.yml @@ -30,6 +30,12 @@ models: - &type name: type description: "Type of Asset" + - &decimals + name: decimals + description: "Decimals of the asset" + - &category + name: category + description: "RWA category for the Asset" - name: rwa_arbitrum_dex_pools diff --git a/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_tokens.sql b/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_tokens.sql index 3e38fcc57aa..6bc56f2101d 100644 --- a/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_tokens.sql +++ b/dbt_subprojects/daily_spellbook/models/_sector/rwa/arbitrum/rwa_arbitrum_tokens.sql @@ -15,14 +15,90 @@ select token_address, symbol, project, - type + type, + decimals, + category from (values - (0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C, 'USDM' , 'Mountain Protocol' , 'RWA' ), - (0xfc90518D5136585ba45e34ED5E1D108BD3950CFa, 'USD+' , 'Dinari' , 'RWA' ), - (0x9d2f299715d94d8a7e6f5eaa8e654e8c74a988a7, 'FXS' , 'Frax Finance' , 'Governance' ) + (0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C, 'USDM' , 'Mountain Protocol' , 'RWA' , 18, 'Stablecoin'), + (0xfc90518D5136585ba45e34ED5E1D108BD3950CFa, 'USD+' , 'Dinari' , 'RWA' , 6 , 'Stocks'), + (0x9d2f299715d94d8a7e6f5eaa8e654e8c74a988a7, 'FXS' , 'Frax Finance' , 'Governance' , 18, 'Stablecoin'), + (0x667fd83e24ca1d935d36717d305d54fa0cac991c, 'FRAX' , 'Frax Finance' , 'RWA' , 18, 'Stablecoin'), + (0xCe38e140fC3982a6bCEbc37b040913EF2Cd6C5a7, 'AAPL.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xd8F728AdB72a46Ae2c92234AE8870D04907786C5, 'AMD.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x8240aFFe697CdE618AD05c3c8963f5Bfe152650b, 'AMZN.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x3619ca1e96c629f7D71C1b03dc0Ee56479356228, 'ARKB.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x67BaD479F77488f0f427584e267e66086a7Da43A, 'ARM.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x769fF50fD49900a6c53b2aF049eACB83dAD52Bdf, 'BITB.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x2B7c643b42409F352B936BF07e0538ba20979Bff, 'BRRR.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x2824eFE5CeDB3BC8730E412981997daC7C7640C2, 'BTCO.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xc52915Fe75dc8db9fb6306f43AAef1344E0837AB, 'BTCW.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x46b979440ac257151ee5a5bc9597b76386907fa1, 'COIN.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xDD92f0723a7318e684A88532CAC2421E3cC9968e, 'DEFI.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x3c9f23db4ddc5655f7be636358d319a3de1ff0c4, 'DIS.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xa6f344abc6e2501b2b303fcbba99cd89f136b5fb, 'EZBC.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x026fdf3024953cb2e8982bc11c67d336f37a5044, 'FBTC.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xb1284f6b3e487e3f773e9ad40f337c3b3cda5c69, 'GBTC.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x8e50d11a54cff859b202b7fe5225353be0646410, 'GOOGL.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x0c59f6b96d3cac58240429c7659ec107f8b1efa7, 'HODL.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xc1ba16afdcb3a41242944c9faaccd9fb6f2b428c, 'IBIT.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x0c29891dc5060618c779e2a45fbe4808aa5ae6ad, 'MCD.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x519062155b0591627c8a0c0958110a8c5639dca6, 'META.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x77308f8b63a99b24b262d930e0218ed2f49f8475, 'MSFT.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x3ad63b3c0ea6d7a093ff98fde040baddc389ecdc, 'NFLX.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x14297be295ab922458277be046e89f73382bdf8e, 'NLY.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x4dafffddea93ddf1e0e7b61e844331455053ce5c, 'NVDA.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xf1f18f765f118c3598cc54dcac1d0e12066263fe, 'PFE.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x118346c2bb9d24412ed58c53bf9bb6f61a20d7ec, 'PLD.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x5b6424769823e82a1829b0a8bcaf501bffd90d25, 'PYPL.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x0b5ac0d7dcf6964609a12af4f6c6f3c257070193, 'RIOT.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xf4bd09b048248876e39fcf2e0cdf1aee1240a9d2, 'SPY.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xd883bcf80b2b085fa40cc3e2416b4ab1cbca649e, 'SQ.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x36d37b6cbca364cf1d843eff8c2f6824491bcf81, 'TSLA.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x9c46e1b70d447b770dbfc8d450543a431af6df3a, 'USFR.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xeb0d1360a14c3b162f2974daa5d218e0c1090146, 'YUM.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x0a2919147b871a0fc90f04944e31fad56d9af666, 'SLX.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xc20770116f2821d550574c2b9ce1b4baa7012377, 'WEAT.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x13f950ee286a5be0254065d4b66420fc0e57adfc, 'WOOD.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xad6a646c1b262586ef3a8b6c6304e7c9218ecac4, 'PHO.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x97ec5dada8262bd922bffd54a93f5a11efe0b136, 'RDDT.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xb415998a7bb6f11dc589e0eb20adf586ba32f12a, 'GME.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x28bf1c9ee2eb746a2d61a0bec97a344028171d6c, 'AMC.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xa0eefbba9c18925fb6bab26281806772398cca1f, 'UBER.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x337842843512192b798a5592053ce8e2245651f8, 'CSCO.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x289594b223ab31832726eb99871fa99adac583e5, 'ADBE.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x7c5fed5e0f8d05748cc12ffe1ca400b07de0f983, 'AVGO.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x315a2dca4b1b633d3a707c71d96243534c02f7c4, 'XOM.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x0e929101c4fa7c91eaa64d7216161ba3eee387fe, 'CVX.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x50e2b96f958133cbda56d1a62d156e812fe97828, 'JNJ.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x44966bf47a494b36dfb407afb334a9226cdf90bc, 'AZN.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x50f7b76a0b888e5d7196f1a472d2e567d425c761, 'TJX.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0xb90e1ee5f4194388e71c11dc2a4eea16da391ce4, 'PG.d' , 'Dinari' , 'RWA' , 18, 'Stocks'), + (0x79ECCE8E2D17603877Ff15BC29804CbCB590EC08, 'fBILL' , 'Fortunafi' , 'RWA' , 18, 'Treasury Bills'), + (0x45bafad5a6a531Bc18Cf6CE5B02C58eA4D20589b, 'ifBILL' , 'Fortunafi' , 'RWA' , 18, 'Treasury Bills'), + (0x20c64dee8fda5269a78f2d5bdba861ca1d83df7a, 'bHIGH' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0xbbcb0356bB9e6B3Faa5CbF9E5F36185d53403Ac9, 'bCOIN' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0x2f11EeeE0bf21E7661A22dbBbb9068F4ad191b86, 'bNIU' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0xAde6057FcAfa57d6d51FFa341C64ce4814995995, 'bZPR1' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0x2F123cF3F37CE3328CC9B5b8415f9EC5109b45e7, 'bC3M' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0x0f76d32cdccdcbd602a55af23eaf58fd1ee17245, 'bERNA' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0x3f95aa88ddbb7d9d484aa3d482bf0a80009c52c9, 'bERNX' , 'BackedFi' , 'RWA' , 18, 'Bonds'), + (0xF84D28A8D28292842dD73D1c5F99476A80b6666A, 'TBILL' , 'OpenEden' , 'RWA' , 6 , 'Treasury Bills'), + (0xB88a5Ac00917a02d82c7cd6CEBd73E2852d43574, 'SWEEP' , 'Sweep' , 'RWA' , 18, 'Stablecoin'), + (0x35e050d3C0eC2d29D269a8EcEa763a183bDF9A9D, 'USDY' , 'Ondo Finance' , 'RWA' , 18, 'Treasury Bonds'), + (0x9B6226dd0191a77d032F56A6d383044EE99944C3, 'flrEUR' , 'Florence Finance' , 'RWA' , 18, 'Stablecoin'), + (0x0BBF664D46becc28593368c97236FAa0fb397595, 'KNOX' , 'Reserve Protocol' , 'RWA' , 18, 'Stablecoin'), + (0x0000206329b97DB379d5E1Bf586BbDB969C63274, 'USDA' , 'Angle' , 'RWA' , 18, 'Stablecoin'), + (0xFA5Ed56A203466CbBC2430a43c66b9D8723528E7, 'agEUR' , 'Angle' , 'RWA' , 18, 'Stablecoin'), + (0x323665443cef804a3b5206103304bd4872ea4253, 'USDV' , 'Verified USD' , 'RWA' , 6 , 'Stablecoin'), + (0xB9e4765BCE2609bC1949592059B17Ea72fEe6C6A, 'BENJI' , 'FranklinTempleton' , 'RWA' , 18, 'U.S. govt Securities'), + (0x89B1e7068bF8E3232dD8f16c35cAc45bDA584f4E, 'SWEEPR' , 'Sweep' , 'Governance' , 18, 'Stablecoin'), + (0x3269a3C00AB86c753856fD135d97b87FACB0d848, 'FFM' , 'Florence Finance' , 'Governance' , 18, 'Stablecoin'), + (0xCa5Ca9083702c56b481D1eec86F1776FDbd2e594, 'RSR' , 'Reserve Protocol' , 'Governance' , 18, 'Stablecoin') ) as t( token_address, symbol, project, - type + type, + decimals, + category ) From bf82c7148c0229d9fe44e382295c63299a506bb8 Mon Sep 17 00:00:00 2001 From: tomfutago <35136350+tomfutago@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:56:14 +0000 Subject: [PATCH 29/68] fix: cbBTC decimals (#7192) --- .../ethereum/covers/nexusmutual_ethereum_covers_v2.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/covers/nexusmutual_ethereum_covers_v2.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/covers/nexusmutual_ethereum_covers_v2.sql index 448047f7964..9e6f803b750 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/covers/nexusmutual_ethereum_covers_v2.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/covers/nexusmutual_ethereum_covers_v2.sql @@ -88,7 +88,7 @@ cover_premiums as ( when 7 then 'cbBTC' else 'NA' end as cover_asset, - c.sum_assured / if(c.cover_asset = 6, 1e6, 1e18) as sum_assured, + c.sum_assured / case c.cover_asset when 6 then 1e6 when 7 then 1e8 else 1e18 end as sum_assured, case c.payment_asset when 0 then 'ETH' when 1 then 'DAI' From 1f286b35b5464b40f4bbef17ac028a163857b940 Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:56:28 +0100 Subject: [PATCH 30/68] enable excluded boost model (#7193) * enable model * remove cast to int and leave as uint256 --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../daily_spellbook/models/boost/boost_deployed.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/boost/boost_deployed.sql b/dbt_subprojects/daily_spellbook/models/boost/boost_deployed.sql index 2b7e0c586ea..40be3f50a3b 100644 --- a/dbt_subprojects/daily_spellbook/models/boost/boost_deployed.sql +++ b/dbt_subprojects/daily_spellbook/models/boost/boost_deployed.sql @@ -1,7 +1,6 @@ {{ config( schema='boost', - tags = ['prod_exclude'], alias='deployed', materialized='incremental', file_format='delta', @@ -33,7 +32,7 @@ select TRY(from_unixtime(end_time)) as end_time, reward_amount_raw, reward_token_address, - cast(max_participants as int) as max_participants, + max_participants, creation_time, creator as creator_address from From 9de2e412b21a62113f489ce6d825fc6707d2064c Mon Sep 17 00:00:00 2001 From: whale_hunter <143016036+whalehunting@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:40:29 +0100 Subject: [PATCH 31/68] feat: add bitfoot solana bot trades spellbook (#7202) * feat: add bitfoot solana bot trades spellbook * fix: add correct seed --- .../_sector/dex/bot_trades/solana/_schema.yml | 32 +++- .../solana/dex_solana_bot_trades.sql | 1 + .../platforms/bitfoot_solana_bot_trades.sql | 152 ++++++++++++++++++ .../bitfoot/bitfoot_solana_trades_seed.csv | 21 +++ 4 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/bitfoot_solana_bot_trades.sql create mode 100644 dbt_subprojects/solana/seeds/bitfoot/bitfoot_solana_trades_seed.csv diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml index 6e9faa06c60..c6d9f401458 100644 --- a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml @@ -454,7 +454,7 @@ models: - check_bot_trades_seed: seed_file: ref('tirador_solana_trades_seed') blockchain: solana - + - name: unibot_solana_bot_trades meta: blockchain: solana @@ -498,7 +498,7 @@ models: - check_bot_trades_seed: seed_file: ref('mev_x_solana_trades_seed') blockchain: solana - + - name: alpha_dex_solana_bot_trades meta: blockchain: solana @@ -578,7 +578,7 @@ models: - check_bot_trades_seed: seed_file: ref('pinkpunk_solana_trades_seed') blockchain: solana - + - name: falcon_solana_bot_trades meta: blockchain: solana @@ -598,7 +598,7 @@ models: - outer_instruction_index - inner_instruction_index - check_bot_trades_seed: - seed_file: ref('falcon_solana_trades_seed') + seed_file: ref('falcon_solana_trades_seed') blockchain: solana - name: bloom_solana_bot_trades @@ -643,4 +643,26 @@ models: - inner_instruction_index - check_bot_trades_seed: seed_file: ref('autosnipe_solana_trades_seed') - blockchain: solana \ No newline at end of file + blockchain: solana + + - name: bitfoot_solana_bot_trades + meta: + blockchain: solana + sector: dex + project: bitfoot + contributors: whale_hunter + config: + tags: ["solana", "dex", "bitfoot", "trades"] + description: > + Bitfoot trades on Solana + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_id + - tx_index + - outer_instruction_index + - inner_instruction_index + - check_bot_trades_seed: + seed_file: ref('bitfoot_solana_trades_seed') + blockchain: solana diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql index 45a86ca4054..3a46f240904 100644 --- a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/dex_solana_bot_trades.sql @@ -35,6 +35,7 @@ , ref('looter_solana_bot_trades') , ref('wifbot_solana_bot_trades') , ref('autosnipe_solana_bot_trades') + , ref('bitfoot_solana_bot_trades') ] %} {% for bot in solana_trading_bot %} diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/bitfoot_solana_bot_trades.sql b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/bitfoot_solana_bot_trades.sql new file mode 100644 index 00000000000..4213660df7b --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/bitfoot_solana_bot_trades.sql @@ -0,0 +1,152 @@ +{{ config( + alias = 'bot_trades', + schema = 'bitfoot_solana', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'tx_id', 'tx_index', 'outer_instruction_index', 'inner_instruction_index'] + ) +}} + +{% set project_start_date = '2024-11-21' %} +{% set fee_receiver_1 = 'BzmpLvrhZHKoXV7CW9F1AVPnie3hNh2JK3BRdHL4Zcya' %} +{% set wsol_token = 'So11111111111111111111111111111111111111112' %} + +WITH + allFeePayments AS ( + SELECT + tx_id, + 'SOL' AS feeTokenType, + balance_change / 1e9 AS fee_token_amount, + '{{wsol_token}}' AS fee_token_mint_address + FROM + {{ source('solana','account_activity') }} + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND tx_success + AND balance_change > 0 + AND ( + address = '{{fee_receiver_1}}' + ) + ), + botTrades AS ( + SELECT + trades.block_time, + CAST(date_trunc('day', trades.block_time) AS date) AS block_date, + CAST(date_trunc('month', trades.block_time) AS date) AS block_month, + 'solana' AS blockchain, + amount_usd, + IF( + token_sold_mint_address = '{{wsol_token}}', + 'Buy', + 'Sell' + ) AS type, + token_bought_amount, + token_bought_symbol, + token_bought_mint_address AS token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_mint_address AS token_sold_address, + fee_token_amount * price AS fee_usd, + fee_token_amount, + IF(feeTokenType = 'SOL', 'SOL', symbol) AS fee_token_symbol, + fee_token_mint_address AS fee_token_address, + project, + version, + token_pair, + project_program_id AS project_contract_address, + trader_id AS user, + trades.tx_id, + tx_index, + outer_instruction_index, + inner_instruction_index + FROM + {{ ref('dex_solana_trades') }} AS trades + JOIN allFeePayments AS feePayments ON trades.tx_id = feePayments.tx_id + LEFT JOIN {{ source('prices', 'usd') }} AS feeTokenPrices ON ( + feeTokenPrices.blockchain = 'solana' + AND fee_token_mint_address = toBase58 (feeTokenPrices.contract_address) + AND date_trunc('minute', block_time) = minute + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + JOIN {{ source('solana','transactions') }} AS transactions ON ( + trades.tx_id = id + {% if is_incremental() %} + AND {{ incremental_predicate('transactions.block_time') }} + {% else %} + AND transactions.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + WHERE + trades.trader_id != '{{fee_receiver_1}}' -- Exclude trades signed by FeeWallet + AND transactions.signer != '{{fee_receiver_1}}' -- Exclude trades signed by FeeWallet + {% if is_incremental() %} + AND {{ incremental_predicate('trades.block_time') }} + {% else %} + AND trades.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ), + highestInnerInstructionIndexForEachTrade AS ( + SELECT + tx_id, + outer_instruction_index, + MAX(inner_instruction_index) AS highestInnerInstructionIndex + FROM + botTrades + GROUP BY + tx_id, + outer_instruction_index + ) +SELECT + block_time, + block_date, + block_month, + 'Bitfoot' as bot, + blockchain, + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + fee_usd, + fee_token_amount, + fee_token_symbol, + fee_token_address, + project, + version, + token_pair, + project_contract_address, + user, + botTrades.tx_id, + tx_index, + botTrades.outer_instruction_index, + COALESCE(inner_instruction_index, 0) AS inner_instruction_index, + IF( + inner_instruction_index = highestInnerInstructionIndex, + true, + false + ) AS is_last_trade_in_transaction +FROM + botTrades + JOIN highestInnerInstructionIndexForEachTrade ON ( + botTrades.tx_id = highestInnerInstructionIndexForEachTrade.tx_id + AND botTrades.outer_instruction_index = highestInnerInstructionIndexForEachTrade.outer_instruction_index + ) +ORDER BY + block_time DESC, + tx_index DESC, + outer_instruction_index DESC, + inner_instruction_index DESC diff --git a/dbt_subprojects/solana/seeds/bitfoot/bitfoot_solana_trades_seed.csv b/dbt_subprojects/solana/seeds/bitfoot/bitfoot_solana_trades_seed.csv new file mode 100644 index 00000000000..2dfe16fe5fe --- /dev/null +++ b/dbt_subprojects/solana/seeds/bitfoot/bitfoot_solana_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_id,tx_index,outer_instruction_index,inner_instruction_index,is_last_trade_in_transaction +2024-11-27 11:39:41.000 UTC,2024-11-27,2024-11-01,Bitfoot,solana,11.689425,Buy,709.813803,Aejo,B16bhVYwE9zQVjbYpnnmvfN7qJFDe21nx5iQC5LJpump,0.0495,SOL,So11111111111111111111111111111111111111112,0.078519875,0.0003325,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Aejo,7tdNR3TNw13wGDz2PBynb9T6t39oskvzNiTvKCnVN4bw,HZidTvr4nRwhPBJvSb842rtBsedtigFWPMfwZfUSWsA7,52E6dhvq1DCqdjqVAxqJ3CLaJd1qSDMUqAhAzyjB3Gx2U8XWHH3T9YkzzSfGv6YYF5ArePxEDwCpuGncJM3WQ3CU,1097,8,2,true +2024-11-28 04:22:56.000 UTC,2024-11-28,2024-11-01,Bitfoot,solana,6.04981532776,Sell,0.025230692,SOL,So11111111111111111111111111111111111111112,200.217182,TRIP,8JZ2R6dzfCeiAvcJ7H1G6hy8x5pBQryHZcWiVY2spump,0.03720642282,0.000155169,SOL,So11111111111111111111111111111111111111112,raydium,4,TRIP-SOL,58JdqNRYCQthSzKY1rZ9LzaK6UNkKhbQgN5kBtyEGoLL,4KsknATdHdgfU1Wi6kakxPRa2TDg4HCXfoc66b6JXp3M,3av3ivTmU1DZCHG7c5LSMzpg5g4o212opYZmuHDY6UEG5SVf1ZBmSVySZQequCwTTgGrgcu9PhB8PQYvZpbNcQzS,2297,6,1,true +2024-11-23 11:40:07.000 UTC,2024-11-23,2024-11-01,Bitfoot,solana,9.86582145959,Sell,0.038428783,SOL,So11111111111111111111111111111111111111112,1099.306621,Mustard,22Xeo6diWfJrScaoVFzgkwzrCByPukK45fdwkJyrpump,0.06560760823,0.000255551,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Mustard,5JbknNv534djG9TeCUMpLevedino2c1WrYB9pqGkyqLe,3VGaybHr8dvZbfTjJrGPLC4WhFUwZgfzXMUHeiymmHRt,2pmYAXnT8hTQzwsfYKVprXvSqcy7aKYedE5AScecSgkngkKmoncXSfM8kwHCYNBgXpvM9ZsB2VS9oK29BABJKSd2,1347,6,1,true +2024-11-25 16:04:04.000 UTC,2024-11-25,2024-11-01,Bitfoot,solana,0.24297570000000002,Buy,17.043396,blob,DgG9sM56ZcVidBV8bNArQPm93a2rmjzHkrrUntGSpump,0.00099,SOL,So11111111111111111111111111111111111111112,0.0015093945000000002,0.00000615,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-blob,7Y3oLPPrBsXGNYNaZLmhRZExFChXP84z2w1oHBjHTwCa,qjmNJ3PrUjCipauKuVtL1wefYC2kP2qq7PpmUVJdunH,VK5kFKKoSwLTfoU2Ra8ygD1ysh3YbAuN8L34RFDQewdwRGtB7R11Sm9bEWCU3rgM4Ehaj7jRwFx4iM17DmB4AYd,329,8,2,true +2024-11-25 00:40:46.000 UTC,2024-11-25,2024-11-01,Bitfoot,solana,7.53405404689,Buy,737146.667049,FCOCK,D7g7pFmuK5SPwQSvPJHgmg83dDVkSQonGqLz87Lkpump,0.030055667,SOL,So11111111111111111111111111111111111111112,0.05111361836,0.000203908,SOL,So11111111111111111111111111111111111111112,pumpdotfun,1,SOL-FCOCK,3C2YwGLpG6JuKjYJ6NsWAg5HYj7TnuXpGiBTcJzX5VPf,GnHVcSJQCpfiYAid2Vd9B6X12AWavdfuLTz6oMTiqP1A,27nAYJAyFXV3FbrR7rj26F74C9WDhd8ULNxCdnuSsjLpDnTMrcyPANbmWXMqWER2L4B8qkz6XbgxnbqYXZQibXej,1477,4,5,true +2024-11-26 18:15:44.000 UTC,2024-11-26,2024-11-01,Bitfoot,solana,11.6310085968,Sell,0.05097072,SOL,So11111111111111111111111111111111111111112,361734.413897,EDNA,CKrqbYKSUD1NQT4UE2EzVGGJAatvu28u8Ko4RdXypump,0.07369418869,0.000322951,SOL,So11111111111111111111111111111111111111112,pumpdotfun,1,SOL-EDNA,AKfD3c7b9ZQx7PgxbYEVfECnPQSkP16UmsqywAJk1weN,JAZfgjSioeg9CBV6N8L2BWrvLbGrtY5xfbPwvvUYKuFV,QcLdxmZCdmMVn3giuGdCL8HVanXY5PUTGQ3aPVWU4wtASqmv3MxYxky1uvVFBM98Hgr12P9z5QWKdaaRJU51odB,841,4,3,true +2024-11-23 22:52:04.000 UTC,2024-11-23,2024-11-01,Bitfoot,solana,1.2420067715,Sell,0.00487157,SOL,So11111111111111111111111111111111111111112,167202.885023,WINDY,4F1PHzeTp83Vg9nPWiZRYUV8sYHfTLcCDvWc53TJpump,0.007869286699999999,0.000030866,SOL,So11111111111111111111111111111111111111112,pumpdotfun,1,WINDY-SOL,,14nXezfdCTFzJ65C5NBbPvVB13oCE5cH8sX38unVYor1,5A1aCmEo46dX248DsDP9uT8j1Qu5vv4BHD1uyzfedX1TtFTQEhF98WqmcJxWGnA1ccMW8xJXH9N8W7MoGfuGDGCT,472,4,3,true +2024-11-25 05:25:32.000 UTC,2024-11-25,2024-11-01,Bitfoot,solana,12.34330347028,Sell,0.048612908,SOL,So11111111111111111111111111111111111111112,4496.168468,HYPR∞,FEiphCSAqjAxvtyMxj8boFTABrZBFyngfyrZueqeMw3q,0.07591147270000001,0.00029897,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-HYPR∞,83j8apUzRtpZwPiEdr31TxyGpA1NRLouLXxLMX8DM2iS,DgGzDWQYitL241ejctUaKQmZCRWiepqP67rsJQw9perf,3WA2P1q3BPcnSECH7EzFYiG9PsLvu6FpLH1S9mAUvuRXXFmhHtgBhiKaDNzHuAere8cWj5eLFy7xVcQBxZmkWj9K,1152,6,1,true +2024-11-23 06:29:14.000 UTC,2024-11-23,2024-11-01,Bitfoot,solana,2.03463991424,Sell,0.007840012,SOL,So11111111111111111111111111111111111111112,34.959386,FATHA,EWWDzCwq4UYW3ERTXbdgd6X6sdkKHFMJqRz1ZiFcpump,0.013530334719999999,0.000052136,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-FATHA,Am1SqWAHhaKWS4H9uwHweeYxCaECR5yDYZiX1jD9RVMP,BperhBq7YoWvWDCQnQrcp55mD6kVDwJ2zQrdSmfwWxYY,3XcpyEkiGpWRLWRsSyyHjmgqHPFk1tL9ASoZcte8wNQK6vZ5mm7xZBPLZdrT3ocHxWa4PLrfFpbpgL16MjWSMuBk,312,6,1,true +2024-11-23 00:02:40.000 UTC,2024-11-23,2024-11-01,Bitfoot,solana,5.72728636454,Sell,0.022308598,SOL,So11111111111111111111111111111111111111112,1841.951928,LEA,8SpPaFLycx897D6sowPZkEkcNdDahzRZb5itr6D8pump,0.03522284254,0.000137198,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-LEA,4ZF5Dd2KzXFE6ECFpKjcNYh48Ee1UvqiBRsVXk8EBmyT,57HvLnB3QecbktLXvxftJ1dNQ1WXnWs3RaV4mQoMwidh,4p8F6VfbMKqm8YyPgGfy7u9focAihhaVDFEBHPV5dpYyXodHjSFpxwtiBQDavEmzTazzoZLM9w6yJZCesuCYp3Gs,259,6,1,true +2024-11-22 23:19:11.000 UTC,2024-11-22,2024-11-01,Bitfoot,solana,205.32150744042,Sell,0.804614419,SOL,So11111111111111111111111111111111111111112,8657386.523431,Print,2cTbxqtyGr8C18iUPF4ditpjTyQiD5FXFF89bw9epump,1.2501000261000002,0.004898895,SOL,So11111111111111111111111111111111111111112,pumpdotfun,1,SOL-Print,Dt3nPfcQkV5i3xJUSKwox69srxtLBz1UVa9MChurqsez,48D6W1Z2p9FjhcHZi5rSbHuAzbhNHU2w4HeWKneM9NSn,39aJjXEPv9Gu5vzsXCwuEJgZ3Fr9y3UQgkrmoPwMZhas6eJDRYB2JsicR6jEhjhiu5kzwXqb3VCCa7vn2pJGFa2g,1869,4,3,true +2024-11-23 20:12:47.000 UTC,2024-11-23,2024-11-01,Bitfoot,solana,17.04803946804,Sell,0.067060182,SOL,So11111111111111111111111111111111111111112,287334.915975,Wiki,DuEGP63NvXRN1SyonCjsNpdxypMFnYsAzeRJbV9pump,0.113369409,0.00044595,SOL,So11111111111111111111111111111111111111112,raydium,4,Wiki-SOL,69fDvj22wF9DcebHvoD9wMqiFp6ueEGvKtxWcb9esHpm,12ZGFLbq86ryeEfuoeC6T49bZkTUai2EstDx1m81sfnk,5bSHtWqepdHhU14Krbn6wSgW1NX8TXXzfWngXs8R7qPb7S9gzXKFSrLGz4o5ZAbinGpzg5HPX9U2c34aFQ9FSPe9,41,6,1,true +2024-11-26 21:58:56.000 UTC,2024-11-26,2024-11-01,Bitfoot,solana,2.2846230000000003,Buy,63236.629215,AOC,2auaVtspPBW6biCkNw25VhAWmc39CurFSwtf8zRhpump,0.0099,SOL,So11111111111111111111111111111111111111112,0.014192355000000002,0.0000615,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-AOC,7w5f9fJd7274ADWAsMJ37qe7fy5d3BjNm19X74M4dn45,8RoZvSFwX3zKMHSyKVQ5BwqgGPhfxoeptkgHQy8gi2Ec,3ndjZVkEThqeY8jLZ8hwp9HG7DhQwWxghn4Mup6KSyGmBTaBvaCrwZS8HqdLtAarTN4LW4QsT9BWP2HitweMHeDy,426,9,2,true +2024-11-26 21:45:44.000 UTC,2024-11-26,2024-11-01,Bitfoot,solana,0.9725261359999999,Sell,0.0042236,SOL,So11111111111111111111111111111111111111112,204.969806,JAK,FBbnzHwJ1WHYwP425cqMNb2t7o7sm6AXQjsQ3sZRpump,0.00622438832,0.000027032,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-JAK,fYxohhysXCovowRnA184Bg5F8hb5EZUQeqFfUNH3SdB,79Ppegxb8QuNzma1KAfNKg26ZcNg1hpdkru7WKMnzZjn,2JqLMdq54vYFJhirQQZNQYSpC2GruQMxULaxcGairzhDBuSk4ES5Q7K1bWwPRr8xcNrHPwnQzNDBneVbkjJ1rYsF,1284,6,1,true +2024-11-23 14:49:56.000 UTC,2024-11-23,2024-11-01,Bitfoot,solana,129.83355,Buy,254676.289256,LOXE,Hdh5UdSUrCRCiqJoYKmgdJ25cubXqpxqkQgkXZdypump,0.495,SOL,So11111111111111111111111111111111111111112,0.8065417500000001,0.003075,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-LOXE,6dQVmJmwLZTKYwUKft6AHe3KqobkWFde8TbEZCt2dCbs,7zmFhq7LacJFGAH5PwVJrcnhczAAGTYCBa5g4Q5auFtL,z3PYDJuTgfBDbXyWMCaCeo1cWmN7ino5thDfGkZgfon1p2uD86QH3mnVdZJX5oHtGcpABqUt8hmCotW91BqX8Ef,1013,9,2,true +2024-11-25 01:26:39.000 UTC,2024-11-25,2024-11-01,Bitfoot,solana,58.51027910046,Sell,0.237585898,SOL,So11111111111111111111111111111111111111112,6336.104156,OVERSEER,3LP15DWcq1YmVw9gvnmjB1SJGmiScMm4CUX2dYf7HRV5,0.35983814931,0.001461153,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-OVERSEER,CVB7RXBYVaB6zyrW7edRaMwQo7CrPJ12QsZjgBC6muUB,92w6P8WBtUoA56iEiojd7bRQEtjWEuT5JEGEx24ysr93,4GKcxGm37qNJsg7YuSNZVfa52bCfYyQ6zBF2uFo6QasPCiUbL4gEjyB3osaFYkukhZnH4RZHDLQzgFFUkEMkkUW4,1641,6,1,true +2024-11-25 14:22:24.000 UTC,2024-11-25,2024-11-01,Bitfoot,solana,4.886838,Buy,49122.72145,BURN,7XcpJgx42Ax7oVtg1EbJTf31guAcgVnU7K4B2vG6pump,0.0198,SOL,So11111111111111111111111111111111111111112,0.03159168,0.000128,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-BURN,FeNMa3en5StkPJYXyv6yUDxbQXoVi3YDQf5whKtokntE,71aUVZrnjwrJSgGYQknJiNVEL3CRPiWNMYXjG7t5sJ9S,5W4m5SYypyyZ6ohaSrHxjkMo7JwzuJ29NCZt6yjbWCfKXzPL8gSbGsv5KuFW1g5q6iF4UEHJRighMfWhysPVsgr,416,9,2,true +2024-11-27 20:19:24.000 UTC,2024-11-27,2024-11-01,Bitfoot,solana,7.938256304599999,Sell,0.033172822,SOL,So11111111111111111111111111111111111111112,1551637.81624,Devika,524V8wH1E9a5uY5swiZMK2sLFRu9JMPTvctrnH17pump,0.07938251040000001,0.000331728,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Devika,56v84bhXnpckT6uHzd5hbm2VvMG38oube2n369ro6oEi,HuMWfZnd74V2uv7RosiyK9pBVjzK9UMmrnjKb3Gg4ons,368qxfv512er4fXDCcRkSEjW9BsrWGR1TU6aHPqFUne2indtrHiRrZizn6yEb5QXyXdoforNoE7m2o5LeByew35Q,1228,6,1,true +2024-11-28 03:51:26.000 UTC,2024-11-28,2024-11-01,Bitfoot,solana,0.34270006716,Sell,0.001427679,SOL,So11111111111111111111111111111111111111112,6918.361444,Brooks,2i21MzKS78AJBUhRyXCYQZUhvLdtyC19XzKKBfGypump,0.00342681104,0.000014276,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-Brooks,D8UZSBfGnUzczobBu2bFUENyRoofNZeDPgSd1JAzoBdL,3jWX6wQQeVtT3yRhKw7n1pnpDZEFwNqfkuzmyFdcUpwV,4rmDWqxyP6cw9iatme7zoSq895Xjk86ffM9SU5NVZp5senxwWeEP6VVbLJHBZ1xaPFypjDmqw13FKt75oSWAGvrj,1314,6,1,true +2024-11-27 19:33:15.000 UTC,2024-11-27,2024-11-01,Bitfoot,solana,11.88,Buy,45555.61198,EFAI,8ZtMMAm42U27efFJ3nPaCvsJ6FGNgG3YJNtLJR93pump,0.0495,SOL,So11111111111111111111111111111111111111112,0.0798,0.0003325,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-EFAI,3eckL39THW9181eLT6Ry71Nuj34pfctbEs4CHQuouvYJ,Cu6zE46JYtpkaKDk5qKt95vvjJsMzn9byydB6zSbLUMS,DMSFEFYmKaY7BQjmp6qo16aoUaogSKZrFWbtJzYRgjDjDfK6fKerfyS7KQemLeSyzvAyaHgNcbnqAvvftMFUDE8,1971,9,2,true From 7ac17e111aba68bc89b96957213b416fbf1eb810 Mon Sep 17 00:00:00 2001 From: clizzard <145153355+clizzard7@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:40:38 +0100 Subject: [PATCH 32/68] Update autosnipe_solana_bot_trades.sql (#7199) * Update autosnipe_solana_bot_trades.sql * fixed date * fix: move start date into future to reflect actual start date --------- Co-authored-by: whale_hunter <143016036+whalehunting@users.noreply.github.com> --- .../bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql index 97d8d471ae9..d332abc1af8 100644 --- a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/autosnipe_solana_bot_trades.sql @@ -10,7 +10,7 @@ ) }} -{% set project_start_date = '2024-11-13' %} +{% set project_start_date = '2024-05-22' %} {% set fee_receiver_1 = 'CWEfC6fLi552zE2KFxhPiBAZUWdT78gMd8NGENik2zfE' %} {% set wsol_token = 'So11111111111111111111111111111111111111112' %} From 7d7fe36aef6b148c041361ef20dc3fc5e6d8e99b Mon Sep 17 00:00:00 2001 From: senyor-kodi <175722951+senyor-kodi@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:41:04 +0100 Subject: [PATCH 33/68] add sanctum router to solana dex trades (#7188) * add sanctum router to solana dex trades * fix: cast project_program_id as varchar * fix: add time filter for last 14 days to prevent memory spilling issues * fix: fixed typos * fix: cast amount_raw cols to uint256 and drop project_main_id from final select in sanctum_router_base_trades.sql * fix: readded project_main_id col * reverted time filter to project_start_date --- .../_sector/dex/dex_solana_base_trades.sql | 1 + .../sanctum_router_base_trades.sql | 203 ++++++++++++++++++ .../sanctum_router/sanctum_router_trades.sql | 14 ++ .../_sector/dex/sanctum_router/schema.yml | 92 ++++++++ .../_sector/dex/sanctum_router/sources.yml | 19 ++ 5 files changed, 329 insertions(+) create mode 100644 dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql create mode 100644 dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_trades.sql create mode 100644 dbt_subprojects/solana/models/_sector/dex/sanctum_router/schema.yml create mode 100644 dbt_subprojects/solana/models/_sector/dex/sanctum_router/sources.yml diff --git a/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql b/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql index 41a99ad235b..991be84e941 100644 --- a/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql @@ -23,6 +23,7 @@ , ref('meteora_v2_solana_base_trades') , ref('goosefx_ssl_v2_solana_base_trades') , ref('pumpdotfun_solana_base_trades') + , ref('sanctum_router_base_trades') ] %} {% for dex in solana_dexes %} diff --git a/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql new file mode 100644 index 00000000000..9f73bb67fff --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql @@ -0,0 +1,203 @@ +{{ + config( + schema = 'sanctum_router', + alias = 'base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_id', 'outer_instruction_index', 'inner_instruction_index', 'tx_index','block_month'], + pre_hook='{{ enforce_join_distribution("PARTITIONED") }}' + ) +}} + +{% set project_start_date = '2023-02-03' %} +{% set dev_start_date = "date_trunc('day', now() - interval '7' day)" %} + +WITH swap_via_stake AS ( + SELECT + call_block_time as block_time + , call_block_slot as block_slot + , call_tx_signer as trader_id + , call_tx_id as tx_id + , call_outer_instruction_index as outer_instruction_index + , COALESCE(call_inner_instruction_index, 0) as inner_instruction_index + , call_tx_index as tx_index + , account_srcTokenFrom as token_sold_vault + , account_destTokenTo as token_bought_vault + , account_srcTokenMint as token_sold_mint_address + , account_destTokenMint as token_bought_mint_address + , bytearray_to_bigint(bytearray_reverse(bytearray_substring(call_data, 2, 8))) AS token_sold_amount_raw + , CASE + WHEN call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' + ELSE call_outer_executing_account + END as trade_source + , 'mintTo' as amount_type + FROM {{ source('sanctum_router_solana', 'stakedex_call_SwapViaStake') }} + WHERE 1=1 + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% else %} + AND call_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} +), + +prefund_swap_via_stake AS ( + SELECT + call_block_time as block_time + , call_block_slot as block_slot + , call_tx_signer as trader_id + , call_tx_id as tx_id + , call_outer_instruction_index as outer_instruction_index + , COALESCE(call_inner_instruction_index, 0) as inner_instruction_index + , call_tx_index as tx_index + , account_srcTokenFrom as token_sold_vault + , account_destTokenTo as token_bought_vault + , account_srcTokenMint as token_sold_mint_address + , account_destTokenMint as token_bought_mint_address + , bytearray_to_bigint(bytearray_reverse(bytearray_substring(call_data, 2, 8))) AS token_sold_amount_raw + , CASE + WHEN call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' + ELSE call_outer_executing_account + END as trade_source + , 'transferChecked' as amount_type + FROM {{ source('sanctum_router_solana', 'stakedex_call_PrefundSwapViaStake') }} + WHERE 1=1 + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% else %} + AND call_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} +), + +stake_wrapped_sol AS ( + SELECT + call_block_time as block_time + , call_block_slot as block_slot + , call_tx_signer as trader_id + , call_tx_id as tx_id + , call_outer_instruction_index as outer_instruction_index + , COALESCE(call_inner_instruction_index, 0) as inner_instruction_index + , call_tx_index as tx_index + , account_wsolFrom as token_sold_vault + , account_destTokenTo as token_bought_vault + , account_wsolMint as token_sold_mint_address + , account_destTokenMint as token_bought_mint_address + , bytearray_to_bigint(bytearray_reverse(bytearray_substring(call_data, 2, 8))) AS token_sold_amount_raw + , CASE + WHEN call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' + ELSE call_outer_executing_account + END as trade_source + , 'transferChecked' as amount_type + FROM {{ source('sanctum_router_solana', 'stakedex_call_StakeWrappedSol') }} + WHERE 1=1 + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% else %} + AND call_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} +), + +withdraw_deposit AS ( + SELECT + w.call_block_time as block_time + , w.call_block_slot as block_slot + , w.call_tx_signer as trader_id + , w.call_tx_id as tx_id + , w.call_outer_instruction_index as outer_instruction_index + , COALESCE(w.call_inner_instruction_index, 0) as inner_instruction_index + , w.call_tx_index as tx_index + , w.account_srcTokenFrom as token_sold_vault + , d.account_destTokenTo as token_bought_vault + , w.account_srcTokenMint as token_sold_mint_address + , d.account_destTokenMint as token_bought_mint_address + , bytearray_to_bigint(bytearray_reverse(bytearray_substring(w.call_data, 2, 8))) AS token_sold_amount_raw + , CASE + WHEN w.call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' + ELSE w.call_outer_executing_account + END as trade_source + , 'transferChecked' as amount_type + FROM {{ source('sanctum_router_solana', 'stakedex_call_PrefundWithdrawStake') }} w + INNER JOIN {{ source('sanctum_router_solana', 'stakedex_call_DepositStake') }} d + ON w.call_tx_id = d.call_tx_id + AND w.call_outer_instruction_index = d.call_outer_instruction_index + AND w.call_inner_instruction_index < d.call_inner_instruction_index + WHERE 1=1 + {% if is_incremental() %} + AND {{incremental_predicate('w.call_block_time')}} + {% else %} + AND w.call_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} +), + +all_trades AS ( + SELECT * FROM swap_via_stake + UNION ALL + SELECT * FROM prefund_swap_via_stake + UNION ALL + SELECT * FROM stake_wrapped_sol + UNION ALL + SELECT * FROM withdraw_deposit +), + +token_amounts AS ( + SELECT + ic.tx_id, + ic.outer_instruction_index, + ic.inner_instruction_index, + bytearray_to_bigint(bytearray_reverse(bytearray_substring(ic.data, 2, 8))) AS amount_bought, + ROW_NUMBER() OVER ( + PARTITION BY ic.tx_id, ic.outer_instruction_index + ORDER BY + CASE + WHEN b.amount_type = 'mintTo' THEN ic.inner_instruction_index + ELSE -ic.inner_instruction_index + END + ) as rn + FROM all_trades b + INNER JOIN {{ source('solana','instruction_calls') }} ic + ON ic.tx_id = b.tx_id + AND ic.outer_instruction_index = b.outer_instruction_index + AND ic.block_slot = b.block_slot + WHERE 1=1 + AND ic.executing_account = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' + AND ( + (b.amount_type = 'mintTo' AND bytearray_substring(ic.data, 1, 1) = 0x07 AND ELEMENT_AT(ic.account_arguments, 1) = b.token_bought_mint_address) + OR + (b.amount_type = 'transferChecked' AND bytearray_substring(ic.data, 1, 1) = 0x0c AND ELEMENT_AT(ic.account_arguments, 2) = b.token_bought_mint_address AND ELEMENT_AT(ic.account_arguments, 3) = b.token_bought_vault) + ) + {% if is_incremental() %} + AND {{incremental_predicate('ic.block_time')}} + {% else %} + AND ic.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} +) + +SELECT + 'solana' as blockchain + , 'sanctum_router' as project + , 1 as version + , CAST(date_trunc('month', b.block_time) AS DATE) as block_month + , b.block_time + , b.block_slot + , b.trade_source + , CAST(t.amount_bought as uint256) as token_bought_amount_raw + , CAST(b.token_sold_amount_raw as uint256) as token_sold_amount_raw + , CAST(NULL as double) as fee_tier + , b.token_bought_mint_address + , b.token_sold_mint_address + , b.token_bought_vault + , b.token_sold_vault + , CAST(NULL as varchar) as project_program_id + , 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' as project_main_id + , b.trader_id + , b.tx_id + , CAST(b.outer_instruction_index as integer) as outer_instruction_index + , CAST(b.inner_instruction_index as integer) as inner_instruction_index + , b.tx_index +FROM all_trades b +INNER JOIN token_amounts t + ON b.tx_id = t.tx_id + AND b.outer_instruction_index = t.outer_instruction_index + AND t.rn = 1 diff --git a/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_trades.sql b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_trades.sql new file mode 100644 index 00000000000..9580d25e6c4 --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_trades.sql @@ -0,0 +1,14 @@ + {{ + config( + schema = 'sanctum_router', + alias = 'trades', + post_hook='{{ expose_spells(\'["solana"]\', + "project", + "sanctum_router", + \'["senyor-kodi"]\') }}' + ) +}} + +-- backwards compatible view so we don't break any user queries +select * from {{ref('dex_solana_trades')}} +where project = 'sanctum_router' and version = 1 \ No newline at end of file diff --git a/dbt_subprojects/solana/models/_sector/dex/sanctum_router/schema.yml b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/schema.yml new file mode 100644 index 00000000000..65523f108c0 --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/schema.yml @@ -0,0 +1,92 @@ +version: 2 + +models: + - name: sanctum_router_base_trades + meta: + blockchain: solana + sector: dex + project: sanctum + contributors: [ senyor-kodi ] + config: + tags: ['solana','dex'] + description: > + Sanctum Router trades on Solana + data_tests: + - check_columns_solana_dex_trades + - dbt_utils.unique_combination_of_columns: + combination_of_columns: [ 'tx_id', 'outer_instruction_index', 'inner_instruction_index', 'tx_index', 'block_month' ] + + - name: sanctum_router_trades + meta: + blockchain: solana + sector: dex + project: sanctum + contributors: [ senyor-kodi ] + config: + tags: ['solana','dex'] + description: > + Sanctum Router trades on Solana + columns: + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &project + name: project + description: "Project name of the DEX" + - &version + name: version + description: "Version of the contract built and deployed by the DEX project" + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &block_time + name: block_time + description: "UTC event block time of each DEX trade" + - &block_slot + name: block_slot + description: "block slot of each DEX trade" + - &trade_source + name: trade_source + description: "Was the trade a direct call to the dexor did it go through another program like Jupiter (Dex Aggregator)" + - &token_bought_amount_raw + name: token_bought_amount_raw + description: "Raw value of the token bought at time of execution in the original currency" + - &token_sold_amount_raw + name: token_sold_amount_raw + description: "Raw value of the token sold at time of execution in the original currency" + - &fee_tier + name: fee_tier + description: "dexfee tier (fee %)" + - &token_bought_mint_address + name: token_bought_address + description: "token mint address of the token bought" + - &token_sold_mint_address + name: token_sold_address + description: "token mint address of the token sold" + - &token_bought_vault + name: token_bought_vault + description: "token associated address for thedex, of the token bought" + - &token_sold_vault + name: token_sold_vault + description: "token associated address for thedex, of the token sold" + - &project_program_id + name: project_program_id + description: "pool program id of the project" + - &project_main_id + name: project_main_id + description: "main program id of the project" + - &trader_id + name: trader_id + description: "id (address) of trader who purchased a token" + - &tx_id + name: tx_id + description: "Unique transaction id value tied to each transaction on the DEX" + - &outer_instruction_index + name: outer_instruction_index + description: "top level instruction index for a given transaction id" + - &inner_instruction_index + name: inner_instruction_index + description: "inner instruction index for a given transaction id" + - &tx_index + name: tx_index + description: "index of the transaction in the block slot" \ No newline at end of file diff --git a/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sources.yml b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sources.yml new file mode 100644 index 00000000000..9814e5d2ceb --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sources.yml @@ -0,0 +1,19 @@ +version: 2 + +sources: + - name: sanctum_router_solana + description: "Sanctum Router decoded contract calls on Solana" + freshness: # default freshness + warn_after: { count: 12, period: hour } + error_after: { count: 24, period: hour } + tables: + - name: stakedex_call_SwapViaStake + loaded_at_field: call_block_time + - name: stakedex_call_PrefundSwapViaStake + loaded_at_field: call_block_time + - name: stakedex_call_StakeWrappedSol + loaded_at_field: call_block_time + - name: stakedex_call_PrefundWithdrawStake + loaded_at_field: call_block_time + - name: stakedex_call_DepositStake + loaded_at_field: call_block_time From aff2cf5ce16fdd75704b6454aeb17adde2ec0607 Mon Sep 17 00:00:00 2001 From: whale_hunter <143016036+whalehunting@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:52:13 +0100 Subject: [PATCH 34/68] feat: add banana gun evm bot trades spellbook (#7180) * init * fix: rename tests to data_tests * chore: disable test for now * chore: add base spellbook, remove outcommented test * feat: add blast spellbook * fix: pick tx_hash column from botTrades table * chore: add bot column, change project_start_date * chore: add real start date for blast * chore: move start date to original value * chore: remove miner bribes from spellbook schema * chore: remove blast spellbook, since it has no data yet * fix: add incremental filters * test: add check_bot_trades_seed for dex subproject * fix: remove leading AND in where condition * test: add base seed * fix: cast value column to decimal * test: add correct seed files * fix: force version column to get parsed as string in seed * Revert "fix: force version column to get parsed as string in seed" This reverts commit 7e6e570893d5ccc200bdcc5f2876452c782b8cff. * fix: force seed column as varchar * fix: fix typo * fix: do not cast fee_token_address to varchar * add type info of varbinary column to seed schema * make hash varbinary as well * fix: remove blockchain filter from seed test * Update dbt_subprojects/dex/models/bot_trades/banana_gun/base/banana_gun_base_bot_trades.sql Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> * perf: add incremental filter to ethereum --------- Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- .../dex/models/bot_trades/_schema.yml | 132 ++++++++++++ .../base/banana_gun_base_bot_trades.sql | 196 +++++++++++++++++ .../banana_gun_ethereum_bot_trades.sql | 198 ++++++++++++++++++ .../models/bot_trades/dex_evm_bot_trades.sql | 57 +++++ .../banana_gun_base_trades_seed.csv | 21 ++ .../banana_gun_ethereum_trades_seed.csv | 21 ++ .../seeds/bot_trades/banana_gun/schema.yml | 24 +++ .../tests/generic/check_bot_trades_seed.sql | 15 ++ 8 files changed, 664 insertions(+) create mode 100644 dbt_subprojects/dex/models/bot_trades/_schema.yml create mode 100644 dbt_subprojects/dex/models/bot_trades/banana_gun/base/banana_gun_base_bot_trades.sql create mode 100644 dbt_subprojects/dex/models/bot_trades/banana_gun/ethereum/banana_gun_ethereum_bot_trades.sql create mode 100644 dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql create mode 100644 dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_base_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_ethereum_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/banana_gun/schema.yml create mode 100644 dbt_subprojects/dex/tests/generic/check_bot_trades_seed.sql diff --git a/dbt_subprojects/dex/models/bot_trades/_schema.yml b/dbt_subprojects/dex/models/bot_trades/_schema.yml new file mode 100644 index 00000000000..2cafe84746b --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/_schema.yml @@ -0,0 +1,132 @@ +version: 2 + +models: + - name: dex_evm_bot_trades + meta: + blockchain: ethereum, base, bnb, avalanche_c + sector: dex + contributors: ["whale_hunter"] + config: + tags: ["evm", "dex", "bot", "trades"] + description: > + Trades by trading bots on EVM chains + columns: + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &block_number + name: block_number + description: "Block number that includes the DEX trade" + - &block_time + name: block_time + description: "UTC event block time of each DEX trade" + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &bot + name: bot + description: "Trading bot which executed the trade" + - &amount_usd + name: amount_usd + description: "USD value of the trade at time of execution" + - &type + name: type + description: "Wether the trade is a buy or sell" + - &token_bought_amount + name: token_bought_amount + description: "Value of the token bought at time of execution in the original currency" + - &token_bought_symbol + name: token_bought_symbol + description: "Token symbol for token bought in the trade" + - &token_bought_address + name: token_bought_address + description: "Contract address of the token bought" + - &token_sold_amount + name: token_sold_amount + description: "Value of the token sold at time of execution in the original currency" + - &token_sold_symbol + name: token_sold_symbol + description: "Token symbol for token sold in the trade" + - &token_sold_address + name: token_sold_address + description: "Contract address of the token sold" + - &fee_percentage_fraction + name: fee_percentage_fraction + description: "The trading fee in percent, as a fraction of 100" + - &fee_usd + name: fee_usd + description: "USD value of the fee at time of execution" + - &fee_token_amount + name: fee_token_amount + description: "Value of the fee paid at time of execution in the original currency" + - &fee_token_symbol + name: fee_token_symbol + description: "Token symbol for fee token" + - &fee_token_address + name: fee_token_address + description: "Contract address of the fee token" + - &project + name: project + description: "Project name of the DEX" + - &version + name: version + description: "Version of the contract built and deployed by the DEX project" + - &token_pair + name: token_pair + description: "Token symbol pair for each token involved in the trade" + - &project_contract_address + name: project_contract_address + description: "Project contract address which executed the trade on the blockchain" + - &user + name: user + description: "Address which initiated the trade" + - &tx_hash + name: tx_hash + description: "Unique transaction hash value tied to each transaction on the DEX" + - &evt_index + name: evt_index + description: "Index of the corresponding trade event" + - &is_last_trade_in_transaction + name: is_last_trade_in_transaction + description: "Wether the trade is the last hop of the trade transaction, in case of a multi-hop trade" + + - name: banana_gun_ethereum_bot_trades + meta: + blockchain: ethereum + sector: dex + project: banana_gun + contributors: whale_hunter + config: + tags: ["evm", "dex", "banana_gun", "trades"] + description: > + Banana Gun trades on Ethereum + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('banana_gun_ethereum_trades_seed') + + - name: banana_gun_base_bot_trades + meta: + blockchain: base + sector: dex + project: banana_gun + contributors: whale_hunter + config: + tags: ["evm", "dex", "banana_gun", "trades"] + description: > + Banana Gun trades on Base + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('banana_gun_base_trades_seed') diff --git a/dbt_subprojects/dex/models/bot_trades/banana_gun/base/banana_gun_base_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/banana_gun/base/banana_gun_base_bot_trades.sql new file mode 100644 index 00000000000..6126ae66844 --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/banana_gun/base/banana_gun_base_bot_trades.sql @@ -0,0 +1,196 @@ +{{ config( + alias = 'bot_trades', + schema = 'banana_gun_base', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'tx_hash', 'evt_index'] + ) +}} + +{% set project_name = 'Banana Gun' %} +{% set project_start_date = '2024-03-05' %} +{% set blockchain = 'base' %} +{% set bot_deployer_1 = '0x37aAb97476bA8dC785476611006fD5dDA4eed66B' %} +{% set weth = '0x4200000000000000000000000000000000000006' %} +{% set fee_token_symbol = 'ETH' %} + +WITH + botContracts AS ( + SELECT + address + FROM + {{ source('base','creation_traces') }} + WHERE + ( + "from" = {{bot_deployer_1}} + ) + AND block_time >= TIMESTAMP '{{project_start_date}}' + ), + botTrades AS ( + SELECT + trades.block_time, + amount_usd, + IF( + token_sold_address = {{weth}}, + 'Buy', + 'Sell' + ) AS type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + project, + version, + token_pair, + project_contract_address, + tx_from AS user, + tx_to AS bot, + trades.tx_hash, + evt_index + FROM + {{ source('dex', 'trades') }} as trades + JOIN botContracts ON trades.tx_to = botContracts.address + WHERE + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('trades.block_time') }} + {% else %} + AND trades.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ), + highestEventIndexForEachTrade AS ( + SELECT + tx_hash, + MAX(evt_index) AS highestEventIndex + FROM + botTrades + GROUP BY + tx_hash + ), + botETHDeposits AS ( + SELECT + tx_hash, + block_number, + CAST(value AS DECIMAL (38, 0)) AS deltaGwei, + CAST(value AS DECIMAL (38, 0)) AS depositGwei + FROM + {{ source('base','traces') }} + JOIN botContracts ON to = botContracts.address + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND value > CAST(0 AS UINT256) + ), + botETHWithdrawals AS ( + SELECT + tx_hash, + block_number, + CAST(value AS DECIMAL (38, 0)) * -1 AS deltaGwei, + 0 AS depositGwei, + block_hash, + to + FROM + {{ source('base','traces') }} + JOIN botContracts ON "from" = botContracts.address + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND value > CAST(0 AS UINT256) + ), + botEthTransfers AS ( + /* Deposits */ + ( + SELECT + tx_hash, + block_number, + deltaGwei, + depositGwei + FROM + botETHDeposits + ) + UNION ALL + /* Withdrawals */ + ( + SELECT + tx_hash, + block_number, + deltaGwei, + depositGwei + FROM + botETHWithdrawals + ) + ), + botEthDeltas AS ( + SELECT + tx_hash, + block_number, + SUM(deltaGwei) AS feeGwei, + SUM(depositGwei) AS depositGwei + FROM + botEthTransfers + GROUP BY + tx_hash, + block_number + ) +SELECT + block_time, + date_trunc('day', botTrades.block_time) as block_date, + date_trunc('month', botTrades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' AS blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + ROUND( + CAST(feeGwei AS DOUBLE) / CAST(depositGwei AS DOUBLE), + /* Round feePercentage to 0.01% steps */ + 4 + ) AS fee_percentage_fraction, + (feeGwei / 1e18) * price AS fee_usd, + feeGwei / 1e18 fee_token_amount, + '{{fee_token_symbol}}' AS fee_token_symbol, + {{weth}} AS fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user, + botTrades.tx_hash, + evt_index, + IF(evt_index = highestEventIndex, true, false) AS is_last_trade_in_transaction +FROM + botTrades + JOIN highestEventIndexForEachTrade ON botTrades.tx_hash = highestEventIndexForEachTrade.tx_hash + LEFT JOIN botETHDeltas ON botTrades.tx_hash = botETHDeltas.tx_hash + LEFT JOIN {{ source('prices', 'usd') }} ON ( + blockchain = '{{blockchain}}' + AND contract_address = {{weth}} + AND minute = DATE_TRUNC('minute', block_time) + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% endif %} + ) +ORDER BY + block_time DESC, + evt_index DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/bot_trades/banana_gun/ethereum/banana_gun_ethereum_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/banana_gun/ethereum/banana_gun_ethereum_bot_trades.sql new file mode 100644 index 00000000000..51b2a6ecf64 --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/banana_gun/ethereum/banana_gun_ethereum_bot_trades.sql @@ -0,0 +1,198 @@ +{{ config( + alias = 'bot_trades', + schema = 'banana_gun_ethereum', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'tx_hash', 'evt_index'] + ) +}} + +{% set project_name = 'Banana Gun' %} +{% set project_start_date = '2023-05-26' %} +{% set blockchain = 'ethereum' %} +{% set bot_deployer_1 = '0xf414d478934c29d9a80244a3626c681a71e53bb2' %} +{% set bot_deployer_2 = '0x37aAb97476bA8dC785476611006fD5dDA4eed66B' %} +{% set weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} +{% set fee_token_symbol = 'ETH' %} + +WITH + botContracts AS ( + SELECT + address + FROM + {{ source('ethereum','creation_traces') }} + WHERE + ( + "from" = {{bot_deployer_1}} + OR "from" = {{bot_deployer_2}} + ) + AND block_time >= TIMESTAMP '{{project_start_date}}' + ), + botTrades AS ( + SELECT + trades.block_time, + amount_usd, + IF( + token_sold_address = {{weth}}, + 'Buy', + 'Sell' + ) AS type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + project, + version, + token_pair, + project_contract_address, + tx_from AS user, + tx_to AS bot, + trades.tx_hash, + evt_index + FROM + {{ source('dex', 'trades') }} as trades + JOIN botContracts ON trades.tx_to = botContracts.address + WHERE + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('trades.block_time') }} + {% else %} + AND trades.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ), + highestEventIndexForEachTrade AS ( + SELECT + tx_hash, + MAX(evt_index) AS highestEventIndex + FROM + botTrades + GROUP BY + tx_hash + ), + botETHDeposits AS ( + SELECT + tx_hash, + block_number, + CAST(value AS DECIMAL (38, 0)) AS deltaGwei, + CAST(value AS DECIMAL (38, 0)) AS depositGwei + FROM + {{ source('ethereum','traces') }} + JOIN botContracts ON to = botContracts.address + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND value > 0 + ), + botETHWithdrawals AS ( + SELECT + tx_hash, + block_number, + CAST(value AS DECIMAL (38, 0)) * -1 AS deltaGwei, + 0 AS depositGwei, + block_hash, + to + FROM + {{ source('ethereum','traces') }} + JOIN botContracts ON "from" = botContracts.address + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND value > 0 + ), + botEthTransfers AS ( + /* Deposits */ + ( + SELECT + tx_hash, + block_number, + deltaGwei, + depositGwei + FROM + botETHDeposits + ) + UNION ALL + /* Withdrawals */ + ( + SELECT + tx_hash, + block_number, + deltaGwei, + depositGwei + FROM + botETHWithdrawals + ) + ), + botEthDeltas AS ( + SELECT + tx_hash, + block_number, + SUM(deltaGwei) AS feeGwei, + SUM(depositGwei) AS depositGwei + FROM + botEthTransfers + GROUP BY + tx_hash, + block_number + ) +SELECT + block_time, + date_trunc('day', botTrades.block_time) as block_date, + date_trunc('month', botTrades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' AS blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + ROUND( + CAST(feeGwei AS DOUBLE) / CAST(depositGwei AS DOUBLE), + /* Round feePercentage to 0.01% steps */ + 4 + ) AS fee_percentage_fraction, + (feeGwei / 1e18) * price AS fee_usd, + feeGwei / 1e18 fee_token_amount, + '{{fee_token_symbol}}' AS fee_token_symbol, + {{weth}} AS fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user AS user, + botTrades.tx_hash, + evt_index, + IF(evt_index = highestEventIndex, true, false) AS is_last_trade_in_transaction +FROM + botTrades + JOIN highestEventIndexForEachTrade ON botTrades.tx_hash = highestEventIndexForEachTrade.tx_hash + LEFT JOIN botETHDeltas ON botTrades.tx_hash = botETHDeltas.tx_hash + LEFT JOIN {{ source('prices', 'usd') }} ON ( + blockchain = '{{blockchain}}' + AND contract_address = {{weth}} + AND minute = DATE_TRUNC('minute', block_time) + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% endif %} + ) +ORDER BY + block_time DESC, + evt_index DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql new file mode 100644 index 00000000000..c339d2e2b55 --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql @@ -0,0 +1,57 @@ +{{ + config( + schema = 'dex_evm', + alias = 'bot_trades', + materialized = 'view', + post_hook = '{{ expose_spells( + blockchains = \'["ethereum", "base", "blast", "arbitrum", "bnb", "avalanche_c"]\', + spell_type = "sector", + spell_name = "bot_trades", + contributors = \'["whale_hunter"]\') }}' + ) +}} + + + +{% set evm_trading_bots = [ + ref('banana_gun_ethereum_bot_trades') + ,ref('banana_gun_base_bot_trades') +] %} + +{% for bot in evm_trading_bots %} +SELECT block_time, + block_date, + block_month, + bot, + block_number, + blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + fee_percentage_fraction, + fee_usd, + fee_token_amount, + fee_token_symbol, + fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user, + tx_hash, + evt_index, + is_last_trade_in_transaction +FROM {{ bot }} +{% if not loop.last %} +UNION ALL +{% endif %} +{% endfor %} \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_base_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_base_trades_seed.csv new file mode 100644 index 00000000000..8f565dddb42 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_base_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2024-09-07 08:46:55.000 UTC,2024-09-07 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19454734,base,3441.57,Sell,1.5,WETH,0x4200000000000000000000000000000000000006,206629.39352997296,MIGGLES,0xb1a03eda10342529bbf8eb700a06c60441fef25d,0.005,34.4157,0.015,ETH,0x4200000000000000000000000000000000000006,uniswap,2,MIGGLES-WETH,0x17a3ad8c74c4947005afeda9965305ae2eb2518a,0x40237a6d80e9a4d9cd8341c5ad42ce3733b822c1,0xda8352e2a41cc3d5793e2211816d7c234ddad30db2b97860f4b6c26be6d5aa67,7,true +2024-09-01 14:10:41.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19205247,base,48.757227722772264,Buy,836176.1213013215,DarkPepePope,0xdc3793eab4681e57b2755783403b3dcc573f220b,0.0198019801980198,WETH,0x4200000000000000000000000000000000000006,0.005,0.48757227722772517,0.000198019801980199,ETH,0x4200000000000000000000000000000000000006,uniswap,2,DarkPepePope-WETH,0x67a45158523835d8477a1877c756c7b8c252d722,0x117c921e599ee1c4f73fe74b08ca584db08475e4,0x25c17e72dc3ede0eec14d4e34b198a7b6854904e8bd862af99814d28e4566204,12,true +2024-09-01 14:10:41.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19205247,base,731.358415841584,Buy,538747.542958548,MUNCHER,0xdcce6d3d2f6fe2e9201de68422f7568610b39860,0.297029702970297,WETH,0x4200000000000000000000000000000000000006,0.005,7.313584158415843,0.002970297029702971,ETH,0x4200000000000000000000000000000000000006,uniswap,2,MUNCHER-WETH,0x3be1dd1c8f859fc49f1da72b1d1328b6595a297d,0x56714990cef7019a7ee8a5bc0e8e6ad991aa76e5,0x0ee0458c7dd96ee1125196cbdb414f31de5c2ab6561ec05be72c791359264e3a,5,true +2024-09-10 09:14:03.000 UTC,2024-09-10 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19585148,base,349.26831683168314,Buy,9105325812.505402,D.O.G.E,0x755b004d7d5dc8fdc92c39333134811e3a69955d,0.1485148514851485,WETH,0x4200000000000000000000000000000000000006,0.005,3.4926831683168333,0.001485148514851486,ETH,0x4200000000000000000000000000000000000006,uniswap,2,D.O.G.E-WETH,0x45b992355d1fa3c5c50ba446c90b578a7b779433,0xaaf1df00167fe59d43c8d1944a6f28aaf8f40f83,0xf09148ffe271bfe5d28c3547362073257ce0d2bb86e6ef788fe6195247441a43,4,true +2024-09-06 15:51:25.000 UTC,2024-09-06 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19424269,base,112.36625779738371,Sell,0.048872106175385115,WETH,0x4200000000000000000000000000000000000006,1027321.7559139789,UBPS,0x0c90c756350fb803a7d5d9f9ee5ac29e77369973,0.005,1.1236625779738343,0.00048872106175385,ETH,0x4200000000000000000000000000000000000006,uniswap,2,UBPS-WETH,0x4557eacd191e266d4166c603131ef3b006836cae,0x24acc9d9517c1ccfd7ffeaaefbc8666a582fc64b,0xdf164d9670faa4429521a5339a0676d7f47c74817a86fd03cf85fb8e9083757c,9,true +2024-09-05 05:14:37.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19361965,base,4.844921559141894,Sell,0.002009432065639148,WETH,0x4200000000000000000000000000000000000006,74784.28391180358,BARIO,0x814fe70e85025bec87d4ad3f3b713bdcaac0579b,0.005,0.04844921559141778,0.000020094320656391,ETH,0x4200000000000000000000000000000000000006,uniswap,3,BARIO-WETH,0x19efcd30370cd4858df84415d9b63eda2048ef27,0x012cd7fb379b72d4c19988d377c3076aa81583a6,0xca1fd9509fd36d1eb4174857b14bfb9dd1fe8ab18fc31c61ad5425301c9b9017,2,true +2024-09-04 00:57:23.000 UTC,2024-09-04 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19311048,base,0.4824217821782178,Buy,26.822871758695317,MIGGLES,0xb1a03eda10342529bbf8eb700a06c60441fef25d,0.000198019801980198,WETH,0x4200000000000000000000000000000000000006,0.005,0.004824217821782226,0.000001980198019802,ETH,0x4200000000000000000000000000000000000006,uniswap,2,MIGGLES-WETH,0x17a3ad8c74c4947005afeda9965305ae2eb2518a,0xbd5ce37cf9c61d781b28ba8c1d612e12f6507243,0x70166ba1b17ce988996e5240a8fd71021e716b29863236a468c636ededbe5b18,35,true +2024-09-05 16:51:15.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19382864,base,141.05584158415843,Buy,16561085558.942457,PEPE,0x52b492a33e447cdb854c7fc19f1e57e8bfa1777d,0.05940594059405941,WETH,0x4200000000000000000000000000000000000006,0.005,1.4105584158415865,0.000594059405940595,ETH,0x4200000000000000000000000000000000000006,uniswap,3,PEPE-WETH,0x0fb597d6cfe5be0d5258a7f017599c2a4ece34c7,0xa7650835f35c4997f93a9e3bb40bc6c0ba8d059d,0x49b82a258a59bd179c4da535038bad40186d59224c431e7fad34a0adf50bf68a,3,true +2024-09-05 22:16:21.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19392617,base,117.19306930693071,Buy,8673078.991486527,XRAY,0x3c48ae7b78bf9ba91fc8e5f6f6bf9f089f278328,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1719306930693094,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,WETH-XRAY,0xb924036f602fa75f0d4ac9545ee4d6d00261c8ad,0xc4dd8211988263c932c0afb59677dd92ab898046,0x6fcd2bc0c758a0aff18c18069a13173f90e7455ed93d8f5317ff62d78dd1cf61,11,true +2024-09-05 21:22:43.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19391008,base,235.0237623762376,Buy,17697.68136626327,WELL,0xa88594d404727625a9437c3f886c7643872296ae,0.09900990099009901,WETH,0x4200000000000000000000000000000000000006,0.005,2.350237623762378,0.000990099009900991,ETH,0x4200000000000000000000000000000000000006,aerodrome,1,WELL-WETH,0x89d0f320ac73dd7d9513ffc5bc58d1161452a657,0x56d0ffbb368ecfb8111a6637fc698d6325e8bc01,0x553bf030f289a28cdb96e4da372ebb3ecf8b138062845edc5266494744d894a3,6,true +2024-09-01 16:31:43.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19209478,base,0.23501467838723727,Sell,0.000094977299170814,WETH,0x4200000000000000000000000000000000000006,51.4387631,Nermie,0x519a319e9bb1000c504a20485084df2337c4c14d,0.005,0.0023501467838670776,9.49772991706e-7,ETH,0x4200000000000000000000000000000000000006,sushiswap,1,Nermie-WETH,0xeb5b859dcc061e1e567d89c8ea5bacbe570b6c4e,0x2f0fcdfda8b4065a4d266ddc53c077750e3b485f,0xa203f9e3f43c2288aff00fc6a9f2aea8a3dc6f84f2c32abcd70c8d6a272ba743,10,true +2024-09-01 12:09:59.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19201626,base,4959.661963579478,Sell,1.9988723188013517,WETH,0x4200000000000000000000000000000000000006,,,0xc53eb9ecc247465e2e1fb16b2ede3a6446053170,0.005,49.59661963579477,0.01998872318801351,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xa854492182dcbda450bcd9ee04870818484dd8ad,0x591be26c53aa3ed600c1c994ecbc2deb545bebb4,0x0c581fc5af9d3a53525f5d31fb09fb9d4dbe5772629ed1c5b2879ad6a59ba30c,11,true +2024-09-01 12:09:59.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19201626,base,51.84239373333868,Sell,0.020893828356637105,WETH,0x4200000000000000000000000000000000000006,,,0xc53eb9ecc247465e2e1fb16b2ede3a6446053170,0.005,49.59661963579477,0.01998872318801351,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xa854492182dcbda450bcd9ee04870818484dd8ad,0x591be26c53aa3ed600c1c994ecbc2deb545bebb4,0x0c581fc5af9d3a53525f5d31fb09fb9d4dbe5772629ed1c5b2879ad6a59ba30c,3,false +2024-09-04 15:30:23.000 UTC,2024-09-04 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19337238,base,24.098712871287123,Buy,878817.008049761,TRFY,0xa7ebc5f9b67e790ac0b5d24ed0d531d319cea597,0.0099009900990099,WETH,0x4200000000000000000000000000000000000006,0.005,0.2409871287128737,0.0000990099009901,ETH,0x4200000000000000000000000000000000000006,uniswap,2,TRFY-WETH,0x5f27785b5e2c8263bdec279c75245b980099ac9d,0x64c23d3f619d825bab287f3c52a0f39d3a03c263,0x37c292515191685a193c9400f4fed0ecdc3e1e8dc08e2a527f79cbc000cec727,4,true +2024-09-02 16:30:51.000 UTC,2024-09-02 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19252652,base,33.64625262721495,Sell,0.013366804770162664,WETH,0x4200000000000000000000000000000000000006,1541948.1284249476,BEE,0xfd09f108d1728e6b6ed241ccd254775e322f1ed6,0.005,0.3364625262721479,0.000133668047701626,ETH,0x4200000000000000000000000000000000000006,uniswap,2,BEE-WETH,0x500e45173f466c058e6dcecd15b27a1e091d92d4,0x64c23d3f619d825bab287f3c52a0f39d3a03c263,0x097dd6b26059fce8166f8fea84aaa12ae13b075cf0d077f717cc1bc31e41ec1b,5,true +2024-09-05 21:11:25.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390669,base,117.3920792079208,Buy,5649267.692887611,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xe3ea037ca6ea651cc3f476712b30374c2115e74e,0xdaf6c33941140880d5baff25f8c65f1362048575535d31bff39d07a56ac510ae,11,true +2024-09-05 21:11:25.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390669,base,117.3920792079208,Buy,4982612.726137387,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xb73bc3772cf29da413966f36fe18a1dd392cf1b6,0xcc475368ad6c4e6e30df134aaad618fc9fcc9101cf01518c2be3d3170ee11d3c,32,true +2024-09-05 21:11:55.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390684,base,117.3920792079208,Buy,4786468.142259231,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xe9869a8c089502b8a8b54b53a9df3ce295a4c17b,0x6909a7e16826cf57cbf3b836e57dcb850150f86902c7d62892db55ab02916947,4,true +2024-09-05 21:11:25.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390669,base,117.3920792079208,Buy,5191072.771597835,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xfe906d692a47246518fe05cd5852501bfb51f012,0x2935af8e620e15691ca2b9e5dc78d1179dc2b4222d1835a35d5955d3951c7a36,25,true +2024-09-05 21:11:55.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390684,base,117.3920792079208,Buy,4601687.433549198,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xfe906d692a47246518fe05cd5852501bfb51f012,0x3f15863dd32a63136646bde0b816fa080f6153c0d6d74d94d7b0bb5fa3d59140,11,true diff --git a/dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_ethereum_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_ethereum_trades_seed.csv new file mode 100644 index 00000000000..bbaf14cedf0 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_ethereum_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2023-06-19 15:26:59.000 UTC,2023-06-19 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17514676,ethereum,83.12745837737252,Sell,0.04836365974946039,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,401724.712464711,IG,0x1c60343f8ee1db0617097341abf56c308597d9d9,0.005,0.4037242114329775,0.000234887253568174,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,IG-WETH,0xec3615f6cd9f2df234c877e501d53f9eef22fcc4,0x842be3379d61bb4d63e757ab485fee99a6cebecc,0x6173075a5d069d1db4187e145ab35849e0bbc25cc2eb8164d0ec8afd76d27ad7,24,false +2023-06-06 17:22:11.000 UTC,2023-06-06 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17422854,ethereum,116.46015223455811,Sell,0.06250511334447438,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,48700.164228039175,0xC,0x2aa4c7e845ced2cb3180a6584df15efd0d886bdb,0.005,0.5823007611727888,0.000312525566722371,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,0xC-WETH,0x57680221d5f90d871f82f43fdf4824a2717041e7,0xc4fb7ad11fbc1c5733e5f56043f44c690d6c5686,0x7611950dedf03734be5a95a7d5a983bd20edcaeae9151568dc32424b6a61ada5,45,true +2023-06-17 13:13:11.000 UTC,2023-06-17 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17499751,ethereum,83.27189660506818,Sell,0.04785878709449592,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,8710044.64601209,METH,0x2d6cfa8781755c922a14d0e7c111700060490198,0.005,0.41635948302533987,0.000239293935472479,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,METH-WETH,0xcd9e2214ae0449d47f2becd56516d1a497a8c5e7,0xbbd018a45b40bb699df47c7bca87623810a2534b,0x69efeb79af7bc11600b5d11a6a8d85a7949f7695801fe1c648916eef368a0d4e,14,true +2023-06-21 21:56:23.000 UTC,2023-06-21 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17530850,ethereum,182.88032782937748,Sell,0.09753877587635802,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,15122057.069775704,DEN,0xe28901beb0630379ced910053294b6f953309c3a,0.005,0.9144016391468872,0.00048769387938179,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,3,DEN-WETH,0xe4da8e91076fdd026c5582279268785dd44f0038,0xe12352f93b86b7262099e8039580990c80e83ca5,0xa92bd896bb9c23194180d03fc93ecea65155c42ed1aaaa89737772f8f98ea1c6,12,true +2023-06-19 18:12:47.000 UTC,2023-06-19 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17515493,ethereum,419.944958659094,Sell,0.24176868838212176,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,48012.75194671747,$ELY,0x8ed2fc62d6850eaadcb717465752dab591286839,0.005,2.973855242525905,0.001712093612742825,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,$ELY-WETH,0xeed363729bdb7f9d7b5fce5dbf8bd5cc4fc98f7f,0xc8ef2326093c2491bb474be405fb04f5cb89a7ce,0xd96b1f10f419f83a3653e10d39dcb667f56fb92eeb13ec66e3bae2643311f10d,92,false +2023-06-30 12:38:47.000 UTC,2023-06-30 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17592143,ethereum,189.009205,Buy,835861314077.003,EPEP,0x975b624dda0903c8100bafccfd537458933d410e,0.0995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,0.949795,0.0005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,EPEP-WETH,0x32eabaec2bd26d647b568715a514a76757c86145,0x8b38b7f821b9a7216d45d49047ecfbf80ae3a566,0xfc7d27e1633e07e8581a8c16939936aa446c07a4399ad9f908d563e868b260e3,22,true +2023-06-28 16:03:59.000 UTC,2023-06-28 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17578886,ethereum,229.26480250785545,Sell,0.12313750900059911,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,275400,FIND,0x638df5a6ef481b4e01982ba750d0008c98ed4c24,0.005,1.1463240125392762,0.000615687545002995,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,FIND-WETH,0xd384a0f245d6a54856f924a9708fdde8c7f3d3a9,0x5b46ff3f518d4db5ff50105dfbe917ce79f6c3bb,0x7d6d07a85bdd642e6964552e1f8e72f0a8911e3408b3c9a10072f6928d89a3aa,42,true +2023-06-05 02:01:35.000 UTC,2023-06-05 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17411242,ethereum,377.23,Buy,2758703618.5463076,SATOSHI,0xf048fdef5f29ca7f4f96a97d534eec1b17c0356f,0.2,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,0,0,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,SATOSHI-WETH,0x76197528ae1f5586c0d636a8859edb2c5daf7681,0x7fd1fa18d2748a0b39d413724d733d2a24075280,0x0e37882eb552c5f9ff5497a076203a4717654ced04ca8c34adbedd41356d32f5,31,true +2023-06-19 12:05:47.000 UTC,2023-06-19 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17513684,ethereum,361.039881415359,Sell,0.2091178526463281,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,71874339683920.4,SHA,0x95565f27d9b7fcacb04954ca4f24b486a641f001,0.005,1.8051994070767943,0.00104558926323164,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,SHA-WETH,0x81de191d0a57f86901a7aec8d44a0698e0f8fb96,0xe12352f93b86b7262099e8039580990c80e83ca5,0xab8668a0d124e9a2c2a4e01e19476e150007e9ac7f4370339c8ad79f690f8813,22,true +2023-06-25 16:00:23.000 UTC,2023-06-25 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17557542,ethereum,62.20631360805016,Buy,12000000000,QBERT,0xa09116cfd21f49689c32083cb3a3632d40c6f7fe,0.03293639664106686,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.0016,0.31103156804025023,0.000164681983205334,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,QBERT-WETH,0x9461485ef8c8c8cdfc910e81e58b03c6b4485553,0xe77fd9756dac9ebfe8a7d9c623d988814987964e,0x41acb6080b560735fd8479e7dc59daf01815c6f9aa6c440ad0ba55aeed653c97,60,true +2023-06-05 01:02:35.000 UTC,2023-06-05 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17410953,ethereum,266.1148617401801,Sell,0.1412027091472491,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,750000,ASUKA,0xfe25f375aa07298f75c39d155855a7c6ecfbbf69,0.005,3.2677701481407015,0.00173390540750211,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,ASUKA-WETH,0xfc93d2b86be176548d2b1b8c007adc85d6c0cc8b,0x9c99d7af32c576eb71dbccc3718be211eb3e14ab,0x263ef72c8cef7859284b4d64f7503ed04e141f79c4482e9fb8360bcbddc79af7,20,false +2023-06-20 15:29:23.000 UTC,2023-06-20 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17521804,ethereum,56.0700216923059,Sell,0.03259278604695981,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,7354.848321544704,0xDeaD,0xdead0f0e934a4137a21811bff798850b0a90dead,0.005,0.2803501084615294,0.000162963930234799,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,0xDeaD-WETH,0xc9a2d5f44b90d957716e656229e142d37270d19a,0x490a028a817a4eb52164c37fda25cff1f1b4b180,0xad85c2bf9d0fc141fe3e44c0f7e69e169c7b9e9bf834c57535d71aa677f296cc,57,true +2023-06-25 19:49:47.000 UTC,2023-06-25 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17558676,ethereum,141.05486574079083,Sell,0.07459510388525856,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,441453.320819254,VisionX,0x8551353a87993c14329df0322f673bca640e3906,0.005,0.7052743287039527,0.000372975519426292,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,VisionX-WETH,0xae5dcd5f4e54998b740eec0af1d8bcbd3ad21b03,0xdee6cfc3c51550e5bd46a4613a09424bc62b6be6,0x96347e0ab77ff0988b616ff584ca8bf2b823ba202e56a1299d45b0e71212a666,20,true +2023-06-23 18:45:23.000 UTC,2023-06-23 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17544135,ethereum,382.533684871126,Sell,0.2003990260527886,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,102707.0809698149,FUMOKILLER,0x9bbe2cebee8c0aba957224e512e4de54bbf79fe6,0.005,1.9126684243556284,0.001001995130263942,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,FUMOKILLER-WETH,0x91459946d9ad8c89fa807488f9e84d83263b5678,0xc4fb7ad11fbc1c5733e5f56043f44c690d6c5686,0x00db9d11fdfc76d624438c577ce6b0734cc50deea875cdb656d730ef036cc1c4,49,true +2023-06-29 20:34:23.000 UTC,2023-06-29 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17587364,ethereum,106.34892104701531,Sell,0.057466023130925144,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1600000,MrsPepe2.0,0x0c2eee9858623f8e6da32c1c3683ed22ef7be5fc,0.005,0.5317446052350753,0.000287330115654625,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,MrsPepe2.0-WETH,0xeaca43d704daae77aed4722a60c32b5538e4aa1c,0xafabb3a635747797dd05ab662ce5dd070ee28b91,0x2f08c34efc6e3397146aaf70afb65afe4d7d47a6811e2b837df933fea1f308b4,70,true +2023-06-29 12:31:47.000 UTC,2023-06-29 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17584974,ethereum,153.49601411690773,Sell,0.08200186665504244,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,12331187.874773905,YFO,0x1f8c2c3e9a17ecd378911a122e876a43993a5e51,0.005,0.7674800705845383,0.000410009333275212,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,WETH-YFO,0xacbd3bdce79c65250ee53aded4a186d4ca2ace23,0xfcc33fc7ab61cda35b8b8abee0635733b388d1bf,0x4f21c5f745e6945c74d6270f63510139bdffa452b150499cef4c03fcab508aae,142,true +2023-06-20 22:14:11.000 UTC,2023-06-20 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17523802,ethereum,0.7480057655563455,Sell,0.000420468901031122,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,7394.251038698974,RPUNKS,0x340b8776063abfdd5117c35e3a4b228079ea6d90,0.005,0.17150376326334374,0.000096405672499603,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,RPUNKS-WETH,0x7dfb889c888189e91c3ca56a993c55594eee3b61,0x0d87e9d89a0c24f5879ea8ab72590ff5cedf2c9b,0x04858f207f668c2a36221c2bd878680dd4f62e7fc925ffd884c50e8a41c8bd9c,90,false +2023-06-20 15:00:11.000 UTC,2023-06-20 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17521662,ethereum,171.22855500000003,Buy,2636.3410224539093,0xDeaD,0xdead0f0e934a4137a21811bff798850b0a90dead,0.0995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,0.860445,0.0005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,0xDeaD-WETH,0xc9a2d5f44b90d957716e656229e142d37270d19a,0xf5ccaf5dcd921b98c594ccdd3b16435006113cc6,0xf33227d240b85898ce859514f0b0c8c016973a1921ce2cea0cd95a8e251aa04b,274,true +2023-06-21 22:48:59.000 UTC,2023-06-21 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17531111,ethereum,360.64435523988095,Sell,0.1915335967029475,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,261323.81103556513,BCT,0x2281c37cc6e7ac0ded17eb1494f63f94a8ee568a,0.005,1.8032217761994038,0.000957667983514737,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,BCT-WETH,0x244ce07231d5156f22a21212768c1fa5e8d84e1b,0xbd42b534f896448ac6cfa7d8229d5b76d46f1927,0x08e369ddc65e1cfba3f2f4ce79a1a7c375d1511ba7d91dcbe641dfe124e1de87,20,true +2023-06-08 22:40:23.000 UTC,2023-06-08 00:00:00.000 UTC,2023-06-01 00:00:00.000 UTC,Banana Gun,17438595,ethereum,84.80449692865044,Buy,20000000000,TARD,0x4a0386cf685e5e2b73a730a85ac3ee65a62585f5,0.045737914574223326,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0,0,0,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TARD-WETH,0x01084d791298ed32bde3481d06b1a59d36757897,0xc8ef2326093c2491bb474be405fb04f5cb89a7ce,0x29e5a82febb20b6539ceb635e7d70588d867860456a17fa10739624e28f198d8,61,true diff --git a/dbt_subprojects/dex/seeds/bot_trades/banana_gun/schema.yml b/dbt_subprojects/dex/seeds/bot_trades/banana_gun/schema.yml new file mode 100644 index 00000000000..9e25049c7c2 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/banana_gun/schema.yml @@ -0,0 +1,24 @@ +version: 2 + +seeds: + - name: banana_gun_ethereum_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary + + - name: banana_gun_base_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary diff --git a/dbt_subprojects/dex/tests/generic/check_bot_trades_seed.sql b/dbt_subprojects/dex/tests/generic/check_bot_trades_seed.sql new file mode 100644 index 00000000000..446757bf1ba --- /dev/null +++ b/dbt_subprojects/dex/tests/generic/check_bot_trades_seed.sql @@ -0,0 +1,15 @@ +-- this tests checks a dex bot_trades model for every row in a seed file. +-- actual implementation in macros/test-helpers/check_seed.sql +{% test check_bot_trades_seed(model, seed_file, blockchain=None, filter=None) %} + + {%- if blockchain == 'solana' -%} + {%- set seed_matching_columns = ['blockchain', 'project', 'version', 'tx_id', 'tx_index', 'outer_instruction_index', 'inner_instruction_index'] -%} + {%- else -%} + {%- set seed_matching_columns = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index',] -%} + {%- endif -%} + + {%- set seed_check_columns = ['fee_token_amount', 'fee_token_address', 'project_contract_address', 'token_bought_address', 'token_sold_address', 'user'] -%} + + {{ check_seed_macro(model, seed_file, seed_matching_columns,seed_check_columns,filter) }} + +{% endtest %} \ No newline at end of file From df8e7790417468e09affc304e2be43647631b611 Mon Sep 17 00:00:00 2001 From: clizzard <145153355+clizzard7@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:03:14 +0100 Subject: [PATCH 35/68] Feat pepeboost evm trades spellbook (#7181) * init * fix: rename tests to data_tests * chore: disable test for now * chore: add base spellbook, remove outcommented test * feat: add blast spellbook * fix: pick tx_hash column from botTrades table * chore: add bot column, change project_start_date * chore: add real start date for blast * chore: move start date to original value * chore: remove miner bribes from spellbook schema * chore: remove blast spellbook, since it has no data yet * fix: add incremental filters * test: add check_bot_trades_seed for dex subproject * fix: remove leading AND in where condition * test: add base seed * fix: cast value column to decimal * test: add correct seed files * add pepeboost evm trades ethereum * fix syntax * fix: force version column to get parsed as string in seed * fix seed * Revert "fix: force version column to get parsed as string in seed" This reverts commit 7e6e570893d5ccc200bdcc5f2876452c782b8cff. * fix: force seed column as varchar * fix: fix typo * add schema * fix: do not cast fee_token_address to varchar * fix varbinary * add type info of varbinary column to seed schema * make hash varbinary as well * fix: remove blockchain filter from seed test * fix: cast all varbinary column explicitly * Update dbt_subprojects/dex/models/bot_trades/banana_gun/base/banana_gun_base_bot_trades.sql Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> * perf: add incremental filter to ethereum * perf: add incremental filter in join condition --------- Co-authored-by: whalehunting <143016036+whalehunting@users.noreply.github.com> Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- .../dex/models/bot_trades/_schema.yml | 20 ++ .../pepeboost_ethereum_bot_trades.sql | 194 ++++++++++++++++++ .../pepeboost_ethereum_trades_seed.csv | 21 ++ .../dex/seeds/bot_trades/pepeboost/schema.yml | 13 ++ 4 files changed, 248 insertions(+) create mode 100644 dbt_subprojects/dex/models/bot_trades/pepeboost/ethereum/pepeboost_ethereum_bot_trades.sql create mode 100644 dbt_subprojects/dex/seeds/bot_trades/pepeboost/pepeboost_ethereum_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/pepeboost/schema.yml diff --git a/dbt_subprojects/dex/models/bot_trades/_schema.yml b/dbt_subprojects/dex/models/bot_trades/_schema.yml index 2cafe84746b..a8b5051de1d 100644 --- a/dbt_subprojects/dex/models/bot_trades/_schema.yml +++ b/dbt_subprojects/dex/models/bot_trades/_schema.yml @@ -130,3 +130,23 @@ models: - evt_index - check_bot_trades_seed: seed_file: ref('banana_gun_base_trades_seed') + + + - name: pepeboost_ethereum_bot_trades + meta: + blockchain: ethereum + sector: dex + project: pepeboost + contributors: whale_hunter + config: + tags: ["evm", "dex", "pepeboost", "trades"] + description: > + Pepeboost trades on Ethereum + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('pepeboost_ethereum_trades_seed') diff --git a/dbt_subprojects/dex/models/bot_trades/pepeboost/ethereum/pepeboost_ethereum_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/pepeboost/ethereum/pepeboost_ethereum_bot_trades.sql new file mode 100644 index 00000000000..ce24a17c97e --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/pepeboost/ethereum/pepeboost_ethereum_bot_trades.sql @@ -0,0 +1,194 @@ +{{ config( + alias = 'bot_trades', + schema = 'pepeboost_ethereum', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'tx_hash', 'evt_index'] + ) +}} + +{% set project_name = 'Pepeboost' %} +{% set project_start_date = '2023-08-28' %} +{% set blockchain = 'ethereum' %} +{% set bot_deployer_1 = '0xeaBEe4C63bD085Fd906d6be5d387B5EEDfF83919' %} +{% set weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} +{% set fee_token_symbol = 'ETH' %} + +WITH + botContracts AS ( + SELECT + address + FROM + {{ source('ethereum','creation_traces') }} + WHERE + "from" = {{bot_deployer_1}} + AND block_time >= TIMESTAMP '{{project_start_date}}' + ), + botTrades AS ( + SELECT + trades.block_time, + amount_usd, + IF( + token_sold_address = {{weth}}, + 'Buy', + 'Sell' + ) AS type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + project, + version, + token_pair, + project_contract_address, + tx_from AS user, + tx_to AS bot, + trades.tx_hash, + evt_index + FROM + {{ source('dex', 'trades') }} as trades + JOIN botContracts ON trades.tx_to = botContracts.address + WHERE + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('trades.block_time') }} + {% else %} + AND trades.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ), + highestEventIndexForEachTrade AS ( + SELECT + tx_hash, + MAX(evt_index) AS highestEventIndex + FROM + botTrades + GROUP BY + tx_hash + ), + botETHDeposits AS ( + SELECT + tx_hash, + block_number, + CAST(value AS DECIMAL (38, 0)) AS deltaGwei, + CAST(value AS DECIMAL (38, 0)) AS depositGwei + FROM + {{ source('ethereum','traces') }} + JOIN botContracts ON to = botContracts.address + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND value > 0 + ), + botETHWithdrawals AS ( + SELECT + tx_hash, + block_number, + CAST(value AS DECIMAL (38, 0)) * -1 AS deltaGwei, + 0 AS depositGwei, + block_hash, + to + FROM + {{ source('ethereum','traces') }} + JOIN botContracts ON "from" = botContracts.address + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND value > 0 + ), + botEthTransfers AS ( + /* Deposits */ + ( + SELECT + tx_hash, + block_number, + deltaGwei, + depositGwei + FROM + botETHDeposits + ) + UNION ALL + /* Withdrawals */ + ( + SELECT + tx_hash, + block_number, + deltaGwei, + depositGwei + FROM + botETHWithdrawals + ) + ), + botEthDeltas AS ( + SELECT + tx_hash, + block_number, + SUM(deltaGwei) AS feeGwei, + SUM(depositGwei) AS depositGwei + FROM + botEthTransfers + GROUP BY + tx_hash, + block_number + ) +SELECT + block_time, + date_trunc('day', botTrades.block_time) as block_date, + date_trunc('month', botTrades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' AS blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + ROUND( + CAST(feeGwei AS DOUBLE) / CAST(depositGwei AS DOUBLE), + /* Round feePercentage to 0.01% steps */ + 4 + ) AS fee_percentage_fraction, + (feeGwei / 1e18) * price AS fee_usd, + feeGwei / 1e18 fee_token_amount, + '{{fee_token_symbol}}' AS fee_token_symbol, + {{weth}} AS fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user AS user, + botTrades.tx_hash, + evt_index, + IF(evt_index = highestEventIndex, true, false) AS is_last_trade_in_transaction +FROM + botTrades + JOIN highestEventIndexForEachTrade ON botTrades.tx_hash = highestEventIndexForEachTrade.tx_hash + LEFT JOIN botETHDeltas ON botTrades.tx_hash = botETHDeltas.tx_hash + LEFT JOIN {{ source('prices', 'usd') }} ON ( + blockchain = '{{blockchain}}' + AND contract_address = {{weth}} + AND minute = DATE_TRUNC('minute', block_time) + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% endif %} + ) +ORDER BY + block_time DESC, + evt_index DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/bot_trades/pepeboost/pepeboost_ethereum_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/pepeboost/pepeboost_ethereum_trades_seed.csv new file mode 100644 index 00000000000..5645bdd3976 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/pepeboost/pepeboost_ethereum_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2024-03-16 11:48:11.000 UTC,2024-03-16 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19447257,ethereum,1827.9162000000001,Buy,50817275171.0449,HELGA,0x78e3b2ee11950df78a35fd924e92fbb8d1403780,0.495,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,18.463800000000003,0.005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,HELGA-WETH,0x5484094940909b16fe991d1adad6a40dfef63417,0x85dba58d67e021489ee1f843de7a7e1fc1ec60e7,0x91f963bc342304acdec15f1716199e8f32e6a3e66bdf88a9e9129fa2a21fa563,58,true +2024-03-10 08:09:23.000 UTC,2024-03-10 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19403410,ethereum,371.51845134960644,Sell,0.09389271523478493,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,8895.610034508,TRSCT,0xfe98796e0af4ababd716508429e51ff9ac1bb4d5,0.005,3.715184513496063,0.000938927152347849,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TRSCT-WETH,0xd4fe3d36d8c405833972987c5fd977345aae2e8a,0x2c32c56471ddae47225ee82658c176945733b180,0x4290ee906089f82d1ba46320d3d2f0737a895009f701afc0d7adfc8e31fbb81d,55,true +2024-03-17 04:57:35.000 UTC,2024-03-17 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19452334,ethereum,282.385224,Buy,9586055909.065296,Jason,0x5d101234df81ab0dfea96e089e3c3dd8840a6ac9,0.0792,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,2.852376,0.0008,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,Jason-WETH,0x49cb6005bcb0aac703e724abe7e76786e9b46226,0xe8490eefeecdcf6cde83dd58ba084c40d98c6535,0xcd74520b2128a5896bfe82f63154cfa89d2febe57b6de5d78df92c63531a3ffd,104,true +2024-03-04 14:12:35.000 UTC,2024-03-04 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19362317,ethereum,689.63202,Buy,87639994.84559023,TRUMP INU,0xd3fb8597d260efb2e693efd500d62a330a00f1eb,0.198,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,6.96598,0.002,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TRUMP INU-WETH,0xa20379e47b2b9b5a02557fd2c862d2915a509bd3,0xf64e814ffad5be14f87a28ab96f9f7112c02d402,0x4835dbed040a104d98fd2e8b8e765e9381dca73c351d28c8b33eb8f6be8106a1,75,true +2024-03-10 07:58:23.000 UTC,2024-03-10 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19403356,ethereum,979.39215,Buy,710909441.5894133,BOYSCLUB,0x2d9996f3b9d2e73540fdbfdfe81d71e9e08cbf03,0.2475,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,9.89285,0.0025,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,BOYSCLUB-WETH,0x7dbc4253e35f20be7164f0a3e0959c33136d007d,0x422412ee213110bc6a7ef3d1d14237893a862bb2,0xefd57d544fade3d4261a7edf0d4f6c0a752802fe79c06ae11a1b04709892141a,94,true +2024-03-02 11:30:23.000 UTC,2024-03-02 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19347195,ethereum,676.22544,Buy,5989066734.089885,HELGA,0x78e3b2ee11950df78a35fd924e92fbb8d1403780,0.198,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,6.83056,0.002,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,HELGA-WETH,0x5484094940909b16fe991d1adad6a40dfef63417,0x7523a8fdbcc92143cf523b6d771433369e915722,0x18f32fec182dba1359473a365d08eb6ead9701d38b8ab31b286976aec8582b61,44,true +2024-03-24 03:17:59.000 UTC,2024-03-24 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19501691,ethereum,1317.00096,Buy,1829.0936718975227,DEAI,0x1495bc9e44af1f8bcb62278d2bec4540cf0c05ea,0.396,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,13.303040000000001,0.004,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,3,DEAI-WETH,0x1385fc1fe0418ea0b4fcf7adc61fc7535ab7f80d,0x854afe28e369c5c2a11f6db6eb40474715c6f121,0xea9797fd00cee663435ccea89614ec3e15f232c9b71173363583727c4cda4eba,25,true +2024-03-28 04:34:23.000 UTC,2024-03-28 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19530259,ethereum,788.4641517453738,Sell,0.22455688987963482,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,169786.953716372,ZENO,0xd51e4965ad973e8c1e1f22369bb884e6914b012c,0.005,7.884641517453737,0.002245568898796348,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,WETH-ZENO,0xef64da9c4840b2c88b2f73b79db3c4e51e27f53a,0xd11f4f01e19d81f8f5abe1f72b1703abfa6b2bbe,0x7568957888e39759fb13c2f16ea0c6216fcbafe34a51ec6e8f9f051e7b4e2858,29,true +2024-03-16 18:38:23.000 UTC,2024-03-16 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19449282,ethereum,797.8422523975116,Sell,0.22122464352984395,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,3854750.491038198,vitalek,0xf5264e1673c9365e7c5d4d1d8b440bbf131ff435,0.005,7.978422523975114,0.002212246435298439,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,vitalek-WETH,0xc8733a25df841f25afeb97ac77e39909d80d5a37,0x9e2d558fccde1ba893ccd00a967dcb39385cae8f,0x9e43de67645117f2b226bdc4e8487fd840cec5640659a5fec57b982c830810c7,145,true +2024-03-01 15:37:23.000 UTC,2024-03-01 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19341264,ethereum,530.3106900148174,Sell,0.15543473953989473,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,5985742.476313816,VAI,0x0cbda0b3fafc4f3730e2c574f52c01c7d94a8a0c,0.005,5.303106900148173,0.001554347395398947,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,VAI-WETH,0x9021acf529ea6a068188e948891db3450bd9f35b,0x84c54ed3b718abd4fa7890b8ce140de6df4e3559,0xc7952373fbacede7463bf770c785da9a818d4063de3760962015079c33f1e661,57,true +2024-03-10 14:53:35.000 UTC,2024-03-10 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19405416,ethereum,1776.9845572782094,Sell,0.45657597348347356,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,899875.5930412533,vitalek,0xf5264e1673c9365e7c5d4d1d8b440bbf131ff435,0.005,17.769845572782092,0.004565759734834735,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,vitalek-WETH,0xc8733a25df841f25afeb97ac77e39909d80d5a37,0x7523a8fdbcc92143cf523b6d771433369e915722,0x6ae1f85413e33f71f5528b1dd620916b0e1abc5e993ec626ed4b7d6936029c42,80,true +2024-03-10 05:31:23.000 UTC,2024-03-10 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19402622,ethereum,322.89277658668607,Sell,0.0816455851448454,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,608817.981919313,BRETT,0x80ee5c641a8ffc607545219a3856562f56427fe9,0.005,3.2289277658668603,0.000816455851448454,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,BRETT-WETH,0x95f2610d0475d72e75bfcbd8bb7ecafe1f351b8d,0xca1857c70aa23f9b5620dbe2bd71b46cd4cb8386,0x6da3fe9d1d3fe30f4e67ed3392984d620805754c1581a4c06227d1e365a15d56,60,true +2024-03-14 07:10:23.000 UTC,2024-03-14 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19431678,ethereum,789.6517200000001,Buy,758892204.8401858,SPEPE,0x7dafe897a6ff1d7b0b64f908e60e8665b61d53af,0.198,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,7.97628,0.002,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,SPEPE-WETH,0xf4041d29ad20219188cb6f4a3ea0fd1b8192a856,0xe4fe0f848583560b8d58a11288cf3dcb1d97ba81,0xe3fe2589cfb03be13632d3f0c588b96a73192cf965ea771c254b2b8cb8ff2709,35,true +2024-03-27 06:32:59.000 UTC,2024-03-27 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19523922,ethereum,7149.4632,Buy,2837722531.63614,GROK1.5,0xa711bcc2b6f5c4fc3dfaccc2a01148765cbbab1c,1.98,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,72.2168,0.02,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,GROK1.5-WETH,0x8a4008961a27752e1c7178b73b9d5fa1d37fee3c,0x4f75a7ca7f6c527d051e400795307e5a395f1b05,0xeca5c9e2e45077a7fe9f4fb19cc4279d8d3556fa3a808c77a822352f9397e56b,46,true +2024-03-07 16:11:35.000 UTC,2024-03-07 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19384405,ethereum,761.65056,Buy,35389.9155006131,HOSTAI,0x07e128e823d2b9b22edbda43820aa1a72de99613,0.198,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,7.69344,0.002,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,HOSTAI-WETH,0x88ee95da6046bc3256d43b7c6883e61415b6e442,0xc7576de93acff71a4516476431a03a1a7f20f3a6,0xd4439e2a97d08d5ee847dc38b80e8b33957db593d5543c88784f24d266cef0c4,47,true +2024-03-07 19:50:35.000 UTC,2024-03-07 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19385493,ethereum,4276.941256077766,Sell,1.1036555721767025,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,2612.2416695698207,TAS,0x64d5fea7d2d600918b76159285994d6ed218f264,0.005,42.76941256077766,0.011036555721767025,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TAS-WETH,0x40849deb556ff2c682088a12b0299ad821ae231a,0xa0a8cdf195b8f383339946a6d748ef6b1d55337e,0x410aa5ad1888333775a990fcb0faf140470b0b8e2036d20aa3e0a9b954963790,62,true +2024-03-12 17:37:11.000 UTC,2024-03-12 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19420533,ethereum,341.20073688283304,Sell,0.08796962241282545,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,894722874971.9131,Dinger,0xcd145189a12ccc3f9c622766fb20d00dc2059ead,0.005,3.4120073688283283,0.000879696224128254,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,Dinger-WETH,0x62f0a25f884cc9bf186196cc1cae15a58fce4732,0xccbb78b5b5066128c70310aaf87254e33054711f,0xef54f3fd55bf02228fdd390ffa11f60415c7c37c6375445c45aa4a5fc456c7b5,55,true +2024-03-15 23:39:35.000 UTC,2024-03-15 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19443665,ethereum,1420.366789210197,Sell,0.380544410177255,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,495160811.29605335,GROK1.5,0xa711bcc2b6f5c4fc3dfaccc2a01148765cbbab1c,0.005,14.203667892101969,0.003805444101772549,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,GROK1.5-WETH,0x8a4008961a27752e1c7178b73b9d5fa1d37fee3c,0x6ff42a9d716ffa5f8e234d00486065226e0376d4,0x7f9e9f40792db4c65e763bc10233eaafec8d163783840fcedadfcec35dea2196,23,true +2024-03-07 03:59:59.000 UTC,2024-03-07 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19380769,ethereum,1311.07284,Buy,1158788900.8645384,DieHarder,0xeea5fb81328343984298819275bda5489e796e62,0.3465,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.01,13.243160000000001,0.0035,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,DieHarder-WETH,0x70410f43d761c5134fdb6e427beb57c1849bac0f,0x79eb850503df9c01997c4ce4ee35a240cce9a45e,0x5cd2a3a05f9f173704256bad8e47e4aabb8abb3220065870a128002a2b5055d2,64,true +2024-03-18 04:24:23.000 UTC,2024-03-18 00:00:00.000 UTC,2024-03-01 00:00:00.000 UTC,Pepeboost,19459285,ethereum,12.078782121141744,Sell,0.003364600753529773,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,845.6214538922925,RAI,0x049c3ee0c38742c1d4904ae957de66d2b240031d,0.005,0.12078782121141482,0.000033646007535297,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,RAI-WETH,0xd12dabe90a1b3dbbf11f257d9d57014ac5ca74cf,0xce23b9958e8e72c716a58041110d05bd705abfff,0xf672df35cd8d7454a7a018da265152a811c2bd05ad21600e1cf9f553e72c5f9e,25,true diff --git a/dbt_subprojects/dex/seeds/bot_trades/pepeboost/schema.yml b/dbt_subprojects/dex/seeds/bot_trades/pepeboost/schema.yml new file mode 100644 index 00000000000..dd18e224376 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/pepeboost/schema.yml @@ -0,0 +1,13 @@ +version: 2 + +seeds: + - name: pepeboost_ethereum_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary From 35aa1cdd25bff9c14a11f08f7b809bb4754e501c Mon Sep 17 00:00:00 2001 From: bram-vdberg Date: Thu, 28 Nov 2024 13:04:06 +0100 Subject: [PATCH 36/68] Add new addresses for Fractal and Quasilabs (#7185) --- .../cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql index a97515ed8be..84d496300be 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql @@ -116,8 +116,11 @@ known_solver_metadata (address, environment, name) as ( (0x2224eAaCC7c2DBf85d5355BAb9E9271e01d30b55, 'prod', 'Sector_Finance'), (0x9DFc9Bb0FfF2dc96728D2bb94eaCee6ba3592351, 'prod', 'Rizzolver'), (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), + (0x95480d3f27658e73b2785d30beb0c847d78294c7, 'prod', 'FractalSolver'), + (0x00806DaA2Cfe49715eA05243FF259DeB195760fC, 'prod', 'Quasilabs'), + (0x7E2eF26AdccB02e57258784957922AEEFEe807e5, 'barn', 'FractalSolver'), (0x5131590ca2E9D3edC182581352b289dcaE83430c, 'barn', 'Portus'), - (0x2a2883ade8ce179265f12fc7b48a4b50b092f1fd, 'barn', 'Fractal'), + (0x2a2883ade8ce179265f12fc7b48a4b50b092f1fd, 'barn', 'FractalSolver'), (0x26B5e3bF135D3Dd05A220508dD61f25BF1A47cBD, 'barn', 'Rizzolver'), (0xA6A871b612bCE899b1CbBad6E545e5e47Da98b87, 'barn', 'Barter'), (0xa08B00576aeE8d8dd960E08298FAc9fD7C756e36, 'barn', 'Apollo'), From 7ddc7617c5164ae447354a5d9fbebc0ad348ae66 Mon Sep 17 00:00:00 2001 From: PA <50184410+peyha@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:04:25 +0100 Subject: [PATCH 37/68] feat: add morpho to tokens (#7200) --- .../models/tokens/base/tokens_base_erc20.sql | 101 +++++++++--------- .../tokens/ethereum/tokens_ethereum_erc20.sql | 60 ++++++----- 2 files changed, 82 insertions(+), 79 deletions(-) diff --git a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql index 027885e76fa..95d8dab348c 100644 --- a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql @@ -245,58 +245,58 @@ FROM (VALUES , (0x62a52757b580e7fd97203bd0408a7445741b5d5f, 'DT', 18) , (0x6985884c4392d348587b19cb9eaaf157f13271cd, 'ZRO', 18) , (0x64b88c73A5DfA78D1713fE1b4c69a22d7E0faAa7, 'MAV', 18) - , (0x0f1D1b7abAeC1Df25f2C4Db751686FC5233f6D3f, 'IMO', 18) + , (0x0f1D1b7abAeC1Df25f2C4Db751686FC5233f6D3f, 'IMO', 18) , (0x9beec80e62aa257ced8b0edd8692f79ee8783777, 'TIMI', 18) - , (0x013b6451e2b2131052d3473593bd786df5143faf, 'FRENCH', 18) - , (0x31b28012f61fc3600e1c076bafc9fd997fb2da90, 'MRSMIGGLES', 18) - , (0x420b0fa3de2efcf2b2fd04152eb1df36a09717cd, 'KING', 18) + , (0x013b6451e2b2131052d3473593bd786df5143faf, 'FRENCH', 18) + , (0x31b28012f61fc3600e1c076bafc9fd997fb2da90, 'MRSMIGGLES', 18) + , (0x420b0fa3de2efcf2b2fd04152eb1df36a09717cd, 'KING', 18) , (0x190b2aA820495c0e92840E8FA699741976cd6439, 'rETH', 18) , (0x85e90a5430af45776548adb82ee4cd9e33b08077, 'DINO', 18) , (0x7c6b91D9Be155A6Db01f749217d76fF02A7227F2, 'BAL', 18) - , (0xa1e4240C9E9B8db3ba9e7625A9571c3B0FF71988, 'PJ', 18) - , (0x340c070260520ae477b88caa085a33531897145b, '9MM', 18) - , (0x38d513ec43dda20f323f26c7bef74c5cf80b6477, 'CARLO', 18) - , (0x8d3419b9a18651f3926a205ee0b1acea1e7192de, 'LOA', 18) - , (0xed899bfdb28c8ad65307fa40f4acab113ae2e14c, 'ROOST', 18) - , (0x6bd81aad9b25ad1e0b99c47ed01b34eacf4b8be7, 'BODA', 18) - , (0x75570e1189ffc1d63b3417cdf0889f87cd3e9bd1, 'Bunny', 18) - , (0x1c7a460413dd4e964f96d8dfc56e7223ce88cd85, 'SEAM', 18) - , (0x8319767a7b602f88e376368dca1b92d38869b9b4, 'PEACH', 18) - , (0x42069de48741db40aef864f8764432bbccbd0b69, 'BETS', 18) - , (0x1ccb4b14a11e0f2994a7ecbbd4cc69632f4c7c76, 'CCC', 18) - , (0xacd1caef47e4c47bafe8a51b3f4305fc38203b7a, 'LUNE', 18) - , (0xd327d36eb6e1f250d191cd62497d08b4aaa843ce, 'FOMO', 9) - , (0x00e57ec29ef2ba7df07ad10573011647b2366f6d, 'TOSHE', 18) - , (0xf1b4ddf712e108cf43711b1c39f2fddb0d5ce243, 'BASE', 18) - , (0x87c211144b1d9bdaa5a791b8099ea4123dc31d21, 'BCP', 18) - , (0xa5fbc981ebd8f4e791be8bd7a9b7cb144d145bf9, 'MEMEGOD', 18) - , (0x30d19fb77c3ee5cfa97f73d72c6a1e509fa06aef, 'CONDO', 18) - , (0x8b781e0f2967571e96d5d95b3cb61e27785eeaa5, 'BORKIE', 18) - , (0x3159fb5589acd6bf9f82eb0efe8382ed55aed8fd, 'APU', 18) - , (0x029635e83bc26c96006298e05798cdda76a2e7a5, 'SYD', 18) - , (0x314da69de85145fdd5b7580971e9db0388a2cdc4, 'BSW', 18) - , (0x8ad5b9007556749de59e088c88801a3aaa87134b, 'FARTHER', 18) - , (0x64cc19a52f4d631ef5be07947caba14ae00c52eb, 'KIBBLE', 18) - , (0x45096bd2871911ee82a3084d77a01efa3c9c6733, 'BUB', 18) - , (0x44fccd875c8e80b37f38530f434386a6d59141bb, 'DTB', 18) - , (0xfd008f937b4d73eeb00cf74ce90c392be5f07f96, 'MOON', 18) - , (0x160381343365de6d5e7d32172987b3e6bd1cce71, 'Mari', 18) - , (0x546d239032b24eceee0cb05c92fc39090846adc7, 'SEED', 18) - , (0x4c584cbc3a221998dc003349e1c12a4179e97b25, 'BMONEY', 18) - , (0x9721b1ce4ffd8af047bbdfd87e4e20ddc544513a, 'BROS', 18) - , (0xc41ba5737baf6bd0ccd5daf7eee39874e4ad45ff, 'DEGENS', 18) - , (0x10c1b6f768e13c624a4a23337f1a5ba5c9be0e4b, 'WARPIE', 18) - , (0xfd9fa4f785331ce88b5af8994a047ba087c705d8, '$blue', 18) + , (0xa1e4240C9E9B8db3ba9e7625A9571c3B0FF71988, 'PJ', 18) + , (0x340c070260520ae477b88caa085a33531897145b, '9MM', 18) + , (0x38d513ec43dda20f323f26c7bef74c5cf80b6477, 'CARLO', 18) + , (0x8d3419b9a18651f3926a205ee0b1acea1e7192de, 'LOA', 18) + , (0xed899bfdb28c8ad65307fa40f4acab113ae2e14c, 'ROOST', 18) + , (0x6bd81aad9b25ad1e0b99c47ed01b34eacf4b8be7, 'BODA', 18) + , (0x75570e1189ffc1d63b3417cdf0889f87cd3e9bd1, 'Bunny', 18) + , (0x1c7a460413dd4e964f96d8dfc56e7223ce88cd85, 'SEAM', 18) + , (0x8319767a7b602f88e376368dca1b92d38869b9b4, 'PEACH', 18) + , (0x42069de48741db40aef864f8764432bbccbd0b69, 'BETS', 18) + , (0x1ccb4b14a11e0f2994a7ecbbd4cc69632f4c7c76, 'CCC', 18) + , (0xacd1caef47e4c47bafe8a51b3f4305fc38203b7a, 'LUNE', 18) + , (0xd327d36eb6e1f250d191cd62497d08b4aaa843ce, 'FOMO', 9) + , (0x00e57ec29ef2ba7df07ad10573011647b2366f6d, 'TOSHE', 18) + , (0xf1b4ddf712e108cf43711b1c39f2fddb0d5ce243, 'BASE', 18) + , (0x87c211144b1d9bdaa5a791b8099ea4123dc31d21, 'BCP', 18) + , (0xa5fbc981ebd8f4e791be8bd7a9b7cb144d145bf9, 'MEMEGOD', 18) + , (0x30d19fb77c3ee5cfa97f73d72c6a1e509fa06aef, 'CONDO', 18) + , (0x8b781e0f2967571e96d5d95b3cb61e27785eeaa5, 'BORKIE', 18) + , (0x3159fb5589acd6bf9f82eb0efe8382ed55aed8fd, 'APU', 18) + , (0x029635e83bc26c96006298e05798cdda76a2e7a5, 'SYD', 18) + , (0x314da69de85145fdd5b7580971e9db0388a2cdc4, 'BSW', 18) + , (0x8ad5b9007556749de59e088c88801a3aaa87134b, 'FARTHER', 18) + , (0x64cc19a52f4d631ef5be07947caba14ae00c52eb, 'KIBBLE', 18) + , (0x45096bd2871911ee82a3084d77a01efa3c9c6733, 'BUB', 18) + , (0x44fccd875c8e80b37f38530f434386a6d59141bb, 'DTB', 18) + , (0xfd008f937b4d73eeb00cf74ce90c392be5f07f96, 'MOON', 18) + , (0x160381343365de6d5e7d32172987b3e6bd1cce71, 'Mari', 18) + , (0x546d239032b24eceee0cb05c92fc39090846adc7, 'SEED', 18) + , (0x4c584cbc3a221998dc003349e1c12a4179e97b25, 'BMONEY', 18) + , (0x9721b1ce4ffd8af047bbdfd87e4e20ddc544513a, 'BROS', 18) + , (0xc41ba5737baf6bd0ccd5daf7eee39874e4ad45ff, 'DEGENS', 18) + , (0x10c1b6f768e13c624a4a23337f1a5ba5c9be0e4b, 'WARPIE', 18) + , (0xfd9fa4f785331ce88b5af8994a047ba087c705d8, '$blue', 18) , (0x420697291f6ce9fbb34e9feddd61868ca2f81f5c, 'MONEYBEE', 18) - , (0x9a589baa21f0492bd4f35a33915986db56d8eecf, 'CATZ', 18) - , (0x2156006a207a793b4069a2b72be58dc2bd759232, 'COIN', 18) - , (0x17931cfc3217261ce0fa21bb066633c463ed8634, 'BASED', 18) - , (0xb9ea61ed1c9942011e5e44f7fae3efddbf277b1e, 'CHIP', 18) + , (0x9a589baa21f0492bd4f35a33915986db56d8eecf, 'CATZ', 18) + , (0x2156006a207a793b4069a2b72be58dc2bd759232, 'COIN', 18) + , (0x17931cfc3217261ce0fa21bb066633c463ed8634, 'BASED', 18) + , (0xb9ea61ed1c9942011e5e44f7fae3efddbf277b1e, 'CHIP', 18) , (0xea6f7e7e0f46a9e0f4e2048eb129d879f609d632, 'PERCY', 18) - , (0x05ad8adc21778f2a2c6800852f05fb949ef507dc, 'HACHI', 18) - , (0x8fe815417913a93ea99049fc0718ee1647a2a07c, 'XSWAP', 18) - , (0x9260409d4719c235c7c199106219f9616d66bde0, 'ArabWif', 18) - , (0x1c22374032e7e5a1bbde3d943f5deb310db060dd, 'onchain', 18) + , (0x05ad8adc21778f2a2c6800852f05fb949ef507dc, 'HACHI', 18) + , (0x8fe815417913a93ea99049fc0718ee1647a2a07c, 'XSWAP', 18) + , (0x9260409d4719c235c7c199106219f9616d66bde0, 'ArabWif', 18) + , (0x1c22374032e7e5a1bbde3d943f5deb310db060dd, 'onchain', 18) , (0x57d0ffb02f73aa09dd22d7e81d6c0c81054ab5d9, 'DRAGGY', 18) , (0xb59c8912c83157a955f9d715e556257f432c35d7, 'TRUF', 18) , (0x619c4bbbd65f836b78b36cbe781513861d57f39d, 'BWB', 18) @@ -390,12 +390,12 @@ FROM (VALUES , (0xdbcae648ebea8c950b616e10e28da09d1ab4a06d, 'ELIZ', 18) , (0x0a14ef61afb32e5ca672e021784f71705ac14908, 'NULL', 18) , (0x7e72d6410803c40e73806f2a72e3eade5d075cc0, 'MOB', 18) - , (0x24da41bae4d7014ec6faf5403d2db0aa1510358d, 'COPY', 18) + , (0x24da41bae4d7014ec6faf5403d2db0aa1510358d, 'COPY', 18) , (0x02e79d42c3297cd4154a1b52b4a3b27cd75762f1, 'FFTP', 9) , (0xc1bf21674a3d782ee552d835863d065b7a89d619, 'MISHA', 18) - , (0xfc21540d6b89667d167d42086e1feb04da3e9b21, 'INFI', 18) + , (0xfc21540d6b89667d167d42086e1feb04da3e9b21, 'INFI', 18) , (0x9a33406165f562e16c3abd82fd1185482e01b49a, 'TALENT', 18) - , (0xde31526ad9f7e8d271e85677e7ec5882f801a34b, 'First Steps Into Sovereignty', 18) + , (0xde31526ad9f7e8d271e85677e7ec5882f801a34b, 'First Steps Into Sovereignty', 18) , (0xd89cd06d54e5e5af76221c00b60c6b567b17b863, 'TAPPY', 18) , (0x1057cc4ef19cc86a1b034145225f47e354f6f95b, 'FLICKY', 18) , (0x8c3ed1f4d142965d19e0db48ae189dd9448ad95a, 'WOT', 18) @@ -405,5 +405,6 @@ FROM (VALUES , (0x574178357661527601482b79af6bb1ff7cc1306a, '1984', 18) , (0x63e14921ba4546cb15087d574346574eee055812, 'PVP', 18) , (0xd68470491eb513365322810e55e0eba80785dfdd, '243M theft', 18) - , (0xb0505e5a99abd03d94a1169e638b78edfed26ea4, 'uSUI', 18) + , (0xb0505e5a99abd03d94a1169e638b78edfed26ea4, 'uSUI', 18) + , (0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842, 'MORPHO', 18) ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 295b395a1d2..10b6ea5c913 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4564,12 +4564,12 @@ FROM (VALUES , ( 0x5983B89FA184f14917013B9C3062afD9434C5b03, 'POWER', 0) , ( 0x988567FE094570cCE1FFdA29D1f2d842B70492be, 'ZERO', 6) , ( 0x10dea67478c5f8c5e2d90e5e9b26dbe60c54d800, 'TAIKO', 18) - , ( 0x80ac24aA929eaF5013f6436cdA2a7ba190f5Cc0b, 'syrupUSDC', 6) - , ( 0xa8258deE2a677874a48F5320670A869D74f0cbC1, 'WAR', 18) + , ( 0x80ac24aA929eaF5013f6436cdA2a7ba190f5Cc0b, 'syrupUSDC', 6) + , ( 0xa8258deE2a677874a48F5320670A869D74f0cbC1, 'WAR', 18) , ( 0xbeef69ac7870777598a04b2bd4771c71212e6abc, 'steakLRT', 18) , ( 0x84631c0d0081fde56deb72f6de77abbbf6a9f93a, 'Re7LRT', 18) , ( 0x7a4effd87c2f3c55ca251080b1343b605f327e3a, 'rstETH', 18) - , ( 0x5fd13359ba15a84b76f7f87568309040176167cd, 'amprETH', 18) + , ( 0x5fd13359ba15a84b76f7f87568309040176167cd, 'amprETH', 18) , ( 0xC8E621909D71F555D2A5A90f68DD9EE0C55514De, 'SATORI', 18) , ( 0x61134511187a9a2df38d10dbe07ba2e8e5563967, 's_aWETH', 18) , ( 0xd1c117319b3595fbc39b471ab1fd485629eb05f2, 'vaETH', 18) @@ -4581,41 +4581,41 @@ FROM (VALUES , ( 0xc14900dfb1aa54e7674e1ecf9ce02b3b35157ba5, 'vaFRAX', 18) , ( 0xce4a49d7ed99c7c8746b713ee2f0c9aa631688d8, 's_aDAI', 18) , ( 0xf591d878608e2e5c7d4f1e499330f4ab9bbae37a, 's_aUSDC', 6) - , ( 0x73a15fed60bf67631dc6cd7bc5b6e8da8190acf5, 'USD0', 18) + , ( 0x73a15fed60bf67631dc6cd7bc5b6e8da8190acf5, 'USD0', 18) , ( 0x2E3CFE45E3EE7C017277f22e35d2f29edC99d570, 'wDAG', 8) , ( 0x7448c7456a97769F6cD04F1E83A4a23cCdC46aBD, 'MAV', 18) , ( 0x63a0964A36c34E81959da5894ad888800e17405b, 'ShezETH', 18) , ( 0xDfFb77dB95E16B791178D28CF994b13E84036076, 'BLU', 18) , ( 0x866a2bf4e572cbcf37d5071a7a58503bfb36be1b, 'M', 6) - , ( 0x20157dbabb84e3bbfe68c349d0d44e48ae7b5ad2, 'dlcBTC', 8) - , ( 0xe1B4d34E8754600962Cd944B535180Bd758E6c2e, 'agETH', 18) - , ( 0x5C5b196aBE0d54485975D1Ec29617D42D9198326, 'stdeUSD', 18) - , ( 0x6dc3ce9c57b20131347fdc9089d740daf6eb34c5, 'balETH', 18) - , ( 0x786f4782d1a5c602ea30bc4a95154110b9e231ea, 'shezBTC', 8) - , ( 0x09db87a538bd693e9d08544577d5ccfaa6373a48, 'ynETH', 18) - , ( 0x3b50805453023a91a8bf641e279401a0b23fa6f9, 'REZ', 18) - , ( 0x7777cec341e7434126864195adef9b05dcc3489c, 'ONI', 18) - , ( 0x3ffeea07a27fab7ad1df5297fa75e77a43cb5790, 'PEIPEI', 18) - , ( 0x00f116ac0c304c570daaa68fa6c30a86a04b5c5f, 'INF', 18) - , ( 0x777be1c6075c20184c4fd76344b7b0b7c858fe6b, 'BAR', 18) - , ( 0xaa32f860756f6dcd5a684dc2aadf6c0921257a9a, 'YUNA', 18) - , ( 0xa045fe936e26e1e1e1fb27c1f2ae3643acde0171, 'KAI', 9) - , ( 0x9e566e28c61690f8afe0468f523e137b1ff29f01, 'GNCAT', 9) - , ( 0x7f911119435d8ded9f018194b4b6661331379a3d, 'FWOG', 18) - , ( 0x6985884c4392d348587b19cb9eaaf157f13271cd, 'ZRO', 18) - , ( 0x7b0df1cd724ec34ec9bc4bd19749b01afb490761, 'KOIN', 9) - , ( 0xb60fdf036f2ad584f79525b5da76c5c531283a1b, 'NEMO', 9) - , ( 0x5b342f03d126314d925fa57a45654f92905e6451, 'MNTA', 18) - , ( 0x8149745670881d99700078ede5903a1a7bebe262, 'PEPAY', 18) - , ( 0xb6f4d11d6c274f8f0a55d101b65223a45a3d1128, 'eBAKE', 9) - , ( 0xb35875b40f5ea5483c84ccd6e4ab0afc42a3c355, 'Nerio', 9) + , ( 0x20157dbabb84e3bbfe68c349d0d44e48ae7b5ad2, 'dlcBTC', 8) + , ( 0xe1B4d34E8754600962Cd944B535180Bd758E6c2e, 'agETH', 18) + , ( 0x5C5b196aBE0d54485975D1Ec29617D42D9198326, 'stdeUSD', 18) + , ( 0x6dc3ce9c57b20131347fdc9089d740daf6eb34c5, 'balETH', 18) + , ( 0x786f4782d1a5c602ea30bc4a95154110b9e231ea, 'shezBTC', 8) + , ( 0x09db87a538bd693e9d08544577d5ccfaa6373a48, 'ynETH', 18) + , ( 0x3b50805453023a91a8bf641e279401a0b23fa6f9, 'REZ', 18) + , ( 0x7777cec341e7434126864195adef9b05dcc3489c, 'ONI', 18) + , ( 0x3ffeea07a27fab7ad1df5297fa75e77a43cb5790, 'PEIPEI', 18) + , ( 0x00f116ac0c304c570daaa68fa6c30a86a04b5c5f, 'INF', 18) + , ( 0x777be1c6075c20184c4fd76344b7b0b7c858fe6b, 'BAR', 18) + , ( 0xaa32f860756f6dcd5a684dc2aadf6c0921257a9a, 'YUNA', 18) + , ( 0xa045fe936e26e1e1e1fb27c1f2ae3643acde0171, 'KAI', 9) + , ( 0x9e566e28c61690f8afe0468f523e137b1ff29f01, 'GNCAT', 9) + , ( 0x7f911119435d8ded9f018194b4b6661331379a3d, 'FWOG', 18) + , ( 0x6985884c4392d348587b19cb9eaaf157f13271cd, 'ZRO', 18) + , ( 0x7b0df1cd724ec34ec9bc4bd19749b01afb490761, 'KOIN', 9) + , ( 0xb60fdf036f2ad584f79525b5da76c5c531283a1b, 'NEMO', 9) + , ( 0x5b342f03d126314d925fa57a45654f92905e6451, 'MNTA', 18) + , ( 0x8149745670881d99700078ede5903a1a7bebe262, 'PEPAY', 18) + , ( 0xb6f4d11d6c274f8f0a55d101b65223a45a3d1128, 'eBAKE', 9) + , ( 0xb35875b40f5ea5483c84ccd6e4ab0afc42a3c355, 'Nerio', 9) , ( 0xf7554eac0bf20d702e69d08c425e817abb976aea, 'MAHA', 18) , ( 0x3742f3fcc56b2d46c7b8ca77c23be60cd43ca80a, 'stAVAIL', 18) , ( 0xd8eb27a94e610a7b859758ed1f2d47ad224bfaaa, 'GOPEPE', 18) , ( 0xf7760c2c0677078b1d1b6b8463f1de1c6c91a9f8, 'PP', 18) , ( 0x78128d17a89e5fe51bd0e757cfbc5703c34c7fb6, '$EWT', 18) , ( 0xf1ff59fa458bee12d6526dbd92290090bf670e29, 'fluffy', 18) - , ( 0xffe9ae172dd1fc9929ba6902873e09fadf81afd7, 'GLOW', 18) + , ( 0xffe9ae172dd1fc9929ba6902873e09fadf81afd7, 'GLOW', 18) , ( 0xb146823fb8ea064d14ba1a52e3e55cde09afff2d, 'EYE', 18) , ( 0x88ce174c655b6d11210a069b2c106632dabdb068, 'YAWN', 18) , ( 0xf6b6235f6725f84457f5d6f0b0aa3c962a079977, 'WBKN', 18) @@ -4643,13 +4643,13 @@ FROM (VALUES , ( 0x0ba45a8b5d5575935b8158a88c631e9f9c95a2e5, 'TRB', 18) , ( 0xf0a949b935e367a94cdfe0f2a54892c2bc7b2131, 'ultraETHs', 18) , ( 0x5e362eb2c0706bd1d134689ec75176018385430b, 'DVstETH', 18) - , ( 0xcbc632833687dacdcc7dfac96f6c5989381f4b47, 'ultraETHs', 18) + , ( 0xcbc632833687dacdcc7dfac96f6c5989381f4b47, 'ultraETHs', 18) , ( 0xa684eaf215ad323452e2b2bf6f817d4aa5c116ab, 'lpETH', 18) , ( 0x100db67f41a2df3c32cc7c0955694b98339b7311, 'MONEY', 18) , ( 0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf, 'cbBTC', 8) , ( 0x66b5228cfd34d9f4d9f03188d67816286c7c0b74, 'VOLT', 18) , ( 0x4d1c297d39c5c1277964d0e3f8aa901493664530, 'PUFER', 18) - , ( 0x460372866fe1448de1549cebdb0539f4075a2aa8, 'SHERK', 9) + , ( 0x460372866fe1448de1549cebdb0539f4075a2aa8, 'SHERK', 9) , ( 0x0a6E7Ba5042B38349e437ec6Db6214AEC7B35676, 'SWELL', 18) , ( 0xf9B24C9364457Ea85792179D285855753549eBAa, 'slisBNB', 18) , ( 0x230ea9aed5d08afdb22cd3c06c47cf24ad501301, 'SPX2.0', 18) @@ -4721,4 +4721,6 @@ FROM (VALUES , ( 0xaf270c38ff895ea3f95ed488ceace2386f038249, 'stataEthDAI', 18) , ( 0x00f2a835758b33f3ac53516ebd69f3dc77b0d152, 'stataEthPYUSD', 6) , ( 0x7cc6694cf75c18d488d16fb4bf3c71a3b31cc7fb, 'stataEthETHx', 18) + , ( 0x58D97B57BB95320F9a05dC918Aef65434969c2B2, 'MORPHO', 18) + , ( 0x9994E35Db50125E0DF82e4c2dde62496CE330999, 'legacyMORPHO', 18) ) AS temp_table (contract_address, symbol, decimals) From 793bfcfecc6c72f90807afda3afa6e1d9465e017 Mon Sep 17 00:00:00 2001 From: synthquest <112836792+Synthquest@users.noreply.github.com> Date: Thu, 28 Nov 2024 07:04:46 -0500 Subject: [PATCH 38/68] add base cex addresses (#7201) --- .../addresses/chains/cex_evms_addresses.sql | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql b/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql index dacb8ab17e9..18acb039b82 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/cex/addresses/chains/cex_evms_addresses.sql @@ -5,7 +5,7 @@ post_hook='{{ expose_spells(\'["ethereum", "arbitrum", "avalanche_c", "bnb", "fantom", "optimism", "polygon", "zksync", "zora", "celo", "base"]\', "sector", "cex", - \'["hildobby", "soispoke", "web3_data", "msilb7", "Henrystats", "sankinyue"]\') }}')}} + \'["hildobby", "soispoke", "web3_data", "msilb7", "Henrystats", "sankinyue", "synthquest"]\') }}')}} SELECT address, cex_name, distinct_name, added_by, added_date FROM (VALUES @@ -150,6 +150,7 @@ FROM (VALUES , (0x4230c402c08cb66dcf3820649a115e54661fce9d, 'Bybit', 'Bybit 8', 'hildobby', date '2023-11-15') , (0x3d5202a0564de9b05ecd07c955bcca964585ea03, 'Bybit', 'Bybit 9', 'hildobby', date '2024-05-09') , (0x1e32760a3285550278aeafa776e5641bc581c845, 'Bybit', 'Bybit 10', 'hildobby', date '2024-10-06') + , (0x88a1493366d48225fc3cefbdae9ebb23e323ade3, 'Bybit', 'Bybit 11', 'synthquest', date '2024-11-27') , (0xab97925eb84fe0260779f58b7cb08d77dcb1ee2b, 'Bybit', 'Bybit Gas Supplier 1', 'hildobby', date '2023-11-15') , (0xa95b83af96d0b8a90bd507f2bd82ad8f3dbb86bc, 'Bybit', 'Bybit Gas Supplier 2', 'hildobby', date '2023-11-20') , (0xf65d698d18bc37bf36e4c8d4fe4f051ef570e2b6, 'Bybit', 'Bybit Gas Supplier 3', 'hildobby', date '2023-11-23') @@ -260,6 +261,30 @@ FROM (VALUES , (0x3dd87411a3754deea8cc52c4cf57e2fc254924cc, 'Coinbase', 'Coinbase 56', 'hildobby', date '2024-05-04') , (0x441cacfd43856409b163b90e094bb42aeb70a70e, 'Coinbase', 'Coinbase 57', 'hildobby', date '2024-05-25') , (0xa14d57f5ea867572b0d239798d2c1dde13153902, 'Coinbase', 'Coinbase 58', 'hildobby', date '2024-05-25') + , (0x9ebe8ae7dbc0285b04e93dab86a081ca32ccf52e, 'Coinbase', 'Coinbase 59', 'synthquest', date '2024-11-27') + , (0x3dc474a2a65507f32b05c5f80d852515b25b2134, 'Coinbase', 'Coinbase 60', 'synthquest', date '2024-11-27') + , (0xcf63fc571adcec4fd4a750ecacc3af1f5b748101, 'Coinbase', 'Coinbase 61', 'synthquest', date '2024-11-27') + , (0x00aac037c2ca137972f963693d38a57d0e9f7475, 'Coinbase', 'Coinbase 62', 'synthquest', date '2024-11-27') + , (0x60eb0250e3a428a51ccb1e44e0aadbd1fd213ff3, 'Coinbase', 'Coinbase 63', 'synthquest', date '2024-11-27') + , (0x336307f2d8390035ba926a61a86b45ca9dc91e57, 'Coinbase', 'Coinbase 64', 'synthquest', date '2024-11-27') + , (0x57a7560d0ec28065762203c0d633943298eac7c0, 'Coinbase', 'Coinbase 65', 'synthquest', date '2024-11-27') + , (0x0b0a5886664376f59c351ba3f598c8a8b4d0a6f3, 'Coinbase', 'Coinbase 66', 'synthquest', date '2024-11-27') + , (0xee81b5afc73cf528778e0ed98622e434e5efadb4, 'Coinbase', 'Coinbase 67', 'synthquest', date '2024-11-27') + , (0x9b4fc9e22b46487f0810ef5dfa230b9f139e5179, 'Coinbase', 'Coinbase 68', 'synthquest', date '2024-11-27') + , (0x95f90ce2e3abaed29eeebdb42e1fdb146e0f848a, 'Coinbase', 'Coinbase 69', 'synthquest', date '2024-11-27') + , (0x122fdd9fecbc82f7d4237c0549a5057e31c8ef8d, 'Coinbase', 'Coinbase 70', 'synthquest', date '2024-11-27') + , (0x8196f70b2c17ba58d8ef56ad62087ee8231be33a, 'Coinbase', 'Coinbase 71', 'synthquest', date '2024-11-27') + , (0xadbbe373b5b5f72c59c0311cffbded51f0c5f434, 'Coinbase', 'Coinbase 72', 'synthquest', date '2024-11-27') + , (0x67857ee12929e74082f1cae64ef4221830c39113, 'Coinbase', 'Coinbase 73', 'synthquest', date '2024-11-27') + , (0xa2908f1758d1cc3990f4a2da8dea0aa2ecf1b913, 'Coinbase', 'Coinbase 74', 'synthquest', date '2024-11-27') + , (0xd451e3919950963e9c1ca2f78a987dbd7937c0fb, 'Coinbase', 'Coinbase 75', 'synthquest', date '2024-11-27') + , (0x27724b0d4fb98a89a092e6a4adbc09154c182637, 'Coinbase', 'Coinbase 76', 'synthquest', date '2024-11-27') + , (0x7c310a03f4cfa19f7f3d7f36dd3e05828629fa78, 'Coinbase', 'Coinbase 77', 'synthquest', date '2024-11-27') + , (0x21bd501f86a0b5ce0907651df3368da905b300a9, 'Coinbase', 'Coinbase 78', 'synthquest', date '2024-11-27') + , (0x7c41fdced2ea646ed85665d1a9b28e6632b61c41, 'Coinbase', 'Coinbase 79', 'synthquest', date '2024-11-27') + , (0x607094ed3a8361bb5e94dd21bcbef2997b687478, 'Coinbase', 'Coinbase 80', 'synthquest', date '2024-11-27') + , (0x1b4c15b991543a6082213a88276e7a83c9985676, 'Coinbase', 'Coinbase 81', 'synthquest', date '2024-11-27') + , (0xd5c41fd4a31eaaf5559ffcc60ec051fcb8ecc375, 'Coinbase', 'Coinbase 82', 'synthquest', date '2024-11-27') , (0xa090e606e30bd747d4e6245a1517ebe430f0057e, 'Coinbase', 'Coinbase Miscellaneous', 'hildobby', date '2022-08-28') , (0xf6874c88757721a02f47592140905c4336dfbc61, 'Coinbase', 'Coinbase Commerce', 'hildobby', date '2022-08-28') , (0x881d4032abe4188e2237efcd27ab435e81fc6bb1, 'Coinbase', 'Coinbase Commerce 2', 'hildobby', date '2022-08-28') From db343e3bad6ab65d7fd90ca1fdb2f756cfdb7839 Mon Sep 17 00:00:00 2001 From: ppclunghe <90045511+ppclunghe@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:05:32 +0100 Subject: [PATCH 39/68] Lido accounting CSM/stonks update (#7190) * Lido accounting CSM/stonks update * revenue fees fix --- ...ido_accounting_ethereum_other_expenses.sql | 36 ++++++------------- .../lido_accounting_ethereum_other_income.sql | 28 ++++++--------- .../lido_accounting_ethereum_revenue.sql | 10 +++--- 3 files changed, 24 insertions(+), 50 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_expenses.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_expenses.sql index 0a2f233dc5d..288a999e1c1 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_expenses.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_expenses.sql @@ -18,13 +18,13 @@ with tokens AS ( select * from (values (0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32), --LDO - (0x6B175474E89094C44Da98b954EedeAC495271d0F), --DAI - (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48), --USDC + (0x6B175474E89094C44Da98b954EedeAC495271d0F), --DAI + (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48), --USDC (0xdAC17F958D2ee523a2206206994597C13D831ec7), -- USDT - (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), --WETH - (0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0), --MATIC - (0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84), --stETH - (0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0) --wstETH + (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), --WETH + (0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0), --MATIC + (0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84), --stETH + (0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0) --wstETH ) as tokens(address)), @@ -99,7 +99,7 @@ dai_referral_payments_addr AS ( steth_referral_payments_addr AS ( SELECT _recipient AS address FROM {{source('lido_ethereum','AllowedRecipientsRegistry_RevShare_evt_RecipientAdded')}} ), -/* + stonks as ( select * from (values ('STETH→DAI', 0x3e2D251275A92a8169A3B17A2C49016e2de492a7), @@ -114,24 +114,7 @@ stonks as ( ) as list(namespace, address) ), -cow_settlement as ( - select * from (values - (0x9008D19f58AAbD9eD0D60971565AA8510560ab41) - ) as list(address) -), -stonks_orders_txns as ( - select evt_tx_hash - from {{source('lido_ethereum', 'steth_evt_Transfer')}} - where "from" in ( - select cast(replace(topic1, 0x000000000000000000000000, 0x) as varbinary) as order_addr - from {{source('ethereum', 'logs')}} l - join stonks s on l.contract_address = s.address - and l.topic0 = 0x96a6d5477fba36522dca4102be8b3785435baf902ef6c4edebcb99850630c75f -- Stonks Deployed - ) - and to in (select address from cow_settlement) -), -*/ other_expenses_txns AS ( SELECT evt_block_time, @@ -160,8 +143,10 @@ other_expenses_txns AS ( SELECT 0x0000000000000000000000000000000000000000 UNION ALL SELECT address FROM diversifications_addresses + UNION ALL + SELECT address FROM stonks ) - -- AND evt_tx_hash NOT IN (select evt_tx_hash from stonks_orders_txns) + UNION ALL --ETH outflow SELECT @@ -199,4 +184,3 @@ other_expenses_txns AS ( FROM other_expenses_txns WHERE contract_address IN (SELECT address FROM tokens) and value != 0 - diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_income.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_income.sql index 4ab559548b4..255876b67f4 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_income.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_other_income.sql @@ -16,13 +16,13 @@ with tokens AS ( select * from (values (0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32), --LDO - (0x6B175474E89094C44Da98b954EedeAC495271d0F), --DAI - (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48), --USDC + (0x6B175474E89094C44Da98b954EedeAC495271d0F), --DAI + (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48), --USDC (0xdAC17F958D2ee523a2206206994597C13D831ec7), -- USDT - (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), --WETH - (0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0), --MATIC - (0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84), --stETH - (0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0) --wstETH + (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), --WETH + (0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0), --MATIC + (0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84), --stETH + (0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0) --wstETH ) as tokens(address)), @@ -91,15 +91,6 @@ select * from (values dai_referral_payments_addr AS ( SELECT _recipient AS address FROM {{source('lido_ethereum','AllowedRecipientsRegistry_evt_RecipientAdded')}} - WHERE - ( - NOT EXISTS (SELECT _recipient FROM {{source('lido_ethereum','AllowedRecipientsRegistry_evt_RecipientRemoved')}}) - OR ( - EXISTS (SELECT _recipient FROM {{source('lido_ethereum','AllowedRecipientsRegistry_evt_RecipientRemoved')}}) - AND - _recipient NOT IN (SELECT _recipient FROM {{source('lido_ethereum','AllowedRecipientsRegistry_evt_RecipientRemoved')}}) - ) - ) UNION ALL SELECT 0xaf8aE6955d07776aB690e565Ba6Fbc79B8dE3a5d --rhino ), @@ -107,7 +98,7 @@ dai_referral_payments_addr AS ( steth_referral_payments_addr AS ( SELECT _recipient AS address FROM {{source('lido_ethereum','AllowedRecipientsRegistry_RevShare_evt_RecipientAdded')}} ), -/* + stonks as ( select * from (values ('STETH→DAI', 0x3e2D251275A92a8169A3B17A2C49016e2de492a7), @@ -139,7 +130,7 @@ stonks_orders_txns as ( ) and to in (select address from cow_settlement) ), -*/ + other_income_txns AS ( SELECT evt_block_time, @@ -167,7 +158,7 @@ other_income_txns AS ( UNION ALL SELECT address FROM diversifications_addresses ) - -- AND evt_tx_hash NOT IN (select evt_tx_hash from stonks_orders_txns) + AND evt_tx_hash NOT IN (select evt_tx_hash from stonks_orders_txns) UNION ALL --ETH staked by DAO @@ -251,3 +242,4 @@ SELECT * from ( from_base64(evt_tx_hash) FROM stsol_income ) WHERE amount_token != 0 + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_revenue.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_revenue.sql index 9847c63cf48..eab910a900a 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_revenue.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/accounting/ethereum/lido_accounting_ethereum_revenue.sql @@ -20,6 +20,7 @@ select * from (values (0x3e40d73eb977dc6a537af587d48316fee66e9c8c, 'Aragon'), (0x55032650b14df07b85bF18A3a3eC8E0Af2e028d5, 'NO (Curated)'), (0xaE7B191A31f627b4eB1d4DaC64eaB9976995b433, 'NO (DVT)'), +(0xdA7dE2ECdDfccC6c3AF10108Db212ACBBf9EA83F, 'NO (CSM)'), (0x8B3f33234ABD88493c0Cd28De33D583B70beDe35, 'InsuranceFund') ) as list(address, name) ), @@ -77,9 +78,9 @@ protocol_fee_distribution AS ( 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84 AS token, lido_rewards AS total, protocol_fee.points AS protocol_fee, - protocol_fee_distribution.insurance_points AS insurance_fee, - protocol_fee_distribution.operators_points AS operators_fee, - protocol_fee_distribution.treasury_points AS treasury_fee, + --protocol_fee_distribution.insurance_points AS insurance_fee, + --protocol_fee_distribution.operators_points AS operators_fee, + --protocol_fee_distribution.treasury_points AS treasury_fee, (1 - protocol_fee.points)*lido_rewards AS depositors_revenue, protocol_fee.points*protocol_fee_distribution.treasury_points*lido_rewards AS treasury_revenue, protocol_fee.points*protocol_fee_distribution.insurance_points*lido_rewards AS insurance_revenue, @@ -96,9 +97,6 @@ protocol_fee_distribution AS ( 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84 AS token, oracle_txns.treasury_revenue + oracle_txns.operators_revenue + oracle_txns.insurance_revenue AS total, protocol_fee.points AS protocol_fee, - protocol_fee_distribution.insurance_points AS insurance_fee, - protocol_fee_distribution.operators_points AS operators_fee, - protocol_fee_distribution.treasury_points AS treasury_fee, 10*(1 - protocol_fee.points)*(oracle_txns.treasury_revenue + oracle_txns.operators_revenue + oracle_txns.insurance_revenue) AS depositors_revenue, oracle_txns.treasury_revenue AS treasury_revenue, oracle_txns.insurance_revenue AS insurance_revenue, From ee48fa96fbe57b129274bdaf5e7e4b8863bef424 Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:27:15 +0100 Subject: [PATCH 40/68] exclude sanctum (#7206) * exclude sanctum * exclude in jinja --- .../_sector/dex/dex_solana_base_trades.sql | 5 ++- .../sanctum_router_base_trades.sql | 43 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql b/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql index 991be84e941..d3dba42ca27 100644 --- a/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql @@ -23,9 +23,10 @@ , ref('meteora_v2_solana_base_trades') , ref('goosefx_ssl_v2_solana_base_trades') , ref('pumpdotfun_solana_base_trades') - , ref('sanctum_router_base_trades') ] %} +-- excluded: , ref('sanctum_router_base_trades') + {% for dex in solana_dexes %} SELECT blockchain @@ -52,7 +53,7 @@ SELECT FROM {{ dex }} {% if is_incremental() %} -WHERE +WHERE {{incremental_predicate('block_time')}} {% endif %} {% if not loop.last %} diff --git a/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql index 9f73bb67fff..c7de77c37c3 100644 --- a/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql @@ -1,6 +1,7 @@ {{ config( schema = 'sanctum_router', + tags = ['prod_exclude'], alias = 'base_trades', partition_by = ['block_month'], materialized = 'incremental', @@ -16,7 +17,7 @@ {% set dev_start_date = "date_trunc('day', now() - interval '7' day)" %} WITH swap_via_stake AS ( - SELECT + SELECT call_block_time as block_time , call_block_slot as block_slot , call_tx_signer as trader_id @@ -29,9 +30,9 @@ WITH swap_via_stake AS ( , account_srcTokenMint as token_sold_mint_address , account_destTokenMint as token_bought_mint_address , bytearray_to_bigint(bytearray_reverse(bytearray_substring(call_data, 2, 8))) AS token_sold_amount_raw - , CASE + , CASE WHEN call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' - ELSE call_outer_executing_account + ELSE call_outer_executing_account END as trade_source , 'mintTo' as amount_type FROM {{ source('sanctum_router_solana', 'stakedex_call_SwapViaStake') }} @@ -44,7 +45,7 @@ WITH swap_via_stake AS ( ), prefund_swap_via_stake AS ( - SELECT + SELECT call_block_time as block_time , call_block_slot as block_slot , call_tx_signer as trader_id @@ -57,9 +58,9 @@ prefund_swap_via_stake AS ( , account_srcTokenMint as token_sold_mint_address , account_destTokenMint as token_bought_mint_address , bytearray_to_bigint(bytearray_reverse(bytearray_substring(call_data, 2, 8))) AS token_sold_amount_raw - , CASE + , CASE WHEN call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' - ELSE call_outer_executing_account + ELSE call_outer_executing_account END as trade_source , 'transferChecked' as amount_type FROM {{ source('sanctum_router_solana', 'stakedex_call_PrefundSwapViaStake') }} @@ -72,7 +73,7 @@ prefund_swap_via_stake AS ( ), stake_wrapped_sol AS ( - SELECT + SELECT call_block_time as block_time , call_block_slot as block_slot , call_tx_signer as trader_id @@ -85,9 +86,9 @@ stake_wrapped_sol AS ( , account_wsolMint as token_sold_mint_address , account_destTokenMint as token_bought_mint_address , bytearray_to_bigint(bytearray_reverse(bytearray_substring(call_data, 2, 8))) AS token_sold_amount_raw - , CASE + , CASE WHEN call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' - ELSE call_outer_executing_account + ELSE call_outer_executing_account END as trade_source , 'transferChecked' as amount_type FROM {{ source('sanctum_router_solana', 'stakedex_call_StakeWrappedSol') }} @@ -100,7 +101,7 @@ stake_wrapped_sol AS ( ), withdraw_deposit AS ( - SELECT + SELECT w.call_block_time as block_time , w.call_block_slot as block_slot , w.call_tx_signer as trader_id @@ -113,14 +114,14 @@ withdraw_deposit AS ( , w.account_srcTokenMint as token_sold_mint_address , d.account_destTokenMint as token_bought_mint_address , bytearray_to_bigint(bytearray_reverse(bytearray_substring(w.call_data, 2, 8))) AS token_sold_amount_raw - , CASE + , CASE WHEN w.call_outer_executing_account = 'stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq' THEN 'direct' - ELSE w.call_outer_executing_account + ELSE w.call_outer_executing_account END as trade_source , 'transferChecked' as amount_type FROM {{ source('sanctum_router_solana', 'stakedex_call_PrefundWithdrawStake') }} w INNER JOIN {{ source('sanctum_router_solana', 'stakedex_call_DepositStake') }} d - ON w.call_tx_id = d.call_tx_id + ON w.call_tx_id = d.call_tx_id AND w.call_outer_instruction_index = d.call_outer_instruction_index AND w.call_inner_instruction_index < d.call_inner_instruction_index WHERE 1=1 @@ -133,7 +134,7 @@ withdraw_deposit AS ( all_trades AS ( SELECT * FROM swap_via_stake - UNION ALL + UNION ALL SELECT * FROM prefund_swap_via_stake UNION ALL SELECT * FROM stake_wrapped_sol @@ -142,29 +143,29 @@ all_trades AS ( ), token_amounts AS ( - SELECT + SELECT ic.tx_id, ic.outer_instruction_index, ic.inner_instruction_index, bytearray_to_bigint(bytearray_reverse(bytearray_substring(ic.data, 2, 8))) AS amount_bought, ROW_NUMBER() OVER ( PARTITION BY ic.tx_id, ic.outer_instruction_index - ORDER BY - CASE + ORDER BY + CASE WHEN b.amount_type = 'mintTo' THEN ic.inner_instruction_index ELSE -ic.inner_instruction_index END ) as rn FROM all_trades b - INNER JOIN {{ source('solana','instruction_calls') }} ic - ON ic.tx_id = b.tx_id + INNER JOIN {{ source('solana','instruction_calls') }} ic + ON ic.tx_id = b.tx_id AND ic.outer_instruction_index = b.outer_instruction_index AND ic.block_slot = b.block_slot WHERE 1=1 AND ic.executing_account = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' AND ( (b.amount_type = 'mintTo' AND bytearray_substring(ic.data, 1, 1) = 0x07 AND ELEMENT_AT(ic.account_arguments, 1) = b.token_bought_mint_address) - OR + OR (b.amount_type = 'transferChecked' AND bytearray_substring(ic.data, 1, 1) = 0x0c AND ELEMENT_AT(ic.account_arguments, 2) = b.token_bought_mint_address AND ELEMENT_AT(ic.account_arguments, 3) = b.token_bought_vault) ) {% if is_incremental() %} @@ -198,6 +199,6 @@ SELECT , b.tx_index FROM all_trades b INNER JOIN token_amounts t - ON b.tx_id = t.tx_id + ON b.tx_id = t.tx_id AND b.outer_instruction_index = t.outer_instruction_index AND t.rn = 1 From 6d41877a2661fc13d40a3da946a83defe44c511d Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:50:34 +0100 Subject: [PATCH 41/68] add Ronin to gas fees (#7228) * add Ronin to metrics * add Ronin to gas_fees * Revert "add Ronin to metrics" This reverts commit 7c46501ca1a08f573b9ccc3a784bf9034957ca97. * add seed tests --- .../models/_sector/gas/fees/gas_fees.sql | 5 +-- .../_sector/gas/fees/ronin/gas_ronin_fees.sql | 17 ++++++++++ .../gas/fees/ronin/gas_ronin_schema.yml | 31 +++++++++++++++++++ .../seeds/_sector/gas/evm_gas_fees.csv | 4 +++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_fees.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_schema.yml diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/gas_fees.sql b/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/gas_fees.sql index 68da93059b2..f2aaab6c006 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/gas_fees.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/gas_fees.sql @@ -45,6 +45,7 @@ , "mantle" , "optimism" , "polygon" + , "ronin" , "scroll" , "sei" , "tron" @@ -89,7 +90,7 @@ FROM {% endfor %} UNION ALL - + SELECT blockchain , block_month @@ -113,4 +114,4 @@ FROM , cast (NULL AS double) AS gas_limit -- this concept doesn't exist in solana , cast (NULL AS double) AS gas_limit_usage -- this concept doesn't exist in solana FROM {{ source('gas_solana', 'fees') }} -) \ No newline at end of file +) diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_fees.sql b/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_fees.sql new file mode 100644 index 00000000000..310d86d1355 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_fees.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'ronin' %} + +{{ config( + schema = 'gas_' + blockchain + ,alias = 'fees' + ,partition_by = ['block_month'] + ,materialized = 'incremental' + ,file_format = 'delta' + ,incremental_strategy='merge' + ,unique_key = ['block_month', 'tx_hash'] + ,incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + gas_fees(blockchain = blockchain) +}} diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_schema.yml new file mode 100644 index 00000000000..696e8a9dfc7 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_sector/gas/fees/ronin/gas_ronin_schema.yml @@ -0,0 +1,31 @@ +version: 2 + +models: + - name: gas_ronin_fees + meta: + blockchain: ronin + sector: gas + contributors: 0xRob, soispoke + config: + tags: ['ronin', 'gas', 'fees'] + description: > + Gas Fees on Ethereum + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_month + - block_number + - tx_hash + - check_seed: + seed_file: ref('evm_gas_fees') + filter: + blockchain: ronin + match_columns: + - blockchain + - tx_hash + check_columns: + - tx_fee_raw + - dbt_utils.expression_is_true: + expression: "tx_fee_raw = reduce(map_values(tx_fee_breakdown_raw),uint256 '0',(s, x) -> s + x,s -> s)" + config: + where: "block_time > now() - interval '7' day" diff --git a/dbt_subprojects/hourly_spellbook/seeds/_sector/gas/evm_gas_fees.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/gas/evm_gas_fees.csv index fce13ac3d2e..887d7dfc46f 100644 --- a/dbt_subprojects/hourly_spellbook/seeds/_sector/gas/evm_gas_fees.csv +++ b/dbt_subprojects/hourly_spellbook/seeds/_sector/gas/evm_gas_fees.csv @@ -62,3 +62,7 @@ zora,Legacy,0xfd5f8df99b747f27303ec22f764a847b9211a7e0f9fbcd13f18301026b28aa99,3 zora,126,0xa694bccb978690204cc9445f8e9c2695f19f87cf1d7923ce4dd5b7122cd69d47,0 zora,AccessList,0x8d1029a6cbb3ec0047371c17e888381f95023487743eeb6597ab65d4c8954fbc,175028874886 zora,DynamicFee,0x92c43dbc36d7234e6cab7b3793b573d9b20a810c4403ae9e5900706a2f9e20a7,47040291290076 +ronin,DynamicFee,0x85a8cdb97b8920934ec8f555db172dd91ebcc95fe7d1e409a1b9b02f41485b7d,14880820000000000 +ronin,AccessList,0xb56e7dfc8d745f6e9d1c99a90f4ae874e541c8c6b38002ed80b3c2965d46aaa3,420000000000000 +ronin,Legacy,0x587223185b0f498faf0715de5855a98a4aae330c17330a22fb9c64636beb38d8,71333000000000 +ronin,100,0x438c07ec4094b9a335fe641ab7ba73e13d18f5113fffca04f8e2d0f82144cdfe,1074820000000000 From ea444ad3de792e690b7b5760272693f7b307ff44 Mon Sep 17 00:00:00 2001 From: bram-vdberg Date: Tue, 3 Dec 2024 15:51:56 +0100 Subject: [PATCH 42/68] [CoW Protocol] Add new Laita solver and rename FractalSolver to Fractal (#7229) * Add new Laita solver and rename FractalSolver to Fractal * Fix Quasilabs address name --- .../ethereum/cow_protocol_ethereum_solvers.sql | 11 ++++++----- .../gnosis/cow_protocol_gnosis_solvers.sql | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql index 84d496300be..7847ccd2d23 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql @@ -105,7 +105,7 @@ known_solver_metadata (address, environment, name) as ( (0xD1508A211D98bb81195dC1F9533eDcdf68aDF036, 'prod', 'Furucombo'), (0x8646Ee3c5e82b495Be8F9FE2f2f213701EeD0edc, 'prod', 'Seasolver_v2'), (0x9528e8c42F7e109bADED964E2D927fD5B6ca71E9, 'prod', 'Odos'), - (0x755BaE1cd46C9C27A3230AeF0CE923BDa13d29F7, 'prod', 'FractalSolver'), + (0x755BaE1cd46C9C27A3230AeF0CE923BDa13d29F7, 'prod', 'Fractal'), (0x8F70A86c1309d8B1F5BefC58948e7386Fd495875, 'prod', 'Tsolver'), (0xbAda55BaBEE5D2B7F3B551f9da846838760E068C, 'prod', 'Project_Blanc'), (0xA883710b6DBf008a1CC25722C54583E35884a209, 'prod', 'Horadrim'), @@ -116,18 +116,19 @@ known_solver_metadata (address, environment, name) as ( (0x2224eAaCC7c2DBf85d5355BAb9E9271e01d30b55, 'prod', 'Sector_Finance'), (0x9DFc9Bb0FfF2dc96728D2bb94eaCee6ba3592351, 'prod', 'Rizzolver'), (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), - (0x95480d3f27658e73b2785d30beb0c847d78294c7, 'prod', 'FractalSolver'), + (0x95480d3f27658e73b2785d30beb0c847d78294c7, 'prod', 'Fractal'), (0x00806DaA2Cfe49715eA05243FF259DeB195760fC, 'prod', 'Quasilabs'), - (0x7E2eF26AdccB02e57258784957922AEEFEe807e5, 'barn', 'FractalSolver'), + (0xd0bA1b1782fbdE45edAb392428f60e14827D08EC, 'barn', 'Laita'), + (0x7E2eF26AdccB02e57258784957922AEEFEe807e5, 'barn', 'Quasilabs'), (0x5131590ca2E9D3edC182581352b289dcaE83430c, 'barn', 'Portus'), - (0x2a2883ade8ce179265f12fc7b48a4b50b092f1fd, 'barn', 'FractalSolver'), + (0x2a2883ade8ce179265f12fc7b48a4b50b092f1fd, 'barn', 'Fractal'), (0x26B5e3bF135D3Dd05A220508dD61f25BF1A47cBD, 'barn', 'Rizzolver'), (0xA6A871b612bCE899b1CbBad6E545e5e47Da98b87, 'barn', 'Barter'), (0xa08B00576aeE8d8dd960E08298FAc9fD7C756e36, 'barn', 'Apollo'), (0x2c3A1c33d96C9DcA1c34EB234B1e65F79dEaE60e, 'barn', 'Horadrim'), (0xa5559C2E1302c5Ce82582A6b1E4Aec562C2FbCf4, 'barn', 'Project_Blanc'), (0xa432cea087311d7cd07925d70f799eE94E7893a4, 'barn', 'Tsolver'), - (0xAb11302CB4f7C417e527A4d39C22Aa9f04EdB07D, 'barn', 'FractalSolver'), + (0xAb11302CB4f7C417e527A4d39C22Aa9f04EdB07D, 'barn', 'Fractal'), (0xf13eaf9093a210EBdaBa581f5448ffA545EE2E65, 'barn', 'Odos'), (0x94aEF67903bFe8Bf65193A78074C887ba901d043, 'barn', 'Seasolver_v2'), (0x279fb872beaF64E94890376725C423c0820eDA97, 'barn', 'Furucombo'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql index ca24dd452be..7a2b6742ae4 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql @@ -64,8 +64,8 @@ known_solver_metadata (address, environment, name) as ( (0x67be9614C4E0FCdA95AFC66a95B5BDAFb55fa362, 'barn', 'Furucombo'), (0x53F5378A6f8bb24333aD8D68FD28816504a467b2, 'barn', 'CopiumCapital'), (0xC4dd6355Fbc6Eb108FD1C100389789C5B1A9A980, 'barn', 'Barter'), - (0x4398129426Cb1377E9E10395b8dfBDa153c7Fe7D, 'barn', 'FractalSolver'), - (0x727EB77c6f84ef148403f641aA32d75b7f6902A7, 'prod', 'FractalSolver'), + (0x4398129426Cb1377E9E10395b8dfBDa153c7Fe7D, 'barn', 'Fractal'), + (0x727EB77c6f84ef148403f641aA32d75b7f6902A7, 'prod', 'Fractal'), (0x0a360134553feED49FE5eb273074d80B6e45941F, 'prod', 'Barter'), (0xb4694FE6590acd1281Dc34a966bbAE224559BaD4, 'prod', 'CopiumCapital'), (0x227FDA1D5970dF605D785Bf5F2F8899d5fdF8624, 'prod', 'Furucombo'), From 0993acba161e0e149df1c2e1b90b2d699462d9fe Mon Sep 17 00:00:00 2001 From: archie17277 <160746411+archie17277@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:54:05 +0530 Subject: [PATCH 43/68] Add akronswap dex to trades (#7226) * Add akronswap dex to trades * update sql file --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/base/_schema.yml | 17 +++++++++++++++ .../trades/base/dex_base_base_trades.sql | 1 + .../platforms/akronswap_base_base_trades.sql | 21 +++++++++++++++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 15 +++++++++++++ .../akronswap_base_base_trades_seed.csv | 3 +++ sources/_sector/dex/trades/base/_sources.yml | 6 +++++- 7 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 dbt_subprojects/dex/models/trades/base/platforms/akronswap_base_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/akronswap_base_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index d63b8308303..ad3c562c04f 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -185,4 +185,5 @@ FROM (VALUES , ('kaia_swap', 'KaiaSwap', 'Direct', 'KaiaSwap') , ('defi_kingdoms', 'DeFi Kingdoms', 'Direct', 'DeFiKingdoms') , ('hyperjump', 'HyperJump', 'Direct', 'Hyperjump_fi') + , ('akronswap', 'Akronswap', 'Direct', 'AkronFinance') ) AS temp_table (project, name, marketplace_type, x_username) diff --git a/dbt_subprojects/dex/models/trades/base/_schema.yml b/dbt_subprojects/dex/models/trades/base/_schema.yml index a8010396e2a..f960a1a8393 100644 --- a/dbt_subprojects/dex/models/trades/base/_schema.yml +++ b/dbt_subprojects/dex/models/trades/base/_schema.yml @@ -996,3 +996,20 @@ models: - evt_index - check_dex_base_trades_seed: seed_file: ref('xchange_base_base_trades_seed') + + - name: akronswap_base_base_trades + meta: + blockchain: base + sector: dex + project: akronswap + contributors: archie + config: + tags: [ 'base', 'dex', 'trades', 'akronswap' ] + description: "akronswap base base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('akronswap_base_base_trades_seed') \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql index 742449afaea..ab4ddf7d67b 100644 --- a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql @@ -50,6 +50,7 @@ , ref('solidly_v3_base_base_trades') , ref('swaap_v2_base_base_trades') , ref('xchange_base_base_trades') + , ref('akronswap_base_base_trades') ] %} WITH base_union AS ( diff --git a/dbt_subprojects/dex/models/trades/base/platforms/akronswap_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/platforms/akronswap_base_base_trades.sql new file mode 100644 index 00000000000..ef4641d1e2c --- /dev/null +++ b/dbt_subprojects/dex/models/trades/base/platforms/akronswap_base_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'akronswap_base', + 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 = 'base', + project = 'akronswap', + version = '2', + Pair_evt_Swap = source('akronswap_base', 'UniswapV2Pair_evt_Swap'), + Factory_evt_PairCreated = source('akronswap_base', 'UniswapV2Factory_evt_PairCreated') + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index 7186b07390a..ac10a1d666f 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -4455,3 +4455,18 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp + + - name: akronswap_base_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/trades/akronswap_base_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/akronswap_base_base_trades_seed.csv new file mode 100644 index 00000000000..c3e9900ab0d --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/akronswap_base_base_trades_seed.csv @@ -0,0 +1,3 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw +base,akronswap_base,2,2024-12-02,0xba6515675bb20188399f976bef2f87592cec85d8cf9b897e95c64f5a7f18cbba,60,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,0x4200000000000000000000000000000000000006,23163282,5184505,1394212043972094 +base,akronswap_base,2,2024-09-18,0x1d295f4ed29ad01a711f9620931dd8c1bc9df385f773db070f33cfafdbf70ee1,88,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,0x4200000000000000000000000000000000000006,19930808,8774564,3791077958266666 \ No newline at end of file diff --git a/sources/_sector/dex/trades/base/_sources.yml b/sources/_sector/dex/trades/base/_sources.yml index 3af9b110190..38f2266b51a 100644 --- a/sources/_sector/dex/trades/base/_sources.yml +++ b/sources/_sector/dex/trades/base/_sources.yml @@ -185,4 +185,8 @@ sources: - name: xchange_base tables: - name: XchangePair_evt_Swap - - name: XchangeFactory_evt_PairCreated \ No newline at end of file + - name: XchangeFactory_evt_PairCreated + - name: akronswap_base + tables: + - name: UniswapV2Pair_evt_Swap + - name: UniswapV2Factory_evt_PairCreated \ No newline at end of file From f9a7d212c0806986082c58a0afbe1b6d9e0ea11f Mon Sep 17 00:00:00 2001 From: archie17277 <160746411+archie17277@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:58:15 +0530 Subject: [PATCH 44/68] Add flashliquidity dex to trades (#7219) * Add flashliquidity dex * updated csv file * update sql file --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/base/_schema.yml | 19 ++++++++++++++++- .../trades/base/dex_base_base_trades.sql | 1 + .../flashliquidity_base_base_trades.sql | 21 +++++++++++++++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 15 +++++++++++++ .../flashliquidity_base_base_trades_seed.csv | 3 +++ sources/_sector/dex/trades/base/_sources.yml | 6 +++++- 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/dex/models/trades/base/platforms/flashliquidity_base_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/flashliquidity_base_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index ad3c562c04f..42fd54da190 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -185,5 +185,6 @@ FROM (VALUES , ('kaia_swap', 'KaiaSwap', 'Direct', 'KaiaSwap') , ('defi_kingdoms', 'DeFi Kingdoms', 'Direct', 'DeFiKingdoms') , ('hyperjump', 'HyperJump', 'Direct', 'Hyperjump_fi') + , ('flashliquidity', 'Flashliquidity', 'Direct', 'flashliquidity') , ('akronswap', 'Akronswap', 'Direct', 'AkronFinance') ) AS temp_table (project, name, marketplace_type, x_username) diff --git a/dbt_subprojects/dex/models/trades/base/_schema.yml b/dbt_subprojects/dex/models/trades/base/_schema.yml index f960a1a8393..76c546922e4 100644 --- a/dbt_subprojects/dex/models/trades/base/_schema.yml +++ b/dbt_subprojects/dex/models/trades/base/_schema.yml @@ -997,6 +997,23 @@ models: - check_dex_base_trades_seed: seed_file: ref('xchange_base_base_trades_seed') + - name: flashliquidity_base_base_trades + meta: + blockchain: base + sector: dex + project: flashliquidity + contributors: archie + config: + tags: [ 'base', 'dex', 'trades', 'flashliquidity' ] + description: "flashliquidity base base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('flashliquidity_base_base_trades_seed') + - name: akronswap_base_base_trades meta: blockchain: base @@ -1012,4 +1029,4 @@ models: - tx_hash - evt_index - check_dex_base_trades_seed: - seed_file: ref('akronswap_base_base_trades_seed') \ No newline at end of file + seed_file: ref('akronswap_base_base_trades_seed') diff --git a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql index ab4ddf7d67b..9cbced710cb 100644 --- a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql @@ -50,6 +50,7 @@ , ref('solidly_v3_base_base_trades') , ref('swaap_v2_base_base_trades') , ref('xchange_base_base_trades') + , ref('flashliquidity_base_base_trades') , ref('akronswap_base_base_trades') ] %} diff --git a/dbt_subprojects/dex/models/trades/base/platforms/flashliquidity_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/platforms/flashliquidity_base_base_trades.sql new file mode 100644 index 00000000000..98c4ae25d82 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/base/platforms/flashliquidity_base_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'flashliquidity_base', + 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 = 'base', + project = 'flashliquidity', + version = '1', + Pair_evt_Swap = source('flashliquidity_base', 'FlashLiquidityPair_evt_Swap'), + Factory_evt_PairCreated = source('flashliquidity_base', 'FlashLiquidityFactory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index ac10a1d666f..3c8a3436252 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -4456,6 +4456,21 @@ seeds: token_sold_amount_raw: uint256 block_date: timestamp + - name: flashliquidity_base_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp + - name: akronswap_base_base_trades_seed config: column_types: diff --git a/dbt_subprojects/dex/seeds/trades/flashliquidity_base_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/flashliquidity_base_base_trades_seed.csv new file mode 100644 index 00000000000..e5d50a8bcc9 --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/flashliquidity_base_base_trades_seed.csv @@ -0,0 +1,3 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw +base,flashliquidity_base,1,2024-01-02,0xe9bf79692277d80abe35da70d44e6a4fe1154bff25cd435fcf257f5981ed8f46,18,0x4200000000000000000000000000000000000006,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,8695071,2074983733705749,5000000 +base,flashliquidity_base,1,2024-01-10,0xcbd2ef2440ad8f360b33a58423960d9cd3073317448e6e5364e76af316776046,37,0x4200000000000000000000000000000000000006,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,9028475,2434495227355002,5652787 \ No newline at end of file diff --git a/sources/_sector/dex/trades/base/_sources.yml b/sources/_sector/dex/trades/base/_sources.yml index 38f2266b51a..3411997a305 100644 --- a/sources/_sector/dex/trades/base/_sources.yml +++ b/sources/_sector/dex/trades/base/_sources.yml @@ -186,7 +186,11 @@ sources: tables: - name: XchangePair_evt_Swap - name: XchangeFactory_evt_PairCreated + - name: flashliquidity_base + tables: + - name: FlashLiquidityPair_evt_Swap + - name: FlashLiquidityFactory_evt_PairCreated - name: akronswap_base tables: - name: UniswapV2Pair_evt_Swap - - name: UniswapV2Factory_evt_PairCreated \ No newline at end of file + - name: UniswapV2Factory_evt_PairCreated From 7fa49e5a3e4af59dd3bc9a9e46651e1cee87d9bc Mon Sep 17 00:00:00 2001 From: ZkSwapFinance <126151208+ZkSwapFinance@users.noreply.github.com> Date: Wed, 4 Dec 2024 02:28:36 +0800 Subject: [PATCH 45/68] add zkswap_finance_v3 to trades (#7212) * add zkswap_finance_v3 to trades * update filter from seed file for zkSwapFinance exchange v2 --- .../dex/models/trades/zksync/_schema.yml | 21 +++++++++++++++++++ .../trades/zksync/dex_zksync_base_trades.sql | 1 + .../zkswap_finance_v3_zksync_base_trades.sql | 21 +++++++++++++++++++ ...zkswap_finance_zksync_base_trades_seed.csv | 4 +++- .../_sector/dex/trades/zksync/_sources.yml | 4 ++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 dbt_subprojects/dex/models/trades/zksync/platforms/zkswap_finance_v3_zksync_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/zksync/_schema.yml b/dbt_subprojects/dex/models/trades/zksync/_schema.yml index b359a8a13c5..1926ab03ca0 100644 --- a/dbt_subprojects/dex/models/trades/zksync/_schema.yml +++ b/dbt_subprojects/dex/models/trades/zksync/_schema.yml @@ -222,6 +222,27 @@ models: - evt_index - check_dex_base_trades_seed: seed_file: ref('zkswap_finance_zksync_base_trades_seed') + filter: + version: 1 + + - name: zkswap_finance_v3_zksync_base_trades + meta: + blockchain: zksync + sector: dex + project: zkswap_finance + contributors: lgingerich + config: + tags: [ 'zksync', 'dex', 'trades', 'zkswap_finance' ] + description: "zkSwap Finance V3 zksync base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('zkswap_finance_zksync_base_trades_seed') + filter: + version: 3 - name: gemswap_zksync_base_trades meta: diff --git a/dbt_subprojects/dex/models/trades/zksync/dex_zksync_base_trades.sql b/dbt_subprojects/dex/models/trades/zksync/dex_zksync_base_trades.sql index 7e5e58347ee..85dcf53065f 100644 --- a/dbt_subprojects/dex/models/trades/zksync/dex_zksync_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/zksync/dex_zksync_base_trades.sql @@ -19,6 +19,7 @@ , ref('ezkalibur_v2_zksync_base_trades') , ref('wagmi_v1_zksync_base_trades') , ref('zkswap_finance_zksync_base_trades') + , ref('zkswap_finance_v3_zksync_base_trades') , ref('gemswap_zksync_base_trades') , ref('vesync_v1_zksync_base_trades') , ref('dracula_finance_zksync_base_trades') diff --git a/dbt_subprojects/dex/models/trades/zksync/platforms/zkswap_finance_v3_zksync_base_trades.sql b/dbt_subprojects/dex/models/trades/zksync/platforms/zkswap_finance_v3_zksync_base_trades.sql new file mode 100644 index 00000000000..29c2d8c2df2 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/zksync/platforms/zkswap_finance_v3_zksync_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'zkswap_finance_v3_zksync', + 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 = 'zksync', + project = 'zkswap_finance', + version = '3', + Pair_evt_Swap = source('zkswap_finance_v3_zksync', 'ZFV3Pool_evt_Swap'), + Factory_evt_PoolCreated = source('zkswap_finance_v3_zksync', 'ZFV3Factory_evt_PoolCreated') + ) +}} diff --git a/dbt_subprojects/dex/seeds/trades/zkswap_finance_zksync_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/zkswap_finance_zksync_base_trades_seed.csv index efa17378d5e..cb949ab04ef 100644 --- a/dbt_subprojects/dex/seeds/trades/zkswap_finance_zksync_base_trades_seed.csv +++ b/dbt_subprojects/dex/seeds/trades/zkswap_finance_zksync_base_trades_seed.csv @@ -1,3 +1,5 @@ blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw zksync,zkswap_finance,1,2024-03-27,0xd9904a2f5ba6123080822d41c3392f43b5596df070405119282e3d3dacebb060,210,0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4,0x493257fd37edb34451f62edf8d2a0c418852ba4c,30012651,94688371,94714471 -zksync,zkswap_finance,1,2024-03-27,0xd595017ca2937ee8117721601605d373d2b9db4bc4fc68af2d676a25aa6531cc,593,0x5aea5775959fbc2557cc8789bc1bf90a239d9a91,0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4,29979948,5030613878243119,17996667 \ No newline at end of file +zksync,zkswap_finance,1,2024-03-27,0xd595017ca2937ee8117721601605d373d2b9db4bc4fc68af2d676a25aa6531cc,593,0x5aea5775959fbc2557cc8789bc1bf90a239d9a91,0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4,29979948,5030613878243119,17996667 +zksync,zkswap_finance,3,2024-11-18,0x7615aa106eafd199cbc0a6a51e75c07c756385110479502c45b96bc0a4a39dd0,8,0x5aea5775959fbc2557cc8789bc1bf90a239d9a91,0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4,49213495,193306889452386,600000 +zksync,zkswap_finance,3,2024-11-18,0xb564f0dc2228961852024f8ad26619bd44bf2e5bc916918e783b04650d5a1f80,19,0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4,0x5aea5775959fbc2557cc8789bc1bf90a239d9a91,49255134,100000,32122756733450 \ No newline at end of file diff --git a/sources/_sector/dex/trades/zksync/_sources.yml b/sources/_sector/dex/trades/zksync/_sources.yml index 76c083d868d..62602a6b1e8 100644 --- a/sources/_sector/dex/trades/zksync/_sources.yml +++ b/sources/_sector/dex/trades/zksync/_sources.yml @@ -60,6 +60,10 @@ sources: tables: - name: ZFPair_evt_Swap - name: Factory_evt_PairCreated + - name: zkswap_finance_v3_zksync + tables: + - name: ZFV3Pool_evt_Swap + - name: ZFV3Factory_evt_PoolCreated - name: gemswap_zksync tables: - name: ZGemPair_evt_Swap From 812b3af867761d087e62ba548c5453e8cd97c37d Mon Sep 17 00:00:00 2001 From: Rantum Date: Tue, 3 Dec 2024 10:29:47 -0800 Subject: [PATCH 46/68] zereox - v2 macro replacements 2 (#7168) * add/replace bnb * add linea * add op * update existing v2 models * add op file * update linea seed * update macro * update macro * fix endif * version from settler to v2 * update arbitrum to macro * add avax to v2 macro * add blast, mantle * cross chain model to v2 * zx_v2_arb * row_number * taker_token_ * taker_token_ * taker fix * add date filter to setter address selection * remove join in results, add tx_to, tx_from to upstream cte * revise taker, update linea seed with verified txs, revise taker_amount * update blast seed file with verified txs * better taker * add missing taker value in indirect cte * replace trade via lifi with wrong taker in internal data * rever taker field * -endif * -endif * taker * add mode * add mode seed * remove fills cte for mode trades * -nulls * cast null for fills_within in mode * adjust seed from eth to weth * simplify metadata CTEs, comments --------- Co-authored-by: jeff-dude Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../models/_project/zeroex/zeroex_v2.sql | 163 ++++----- .../arbitrum/zeroex_arbitrum_schema.yml | 4 +- .../zeroex_arbitrum_settler_trades.sql | 310 ----------------- .../arbitrum/zeroex_v2_arbitrum_trades.sql | 70 ++++ .../avalanche_c/zeroex_avalanche_c_schema.yml | 4 +- .../zeroex_avalanche_c_settler_trades.sql | 310 ----------------- .../zeroex_v2_avalanche_c_trades.sql | 70 ++++ .../zeroex/base/zeroex_v2_base_trades.sql | 13 +- .../zeroex/blast/zeroex_blast_schema.yml | 4 +- .../blast/zeroex_blast_settler_trades.sql | 301 ----------------- .../zeroex/blast/zeroex_v2_blast_trades.sql | 70 ++++ .../zeroex/bnb/zeroex_bnb_schema.yml | 4 +- .../zeroex/bnb/zeroex_bnb_settler_trades.sql | 312 ------------------ .../zeroex/bnb/zeroex_v2_bnb_trades.sql | 71 ++++ .../ethereum/zeroex_v2_ethereum_trades.sql | 13 +- .../zeroex/linea/zeroex_linea_schema.yml | 4 +- .../linea/zeroex_linea_settler_trades.sql | 304 ----------------- .../zeroex/linea/zeroex_v2_linea_trades.sql | 71 ++++ .../zeroex/mantle/zeroex_mantle_schema.yml | 4 +- .../mantle/zeroex_mantle_settler_trades.sql | 296 ----------------- .../zeroex/mantle/zeroex_v2_mantle_trades.sql | 70 ++++ .../zeroex/mode/zeroex_mode_schema.yml | 111 +++++++ .../zeroex/mode/zeroex_v2_mode_trades.sql | 61 ++++ .../optimism/zeroex_optimism_schema.yml | 2 +- .../zeroex_optimism_settler_trades.sql | 312 ------------------ .../optimism/zeroex_v2_optimism_trades.sql | 71 ++++ .../polygon/zeroex_v2_polygon_trades.sql | 13 +- .../zeroex/scroll/zeroex_scroll_schema.yml | 4 +- .../scroll/zeroex_scroll_settler_trades.sql | 302 ----------------- .../zeroex/scroll/zeroex_v2_scroll_trades.sql | 71 ++++ .../zeroex/zeroex_api_fills_deduped.sql | 27 +- .../models/_projects/zeroex/zeroex_trades.sql | 2 +- .../zeroex_blast_settler_trades_sample.csv | 5 +- .../zeroex_linea_settler_trades_sample.csv | 4 +- .../seeds/_project/zeroex/mode/_schema.yml | 11 + .../zeroex_mode_settler_trades_sample.csv | 3 + 36 files changed, 901 insertions(+), 2566 deletions(-) delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql create mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml create mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql index 4589ba128b7..36771b166bd 100644 --- a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql +++ b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql @@ -1,15 +1,17 @@ {% macro zeroex_settler_txs_cte(blockchain, start_date) %} WITH tbl_addresses AS ( SELECT - token_id, - "to" AS settler_address, + varbinary_to_int256 (topic1) as token_id, + bytearray_substring(logs.topic3,13,20) as settler_address, block_time AS begin_block_time, block_number AS begin_block_number FROM - {{ source('nft', 'transfers') }} + {{ source( blockchain, 'logs') }} WHERE contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = '{{ blockchain }}' + and topic0 = 0xaa94c583a45742b26ac5274d230aea34ab334ed5722264aa5673010e612bc0b2 + AND block_time >= DATE '2024-04-04' + /* no need to filter incrmeentally, as this returns small subset of addresses tracked as settler address over time */ ), tbl_end_times AS ( @@ -76,20 +78,29 @@ SELECT * FROM settler_txs {% endmacro %} {% macro zeroex_v2_trades(blockchain, start_date, is_direct=true) %} +/* + this macro is called twice -- once for direct, once for indirect trades + this is required due to how logs joins back to input settler address tx's +*/ WITH tbl_all_logs AS ( SELECT logs.tx_hash, logs.block_time, logs.block_number, index, - CASE WHEN ((varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) OVER (PARTITION BY logs.tx_hash ORDER BY index)) OR - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - THEN 1 END AS valid, - COALESCE(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) OVER (PARTITION BY logs.tx_hash ORDER BY index)) AS taker, - logs.contract_address AS maker_token, - first_value(logs.contract_address) OVER (PARTITION BY logs.tx_hash ORDER BY index) AS taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) AS int256)) OVER (PARTITION BY logs.tx_hash ORDER BY index) AS taker_amount, + case when (varbinary_substring(logs.topic2, 13, 20) in (settler_address)) + and varbinary_substring(logs.topic1, 13, 20) != 0x0000000000000000000000000000000000000000 + then varbinary_substring(logs.topic1, 13, 20) else tx_from + end as taker_, + case when (varbinary_substring(logs.topic1, 13, 20) in (tx_from, settler_address)) + then logs.contract_address + end as taker_token_, + case when (varbinary_substring(logs.topic2, 13, 20) in (settler_address, tx_from)) + then logs.contract_address + end as maker_token_, + case when (varbinary_substring(logs.topic1, 13, 20) in (tx_from, settler_address)) + then try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) + end as taker_amount_, try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) AS int256) AS maker_amount, method_id, tag, @@ -98,7 +109,8 @@ WITH tbl_all_logs AS ( st.settler_address AS contract_address, topic1, topic2, - tx_to + tx_to, + tx_from FROM {{ source(blockchain, 'logs') }} AS logs JOIN @@ -114,32 +126,37 @@ WITH tbl_all_logs AS ( AND topic0 IN (0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c) - AND topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 AND zid != 0xa00000000000000000000000 + {% if is_direct %} AND (logs.tx_to = settler_address) - {% else %} - AND (tx_to = settler_address OR varbinary_substring(logs.topic2, 13, 20) != 0x0000000000000000000000000000000000000000) - AND logs.tx_to != varbinary_substring(logs.topic1,13,20) - AND logs.tx_to != settler_address + AND (tx_from in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) + OR tx_to in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) + ) {% endif %} - {% if is_direct %} - AND (st.settler_address = bytearray_substring(logs.topic1,13,20) - OR st.settler_address = bytearray_substring(logs.topic2,13,20) - OR logs.tx_from = varbinary_substring(logs.topic1,13,20) - OR logs.tx_from = varbinary_substring(logs.topic2,13,20) - OR logs.tx_to = varbinary_substring(logs.topic1,13,20)) + {% if not is_direct %} + AND logs.tx_to != settler_address + and ( settler_address in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) + OR tx_from in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) + OR tx_to in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) + ) {% endif %} ), tbl_valid_logs AS ( SELECT - *, - ROW_NUMBER() OVER (PARTITION BY tx_hash ORDER BY valid, index DESC) AS rn + * + ,FIRST_VALUE(taker_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS taker + ,FIRST_VALUE(taker_amount_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS taker_amount + ,LAST_VALUE(maker_token_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS maker_token + ,FIRST_VALUE(taker_token_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS taker_token + ,ROW_NUMBER() OVER (PARTITION BY tx_hash ORDER BY index DESC) AS rn FROM tbl_all_logs - WHERE - taker_token != maker_token ) SELECT * FROM tbl_valid_logs @@ -148,51 +165,21 @@ WHERE rn = 1 {% macro zeroex_v2_trades_detail(blockchain, start_date) %} WITH tokens AS ( - SELECT DISTINCT token, te.* - FROM ( - SELECT maker_token AS token FROM tbl_trades - UNION ALL - SELECT taker_token FROM tbl_trades - ) t - JOIN {{ source('tokens', 'erc20') }} AS te ON te.contract_address = t.token - WHERE te.blockchain = '{{blockchain}}' + SELECT * + FROM {{ source('tokens', 'erc20') }} + WHERE blockchain = '{{blockchain}}' ), prices AS ( - SELECT DISTINCT pu.* - FROM {{ source('prices', 'usd') }} AS pu - JOIN tbl_trades ON (pu.contract_address IN (taker_token, maker_token)) AND DATE_TRUNC('minute', block_time) = minute + SELECT * + FROM {{ source('prices', 'usd') }} WHERE - pu.blockchain = '{{blockchain}}' - {% if is_incremental() %} - AND {{ incremental_predicate('pu.minute') }} - {% else %} - AND pu.minute >= DATE '{{start_date}}' - {% endif %} -), - -fills AS ( - WITH signatures AS ( - SELECT DISTINCT signature - FROM {{ source(blockchain, 'logs_decoded') }} l - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + blockchain = '{{blockchain}}' {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} + AND {{ incremental_predicate('minute') }} {% else %} - AND l.block_time >= DATE '{{start_date}}' + AND minute >= DATE '{{start_date}}' {% endif %} - ) - SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within - FROM {{ source(blockchain, 'logs') }} l - JOIN signatures ON signature = topic0 - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - {% if is_incremental() %} - WHERE {{ incremental_predicate('l.block_time') }} - {% else %} - WHERE l.block_time >= DATE '{{start_date}}' - {% endif %} - GROUP BY 1,2,3 ), results AS ( @@ -204,10 +191,10 @@ results AS ( trades.contract_address, method_id, trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, + tx_from, + tx_to, trades.index AS tx_index, - CASE WHEN varbinary_substring(tr.data,1,4) = 0x500c22bc THEN "from" ELSE taker END AS taker, + taker, CAST(NULL AS varbinary) AS maker, taker_token, taker_token AS token_sold_address, @@ -224,19 +211,9 @@ results AS ( maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS token_bought_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within + tag FROM tbl_trades trades - JOIN - {{ source(blockchain, 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{start_date}}' - {% endif %} - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number LEFT JOIN tokens tt ON tt.blockchain = '{{blockchain}}' AND tt.contract_address = taker_token LEFT JOIN @@ -258,7 +235,7 @@ results_usd AS ( SELECT '{{blockchain}}' AS blockchain, '0x-API' AS project, - 'settler' AS version, + 'v2' AS version, DATE_TRUNC('day', block_time) block_date, DATE_TRUNC('month', block_time) AS block_month, block_time, @@ -296,4 +273,28 @@ order by block_time desc {% macro zeroex_v2_trades_indirect(blockchain, start_date) %} {{ zeroex_v2_trades(blockchain, start_date, false) }} +{% endmacro %} + +{% macro zeroex_v2_trades_fills_count(blockchain, start_date) %} + WITH signatures AS ( + SELECT DISTINCT signature + FROM {{ source(blockchain, 'logs_decoded') }} l + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{start_date}}' + {% endif %} + ) + SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within + FROM {{ source(blockchain, 'logs') }} l + JOIN signatures ON signature = topic0 + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + {% if is_incremental() %} + WHERE {{ incremental_predicate('l.block_time') }} + {% else %} + WHERE l.block_time >= DATE '{{start_date}}' + {% endif %} + GROUP BY 1,2,3 {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml index 3498e9df2ef..3ca18250dcb 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml @@ -206,7 +206,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_arbitrum_settler_trades + - name: zeroex_v2_arbitrum_trades meta: blockchain: arbitrum project: zeroex @@ -214,7 +214,7 @@ models: config: tags: ['arbitrum','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql deleted file mode 100644 index 815021d5009..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql +++ /dev/null @@ -1,310 +0,0 @@ -{{ config( - schema = 'zeroex_arbitrum', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'arbitrum' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('arbitrum', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'arbitrum' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address is not null or tr.to in (0x0000000000001fF3684f28c67538d4D072C22734)) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - then 1 end as valid, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('arbitrum', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash - AND logs.block_time = st.block_time - AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = bytearray_substring(logs.topic1,13,20) - or logs.tx_from = bytearray_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'arbitrum' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'arbitrum' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('arbitrum', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellarbitrumToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('arbitrum', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('arbitrum', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'arbitrum' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'arbitrum' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'arbitrum' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'arbitrum' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'arbitrum' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, - 0xaf88d065e77c8cc2239327c5edb3a432268e5831, - 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, - 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, - 0x912ce59144191c1204e64559fe8253a0e49e6548) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, - 0xaf88d065e77c8cc2239327c5edb3a432268e5831, - 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, - 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, - 0x912ce59144191c1204e64559fe8253a0e49e6548) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql new file mode 100644 index 00000000000..6c70a2e8644 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql @@ -0,0 +1,70 @@ +{{ config( + schema = 'zeroex_v2_arbitrum', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'arbitrum' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml index 48deac58eea..98b01576297 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml @@ -150,7 +150,7 @@ models: name: fills_within description: "fills in then multihop, if present" - - name: zeroex_avalanche_c_settler_trades + - name: zeroex_v2_avalanche_c_trades meta: blockchain: avalanche_c project: zeroex @@ -158,7 +158,7 @@ models: config: tags: ['avalanche_c','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql deleted file mode 100644 index 4434aa4ad0c..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql +++ /dev/null @@ -1,310 +0,0 @@ -{{ config( - schema = 'zeroex_avalanche_c', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'avalanche_c' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('avalanche_c', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'avalanche_c' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000005E88410CcDFaDe4a5EfaE4b49562 ) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - then 1 end as valid, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('avalanche_c', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash - AND logs.block_time = st.block_time - AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = bytearray_substring(logs.topic1,13,20) - or logs.tx_from = bytearray_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by valid, index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'avalanche_c' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'avalanche_c' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('avalanche_c', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'Sellavalanche_cToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('avalanche_c', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('avalanche_c', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'avalanche_c' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'avalanche_c' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'avalanche_c' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'avalanche_c' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'avalanche_c' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, - 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, - 0x152b9d0fdc40c096757f570a51e494bd4b943e50, - 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, - 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, - 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, - 0x152b9d0fdc40c096757f570a51e494bd4b943e50, - 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, - 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql new file mode 100644 index 00000000000..e570380c699 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql @@ -0,0 +1,70 @@ +{{ config( + schema = 'zeroex_v2_avalanche_c', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'avalanche_c' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql index d69c3174508..2dc75f30a85 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql @@ -46,6 +46,14 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), trade_details as ( {{ zeroex_v2_trades_detail( @@ -57,5 +65,6 @@ trade_details as ( ) select - * - from trade_details + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml index 598e21561d9..4361c49a24b 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_blast_settler_trades + - name: zeroex_v2_blast_trades meta: blockchain: blast project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['blast','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql deleted file mode 100644 index 9fe304e77ba..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql +++ /dev/null @@ -1,301 +0,0 @@ -{{ config( - schema = 'zeroex_blast', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'blast' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('blast', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'blast' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('blast', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = varbinary_substring(logs.topic1,13,20) - or logs.tx_from = varbinary_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where maker_token != taker_token - ) - select * from tbl_valid_logs - where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'blast' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'blast' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('blast', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellblastToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('blast', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('blast', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'blast' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'blast' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'blast' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'blast' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'blast' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql new file mode 100644 index 00000000000..fca2b0c42a4 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql @@ -0,0 +1,70 @@ +{{ config( + schema = 'zeroex_v2_blast', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'blast' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml index e185fda2fd3..4eff3902e3a 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml @@ -197,7 +197,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_bnb_settler_trades + - name: zeroex_v2_bnb_trades meta: blockchain: bnb project: zeroex @@ -205,7 +205,7 @@ models: config: tags: ['bnb','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql deleted file mode 100644 index 06d2c811649..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql +++ /dev/null @@ -1,312 +0,0 @@ -{{ config( - schema = 'zeroex_bnb', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'bnb' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('bnb', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'bnb' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734 ) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - then 1 end as valid, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('bnb', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash - AND logs.block_time = st.block_time - AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = bytearray_substring(logs.topic1,13,20) - or logs.tx_from = bytearray_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by valid, index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'bnb' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'bnb' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('bnb', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellbnbToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('bnb', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('bnb', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'bnb' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'bnb' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'bnb' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'bnb' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'bnb' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x55d398326f99059ff775485246999027b3197955, - 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c, - 0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d, - 0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c, - 0x2170ed0880ac9a755fd29b2688956bd959f933f8, - 0xe9e7cea3dedca5984780bafc599bd69add087d56) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x55d398326f99059ff775485246999027b3197955, - 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c, - 0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d, - 0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c, - 0x2170ed0880ac9a755fd29b2688956bd959f933f8, - 0xe9e7cea3dedca5984780bafc599bd69add087d56) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql new file mode 100644 index 00000000000..687faaab8ac --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_bnb', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'bnb' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql index ceea2b3d384..256d8476c7d 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql @@ -46,6 +46,14 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), trade_details as ( {{ zeroex_v2_trades_detail( @@ -57,5 +65,6 @@ trade_details as ( ) select - * - from trade_details + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml index 35919de1e65..ac24be9a6b9 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_linea_settler_trades + - name: zeroex_v2_linea_trades meta: blockchain: linea project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['linea','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql deleted file mode 100644 index 4267d287b96..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql +++ /dev/null @@ -1,304 +0,0 @@ -{{ config( - schema = 'zeroex_linea', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'linea' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('linea', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'linea' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x000000000000175a8b9bC6d539B3708EEd92EA6c) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('linea', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = varbinary_substring(logs.topic1,13,20) - or logs.tx_from = varbinary_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where maker_token != taker_token - ) - select * from tbl_valid_logs - where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'linea' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'linea' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('linea', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SelllineaToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('linea', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('linea', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'linea' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'linea' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'linea' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'linea' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'linea' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, - 0x176211869ca2b568f2a7d4ee941e073a821ee1ff, - 0xa219439258ca9da29e9cc4ce5596924745e12b93, - 0x3aab2285ddcddad8edf438c1bab47e1a9d05a9b4 ) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, - 0x176211869ca2b568f2a7d4ee941e073a821ee1ff, - 0xa219439258ca9da29e9cc4ce5596924745e12b93, - 0x3aab2285ddcddad8edf438c1bab47e1a9d05a9b4 ) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql new file mode 100644 index 00000000000..6316ca85683 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_linea', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'linea' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml index bbbabcb2e22..418999bf150 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_mantle_settler_trades + - name: zeroex_v2_mantle_trades meta: blockchain: mantle project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['mantle','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql deleted file mode 100644 index 35bd8dc974e..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql +++ /dev/null @@ -1,296 +0,0 @@ -{{ config( - schema = 'zeroex_mantle', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'mantle' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('mantle', 'traces') }} AS tr - JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'mantle' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0xca11bde05977b3631167028862be2a173976ca11) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('mantle', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number - - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where maker_token != taker_token - ) - select * from tbl_valid_logs - where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'mantle' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'mantle' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('mantle', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellmantleToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('mantle', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('mantle', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'mantle' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'mantle' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'mantle' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'mantle' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'mantle' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x4300000000000000000000000000000000000004, - 0x4300000000000000000000000000000000000003, - 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql new file mode 100644 index 00000000000..a8b93a02368 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql @@ -0,0 +1,70 @@ +{{ config( + schema = 'zeroex_v2_mantle', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'mantle' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml new file mode 100644 index 00000000000..8f56bbccc93 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml @@ -0,0 +1,111 @@ +version: 2 + +models: + - name: zeroex_v2_mode_trades + meta: + blockchain: mode + project: zeroex + contributors: rantum + config: + tags: ['mode','0x','dex_aggregator','dex','aggregator'] + description: > + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_month + - block_date + - tx_hash + - evt_index + - check_seed: + seed_file: ref('zeroex_mode_settler_trades_sample') + match_columns: + - tx_hash + check_columns: + - taker + - maker_token + - taker_token + columns: + - &blockchain + name: blockchain + description: "Blockchain which the aggregator project is deployed" + - &block_date + name: block_date + description: "UTC event block date of each trade" + - &block_month + name: block_month + description: "UTC event block month of each trade" + - &block_time + name: block_time + description: "UTC event block time of each trade" + - &taker_symbol + name: taker_symbol + description: "Symbol of the token taker sells" + - &maker_symbol + name: maker_symbol + description: "Symbol of the token taker buys" + - &token_pair + name: token_pair + description: "Token pair traded" + - &taker_token_amount + name: taker_token_amount + description: "The after-decimal amount of the token taker sells" + - &taker_token_amount_raw + name: taker_token_amount_raw + description: "The raw amount of the token taker sells" + - &maker_token_amount + name: maker_token_amount + description: "The after-decimal amount of the token taker buys" + - &maker_token_amount_raw + name: maker_token_amount_raw + description: "The raw amount of the token taker buys" + - &volume_usd + name: volume_usd + description: "Trading volume measured in USD value" + - &taker_token + name: taker_token + description: "Contract address of the token taker sells" + - &maker_token + name: maker_token + description: "Contract address of the token taker buys" + - &maker + name: maker + description: "buyer of the trade" + - &taker + name: taker + description: "seller of the trade" + - &affiliate_address + name: affiliate_address + description: "The recipient address of the affiliate, or the applications that is using 0x API, for receiving affiliate fee" + - &tx_hash + name: tx_hash + description: "Transaction hash of the fill" + - &tx_from + name: tx_from + description: "Address which initiated the trade" + - &tx_to + name: tx_to + description: "Address which received the trade" + - &evt_index + name: evt_index + description: "Index of the corresponding order filled event" + - &type + name: type + description: "The liquidity route the order went thru" + - &swap_flag + name: swap_flag + description: "If the swap was filled/consumed thru 0x API" + - &contract_address + name: contract_address + desctiption: "The address of the contract which fired the fill/swap event" + - &fills_within + name: fills_within + description: "fills in then multihop, if present" + + + + + + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql new file mode 100644 index 00000000000..55f96ade5bc --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql @@ -0,0 +1,61 @@ +{{ config( + schema = 'zeroex_v2_mode', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'mode' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, cast(null as int) as fills_within + from trade_details t diff --git a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml index 8ad876a830c..e83453577cb 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml @@ -200,7 +200,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_optimism_settler_trades + - name: zeroex_v2_optimism_trades meta: blockchain: optimism project: zeroex diff --git a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql deleted file mode 100644 index 3ec7000ea9b..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql +++ /dev/null @@ -1,312 +0,0 @@ -{{ config( - schema = 'zeroex_optimism', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'optimism' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('optimism', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'optimism' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR - (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or - topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) - then 1 end as valid, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('optimism', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash - AND logs.block_time = st.block_time - AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = bytearray_substring(logs.topic1,13,20) - or logs.tx_from = bytearray_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by valid, index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'optimism' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'optimism' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('optimism', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SelloptimismToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('optimism', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('optimism', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'optimism' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'optimism' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'optimism' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'optimism' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'optimism' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x4200000000000000000000000000000000000006, - 0x7f5c764cbc14f9669b88837ca1490cca17c31607, - 0x4200000000000000000000000000000000000042, - 0x0b2c639c533813f4aa9d7837caf62653d097ff85, - 0x94b008aa00579c1307b0ef2c499ad98a8ce58e58, - 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x4200000000000000000000000000000000000006, - 0x7f5c764cbc14f9669b88837ca1490cca17c31607, - 0x4200000000000000000000000000000000000042, - 0x0b2c639c533813f4aa9d7837caf62653d097ff85, - 0x94b008aa00579c1307b0ef2c499ad98a8ce58e58, - 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql new file mode 100644 index 00000000000..fded3f2bf4b --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_optimism', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'optimism' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql index 1177284b18a..6c45e4fbcff 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql @@ -46,6 +46,14 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), trade_details as ( {{ zeroex_v2_trades_detail( @@ -57,5 +65,6 @@ trade_details as ( ) select - * - from trade_details + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml index f001bd15c5e..47a5f603a10 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_scroll_settler_trades + - name: zeroex_v2_scroll_trades meta: blockchain: scroll project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['scroll','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql deleted file mode 100644 index 0bfec20ce7a..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql +++ /dev/null @@ -1,302 +0,0 @@ -{{ config( - schema = 'zeroex_scroll', - alias = 'settler_trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} - -WITH tbl_addresses AS ( - SELECT - blockchain, - token_id, - to AS settler_address, - block_time AS begin_block_time, - block_number AS begin_block_number - FROM - {{ source('nft', 'transfers') }} - WHERE - contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - AND blockchain = 'scroll' - and block_time > TIMESTAMP '2024-05-23' -), - -tbl_end_times AS ( - SELECT - *, - LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, - LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number - FROM - tbl_addresses -), - -result_0x_settler_addresses AS ( - SELECT - * - FROM - tbl_end_times - WHERE - settler_address != 0x0000000000000000000000000000000000000000 -), - -settler_txs AS ( - SELECT - tx_hash, - block_time, - block_number, - method_id, - contract_address, - settler_address, - MAX(varbinary_substring(tracker,2,12)) AS zid, - CASE - WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) - WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) - END AS tag - FROM ( - SELECT - tr.tx_hash, - block_number, - block_time, - "to" AS contract_address, - varbinary_substring(input,1,4) AS method_id, - varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, - a.settler_address - FROM - {{ source('scroll', 'traces') }} AS tr - LEFT JOIN - result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'scroll' AND tr.block_time > a.begin_block_time - WHERE - (a.settler_address IS NOT NULL OR tr.to = 0x0000000000005E88410CcDFaDe4a5EfaE4b49562) - AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) - {% if is_incremental() %} - AND {{ incremental_predicate('block_time') }} - {% else %} - AND block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - GROUP BY - 1,2,3,4,5,6 -), -tbl_trades as ( - -with tbl_all_logs AS ( - SELECT - logs.tx_hash, - logs.block_time, - logs.block_number, - index, - coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, - logs.contract_address as maker_token, - first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, - first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, - try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, - method_id, - tag, - st.settler_address, - zid, - st.settler_address as contract_address - FROM - {{ source('scroll', 'logs') }} AS logs - JOIN - settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number - AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) - or (st.settler_address= bytearray_substring(logs.topic2,13,20)) - or logs.tx_from = varbinary_substring(logs.topic1,13,20) - or logs.tx_from = varbinary_substring(logs.topic2,13,20) - or logs.tx_to = varbinary_substring(logs.topic1,13,20) - ) - WHERE - topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) - and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 - and zid != 0xa00000000000000000000000 - {% if is_incremental() %} - AND {{ incremental_predicate('logs.block_time') }} - {% else %} - AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ), - tbl_valid_logs as ( - select * - , row_number() over (partition by tx_hash order by index desc) rn - from tbl_all_logs - where taker_token != maker_token - ) - select * from tbl_valid_logs where rn = 1 -), - - -tokens AS ( - with token_list as ( - select - distinct maker_token as token - from - tbl_trades - - union distinct - - select - distinct taker_token as token - from tbl_trades - ) - - select * - from - token_list tl - join - {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token - WHERE - te.blockchain = 'scroll' -), - -prices AS ( - SELECT DISTINCT - pu.* - FROM - {{ source('prices', 'usd') }} AS pu - JOIN - tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute - WHERE - pu.blockchain = 'scroll' - {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} - {% else %} - AND minute >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -fills as ( - with signatures as ( - select distinct signature - from {{ source('scroll', 'logs_decoded') }} l - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellscrollToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - ) - - select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within - from {{ source('scroll', 'logs') }} l - join signatures on signature = topic0 - join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number - WHERE 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} - group by 1,2,3 - ), - -results AS ( - SELECT - trades.block_time, - trades.block_number, - zid, - trades.contract_address, - method_id, - trades.tx_hash, - "from" AS tx_from, - "to" AS tx_to, - trades.index AS tx_index, - case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, - CAST(NULL AS varbinary) AS maker, - taker_token, - pt.price, - COALESCE(tt.symbol, pt.symbol) AS taker_symbol, - taker_amount AS taker_token_amount_raw, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, - taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, - maker_token, - COALESCE(tm.symbol, pm.symbol) AS maker_symbol, - maker_amount AS maker_token_amount_raw, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, - maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag, - fills_within - FROM - tbl_trades trades - JOIN - {{ source('scroll', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number - LEFT JOIN - fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number - LEFT JOIN - tokens tt ON tt.blockchain = 'scroll' AND tt.contract_address = taker_token - LEFT JOIN - tokens tm ON tm.blockchain = 'scroll' AND tm.contract_address = maker_token - LEFT JOIN - prices pt ON pt.blockchain = 'scroll' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) - LEFT JOIN - prices pm ON pm.blockchain = 'scroll' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) - WHERE - 1=1 - {% if is_incremental() %} - AND {{ incremental_predicate('tr.block_time') }} - {% else %} - AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' - {% endif %} -), - -results_usd AS ( - SELECT - 'scroll' AS blockchain, - '0x-API' AS project, - 'settler' AS version, - DATE_TRUNC('day', block_time) block_date, - DATE_TRUNC('month', block_time) AS block_month, - block_time, - taker_symbol, - maker_symbol, - CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, - taker_token_amount, - maker_token_amount, - taker_token_amount_raw, - maker_token_amount_raw, - CASE WHEN maker_token IN (0x5300000000000000000000000000000000000004, - 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4, - 0xf55bec9cafdbe8730f096aa55dad6d22d44099df, - 0xca77eb3fefe3725dc33bccb54edefc3d9f764f97) AND maker_amount IS NOT NULL - THEN maker_amount - WHEN taker_token IN (0x5300000000000000000000000000000000000004, - 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4, - 0xf55bec9cafdbe8730f096aa55dad6d22d44099df, - 0xca77eb3fefe3725dc33bccb54edefc3d9f764f97) AND taker_amount IS NOT NULL - THEN taker_amount - ELSE COALESCE(maker_amount, taker_amount) - END AS volume_usd, - taker_token, - maker_token, - taker, - maker, - tag, - zid, - tx_hash, - tx_from, - tx_to, - tx_index AS evt_index, - (ARRAY[-1]) AS trace_address, - 'settler' AS type, - TRUE AS swap_flag, - fills_within, - contract_address - FROM - results -) - -SELECT DISTINCT - * -FROM - results_usd -ORDER BY - block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql new file mode 100644 index 00000000000..3afca6ccc8e --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql @@ -0,0 +1,71 @@ +{{ config( + schema = 'zeroex_v2_scroll', + alias = 'trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} +{% set blockchain = 'scroll' %} + +WITH zeroex_tx AS ( + {{ + zeroex_settler_txs_cte( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +zeroex_v2_trades_direct AS ( + {{ + zeroex_v2_trades_direct( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +zeroex_v2_trades_indirect AS ( + {{ + zeroex_v2_trades_indirect( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} +), +tbl_trades AS ( + SELECT * + FROM zeroex_v2_trades_direct + UNION ALL + SELECT * + FROM zeroex_v2_trades_indirect +), +fills_count as( + {{ + zeroex_v2_trades_fills_count( + blockchain = blockchain, + start_date = zeroex_settler_start_date + ) + }} +), +trade_details as ( + {{ + zeroex_v2_trades_detail( + blockchain = blockchain, + start_date = zeroex_settler_start_date + + ) + }} + +) +select + t.*, fills_within + from trade_details t + left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 51563852cb7..fbb62cea130 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -1,7 +1,7 @@ {{ config( schema = 'zeroex' , alias = 'api_fills_deduped' - , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle"]\', + , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle","mode"]\', "project", "zeroex", \'["rantum","bakabhai993"]\') }}' @@ -9,7 +9,7 @@ }} -{% set zeroex_models = [ +{% set v1_models = [ ref('zeroex_arbitrum_api_fills_deduped') ,ref('zeroex_avalanche_c_api_fills_deduped') ,ref('zeroex_base_api_fills_deduped') @@ -21,24 +21,25 @@ ,ref('zeroex_bnb_api_fills_deduped') ] %} -{% set settler_models = [ +{% set v2_models = [ ref('zeroex_v2_ethereum_trades') ,ref('zeroex_v2_base_trades') ,ref('zeroex_v2_polygon_trades') - ,ref('zeroex_optimism_settler_trades') - ,ref('zeroex_bnb_settler_trades') - ,ref('zeroex_avalanche_c_settler_trades') - ,ref('zeroex_arbitrum_settler_trades') - ,ref('zeroex_scroll_settler_trades') - ,ref('zeroex_linea_settler_trades') - ,ref('zeroex_blast_settler_trades') - ,ref('zeroex_mantle_settler_trades') + ,ref('zeroex_v2_optimism_trades') + ,ref('zeroex_v2_bnb_trades') + ,ref('zeroex_v2_avalanche_c_trades') + ,ref('zeroex_v2_arbitrum_trades') + ,ref('zeroex_v2_scroll_trades') + ,ref('zeroex_v2_linea_trades') + ,ref('zeroex_v2_blast_trades') + ,ref('zeroex_v2_mantle_trades') + ,ref('zeroex_v2_mode_trades') ] %} SELECT * FROM ( - {% for model in zeroex_models %} + {% for model in v1_models %} SELECT blockchain ,version @@ -77,7 +78,7 @@ UNION ALL SELECT * FROM ( - {% for model in settler_models %} + {% for model in v2_models %} SELECT blockchain ,version diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql index 7f6826c10b6..dc0608ac407 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql @@ -1,7 +1,7 @@ {{ config( schema = 'zeroex' ,alias = 'trades' - ,post_hook='{{ expose_spells(\'["ethereum","arbitrum", "optimism", "polygon","fantom","avalanche_c","bnb","base","scroll","linea","blast","mantle"]\', + ,post_hook='{{ expose_spells(\'["ethereum","arbitrum", "optimism", "polygon","fantom","avalanche_c","bnb","base","scroll","linea","blast","mantle","mode"]\', "project", "zeroex", \'["rantum","bakabhai993"]\') }}' diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv index 6485f75e989..8d032b5eccf 100644 --- a/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv +++ b/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv @@ -1,3 +1,4 @@ tx_hash,taker,taker_token,maker_token,taker_token_amount -0x92f05d2cc3e693ae5863e5a3c08475a9fb62c1db76acce05461aa8538cb9689a,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0x4300000000000000000000000000000000000003,0x4300000000000000000000000000000000000004,1 -0x4477ae1598016d0abee946f6bd7a0f6cbdbd6a87a3dde5eae1007d9f6a8ced06,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0x4300000000000000000000000000000000000003,0x4300000000000000000000000000000000000004,1e-12 \ No newline at end of file +0x1039b307c87496757057f2ff6355886434c167bbb91481a6948200f9731f01e9,0x34c241faf3e5ff210cd50f23d781f090fd8d6d43,0x4300000000000000000000000000000000000003,0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad,3.5882931897308494 +0x0189d26190c6498a93bf5e43463e87c11181f33cbb9d6477fe1c5921279773c6,0x1e42d0891a7328b650e9aebca35c135cc1693ee1,0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad,0x4300000000000000000000000000000000000003,20000 +0x03de7fc149d44a67dcd41522d887f6226b5a734ffd08d2f241bb20339fa69998,0xe9805ecab212eabf696cf458d2c4840a619ee6de,0x52f847356b38720b55ee18cb3e094ca11c85a192,0xd43d8adac6a4c7d9aeece7c3151fca8f23752cf8, diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv index 6760f03e395..a45529dffba 100644 --- a/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv +++ b/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv @@ -1,2 +1,4 @@ tx_hash,taker,taker_token,maker_token,taker_token_amount -0xfd32094a40aea663ed1662833709c1c3590989607abf99e70a18f5740c8fd043,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,0xa219439258ca9da29e9cc4ce5596924745e12b93,0.000745504333903425 \ No newline at end of file +0x0027e74f02780c84c30e0913cf4a56001d47c4d0830f9c0c036ed2641b1c861a,0xc0263992b8ef45e48d653683164ce40f32c0173a,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,0x4af15ec2a0bd43db75dd04e62faa3b8ef36b00d5,153.039629 +0x0032a240fba185828915257a67952aca9e3ed2c7df4508fa3b9b8a6df627b736,0xdbfd6dc67d3ce76b2c334d305527a5e6ec734da0,0xb5bedd42000b71fdde22d3ee8a79bd49a568fc8f,0x2416092f143378750bb29b79ed961ab195cceea5,0.2797467631837312 +0xa6f26819efd68a95c4a5ebed953026446084ba1b5f1dabb30a0a54f1c2df0593,0x48655b457be821670d42b22f94f98044b737f46b,0xaaaac83751090c6ea42379626435f805ddf54dc8,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,94.86653636189624 \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml b/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml new file mode 100644 index 00000000000..4381886dd99 --- /dev/null +++ b/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml @@ -0,0 +1,11 @@ +version: 2 + +seeds: + - name: zeroex_mode_settler_trades_sample + config: + column_types: + tx_hash: varbinary + taker: varbinary + taker_token: varbinary + maker_token: varbinary + taker_token_amount: double \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv new file mode 100644 index 00000000000..e1355700bf2 --- /dev/null +++ b/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv @@ -0,0 +1,3 @@ +tx_hash,taker,taker_token,maker_token,taker_token_amount +0xd7ace13835ceb119b071c508e8ee262fcecb5a0f2a1bfdd1b9b1f04afa73d94d,0x44c20316a06371ca5acb975974c18abfa7a14a5a,0xf0f161fda2712db8b566946122a5af183995e2ed,0x4200000000000000000000000000000000000006,5.5 +0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x6a660e56fa3b630a786cc4ae98859f8532d03de9,0x2416092f143378750bb29b79ed961ab195cceea5,238973 \ No newline at end of file From 7740fd4866fc98c902ee2e844c4aa0818eae5d97 Mon Sep 17 00:00:00 2001 From: Jacob Sharples <45126111+JacobSharples@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:30:35 -0500 Subject: [PATCH 47/68] Update prices_base_tokens.sql (#7225) Added Virtual Protocol --- .../tokens/models/prices/base/prices_base_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql index 7891a6ece06..4796d3a7646 100644 --- a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql @@ -190,6 +190,7 @@ FROM ('alf-alf', 'base', 'ALF',0x26f1bb40ea88b46ceb21557dc0ffac7b7c0ad40f, 18), ('tad1-tadpole', 'base', 'TAD',0x55027a5b06f4340cc4c82dcc74c90ca93dcb173e, 18), ('blue-blue-guy', 'base', 'BLUE',0x891502ba08132653151f822a3a430198f1844115, 18), - ('alb-alienbase', 'base', 'ALB',0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4, 18) + ('alb-alienbase', 'base', 'ALB',0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4, 18), + ('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) From 9e7fc2e12e0dcc5567f38caa70cbf350563d32e1 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:31:31 +0000 Subject: [PATCH 48/68] add missing tokens to prices.usd and tokens.erc20 (#7220) Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../tokens/models/prices/base/prices_base_tokens.sql | 2 +- .../models/prices/optimism/prices_optimism_tokens_curated.sql | 3 ++- .../tokens/models/tokens/base/tokens_base_erc20.sql | 2 ++ .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 1 + .../models/tokens/optimism/tokens_optimism_erc20_curated.sql | 3 ++- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql index 4796d3a7646..9cda8da5f0a 100644 --- a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql @@ -191,6 +191,6 @@ FROM ('tad1-tadpole', 'base', 'TAD',0x55027a5b06f4340cc4c82dcc74c90ca93dcb173e, 18), ('blue-blue-guy', 'base', 'BLUE',0x891502ba08132653151f822a3a430198f1844115, 18), ('alb-alienbase', 'base', 'ALB',0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4, 18), + ('gyd-gyro-dollar','base','GYD',0xca5d8f8a8d49439357d3cf46ca2e720702f132b8, 18), ('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18) - ) as temp (token_id, blockchain, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql b/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql index d0e1460b32d..ba2a0644a73 100644 --- a/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql +++ b/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql @@ -136,5 +136,6 @@ FROM ('pendle-pendle', 'PENDLE',0xbc7b1ff1c6989f006a1185318ed4e7b5796e66e1, 18), ('trb-tellor', 'TRB', 0xaf8ca653fa2772d58f4368b0a71980e9e3ceb888, 18), ('dtoro-dextoro', 'DTORO', 0x1cef2d62af4cd26673c7416957cc4ec619a696a7, 18), - ('osak-osaka-protocol', 'OSAK', 0xbfd5206962267c7b4b4a8b3d76ac2e1b2a5c4d5e, 18) + ('osak-osaka-protocol', 'OSAK', 0xbfd5206962267c7b4b4a8b3d76ac2e1b2a5c4d5e, 18), + ('gyd-gyro-dollar','GYD',0xca5d8f8a8d49439357d3cf46ca2e720702f132b8, 18) ) as temp (token_id, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql index 95d8dab348c..0e2dece240f 100644 --- a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql @@ -407,4 +407,6 @@ FROM (VALUES , (0xd68470491eb513365322810e55e0eba80785dfdd, '243M theft', 18) , (0xb0505e5a99abd03d94a1169e638b78edfed26ea4, 'uSUI', 18) , (0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842, 'MORPHO', 18) + , (0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8, 'GYD', 18) + , (0xC0D3700000987C99b3C9009069E4f8413fD22330, 'cdxUSD', 18) ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 10b6ea5c913..0091a2ae557 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4723,4 +4723,5 @@ FROM (VALUES , ( 0x7cc6694cf75c18d488d16fb4bf3c71a3b31cc7fb, 'stataEthETHx', 18) , ( 0x58D97B57BB95320F9a05dC918Aef65434969c2B2, 'MORPHO', 18) , ( 0x9994E35Db50125E0DF82e4c2dde62496CE330999, 'legacyMORPHO', 18) + , ( 0x6e6B7ADfC7Db9fEeB8896418aC3422966f65D0A5, 'NET', 18) ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_curated.sql b/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_curated.sql index fbb3b7e3457..289d88f6963 100644 --- a/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_curated.sql +++ b/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_curated.sql @@ -450,7 +450,8 @@ WITH raw_token_list AS ( ,(0xe62dda84e579e6a37296bcfc74c97349d2c59ce3, 'ysWETH', 18, 'receipt') ,(0xd08C3F25862077056cb1b710937576Af899a4959, 'InstETH', 18, 'underlying') ,(0x57f5e098cad7a3d1eed53991d4d66c45c9af7812, 'wUSDM', 18, 'receipt') - ,(0xbfd5206962267c7b4b4a8b3d76ac2e1b2a5c4d5e, 'OSAK', 18, 'underlying') + ,(0xbfd5206962267c7b4b4a8b3d76ac2e1b2a5c4d5e, 'OSAK', 18, 'underlying') + , (0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8, 'GYD', 18, 'underlying') ) AS temp_table (contract_address, symbol, decimals, token_type) ) SELECT From ddf97986c9e0776e3cd7dd7a19f85c9a76fc4dd4 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:32:21 +0000 Subject: [PATCH 49/68] Add BRLA to prices.usd and tokens.erc20 on gnosis (#7230) * Update prices_gnosis_tokens.sql * Update tokens_gnosis_erc20.sql --- .../tokens/models/prices/gnosis/prices_gnosis_tokens.sql | 3 ++- .../tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/gnosis/prices_gnosis_tokens.sql b/dbt_subprojects/tokens/models/prices/gnosis/prices_gnosis_tokens.sql index 24abc9275ef..396bd2ca4bc 100644 --- a/dbt_subprojects/tokens/models/prices/gnosis/prices_gnosis_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/gnosis/prices_gnosis_tokens.sql @@ -40,5 +40,6 @@ FROM ('safe-safe', 'gnosis', 'SAFE', 0x4d18815d14fe5c3304e87b3fa18318baa5c23820, 18), ('giv-giv', 'gnosis', 'GIV', 0x4f4F9b8D5B4d0Dc10506e5551B0513B61fD59e75, 18), ('usdc-usd-coin', 'gnosis', 'USDC.e', 0x2a22f9c3b484c3629090feed35f17ff8f88f76f0, 6), - ('ageur-ageur', 'gnosis', 'agEUR', 0x4b1e2c2762667331bc91648052f646d1b0d35984, 18) + ('ageur-ageur', 'gnosis', 'agEUR', 0x4b1e2c2762667331bc91648052f646d1b0d35984, 18), + ('brla-brla-digital-brla', 'gnosis', 'BRLA', 0xFECB3F7c54E2CAAE9dC6Ac9060A822D47E053760, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql b/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql index bff97b5ba67..50bb05cede7 100644 --- a/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql @@ -7820,4 +7820,5 @@ FROM (VALUES , ( 0x8418d17640a74f1614ac3e1826f29e78714488a1, 'stataGnoEURe', 18) , ( 0xecfd0638175e291ba3f784a58fb9d38a25418904, 'stataGnowstETH', 18) , ( 0xf0e7ec247b918311afa054e0aedb99d74c31b809, 'stataGnoUSDCe', 6) + , ( 0xFECB3F7c54E2CAAE9dC6Ac9060A822D47E053760, 'BRLA', 18) ) AS temp_table (contract_address, symbol, decimals) From 0cfd9e108071d314a092ba4db057ed6fe242df8f Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:34:02 +0000 Subject: [PATCH 50/68] Update tokens_ethereum_erc20.sql (#7231) Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 0091a2ae557..79c8d74e04e 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4723,5 +4723,6 @@ FROM (VALUES , ( 0x7cc6694cf75c18d488d16fb4bf3c71a3b31cc7fb, 'stataEthETHx', 18) , ( 0x58D97B57BB95320F9a05dC918Aef65434969c2B2, 'MORPHO', 18) , ( 0x9994E35Db50125E0DF82e4c2dde62496CE330999, 'legacyMORPHO', 18) + , ( 0xc824a08db624942c5e5f330d56530cd1598859fd, 'hgETH', 18) , ( 0x6e6B7ADfC7Db9fEeB8896418aC3422966f65D0A5, 'NET', 18) ) AS temp_table (contract_address, symbol, decimals) From 924c646a061ba4145fb89c6f0550573f33960f7b Mon Sep 17 00:00:00 2001 From: timmaycastags <102872759+timmaycastags@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:35:11 -0500 Subject: [PATCH 51/68] Add Clark to tokens and prices for base (#7211) * Add PNDC to Tokens and Price * Removed duplicate prices for PNDC * removed legacy price update for PNDC * Merge branch 'main' of https://github.com/timmaycastags/spellbook * Add Clark to Tokens and Prices for Base chain * Merged Morpho and Clark --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql | 1 + dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql index 9cda8da5f0a..2cc0457de62 100644 --- a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql @@ -191,6 +191,7 @@ FROM ('tad1-tadpole', 'base', 'TAD',0x55027a5b06f4340cc4c82dcc74c90ca93dcb173e, 18), ('blue-blue-guy', 'base', 'BLUE',0x891502ba08132653151f822a3a430198f1844115, 18), ('alb-alienbase', 'base', 'ALB',0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4, 18), + ('clark-coinbase-mascot','base','CLARK',0x5f7373Fa845692b1dD7bfaE576D6c743482bf26a, 18), ('gyd-gyro-dollar','base','GYD',0xca5d8f8a8d49439357d3cf46ca2e720702f132b8, 18), ('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql index 0e2dece240f..a7feaeee8e3 100644 --- a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql @@ -406,6 +406,7 @@ FROM (VALUES , (0x63e14921ba4546cb15087d574346574eee055812, 'PVP', 18) , (0xd68470491eb513365322810e55e0eba80785dfdd, '243M theft', 18) , (0xb0505e5a99abd03d94a1169e638b78edfed26ea4, 'uSUI', 18) + , (0x5f7373Fa845692b1dD7bfaE576D6c743482bf26a, 'CLARK', 18) , (0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842, 'MORPHO', 18) , (0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8, 'GYD', 18) , (0xC0D3700000987C99b3C9009069E4f8413fD22330, 'cdxUSD', 18) From 0473a6407f641c2c5d366ab10456131953f66e38 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Wed, 4 Dec 2024 02:35:37 +0800 Subject: [PATCH 52/68] Init boba chain (#7209) * Init boba chain * Fix evm info: * Add native token * Update token checker * Remove not existed transfers sources * Match raw data schema * Rewrite boba docs block --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../daily_spellbook/models/evms/evms_info.sql | 4 +- .../tokens/models/prices/boba/_schema.yml | 29 ++ .../models/prices/boba/prices_boba_tokens.sql | 28 ++ .../models/prices/prices_native_tokens.sql | 1 + .../tokens/models/prices/prices_tokens.sql | 2 + .../models/prices/prices_trusted_tokens.sql | 7 + .../tokens/models/tokens/_schema.yml | 4 +- .../tokens/models/tokens/boba/_schema.yml | 21 ++ .../models/tokens/boba/tokens_boba_erc20.sql | 21 ++ .../tokens/models/tokens/tokens_erc20.sql | 2 + scripts/token_checker.py | 3 +- .../_base_sources/evm/boba_base_sources.yml | 335 ++++++++++++++++++ sources/_base_sources/evm/boba_docs_block.md | 162 +++++++++ 13 files changed, 614 insertions(+), 5 deletions(-) create mode 100644 dbt_subprojects/tokens/models/prices/boba/_schema.yml create mode 100644 dbt_subprojects/tokens/models/prices/boba/prices_boba_tokens.sql create mode 100644 dbt_subprojects/tokens/models/tokens/boba/_schema.yml create mode 100644 dbt_subprojects/tokens/models/tokens/boba/tokens_boba_erc20.sql create mode 100644 sources/_base_sources/evm/boba_base_sources.yml create mode 100644 sources/_base_sources/evm/boba_docs_block.md diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql index dcb86d95584..991164f9456 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql @@ -8,6 +8,7 @@ , "base" , "blast" , "bnb" + , "boba" , "celo" , "ethereum" , "fantom" @@ -63,7 +64,7 @@ FROM ( , (1101, 'zkevm', 'Polygon zkEVM', 'Layer 2', 'ZK Rollup', 'ETH', 0x4f9a0e7fd2bf6067db6994cf12e4495df938e6e9, 'https://zkevm.polygonscan.com/', timestamp '2023-03-24 05:30', 'Polygon', 'Ethereum', 'Ethereum', true) , (1088, 'metis_andromeda', 'Metis Andromeda', NULL, NULL, NULL, NULL, 'https://andromeda-explorer.metis.io/', timestamp '2021-11-18 22:19', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum', false) , (59144, 'linea', 'Linea', 'Layer 2', 'ZK Rollup', 'ETH', 0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, 'https://lineascan.build/', timestamp '2023-07-06 13:15', NULL, 'Ethereum Blobs', 'Ethereum', true) - , (288, 'boba', 'Boba Network', 'Layer 2', 'Optimistic Rollup', 'ETH', NULL, 'https://bobascan.com/', timestamp '2021-10-28 05:03', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum', false) + , (288, 'boba', 'Boba Network', 'Layer 2', 'Optimistic Rollup', 'ETH', 0x4200000000000000000000000000000000000006, 'https://bobascan.com/', timestamp '2021-10-28 05:03', 'OP Stack', 'Ethereum', 'Ethereum', true) , (7700, 'canto', 'Canto', 'Layer 2', NULL, 'ETH', NULL, 'https://evm.explorer.canto.io/', timestamp '2022-07-26 19:27', NULL, 'Ethereum', 'Ethereum', false) , (420, 'optimism_goerli', 'Optimism Goerli', 'Testnet', 'Optimistic Rollup', 'GTH', 0x4200000000000000000000000000000000000006, 'https://optimism-goerli.blockscout.com/', timestamp '2022-06-09 16:55', 'OP Stack', 'Goerli', 'Goerli', false) , (1313161554, 'aurora', 'Aurora', 'Layer 2', NULL, 'ETH', 0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB, 'https://explorer.aurora.dev/', timestamp '2020-07-21 21:50:11', NULL, NULL, NULL, false) @@ -91,4 +92,3 @@ FROM ( , (42170, 'nova', 'Arbitrum Nova', 'Layer 2', 'Optimistic Rollup', 'ETH', 0x722e8bdd2ce80a4422e880164f2079488e115365, 'https://nova-explorer.arbitrum.io/', timestamp '2022-06-25 04:01', 'Arbitrum', 'Ethereum', 'Ethereum', true) , (2020, 'ronin', 'Ronin', 'Layer 1', null, 'RON', 0xe514d9deb7966c8be0ca922de8a064264ea6bcd4, 'https://app.roninchain.com/', timestamp '2021-01-25 10:49', NULL, NULL, NULL, true) ) AS temp_table (chain_id, blockchain, name, chain_type, rollup_type, native_token_symbol, wrapped_native_token_address, explorer_link, first_block_time, codebase, data_availability, settlement, is_on_dune) - diff --git a/dbt_subprojects/tokens/models/prices/boba/_schema.yml b/dbt_subprojects/tokens/models/prices/boba/_schema.yml new file mode 100644 index 00000000000..1a0a161aad8 --- /dev/null +++ b/dbt_subprojects/tokens/models/prices/boba/_schema.yml @@ -0,0 +1,29 @@ +version: 2 + +models: + - name: prices_boba_tokens + meta: + blockchain: boba + sector: prices + contributors: hosuke + config: + tags: ['prices', 'tokens', 'usd', 'boba'] + description: "Price tokens on Boba Network EVM chain" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - contract_address + columns: + - name: token_id + description: "Id of the token at coinpaprika. This id is required to pull the price feed data. NOTE: Not all tokens are listed at coinpaprika - consider using price data from DEX sources in this case or submit a listing request at coinpaprika." + - name: blockchain + description: "Native blockchain of the token, if any" + data_tests: + - accepted_values: + values: [ "boba" ] + - name: contract_address + description: "Contract address of the token, if any" + - name: symbol + description: "Token symbol" + - name: decimals + description: "Number of decimals for the token contract" diff --git a/dbt_subprojects/tokens/models/prices/boba/prices_boba_tokens.sql b/dbt_subprojects/tokens/models/prices/boba/prices_boba_tokens.sql new file mode 100644 index 00000000000..8480d16c5c2 --- /dev/null +++ b/dbt_subprojects/tokens/models/prices/boba/prices_boba_tokens.sql @@ -0,0 +1,28 @@ +{% set blockchain = 'boba' %} + +{{ config( + schema = 'prices_' + blockchain, + alias = 'tokens', + materialized = 'table', + file_format = 'delta', + tags = ['static'] + ) +}} + +SELECT + token_id + , '{{ blockchain }}' as blockchain + , symbol + , contract_address + , decimals +FROM +( + VALUES + ('usdt-tether', 'USDT', 0x5DE1677344D3Cb0D7D465c10b72A8f60699C062d, 6) + , ('usdc-usd-coin', 'USDC', 0x66a2A913e447d6b4BF33EFbec43aAeF87890FBbc, 6) + , ('eth-ethereum', 'WETH', 0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000, 18) + , ('boba-boba-network', 'BOBA', 0xa18bF3994C0Cc6E3b63ac420308E5383f53120D7, 18) + , ('dai-dai', 'DAI', 0xf74195Bb8a5cf652411867c5C2C5b8C2a402be35, 18) + , ('frax-frax', 'FRAX', 0x7562F525106F5d54E891e005867Bf489B5988CD9, 18) + , ('bnb-binance-coin', 'BNB', 0x68ac1623ACf9eB9F88b65B5F229fE3e2c0d5789E, 18) +) as temp (token_id, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql b/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql index f86c6a37a71..978c1669a8c 100644 --- a/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql @@ -25,6 +25,7 @@ FROM ('avax-avalanche', null, 'AVAX', null, null), ('bch-bitcoin-cash', null, 'BCH', null, null), ('bnb-binance-coin', null, 'BNB', null, null), + ('boba-boba-network', null, 'BOBA', null, null), ('bsv-bitcoin-sv', null, 'BSV', null, null), ('btc-bitcoin', null, 'BTC', null, null), ('celo-celo', null, 'CELO', null, null), diff --git a/dbt_subprojects/tokens/models/prices/prices_tokens.sql b/dbt_subprojects/tokens/models/prices/prices_tokens.sql index 665f2adde64..9fa9d762641 100644 --- a/dbt_subprojects/tokens/models/prices/prices_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/prices_tokens.sql @@ -11,6 +11,7 @@ , "bitcoin" , "blast" , "bnb" + , "boba" , "cardano" , "celo" , "ethereum" @@ -64,6 +65,7 @@ ref('prices_native_tokens') ,ref('prices_kaia_tokens') ,ref('prices_tron_tokens') ,ref('prices_ronin_tokens') +,ref('prices_boba_tokens') ] %} diff --git a/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql b/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql index 37ad50a9faa..613aca4cf83 100644 --- a/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql @@ -47,6 +47,13 @@ WITH trusted_tokens AS ( , ('bnb', 0x2170ed0880ac9a755fd29b2688956bd959f933f8) , ('bnb', 0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c) , ('bnb', 0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3) + , ('boba', 0x5DE1677344D3Cb0D7D465c10b72A8f60699C062d) + , ('boba', 0x66a2A913e447d6b4BF33EFbec43aAeF87890FBbc) + , ('boba', 0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000) + , ('boba', 0xa18bF3994C0Cc6E3b63ac420308E5383f53120D7) + , ('boba', 0xf74195Bb8a5cf652411867c5C2C5b8C2a402be35) + , ('boba', 0x7562F525106F5d54E891e005867Bf489B5988CD9) + , ('boba', 0x68ac1623ACf9eB9F88b65B5F229fE3e2c0d5789E) , ('celo', 0x765de816845861e75a25fca122bb6898b8b1282a) , ('celo', 0x471ece3750da237f93b8e339c536989b8978a438) , ('celo', 0xceba9300f2b948710d2653dd7b07f33a8b32118c) diff --git a/dbt_subprojects/tokens/models/tokens/_schema.yml b/dbt_subprojects/tokens/models/tokens/_schema.yml index 5b5784747a1..bb64ce8a7d8 100644 --- a/dbt_subprojects/tokens/models/tokens/_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/_schema.yml @@ -3,11 +3,11 @@ version: 2 models: - name: tokens_erc20 meta: - blockchain: arbitrum, avalanche_c, bnb, ethereum, gnosis, mantle, optimism, fantom, polygon, base, blast, sepolia, sei, nova, worldchain, kaia, ronin + blockchain: arbitrum, avalanche_c, bnb, ethereum, gnosis, mantle, optimism, fantom, polygon, base, blast, sepolia, sei, nova, worldchain, kaia, ronin, boba sector: tokens contributors: hildobby, 0xManny, dot2dotseurat, soispoke, mtitus6, wuligy, angus_1, Henrystats, viniabussafi, jeff-dude, rantum, hosuke config: - tags: ['tokens','erc20', 'arbitrum', 'avalanche_c', 'bnb', 'ethereum', 'gnosis', 'mantle', 'optimism', 'fantom', 'base', 'blast', 'sei', 'nova', 'linea', 'worldchain', 'kaia', 'ronin'] + tags: ['tokens','erc20', 'arbitrum', 'avalanche_c', 'bnb', 'ethereum', 'gnosis', 'mantle', 'optimism', 'fantom', 'base', 'blast', 'sei', 'nova', 'linea', 'worldchain', 'kaia', 'ronin', 'boba'] description: > Crosschain ERC20 tokens data_tests: diff --git a/dbt_subprojects/tokens/models/tokens/boba/_schema.yml b/dbt_subprojects/tokens/models/tokens/boba/_schema.yml new file mode 100644 index 00000000000..61083aa8444 --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/boba/_schema.yml @@ -0,0 +1,21 @@ +version: 2 + +models: + - name: tokens_boba_erc20 + meta: + blockchain: boba + sector: tokens + project: erc20 + contributors: hosuke + config: + tags: ['table', 'erc20', 'boba'] + description: "ERC20 Token Addresses, Symbols and Decimals on Boba Network" + columns: + - name: contract_address + description: "ERC20 token contract address" + data_tests: + - unique + - name: symbol + description: "ERC20 token symbol" + - name: decimals + description: "Number of decimals, refers to how divisible an ERC20 token can be" diff --git a/dbt_subprojects/tokens/models/tokens/boba/tokens_boba_erc20.sql b/dbt_subprojects/tokens/models/tokens/boba/tokens_boba_erc20.sql new file mode 100644 index 00000000000..4d812cedd8e --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/boba/tokens_boba_erc20.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'tokens_boba' + ,alias = 'erc20' + ,tags = ['static'] + ,materialized = 'table' + ) +}} + +SELECT + contract_address + , symbol + , decimals +FROM (VALUES + (0xa18bf3994c0cc6e3b63ac420308e5383f53120d7, 'BOBA', 18) + , (0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000, 'ETH', 18) + , (0x66a2a913e447d6b4bf33efbec43aaef87890fbbc, 'USDC', 6) + , (0x5de1677344d3cb0d7d465c10b72a8f60699c062d, 'USDT', 6) + , (0xf74195bb8a5cf652411867c5c2c5b8c2a402be35, 'DAI', 18) + , (0xd203de32170130082896b4111edf825a4774c18e, 'WETH', 18) +) as temp (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql b/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql index c50255ecaf7..4371252253b 100644 --- a/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql @@ -10,6 +10,7 @@ ,"base" ,"blast" ,"bnb" + ,"boba" ,"celo" ,"ethereum" ,"fantom" @@ -71,6 +72,7 @@ ,'tokens_tron': {'blockchain': 'tron', 'model': ref('tokens_tron_erc20')} ,'tokens_ronin': {'blockchain': 'ronin', 'model': ref('tokens_ronin_erc20')} ,'tokens_bob': {'blockchain': 'bob', 'model': ref('tokens_bob_erc20')} + ,'tokens_boba': {'blockchain': 'boba', 'model': ref('tokens_boba_erc20')} } %} with automated_source as ( diff --git a/scripts/token_checker.py b/scripts/token_checker.py index 8f0c4f1cfcf..16da52aaacc 100644 --- a/scripts/token_checker.py +++ b/scripts/token_checker.py @@ -32,7 +32,8 @@ def __init__(self): "zkevm": "eth-ethereum", "ronin": "ron-ronin-token", "cardano": "ada-cardano", - "tron": "trx-tron" + "tron": "trx-tron", + "boba": "eth-ethereum" } self.tokens_by_id = self.get_tokens() self.contracts_by_chain = self.get_contracts() diff --git a/sources/_base_sources/evm/boba_base_sources.yml b/sources/_base_sources/evm/boba_base_sources.yml new file mode 100644 index 00000000000..4d9ab561dd0 --- /dev/null +++ b/sources/_base_sources/evm/boba_base_sources.yml @@ -0,0 +1,335 @@ +version: 2 + +sources: + # Boba Tables + - name: boba + description: "raw tables for the chain" + + tables: + - name: transactions + meta: + docs_slug: /evm/boba/raw/transactions + short_description: The transactions table contains detailed information about transactions on the network. + description: '{{ doc("boba_transactions_doc") }}' + + columns: + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: value + description: "Amount of ETH sent from sender to recipient (if any), measured in wei (1 ETH = 10^18 wei)" + - name: gas_limit + description: "Maximum number of gas units this transaction can consume" + - name: gas_price + description: "Price per unit of gas for this transaction, denominated in wei (1 gwei = 10^9 wei)" + - name: gas_used + description: "Actual amount of gas units consumed by this transaction's execution" + - name: max_fee_per_gas + description: "Maximum total amount per gas unit the initiator is willing to pay, including boba fee and priority fee" + - name: max_priority_fee_per_gas + description: "Maximum additional fee per gas unit the initiator is willing to pay as a tip to validators" + - name: priority_fee_per_gas + description: "Actual priority fee per gas paid to validators" + - name: nonce + description: "Sequential number representing the count of transactions sent from the sender's address" + - name: index + description: "Position of this transaction within its containing block" + - name: success + description: "Boolean flag indicating whether the transaction executed successfully (true) or failed (false)" + - name: from + description: "Address of the account that initiated and signed this transaction" + - name: to + description: "Address of the recipient account or contract for this transaction" + - name: block_hash + description: "Unique 256-bit identifier (hash) of the block containing this transaction" + - name: data + description: "Input data for the transaction, which may include function calls or contract interaction data" + - name: hash + description: "Unique 256-bit identifier (hash) of this specific transaction" + - name: type + description: "Type of transaction (e.g., legacy, EIP-1559) indicating its structure and fee mechanism" + - name: access_list + description: "List of addresses and storage keys the transaction plans to access, used for gas optimization in EIP-2930 transactions" + - name: chain_id + description: "Chain identifier for the network" + - name: block_date + description: "The UTC date of the block in which this transaction was included" + - name: l1_gas_used + description: "The gas used on Ethereum L1 to publish this L2 transaction" + - name: l1_gas_price + description: "Gas price on the L1 at the time of L2 transaction submission" + - name: l1_fee + description: "L1 Fees that the network pays to submit L2 transactions to Ethereum L1" + - name: l1_fee_scalar + description: "Scalar value used to calculate L1 fee, covering potential changes in L1 gas price and network costs" + - name: l1_block_number + description: "Block number on the L1 where this L2 transaction was batch submitted" + - name: l1_timestamp + description: "The timestamp when the L2 transaction was batched and confirmed on the L1" + - name: l1_tx_origin + description: "L1 transaction origin address for L2 transactions that were initiated on L1" + + - name: traces + meta: + docs_slug: /evm/boba/raw/traces + short_description: The traces table contains information about traces on the network. + description: '{{ doc("boba_traces_doc") }}' + columns: + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: value + description: "Amount of ETH sent from sender to recipient (if any), measured in wei (1 ETH = 10^18 wei)" + - name: gas + description: "Amount of gas allocated for this trace's execution (including gas used by child traces)" + - name: gas_used + description: "Actual amount of gas consumed by this trace's execution" + - name: block_hash + description: "Unique 256-bit identifier (hash) of the block containing this transaction" + - name: success + description: "Boolean flag indicating whether this specific trace was executed successfully (true) or reverted (false)" + - name: tx_index + description: "Position of the parent transaction within its containing block" + - name: tx_from + description: "Address that initiated the parent transaction" + - name: tx_to + description: "Recipient address of the parent transaction" + - name: sub_traces + description: "Number of child traces spawned by this trace during execution" + - name: error + description: "Error message or code if the trace execution failed" + - name: tx_success + description: "Boolean flag indicating whether the parent transaction of this trace was successful" + - name: tx_hash + description: "Unique 256-bit identifier (hash) of the parent transaction" + - name: from + description: "Address that sent this trace" + - name: to + description: "Address that received this trace" + - name: trace_address + description: "Array indicating the exact position of this trace within the trace tree of the transaction" + - name: type + description: "Type of trace (e.g., call, create, suicide) indicating the nature of the operation" + - name: address + description: "If this trace is a contract creation, this is the address of the deployed contract" + - name: code + description: "If this trace is a contract creation, this is the deployed bytecode of contract" + - name: call_type + description: "Type of call made in this trace (e.g., call, delegatecall, staticcall)" + - name: input + description: "Call data provided to this trace, often containing function signatures and parameters" + - name: output + description: "Data returned by this trace after execution" + - name: refund_address + description: "Address designated to receive any gas refund from this trace" + - name: revert_reason + description: "Reason for reversion if the trace was reverted" + - name: block_date + description: "The UTC date of the block in which this transaction was included" + + - name: traces_decoded + meta: + docs_slug: /evm/boba/decoded/traces_decoded + short_description: The `boba.traces_decoded` table contains decoded traces, including additional information based on submitted smart contracts and their ABIs. + description: '{{ doc("boba_traces_decoded_doc") }}' + columns: + - name: block_date + description: "The UTC date of the block in which this transaction was included" + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: namespace + description: "Categorical grouping or project name associated with the contract" + - name: contract_name + description: "Human-readable name of the smart contract involved in this trace" + - name: to + description: "Address of the contract or account receiving this trace" + - name: trace_address + description: "Array indicating the exact position of this trace within the trace tree of the transaction" + - name: tx_hash + description: "Unique 256-bit identifier (hash) of the parent transaction" + - name: tx_from + description: "Address that initiated the parent transaction" + - name: tx_to + description: "Recipient address of the parent transaction" + - name: signature + description: "Function signature hash" + - name: function_name + description: "Name of the specific contract function called in this trace" + + - name: logs + meta: + docs_slug: /evm/boba/raw/logs + short_description: The `boba.logs` table contains information about event logs emitted by smart contracts on the boba blockchain. + description: '{{ doc("boba_logs_doc") }}' + columns: + - name: block_date + description: "The UTC date of the block in which this transaction was included" + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: block_hash + description: "Unique 256-bit identifier (hash) of the block containing this transaction" + - name: tx_index + description: "Position of the parent transaction within its containing block" + - name: tx_hash + description: "Unique 256-bit identifier (hash) of the parent transaction" + - name: contract_address + description: "Address of the smart contract that emitted this log" + - name: topic0 + description: "First 32-byte topic, typically containing the event signature hash" + - name: topic1 + description: "Second 32-byte topic, often containing indexed event parameters" + - name: topic2 + description: "Third 32-byte topic, often containing indexed event parameters" + - name: topic3 + description: "Fourth 32-byte topic, often containing indexed event parameters" + - name: data + description: "ABI-encoded data of the log, containing non-indexed event parameters" + - name: index + description: "Position of this log within the block" + - name: tx_from + description: "Address that initiated the transaction which created this log" + - name: tx_to + description: "Recipient address of the transaction which created this log" + + - name: logs_decoded + meta: + docs_slug: /evm/boba/decoded/logs_decoded + short_description: The `boba.logs_decoded` table contains a subset of all logs for which Dune has the ABI. + description: '{{ doc("boba_logs_decoded_doc") }}' + columns: + - name: block_date + description: "The UTC date of the block in which this transaction was included" + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: namespace + description: "Categorical grouping or project name associated with the contract" + - name: contract_name + description: "Human-readable name of the smart contract" + - name: contract_address + description: "Address of the smart contract that emitted this log" + - name: tx_hash + description: "Unique 256-bit identifier (hash) of the parent transaction" + - name: tx_from + description: "Address that initiated the transaction which created this log" + - name: tx_to + description: "Recipient address of the transaction which created this log" + - name: index + description: "Position of this log within the block" + - name: signature + description: "Event signature hash" + - name: event_name + description: "Human-readable name of the event" + + - name: contracts + meta: + docs_slug: /evm/boba/raw/contracts + short_description: The `boba.contracts` table tracks decoded contracts on boba, including associated metadata such as namespace, name, address, ABI. It is populated manually by the Dune Community via [contract decoding submissions](https://dune.com/contracts/new). + description: '{{ doc("boba_contracts_doc") }}' + columns: + - name: address + description: "Unique address of the contract on the blockchain" + - name: bytecode + description: "Compiled bytecode of the contract" + - name: name + description: "Human-readable name of the contract" + - name: namespace + description: "Project or protocol name associated with the contract" + - name: abi + description: "JSON representation of the contract's Application Binary Interface" + - name: created_at + description: "Timestamp when this contract entry was created in the table" + + - name: contracts_submitted + meta: + docs_slug: /evm/boba/decoded/contracts_submitted + short_description: The `boba.contracts_submitted` table contains information about contracts submitted for decoding. + description: '{{ doc("boba_contracts_submitted_doc") }}' + columns: + - name: address + description: "Address of the submitted contract" + - name: namespace + description: "Project or protocol name associated with the contract" + - name: name + description: "Name of the submitted contract" + - name: submitted_at + description: "Timestamp when the contract was submitted for decoding" + - name: submitted_by + description: "Address or identifier of the user who submitted the contract" + + - name: creation_traces + meta: + docs_slug: /evm/boba/raw/creation_traces + short_description: The `boba.creation_traces` table contains information about contract creation traces. + description: '{{ doc("boba_creation_traces_doc") }}' + columns: + - name: block_date + description: "The UTC date of the block in which this transaction was included" + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: tx_hash + description: "Unique 256-bit identifier (hash) of the parent transaction" + - name: address + description: "Address of the created contract" + - name: from + description: "Address that created the contract" + - name: code + description: "Contract bytecode" + - name: success + description: "Whether the contract creation was successful" + - name: block_month + description: "The month of the block date" + + - name: blocks + meta: + docs_slug: /evm/boba/raw/blocks + short_description: The `boba.blocks` table contains information about blocks on the boba blockchain. + description: '{{ doc("boba_blocks_doc") }}' + columns: + - name: block_date + description: "The UTC date of the block in which this transaction was included" + - name: block_time + description: "The exact UTC timestamp when the block containing this transaction was added to the chain" + - name: block_number + description: "The sequential number of the block containing this transaction" + - name: block_hash + description: "Unique 256-bit identifier (hash) of the block containing this transaction" + - name: parent_hash + description: "Hash of the parent block" + - name: nonce + description: "Block nonce value" + - name: difficulty + description: "Block mining difficulty" + - name: gas_limit + description: "Maximum gas allowed in this block" + - name: gas_used + description: "Total gas used by all transactions in this block" + - name: miner + description: "Address of the miner/validator who produced this block" + - name: size + description: "Size of the block in bytes" + - name: total_difficulty + description: "Total chain difficulty up to this block" + - name: base_fee_per_gas + description: "Base fee per gas in this block (EIP-1559)" + - name: state_root + description: "Root hash of the state trie after this block" + - name: transactions_root + description: "Root hash of the transactions trie of this block" + - name: receipts_root + description: "Root hash of the receipts trie of this block" + - name: blob_gas_used + description: "Total blob gas used in this block" + - name: excess_blob_gas + description: "Excess blob gas in this block" + - name: parent_beacon_block_root + description: "Root hash of the parent beacon block" diff --git a/sources/_base_sources/evm/boba_docs_block.md b/sources/_base_sources/evm/boba_docs_block.md new file mode 100644 index 00000000000..90a77a0192c --- /dev/null +++ b/sources/_base_sources/evm/boba_docs_block.md @@ -0,0 +1,162 @@ +{% docs boba_transactions_doc %} + +The `boba.transactions` table contains detailed information about transactions on the Boba blockchain. It includes: + +- Block information: number, timestamp, hash +- Transaction details: hash, from_address, to_address, value +- Gas data: gas_price, gas_limit, gas_used, max_fee_per_gas, priority_fee_per_gas +- L1 data: l1_gas_used, l1_gas_price, l1_fee, l1_block_number, l1_timestamp +- Status: success or failure +- Input data for contract interactions +- Nonce and chain_id +- Transaction type and access list + +This table is used for analyzing transaction patterns, gas usage, value transfers, L1-L2 interactions, and overall network activity on Boba. + +{% enddocs %} + +{% docs boba_traces_doc %} + +The `boba.traces` table contains records of execution steps for transactions on the Boba blockchain. Each trace represents an atomic operation that modifies the state of the Ethereum Virtual Machine (EVM). Key components include: + +- Transaction hash and block information +- From and to addresses +- Value transferred +- Gas metrics (gas, gas_used) +- Input and output data +- Call type (e.g., CALL, DELEGATECALL, CREATE) +- Error information and revert reasons +- Trace address for nested calls +- L1-L2 specific information + +This table is essential for: +- Analyzing internal transactions +- Debugging smart contract interactions +- Tracking value flows through complex transactions +- Understanding contract creation and deployment +- Monitoring L1-L2 message passing + +{% enddocs %} + +{% docs boba_traces_decoded_doc %} + +The `boba.traces_decoded` table contains a subset of decoded traces from the Boba blockchain dependent on submitted smart contracts and their ABIs. It includes: + +- Block information and transaction details +- Contract name and namespace +- Decoded function names and signatures +- Trace address for execution path tracking +- Transaction origin and destination +- Function parameters (when available) + +This table is used for high level analysis of smart contract interactions. For fully decoded function calls and parameters, refer to protocol-specific decoded tables. + +{% enddocs %} + +{% docs boba_logs_doc %} + +The `boba.logs` table contains event logs emitted by smart contracts on the Boba blockchain. It includes: + +- Block information: number, timestamp, hash +- Transaction details: hash, index, from, to +- Contract address (emitting the event) +- Topic0 (event signature) +- Additional topics (indexed parameters) +- Data field (non-indexed parameters) +- Log index and transaction index + +This table is crucial for: +- Tracking on-chain events +- Monitoring contract activity +- Analyzing token transfers +- Following protocol-specific events +- Understanding L1-L2 interactions + +{% enddocs %} + +{% docs boba_logs_decoded_doc %} + +The `boba.logs_decoded` table contains a subset of decoded logs from the Boba blockchain dependent on submitted smart contracts and their ABIs. It includes: + +- Block and transaction information +- Contract details (name, namespace, address) +- Decoded event names and signatures +- Transaction origin and destination +- Event parameters (when available) + +This table is used for high level analysis of smart contract events. For fully decoded events and parameters, refer to protocol-specific decoded tables. + +{% enddocs %} + +{% docs boba_blocks_doc %} + +The `boba.blocks` table contains information about Boba blocks. It provides essential data about each block in the Boba blockchain, including: + +- Block identifiers and timestamps +- Gas metrics and size +- Consensus information (difficulty, nonce) +- State roots and receipts +- L2-specific block data +- Parent block information + +This table is fundamental for analyzing: +- Blockchain structure and growth +- Block production rates +- Network performance +- L1-L2 block relationships +- Chain reorganizations + +{% enddocs %} + +{% docs boba_contracts_doc %} + +The `boba.contracts` table tracks decoded contracts on Boba, including: + +- Contract address and bytecode +- Contract name and namespace +- Complete ABI +- Creation timestamp +- Verification status + +This table is used for: +- Contract verification and analysis +- Protocol research and monitoring +- Development and debugging +- Smart contract security analysis + +{% enddocs %} + +{% docs boba_contracts_submitted_doc %} + +The `boba.contracts_submitted` table tracks contracts submitted for decoding on Boba. It includes: + +- Contract address +- Submission metadata (timestamp, submitter) +- Contract name and namespace +- Verification status + +This table helps track the progress of contract verification and community contributions to the Boba ecosystem. + +{% enddocs %} + +{% docs boba_creation_traces_doc %} + +The `boba.creation_traces` table contains data about contract creation events on the Boba blockchain. It includes: + +- Block information and timestamps +- Transaction details +- Creator's address +- Created contract address +- Deployed contract bytecode +- Creation success status +- Gas consumption + +This table is used for: +- Analyzing contract deployment patterns +- Tracking smart contract origins +- Monitoring protocol deployments +- Understanding contract creation costs + +It's essentially a filtered version of the `boba.traces` table where `type = create`. + +{% enddocs %} From a84e28a3200a63e85934af92dc70e4a057152120 Mon Sep 17 00:00:00 2001 From: max-morrow Date: Tue, 3 Dec 2024 21:35:59 +0300 Subject: [PATCH 53/68] 1inch-U51: fixes to project.* lineage (#7184) * fixes to project.* lineage * fixes & improvements & easy dates - updated a mode definition - updated a project definition - added partitions by projects * revert easy dates * expose zksync * easy dates * Revert "easy dates" This reverts commit b60169afb71dff7b5986468b2261fe8edfe1831d. --------- Co-authored-by: grkhr --- ...project_swaps_exposed_blockchains_list.sql | 3 +- ...einch_project_orders_cfg_methods_macro.sql | 14 +++--- .../project/oneinch_project_swaps_macro.sql | 43 +++++++++++++++---- .../oneinch_arbitrum_project_swaps.sql | 2 +- .../oneinch_avalanche_c_project_swaps.sql | 2 +- .../project/oneinch_base_project_swaps.sql | 2 +- .../bnb/project/oneinch_bnb_project_swaps.sql | 2 +- .../oneinch_ethereum_project_swaps.sql | 2 +- .../project/oneinch_fantom_project_swaps.sql | 2 +- .../project/oneinch_gnosis_project_swaps.sql | 2 +- .../oneinch_optimism_project_swaps.sql | 2 +- .../project/oneinch_polygon_project_swaps.sql | 2 +- .../project/oneinch_zksync_project_swaps.sql | 2 +- 13 files changed, 53 insertions(+), 27 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/macros/project/oneinch/_meta/oneinch_project_swaps_exposed_blockchains_list.sql b/dbt_subprojects/daily_spellbook/macros/project/oneinch/_meta/oneinch_project_swaps_exposed_blockchains_list.sql index 7f0d322d55d..3d305d8d719 100644 --- a/dbt_subprojects/daily_spellbook/macros/project/oneinch/_meta/oneinch_project_swaps_exposed_blockchains_list.sql +++ b/dbt_subprojects/daily_spellbook/macros/project/oneinch/_meta/oneinch_project_swaps_exposed_blockchains_list.sql @@ -8,6 +8,7 @@ 'bnb', 'gnosis', 'fantom', - 'base', + 'base', + 'zksync', ]) }} {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/cfg/oneinch_project_orders_cfg_methods_macro.sql b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/cfg/oneinch_project_orders_cfg_methods_macro.sql index 9afcded3291..47938970284 100644 --- a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/cfg/oneinch_project_orders_cfg_methods_macro.sql +++ b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/cfg/oneinch_project_orders_cfg_methods_macro.sql @@ -475,7 +475,7 @@ {% set _taker_data = "4 + 32*4 + bytearray_to_bigint(substr(input, 4 + 32*13 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _taker_data ~ " + 32*1 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x3f62192e", "tag": "'UniswapXV1'", "name": "execute", @@ -501,7 +501,7 @@ {% set _taker_data = "4 + 32*5 + bytearray_to_bigint(substr(input, 4 + 32*14 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _taker_data ~ " + 32*1 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x0d335884", "tag": "'UniswapXV1'", "name": "executeWithCallback", @@ -528,7 +528,7 @@ {% set _taker_data = "bytearray_to_bigint(substr(input, " ~ _order_beginning ~ " + 32*12 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _order_beginning ~ " + " ~ _taker_data ~ " + 32*4 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x0d7a16c3", "tag": "'UniswapXV1'", "name": "executeBatch", @@ -557,7 +557,7 @@ {% set _taker_data = "bytearray_to_bigint(substr(input, " ~ _order_beginning ~ " + 32*12 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _order_beginning ~ " + " ~ _taker_data ~ " + 32*4 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x13fb72c7", "tag": "'UniswapXV1'", "name": "executeBatchWithCallback", @@ -584,7 +584,7 @@ {% set _taker_data = "4 + 32*1 + bytearray_to_bigint(substr(input, 4 + 32*10 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _taker_data ~ " + 32*4 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x3f62192e", "tag": "'UniswapXV2'", "name": "execute", @@ -610,7 +610,7 @@ {% set _taker_data = "4 + 32*2 + bytearray_to_bigint(substr(input, 4 + 32*11 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _taker_data ~ " + 32*4 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x0d335884", "tag": "'UniswapXV2'", "name": "executeWithCallback", @@ -638,7 +638,7 @@ {% set _taker_data = "bytearray_to_bigint(substr(input, " ~ _order_beginning ~ " + 32*9 + 24 + 1, 8))" %} {% set _recipients = "bytearray_to_bigint(substr(input, " ~ _order_beginning ~ " + " ~ _taker_data ~ " + 32*4 + 24 + 1, 8))" %} {% set methods = methods + [{ - "project": "Uniswap", + "project": "UniswapX", "selector": "0x13fb72c7", "tag": "'UniswapXV2'", "name": "executeBatchWithCallback", diff --git a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_swaps_macro.sql b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_swaps_macro.sql index b361c3c31f5..85e26190556 100644 --- a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_swaps_macro.sql +++ b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_swaps_macro.sql @@ -27,7 +27,7 @@ meta as ( block_number , tx_hash , call_trace_address - , project + , project as order_project , order_hash , maker , taker @@ -51,7 +51,7 @@ meta as ( block_number , tx_hash , call_trace_address - , '1inch' as project + , '1inch' as order_project , coalesce(order_hash, concat(tx_hash, to_big_endian_32(cast(counter as int)))) as order_hash , maker , receiver as taker @@ -81,7 +81,7 @@ meta as ( , tx_from , tx_to , call_trace_address - , project + , coalesce(order_project, project) as project , tag , flags , call_selector @@ -116,7 +116,7 @@ meta as ( and call_success and (flags['cross_chain'] or not flags['cross_chain_method']) -- without cross-chain methods calls in non cross-chain protocols ) - left join orders using(block_number, tx_hash, call_trace_address, project) + left join orders using(block_number, tx_hash, call_trace_address) join meta on true where reduce(call_trace_addresses, true, (r, x) -> if(r and x <> call_trace_address and slice(call_trace_address, 1, cardinality(x)) = x, false, r), r -> r) -- only not nested calls of the project in tx @@ -314,11 +314,36 @@ meta as ( select * , map_from_entries(array[ - ('classic: direct', flags['direct'] and order_hash is null and not auction and not cross_chain_swap or second_side) - , ('classic: external', not flags['direct'] and order_hash is null and not auction and not cross_chain_swap) - , ('intent: intra-chain auction', auction and not cross_chain_swap) - , ('intent: intra-chain user limit order', order_hash is not null and not auction and not cross_chain_swap and not contracts_only) - , ('intent: intra-chain contracts only', contracts_only) + ('intra-chain: classic: direct', + flags['direct'] + and order_hash is null + and not auction + and not cross_chain_swap + and not contracts_only + or second_side + ) + , ('intra-chain: classic: external', + not flags['direct'] + and order_hash is null + and not auction + and not contracts_only + and not cross_chain_swap + ) + , ('intra-chain: intents: auction', + auction + and not cross_chain_swap + ) + , ('intra-chain: intents: user limit order', + order_hash is not null + and not auction + and not cross_chain_swap + and not contracts_only + and not second_side + ) + , ('intra-chain: intents: contracts only', + contracts_only + and not second_side + ) , ('cross-chain', cross_chain_swap) ]) as modes from ( diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/arbitrum/project/oneinch_arbitrum_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/arbitrum/project/oneinch_arbitrum_project_swaps.sql index 2eb1fe7a88b..5f77999fd1c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/arbitrum/project/oneinch_arbitrum_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/arbitrum/project/oneinch_arbitrum_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/avalanche_c/project/oneinch_avalanche_c_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/avalanche_c/project/oneinch_avalanche_c_project_swaps.sql index 2907e88ba5d..093d2639f73 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/avalanche_c/project/oneinch_avalanche_c_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/avalanche_c/project/oneinch_avalanche_c_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/base/project/oneinch_base_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/base/project/oneinch_base_project_swaps.sql index e954d34e994..03801b0e475 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/base/project/oneinch_base_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/base/project/oneinch_base_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/bnb/project/oneinch_bnb_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/bnb/project/oneinch_bnb_project_swaps.sql index cc7fb07f019..f82ebf6751b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/bnb/project/oneinch_bnb_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/bnb/project/oneinch_bnb_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/ethereum/project/oneinch_ethereum_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/ethereum/project/oneinch_ethereum_project_swaps.sql index 9d47240179a..a4c2e198af3 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/ethereum/project/oneinch_ethereum_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/ethereum/project/oneinch_ethereum_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/fantom/project/oneinch_fantom_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/fantom/project/oneinch_fantom_project_swaps.sql index 0b1cd0356cc..3829f2abadd 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/fantom/project/oneinch_fantom_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/fantom/project/oneinch_fantom_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/gnosis/project/oneinch_gnosis_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/gnosis/project/oneinch_gnosis_project_swaps.sql index 09149d17b28..7989d8ab3f4 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/gnosis/project/oneinch_gnosis_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/gnosis/project/oneinch_gnosis_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/optimism/project/oneinch_optimism_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/optimism/project/oneinch_optimism_project_swaps.sql index b1d1415c487..11824e6478e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/optimism/project/oneinch_optimism_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/optimism/project/oneinch_optimism_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/polygon/project/oneinch_polygon_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/polygon/project/oneinch_polygon_project_swaps.sql index fdb95800436..8af9dd17c97 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/polygon/project/oneinch_polygon_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/polygon/project/oneinch_polygon_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/zksync/project/oneinch_zksync_project_swaps.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/zksync/project/oneinch_zksync_project_swaps.sql index a365adc4658..34df6a770ba 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/zksync/project/oneinch_zksync_project_swaps.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/zksync/project/oneinch_zksync_project_swaps.sql @@ -6,7 +6,7 @@ config( schema = 'oneinch_' + blockchain, alias = 'project_swaps', - partition_by = ['block_month'], + partition_by = ['block_month', 'project'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', From 71e038c81ef975e5c34087aac7c4a08be27142a2 Mon Sep 17 00:00:00 2001 From: whale_hunter <143016036+whalehunting@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:36:21 +0100 Subject: [PATCH 54/68] chore: add new chainswap deployer to spellbook (#6909) * chore: add new chainswap deployer to spellbook * chore: add new deployer on ethereum * fix: aggreagte fee deposits by tx * fix: aggregate fee deposits by tx for all chains * chore: add new deployer to all chains * test: change uniqueness test to also include multi-fee trades * fix: also handle USDT fees * fix: handle usdt payments * fix: fallback to native wrapped token if no fee is detected --- .../arbitrum/chain_swap_arbitrum_trades.sql | 15 ++++++++++----- .../chain_swap_avalanche_c_trades.sql | 14 ++++++++++---- .../chainswap/base/chain_swap_base_trades.sql | 14 ++++++++++---- .../chainswap/bnb/chain_swap_bnb_trades.sql | 13 ++++++++++--- .../models/chainswap/chain_swap_schema.yml | 9 ++++++++- .../ethereum/chain_swap_ethereum_trades.sql | 18 ++++++++++++++---- .../optimism/chain_swap_optimism_trades.sql | 13 ++++++++++--- .../polygon/chain_swap_polygon_trades.sql | 17 ++++++++++++----- 8 files changed, 84 insertions(+), 29 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql index c83e6121cf0..99e946ced3c 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate('DBT_INTERNAL_DEST.block_time') ], - unique_key=['blockchain', 'tx_hash', 'evt_index'], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -22,6 +22,7 @@ {% set deployer_5 = '0xb7b953e81612c57256ff0aebd62b6a2f0546f7da' %} {% set deployer_6 = '0xb252f0ab7bdf1be4d5bbf607eb5c220b2d902a2c' %} {% set deployer_7 = '0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94' %} +{% set deployer_8 = '0xc8378819fbB95130c34D62f520167F745B13C305' %} {% set weth_contract_address = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1' %} {% set usdc_contract_address = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' %} {% set fee_recipient_1 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} @@ -40,6 +41,7 @@ with or "from" = {{ deployer_5 }} or "from" = {{ deployer_6 }} or "from" = {{ deployer_7 }} + or "from" = {{ deployer_8 }} ) and block_time >= timestamp '{{project_start_date}}' ), @@ -102,7 +104,11 @@ with (to = {{ fee_recipient_1 }} or to = {{ fee_recipient_2 }}) and block_time >= timestamp '{{project_start_date}}' and value > 0 - + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) select distinct block_time, @@ -122,7 +128,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + coalesce(fee_token_address, {{weth_contract_address}}) as fee_token_address, -- Dex project, version, @@ -137,8 +143,7 @@ from bot_trades join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash -/* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source('prices', 'usd') }} on ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql index d66064471be..6a0e0795213 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate('DBT_INTERNAL_DEST.block_time') ], - unique_key=['blockchain', 'tx_hash', 'evt_index'], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -19,6 +19,7 @@ {% set deployer_2 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} {% set deployer_3 = '0xc1cc1a300Dcfe5359eBe37f2007A77d1F91533ba' %} {% set deployer_4 = '0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94' %} +{% set deployer_5 = '0xc8378819fbB95130c34D62f520167F745B13C305' %} {% set wavax_contract_address = '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7' %} {% set usdc_contract_address = '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E' %} {% set fee_recipient_1 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} @@ -34,6 +35,7 @@ with or "from" = {{ deployer_2 }} or "from" = {{ deployer_3 }} or "from" = {{ deployer_4 }} + or "from" = {{ deployer_5 }} ) and block_time >= timestamp '{{project_start_date}}' ), @@ -104,6 +106,11 @@ with {% else %} and block_time >= timestamp '{{project_start_date}}' {% endif %} + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) select distinct block_time, @@ -123,7 +130,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + cast(coalesce(fee_token_address, {{wavax_contract_address}}) as varchar) as fee_token_address, -- Dex project, version, @@ -138,8 +145,7 @@ from bot_trades join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash -/* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source('prices', 'usd') }} on ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql index 32ba14c0fb4..5e021ef8056 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate('DBT_INTERNAL_DEST.block_time') ], - unique_key=['blockchain', 'tx_hash', 'evt_index'], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -21,6 +21,7 @@ {% set deployer_4 = '0x3A510C5a32bCb381c53704AED9c02b0c70041F7A' %} {% set deployer_5 = '0xb252f0ab7bdf1be4d5bbf607eb5c220b2d902a2c' %} {% set deployer_6 = '0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94' %} +{% set deployer_7 = "0xc8378819fbB95130c34D62f520167F745B13C305" %} {% set weth_contract_address = '0x4200000000000000000000000000000000000006' %} {% set usdc_contract_address = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' %} {% set fee_recipient_1 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} @@ -38,6 +39,7 @@ with or "from" = {{ deployer_4 }} or "from" = {{ deployer_5 }} or "from" = {{ deployer_6 }} + or "from" = {{ deployer_7 }} ) and block_time >= timestamp '{{project_start_date}}' ), @@ -108,6 +110,11 @@ with {% else %} and block_time >= timestamp '{{project_start_date}}' {% endif %} + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) select distinct block_time, @@ -127,7 +134,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + coalesce(fee_token_address, {{weth_contract_address}}) as fee_token_address, -- Dex project, version, @@ -142,8 +149,7 @@ from bot_trades join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash -/* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source('prices', 'usd') }} on ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql index ab069893eaf..c0a18a2e654 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate('DBT_INTERNAL_DEST.block_time') ], - unique_key=['blockchain', 'tx_hash', 'evt_index'], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -18,6 +18,7 @@ {% set deployer_1 = '0x1d32cFeFd97de9D740714A31b2E8C7bc34825442' %} {% set deployer_2 = '0x3A510C5a32bCb381c53704AED9c02b0c70041F7A' %} {% set deployer_3 = '0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94' %} +{% set deployer_4 = '0xc8378819fbB95130c34D62f520167F745B13C305' %} {% set wbnb_contract_address = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' %} {% set usdc_contract_address = '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d' %} {% set fee_recipient_1 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} @@ -32,6 +33,7 @@ with "from" = {{ deployer_1 }} or "from" = {{ deployer_2 }} or "from" = {{ deployer_3 }} + or "from" = {{ deployer_4 }} ) and block_time >= timestamp '{{project_start_date}}' @@ -103,6 +105,11 @@ with {% else %} and block_time >= timestamp '{{project_start_date}}' {% endif %} + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) select distinct block_time, @@ -122,7 +129,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + coalesce(fee_token_address, {{wbnb_contract_address}}) as fee_token_address, -- Dex project, version, @@ -138,7 +145,7 @@ join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash /* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source('prices', 'usd') }} on ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/chain_swap_schema.yml b/dbt_subprojects/daily_spellbook/models/chainswap/chain_swap_schema.yml index fc91c877fab..5dfa1b400d0 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/chain_swap_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/chainswap/chain_swap_schema.yml @@ -100,6 +100,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain - *block_time @@ -142,6 +143,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain - *block_time @@ -184,6 +186,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain - *block_time @@ -226,6 +229,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain - *block_time @@ -268,6 +272,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain - *block_time @@ -310,6 +315,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain - *block_time @@ -352,6 +358,7 @@ models: - blockchain - tx_hash - evt_index + - fee_token_address columns: - *blockchain @@ -377,4 +384,4 @@ models: - *user - *tx_hash - *evt_index - - *is_last_trade_in_transaction \ No newline at end of file + - *is_last_trade_in_transaction diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/ethereum/chain_swap_ethereum_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/ethereum/chain_swap_ethereum_trades.sql index 073195a8c12..8a7689ce356 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/ethereum/chain_swap_ethereum_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/ethereum/chain_swap_ethereum_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate("DBT_INTERNAL_DEST.block_time") ], - unique_key=["blockchain", "tx_hash", "evt_index"], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -20,8 +20,11 @@ {% set deployer_3 = "0xc1cc1a300Dcfe5359eBe37f2007A77d1F91533ba" %} {% set deployer_4 = "0x3A510C5a32bCb381c53704AED9c02b0c70041F7A" %} {% set deployer_5 = "0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94" %} +{% set deployer_6 = "0x686c0072dF3Df7A13ef666a3b661803a48558A90" %} +{% set deployer_7 = "0xc8378819fbB95130c34D62f520167F745B13C305" %} {% set weth_contract_address = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" %} {% set usdc_contract_address = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" %} +{% set usdt_contract_address = "0xdac17f958d2ee523a2206206994597c13d831ec7" %} {% set fee_recipient_1 = "0x415EEc63c95e944D544b3088bc682B759edB8548" %} {% set fee_recipient_2 = "0xe1ff5a4c489b11e094bfbb5d23c6d4597a3a79ad" %} @@ -36,6 +39,8 @@ with or "from" = {{ deployer_3 }} or "from" = {{ deployer_4 }} or "from" = {{ deployer_5 }} + or "from" = {{ deployer_6 }} + or "from" = {{ deployer_7 }} ) and block_time >= timestamp '{{project_start_date}}' ), @@ -86,6 +91,7 @@ with and ( contract_address = {{ weth_contract_address }} or contract_address = {{ usdc_contract_address }} + or contract_address = {{ usdt_contract_address }} ) {% if is_incremental() %} and {{ incremental_predicate('evt_block_time') }} @@ -106,6 +112,11 @@ with {% else %} and block_time >= timestamp '{{project_start_date}}' {% endif %} + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) select distinct block_time, @@ -125,7 +136,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + coalesce(fee_token_address, {{weth_contract_address}}) as fee_token_address, -- Dex project, version, @@ -140,8 +151,7 @@ from bot_trades join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash -/* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source("prices", "usd") }} on ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql index db7bb3f0001..08677164306 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate('DBT_INTERNAL_DEST.block_time') ], - unique_key=['blockchain', 'tx_hash', 'evt_index'], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -22,6 +22,7 @@ {% set deployer_5 = '0x9eC1ACAe39d07E1e8D8B3cEbe7022790D87D744A' %} {% set deployer_6 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} {% set deployer_7 = '0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94' %} +{% set deployer_8 = '0xc8378819fbB95130c34D62f520167F745B13C305' %} {% set weth_contract_address = '0x4200000000000000000000000000000000000006' %} {% set usdc_contract_address = '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' %} {% set fee_recipient_1 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} @@ -40,6 +41,7 @@ with or "from" = {{ deployer_5 }} or "from" = {{ deployer_6 }} or "from" = {{ deployer_7 }} + or "from" = {{ deployer_8 }} ) and block_time >= timestamp '{{project_start_date}}' ), @@ -110,6 +112,11 @@ with {% else %} and block_time >= timestamp '{{project_start_date}}' {% endif %} + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) select distinct block_time, @@ -129,7 +136,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + coalesce(fee_token_address, {{weth_contract_address}}) as fee_token_address, -- Dex project, version, @@ -145,7 +152,7 @@ join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash /* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source('prices', 'usd') }} on ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql index 01556b7a6bf..f0a9fdbf3b3 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql @@ -9,7 +9,7 @@ incremental_predicates=[ incremental_predicate('DBT_INTERNAL_DEST.block_time') ], - unique_key=['blockchain', 'tx_hash', 'evt_index'], + unique_key=['blockchain', 'tx_hash', 'evt_index', 'fee_token_address'], ) }} @@ -21,8 +21,10 @@ {% set deployer_4 = '0x3A510C5a32bCb381c53704AED9c02b0c70041F7A' %} {% set deployer_5 = '0xB7B953e81612c57256fF0aebD62B6a2F0546F7dA' %} {% set deployer_6 = '0xa24e8cE77D4A7Ce869DA3730e6560BfB66553F94' %} +{% set deployer_7 = "0xc8378819fbB95130c34D62f520167F745B13C305" %} {% set wmatic_contract_address = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270' %} {% set usdc_contract_address = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359' %} +{% set usdt_contract_address = '0xc2132d05d31c914a87c6611c10748aeb04b58e8f' %} {% set fee_recipient_1 = '0x415EEc63c95e944D544b3088bc682B759edB8548' %} {% set fee_recipient_2 = '0xe1ff5a4c489b11e094bfbb5d23c6d4597a3a79ad' %} @@ -38,6 +40,7 @@ with or "from" = {{ deployer_4 }} or "from" = {{ deployer_5 }} or "from" = {{ deployer_6 }} + or "from" = {{ deployer_7 }} ) and block_time >= timestamp '{{project_start_date}}' ), @@ -88,6 +91,7 @@ with and ( contract_address = {{ wmatic_contract_address }} or contract_address = {{ usdc_contract_address }} + or contract_address = {{ usdt_contract_address }} ) {% if is_incremental() %} and {{ incremental_predicate('evt_block_time') }} @@ -108,9 +112,12 @@ with {% else %} and block_time >= timestamp '{{project_start_date}}' {% endif %} + ), + aggregated_fee_deposits as ( + select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address + from fee_deposits + group by evt_tx_hash, fee_token_address ) - - select distinct block_time, date_trunc('day', block_time) as block_date, @@ -129,7 +136,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(fee_token_address as varchar) as fee_token_address, + coalesce(fee_token_address, {{wmatic_contract_address}}) as fee_token_address, -- Dex project, version, @@ -145,7 +152,7 @@ join highest_event_index_for_each_trade on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash /* Left Outer Join to support 0 fee trades */ -left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash +left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash left join {{ source('prices', 'usd') }} on ( From 44c052b9a3c412ed09a1f37213b78598be6ca8c7 Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:36:38 +0100 Subject: [PATCH 55/68] add Ronin to metrics (#7227) --- .../models/_metrics/fees/chains/evm/_schema.yml | 13 +++++++++++++ .../chains/evm/metrics_ronin_gas_fees_daily.sql | 15 +++++++++++++++ .../_metrics/fees/metrics_gas_fees_daily.sql | 1 + .../_metrics/transactions/chains/evm/_schema.yml | 13 +++++++++++++ .../evm/metrics_ronin_transactions_daily.sql | 15 +++++++++++++++ .../transactions/metrics_transactions_daily.sql | 1 + .../_metrics/transfers/chains/evm/_schema.yml | 13 +++++++++++++ .../chains/evm/metrics_ronin_transfers_daily.sql | 15 +++++++++++++++ .../transfers/metrics_transfers_daily.sql | 1 + 9 files changed, 87 insertions(+) create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ronin_gas_fees_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ronin_transactions_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ronin_transfers_daily.sql diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml index 58105e44cd9..90f3acd15d3 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/_schema.yml @@ -234,3 +234,16 @@ models: combination_of_columns: - blockchain - block_date + + - name: metrics_ronin_gas_fees_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'fees', 'gas', 'daily'] + description: "Sum of total fees spent per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ronin_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ronin_gas_fees_daily.sql new file mode 100644 index 00000000000..5e4da1dffdc --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/evm/metrics_ronin_gas_fees_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'ronin' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'gas_fees_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_fees_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql index 4d577b17c5f..4b661ed7545 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_gas_fees_daily.sql @@ -20,6 +20,7 @@ , 'mantle' , 'optimism' , 'polygon' + , 'ronin' , 'scroll' , 'sei' , 'solana' diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml index aa0e43b7912..3df2dbfcae7 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/_schema.yml @@ -247,3 +247,16 @@ models: combination_of_columns: - blockchain - block_date + + - name: metrics_ronin_transactions_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: ['metrics', 'transactions', 'daily'] + description: "Sum of total tx's per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ronin_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ronin_transactions_daily.sql new file mode 100644 index 00000000000..b85f21c8656 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/chains/evm/metrics_ronin_transactions_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'ronin' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transactions_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transactions_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql index 915451e5703..3357ab15032 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transactions/metrics_transactions_daily.sql @@ -20,6 +20,7 @@ , 'mantle' , 'optimism' , 'polygon' + , 'ronin' , 'scroll' , 'sei' , 'solana' diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml index c4b82af4cbd..0208f15cd8f 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/_schema.yml @@ -247,3 +247,16 @@ models: combination_of_columns: - blockchain - block_date + + - name: metrics_ronin_transfers_daily + meta: + sector: metrics + contributors: jeff-dude, 0xRob + config: + tags: [ 'metrics', 'transfers', 'daily' ] + description: "Total transfer amount per day" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - block_date diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ronin_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ronin_transfers_daily.sql new file mode 100644 index 00000000000..2276a133d6a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/chains/evm/metrics_ronin_transfers_daily.sql @@ -0,0 +1,15 @@ +{% set blockchain = 'ronin' %} + +{{ config( + schema = 'metrics_' + blockchain + , alias = 'transfers_daily' + , materialized = 'incremental' + , file_format = 'delta' + , incremental_strategy = 'merge' + , unique_key = ['blockchain', 'block_date'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] + ) +}} + + +{{ metrics_transfers_evm(blockchain) }} diff --git a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql index 108611d314f..b0982950cc5 100644 --- a/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql +++ b/dbt_subprojects/daily_spellbook/models/_metrics/transfers/metrics_transfers_daily.sql @@ -20,6 +20,7 @@ , 'mantle' , 'optimism' , 'polygon' + , 'ronin' , 'scroll' , 'sei' , 'solana' From 87290bd4bf026bd63c1d8fcd4a6f829a3cbf2930 Mon Sep 17 00:00:00 2001 From: hinus <64959125+cxheng315@users.noreply.github.com> Date: Wed, 4 Dec 2024 02:36:59 +0800 Subject: [PATCH 56/68] Fix multiple hyperlinks in README (#7205) Updated several hyperlinks in the README file to replace empty with correct ones. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e70873c945..3c6381fe0db 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ Welcome to [Spellbook](https://youtu.be/o7p0BNt7NHs). Cast a magical incantation - Are you building something new? **Please make sure to open a Draft PR**, so we minimize duplicated work, and other wizards can help you if you need - Don't know where to start? The docs below will guide you, but as a summary: - Want to make an incremental improvement to one of our spells? (add a new project, fix a bug you found), simply open a PR with your changes. - - Follow the guide for [Submitting a PR](), [Setting up your dev environment]() and [Using dbt to write spells]() if you find yourself lost. - - Not sure how to start? Follow the walkthrough [here](https://dune.com/docs/spellbook/). + - Follow the guide for [Submitting a PR](#submitting-a-pr), [Setting up your dev environment](#setting-up-your-local-dev-environment) and [Using dbt to write spells](#how-to-use-dbt-to-create-spells) if you find yourself lost. + - Not sure how to start? Follow the walkthrough [here](#introduction). - Make sure to open a draft PR if you will work on your spell for longer than a few days, to avoid duplicated work - - Do you want to get started building spells and you don't know what to build? Check [Issues]() to see what the community needs. + - Do you want to get started building spells and you don't know what to build? Check [Issues](https://github.com/duneanalytics/spellbook/issues) to see what the community needs. - Check the Discussions section to see what problems the community is trying to solve (i.e. non-incremental changes) or propose your own! - Have questions? Head over to #spellbook on our [discord](https://discord.com/channels/757637422384283659/999683200563564655) and the community will be happy to help out! - Like with most OSS projects, your contributions to Spellbook are your own IP, you can find more details in the [Contributor License Agreement](CLA.md) From a7023aef73363c38962b49cbcc2948bf5872c72a Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:18:54 -0500 Subject: [PATCH 57/68] remove cast to varchar (#7232) --- .../chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql index 6a0e0795213..b2a0547ac21 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql @@ -130,7 +130,7 @@ select distinct fee_token_amount / power(10, decimals) * price as fee_usd, fee_token_amount / power(10, decimals) as fee_token_amount, symbol as fee_token_symbol, - cast(coalesce(fee_token_address, {{wavax_contract_address}}) as varchar) as fee_token_address, + coalesce(fee_token_address, {{wavax_contract_address}}) as fee_token_address, -- Dex project, version, From 4fec73190cf8e87ad3e0f6f8a68d276fccefb0cd Mon Sep 17 00:00:00 2001 From: whale_hunter <143016036+whalehunting@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:58:48 +0100 Subject: [PATCH 58/68] feat: add flokibot evm bot trades spellbook (#7214) * chore: add pepeboost to dex_evm.bot_trades * fix: remove trailing commas * chore: add seeds + seed schema * feat: add flokibot ethereum spellbook * fix: typo * fix: typo * fix: typo * chore: format with sqlfmt * chore: add aggregator trades and fee payments * refactor: get fees from treasury + buyback fee deposits * fix: use source syntax * fix: add block_time to deployed routers * fix: remove block_number for routers * fix: typo * test: add ethereum seed * fix: sum fees per tx to avoid duplicates * test: add seed * feat: add base spellbook * fix: do not escape blockchain * fix: typo * fix: typo * chore: add base schema * test: add base seed * feat: add bnb spellbook + schema * fix: correct base deployers + start date * fix: add source for openocean bnb * test: add bnb seed file --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../dex/models/bot_trades/_schema.yml | 58 +++++- .../models/bot_trades/dex_evm_bot_trades.sql | 8 +- .../base/flokibot_base_bot_trades.sql | 165 ++++++++++++++++ .../flokibot/bnb/flokibot_bnb_bot_trades.sql | 181 ++++++++++++++++++ .../ethereum/flokibot_ethereum_bot_trades.sql | 165 ++++++++++++++++ .../flokibot/flokibot_base_trades_seed.csv | 21 ++ .../flokibot/flokibot_bnb_trades_seed.csv | 21 ++ .../flokibot_ethereum_trades_seed.csv | 21 ++ .../dex/seeds/bot_trades/flokibot/schema.yml | 33 ++++ .../openocean/bnb/openocean_bnb_sources.yml | 6 + 10 files changed, 676 insertions(+), 3 deletions(-) create mode 100644 dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql create mode 100644 dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql create mode 100644 dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql create mode 100644 dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_base_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_bnb_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_ethereum_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/flokibot/schema.yml create mode 100644 sources/openocean/bnb/openocean_bnb_sources.yml diff --git a/dbt_subprojects/dex/models/bot_trades/_schema.yml b/dbt_subprojects/dex/models/bot_trades/_schema.yml index a8b5051de1d..fc7242490fa 100644 --- a/dbt_subprojects/dex/models/bot_trades/_schema.yml +++ b/dbt_subprojects/dex/models/bot_trades/_schema.yml @@ -131,7 +131,6 @@ models: - check_bot_trades_seed: seed_file: ref('banana_gun_base_trades_seed') - - name: pepeboost_ethereum_bot_trades meta: blockchain: ethereum @@ -150,3 +149,60 @@ models: - evt_index - check_bot_trades_seed: seed_file: ref('pepeboost_ethereum_trades_seed') + + - name: flokibot_ethereum_bot_trades + meta: + blockchain: ethereum + sector: dex + project: flokibot + contributors: whale_hunter + config: + tags: ["evm", "dex", "flokibot", "trades"] + description: > + Flokibot trades on Ethereum + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('flokibot_ethereum_trades_seed') + + - name: flokibot_base_bot_trades + meta: + blockchain: base + sector: dex + project: flokibot + contributors: whale_hunter + config: + tags: ["evm", "dex", "flokibot", "trades"] + description: > + Flokibot trades on Base + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('flokibot_base_trades_seed') + + - name: flokibot_bnb_bot_trades + meta: + blockchain: bnb + sector: dex + project: flokibot + contributors: whale_hunter + config: + tags: ["evm", "dex", "flokibot", "trades"] + description: > + Flokibot trades on BNB + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('flokibot_bnb_trades_seed') diff --git a/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql index c339d2e2b55..66c51dcbbc2 100644 --- a/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql +++ b/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql @@ -14,8 +14,12 @@ {% set evm_trading_bots = [ - ref('banana_gun_ethereum_bot_trades') - ,ref('banana_gun_base_bot_trades') + ref('banana_gun_base_bot_trades') + ,ref('banana_gun_ethereum_bot_trades') + ,ref('pepeboost_ethereum_bot_trades') + ,ref('flokibot_base_bot_trades') + ,ref('flokibot_bnb_bot_trades') + ,ref('flokibot_ethereum_bot_trades') ] %} {% for bot in evm_trading_bots %} diff --git a/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql new file mode 100644 index 00000000000..6414dedc79d --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql @@ -0,0 +1,165 @@ +{{ + config( + alias='bot_trades', + schema='flokibot_base', + partition_by=['block_month'], + materialized='incremental', + file_format='delta', + incremental_strategy='merge', + incremental_predicates=[ + incremental_predicate('DBT_INTERNAL_DEST.block_time') + ], + unique_key=['blockchain', 'tx_hash', 'evt_index'], + ) +}} + +{% set project_name = 'Floki Trading Bot' %} +{% set project_start_date = '2024-02-13' %} +{% set blockchain = 'base' %} +{% set bot_deployer_1 = '0xdeb9e55e0f20bc59029271372ecea50e67182a3a' %} +{% set bot_deployer_2 = '0xcE6a13955EC32B6B1b7EBe089302b536Ad40aeC3' %} +{% set treasury_fee_wallet_1 = '0xc69df57dbb39e52d5836753e6abb71a9ab271c2d' %} +{% set treasury_fee_wallet_2 = '0x800E2f14a25Ae52300209b2D7Fb45cC27ae91a9d' %} +{% set buyback_fee_wallet_1 = '0xCc5374Be204990A3205EB9f93C5bD37B4f8e2c5e' %} +{% set aggregator_fee_wallet_1 = '0x7b41114eCB5C09d483343116C229Be3d3eb3b0fC' %} +{% set weth = '0x4200000000000000000000000000000000000006' %} +{% set fee_token_symbol = 'ETH' %} + +with + bot_contracts as ( + select block_time, address + from {{ source('base', 'creation_traces') }} + where + ("from" = {{ bot_deployer_1 }} or "from" = {{ bot_deployer_2 }}) + and block_time >= timestamp '{{project_start_date}}' + ), + fees as ( + select sum(value) / 1e18 as fee_token_amount, tx_hash + from {{ source('base', 'traces') }} + where + ( + to = {{ treasury_fee_wallet_1 }} + or to = {{ treasury_fee_wallet_2 }} + or to = {{ buyback_fee_wallet_1 }} + ) + and tx_success = true + and value > 0 + {% if is_incremental() %} + and {{ incremental_predicate('block_time') }} + {% else %} and block_time >= timestamp '{{project_start_date}}' + {% endif %} + group by tx_hash + ), + oneinch_aggregator_trades as ( + select call_block_time as block_time, call_tx_hash as tx_hash + from {{ source('oneinch_base', 'AggregationRouterV6_call_swap') }} + where + ( + varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0 + ) + and call_success + {% if is_incremental() %} + and {{ incremental_predicate('call_block_time') }} + {% else %} and call_block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + trade_transactions as ( + select block_time, address, null as tx_hash + from bot_contracts + union all + select block_time, null as address, tx_hash + from oneinch_aggregator_trades + ), + bot_trades as ( + select + trades.block_time, + trades.block_number, + amount_usd, + if(token_sold_address = {{ weth }}, 'Buy', 'Sell') as type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + {{ weth }} as fee_token_address, + project, + version, + token_pair, + project_contract_address, + tx_from as user, + tx_to as bot, + trades.tx_hash, + evt_index + from {{ source('dex', 'trades') }} as trades + join trade_transactions ON ( + ( + trades.tx_to = trade_transactions.address + OR trades.tx_hash = trade_transactions.tx_hash + ) + AND trades.block_time >= trade_transactions.block_time + ) + left join fees on fees.tx_hash = trades.tx_hash + where + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + and {{ incremental_predicate('trades.block_time') }} + {% else %} and trades.block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + highest_event_index_for_each_trade as ( + select tx_hash, max(evt_index) as highest_event_index + from bot_trades + group by tx_hash + ) +select + block_time, + date_trunc('day', bot_trades.block_time) as block_date, + date_trunc('month', bot_trades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' as blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + round( + fee_token_amount * price / cast(amount_usd as double), + 4 -- Round feePercentage to 0.01% steps + ) as fee_percentage_fraction, + fee_token_amount * price as fee_usd, + fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user as user, + bot_trades.tx_hash, + evt_index, + if(evt_index = highest_event_index, true, false) as is_last_trade_in_transaction +from bot_trades +join + highest_event_index_for_each_trade + on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash +left join + {{ source('prices', 'usd') }} + on ( + blockchain = '{{blockchain}}' + and contract_address = {{ weth }} + and minute = date_trunc('minute', block_time) + {% if is_incremental() %} and {{ incremental_predicate('minute') }} {% endif %} + ) +order by block_time desc, evt_index desc diff --git a/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql new file mode 100644 index 00000000000..63eade0c94a --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql @@ -0,0 +1,181 @@ +{{ + config( + alias='bot_trades', + schema='flokibot_bnb', + partition_by=['block_month'], + materialized='incremental', + file_format='delta', + incremental_strategy='merge', + incremental_predicates=[ + incremental_predicate('DBT_INTERNAL_DEST.block_time') + ], + unique_key=['blockchain', 'tx_hash', 'evt_index'], + ) +}} + +{% set project_name = 'Floki Trading Bot' %} +{% set project_start_date = '2024-02-13' %} +{% set blockchain = 'bnb' %} +{% set bot_deployer_1 = '0xdeb9E55E0F20bC59029271372ECea50E67182A3A' %} +{% set bot_deployer_2 = '0xfE188fee982CF9588841ea8540bD490a495D9f2c' %} +{% set bot_deployer_3 = '0xcE6a13955EC32B6B1b7EBe089302b536Ad40aeC3' %} +{% set treasury_fee_wallet_1 = '0xc69df57dbb39e52d5836753e6abb71a9ab271c2d' %} +{% set treasury_fee_wallet_2 = '0x07b127f66cf580aBd2FC59b7836fc2CF6cec3502' %} +{% set treasury_fee_wallet_3 = '0x197d8fab9d5a4c026a56d01f529caf023ba46df5' %} +{% set buyback_fee_wallet_1 = '0xCc5374Be204990A3205EB9f93C5bD37B4f8e2c5e' %} +{% set aggregator_fee_wallet_1 = '0x7b41114eCB5C09d483343116C229Be3d3eb3b0fC' %} +{% set wbnb = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' %} +{% set fee_token_symbol = 'BNB' %} + +with + bot_contracts as ( + select block_time, address + from {{ source('bnb', 'creation_traces') }} + where + ("from" = {{ bot_deployer_1 }} or "from" = {{ bot_deployer_2 }} or "from" = {{ bot_deployer_3 }}) + and block_time >= timestamp '{{project_start_date}}' + ), + fees as ( + select sum(value) / 1e18 as fee_token_amount, tx_hash + from {{ source('bnb', 'traces') }} + where + ( + to = {{ treasury_fee_wallet_1 }} + or to = {{ treasury_fee_wallet_2 }} + or to = {{ buyback_fee_wallet_1 }} + ) + and tx_success = true + and value > 0 + {% if is_incremental() %} + and {{ incremental_predicate('block_time') }} + {% else %} and block_time >= timestamp '{{project_start_date}}' + {% endif %} + group by tx_hash + ), + oneinch_aggregator_trades as ( + select call_block_time as block_time, call_tx_hash as tx_hash + from {{ source('oneinch_bnb', 'AggregationRouterV6_call_swap') }} + where + ( + varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_3 }}) > 0 + ) + and call_success + {% if is_incremental() %} + and {{ incremental_predicate('call_block_time') }} + {% else %} and call_block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + openocean_aggregator_trades as ( + select evt_block_time as block_time, evt_tx_hash as tx_hash + from {{ source('openocean_v2_bnb', 'OpenOceanExchange_evt_Swapped') }} + where + referrer = {{ treasury_fee_wallet_3 }} + {% if is_incremental() %} + and {{ incremental_predicate('evt_block_time') }} + {% else %} and evt_block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + trade_transactions as ( + select block_time, address, null as tx_hash + from bot_contracts + union all + select block_time, null as address, tx_hash + from oneinch_aggregator_trades + union all + select block_time, null as address, tx_hash + from openocean_aggregator_trades + ), + bot_trades as ( + select + trades.block_time, + trades.block_number, + amount_usd, + if(token_sold_address = {{ wbnb }}, 'Buy', 'Sell') as type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + {{ wbnb }} as fee_token_address, + project, + version, + token_pair, + project_contract_address, + tx_from as user, + tx_to as bot, + trades.tx_hash, + evt_index + from {{ source('dex', 'trades') }} as trades + join trade_transactions ON ( + ( + trades.tx_to = trade_transactions.address + OR trades.tx_hash = trade_transactions.tx_hash + ) + AND trades.block_time >= trade_transactions.block_time + ) + left join fees on fees.tx_hash = trades.tx_hash + where + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + and {{ incremental_predicate('trades.block_time') }} + {% else %} and trades.block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + highest_event_index_for_each_trade as ( + select tx_hash, max(evt_index) as highest_event_index + from bot_trades + group by tx_hash + ) +select + block_time, + date_trunc('day', bot_trades.block_time) as block_date, + date_trunc('month', bot_trades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' as blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + round( + fee_token_amount * price / cast(amount_usd as double), + 4 -- Round feePercentage to 0.01% steps + ) as fee_percentage_fraction, + fee_token_amount * price as fee_usd, + fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user as user, + bot_trades.tx_hash, + evt_index, + if(evt_index = highest_event_index, true, false) as is_last_trade_in_transaction +from bot_trades +join + highest_event_index_for_each_trade + on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash +left join + {{ source('prices', 'usd') }} + on ( + blockchain = '{{blockchain}}' + and contract_address = {{ wbnb }} + and minute = date_trunc('minute', block_time) + {% if is_incremental() %} and {{ incremental_predicate('minute') }} {% endif %} + ) +order by block_time desc, evt_index desc diff --git a/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql new file mode 100644 index 00000000000..d8991b7cbfd --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql @@ -0,0 +1,165 @@ +{{ + config( + alias='bot_trades', + schema='flokibot_ethereum', + partition_by=['block_month'], + materialized='incremental', + file_format='delta', + incremental_strategy='merge', + incremental_predicates=[ + incremental_predicate('DBT_INTERNAL_DEST.block_time') + ], + unique_key=['blockchain', 'tx_hash', 'evt_index'], + ) +}} + +{% set project_name = 'Floki Trading Bot' %} +{% set project_start_date = '2024-02-01' %} +{% set blockchain = 'ethereum' %} +{% set bot_deployer_1 = '0xdeb9E55E0F20bC59029271372ECea50E67182A3A' %} +{% set bot_deployer_2 = '0xcE6a13955EC32B6B1b7EBe089302b536Ad40aeC3' %} +{% set treasury_fee_wallet_1 = '0xc69df57dbb39e52d5836753e6abb71a9ab271c2d' %} +{% set treasury_fee_wallet_2 = '0xffdc626bb733a8c2e906242598e2e99752dcb922' %} +{% set buyback_fee_wallet_1 = '0xCc5374Be204990A3205EB9f93C5bD37B4f8e2c5e' %} +{% set aggregator_fee_wallet_1 = '0x7b41114eCB5C09d483343116C229Be3d3eb3b0fC' %} +{% set weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} +{% set fee_token_symbol = 'ETH' %} + +with + bot_contracts as ( + select block_time, address + from {{ source('ethereum', 'creation_traces') }} + where + ("from" = {{ bot_deployer_1 }} or "from" = {{ bot_deployer_2 }}) + and block_time >= timestamp '{{project_start_date}}' + ), + fees as ( + select sum(value) / 1e18 as fee_token_amount, tx_hash + from {{ source('ethereum', 'traces') }} + where + ( + to = {{ treasury_fee_wallet_1 }} + or to = {{ treasury_fee_wallet_2 }} + or to = {{ buyback_fee_wallet_1 }} + ) + and tx_success = true + and value > 0 + {% if is_incremental() %} + and {{ incremental_predicate('block_time') }} + {% else %} and block_time >= timestamp '{{project_start_date}}' + {% endif %} + group by tx_hash + ), + oneinch_aggregator_trades as ( + select call_block_time as block_time, call_tx_hash as tx_hash + from {{ source('oneinch_ethereum', 'AggregationRouterV6_call_swap') }} + where + ( + varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0 + ) + and call_success + {% if is_incremental() %} + and {{ incremental_predicate('call_block_time') }} + {% else %} and call_block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + trade_transactions as ( + select block_time, address, null as tx_hash + from bot_contracts + union all + select block_time, null as address, tx_hash + from oneinch_aggregator_trades + ), + bot_trades as ( + select + trades.block_time, + trades.block_number, + amount_usd, + if(token_sold_address = {{ weth }}, 'Buy', 'Sell') as type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + {{ weth }} as fee_token_address, + project, + version, + token_pair, + project_contract_address, + tx_from as user, + tx_to as bot, + trades.tx_hash, + evt_index + from {{ source('dex', 'trades') }} as trades + join trade_transactions ON ( + ( + trades.tx_to = trade_transactions.address + OR trades.tx_hash = trade_transactions.tx_hash + ) + AND trades.block_time >= trade_transactions.block_time + ) + left join fees on fees.tx_hash = trades.tx_hash + where + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + and {{ incremental_predicate('trades.block_time') }} + {% else %} and trades.block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + highest_event_index_for_each_trade as ( + select tx_hash, max(evt_index) as highest_event_index + from bot_trades + group by tx_hash + ) +select + block_time, + date_trunc('day', bot_trades.block_time) as block_date, + date_trunc('month', bot_trades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' as blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + round( + fee_token_amount * price / cast(amount_usd as double), + 4 -- Round feePercentage to 0.01% steps + ) as fee_percentage_fraction, + fee_token_amount * price as fee_usd, + fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user as user, + bot_trades.tx_hash, + evt_index, + if(evt_index = highest_event_index, true, false) as is_last_trade_in_transaction +from bot_trades +join + highest_event_index_for_each_trade + on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash +left join + {{ source('prices', 'usd') }} + on ( + blockchain = '{{blockchain}}' + and contract_address = {{ weth }} + and minute = date_trunc('minute', block_time) + {% if is_incremental() %} and {{ incremental_predicate('minute') }} {% endif %} + ) +order by block_time desc, evt_index desc diff --git a/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_base_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_base_trades_seed.csv new file mode 100644 index 00000000000..37f8fa3b5d1 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_base_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2024-11-27 04:37:49.000 UTC,2024-11-27 00:00:00.000 UTC,2024-11-01 00:00:00.000 UTC,Floki Trading Bot,22946461,base,0.33883937999999997,Buy,520.2338446502055,USA,0xb56d0839998fd79efcd15c27cf966250aa58d6d3,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.00342262,0.000001,ETH,0x4200000000000000000000000000000000000006,uniswap,3,USA-WETH,0x6e668dcafaaab8e9dc9b8255fe125622230fb9a6,0xe96321ceb4deae752ffbf876ce9fcf45587a4492,0xe66b19d7b39766715feef54cef41d1657047f1746eb22795a0a65d115259aeba,243,true +2024-10-29 23:42:19.000 UTC,2024-10-29 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21727996,base,2.6076699000000003,Buy,48950.585902226,NEIRO,0xa816ee97b1d7ae50fb0c68672a56f45334b90aa7,0.00099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.026340100000000005,0.00001,ETH,0x4200000000000000000000000000000000000006,uniswap,2,NEIRO-WETH,0x052ed7ee8377e03b10c312b7cda7edb39d0daa33,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0xe27c53821c1061adf5ac8bbc728a41360019ace832f89649622f7c8bd9b50a7d,433,true +2024-10-17 18:57:01.000 UTC,2024-10-17 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21201037,base,0.12637520885044923,Sell,0.000048847645402608,WETH,0x4200000000000000000000000000000000000006,3.0287101028116847,TRUMP,0x2e1d332893dc16124194e598a29866d2d5e8786b,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,TRUMP-WETH,0xd33805985642fa9338e1fa150ca811406f96f0de,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0x5cd4aaaf25c12cf954b7456f0243f63e8c41ba63cf8b2287c3672687ed7a8b0e,121,true +2024-10-11 01:19:35.000 UTC,2024-10-11 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,20910114,base,0.3574667213813365,Sell,0.000149849181676596,WETH,0x4200000000000000000000000000000000000006,,,0xb0492857994e2af4ad0fa41d10bd711d4534f768,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xab10864ace3da8046e2218fbccda1c23318a4219,0xe162325f3579e99c7a051232c242b6f9bcc0f39c,0xf0d3958952b71eda82a42d443f3a5390248b131e063951e552ce6f86cc8b0709,93,true +2024-10-31 20:12:43.000 UTC,2024-10-31 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21808108,base,0.24954929999999997,Buy,0.2184472091214867,AERO,0x940181a94a35a4569e4529a3cdfb74e38fd98631,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.0025207,0.000001,ETH,0x4200000000000000000000000000000000000006,pancakeswap,3,AERO-WETH,0x20cb8f872ae894f7c9e32e621c186e5afce82fd0,0x74a916ac78d5f52d5fafc078e9bf27993bf7ecdb,0x2e9d1e914f025dde460cd912813f7ade049db078de214708112ac65756eeaeda,1459,true +2024-10-30 10:30:39.000 UTC,2024-10-30 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21747446,base,199.6681192420227,Sell,0.07432415241006633,WETH,0x4200000000000000000000000000000000000006,110477.50457230002,USA,0xb56d0839998fd79efcd15c27cf966250aa58d6d3,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,3,USA-WETH,0x6e668dcafaaab8e9dc9b8255fe125622230fb9a6,0xa1128f9b8ffcedb16d6fdcf1509ccbb14816da7b,0xf8c26d9130ce0b754ecdfda6c9eebeb0e058962b98a9760c0a4ac45e0ca7ff4d,516,false +2024-10-27 22:55:55.000 UTC,2024-10-27 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21640204,base,0.7324634032629762,Sell,0.000291212459849626,WETH,0x4200000000000000000000000000000000000006,10.192021241117352,TRUMP,0x2e1d332893dc16124194e598a29866d2d5e8786b,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,TRUMP-WETH,0xd33805985642fa9338e1fa150ca811406f96f0de,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0x26bd4e82b438fb52070dd8cc650e95106c945e81886eae1f54471f034a9e306a,65,true +2024-10-13 08:51:01.000 UTC,2024-10-13 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21010057,base,9.7629444,Buy,72532.06361495884,TYBG,0x0d97f261b1e88845184f678e2d1e7a98d9fd38de,0.00396,WETH,0x4200000000000000000000000000000000000006,0.0101,0.0986156,0.00004,ETH,0x4200000000000000000000000000000000000006,sushiswap,1,TYBG-WETH,0xf65bb528ced09008603509c3fda43e1ccfddf935,0x081120a2bb4882d04644790a1440be231e71c3fc,0x5133fbcabdc067b3a53581c550f0a83d2d535ff5ec217019da3695c74d70479e,50,true +2024-10-13 04:53:25.000 UTC,2024-10-13 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21002929,base,0.24389441999999997,Buy,19.786076776911564,ANDY,0x18a8bd1fe17a1bb9ffb39ecd83e9489cfd17a022,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.00246358,0.000001,ETH,0x4200000000000000000000000000000000000006,sushiswap,1,ANDY-WETH,0xff5375bd65056dbe6119256fc3be2eb0ffa8a840,0xe162325f3579e99c7a051232c242b6f9bcc0f39c,0xd48698d7bd98e4aeb80d05aa1ef5124094fcdc03be76b208add7ba22b4399242,41,true +2024-10-13 02:52:35.000 UTC,2024-10-13 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,20999304,base,0.024064873853599695,Sell,0.000009742272272372,WETH,0x4200000000000000000000000000000000000006,15.787352393617192,USA,0xb56d0839998fd79efcd15c27cf966250aa58d6d3,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,USA-WETH,0xfffed65c9fdaf0818867e8b6d841fdb0631bc223,0x74b1ae6bc107f6b95620ec0b808b1a85fa150421,0x5fade0e53b6e9452b95398732ed3e976808826d521aa4391bf09d4b8e6c7b4b2,145,true +2024-10-27 22:46:13.000 UTC,2024-10-27 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21639913,base,0.24908102999999995,Buy,3.42403973966794,TRUMP,0x2e1d332893dc16124194e598a29866d2d5e8786b,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.0025159699999999998,0.000001,ETH,0x4200000000000000000000000000000000000006,uniswap,2,TRUMP-WETH,0xd33805985642fa9338e1fa150ca811406f96f0de,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0x9f96599ad1e15b1221074d05c0434ff4a0aacd4970030ce90c21916dc56a2c1b,580,true +2024-10-27 16:47:47.000 UTC,2024-10-27 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21629160,base,0.24709212,Buy,136553.29223940978,BASE,0xd07379a755a8f11b57610154861d694b2a0f615a,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.00249588,0.000001,ETH,0x4200000000000000000000000000000000000006,swapbased,1,BASE-WETH,0x5554419ccd0293d9383901f461c7c3e0c66e925f,0xd1a2dc602e86814f4a9996fb7901d2f3caee4fa0,0x11baa2b637dfd468bc907c4082dbe39a869768bc79e64e0544bdca42dd306b2c,88,true +2024-10-13 07:49:51.000 UTC,2024-10-13 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21008222,base,59.028199560000004,Buy,438049.5664395944,TYBG,0x0d97f261b1e88845184f678e2d1e7a98d9fd38de,0.023958,WETH,0x4200000000000000000000000000000000000006,0.0459,2.710202,0.0011,ETH,0x4200000000000000000000000000000000000006,aerodrome,slipstream,TYBG-WETH,0x8d628d22d298b4a6e3dc9171d4b7aa5229e2353c,0x081120a2bb4882d04644790a1440be231e71c3fc,0x66dc9a8e7a87d501e8eb4ac8ddce4c9cb3d3cbc33304ea5e7d702f45cc3f5517,154,false +2024-10-30 07:53:37.000 UTC,2024-10-30 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21742735,base,0.26348652,Buy,10.092482462526931,SKOP,0x6d3b8c76c5396642960243febf736c6be8b60562,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.00266148,0.000001,ETH,0x4200000000000000000000000000000000000006,uniswap,2,SKOP-WETH,0xa5c7015c81d2280032b031406048c75696ba77d5,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0xa65a33733441514c34cca9e82e27cd74f95ea42ceb9fb21f66f1983e992a6507,277,true +2024-10-17 03:04:45.000 UTC,2024-10-17 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21172469,base,0.0727270236,Buy,4.080240547382812,SKOP,0x6d3b8c76c5396642960243febf736c6be8b60562,0.00002772,WETH,0x4200000000000000000000000000000000000006,0.0361,0.00262363,0.000001,ETH,0x4200000000000000000000000000000000000006,aerodrome,1,SKOP-WETH,0x18c55864d9bc0d7c3f6dc18e3a1d20e50f551891,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0x866164ab910f1f15c54a30ea438724fec953a1aaf963bd998f47e05471a4bb60,62,false +2024-10-13 07:49:51.000 UTC,2024-10-13 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21008222,base,128.78879904000001,Buy,955759.5197680636,TYBG,0x0d97f261b1e88845184f678e2d1e7a98d9fd38de,0.052272,WETH,0x4200000000000000000000000000000000000006,0.021,2.710202,0.0011,ETH,0x4200000000000000000000000000000000000006,uniswap,3,TYBG-WETH,0xe745a591970e0fa981204cf525e170a2b9e4fb93,0x081120a2bb4882d04644790a1440be231e71c3fc,0x66dc9a8e7a87d501e8eb4ac8ddce4c9cb3d3cbc33304ea5e7d702f45cc3f5517,158,true +2024-10-14 17:32:43.000 UTC,2024-10-14 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21068908,base,0.32123877776357196,Sell,0.000122715137279037,WETH,0x4200000000000000000000000000000000000006,,,0xb0492857994e2af4ad0fa41d10bd711d4534f768,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xab10864ace3da8046e2218fbccda1c23318a4219,0xe162325f3579e99c7a051232c242b6f9bcc0f39c,0x2a89fbe29f1a7a4b37e97e17c08e721d102051966f47594ca05498e3a39a4425,110,true +2024-10-30 07:43:23.000 UTC,2024-10-30 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21742428,base,0.26436761999999997,Buy,2.808298863289798,TRUMP,0x2e1d332893dc16124194e598a29866d2d5e8786b,0.000099,WETH,0x4200000000000000000000000000000000000006,0.0101,0.00267038,0.000001,ETH,0x4200000000000000000000000000000000000006,uniswap,2,TRUMP-WETH,0xd33805985642fa9338e1fa150ca811406f96f0de,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0x93f4a732fefdfe54bcfecba0584c253b077d157fb8ffc83dfcbd4084695a60b7,36,true +2024-10-17 03:07:37.000 UTC,2024-10-17 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21172555,base,0.3836886733810342,Sell,0.000146134268252482,WETH,0x4200000000000000000000000000000000000006,1104.249675604,NEIRO,0xa816ee97b1d7ae50fb0c68672a56f45334b90aa7,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,NEIRO-WETH,0x052ed7ee8377e03b10c312b7cda7edb39d0daa33,0x332f1d9653f43fb13668594cbc957bf7ad63e737,0x5591cab4cb6daded34e3e5b7f366830dfa1e0ce388c375982ccce5dbb3294ef6,32,true +2024-10-14 17:32:43.000 UTC,2024-10-14 00:00:00.000 UTC,2024-10-01 00:00:00.000 UTC,Floki Trading Bot,21068908,base,287.07337637096515,Sell,0.10966374930129773,WETH,0x4200000000000000000000000000000000000006,,,0xb0492857994e2af4ad0fa41d10bd711d4534f768,,,,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xab10864ace3da8046e2218fbccda1c23318a4219,0xe162325f3579e99c7a051232c242b6f9bcc0f39c,0x2a89fbe29f1a7a4b37e97e17c08e721d102051966f47594ca05498e3a39a4425,104,false diff --git a/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_bnb_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_bnb_trades_seed.csv new file mode 100644 index 00000000000..850cba1b57e --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_bnb_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2024-12-01 06:08:41.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44484170,bnb,0.7069570199999999,Buy,15758.15255764733,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.001089,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,0.007140979999999999,0.000011,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0xa2692d110bddf9e3235f3b6d00e8108e3ccdfa04,0x6b4a3b71a5e8871bb802fe2448fe87db6af8d9a7dc4916be850f83339da35adf,72,true +2024-12-01 05:57:08.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483939,bnb,572.1670328391788,Sell,0.8813009762937307,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,12851365.705668807,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,3,CAT-WBNB,0x588d7cf062f4edd7c7c7f2d66fd770e03b1ea735,0xcfa1c1596780cb77fba610f85826fea58e988842,0x3736d5260401f4829a383851e35167586ca074aff19e590f19dff4fd767ca5af,175,true +2024-12-01 05:38:59.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483576,bnb,63.6124781019977,Sell,0.09792109062389007,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,1438290.103368273,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,3,CAT-WBNB,0x588d7cf062f4edd7c7c7f2d66fd770e03b1ea735,0x2e170be73bddd948f9dbd7b5ca873a5a48d40633,0xfd9e62486c20e559c92c33e3714f9c20b323e0c1315f27bd9b607beb866a3c1d,98,true +2024-12-01 06:17:56.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44484355,bnb,0.6434406,Buy,14311.815785843628,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.00099,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,0.006499400000000001,0.00001,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0xc52102e7cf3a46aaaf59d4c16f63ab704a0753a1,0xf4858f045ab00048cb27931f63b21ee7abdc3dfad8c093fd70c11640a6b2263f,119,true +2024-12-01 05:44:53.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483694,bnb,0.6425892000000001,Buy,14504.676434395149,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.00099,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,0.0064908000000000006,0.00001,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0x7905e8e6323dcc3730ef51db9918f4d5496d6ed6,0x259ff14631286325766590034ab5e712144850622232cc6093d262e590839736,43,true +2024-12-01 02:55:02.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44480297,bnb,320.74515,Buy,7336656.59421379,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.495,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,3.23985,0.005,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0x06aa01d9d5370a7853e4ce1c394487cbde38467c,0x2412a65ab0328ebb0a3d5c303d6cb3b491e6f6648260951691c354f0c19a007a,58,true +2024-12-01 05:10:11.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483000,bnb,0.6443118000000001,Buy,14538.50332775852,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.00099,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,0.006508200000000001,0.00001,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0x1d24d1b353caef80af08b4f3fda7210d4cbad32a,0x09ccd88430170286c7de82fb24f63c45d2f3cb5d1f327acd98f741835756b4eb,48,true +2024-12-01 03:04:59.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44480496,bnb,320.22044999999997,Buy,7347347.6147423815,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.495,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0x40045b953b7168339f87dbe2c6c43f4808a27f46,0x78a178a37adc1be58b816b518fbc8d7d4ffc274d34ba9439ffc00569d944c909,66,true +2024-12-01 01:02:32.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44478047,bnb,4.357445453967259,Sell,0.006693670241739007,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,97174.31931894596,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,uniswap,3,CAT-WBNB,0x05c0a0b84b6b67499c33e6403686f45cab063810,0xd6debea50b34fd002249fab262ca8af692e24ebf,0xf649f80b73c0efe000eedc6564f0f120c5a50cab0f4f3a6be1ce14e42b3b42aa,453,true +2024-12-01 05:24:59.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483296,bnb,64.43811,Buy,1456670.3541323277,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.099,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,0.65089,0.001,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0x19a48629d6bc384634223646065ab70ec1cf866d,0xd1b0e061b7dbeb0132cd0a935603ffeeb9a66322483fb55fd5df430fb862cd2a,65,true +2024-12-01 05:41:44.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483631,bnb,63.554928938311484,Sell,0.09791540170443008,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,271196.736042164,FLOKI,0xfb5b838b6cfeedc2873ab27866079ac55363d37e,0.01,0.6355492893831144,0.0009791540170443,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,FLOKI-WBNB,0x231d9e7181e8479a8b40930961e93e7ed798542c,0x2e170be73bddd948f9dbd7b5ca873a5a48d40633,0xf37fdb8195b2a6be26e189a7427c977803aa1652ff5207720696c60c9d05987e,42,true +2024-12-01 03:38:50.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44481173,bnb,0.6430941,Buy,14534.765202561795,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.00099,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,0.0101,0.006495900000000001,0.00001,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,CAT-WBNB,0x6df9adc1837bf37e0b1b943d59a7e50d9678c81b,0xe408cfe7caf64196f57b15e8bc7c34c73acd38a9,0x85dbf4fd8f6fb97313e4cff6d3bb1156bb0cf43401484fdc9a5c3dd02bd514ba,44,true +2024-12-01 00:13:17.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44477062,bnb,1552.5279138857659,Sell,2.3721548617005346,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,21934,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.01,15.52527913885766,0.023721548617005348,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,TOKEN-WBNB,0x05616b7b6da03fb4c773b76663816b360ccaede4,0x559645f9eb8d6935bb489d6f04a8315372d70111,0x73ff2a7ae3f45bfcf375ea2e220f29e8ad8f5278f4c8fb8da28621ee48a59f01,183,true +2024-12-01 05:41:44.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483631,bnb,0.0016005088123281475,Sell,0.000002465811321144,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,6.829533578,FLOKI,0xfb5b838b6cfeedc2873ab27866079ac55363d37e,397.092,0.6355492893831144,0.0009791540170443,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,FLOKI-WBNB,0x231d9e7181e8479a8b40930961e93e7ed798542c,0x2e170be73bddd948f9dbd7b5ca873a5a48d40633,0xf37fdb8195b2a6be26e189a7427c977803aa1652ff5207720696c60c9d05987e,25,false +2024-12-01 00:13:17.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44477062,bnb,0.4659387033785003,Sell,0.000711921989027167,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,6.57984954,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,33.3204,15.52527913885766,0.023721548617005348,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,2,TOKEN-WBNB,0x05616b7b6da03fb4c773b76663816b360ccaede4,0x559645f9eb8d6935bb489d6f04a8315372d70111,0x73ff2a7ae3f45bfcf375ea2e220f29e8ad8f5278f4c8fb8da28621ee48a59f01,165,false +2024-12-01 05:49:47.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483792,bnb,824.6520450119638,Sell,1.2692422043525884,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,18511266.159998745,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,3,CAT-WBNB,0x588d7cf062f4edd7c7c7f2d66fd770e03b1ea735,0xcfa1c1596780cb77fba610f85826fea58e988842,0xaa84f5c1c3bac9d228bebdd666d5b1d7817acbd4fbf6f3f6c06a37f53bce87bc,60,true +2024-12-01 06:52:26.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44485045,bnb,0.7791272652408384,Sell,0.001198178059915785,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,17439.9731907165,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,3,CAT-WBNB,0x1a1adea3c1e2f55526379a21023ef46714e73d06,0x365f65f76c581d0e00962392003b185e9c92a133,0x2d7aa90e273457d50efcb2866ebdd4918a62cf3ea3732de9e3f3fa36cf83acf8,83,true +2024-12-01 02:33:26.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44479865,bnb,48.024672977768915,Sell,0.07382618711129563,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,1082266.712964405,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,3,CAT-WBNB,0x588d7cf062f4edd7c7c7f2d66fd770e03b1ea735,0x596817f9472e492489de0bc24e4605d139abc19d,0x93b4b675c36ccde9c1561d9b574e21a0a74f9b222d14ef5b94d499075807c796,82,true +2024-12-01 05:49:20.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483783,bnb,66.89517120000001,Buy,1495280.3937194524,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,0.10296,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,uniswap,3,CAT-WBNB,0x05c0a0b84b6b67499c33e6403686f45cab063810,0xcfa1c1596780cb77fba610f85826fea58e988842,0x0607e759ff525b3f7f27dd5799be08347e19463da741be78c47e068494bed8c6,96,false +2024-12-01 05:48:56.000 UTC,2024-12-01 00:00:00.000 UTC,2024-12-01 00:00:00.000 UTC,Floki Trading Bot,44483775,bnb,859.503341921597,Sell,1.322882690884684,WBNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,19241616.414468314,CAT,0x6894cde390a3f51155ea41ed24a33a4827d3063d,,,,BNB,0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c,pancakeswap,3,CAT-WBNB,0x588d7cf062f4edd7c7c7f2d66fd770e03b1ea735,0xcfa1c1596780cb77fba610f85826fea58e988842,0x10c816a8e63272b4054b261659d060001a14b5bc6c208e04a46c21d34bd712b9,8,true diff --git a/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_ethereum_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_ethereum_trades_seed.csv new file mode 100644 index 00000000000..3a54630f1f8 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/flokibot/flokibot_ethereum_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2024-02-13 13:26:11.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219371,ethereum,49.855582061697035,Buy,1541.058761682,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.01864317630008864,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0x78c4f5cef16333804394fe736fc5868351968fd7,0xb8f01482f050c21182adfb98f0c0331325b2118634e5458ecebdce61b9af3e9c,227,true +2024-02-13 13:26:11.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219371,ethereum,100.06479999999999,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.03751105931449979,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0x78c4f5cef16333804394fe736fc5868351968fd7,0xb8f01482f050c21182adfb98f0c0331325b2118634e5458ecebdce61b9af3e9c,218,false +2024-02-13 13:26:11.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219371,ethereum,49.855582061697035,Sell,0.01864317630008864,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0x78c4f5cef16333804394fe736fc5868351968fd7,0xb8f01482f050c21182adfb98f0c0331325b2118634e5458ecebdce61b9af3e9c,223,false +2024-02-13 12:42:47.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219163,ethereum,49.75253646823398,Buy,1538.612246785,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.0185924761181016,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0xa1198aa72fbc54441585425c7beb8b266ddfb951,0xc80cd0bdfd34a9f33437acba12d99116e217729cd9cbdf2feceec7ecdfd7016d,1112,true +2024-02-13 12:42:47.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219163,ethereum,49.75253646823398,Sell,0.0185924761181016,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xa1198aa72fbc54441585425c7beb8b266ddfb951,0xc80cd0bdfd34a9f33437acba12d99116e217729cd9cbdf2feceec7ecdfd7016d,1108,false +2024-02-13 12:42:47.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219163,ethereum,100.0135,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.03740904788982464,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xa1198aa72fbc54441585425c7beb8b266ddfb951,0xc80cd0bdfd34a9f33437acba12d99116e217729cd9cbdf2feceec7ecdfd7016d,1103,false +2024-02-17 21:36:23.000 UTC,2024-02-17 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19250287,ethereum,49.88413945963971,Buy,1461.637897524,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.017853958811757907,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0xd4f6bfd4bd2fef270dc5798c8320080b187ae089,0x69e356badb13f89d4a4246cef98b828bd6dfd29baac59a70caa7548e487fd408,114,true +2024-02-17 21:36:23.000 UTC,2024-02-17 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19250287,ethereum,100.0492,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.03592311227725229,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xd4f6bfd4bd2fef270dc5798c8320080b187ae089,0x69e356badb13f89d4a4246cef98b828bd6dfd29baac59a70caa7548e487fd408,105,false +2024-02-17 21:36:23.000 UTC,2024-02-17 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19250287,ethereum,49.88413945963971,Sell,0.017853958811757907,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xd4f6bfd4bd2fef270dc5798c8320080b187ae089,0x69e356badb13f89d4a4246cef98b828bd6dfd29baac59a70caa7548e487fd408,110,false +2024-02-25 00:41:47.000 UTC,2024-02-25 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19301087,ethereum,100.18169999999999,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.03352325931297117,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0x1ce9b29b82bb3e6d9a22b622b0c1398f0c2aafa6,0x719b7d0582dcb0b8064ed06dfebcb807d079dc32af66a1b9f6b983c9ef4ca627,225,false +2024-02-25 00:41:47.000 UTC,2024-02-25 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19301087,ethereum,49.820551418894055,Sell,0.0166612215927624,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0x1ce9b29b82bb3e6d9a22b622b0c1398f0c2aafa6,0x719b7d0582dcb0b8064ed06dfebcb807d079dc32af66a1b9f6b983c9ef4ca627,230,false +2024-02-25 00:41:47.000 UTC,2024-02-25 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19301087,ethereum,49.820551418894055,Buy,1365.848487601,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.0166612215927624,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0x1ce9b29b82bb3e6d9a22b622b0c1398f0c2aafa6,0x719b7d0582dcb0b8064ed06dfebcb807d079dc32af66a1b9f6b983c9ef4ca627,234,true +2024-02-14 02:36:47.000 UTC,2024-02-14 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19223276,ethereum,49.91385925985842,Sell,0.018989989940709252,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0x65c0697d67310caa44c20d5263d3ea2e24d8ff02,0x5bc2d176954a04eb066faca6fad27987a246798b29df266428d0c452568096d1,222,false +2024-02-14 02:36:47.000 UTC,2024-02-14 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19223276,ethereum,49.91385925985842,Buy,1605.382586816,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.018989989940709252,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0x65c0697d67310caa44c20d5263d3ea2e24d8ff02,0x5bc2d176954a04eb066faca6fad27987a246798b29df266428d0c452568096d1,226,true +2024-02-14 02:36:47.000 UTC,2024-02-14 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19223276,ethereum,100.07159999999999,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.03820886646960064,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0x65c0697d67310caa44c20d5263d3ea2e24d8ff02,0x5bc2d176954a04eb066faca6fad27987a246798b29df266428d0c452568096d1,217,false +2024-02-13 13:47:59.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219479,ethereum,49.96830409960819,Sell,0.01889796721755456,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,50,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xa1198aa72fbc54441585425c7beb8b266ddfb951,0x45415f4c4e7305ee67ea859634542ae5e5795fb4d6653574fe9f76e092c5c6f0,136,false +2024-02-13 13:47:59.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219479,ethereum,49.96830409960819,Buy,1575.491567539,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.01889796721755456,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0xa1198aa72fbc54441585425c7beb8b266ddfb951,0x45415f4c4e7305ee67ea859634542ae5e5795fb4d6653574fe9f76e092c5c6f0,140,true +2024-02-13 13:47:59.000 UTC,2024-02-13 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19219479,ethereum,100.0727,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.038023711998634656,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xa1198aa72fbc54441585425c7beb8b266ddfb951,0x45415f4c4e7305ee67ea859634542ae5e5795fb4d6653574fe9f76e092c5c6f0,131,false +2024-02-20 14:10:59.000 UTC,2024-02-20 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19269419,ethereum,49.89031343571954,Buy,1348.528098563,TOKEN,0x4507cef57c46789ef8d1a19ea45f4216bae2b528,0.016691361776292175,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TOKEN-WETH,0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6,0xa1ab11e84b88e06b54ece58d79b46df8d006aab4,0x430711fe0aeae96ac381b8b6a9de64f4e40b3ab77c6e094da92bf4d2b88e3f2f,154,true +2024-02-20 14:10:59.000 UTC,2024-02-20 00:00:00.000 UTC,2024-02-01 00:00:00.000 UTC,Floki Trading Bot,19269419,ethereum,100.1747,Buy,100,USDT,0xdac17f958d2ee523a2206206994597c13d831ec7,0.03358390458672427,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,USDT-WETH,0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852,0xa1ab11e84b88e06b54ece58d79b46df8d006aab4,0x430711fe0aeae96ac381b8b6a9de64f4e40b3ab77c6e094da92bf4d2b88e3f2f,145,false diff --git a/dbt_subprojects/dex/seeds/bot_trades/flokibot/schema.yml b/dbt_subprojects/dex/seeds/bot_trades/flokibot/schema.yml new file mode 100644 index 00000000000..49ff5c1ad78 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/flokibot/schema.yml @@ -0,0 +1,33 @@ +version: 2 + +seeds: + - name: flokibot_base_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary + - name: flokibot_bnb_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary + - name: flokibot_ethereum_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary diff --git a/sources/openocean/bnb/openocean_bnb_sources.yml b/sources/openocean/bnb/openocean_bnb_sources.yml new file mode 100644 index 00000000000..0d33a49b1c1 --- /dev/null +++ b/sources/openocean/bnb/openocean_bnb_sources.yml @@ -0,0 +1,6 @@ +version: 2 + +sources: + - name: openocean_v2_bnb + tables: + - name: OpenOceanExchange_evt_Swapped From b421f8b2fbc9c397626cc9f4b21462ea1861ed60 Mon Sep 17 00:00:00 2001 From: whale_hunter <143016036+whalehunting@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:01:08 +0100 Subject: [PATCH 59/68] feat: add readyswap evm bot trades (#7216) * chore: init * chore: add correct query implementation * chore: add seed, add to schema * fix: add correct project to schema * chore: remove from dex_evm_bot_trades to debug * fix: add group by tx_hash * fix: add block_number * test: add seed * chore: add to dex_evm.bot_trades --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../dex/models/bot_trades/_schema.yml | 19 +++ .../models/bot_trades/dex_evm_bot_trades.sql | 1 + .../readyswap_ethereum_bot_trades.sql | 150 ++++++++++++++++++ .../readyswap_ethereum_trades_seed.csv | 21 +++ .../dex/seeds/bot_trades/readyswap/schema.yml | 13 ++ 5 files changed, 204 insertions(+) create mode 100644 dbt_subprojects/dex/models/bot_trades/readyswap/ethereum/readyswap_ethereum_bot_trades.sql create mode 100644 dbt_subprojects/dex/seeds/bot_trades/readyswap/readyswap_ethereum_trades_seed.csv create mode 100644 dbt_subprojects/dex/seeds/bot_trades/readyswap/schema.yml diff --git a/dbt_subprojects/dex/models/bot_trades/_schema.yml b/dbt_subprojects/dex/models/bot_trades/_schema.yml index fc7242490fa..4973ff57beb 100644 --- a/dbt_subprojects/dex/models/bot_trades/_schema.yml +++ b/dbt_subprojects/dex/models/bot_trades/_schema.yml @@ -150,6 +150,25 @@ models: - check_bot_trades_seed: seed_file: ref('pepeboost_ethereum_trades_seed') + - name: readyswap_ethereum_bot_trades + meta: + blockchain: ethereum + sector: dex + project: readyswap + contributors: whale_hunter + config: + tags: ["evm", "dex", "readyswap", "trades"] + description: > + ReadySwap trades on Ethereum + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_hash + - evt_index + - check_bot_trades_seed: + seed_file: ref('readyswap_ethereum_trades_seed') + - name: flokibot_ethereum_bot_trades meta: blockchain: ethereum diff --git a/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql index 66c51dcbbc2..75b185949eb 100644 --- a/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql +++ b/dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql @@ -16,6 +16,7 @@ {% set evm_trading_bots = [ ref('banana_gun_base_bot_trades') ,ref('banana_gun_ethereum_bot_trades') + ,ref('readyswap_ethereum_bot_trades') ,ref('pepeboost_ethereum_bot_trades') ,ref('flokibot_base_bot_trades') ,ref('flokibot_bnb_bot_trades') diff --git a/dbt_subprojects/dex/models/bot_trades/readyswap/ethereum/readyswap_ethereum_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/readyswap/ethereum/readyswap_ethereum_bot_trades.sql new file mode 100644 index 00000000000..bfa6169db5e --- /dev/null +++ b/dbt_subprojects/dex/models/bot_trades/readyswap/ethereum/readyswap_ethereum_bot_trades.sql @@ -0,0 +1,150 @@ +{{ + config( + alias='bot_trades', + schema='readyswap_ethereum', + partition_by=['block_month'], + materialized='incremental', + file_format='delta', + incremental_strategy='merge', + incremental_predicates=[ + incremental_predicate('DBT_INTERNAL_DEST.block_time') + ], + unique_key=['blockchain', 'tx_hash', 'evt_index'], + ) +}} + +{% set project_name = 'ReadySwap' %} +{% set project_start_date = '2023-05-12' %} +{% set blockchain = 'ethereum' %} +{% set bot_deployer_1 = '0xCf695491Dd1Afff04C50892dE0d758641e6D7Afd' %} +{% set fee_wallet_1 = '0x3d91e131Cc353018B4e95b7A5a475e8681fa6790' %} +{% set weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %} +{% set fee_token_symbol = 'ETH' %} + +with + bot_contracts as ( + select address + from {{ source('ethereum', 'creation_traces') }} + where + ("from" = {{ bot_deployer_1 }}) + and block_time >= timestamp '{{project_start_date}}' + ), + bot_trades as ( + select + trades.block_time, + amount_usd, + if(token_sold_address = {{ weth }}, 'Buy', 'Sell') as type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + project, + version, + token_pair, + project_contract_address, + tx_from as user, + tx_to as bot, + trades.tx_hash, + evt_index + from {{ source('dex', 'trades') }} as trades + join bot_contracts on trades.tx_to = bot_contracts.address + where + trades.blockchain = '{{blockchain}}' + {% if is_incremental() %} + and {{ incremental_predicate('trades.block_time') }} + {% else %} and trades.block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), + highest_event_index_for_each_trade as ( + select tx_hash, max(evt_index) as highest_event_index + from bot_trades + group by tx_hash + ), + fee_payments as ( + select + tx_hash, + block_number, + sum(value) as fee_gwei + from {{ source('ethereum', 'traces') }} + where + to = {{ fee_wallet_1 }} + and value > 0 + {% if is_incremental() %} and {{ incremental_predicate('block_time') }} + {% else %} and block_time >= timestamp '{{project_start_date}}' + {% endif %} + group by tx_hash, block_number + ), + bot_eth_deposits as ( + select + tx_hash, + block_number, + sum(value) as deposit_gwei + from {{ source('ethereum', 'traces') }} + join bot_contracts on to = bot_contracts.address + where + {% if is_incremental() %} {{ incremental_predicate('block_time') }} + {% else %} block_time >= timestamp '{{project_start_date}}' + {% endif %} + and value > 0 + group by tx_hash, block_number + ), + bot_deposits_and_fee_payments as ( + select + coalesce(bot_eth_deposits.tx_hash, fee_payments.tx_hash) as tx_hash, + coalesce(bot_eth_deposits.block_number, fee_payments.block_number) as block_number, + coalesce(fee_gwei, cast(0 AS UINT256)) as fee_gwei, + coalesce(deposit_gwei, cast(0 AS UINT256)) as deposit_gwei + from fee_payments + full outer join bot_eth_deposits on fee_payments.tx_hash = bot_eth_deposits.tx_hash + ) +select + block_time, + date_trunc('day', bot_trades.block_time) as block_date, + date_trunc('month', bot_trades.block_time) as block_month, + '{{project_name}}' as bot, + block_number, + '{{blockchain}}' as blockchain, + -- Trade + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + -- Fees + round( + cast(fee_gwei as double) / cast(deposit_gwei as double), + 4 -- Round feePercentage to 0.01% steps + ) as fee_percentage_fraction, + (fee_gwei / 1e18) * price as fee_usd, + fee_gwei / 1e18 fee_token_amount, + '{{fee_token_symbol}}' as fee_token_symbol, + {{ weth }} as fee_token_address, + -- Dex + project, + version, + token_pair, + project_contract_address, + -- User + user as user, + bot_trades.tx_hash, + evt_index, + if(evt_index = highest_event_index, true, false) as is_last_trade_in_transaction +from bot_trades +join + highest_event_index_for_each_trade + on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash +left join bot_deposits_and_fee_payments on bot_trades.tx_hash = bot_deposits_and_fee_payments.tx_hash +left join + {{ source('prices', 'usd') }} + on ( + blockchain = '{{blockchain}}' + and contract_address = {{ weth }} + and minute = date_trunc('minute', block_time) + {% if is_incremental() %} and {{ incremental_predicate('minute') }} {% endif %} + ) +order by block_time desc, evt_index desc diff --git a/dbt_subprojects/dex/seeds/bot_trades/readyswap/readyswap_ethereum_trades_seed.csv b/dbt_subprojects/dex/seeds/bot_trades/readyswap/readyswap_ethereum_trades_seed.csv new file mode 100644 index 00000000000..ee3a5c3659c --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/readyswap/readyswap_ethereum_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction +2024-07-22 14:22:35.000 UTC,2024-07-22 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20362638,ethereum,345.40629,Buy,422329649.8284222,DMAGA,0x07b74763b630f59eba4f711b4745a4b38dcc15ee,0.0995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.0043,1.73571,0.0005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,DMAGA-WETH,0xa34b6c3086737b6ded2908b08994ade3aed941e8,0x7cdd83f650f583dcbd53bf3507ab3a8ca8f7c35e,0x68c30a2223e31de4a8a1ebf281d88a332c0a2d7598b9b343a208889cc7795dd3,29,true +2024-07-31 10:07:23.000 UTC,2024-07-31 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20425833,ethereum,3301.5890999999997,Buy,27100.76761123,NEIRO,0xee2a03aa6dacf51c18679c516ad5283d8e7c2637,0.995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,16.590899999999998,0.005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,NEIRO-WETH,0x3885fbe4cd8aed7b7e9625923927fa1ce30662a3,0x0b7c57a13b1fcf185cbdf40382c721429b4352f0,0xafda1b81ef6d67bff0b990d9ce011e82fab39478299448409046ffcbf43a87e3,14,true +2024-07-16 21:13:11.000 UTC,2024-07-16 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20321686,ethereum,15.944534061147703,Sell,0.004630274096176523,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,,,0xd40c688da9df74e03566eaf0a7c754ed98fbb8cc,0.0025,0.0797226703057364,0.000023151370480882,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,,0x8ee1270d83705e7202e9b56aa7e15eeed58c046b,0xfcf058d3219fb91383a0f2f5972a84d7951147a1,0x29833ead514731eeea0004aa416c385e022079427ce8a281d603e2ab9b4eaa84,374,true +2024-07-25 07:11:47.000 UTC,2024-07-25 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20381989,ethereum,303.2560508324369,Sell,0.09554772275878877,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,8414.655882369,DRIP,0xb8a914a00664e9361eae187468eff94905dfbc15,0.0025,1.5162802541621818,0.000477738613793943,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,DRIP-WETH,0x4374eead5e21540f9ce0695ebb92708313d1f42b,0x9c3543ffc3dc675dceecaa430f74a1dc8fc0874b,0x858f89a07d1636e29359b40bf475050ae1013a32a338eefd17a3d65997fedab1,225,true +2024-07-24 06:26:11.000 UTC,2024-07-24 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20374600,ethereum,350.62905929124753,Sell,0.1017330495599228,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,584415863606.6559,Mogei,0xb1c8f9a6ced16d5eac825c59afb9c76504941158,0.0025,1.7531452964562342,0.000508665247799613,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,Mogei-WETH,0x112a9f103222060c6fa5b8ec576cd559c94e43f0,0x9c3543ffc3dc675dceecaa430f74a1dc8fc0874b,0x58dcf2edc13a845410a47dbe27f46b7475e41e14d4676fd87fb08dde46f5a287,173,true +2024-07-18 11:06:11.000 UTC,2024-07-18 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20332996,ethereum,850.4427385211566,Sell,0.24686721351348836,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,471283.4902592069,TRUMP,0x194605aa511d90f1cbfec2d6aa61c3d713f7157e,0.0025,4.25221369260578,0.001234336067567441,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TRUMP-WETH,0xc82f817bb2dbbdee88f954e0c42332662b8870fa,0x9c3543ffc3dc675dceecaa430f74a1dc8fc0874b,0x126156ad631ffb8d78f637635f90ea66852f11de0cf524db7f2c1f48053e3b48,204,true +2024-07-18 19:55:11.000 UTC,2024-07-18 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20335630,ethereum,379.409454825,Buy,250493711927.0643,WWNF,0x2ec6603cff128dd4500e6edc90cf4a25050f37b3,0.1113405,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,1.906580175,0.0005595,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,WETH-WWNF,0x921b9fc57124651642678a1865fad627e3b8eb4d,0x2de65f84526dc07fd874b43047b34aa5bc1cb288,0xc9321e9481eda34506ba6a9ffb42118c4b215fe2ae98adaa41cafb3a1c9f2ee7,146,true +2024-07-30 05:55:59.000 UTC,2024-07-30 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20417432,ethereum,3294.5643999999998,Buy,63220.338506264,NEIRO,0xee2a03aa6dacf51c18679c516ad5283d8e7c2637,0.995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,16.5556,0.005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,NEIRO-WETH,0x3885fbe4cd8aed7b7e9625923927fa1ce30662a3,0xac3a26d1580104febcddb8ec96df42b46c28928d,0x4a468319d8711bb0a5ee6867cf8922b492a7d9c3c16ba37e137ed49810e619d5,263,true +2024-07-31 16:56:11.000 UTC,2024-07-31 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20427865,ethereum,5267.304618285685,Sell,1.599341905461704,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,44048.834400221,NEIRO,0xee2a03aa6dacf51c18679c516ad5283d8e7c2637,0.0025,26.336523091428425,0.00799670952730852,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,NEIRO-WETH,0x3885fbe4cd8aed7b7e9625923927fa1ce30662a3,0xac3a26d1580104febcddb8ec96df42b46c28928d,0xbd333a302493f2858aec79108ee09f1ee7f9a63f72adc17abaf871e2ef0523c6,83,true +2024-07-10 06:45:35.000 UTC,2024-07-10 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20274391,ethereum,154.77822,Buy,449.5044853880837,NATOR,0x6f483e2828da4373fc86ea31293137a4270f4762,0.04975,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,0.77778,0.00025,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,NATOR-WETH,0x983f144ff1a7ce824e26b02a103f6e9c1d7e3a3f,0xffa6eab550d571eb0c473142475a759e1492c7a3,0x5c0604a5d1540eaa06089c7429452077090c53dfb059c19056201278d5906eda,260,true +2024-07-16 01:31:23.000 UTC,2024-07-16 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20315798,ethereum,3458.7294500000003,Buy,270291249.7936392,COOMER,0x494930dabcfa57748a4c4788c0054f723a789047,0.995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,17.38055,0.005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,COOMER-WETH,0xf44c7cb42e6d4f74568752b7b1443c319f97eaf3,0x0b7c57a13b1fcf185cbdf40382c721429b4352f0,0x38ae5b89b574fbb4cd97485249248c9896213be5779f9e0869791dab2bb4d056,14,true +2024-07-19 20:34:47.000 UTC,2024-07-19 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20343000,ethereum,3484.6492,Buy,65598.387221542,SWAG,0x36c7188d64c44301272db3293899507eabb8ed43,0.995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,17.5108,0.005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,SWAG-WETH,0x0f388ecdbc128083bfe317b00de2c25fbe9f24d5,0x0b7c57a13b1fcf185cbdf40382c721429b4352f0,0x95796ac0ec0d3d903d7dd9146dbf77cc99317c24f24c0db9564c43bddf06cec8,69,true +2024-07-15 04:33:35.000 UTC,2024-07-15 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20309551,ethereum,13271.588600000001,Buy,10476342.955435243,WOJAK,0x5026f006b85729a8b14553fae6af249ad16c9aab,3.98,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,66.6914,0.02,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,WETH-WOJAK,0x0f23d49bc92ec52ff591d091b3e16c937034496e,0x0b7c57a13b1fcf185cbdf40382c721429b4352f0,0x5443ab276759d1c5a0e7c61f05387731cbf1fc9de8528def209a3754964acc35,4,true +2024-07-29 16:21:47.000 UTC,2024-07-29 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20413384,ethereum,527.7406279877619,Sell,0.15953465174962572,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,65772.866040966,SEX,0x92f04e0c56eef8b6bdbade5448105dc78087887d,0.0025,2.6387031399388072,0.000797673258748128,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,SEX-WETH,0x087edec2bab72f1bbc4fda1e431bea3cc5db5a9c,0x960f81aefeabb64250c17df87d5311e1814ab791,0xb0fde0cfac973a3683ee54a2c8b28ec5aaf60f1bfa69a554eee8c90c31edfbc0,258,true +2024-07-17 05:32:59.000 UTC,2024-07-17 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20324179,ethereum,360.6876433328931,Sell,0.10276762476220265,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,10098040337.961311,PEEZY,0x69ee720c120ec7c9c52a625c04414459b3185f23,0.0025,1.8034382166644645,0.000513838123811013,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,PEEZY-WETH,0x06acf8b25ab8ce249f487d30d78be4fc021cff8a,0x9c3543ffc3dc675dceecaa430f74a1dc8fc0874b,0x158ed62055b4fd7487325df6ec8aab44ff9c0e05e1508caefe8384d6a283fd0c,343,true +2024-07-23 10:30:35.000 UTC,2024-07-23 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20368644,ethereum,310.1347147333576,Sell,0.08803842335847233,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,1707251.6554004955,TRUMPZ,0x8c68a74a69e2cd2815cad9c0379fccb960f64cdd,0.0025,1.5506735736667858,0.000440192116792361,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,TRUMPZ-WETH,0xf5bc62f2f0ac3d5d18c564d74b9b810f284cf59f,0x404dc1f5f7286eb06854771e69b7789c7d81ea7c,0xa20b7ffb5f8da40eecc338b35fe91e10911485e6ba3d889ff5302dcb3ebdcd2e,25,true +2024-07-22 11:09:47.000 UTC,2024-07-22 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20361682,ethereum,334.28769966243993,Sell,0.095642758338633,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,8363830.977371112,BEBE,0xe5d4032078f9c85b6290f2c96de2dc8e2f08f14f,0.0025,1.6714384983121995,0.000478213791693165,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,BEBE-WETH,0x542ef1edf02a4e1e7a48789faf090137fac47868,0x037d6d7ee801c624cd62bdf3203e0150dbd3f699,0xfb23b381e28d1f5604d407574d0043933e47005547ab794d34cbff46f213b414,24,true +2024-07-19 08:57:11.000 UTC,2024-07-19 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20339524,ethereum,338.016425,Buy,176406375.92947543,BUMP,0xc423de90302f3a6d37df24f097f706089e18f95c,0.0995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,1.6985750000000002,0.0005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,BUMP-WETH,0xda739f15ce628702c9a63eea77fae41d3e81035b,0x9c3543ffc3dc675dceecaa430f74a1dc8fc0874b,0x7902c12c94bf505e968cd32eb84c216eba5f31df42c281e3cb780c60e5a874f5,282,true +2024-07-22 16:23:23.000 UTC,2024-07-22 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20363239,ethereum,344.53765500000003,Buy,774928.712843622,HARRIS,0xc69aa0d3b6b0043a3a36ac9fa9b6c479b3a7e105,0.0995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,1.7313450000000001,0.0005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,HARRIS-WETH,0x8e8a5dd7960a428cced2b4e0c2054ea7888ec75e,0x9c3543ffc3dc675dceecaa430f74a1dc8fc0874b,0x8425d1571d54625747bcf03a1cdb759c0edf11671b99d173c58989f167f6e417,234,true +2024-07-18 23:47:23.000 UTC,2024-07-18 00:00:00.000 UTC,2024-07-01 00:00:00.000 UTC,ReadySwap,20336787,ethereum,3418.5911499999997,Buy,388009323.75188565,BTC,0x43fd9de06bb69ad771556e171f960a91c42d2955,0.995,WETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.005,17.17885,0.005,ETH,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,uniswap,2,BTC-WETH,0xc5f05ce6c07f203b82ad9e1ba84010729af351fc,0xac3a26d1580104febcddb8ec96df42b46c28928d,0x7fab2adbadc06f3ad4bb6d493c0cbb312c528bb1a217ebbf15b198ececda3d0a,827,true diff --git a/dbt_subprojects/dex/seeds/bot_trades/readyswap/schema.yml b/dbt_subprojects/dex/seeds/bot_trades/readyswap/schema.yml new file mode 100644 index 00000000000..a37643174a2 --- /dev/null +++ b/dbt_subprojects/dex/seeds/bot_trades/readyswap/schema.yml @@ -0,0 +1,13 @@ +version: 2 + +seeds: + - name: readyswap_ethereum_trades_seed + config: + column_types: + version: varchar + token_bought_address: varbinary + token_sold_address: varbinary + fee_token_address: varbinary + project_contract_address: varbinary + user: varbinary + tx_hash: varbinary From b7fcee8b5c03bbd0e729b9749e7db849bd8822f0 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:48:17 -0500 Subject: [PATCH 60/68] Revert "zereox - v2 macro replacements 2 (#7168)" (#7233) This reverts commit e025533a5849c2d4d49df683c851be22ac80a057. --- .../models/_project/zeroex/zeroex_v2.sql | 163 +++++---- .../arbitrum/zeroex_arbitrum_schema.yml | 4 +- .../zeroex_arbitrum_settler_trades.sql | 310 +++++++++++++++++ .../arbitrum/zeroex_v2_arbitrum_trades.sql | 70 ---- .../avalanche_c/zeroex_avalanche_c_schema.yml | 4 +- .../zeroex_avalanche_c_settler_trades.sql | 310 +++++++++++++++++ .../zeroex_v2_avalanche_c_trades.sql | 70 ---- .../zeroex/base/zeroex_v2_base_trades.sql | 13 +- .../zeroex/blast/zeroex_blast_schema.yml | 4 +- .../blast/zeroex_blast_settler_trades.sql | 301 +++++++++++++++++ .../zeroex/blast/zeroex_v2_blast_trades.sql | 70 ---- .../zeroex/bnb/zeroex_bnb_schema.yml | 4 +- .../zeroex/bnb/zeroex_bnb_settler_trades.sql | 312 ++++++++++++++++++ .../zeroex/bnb/zeroex_v2_bnb_trades.sql | 71 ---- .../ethereum/zeroex_v2_ethereum_trades.sql | 13 +- .../zeroex/linea/zeroex_linea_schema.yml | 4 +- .../linea/zeroex_linea_settler_trades.sql | 304 +++++++++++++++++ .../zeroex/linea/zeroex_v2_linea_trades.sql | 71 ---- .../zeroex/mantle/zeroex_mantle_schema.yml | 4 +- .../mantle/zeroex_mantle_settler_trades.sql | 296 +++++++++++++++++ .../zeroex/mantle/zeroex_v2_mantle_trades.sql | 70 ---- .../zeroex/mode/zeroex_mode_schema.yml | 111 ------- .../zeroex/mode/zeroex_v2_mode_trades.sql | 61 ---- .../optimism/zeroex_optimism_schema.yml | 2 +- .../zeroex_optimism_settler_trades.sql | 312 ++++++++++++++++++ .../optimism/zeroex_v2_optimism_trades.sql | 71 ---- .../polygon/zeroex_v2_polygon_trades.sql | 13 +- .../zeroex/scroll/zeroex_scroll_schema.yml | 4 +- .../scroll/zeroex_scroll_settler_trades.sql | 302 +++++++++++++++++ .../zeroex/scroll/zeroex_v2_scroll_trades.sql | 71 ---- .../zeroex/zeroex_api_fills_deduped.sql | 27 +- .../models/_projects/zeroex/zeroex_trades.sql | 2 +- .../zeroex_blast_settler_trades_sample.csv | 5 +- .../zeroex_linea_settler_trades_sample.csv | 4 +- .../seeds/_project/zeroex/mode/_schema.yml | 11 - .../zeroex_mode_settler_trades_sample.csv | 3 - 36 files changed, 2566 insertions(+), 901 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql delete mode 100644 dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql delete mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml delete mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv diff --git a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql index 36771b166bd..4589ba128b7 100644 --- a/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql +++ b/dbt_subprojects/dex/macros/models/_project/zeroex/zeroex_v2.sql @@ -1,17 +1,15 @@ {% macro zeroex_settler_txs_cte(blockchain, start_date) %} WITH tbl_addresses AS ( SELECT - varbinary_to_int256 (topic1) as token_id, - bytearray_substring(logs.topic3,13,20) as settler_address, + token_id, + "to" AS settler_address, block_time AS begin_block_time, block_number AS begin_block_number FROM - {{ source( blockchain, 'logs') }} + {{ source('nft', 'transfers') }} WHERE contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae - and topic0 = 0xaa94c583a45742b26ac5274d230aea34ab334ed5722264aa5673010e612bc0b2 - AND block_time >= DATE '2024-04-04' - /* no need to filter incrmeentally, as this returns small subset of addresses tracked as settler address over time */ + AND blockchain = '{{ blockchain }}' ), tbl_end_times AS ( @@ -78,29 +76,20 @@ SELECT * FROM settler_txs {% endmacro %} {% macro zeroex_v2_trades(blockchain, start_date, is_direct=true) %} -/* - this macro is called twice -- once for direct, once for indirect trades - this is required due to how logs joins back to input settler address tx's -*/ WITH tbl_all_logs AS ( SELECT logs.tx_hash, logs.block_time, logs.block_number, index, - case when (varbinary_substring(logs.topic2, 13, 20) in (settler_address)) - and varbinary_substring(logs.topic1, 13, 20) != 0x0000000000000000000000000000000000000000 - then varbinary_substring(logs.topic1, 13, 20) else tx_from - end as taker_, - case when (varbinary_substring(logs.topic1, 13, 20) in (tx_from, settler_address)) - then logs.contract_address - end as taker_token_, - case when (varbinary_substring(logs.topic2, 13, 20) in (settler_address, tx_from)) - then logs.contract_address - end as maker_token_, - case when (varbinary_substring(logs.topic1, 13, 20) in (tx_from, settler_address)) - then try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) - end as taker_amount_, + CASE WHEN ((varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) OVER (PARTITION BY logs.tx_hash ORDER BY index)) OR + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + THEN 1 END AS valid, + COALESCE(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) OVER (PARTITION BY logs.tx_hash ORDER BY index)) AS taker, + logs.contract_address AS maker_token, + first_value(logs.contract_address) OVER (PARTITION BY logs.tx_hash ORDER BY index) AS taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) AS int256)) OVER (PARTITION BY logs.tx_hash ORDER BY index) AS taker_amount, try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) AS int256) AS maker_amount, method_id, tag, @@ -109,8 +98,7 @@ WITH tbl_all_logs AS ( st.settler_address AS contract_address, topic1, topic2, - tx_to, - tx_from + tx_to FROM {{ source(blockchain, 'logs') }} AS logs JOIN @@ -126,37 +114,32 @@ WITH tbl_all_logs AS ( AND topic0 IN (0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c) + AND topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 AND zid != 0xa00000000000000000000000 - {% if is_direct %} AND (logs.tx_to = settler_address) - AND (tx_from in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) - OR tx_to in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) - ) - {% endif %} - {% if not is_direct %} + {% else %} + AND (tx_to = settler_address OR varbinary_substring(logs.topic2, 13, 20) != 0x0000000000000000000000000000000000000000) + AND logs.tx_to != varbinary_substring(logs.topic1,13,20) AND logs.tx_to != settler_address - and ( settler_address in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) - OR tx_from in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) - OR tx_to in (bytearray_substring(logs.topic2,13,20), bytearray_substring(logs.topic1,13,20)) - ) + {% endif %} + {% if is_direct %} + AND (st.settler_address = bytearray_substring(logs.topic1,13,20) + OR st.settler_address = bytearray_substring(logs.topic2,13,20) + OR logs.tx_from = varbinary_substring(logs.topic1,13,20) + OR logs.tx_from = varbinary_substring(logs.topic2,13,20) + OR logs.tx_to = varbinary_substring(logs.topic1,13,20)) {% endif %} ), tbl_valid_logs AS ( SELECT - * - ,FIRST_VALUE(taker_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS taker - ,FIRST_VALUE(taker_amount_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS taker_amount - ,LAST_VALUE(maker_token_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS maker_token - ,FIRST_VALUE(taker_token_) IGNORE NULLS OVER (PARTITION BY tx_hash ORDER BY index - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS taker_token - ,ROW_NUMBER() OVER (PARTITION BY tx_hash ORDER BY index DESC) AS rn + *, + ROW_NUMBER() OVER (PARTITION BY tx_hash ORDER BY valid, index DESC) AS rn FROM tbl_all_logs + WHERE + taker_token != maker_token ) SELECT * FROM tbl_valid_logs @@ -165,21 +148,51 @@ WHERE rn = 1 {% macro zeroex_v2_trades_detail(blockchain, start_date) %} WITH tokens AS ( - SELECT * - FROM {{ source('tokens', 'erc20') }} - WHERE blockchain = '{{blockchain}}' + SELECT DISTINCT token, te.* + FROM ( + SELECT maker_token AS token FROM tbl_trades + UNION ALL + SELECT taker_token FROM tbl_trades + ) t + JOIN {{ source('tokens', 'erc20') }} AS te ON te.contract_address = t.token + WHERE te.blockchain = '{{blockchain}}' ), prices AS ( - SELECT * - FROM {{ source('prices', 'usd') }} + SELECT DISTINCT pu.* + FROM {{ source('prices', 'usd') }} AS pu + JOIN tbl_trades ON (pu.contract_address IN (taker_token, maker_token)) AND DATE_TRUNC('minute', block_time) = minute WHERE - blockchain = '{{blockchain}}' + pu.blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('pu.minute') }} + {% else %} + AND pu.minute >= DATE '{{start_date}}' + {% endif %} +), + +fills AS ( + WITH signatures AS ( + SELECT DISTINCT signature + FROM {{ source(blockchain, 'logs_decoded') }} l + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') {% if is_incremental() %} - AND {{ incremental_predicate('minute') }} + AND {{ incremental_predicate('l.block_time') }} {% else %} - AND minute >= DATE '{{start_date}}' + AND l.block_time >= DATE '{{start_date}}' {% endif %} + ) + SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within + FROM {{ source(blockchain, 'logs') }} l + JOIN signatures ON signature = topic0 + JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number + {% if is_incremental() %} + WHERE {{ incremental_predicate('l.block_time') }} + {% else %} + WHERE l.block_time >= DATE '{{start_date}}' + {% endif %} + GROUP BY 1,2,3 ), results AS ( @@ -191,10 +204,10 @@ results AS ( trades.contract_address, method_id, trades.tx_hash, - tx_from, - tx_to, + "from" AS tx_from, + "to" AS tx_to, trades.index AS tx_index, - taker, + CASE WHEN varbinary_substring(tr.data,1,4) = 0x500c22bc THEN "from" ELSE taker END AS taker, CAST(NULL AS varbinary) AS maker, taker_token, taker_token AS token_sold_address, @@ -211,9 +224,19 @@ results AS ( maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS token_bought_amount, maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, - tag + tag, + fills_within FROM tbl_trades trades + JOIN + {{ source(blockchain, 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{start_date}}' + {% endif %} + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number LEFT JOIN tokens tt ON tt.blockchain = '{{blockchain}}' AND tt.contract_address = taker_token LEFT JOIN @@ -235,7 +258,7 @@ results_usd AS ( SELECT '{{blockchain}}' AS blockchain, '0x-API' AS project, - 'v2' AS version, + 'settler' AS version, DATE_TRUNC('day', block_time) block_date, DATE_TRUNC('month', block_time) AS block_month, block_time, @@ -273,28 +296,4 @@ order by block_time desc {% macro zeroex_v2_trades_indirect(blockchain, start_date) %} {{ zeroex_v2_trades(blockchain, start_date, false) }} -{% endmacro %} - -{% macro zeroex_v2_trades_fills_count(blockchain, start_date) %} - WITH signatures AS ( - SELECT DISTINCT signature - FROM {{ source(blockchain, 'logs_decoded') }} l - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - WHERE event_name IN ('TokenExchange', 'OtcOrderFilled', 'SellBaseToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') - {% if is_incremental() %} - AND {{ incremental_predicate('l.block_time') }} - {% else %} - AND l.block_time >= DATE '{{start_date}}' - {% endif %} - ) - SELECT tt.tx_hash, tt.block_number, tt.block_time, COUNT(*) AS fills_within - FROM {{ source(blockchain, 'logs') }} l - JOIN signatures ON signature = topic0 - JOIN tbl_trades tt ON tt.tx_hash = l.tx_hash AND l.block_time = tt.block_time AND l.block_number = tt.block_number - {% if is_incremental() %} - WHERE {{ incremental_predicate('l.block_time') }} - {% else %} - WHERE l.block_time >= DATE '{{start_date}}' - {% endif %} - GROUP BY 1,2,3 {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml index 3ca18250dcb..3498e9df2ef 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_schema.yml @@ -206,7 +206,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_v2_arbitrum_trades + - name: zeroex_arbitrum_settler_trades meta: blockchain: arbitrum project: zeroex @@ -214,7 +214,7 @@ models: config: tags: ['arbitrum','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql new file mode 100644 index 00000000000..815021d5009 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_arbitrum_settler_trades.sql @@ -0,0 +1,310 @@ +{{ config( + schema = 'zeroex_arbitrum', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'arbitrum' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('arbitrum', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'arbitrum' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address is not null or tr.to in (0x0000000000001fF3684f28c67538d4D072C22734)) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + then 1 end as valid, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('arbitrum', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash + AND logs.block_time = st.block_time + AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = bytearray_substring(logs.topic1,13,20) + or logs.tx_from = bytearray_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'arbitrum' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'arbitrum' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('arbitrum', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellarbitrumToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('arbitrum', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('arbitrum', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'arbitrum' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'arbitrum' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'arbitrum' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'arbitrum' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'arbitrum' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, + 0xaf88d065e77c8cc2239327c5edb3a432268e5831, + 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, + 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, + 0x912ce59144191c1204e64559fe8253a0e49e6548) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x82af49447d8a07e3bd95bd0d56f35241523fbab1, + 0xaf88d065e77c8cc2239327c5edb3a432268e5831, + 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, + 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, + 0x912ce59144191c1204e64559fe8253a0e49e6548) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql deleted file mode 100644 index 6c70a2e8644..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/arbitrum/zeroex_v2_arbitrum_trades.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - schema = 'zeroex_v2_arbitrum', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'arbitrum' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml index 98b01576297..48deac58eea 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_schema.yml @@ -150,7 +150,7 @@ models: name: fills_within description: "fills in then multihop, if present" - - name: zeroex_v2_avalanche_c_trades + - name: zeroex_avalanche_c_settler_trades meta: blockchain: avalanche_c project: zeroex @@ -158,7 +158,7 @@ models: config: tags: ['avalanche_c','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql new file mode 100644 index 00000000000..4434aa4ad0c --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_avalanche_c_settler_trades.sql @@ -0,0 +1,310 @@ +{{ config( + schema = 'zeroex_avalanche_c', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'avalanche_c' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('avalanche_c', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'avalanche_c' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000005E88410CcDFaDe4a5EfaE4b49562 ) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + then 1 end as valid, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('avalanche_c', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash + AND logs.block_time = st.block_time + AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = bytearray_substring(logs.topic1,13,20) + or logs.tx_from = bytearray_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by valid, index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'avalanche_c' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'avalanche_c' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('avalanche_c', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'Sellavalanche_cToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('avalanche_c', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('avalanche_c', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'avalanche_c' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'avalanche_c' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'avalanche_c' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'avalanche_c' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'avalanche_c' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, + 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, + 0x152b9d0fdc40c096757f570a51e494bd4b943e50, + 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, + 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7, + 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e, + 0x152b9d0fdc40c096757f570a51e494bd4b943e50, + 0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab, + 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql deleted file mode 100644 index e570380c699..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/avalanche_c/zeroex_v2_avalanche_c_trades.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - schema = 'zeroex_v2_avalanche_c', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'avalanche_c' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql index 2dc75f30a85..d69c3174508 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/base/zeroex_v2_base_trades.sql @@ -46,14 +46,6 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), trade_details as ( {{ zeroex_v2_trades_detail( @@ -65,6 +57,5 @@ trade_details as ( ) select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml index 4361c49a24b..598e21561d9 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_v2_blast_trades + - name: zeroex_blast_settler_trades meta: blockchain: blast project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['blast','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql new file mode 100644 index 00000000000..9fe304e77ba --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql @@ -0,0 +1,301 @@ +{{ config( + schema = 'zeroex_blast', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'blast' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('blast', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'blast' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('blast', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = varbinary_substring(logs.topic1,13,20) + or logs.tx_from = varbinary_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where maker_token != taker_token + ) + select * from tbl_valid_logs + where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'blast' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'blast' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('blast', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellblastToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('blast', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('blast', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'blast' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'blast' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'blast' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'blast' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'blast' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql deleted file mode 100644 index fca2b0c42a4..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_v2_blast_trades.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - schema = 'zeroex_v2_blast', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'blast' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml index 4eff3902e3a..e185fda2fd3 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_schema.yml @@ -197,7 +197,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_v2_bnb_trades + - name: zeroex_bnb_settler_trades meta: blockchain: bnb project: zeroex @@ -205,7 +205,7 @@ models: config: tags: ['bnb','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql new file mode 100644 index 00000000000..06d2c811649 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_bnb_settler_trades.sql @@ -0,0 +1,312 @@ +{{ config( + schema = 'zeroex_bnb', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'bnb' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('bnb', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'bnb' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734 ) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + then 1 end as valid, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('bnb', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash + AND logs.block_time = st.block_time + AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = bytearray_substring(logs.topic1,13,20) + or logs.tx_from = bytearray_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by valid, index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'bnb' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'bnb' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('bnb', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellbnbToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('bnb', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('bnb', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'bnb' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'bnb' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'bnb' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'bnb' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'bnb' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x55d398326f99059ff775485246999027b3197955, + 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c, + 0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d, + 0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c, + 0x2170ed0880ac9a755fd29b2688956bd959f933f8, + 0xe9e7cea3dedca5984780bafc599bd69add087d56) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x55d398326f99059ff775485246999027b3197955, + 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c, + 0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d, + 0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c, + 0x2170ed0880ac9a755fd29b2688956bd959f933f8, + 0xe9e7cea3dedca5984780bafc599bd69add087d56) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql deleted file mode 100644 index 687faaab8ac..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/bnb/zeroex_v2_bnb_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_bnb', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'bnb' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql index 256d8476c7d..ceea2b3d384 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/ethereum/zeroex_v2_ethereum_trades.sql @@ -46,14 +46,6 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), trade_details as ( {{ zeroex_v2_trades_detail( @@ -65,6 +57,5 @@ trade_details as ( ) select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml index ac24be9a6b9..35919de1e65 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_v2_linea_trades + - name: zeroex_linea_settler_trades meta: blockchain: linea project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['linea','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql new file mode 100644 index 00000000000..4267d287b96 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_linea_settler_trades.sql @@ -0,0 +1,304 @@ +{{ config( + schema = 'zeroex_linea', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'linea' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('linea', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'linea' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x000000000000175a8b9bC6d539B3708EEd92EA6c) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('linea', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = varbinary_substring(logs.topic1,13,20) + or logs.tx_from = varbinary_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where maker_token != taker_token + ) + select * from tbl_valid_logs + where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'linea' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'linea' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('linea', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SelllineaToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('linea', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('linea', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'linea' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'linea' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'linea' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'linea' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'linea' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, + 0x176211869ca2b568f2a7d4ee941e073a821ee1ff, + 0xa219439258ca9da29e9cc4ce5596924745e12b93, + 0x3aab2285ddcddad8edf438c1bab47e1a9d05a9b4 ) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, + 0x176211869ca2b568f2a7d4ee941e073a821ee1ff, + 0xa219439258ca9da29e9cc4ce5596924745e12b93, + 0x3aab2285ddcddad8edf438c1bab47e1a9d05a9b4 ) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql deleted file mode 100644 index 6316ca85683..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/linea/zeroex_v2_linea_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_linea', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'linea' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml index 418999bf150..bbbabcb2e22 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_v2_mantle_trades + - name: zeroex_mantle_settler_trades meta: blockchain: mantle project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['mantle','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql new file mode 100644 index 00000000000..35bd8dc974e --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_mantle_settler_trades.sql @@ -0,0 +1,296 @@ +{{ config( + schema = 'zeroex_mantle', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'mantle' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('mantle', 'traces') }} AS tr + JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'mantle' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0xca11bde05977b3631167028862be2a173976ca11) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('mantle', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where maker_token != taker_token + ) + select * from tbl_valid_logs + where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'mantle' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'mantle' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('mantle', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellmantleToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('mantle', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('mantle', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'mantle' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'mantle' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'mantle' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'mantle' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'mantle' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql deleted file mode 100644 index a8b93a02368..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mantle/zeroex_v2_mantle_trades.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - schema = 'zeroex_v2_mantle', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'mantle' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml deleted file mode 100644 index 8f56bbccc93..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_mode_schema.yml +++ /dev/null @@ -1,111 +0,0 @@ -version: 2 - -models: - - name: zeroex_v2_mode_trades - meta: - blockchain: mode - project: zeroex - contributors: rantum - config: - tags: ['mode','0x','dex_aggregator','dex','aggregator'] - description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - block_month - - block_date - - tx_hash - - evt_index - - check_seed: - seed_file: ref('zeroex_mode_settler_trades_sample') - match_columns: - - tx_hash - check_columns: - - taker - - maker_token - - taker_token - columns: - - &blockchain - name: blockchain - description: "Blockchain which the aggregator project is deployed" - - &block_date - name: block_date - description: "UTC event block date of each trade" - - &block_month - name: block_month - description: "UTC event block month of each trade" - - &block_time - name: block_time - description: "UTC event block time of each trade" - - &taker_symbol - name: taker_symbol - description: "Symbol of the token taker sells" - - &maker_symbol - name: maker_symbol - description: "Symbol of the token taker buys" - - &token_pair - name: token_pair - description: "Token pair traded" - - &taker_token_amount - name: taker_token_amount - description: "The after-decimal amount of the token taker sells" - - &taker_token_amount_raw - name: taker_token_amount_raw - description: "The raw amount of the token taker sells" - - &maker_token_amount - name: maker_token_amount - description: "The after-decimal amount of the token taker buys" - - &maker_token_amount_raw - name: maker_token_amount_raw - description: "The raw amount of the token taker buys" - - &volume_usd - name: volume_usd - description: "Trading volume measured in USD value" - - &taker_token - name: taker_token - description: "Contract address of the token taker sells" - - &maker_token - name: maker_token - description: "Contract address of the token taker buys" - - &maker - name: maker - description: "buyer of the trade" - - &taker - name: taker - description: "seller of the trade" - - &affiliate_address - name: affiliate_address - description: "The recipient address of the affiliate, or the applications that is using 0x API, for receiving affiliate fee" - - &tx_hash - name: tx_hash - description: "Transaction hash of the fill" - - &tx_from - name: tx_from - description: "Address which initiated the trade" - - &tx_to - name: tx_to - description: "Address which received the trade" - - &evt_index - name: evt_index - description: "Index of the corresponding order filled event" - - &type - name: type - description: "The liquidity route the order went thru" - - &swap_flag - name: swap_flag - description: "If the swap was filled/consumed thru 0x API" - - &contract_address - name: contract_address - desctiption: "The address of the contract which fired the fill/swap event" - - &fills_within - name: fills_within - description: "fills in then multihop, if present" - - - - - - - - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql deleted file mode 100644 index 55f96ade5bc..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/mode/zeroex_v2_mode_trades.sql +++ /dev/null @@ -1,61 +0,0 @@ -{{ config( - schema = 'zeroex_v2_mode', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'mode' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, cast(null as int) as fills_within - from trade_details t diff --git a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml index e83453577cb..8ad876a830c 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_schema.yml @@ -200,7 +200,7 @@ models: name: protocol_fee_paid_eth description: "The protocol fee paid in ETH" - - name: zeroex_v2_optimism_trades + - name: zeroex_optimism_settler_trades meta: blockchain: optimism project: zeroex diff --git a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql new file mode 100644 index 00000000000..3ec7000ea9b --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_optimism_settler_trades.sql @@ -0,0 +1,312 @@ +{{ config( + schema = 'zeroex_optimism', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'optimism' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('optimism', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'optimism' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000001fF3684f28c67538d4D072C22734) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + case when ( (varbinary_substring(logs.topic2, 13, 20) = logs.tx_from) OR + (varbinary_substring(logs.topic2, 13, 20) = first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) or + topic0 = 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65) + then 1 end as valid, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('optimism', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash + AND logs.block_time = st.block_time + AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = bytearray_substring(logs.topic1,13,20) + or logs.tx_from = bytearray_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by valid, index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'optimism' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'optimism' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('optimism', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SelloptimismToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('optimism', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('optimism', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'optimism' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'optimism' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'optimism' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'optimism' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'optimism' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x4200000000000000000000000000000000000006, + 0x7f5c764cbc14f9669b88837ca1490cca17c31607, + 0x4200000000000000000000000000000000000042, + 0x0b2c639c533813f4aa9d7837caf62653d097ff85, + 0x94b008aa00579c1307b0ef2c499ad98a8ce58e58, + 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x4200000000000000000000000000000000000006, + 0x7f5c764cbc14f9669b88837ca1490cca17c31607, + 0x4200000000000000000000000000000000000042, + 0x0b2c639c533813f4aa9d7837caf62653d097ff85, + 0x94b008aa00579c1307b0ef2c499ad98a8ce58e58, + 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql deleted file mode 100644 index fded3f2bf4b..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/optimism/zeroex_v2_optimism_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_optimism', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'optimism' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql index 6c45e4fbcff..1177284b18a 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/polygon/zeroex_v2_polygon_trades.sql @@ -46,14 +46,6 @@ tbl_trades AS ( SELECT * FROM zeroex_v2_trades_indirect ), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), trade_details as ( {{ zeroex_v2_trades_detail( @@ -65,6 +57,5 @@ trade_details as ( ) select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time + * + from trade_details diff --git a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml index 47a5f603a10..f001bd15c5e 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: zeroex_v2_scroll_trades + - name: zeroex_scroll_settler_trades meta: blockchain: scroll project: zeroex @@ -9,7 +9,7 @@ models: config: tags: ['scroll','0x','dex_aggregator','dex','aggregator'] description: > - 0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions. + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: diff --git a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql new file mode 100644 index 00000000000..0bfec20ce7a --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_scroll_settler_trades.sql @@ -0,0 +1,302 @@ +{{ config( + schema = 'zeroex_scroll', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'scroll' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('scroll', 'traces') }} AS tr + LEFT JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'scroll' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0x0000000000005E88410CcDFaDe4a5EfaE4b49562) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('scroll', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + AND ( (st.settler_address = bytearray_substring(logs.topic1,13,20)) + or (st.settler_address= bytearray_substring(logs.topic2,13,20)) + or logs.tx_from = varbinary_substring(logs.topic1,13,20) + or logs.tx_from = varbinary_substring(logs.topic2,13,20) + or logs.tx_to = varbinary_substring(logs.topic1,13,20) + ) + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where taker_token != maker_token + ) + select * from tbl_valid_logs where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'scroll' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'scroll' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('scroll', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellscrollToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('scroll', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('scroll', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'scroll' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'scroll' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'scroll' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'scroll' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'scroll' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x5300000000000000000000000000000000000004, + 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4, + 0xf55bec9cafdbe8730f096aa55dad6d22d44099df, + 0xca77eb3fefe3725dc33bccb54edefc3d9f764f97) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x5300000000000000000000000000000000000004, + 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4, + 0xf55bec9cafdbe8730f096aa55dad6d22d44099df, + 0xca77eb3fefe3725dc33bccb54edefc3d9f764f97) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql deleted file mode 100644 index 3afca6ccc8e..00000000000 --- a/dbt_subprojects/dex/models/_projects/zeroex/scroll/zeroex_v2_scroll_trades.sql +++ /dev/null @@ -1,71 +0,0 @@ -{{ config( - schema = 'zeroex_v2_scroll', - alias = 'trades', - materialized='incremental', - partition_by = ['block_month'], - unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], - on_schema_change='sync_all_columns', - file_format ='delta', - incremental_strategy='merge', - incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] -)}} - -{% set zeroex_settler_start_date = '2024-07-15' %} -{% set blockchain = 'scroll' %} - -WITH zeroex_tx AS ( - {{ - zeroex_settler_txs_cte( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -zeroex_v2_trades_direct AS ( - {{ - zeroex_v2_trades_direct( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -zeroex_v2_trades_indirect AS ( - {{ - zeroex_v2_trades_indirect( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} -), -tbl_trades AS ( - SELECT * - FROM zeroex_v2_trades_direct - UNION ALL - SELECT * - FROM zeroex_v2_trades_indirect -), -fills_count as( - {{ - zeroex_v2_trades_fills_count( - blockchain = blockchain, - start_date = zeroex_settler_start_date - ) - }} -), -trade_details as ( - {{ - zeroex_v2_trades_detail( - blockchain = blockchain, - start_date = zeroex_settler_start_date - - ) - }} - -) -select - t.*, fills_within - from trade_details t - left join fills_count f on t.tx_hash = f.tx_hash and t.block_time = f.block_time - \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index fbb62cea130..51563852cb7 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -1,7 +1,7 @@ {{ config( schema = 'zeroex' , alias = 'api_fills_deduped' - , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle","mode"]\', + , post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle"]\', "project", "zeroex", \'["rantum","bakabhai993"]\') }}' @@ -9,7 +9,7 @@ }} -{% set v1_models = [ +{% set zeroex_models = [ ref('zeroex_arbitrum_api_fills_deduped') ,ref('zeroex_avalanche_c_api_fills_deduped') ,ref('zeroex_base_api_fills_deduped') @@ -21,25 +21,24 @@ ,ref('zeroex_bnb_api_fills_deduped') ] %} -{% set v2_models = [ +{% set settler_models = [ ref('zeroex_v2_ethereum_trades') ,ref('zeroex_v2_base_trades') ,ref('zeroex_v2_polygon_trades') - ,ref('zeroex_v2_optimism_trades') - ,ref('zeroex_v2_bnb_trades') - ,ref('zeroex_v2_avalanche_c_trades') - ,ref('zeroex_v2_arbitrum_trades') - ,ref('zeroex_v2_scroll_trades') - ,ref('zeroex_v2_linea_trades') - ,ref('zeroex_v2_blast_trades') - ,ref('zeroex_v2_mantle_trades') - ,ref('zeroex_v2_mode_trades') + ,ref('zeroex_optimism_settler_trades') + ,ref('zeroex_bnb_settler_trades') + ,ref('zeroex_avalanche_c_settler_trades') + ,ref('zeroex_arbitrum_settler_trades') + ,ref('zeroex_scroll_settler_trades') + ,ref('zeroex_linea_settler_trades') + ,ref('zeroex_blast_settler_trades') + ,ref('zeroex_mantle_settler_trades') ] %} SELECT * FROM ( - {% for model in v1_models %} + {% for model in zeroex_models %} SELECT blockchain ,version @@ -78,7 +77,7 @@ UNION ALL SELECT * FROM ( - {% for model in v2_models %} + {% for model in settler_models %} SELECT blockchain ,version diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql index dc0608ac407..7f6826c10b6 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_trades.sql @@ -1,7 +1,7 @@ {{ config( schema = 'zeroex' ,alias = 'trades' - ,post_hook='{{ expose_spells(\'["ethereum","arbitrum", "optimism", "polygon","fantom","avalanche_c","bnb","base","scroll","linea","blast","mantle","mode"]\', + ,post_hook='{{ expose_spells(\'["ethereum","arbitrum", "optimism", "polygon","fantom","avalanche_c","bnb","base","scroll","linea","blast","mantle"]\', "project", "zeroex", \'["rantum","bakabhai993"]\') }}' diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv index 8d032b5eccf..6485f75e989 100644 --- a/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv +++ b/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv @@ -1,4 +1,3 @@ tx_hash,taker,taker_token,maker_token,taker_token_amount -0x1039b307c87496757057f2ff6355886434c167bbb91481a6948200f9731f01e9,0x34c241faf3e5ff210cd50f23d781f090fd8d6d43,0x4300000000000000000000000000000000000003,0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad,3.5882931897308494 -0x0189d26190c6498a93bf5e43463e87c11181f33cbb9d6477fe1c5921279773c6,0x1e42d0891a7328b650e9aebca35c135cc1693ee1,0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad,0x4300000000000000000000000000000000000003,20000 -0x03de7fc149d44a67dcd41522d887f6226b5a734ffd08d2f241bb20339fa69998,0xe9805ecab212eabf696cf458d2c4840a619ee6de,0x52f847356b38720b55ee18cb3e094ca11c85a192,0xd43d8adac6a4c7d9aeece7c3151fca8f23752cf8, +0x92f05d2cc3e693ae5863e5a3c08475a9fb62c1db76acce05461aa8538cb9689a,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0x4300000000000000000000000000000000000003,0x4300000000000000000000000000000000000004,1 +0x4477ae1598016d0abee946f6bd7a0f6cbdbd6a87a3dde5eae1007d9f6a8ced06,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0x4300000000000000000000000000000000000003,0x4300000000000000000000000000000000000004,1e-12 \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv index a45529dffba..6760f03e395 100644 --- a/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv +++ b/dbt_subprojects/dex/seeds/_project/zeroex/linea/zeroex_linea_settler_trades_sample.csv @@ -1,4 +1,2 @@ tx_hash,taker,taker_token,maker_token,taker_token_amount -0x0027e74f02780c84c30e0913cf4a56001d47c4d0830f9c0c036ed2641b1c861a,0xc0263992b8ef45e48d653683164ce40f32c0173a,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,0x4af15ec2a0bd43db75dd04e62faa3b8ef36b00d5,153.039629 -0x0032a240fba185828915257a67952aca9e3ed2c7df4508fa3b9b8a6df627b736,0xdbfd6dc67d3ce76b2c334d305527a5e6ec734da0,0xb5bedd42000b71fdde22d3ee8a79bd49a568fc8f,0x2416092f143378750bb29b79ed961ab195cceea5,0.2797467631837312 -0xa6f26819efd68a95c4a5ebed953026446084ba1b5f1dabb30a0a54f1c2df0593,0x48655b457be821670d42b22f94f98044b737f46b,0xaaaac83751090c6ea42379626435f805ddf54dc8,0x176211869ca2b568f2a7d4ee941e073a821ee1ff,94.86653636189624 \ No newline at end of file +0xfd32094a40aea663ed1662833709c1c3590989607abf99e70a18f5740c8fd043,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f,0xa219439258ca9da29e9cc4ce5596924745e12b93,0.000745504333903425 \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml b/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml deleted file mode 100644 index 4381886dd99..00000000000 --- a/dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 - -seeds: - - name: zeroex_mode_settler_trades_sample - config: - column_types: - tx_hash: varbinary - taker: varbinary - taker_token: varbinary - maker_token: varbinary - taker_token_amount: double \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv deleted file mode 100644 index e1355700bf2..00000000000 --- a/dbt_subprojects/dex/seeds/_project/zeroex/mode/zeroex_mode_settler_trades_sample.csv +++ /dev/null @@ -1,3 +0,0 @@ -tx_hash,taker,taker_token,maker_token,taker_token_amount -0xd7ace13835ceb119b071c508e8ee262fcecb5a0f2a1bfdd1b9b1f04afa73d94d,0x44c20316a06371ca5acb975974c18abfa7a14a5a,0xf0f161fda2712db8b566946122a5af183995e2ed,0x4200000000000000000000000000000000000006,5.5 -0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x6a660e56fa3b630a786cc4ae98859f8532d03de9,0x2416092f143378750bb29b79ed961ab195cceea5,238973 \ No newline at end of file From e40430a43831839fcb8d43f237be57fd63ca9942 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Wed, 4 Dec 2024 23:29:35 +0800 Subject: [PATCH 61/68] Init flare chain (#7222) * Init flare chain * fix price * Fix source * Add tokens.erc20 * Update flare tokens * Verify source table schema * Fix source * Complete docs block * Update prices_flare_tokens.sql * Fix native token * Add yakufff's credit * Remove post_hook * Update schema --- .../chain_info/chain_info_chain_ids.sql | 6 +- .../daily_spellbook/models/evms/evms_info.sql | 2 + .../tokens/models/prices/flare/_schema.yml | 29 + .../prices/flare/prices_flare_tokens.sql | 25 + .../tokens/models/prices/prices_tokens.sql | 2 + .../models/prices/prices_trusted_tokens.sql | 1 + .../tokens/models/tokens/_schema.yml | 5 +- .../tokens/models/tokens/flare/_schema.yml | 21 + .../tokens/flare/tokens_flare_erc20.sql | 32 + .../tokens/models/tokens/tokens_erc20.sql | 1 + .../_base_sources/evm/flare_base_sources.yml | 593 ++++++++++++++++++ sources/_base_sources/evm/flare_docs_block.md | 311 +++++++++ 12 files changed, 1023 insertions(+), 5 deletions(-) create mode 100644 dbt_subprojects/tokens/models/prices/flare/_schema.yml create mode 100644 dbt_subprojects/tokens/models/prices/flare/prices_flare_tokens.sql create mode 100644 dbt_subprojects/tokens/models/tokens/flare/_schema.yml create mode 100644 dbt_subprojects/tokens/models/tokens/flare/tokens_flare_erc20.sql create mode 100644 sources/_base_sources/evm/flare_base_sources.yml create mode 100644 sources/_base_sources/evm/flare_docs_block.md diff --git a/dbt_subprojects/daily_spellbook/models/chain_info/chain_info_chain_ids.sql b/dbt_subprojects/daily_spellbook/models/chain_info/chain_info_chain_ids.sql index 83a864dd8dd..a0df844e8e3 100644 --- a/dbt_subprojects/daily_spellbook/models/chain_info/chain_info_chain_ids.sql +++ b/dbt_subprojects/daily_spellbook/models/chain_info/chain_info_chain_ids.sql @@ -31,12 +31,12 @@ FROM ( values ,('Metadium Mainnet' ,'META' ,'META' ,'11' ,'11' ,'https://metadium.com' ,'') ,('Metadium Testnet' ,'META' ,'KAL' ,'12' ,'12' ,'https://metadium.com' ,'') ,('Diode Testnet Staging' ,'DIODE' ,'sDIODE' ,'13' ,'13' ,'https://diode.io/staging' ,'') -,('Flare Mainnet' ,'FLR' ,'FLR' ,'14' ,'14' ,'https://flare.xyz' ,'https://flare-explorer.flare.network') +,('Flare Mainnet', 'FLR', 'FLR', '14', '14', 'https://flare.network', 'https://flare-explorer.flare.network') ,('Diode Prenet' ,'DIODE' ,'DIODE' ,'15' ,'15' ,'https://diode.io/prenet' ,'') -,('Flare Testnet Coston' ,'FLR' ,'CFLR' ,'16' ,'16' ,'https://flare.xyz' ,'https://coston-explorer.flare.network') +,('Flare Testnet Coston', 'CFLR', 'CFLR', '16', '16', 'https://flare.network', 'https://coston-explorer.flare.network') ,('ThaiChain 2.0 ThaiFi' ,'TCH' ,'TFI' ,'17' ,'17' ,'https://exp.thaifi.com' ,'') ,('ThunderCore Testnet' ,'TST' ,'TST' ,'18' ,'18' ,'https://thundercore.com' ,'https://explorer-testnet.thundercore.com') -,('Songbird Canary-Network' ,'SGB' ,'SGB' ,'19' ,'19' ,'https://flare.xyz' ,'https://songbird-explorer.flare.network') +,('Songbird Canary-Network' ,'SGB' ,'SGB' ,'19' ,'19' ,'https://flare.network' ,'https://songbird-explorer.flare.network') ,('Elastos Smart Chain' ,'ETH' ,'ELA' ,'20' ,'20' ,'https://www.elastos.org/' ,'https://esc.elastos.io') ,('Elastos Smart Chain Testnet' ,'ETH' ,'tELA' ,'21' ,'21' ,'https://www.elastos.org/' ,'https://esc-testnet.elastos.io') ,('ELA-DID-Sidechain Mainnet' ,'ETH' ,'ELA' ,'22' ,'22' ,'https://www.elastos.org/' ,'') diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql index 991164f9456..27139065f67 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_info.sql @@ -12,6 +12,7 @@ , "celo" , "ethereum" , "fantom" + , "flare" , "gnosis" , "kaia" , "linea" @@ -91,4 +92,5 @@ FROM ( , (5000, 'mantle', 'Mantle', 'Layer 2', 'Optimistic Rollup', 'MNT', 0x78c1b0c915c4faa5fffa6cabf0219da63d7f4cb8, 'https://mantlescan.xyz/', timestamp '2023-07-02 18:21', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum', true) , (42170, 'nova', 'Arbitrum Nova', 'Layer 2', 'Optimistic Rollup', 'ETH', 0x722e8bdd2ce80a4422e880164f2079488e115365, 'https://nova-explorer.arbitrum.io/', timestamp '2022-06-25 04:01', 'Arbitrum', 'Ethereum', 'Ethereum', true) , (2020, 'ronin', 'Ronin', 'Layer 1', null, 'RON', 0xe514d9deb7966c8be0ca922de8a064264ea6bcd4, 'https://app.roninchain.com/', timestamp '2021-01-25 10:49', NULL, NULL, NULL, true) + , (14, 'flare', 'Flare', 'Layer 1', NULL, 'FLR', NULL, 'https://flare-explorer.flare.network/', timestamp '2022-07-13 15:32', NULL, NULL, NULL, true) ) AS temp_table (chain_id, blockchain, name, chain_type, rollup_type, native_token_symbol, wrapped_native_token_address, explorer_link, first_block_time, codebase, data_availability, settlement, is_on_dune) diff --git a/dbt_subprojects/tokens/models/prices/flare/_schema.yml b/dbt_subprojects/tokens/models/prices/flare/_schema.yml new file mode 100644 index 00000000000..dcd1b19db3a --- /dev/null +++ b/dbt_subprojects/tokens/models/prices/flare/_schema.yml @@ -0,0 +1,29 @@ +version: 2 + +models: + - name: prices_flare_tokens + meta: + blockchain: flare + sector: prices + contributors: hosuke, yakufff + config: + tags: ['prices', 'tokens', 'usd', 'flare'] + description: "Price tokens on Flare Network EVM chain" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - contract_address + columns: + - name: token_id + description: "Id of the token at coinpaprika. This id is required to pull the price feed data. NOTE: Not all tokens are listed at coinpaprika - consider using price data from DEX sources in this case or submit a listing request at coinpaprika." + - name: blockchain + description: "Native blockchain of the token, if any" + data_tests: + - accepted_values: + values: [ "flare" ] + - name: contract_address + description: "Contract address of the token, if any" + - name: symbol + description: "Token symbol" + - name: decimals + description: "Number of decimals for the token contract" diff --git a/dbt_subprojects/tokens/models/prices/flare/prices_flare_tokens.sql b/dbt_subprojects/tokens/models/prices/flare/prices_flare_tokens.sql new file mode 100644 index 00000000000..956f9317452 --- /dev/null +++ b/dbt_subprojects/tokens/models/prices/flare/prices_flare_tokens.sql @@ -0,0 +1,25 @@ +{% set blockchain = 'flare' %} + +{{ config( + schema = 'prices_' + blockchain, + alias = 'tokens', + materialized = 'table', + file_format = 'delta', + tags = ['static'] + ) +}} + +SELECT + token_id + , '{{ blockchain }}' as blockchain + , symbol + , contract_address + , decimals +FROM +( + VALUES + ('flr-flare-network', 'WFLR', 0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d, 18) + , ('joule-kinetic', 'JOULE', 0xE6505f92583103AF7ed9974DEC451A7Af4e3A3bE, 18) + , ('usdc.e-usd-coin.e', 'USDC.e', 0xFbDa5F676cB37624f28265A144A48B0d6e87d3b6, 6) + , ('usdt-tether', 'USDT', 0x0B38e83B86d491735fEaa0a791F65c2B99535396, 6) +) as temp (token_id, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/prices/prices_tokens.sql b/dbt_subprojects/tokens/models/prices/prices_tokens.sql index 9fa9d762641..c468060c72b 100644 --- a/dbt_subprojects/tokens/models/prices/prices_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/prices_tokens.sql @@ -16,6 +16,7 @@ , "celo" , "ethereum" , "fantom" + , "flare" , "gnosis" , "kaia" , "linea" @@ -46,6 +47,7 @@ ref('prices_native_tokens') ,ref('prices_cardano_tokens') ,ref('prices_ethereum_tokens') ,ref('prices_fantom_tokens') +,ref('prices_flare_tokens') ,ref('prices_gnosis_tokens') ,ref('prices_optimism_tokens') ,ref('prices_polygon_tokens') diff --git a/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql b/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql index 613aca4cf83..6aab6582b3b 100644 --- a/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/prices_trusted_tokens.sql @@ -68,6 +68,7 @@ WITH trusted_tokens AS ( , ('ethereum', 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599) , ('ethereum', 0xf939e0a03fb07f59a73314e73794be0e57ac1b4e) , ('fantom', 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83) + , ('flare', 0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d) , ('fantom', 0x04068da6c83afcfa0e13ba15a6696662335d5b75) , ('fantom', 0x74b23882a30290451a17c44f4f05243b6b58c76d) , ('fantom', 0x8d11ec38a3eb5e956b052f67da8bdc9bef8abf3e) diff --git a/dbt_subprojects/tokens/models/tokens/_schema.yml b/dbt_subprojects/tokens/models/tokens/_schema.yml index bb64ce8a7d8..68d13b23633 100644 --- a/dbt_subprojects/tokens/models/tokens/_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/_schema.yml @@ -3,11 +3,12 @@ version: 2 models: - name: tokens_erc20 meta: - blockchain: arbitrum, avalanche_c, bnb, ethereum, gnosis, mantle, optimism, fantom, polygon, base, blast, sepolia, sei, nova, worldchain, kaia, ronin, boba + blockchain: arbitrum, avalanche_c, bnb, ethereum, gnosis, mantle, optimism, fantom, polygon, base, blast, sepolia, sei, nova, worldchain, kaia, ronin, boba, flare sector: tokens contributors: hildobby, 0xManny, dot2dotseurat, soispoke, mtitus6, wuligy, angus_1, Henrystats, viniabussafi, jeff-dude, rantum, hosuke config: - tags: ['tokens','erc20', 'arbitrum', 'avalanche_c', 'bnb', 'ethereum', 'gnosis', 'mantle', 'optimism', 'fantom', 'base', 'blast', 'sei', 'nova', 'linea', 'worldchain', 'kaia', 'ronin', 'boba'] + tags: ['tokens','erc20', 'arbitrum', 'avalanche_c', 'bnb', 'ethereum', 'gnosis', 'mantle', 'optimism', 'fantom', 'base', 'blast', 'sei', 'nova', 'linea', 'worldchain', 'kaia', 'ronin', 'boba', 'flare'] + description: > Crosschain ERC20 tokens data_tests: diff --git a/dbt_subprojects/tokens/models/tokens/flare/_schema.yml b/dbt_subprojects/tokens/models/tokens/flare/_schema.yml new file mode 100644 index 00000000000..93ec5d26b80 --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/flare/_schema.yml @@ -0,0 +1,21 @@ +version: 2 + +models: + - name: tokens_flare_erc20 + meta: + blockchain: flare + sector: tokens + project: erc20 + contributors: hosuke, yakufff + config: + tags: ['table', 'erc20', 'flare'] + description: "ERC20 Token Addresses, Symbols and Decimals on flare Network" + columns: + - name: contract_address + description: "ERC20 token contract address" + data_tests: + - unique + - name: symbol + description: "ERC20 token symbol" + - name: decimals + description: "Number of decimals, refers to how divisible an ERC20 token can be" diff --git a/dbt_subprojects/tokens/models/tokens/flare/tokens_flare_erc20.sql b/dbt_subprojects/tokens/models/tokens/flare/tokens_flare_erc20.sql new file mode 100644 index 00000000000..b12a5c48e61 --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/flare/tokens_flare_erc20.sql @@ -0,0 +1,32 @@ +{{ + config( + schema = 'tokens_flare' + , alias = 'erc20' + , tags = ['static'] + , materialized = 'table' + ) +}} + +SELECT + contract_address + , symbol + , decimals +FROM (VALUES + (0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d, 'WFLR', 18) + , (0xE6505f92583103AF7ed9974DEC451A7Af4e3A3bE, 'JOULE', 18) + , (0x12e605bc104e93B45e1aD99F9e555f659051c2BB, 'sFLR', 18) + , (0xfF56Eb5b1a7FAa972291117E5E9565dA29bc808d, 'APS', 18) + , (0x4A771Cc1a39FDd8AA08B8EA51F7Fd412e73B3d2B, 'USDX', 6) + , (0x140D8d3649Ec605CF69018C627fB44cCC76eC89f, 'HLN', 18) + , (0xFbDa5F676cB37624f28265A144A48B0d6e87d3b6, 'USDC.e', 6) + , (0x0B38e83B86d491735fEaa0a791F65c2B99535396, 'USDT', 6) + , (0x22757fb83836e3F9F0F353126cACD3B1Dc82a387, 'FLX', 18) + , (0xC18f99CE6DD6278BE2D3f1e738Ed11623444aE33, 'POODLE', 18) + , (0x96B41289D90444B8adD57e6F265DB5aE8651DF29, 'eUSDT', 6) + , (0x932E691aA8c8306C4bB0b19F3f00a284371be8Ba, 'PHIL', 18) + , (0xB5010D5Eb31AA8776b52C7394B76D6d627501C73, 'PFL', 18) + , (0x908BB3E15040801fd29E542221A31Baaa7A4bE19, 'FODO', 18) + , (0xe2bBf70A52Ee84837E9E2e245E5aFc560E259249, 'ZOINK', 18) + , (0x1aa5282692398c078e71Fb3e4A85660d1BF8F586, 'BUNNY', 18) + , (0xc6B19B06A92B337Cbca5f7334d29d45ec4d5E532, 'Moon', 18) +) as temp (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql b/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql index 4371252253b..eee5511d121 100644 --- a/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/tokens_erc20.sql @@ -72,6 +72,7 @@ ,'tokens_tron': {'blockchain': 'tron', 'model': ref('tokens_tron_erc20')} ,'tokens_ronin': {'blockchain': 'ronin', 'model': ref('tokens_ronin_erc20')} ,'tokens_bob': {'blockchain': 'bob', 'model': ref('tokens_bob_erc20')} + ,'tokens_flare': {'blockchain': 'flare', 'model': ref('tokens_flare_erc20')} ,'tokens_boba': {'blockchain': 'boba', 'model': ref('tokens_boba_erc20')} } %} diff --git a/sources/_base_sources/evm/flare_base_sources.yml b/sources/_base_sources/evm/flare_base_sources.yml new file mode 100644 index 00000000000..aced6efea3d --- /dev/null +++ b/sources/_base_sources/evm/flare_base_sources.yml @@ -0,0 +1,593 @@ +version: 2 + +sources: + - name: flare + description: "Raw tables for the Flare blockchain" + tables: + - name: transactions + meta: + docs_slug: "/evm/flare/raw/transactions" + short_description: "The `flare.transactions` table contains all transactions on the Flare blockchain." + description: '{{ doc("flare_transactions_doc") }}' + columns: + - name: block_time + description: "The exact UTC timestamp when this transaction was included" + data_type: timestamp + - name: block_number + description: "The sequential number of the block containing this transaction" + data_type: bigint + - name: value + description: "Amount of native tokens transferred in this transaction" + data_type: uint256 + - name: gas_limit + description: "Maximum amount of gas that can be used by this transaction" + data_type: bigint + - name: gas_price + description: "Price per unit of gas specified by the sender" + data_type: uint256 + - name: gas_used + description: "Amount of gas used by this transaction" + data_type: bigint + - name: max_fee_per_gas + description: "Maximum total fee per unit of gas (EIP-1559)" + data_type: bigint + - name: max_priority_fee_per_gas + description: "Maximum priority fee per unit of gas (EIP-1559)" + data_type: bigint + - name: priority_fee_per_gas + description: "Actual priority fee per unit of gas (EIP-1559)" + data_type: bigint + - name: nonce + description: "Number of transactions sent by the sender prior to this one" + data_type: bigint + - name: index + description: "Index of this transaction within the block" + data_type: bigint + - name: success + description: "Whether the transaction was successful" + data_type: boolean + - name: from + description: "Address that sent the transaction" + data_type: varbinary + - name: to + description: "Address that received the transaction" + data_type: varbinary + - name: block_hash + description: "Hash of the block containing this transaction" + data_type: varbinary + - name: data + description: "Data payload of the transaction" + data_type: varbinary + - name: hash + description: "Unique identifier (hash) of this transaction" + data_type: varbinary + - name: type + description: "Transaction type (0 = legacy, 1 = access list, 2 = EIP-1559)" + data_type: varchar + - name: access_list + description: "List of addresses and storage keys that the transaction plans to access" + data_type: array(row(address varbinary,storageKeys array(varbinary))) + - name: block_date + description: "UTC date of the block containing this transaction" + data_type: date + + - name: traces + meta: + docs_slug: "/evm/flare/raw/traces" + short_description: "The `flare.traces` table contains all transaction traces on the Flare blockchain." + description: '{{ doc("flare_traces_doc") }}' + columns: + - name: block_time + description: "The exact UTC timestamp when this trace was created" + data_type: timestamp + - name: block_number + description: "The sequential number of the block containing this trace" + data_type: bigint + - name: value + description: "Amount of native tokens transferred in this trace" + data_type: uint256 + - name: gas + description: "Gas limit for this trace" + data_type: bigint + - name: gas_used + description: "Amount of gas used by this trace" + data_type: bigint + - name: block_hash + description: "Hash of the block containing this trace" + data_type: varbinary + - name: success + description: "Whether this trace was successful" + data_type: boolean + - name: tx_index + description: "Index of the transaction within the block" + data_type: integer + - name: tx_from + description: "Address that sent the transaction" + data_type: varbinary + - name: tx_to + description: "Address that received the transaction" + data_type: varbinary + - name: sub_traces + description: "Number of sub-traces" + data_type: bigint + - name: error + description: "Error message if the trace failed" + data_type: varchar + - name: tx_success + description: "Whether the parent transaction was successful" + data_type: boolean + - name: tx_hash + description: "Hash of the transaction" + data_type: varbinary + - name: from + description: "Address initiating this trace" + data_type: varbinary + - name: to + description: "Address receiving this trace" + data_type: varbinary + - name: trace_address + description: "Array indicating the position in the call trace tree" + data_type: array(bigint) + - name: type + description: "Type of the trace (call, create, suicide, reward)" + data_type: varchar + - name: address + description: "Address of the contract if this is a create trace" + data_type: varbinary + - name: code + description: "Contract code for create traces" + data_type: varbinary + - name: call_type + description: "Type of call (call, delegatecall, staticcall)" + data_type: varchar + - name: input + description: "Input data for the trace" + data_type: varbinary + - name: output + description: "Output data from the trace" + data_type: varbinary + - name: refund_address + description: "Address receiving refund for self-destruct" + data_type: varbinary + - name: revert_reason + description: "Reason for revert if the trace failed" + data_type: varchar + - name: block_date + description: "UTC date of the block containing this trace" + data_type: date + + - name: traces_decoded + meta: + docs_slug: "/evm/flare/raw/traces_decoded" + short_description: "The `flare.traces_decoded` table contains decoded traces from known contracts on the Flare blockchain." + description: '{{ doc("flare_traces_decoded_doc") }}' + columns: + - name: block_date + description: "UTC date of the block containing this trace" + data_type: date + - name: block_time + description: "The exact UTC timestamp when this trace was created" + data_type: timestamp + - name: block_number + description: "The sequential number of the block containing this trace" + data_type: bigint + - name: namespace + description: "Project namespace for the contract" + data_type: varchar + - name: contract_name + description: "Name of the contract" + data_type: varchar + - name: to + description: "Address receiving this trace" + data_type: varbinary + - name: trace_address + description: "Array indicating the position in the call trace tree" + data_type: array(bigint) + - name: tx_hash + description: "Hash of the transaction" + data_type: varbinary + - name: tx_from + description: "Address that sent the transaction" + data_type: varbinary + - name: tx_to + description: "Address that received the transaction" + data_type: varbinary + - name: signature + description: "Function signature hash" + data_type: varbinary + - name: function_name + description: "Name of the called function" + data_type: varchar + + - name: creation_traces + meta: + docs_slug: "/evm/flare/raw/creation_traces" + short_description: "The `flare.creation_traces` table contains information about contract creation events." + description: '{{ doc("flare_creation_traces_doc") }}' + columns: + - name: block_time + description: "The exact UTC timestamp when the block containing this creation was added to the chain" + data_type: timestamp + - name: block_number + description: "The sequential number of the block containing this creation" + data_type: bigint + - name: tx_hash + description: "Unique 256-bit identifier (hash) of the transaction" + data_type: varbinary + - name: address + description: "Address of the deployed contract" + data_type: varbinary + - name: from + description: "Address of the account that created the contract" + data_type: varbinary + - name: code + description: "Bytecode of the deployed contract" + data_type: varbinary + - name: block_month + description: "The month of the block date" + data_type: date + + - name: logs + meta: + docs_slug: "/evm/flare/raw/logs" + short_description: "The `flare.logs` table contains all event logs emitted by contracts on the Flare blockchain." + description: '{{ doc("flare_logs_doc") }}' + columns: + - name: block_time + description: "The exact UTC timestamp when this log was emitted" + data_type: timestamp + - name: block_number + description: "The sequential number of the block containing this log" + data_type: bigint + - name: block_hash + description: "Hash of the block containing this log" + data_type: varbinary + - name: contract_address + description: "Address of the contract that emitted this log" + data_type: varbinary + - name: topic0 + description: "First topic of the log (typically the event signature)" + data_type: varbinary + - name: topic1 + description: "Second topic of the log" + data_type: varbinary + - name: topic2 + description: "Third topic of the log" + data_type: varbinary + - name: topic3 + description: "Fourth topic of the log" + data_type: varbinary + - name: data + description: "Additional data included in the log" + data_type: varbinary + - name: tx_hash + description: "Hash of the transaction that generated this log" + data_type: varbinary + - name: index + description: "Index of this log within the transaction" + data_type: integer + - name: tx_index + description: "Index of the transaction within the block" + data_type: integer + - name: block_date + description: "UTC date of the block containing this log" + data_type: date + - name: tx_from + description: "Address that sent the transaction" + data_type: varbinary + - name: tx_to + description: "Address that received the transaction" + data_type: varbinary + + - name: logs_decoded + meta: + docs_slug: "/evm/flare/raw/logs_decoded" + short_description: "The `flare.logs_decoded` table contains decoded event logs from known contracts on the Flare blockchain." + description: '{{ doc("flare_logs_decoded_doc") }}' + columns: + - name: block_date + description: "UTC date of the block containing this log" + data_type: date + - name: block_time + description: "The exact UTC timestamp when this log was emitted" + data_type: timestamp + - name: block_number + description: "The sequential number of the block containing this log" + data_type: bigint + - name: namespace + description: "Project namespace for the contract" + data_type: varchar + - name: contract_name + description: "Name of the contract that emitted this event" + data_type: varchar + - name: contract_address + description: "Address of the contract that emitted this event" + data_type: varbinary + - name: tx_hash + description: "Hash of the transaction that generated this event" + data_type: varbinary + - name: tx_from + description: "Address that sent the transaction" + data_type: varbinary + - name: tx_to + description: "Address that received the transaction" + data_type: varbinary + - name: index + description: "Index of this event within the transaction" + data_type: integer + - name: signature + description: "Event signature hash" + data_type: varbinary + - name: event_name + description: "Name of the emitted event" + data_type: varchar + + - name: blocks + meta: + docs_slug: "/evm/flare/raw/blocks" + short_description: "The `flare.blocks` table contains information about blocks on the Flare blockchain." + description: '{{ doc("flare_blocks_doc") }}' + columns: + - name: time + description: "The exact UTC timestamp when this block was added to the chain" + data_type: timestamp + - name: number + description: "The sequential number of this block in the chain" + data_type: bigint + - name: gas_limit + description: "Maximum amount of gas that could be used by all transactions in this block" + data_type: decimal(38,0) + - name: gas_used + description: "Actual amount of gas used by all transactions in this block" + data_type: decimal(38,0) + - name: difficulty + description: "Numerical value indicating the computational effort required to mine this block" + data_type: bigint + - name: total_difficulty + description: "Sum of block difficulties up to this block" + data_type: decimal(38,0) + - name: size + description: "Size of this block in bytes" + data_type: bigint + - name: base_fee_per_gas + description: "Base fee per gas in the block (post-EIP-1559)" + data_type: bigint + - name: hash + description: "Unique 256-bit identifier (hash) of this block" + data_type: varbinary + - name: parent_hash + description: "Hash of the previous block in the chain" + data_type: varbinary + - name: miner + description: "Address of the validator that produced this block" + data_type: varbinary + - name: nonce + description: "Value used to demonstrate proof of work for this block" + data_type: varbinary + - name: state_root + description: "Root hash of the state trie" + data_type: varbinary + - name: transactions_root + description: "Root hash of the transactions trie" + data_type: varbinary + - name: receipts_root + description: "Root hash of the receipts trie" + data_type: varbinary + - name: date + description: "The UTC date when this block was added to the chain" + data_type: date + + - name: erc20_flare + description: "Transfer events for ERC20 tokens on Flare blockchain" + tables: + - name: evt_transfer + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc20/evt_transfer" + short_description: "This table contains individual transfer events for ERC20 tokens on the Flare blockchain. Each row represents a single token transfer event." + description: '{{ doc("erc20_flare_evt_transfer_doc") }}' + columns: + - name: contract_address + description: "Address of the ERC20 token contract that emitted this event" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: from + description: "Address that sent the transaction" + data_type: varbinary + - name: to + description: "Address that received the transaction" + data_type: varbinary + - name: value + description: "Amount of ERC20 tokens transferred, in the token's Flare unit" + + - name: evt_approval + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc20/evt_approval" + short_description: "The `flare.evt_approval` table contains approval events for ERC20 tokens on Flare, allowing an address to spend tokens on behalf of the owner." + description: '{{ doc("erc20_flare_evt_approval_doc") }}' + columns: + - name: contract_address + description: "Address of the ERC20 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: owner + description: "Address of the token owner granting approval" + data_type: varbinary + - name: spender + description: "Address being granted permission to spend tokens" + data_type: varbinary + - name: value + description: "Amount of ERC20 tokens approved for spending, in the token's smallest unit" + + - name: erc1155_flare + description: "Events related to ERC1155 tokens on Flare blockchain" + tables: + - name: evt_transfersingle + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc1155/evt_transfersingle" + short_description: "This table contains single transfer events for ERC1155 tokens on the network." + description: '{{ doc("erc1155_flare_evt_transfersingle_doc") }}' + columns: + - name: contract_address + description: "Address of the ERC1155 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: operator + description: "The address that is authorized to execute the transfer on behalf of the owner" + data_type: varbinary + - name: from + description: "Address that sent the transaction" + data_type: varbinary + - name: to + description: "Address that received the transaction" + data_type: varbinary + - name: id + description: "Unique identifier of the ERC1155 token being transferred" + - name: value + description: "Quantity of the ERC1155 token transferred" + + - name: evt_transferbatch + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc1155/evt_transferbatch" + short_description: "This table contains all batch transfer events for ERC1155 tokens on the network." + description: '{{ doc("erc1155_ethereum_evt_transferbatch_doc") }}' + columns: + - name: contract_address + description: "Contract address of the ERC1155 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: operator + description: "Contract address authorized to execute the batch transfer on behalf of the owner" + data_type: varbinary + - name: from + description: "Address that sent the transaction" + data_type: varbinary + - name: to + description: "Address that received the transaction" + data_type: varbinary + - name: ids + description: "Array of unique identifiers of the ERC1155 tokens being transferred" + - name: values + description: "Array of quantities for each ERC1155 token transferred, corresponding to the ids array" + + - name: evt_ApprovalForAll + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc1155/evt_ApprovalForAll" + short_description: "This table contains approval events for all tokens of an ERC1155 contract on this network." + description: '{{ doc("erc1155_ethereum_evt_ApprovalForAll_doc") }}' + columns: + - name: contract_address + description: "Flare address of the ERC1155 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: approved + description: "Boolean indicating whether approval is granted (true) or revoked (false)" + - name: owner + description: "Flare address of the token owner granting or revoking approval" + data_type: varbinary + - name: operator + description: "Flare address being granted or revoked permission to operate all tokens" + data_type: varbinary + + - name: erc721_flare + description: '{{ doc("erc721_flare_evt_transfer_doc") }}' + tables: + - name: evt_transfer + description: "Transfer events for ERC721 tokens on this network" + columns: + - name: contract_address + description: "Contract address of the ERC721 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: from + description: "Address that sent the transaction" + data_type: varbinary + - name: to + description: "Address that received the transaction" + data_type: varbinary + - name: tokenId + description: "Unique identifier of the ERC721 token (NFT) being transferred" + + - name: evt_Approval + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc721/evt_Approval" + short_description: "Approval events for ERC721 tokens on this network" + description: '{{ doc("erc721_ethereum_evt_Approval_doc") }}' + columns: + - name: contract_address + description: "Contract address of the ERC721 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: approved + description: "Boolean indicating whether approval is granted (true) or revoked (false)" + - name: owner + description: "Address of the token owner granting or revoking approval" + data_type: varbinary + - name: tokenId + description: "Unique identifier of the ERC721 token (NFT) for which approval is granted or revoked" + + - name: evt_ApprovalForAll + meta: + docs_slug: "/evm/flare/decoded/interfaces/erc721/evt_ApprovalForAll" + short_description: "The `flare.evt_ApprovalForAll` table contains approval events for all tokens of an ERC721 contract on the Flare blockchain." + description: '{{ doc("erc721_ethereum_evt_ApprovalForAll_doc") }}' + columns: + - name: contract_address + description: "Address of the ERC721 token contract" + - name: evt_tx_hash + description: "Hash of the transaction containing this event" + - name: evt_index + description: "Index position of this event within the transaction" + - name: evt_block_time + description: "Timestamp of the block containing this event" + - name: evt_block_number + description: "The block number containing this event" + - name: approved + description: "Boolean indicating whether approval is granted (true) or revoked (false)" + - name: owner + description: "Address of the token owner granting or revoking approval" + data_type: varbinary + - name: operator + description: "The address being granted or revoked permission to operate all tokens" + data_type: varbinary diff --git a/sources/_base_sources/evm/flare_docs_block.md b/sources/_base_sources/evm/flare_docs_block.md new file mode 100644 index 00000000000..06a96b286c2 --- /dev/null +++ b/sources/_base_sources/evm/flare_docs_block.md @@ -0,0 +1,311 @@ +{% docs flare_transactions_doc %} + +The `flare.transactions` table contains detailed information about transactions on the Flare blockchain. It includes: + +- Block information: number, timestamp, hash +- Transaction details: hash, from_address, to_address, value +- Gas data: gas_price, gas_limit, gas_used, max_fee_per_gas, priority_fee_per_gas +- Status: success or failure +- Input data for contract interactions +- Nonce and chain_id +- Transaction type and access list + +This table is used for analyzing transaction patterns, gas usage, value transfers, and overall network activity on Flare. + +{% enddocs %} + +{% docs flare_traces_doc %} + +The `flare.traces` table contains records of execution steps for transactions on the Flare blockchain. Each trace represents an atomic operation that modifies the state of the Ethereum Virtual Machine (EVM). Key components include: + +- Transaction hash and block information +- From and to addresses +- Value transferred +- Gas metrics (gas, gas_used) +- Input and output data +- Call type (e.g., CALL, DELEGATECALL, CREATE) +- Error information and revert reasons +- Trace address for nested calls + +This table is essential for: +- Analyzing internal transactions +- Debugging smart contract interactions +- Tracking value flows through complex transactions +- Understanding contract creation and deployment +- Monitoring FTSO (Flare Time Series Oracle) interactions +- Analyzing State Connector operations + +{% enddocs %} + +{% docs flare_traces_decoded_doc %} + +The `flare.traces_decoded` table contains a subset of decoded traces from the Flare blockchain dependent on submitted smart contracts and their ABIs. It includes: + +- Block information and transaction details +- Contract name and namespace +- Decoded function names and signatures +- Trace address for execution path tracking +- Transaction origin and destination +- Function parameters (when available) + +This table is used for high level analysis of smart contract interactions, including FTSO and State Connector operations. For fully decoded function calls and parameters, refer to protocol-specific decoded tables. + +{% enddocs %} + +{% docs flare_logs_doc %} + +The `flare.logs` table contains event logs emitted by smart contracts on the Flare blockchain. It includes: + +- Block information: number, timestamp, hash +- Transaction details: hash, index, from, to +- Contract address (emitting the event) +- Topic0 (event signature) +- Additional topics (indexed parameters) +- Data field (non-indexed parameters) +- Log index and transaction index + +This table is crucial for: +- Tracking on-chain events +- Monitoring contract activity +- Analyzing token transfers +- Following protocol-specific events +- Tracking FTSO price submissions and rewards +- Monitoring State Connector attestations + +{% enddocs %} + +{% docs flare_logs_decoded_doc %} + +The `flare.logs_decoded` table contains a subset of decoded logs from the Flare blockchain dependent on submitted smart contracts and their ABIs. It includes: + +- Block and transaction information +- Contract details (name, namespace, address) +- Decoded event names and signatures +- Transaction origin and destination +- Event parameters (when available) + +This table is used for high level analysis of smart contract events, particularly useful for monitoring FTSO and State Connector activities. For fully decoded events and parameters, refer to protocol-specific decoded tables. + +{% enddocs %} + +{% docs flare_blocks_doc %} + +The `flare.blocks` table contains information about Flare blocks. It provides essential data about each block in the Flare blockchain, including: + +- Block identifiers and timestamps +- Gas metrics and size +- Consensus information (difficulty, nonce) +- State roots and receipts +- Parent block information +- Base fee per gas +- Extra data + +This table is used for: +- Block timing analysis +- Network performance monitoring +- Gas price trends +- Chain reorganization studies +- Consensus metrics tracking + +{% enddocs %} + +{% docs flare_contracts_doc %} + +The `flare.contracts` table contains information about verified smart contracts on the Flare blockchain. It includes: + +- Contract address +- Contract name and version +- Verification status and timestamp +- Compiler information +- Source code and ABI +- License type +- Implementation details + +This table is used for: +- Contract verification status +- Smart contract analysis +- Protocol research +- Development and debugging +- FTSO and State Connector contract tracking + +{% enddocs %} + +{% docs flare_creation_traces_doc %} + +The `flare.creation_traces` table contains detailed information about contract creation events on the Flare blockchain. It includes: + +- Block information: time, number, date +- Transaction details: hash, from address +- Contract creation specifics: + * Created contract address + * Contract bytecode + * Creation transaction details + * Success/failure status + +This table is essential for: +- Tracking smart contract deployments +- Analyzing contract creation patterns +- Monitoring new protocol deployments +- Auditing contract creation history +- Understanding contract deployment costs + +{% enddocs %} + +{% docs erc20_flare_evt_transfer_doc %} + +The `flare.erc20_flare.evt_transfer` table contains ERC20 token transfer events on the Flare blockchain. Each row represents a single token transfer and includes: + +- Contract address of the token +- Transaction details (hash, block info) +- Transfer participants (from and to addresses) +- Amount transferred +- Event metadata (index, block time) + +This table is crucial for: +- Tracking token movements +- Analyzing token holder behavior +- Monitoring token activity +- Computing token metrics +- Identifying significant transfers + +{% enddocs %} + +{% docs erc20_flare_evt_approval_doc %} + +The `flare.erc20_flare.evt_approval` table contains ERC20 token approval events on the Flare blockchain. It records when token holders authorize other addresses to spend tokens on their behalf, including: + +- Token contract address +- Transaction information +- Owner address (granting approval) +- Spender address (receiving approval) +- Approved amount +- Event metadata + +This table is used for: +- Monitoring token approvals +- Analyzing DEX interactions +- Tracking delegation patterns +- Security monitoring +- Protocol integration analysis + +{% enddocs %} + +{% docs erc1155_flare_evt_transfersingle_doc %} + +The `flare.erc1155_flare.evt_transfersingle` table contains single transfer events for ERC1155 tokens on the Flare blockchain. Each record includes: + +- Contract address +- Transaction details +- Operator address +- From and to addresses +- Token ID +- Amount transferred +- Event metadata + +This table is essential for: +- Tracking multi-token transfers +- Gaming asset movements +- NFT marketplace analysis +- Collection statistics +- User activity monitoring + +{% enddocs %} + +{% docs erc1155_flare_evt_transferbatch_doc %} + +The `flare.erc1155_flare.evt_transferbatch` table contains batch transfer events for ERC1155 tokens on the Flare blockchain. It records multiple token transfers in a single transaction: + +- Contract address +- Transaction information +- Operator address +- From and to addresses +- Arrays of token IDs and amounts +- Event metadata + +This table is used for: +- Analyzing bulk transfers +- Gaming inventory movements +- Marketplace activity +- Collection migrations +- Protocol efficiency analysis + +{% enddocs %} + +{% docs erc1155_flare_evt_approvalforall_doc %} + +The `flare.erc1155_flare.evt_approvalforall` table contains approval events for ERC1155 tokens on the Flare blockchain. It records when owners grant or revoke approval for all their tokens: + +- Contract address +- Transaction details +- Owner address +- Operator address +- Approval status +- Event metadata + +This table is crucial for: +- Monitoring collection approvals +- Marketplace integrations +- Protocol permissions +- Security analysis +- User behavior studies + +{% enddocs %} + +{% docs erc721_flare_evt_transfer_doc %} + +The `flare.erc721_flare.evt_transfer` table contains transfer events for ERC721 tokens (NFTs) on the Flare blockchain. Each record represents a single NFT transfer: + +- Contract address +- Transaction information +- From and to addresses +- Token ID +- Event metadata + +This table is essential for: +- NFT ownership tracking +- Collection analysis +- Market activity monitoring +- User portfolio tracking +- Transfer pattern analysis + +{% enddocs %} + +{% docs erc721_flare_evt_approval_doc %} + +The `flare.erc721_flare.evt_approval` table contains approval events for ERC721 tokens on the Flare blockchain. It records when NFT owners authorize specific addresses to transfer individual tokens: + +- Contract address +- Transaction details +- Owner address +- Approved address +- Token ID +- Event metadata + +This table is used for: +- NFT approval tracking +- Marketplace integration analysis +- Permission monitoring +- Security auditing +- Protocol interaction study + +{% enddocs %} + +{% docs erc721_flare_evt_approvalforall_doc %} + +The `flare.erc721_flare.evt_approvalforall` table contains collection-wide approval events for ERC721 tokens on the Flare blockchain. It records when owners grant or revoke approval for all their NFTs: + +- Contract address +- Transaction information +- Owner address +- Operator address +- Approval status +- Event metadata + +This table is crucial for: +- Collection permission tracking +- Marketplace authorization +- Protocol integration analysis +- Security monitoring +- User behavior analysis + +{% enddocs %} From e968576fc6e7f7541063599a1c625390b24916e2 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Wed, 4 Dec 2024 20:12:56 +0200 Subject: [PATCH 62/68] Upgrade Event Models for GMX v2 Project (#7195) * Add 5 new Event Models. Update 4 Event Models Based on Changes in Contracts * Update 4 Event Models * fix Error * Final changes on 4 event models * Empty commit * fix tests * fix tests * fix errors again * Run Check Again. --------- Co-authored-by: Huang Geyang Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 124 +++++++---- .../gmx_v2_arbitrum_order_created.sql | 13 +- .../gmx_v2_arbitrum_order_updated.sql | 31 ++- ...mx_v2_arbitrum_position_fees_collected.sql | 202 ++++++++++++++--- .../gmx_v2_arbitrum_position_fees_info.sql | 203 ++++++++++++++--- .../gmx_v2_avalanche_c_event_schema.yml | 122 +++++++---- .../gmx_v2_avalanche_c_order_created.sql | 15 +- .../gmx_v2_avalanche_c_order_updated.sql | 31 ++- ...v2_avalanche_c_position_fees_collected.sql | 204 ++++++++++++++--- .../gmx_v2_avalanche_c_position_fees_info.sql | 205 +++++++++++++++--- .../gmx/event/gmx_v2_event_schema.yml | 120 ++++++---- .../gmx/event/gmx_v2_order_created.sql | 3 +- .../gmx/event/gmx_v2_order_updated.sql | 5 +- .../event/gmx_v2_position_fees_collected.sql | 16 +- .../gmx/event/gmx_v2_position_fees_info.sql | 18 +- 15 files changed, 1023 insertions(+), 289 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index d61b2d58e13..a234b79c6fb 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -152,12 +152,12 @@ models: data_tests: - not_null - name: updated_at_block - description: The block number at which the order was last updated. - data_tests: - - not_null + description: The block number at which the order was last updated. - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. + - name: valid_from_time + description: The time from which the order becomes valid for execution. - &is_long name: is_long description: A boolean indicating whether the position is long @@ -165,8 +165,8 @@ models: - not_null - name: should_unwrap_native_token description: Boolean indicating if the native token should be unwrapped. - - name: is_frozen - description: Boolean indicating if the order is frozen. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. - &key name: key description: The unique identifier for the order, stored as a bytes32 value. @@ -604,31 +604,6 @@ models: description: The size of the trade in USD data_tests: - not_null - - &total_rebate_factor - name: total_rebate_factor - description: The total rebate factor for the position - data_tests: - - not_null - - &trader_discount_factor - name: trader_discount_factor - description: The discount factor applied to the trader - data_tests: - - not_null - - &total_rebate_amount - name: total_rebate_amount - description: The total amount of rebate given - data_tests: - - not_null - - &trader_discount_amount - name: trader_discount_amount - description: The amount of discount given to the trader - data_tests: - - not_null - - &affiliate_reward_amount - name: affiliate_reward_amount - description: The reward amount given to the affiliate - data_tests: - - not_null - &funding_fee_amount name: funding_fee_amount description: The amount of funding fee charged @@ -637,28 +612,18 @@ models: - &claimable_long_token_amount name: claimable_long_token_amount description: The amount of long tokens claimable - data_tests: - - not_null - &claimable_short_token_amount name: claimable_short_token_amount description: The amount of short tokens claimable - data_tests: - - not_null - &latest_funding_fee_amount_per_size name: latest_funding_fee_amount_per_size description: The latest funding fee amount per size - data_tests: - - not_null - &latest_long_token_claimable_funding_amount_per_size name: latest_long_token_claimable_funding_amount_per_size description: The latest claimable long token funding amount per size - data_tests: - - not_null - &latest_short_token_claimable_funding_amount_per_size name: latest_short_token_claimable_funding_amount_per_size description: The latest claimable short token funding amount per size - data_tests: - - not_null - &borrowing_fee_usd name: borrowing_fee_usd description: The borrowing fee amount in USD @@ -729,6 +694,61 @@ models: description: The total amount of UI fee collected data_tests: - not_null + - &referral_total_rebate_factor + name: referral_total_rebate_factor + description: The total rebate factor associated with referrals. + data_tests: + - not_null + - &referral_total_rebate_amount + name: referral_total_rebate_amount + description: The total rebate amount given for referrals. + data_tests: + - not_null + - &referral_trader_discount_factor + name: referral_trader_discount_factor + description: The discount factor applied to the trader through referrals. + data_tests: + - not_null + - &referral_adjusted_affiliate_reward_factor + name: referral_adjusted_affiliate_reward_factor + description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null + - &referral_affiliate_reward_amount + name: referral_affiliate_reward_amount + description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null + - &referral_trader_discount_amount + name: referral_trader_discount_amount + description: The discount amount given to the trader through referrals. + data_tests: + - not_null + - &pro_trader_discount_factor + name: pro_trader_discount_factor + description: The discount factor applied for pro traders. + data_tests: + - not_null + - &pro_trader_discount_amount + name: pro_trader_discount_amount + description: The discount amount given to pro traders. + data_tests: + - not_null + - &liquidation_fee_amount + name: liquidation_fee_amount + description: The amount of fees charged during liquidation. + data_tests: + - not_null + - &liquidation_fee_receiver_factor + name: liquidation_fee_receiver_factor + description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null + - &liquidation_fee_amount_for_fee_receiver + name: liquidation_fee_amount_for_fee_receiver + description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) @@ -785,11 +805,6 @@ models: - *collateral_token_price_min - *collateral_token_price_max - *trade_size_usd - - *total_rebate_factor - - *trader_discount_factor - - *total_rebate_amount - - *trader_discount_amount - - *affiliate_reward_amount - *funding_fee_amount - *claimable_long_token_amount - *claimable_short_token_amount @@ -810,6 +825,17 @@ models: - *total_cost_amount - *ui_fee_receiver_factor - *ui_fee_amount + - *referral_total_rebate_factor + - *referral_total_rebate_amount + - *referral_trader_discount_factor + - *referral_adjusted_affiliate_reward_factor + - *referral_affiliate_reward_amount + - *referral_trader_discount_amount + - *pro_trader_discount_factor + - *pro_trader_discount_amount + - *liquidation_fee_amount + - *liquidation_fee_receiver_factor + - *liquidation_fee_amount_for_fee_receiver - *is_increase - *order_key - *position_key @@ -898,7 +924,7 @@ models: data_tests: - not_null - name: market - description: The market in which the order was updated. + description: The market in which the order was updated data_tests: - not_null - name: account @@ -909,4 +935,8 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + - name: valid_from_time + description: The time from which the order becomes valid for execution. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 4339e211083..37823907ffc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -171,10 +171,11 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'updatedAtBlock' THEN value END) AS updated_at_block, MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, - MAX(CASE WHEN key_name = 'isFrozen' THEN value END) AS is_frozen, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel, MAX(CASE WHEN key_name = 'key' THEN value END) AS key FROM @@ -213,9 +214,10 @@ WITH evt_data_1 AS ( TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, TRY_CAST(updated_at_block AS BIGINT) AS updated_at_block, TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, TRY_CAST(is_long AS BOOLEAN) AS is_long, TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, - TRY_CAST(is_frozen AS BOOLEAN) AS is_frozen, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel, from_hex(key) AS key FROM evt_data AS ED @@ -284,9 +286,14 @@ WITH evt_data_1 AS ( WHEN updated_at_time = 0 THEN NULL ELSE updated_at_time END AS updated_at_time, + valid_from_time, is_long, should_unwrap_native_token, - is_frozen, + + CASE + WHEN auto_cancel IS NULL THEN false + ELSE auto_cancel + END AS auto_cancel, key FROM event_data AS ED diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql index 4fe2a489b05..edb33308631 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -58,7 +58,8 @@ WITH evt_data_1 AS ( index, json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items FROM evt_data ) @@ -102,6 +103,19 @@ WITH evt_data_1 AS ( ) AS t(item) ) +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + , combined AS ( SELECT * FROM bytes32_items_parsed @@ -111,6 +125,9 @@ WITH evt_data_1 AS ( UNION ALL SELECT * FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed ) , evt_data_parsed AS ( @@ -123,7 +140,9 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'acceptablePrice' THEN value END) AS acceptable_price, MAX(CASE WHEN key_name = 'triggerPrice' THEN value END) AS trigger_price, MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, - MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel FROM combined GROUP BY tx_hash, index @@ -147,7 +166,9 @@ WITH evt_data_1 AS ( TRY_CAST(acceptable_price AS DOUBLE) AS acceptable_price, TRY_CAST(trigger_price AS DOUBLE) AS trigger_price, TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, - TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP @@ -186,7 +207,9 @@ WITH evt_data_1 AS ( CASE WHEN ED.updated_at_time = 0 THEN NULL ELSE ED.updated_at_time - END AS updated_at_time + END AS updated_at_time, + ED.valid_from_time, + ED.auto_cancel FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql index fa7d065f5fa..7019c6c497d 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql @@ -135,19 +135,19 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +168,28 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +208,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +241,29 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +283,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +295,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,11 +316,29 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD ON ED.market = MD.market @@ -293,10 +346,99 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql index 4a7432cea9b..6665accfbd1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql @@ -135,19 +135,20 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +169,28 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +209,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +242,29 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +284,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +296,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,10 +317,28 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD @@ -293,10 +347,99 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index d43cb91644a..ba40d0e98e5 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -153,11 +153,11 @@ models: - not_null - name: updated_at_block description: The block number at which the order was last updated. - data_tests: - - not_null - - &updated_at_time + - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. + - name: valid_from_time + description: The time from which the order becomes valid for execution. - &is_long name: is_long description: A boolean indicating whether the position is long @@ -165,8 +165,8 @@ models: - not_null - name: should_unwrap_native_token description: Boolean indicating if the native token should be unwrapped. - - name: is_frozen - description: Boolean indicating if the order is frozen. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. - &key name: key description: The unique identifier for the order, stored as a bytes32 value. @@ -604,31 +604,6 @@ models: description: The size of the trade in USD data_tests: - not_null - - &total_rebate_factor - name: total_rebate_factor - description: The total rebate factor for the position - data_tests: - - not_null - - &trader_discount_factor - name: trader_discount_factor - description: The discount factor applied to the trader - data_tests: - - not_null - - &total_rebate_amount - name: total_rebate_amount - description: The total amount of rebate given - data_tests: - - not_null - - &trader_discount_amount - name: trader_discount_amount - description: The amount of discount given to the trader - data_tests: - - not_null - - &affiliate_reward_amount - name: affiliate_reward_amount - description: The reward amount given to the affiliate - data_tests: - - not_null - &funding_fee_amount name: funding_fee_amount description: The amount of funding fee charged @@ -637,28 +612,18 @@ models: - &claimable_long_token_amount name: claimable_long_token_amount description: The amount of long tokens claimable - data_tests: - - not_null - &claimable_short_token_amount name: claimable_short_token_amount description: The amount of short tokens claimable - data_tests: - - not_null - &latest_funding_fee_amount_per_size name: latest_funding_fee_amount_per_size description: The latest funding fee amount per size - data_tests: - - not_null - &latest_long_token_claimable_funding_amount_per_size name: latest_long_token_claimable_funding_amount_per_size description: The latest claimable long token funding amount per size - data_tests: - - not_null - &latest_short_token_claimable_funding_amount_per_size name: latest_short_token_claimable_funding_amount_per_size description: The latest claimable short token funding amount per size - data_tests: - - not_null - &borrowing_fee_usd name: borrowing_fee_usd description: The borrowing fee amount in USD @@ -729,6 +694,61 @@ models: description: The total amount of UI fee collected data_tests: - not_null + - &referral_total_rebate_factor + name: referral_total_rebate_factor + description: The total rebate factor associated with referrals. + data_tests: + - not_null + - &referral_total_rebate_amount + name: referral_total_rebate_amount + description: The total rebate amount given for referrals. + data_tests: + - not_null + - &referral_trader_discount_factor + name: referral_trader_discount_factor + description: The discount factor applied to the trader through referrals. + data_tests: + - not_null + - &referral_adjusted_affiliate_reward_factor + name: referral_adjusted_affiliate_reward_factor + description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null + - &referral_affiliate_reward_amount + name: referral_affiliate_reward_amount + description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null + - &referral_trader_discount_amount + name: referral_trader_discount_amount + description: The discount amount given to the trader through referrals. + data_tests: + - not_null + - &pro_trader_discount_factor + name: pro_trader_discount_factor + description: The discount factor applied for pro traders. + data_tests: + - not_null + - &pro_trader_discount_amount + name: pro_trader_discount_amount + description: The discount amount given to pro traders. + data_tests: + - not_null + - &liquidation_fee_amount + name: liquidation_fee_amount + description: The amount of fees charged during liquidation. + data_tests: + - not_null + - &liquidation_fee_receiver_factor + name: liquidation_fee_receiver_factor + description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null + - &liquidation_fee_amount_for_fee_receiver + name: liquidation_fee_amount_for_fee_receiver + description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) @@ -785,11 +805,6 @@ models: - *collateral_token_price_min - *collateral_token_price_max - *trade_size_usd - - *total_rebate_factor - - *trader_discount_factor - - *total_rebate_amount - - *trader_discount_amount - - *affiliate_reward_amount - *funding_fee_amount - *claimable_long_token_amount - *claimable_short_token_amount @@ -810,6 +825,17 @@ models: - *total_cost_amount - *ui_fee_receiver_factor - *ui_fee_amount + - *referral_total_rebate_factor + - *referral_total_rebate_amount + - *referral_trader_discount_factor + - *referral_adjusted_affiliate_reward_factor + - *referral_affiliate_reward_amount + - *referral_trader_discount_amount + - *pro_trader_discount_factor + - *pro_trader_discount_amount + - *liquidation_fee_amount + - *liquidation_fee_receiver_factor + - *liquidation_fee_amount_for_fee_receiver - *is_increase - *order_key - *position_key @@ -909,4 +935,8 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + - name: valid_from_time + description: The time from which the order becomes valid for execution. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql index cec7a4baf06..ba428954368 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql @@ -171,10 +171,11 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'updatedAtBlock' THEN value END) AS updated_at_block, MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, - MAX(CASE WHEN key_name = 'isFrozen' THEN value END) AS is_frozen, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel, MAX(CASE WHEN key_name = 'key' THEN value END) AS key FROM @@ -213,9 +214,10 @@ WITH evt_data_1 AS ( TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, TRY_CAST(updated_at_block AS BIGINT) AS updated_at_block, TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, TRY_CAST(is_long AS BOOLEAN) AS is_long, TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, - TRY_CAST(is_frozen AS BOOLEAN) AS is_frozen, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel, from_hex(key) AS key FROM evt_data AS ED @@ -272,7 +274,7 @@ WITH evt_data_1 AS ( END AS trigger_price, acceptable_price AS acceptable_price_raw, CASE - WHEN index_token_decimals IS NULL THEN NULL + WHEN index_token_decimals IS NULL THEN NULL ELSE acceptable_price / POWER(10, 30 - index_token_decimals) END AS acceptable_price, execution_fee / POWER(10, 18) AS execution_fee, @@ -284,9 +286,14 @@ WITH evt_data_1 AS ( WHEN updated_at_time = 0 THEN NULL ELSE updated_at_time END AS updated_at_time, + valid_from_time, is_long, should_unwrap_native_token, - is_frozen, + + CASE + WHEN auto_cancel IS NULL THEN false + ELSE auto_cancel + END AS auto_cancel, key FROM event_data AS ED diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql index 5f0b28869f7..0f56ec17a91 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql @@ -58,7 +58,8 @@ WITH evt_data_1 AS ( index, json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items FROM evt_data ) @@ -102,6 +103,19 @@ WITH evt_data_1 AS ( ) AS t(item) ) +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + , combined AS ( SELECT * FROM bytes32_items_parsed @@ -111,6 +125,9 @@ WITH evt_data_1 AS ( UNION ALL SELECT * FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed ) , evt_data_parsed AS ( @@ -123,7 +140,9 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'acceptablePrice' THEN value END) AS acceptable_price, MAX(CASE WHEN key_name = 'triggerPrice' THEN value END) AS trigger_price, MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, - MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel FROM combined GROUP BY tx_hash, index @@ -147,7 +166,9 @@ WITH evt_data_1 AS ( TRY_CAST(acceptable_price AS DOUBLE) AS acceptable_price, TRY_CAST(trigger_price AS DOUBLE) AS trigger_price, TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, - TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP @@ -186,7 +207,9 @@ WITH evt_data_1 AS ( CASE WHEN ED.updated_at_time = 0 THEN NULL ELSE ED.updated_at_time - END AS updated_at_time + END AS updated_at_time, + ED.valid_from_time, + ED.auto_cancel FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_avalanche_c_order_created') }} AS OC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql index 2241dfb0e56..5e19b65ebfd 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql @@ -135,19 +135,19 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +168,28 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +208,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +241,29 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +283,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +295,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,11 +316,29 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD ON ED.market = MD.market @@ -293,11 +346,100 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) -}} +}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql index 0e71e6ccfdf..6dff079f071 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql @@ -135,19 +135,20 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +169,28 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +209,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +242,29 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +284,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +296,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,10 +317,28 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD @@ -293,11 +347,100 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) -}} +}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index bbe86ebd151..c772b056d86 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -153,11 +153,11 @@ models: - not_null - name: updated_at_block description: The block number at which the order was last updated. - data_tests: - - not_null - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. + - name: valid_from_time + description: The time from which the order becomes valid for execution. - &is_long name: is_long description: A boolean indicating whether the position is long @@ -165,8 +165,8 @@ models: - not_null - name: should_unwrap_native_token description: Boolean indicating if the native token should be unwrapped. - - name: is_frozen - description: Boolean indicating if the order is frozen. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. - &key name: key description: The unique identifier for the order, stored as a bytes32 value. @@ -604,31 +604,6 @@ models: description: The size of the trade in USD data_tests: - not_null - - &total_rebate_factor - name: total_rebate_factor - description: The total rebate factor for the position - data_tests: - - not_null - - &trader_discount_factor - name: trader_discount_factor - description: The discount factor applied to the trader - data_tests: - - not_null - - &total_rebate_amount - name: total_rebate_amount - description: The total amount of rebate given - data_tests: - - not_null - - &trader_discount_amount - name: trader_discount_amount - description: The amount of discount given to the trader - data_tests: - - not_null - - &affiliate_reward_amount - name: affiliate_reward_amount - description: The reward amount given to the affiliate - data_tests: - - not_null - &funding_fee_amount name: funding_fee_amount description: The amount of funding fee charged @@ -637,28 +612,18 @@ models: - &claimable_long_token_amount name: claimable_long_token_amount description: The amount of long tokens claimable - data_tests: - - not_null - &claimable_short_token_amount name: claimable_short_token_amount description: The amount of short tokens claimable - data_tests: - - not_null - &latest_funding_fee_amount_per_size name: latest_funding_fee_amount_per_size description: The latest funding fee amount per size - data_tests: - - not_null - &latest_long_token_claimable_funding_amount_per_size name: latest_long_token_claimable_funding_amount_per_size description: The latest claimable long token funding amount per size - data_tests: - - not_null - &latest_short_token_claimable_funding_amount_per_size name: latest_short_token_claimable_funding_amount_per_size description: The latest claimable short token funding amount per size - data_tests: - - not_null - &borrowing_fee_usd name: borrowing_fee_usd description: The borrowing fee amount in USD @@ -729,6 +694,61 @@ models: description: The total amount of UI fee collected data_tests: - not_null + - &referral_total_rebate_factor + name: referral_total_rebate_factor + description: The total rebate factor associated with referrals. + data_tests: + - not_null + - &referral_total_rebate_amount + name: referral_total_rebate_amount + description: The total rebate amount given for referrals. + data_tests: + - not_null + - &referral_trader_discount_factor + name: referral_trader_discount_factor + description: The discount factor applied to the trader through referrals. + data_tests: + - not_null + - &referral_adjusted_affiliate_reward_factor + name: referral_adjusted_affiliate_reward_factor + description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null + - &referral_affiliate_reward_amount + name: referral_affiliate_reward_amount + description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null + - &referral_trader_discount_amount + name: referral_trader_discount_amount + description: The discount amount given to the trader through referrals. + data_tests: + - not_null + - &pro_trader_discount_factor + name: pro_trader_discount_factor + description: The discount factor applied for pro traders. + data_tests: + - not_null + - &pro_trader_discount_amount + name: pro_trader_discount_amount + description: The discount amount given to pro traders. + data_tests: + - not_null + - &liquidation_fee_amount + name: liquidation_fee_amount + description: The amount of fees charged during liquidation. + data_tests: + - not_null + - &liquidation_fee_receiver_factor + name: liquidation_fee_receiver_factor + description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null + - &liquidation_fee_amount_for_fee_receiver + name: liquidation_fee_amount_for_fee_receiver + description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) @@ -785,11 +805,6 @@ models: - *collateral_token_price_min - *collateral_token_price_max - *trade_size_usd - - *total_rebate_factor - - *trader_discount_factor - - *total_rebate_amount - - *trader_discount_amount - - *affiliate_reward_amount - *funding_fee_amount - *claimable_long_token_amount - *claimable_short_token_amount @@ -810,6 +825,17 @@ models: - *total_cost_amount - *ui_fee_receiver_factor - *ui_fee_amount + - *referral_total_rebate_factor + - *referral_total_rebate_amount + - *referral_trader_discount_factor + - *referral_adjusted_affiliate_reward_factor + - *referral_affiliate_reward_amount + - *referral_trader_discount_amount + - *pro_trader_discount_factor + - *pro_trader_discount_amount + - *liquidation_fee_amount + - *liquidation_fee_receiver_factor + - *liquidation_fee_amount_for_fee_receiver - *is_increase - *order_key - *position_key @@ -909,4 +935,8 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + - name: valid_from_time + description: The time from which the order becomes valid for execution. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql index 9f95d34ebbd..11d0a609f05 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql @@ -46,9 +46,10 @@ SELECT min_output_amount_raw, updated_at_block, updated_at_time, + valid_from_time, is_long, should_unwrap_native_token, - is_frozen, + auto_cancel, key FROM {{ ref('gmx_v2_' ~ chain ~ '_order_created') }} {% if not loop.last %} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql index 9481e7bc1b6..c456c7dcc75 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql @@ -34,8 +34,9 @@ SELECT trigger_price, trigger_price_raw, min_output_amount_raw, - updated_at_time - + updated_at_time, + valid_from_time, + auto_cancel FROM {{ ref('gmx_v2_' ~ chain ~ '_order_updated') }} {% if not loop.last %} UNION ALL diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql index 78e89d3a511..c54fcae240e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql @@ -34,11 +34,6 @@ SELECT collateral_token_price_min, collateral_token_price_max, trade_size_usd, - total_rebate_factor, - trader_discount_factor, - total_rebate_amount, - trader_discount_amount, - affiliate_reward_amount, funding_fee_amount, claimable_long_token_amount, claimable_short_token_amount, @@ -59,6 +54,17 @@ SELECT total_cost_amount, ui_fee_receiver_factor, ui_fee_amount, + referral_total_rebate_factor, + referral_total_rebate_amount, + referral_trader_discount_factor, + referral_adjusted_affiliate_reward_factor, + referral_affiliate_reward_amount, + referral_trader_discount_amount, + pro_trader_discount_factor, + pro_trader_discount_amount, + liquidation_fee_amount, + liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver, is_increase, order_key, position_key, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql index 917113693ac..9ae7458454b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql @@ -34,11 +34,6 @@ SELECT collateral_token_price_min, collateral_token_price_max, trade_size_usd, - total_rebate_factor, - trader_discount_factor, - total_rebate_amount, - trader_discount_amount, - affiliate_reward_amount, funding_fee_amount, claimable_long_token_amount, claimable_short_token_amount, @@ -59,6 +54,17 @@ SELECT total_cost_amount, ui_fee_receiver_factor, ui_fee_amount, + referral_total_rebate_factor, + referral_total_rebate_amount, + referral_trader_discount_factor, + referral_adjusted_affiliate_reward_factor, + referral_affiliate_reward_amount, + referral_trader_discount_amount, + pro_trader_discount_factor, + pro_trader_discount_amount, + liquidation_fee_amount, + liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver, is_increase, order_key, position_key, @@ -67,4 +73,4 @@ FROM {{ ref('gmx_v2_' ~ chain ~ '_position_fees_info') }} {% if not loop.last %} UNION ALL {% endif %} -{%- endfor -%} \ No newline at end of file +{%- endfor -%} From 3f50381175ca89761ac2d0dfe8f6e0e250be33cb Mon Sep 17 00:00:00 2001 From: Patel Princi Date: Thu, 5 Dec 2024 02:09:28 +0530 Subject: [PATCH 63/68] Added Stablebase for Base (#7221) * Added Stablebase for Base * Schema configuration added in _schema.yml file * modified code in _schema.yml file * modified code in _schema.yml file * modified code in _schema.yml file * modified code in _schema.yml file * replaced id with address in token bought and sold, chnaged schmea and alias name in base trades file of stablebase * chnaged in timestamo in csv * changed the type of column mismatch * Changed the type in seed file * trying to remove the issue in trade seed file * changed the X username of the protocol * changed the _schema.yml file * changed the _schema.yml file * changed the _schema.yml file * changed the _schema.yml file * changed the _schema.yml file * took pull --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/base/_schema.yml | 142 ++++++++------- .../trades/base/dex_base_base_trades.sql | 1 + .../platforms/stablebase_base_base_trades.sql | 50 ++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 164 ++++++++++-------- .../stablebase_base_base_trades_seed.csv | 2 + sources/_sector/dex/trades/base/_sources.yml | 3 + 7 files changed, 214 insertions(+), 149 deletions(-) create mode 100644 dbt_subprojects/dex/models/trades/base/platforms/stablebase_base_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/stablebase_base_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index 42fd54da190..214f25e6c75 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -185,6 +185,7 @@ FROM (VALUES , ('kaia_swap', 'KaiaSwap', 'Direct', 'KaiaSwap') , ('defi_kingdoms', 'DeFi Kingdoms', 'Direct', 'DeFiKingdoms') , ('hyperjump', 'HyperJump', 'Direct', 'Hyperjump_fi') + , ('stablebase', 'StableBase', 'Direct', 'stablebasefi') , ('flashliquidity', 'Flashliquidity', 'Direct', 'flashliquidity') , ('akronswap', 'Akronswap', 'Direct', 'AkronFinance') ) AS temp_table (project, name, marketplace_type, x_username) diff --git a/dbt_subprojects/dex/models/trades/base/_schema.yml b/dbt_subprojects/dex/models/trades/base/_schema.yml index 76c546922e4..b7b9bea1fce 100644 --- a/dbt_subprojects/dex/models/trades/base/_schema.yml +++ b/dbt_subprojects/dex/models/trades/base/_schema.yml @@ -12,7 +12,7 @@ models: project: uniswap contributors: wuligy config: - tags: [ 'base', 'dex', 'trades', 'uniswap', 'v3' ] + tags: ["base", "dex", "trades", "uniswap", "v3"] description: "uniswap base v3 base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -24,7 +24,6 @@ models: filter: version: 3 - - name: aerodrome_base_base_trades meta: blockchain: base @@ -32,7 +31,7 @@ models: project: aerodrome contributors: msilb7, tomfutago, Henrystats config: - tags: [ 'base', 'dex', 'trades', 'aerodrome' ] + tags: ["base", "dex", "trades", "aerodrome"] description: aerodrome base trades data_tests: - dbt_utils.unique_combination_of_columns: @@ -42,6 +41,22 @@ models: - check_dex_base_trades_seed: seed_file: ref('aerodrome_base_base_trades_seed') + - name: stablebase_base_base_trades + meta: + blockchain: base + sector: dex + project: stablebase + contributors: principatel + config: + tags: ["base", "dex", "trades", "stablebase"] + description: stablebase base trades + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('stablebase_base_base_trades_seed') - name: sushiswap_v1_base_base_trades meta: @@ -50,7 +65,7 @@ models: project: sushiswap contributors: tomfutago config: - tags: [ 'base', 'dex', 'trades', 'sushiswap', 'v1' ] + tags: ["base", "dex", "trades", "sushiswap", "v1"] description: "sushiswap base v1 base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -62,7 +77,6 @@ models: filter: version: 1 - - name: sushiswap_v2_base_base_trades meta: blockchain: base @@ -70,7 +84,7 @@ models: project: sushiswap contributors: wuligy, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'sushiswap', 'v2' ] + tags: ["base", "dex", "trades", "sushiswap", "v2"] description: "sushiswap base v2 base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -89,7 +103,7 @@ models: project: pancakeswap contributors: chef_seaweed, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'pancakeswap', 'uniswap', 'v2' ] + tags: ["base", "dex", "trades", "pancakeswap", "uniswap", "v2"] description: "Pancakeswap Base v2 base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -108,7 +122,7 @@ models: project: balancer contributors: bizzyvinci, thetroyharris, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'balancer' ] + tags: ["base", "dex", "trades", "balancer"] description: "Balancer v2 base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -127,7 +141,7 @@ models: project: pancakeswap contributors: chef_seaweed, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'pancakeswap', 'uniswap', 'v3' ] + tags: ["base", "dex", "trades", "pancakeswap", "uniswap", "v3"] description: "Pancakeswap Base v3 base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -146,7 +160,7 @@ models: project: dodo contributors: owen05, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'dodo' ] + tags: ["base", "dex", "trades", "dodo"] description: "Dodo base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -165,7 +179,7 @@ models: project: maverick contributors: get620v, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'maverick' ] + tags: ["base", "dex", "trades", "maverick"] description: "Maverick Base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -184,7 +198,7 @@ models: project: maverick contributors: get620v config: - tags: [ 'base', 'dex', 'trades', 'maverick' ] + tags: ["base", "dex", "trades", "maverick"] description: "Maverick Base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -203,7 +217,7 @@ models: project: smardex contributors: Chain_L config: - tags: [ 'base', 'dex', 'trades', 'smardex' ] + tags: ["base", "dex", "trades", "smardex"] description: "smardex base trades on base" data_tests: - dbt_utils.unique_combination_of_columns: @@ -220,7 +234,7 @@ models: project: baseswap contributors: ARDev097 config: - tags: [ 'base', 'dex', 'trades', 'baseswap' ] + tags: ["base", "dex", "trades", "baseswap"] description: "baseswap base trades on base" data_tests: - dbt_utils.unique_combination_of_columns: @@ -239,7 +253,7 @@ models: project: baseswap contributors: chef_seaweed config: - tags: [ 'base', 'dex', 'trades', 'baseswap' ] + tags: ["base", "dex", "trades", "baseswap"] description: "baseswap base trades on base" data_tests: - dbt_utils.unique_combination_of_columns: @@ -258,7 +272,7 @@ models: project: dackieswap contributors: Chain_L config: - tags: [ 'base', 'dex', 'trades', 'dackieswap' ] + tags: ["base", "dex", "trades", "dackieswap"] description: "dackieswap base trades on base" data_tests: - dbt_utils.unique_combination_of_columns: @@ -275,7 +289,7 @@ models: project: scale contributors: ARDev097 config: - tags: [ 'base', 'dex', 'trades', 'scale' ] + tags: ["base", "dex", "trades", "scale"] description: "scale base trades on base" data_tests: - dbt_utils.unique_combination_of_columns: @@ -292,7 +306,7 @@ models: project: rubicon contributors: denver, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'rubicon' ] + tags: ["base", "dex", "trades", "rubicon"] description: "rubicon base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -302,7 +316,6 @@ models: - check_dex_base_trades_seed: seed_file: ref('rubicon_base_base_trades_seed') - - name: kyberswap_base_base_trades meta: blockchain: base @@ -310,7 +323,7 @@ models: project: kyberswap contributors: lldao config: - tags: [ 'base', 'dex', 'trades', 'kyberswap' ] + tags: ["base", "dex", "trades", "kyberswap"] description: "kyberswap base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -322,7 +335,6 @@ models: filter: version: 2 - - name: woofi_base_base_trades meta: blockchain: base @@ -330,7 +342,7 @@ models: project: woofi contributors: lldao config: - tags: [ 'base', 'dex', 'trades', 'woofi' ] + tags: ["base", "dex", "trades", "woofi"] description: "woofi base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -342,7 +354,6 @@ models: filter: version: 2 - - name: velocimeter_v2_base_base_trades meta: blockchain: base @@ -350,7 +361,7 @@ models: project: velocimeter_v2 contributors: lldao config: - tags: [ 'base', 'dex', 'trades', 'velocimeter_v2' ] + tags: ["base", "dex", "trades", "velocimeter_v2"] description: "velocimeter_v2 base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -362,7 +373,6 @@ models: filter: version: 2 - - name: moonbase_base_base_trades meta: blockchain: base @@ -370,7 +380,7 @@ models: project: moonbase contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'moonbase' ] + tags: ["base", "dex", "trades", "moonbase"] description: "moonbase base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -382,7 +392,6 @@ models: filter: version: 1 - - name: sobal_base_base_trades meta: blockchain: base @@ -390,7 +399,7 @@ models: project: sobal contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'sobal' ] + tags: ["base", "dex", "trades", "sobal"] description: "sobal base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -402,7 +411,6 @@ models: filter: version: 1 - - name: plantbaseswap_base_base_trades meta: blockchain: base @@ -410,7 +418,7 @@ models: project: plantbaseswap contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'plantbaseswap' ] + tags: ["base", "dex", "trades", "plantbaseswap"] description: "plantbaseswap base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -422,7 +430,6 @@ models: filter: version: 2 - - name: derpdex_base_base_trades meta: blockchain: base @@ -430,7 +437,7 @@ models: project: derpdex contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'derpdex' ] + tags: ["base", "dex", "trades", "derpdex"] description: "derpdex base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -442,8 +449,6 @@ models: filter: version: 1 - - - name: torus_base_base_trades meta: blockchain: base @@ -451,7 +456,7 @@ models: project: torus contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'torus', 'v1' ] + tags: ["base", "dex", "trades", "torus", "v1"] description: "torus base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -461,7 +466,6 @@ models: - check_dex_base_trades_seed: seed_file: ref('torus_base_base_trades_seed') - - name: throne_exchange_v2_base_base_trades meta: blockchain: base @@ -469,7 +473,7 @@ models: project: throne_exchange contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'throne_exchange' ] + tags: ["base", "dex", "trades", "throne_exchange"] description: "throne_exchange base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -481,7 +485,6 @@ models: filter: version: 2 - - name: sharkswap_base_base_trades meta: blockchain: base @@ -489,7 +492,7 @@ models: project: sharkswap contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'sharkswap' ] + tags: ["base", "dex", "trades", "sharkswap"] description: "sharkswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -501,7 +504,6 @@ models: filter: version: 1 - - name: throne_exchange_v3_base_base_trades meta: blockchain: base @@ -509,7 +511,7 @@ models: project: throne_exchange contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'throne_exchange' ] + tags: ["base", "dex", "trades", "throne_exchange"] description: "throne_exchange base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -521,7 +523,6 @@ models: filter: version: 3 - - name: horizondex_base_base_trades meta: blockchain: base @@ -529,7 +530,7 @@ models: project: horizondex contributors: p2c2e config: - tags: [ 'base', 'dex', 'trades', 'horizondex' ] + tags: ["base", "dex", "trades", "horizondex"] description: "horizondex dex swaps on base chain" data_tests: - dbt_utils.unique_combination_of_columns: @@ -541,7 +542,6 @@ models: filter: version: 1 - - name: citadelswap_base_base_trades meta: blockchain: base @@ -549,7 +549,7 @@ models: project: citadelswap contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'citadelswap' ] + tags: ["base", "dex", "trades", "citadelswap"] description: "citadelswap base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -561,7 +561,6 @@ models: filter: version: 1 - - name: autotronic_base_base_trades meta: blockchain: base @@ -569,7 +568,7 @@ models: project: autotronic contributors: LLDAO config: - tags: [ 'base', 'dex', 'trades', 'autotronic' ] + tags: ["base", "dex", "trades", "autotronic"] description: "autotronic base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -581,7 +580,6 @@ models: filter: version: 1 - - name: uniswap_v2_base_base_trades meta: blockchain: base @@ -589,7 +587,7 @@ models: project: uniswap contributors: Henrystats config: - tags: [ 'base', 'dex', 'trades', 'uniswap', 'v2' ] + tags: ["base", "dex", "trades", "uniswap", "v2"] description: "uniswap base v2 base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -601,7 +599,6 @@ models: filter: version: 2 - - name: soswap_base_base_trades meta: blockchain: base @@ -609,7 +606,7 @@ models: project: soswap contributors: archie config: - tags: [ 'base', 'dex', 'trades', 'soswap' ] + tags: ["base", "dex", "trades", "soswap"] description: "soswap base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -621,7 +618,6 @@ models: filter: version: 1 - - name: elk_finance_base_base_trades meta: blockchain: base @@ -629,7 +625,7 @@ models: project: elk_finance contributors: archie config: - tags: [ 'base', 'dex', 'trades', 'elk_finance' ] + tags: ["base", "dex", "trades", "elk_finance"] description: "elk_finance base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -641,7 +637,6 @@ models: filter: version: 1 - - name: oasisswap_base_base_trades meta: blockchain: base @@ -649,7 +644,7 @@ models: project: oasisswap contributors: archie config: - tags: [ 'base', 'dex', 'trades', 'oasisswap' ] + tags: ["base", "dex", "trades", "oasisswap"] description: "oasisswap base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -661,7 +656,6 @@ models: filter: version: 1 - - name: leetswap_v2_base_base_trades meta: blockchain: base @@ -669,7 +663,7 @@ models: project: leetswap_v2 contributors: archie config: - tags: [ 'base', 'dex', 'trades', 'leetswap' ] + tags: ["base", "dex", "trades", "leetswap"] description: "leetswap_v2 base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -688,7 +682,7 @@ models: project: openocean contributors: Henrystats, tomfutago config: - tags: [ 'base', 'dex', 'trades', 'openocean' ] + tags: ["base", "dex", "trades", "openocean"] description: "openocean base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -705,7 +699,7 @@ models: project: rocketswap contributors: intensodefi config: - tags: [ 'base', 'dex', 'trades', 'rocketswap' ] + tags: ["base", "dex", "trades", "rocketswap"] description: "rocketswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -724,7 +718,7 @@ models: project: wombat_exchange contributors: Henrystats config: - tags: [ 'base', 'dex', 'trades', 'wombat_exchange' ] + tags: ["base", "dex", "trades", "wombat_exchange"] description: "wombat exchange base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -743,7 +737,7 @@ models: project: icecreamswap contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'icecreamswap' ] + tags: ["base", "dex", "trades", "icecreamswap"] description: "icecreamswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -760,7 +754,7 @@ models: project: alienbase contributors: intensodefi config: - tags: [ 'base', 'dex', 'trades', 'alienbase' ] + tags: ["base", "dex", "trades", "alienbase"] description: "alienbase base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -779,7 +773,7 @@ models: project: swapbased contributors: intensodefi config: - tags: [ 'base', 'dex', 'trades', 'swapbased' ] + tags: ["base", "dex", "trades", "swapbased"] description: "swapbased base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -798,7 +792,7 @@ models: project: gridex contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'gridex' ] + tags: ["base", "dex", "trades", "gridex"] description: "gridex base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -817,7 +811,7 @@ models: project: baseswap contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'baseswap' ] + tags: ["base", "dex", "trades", "baseswap"] description: "baseswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -836,7 +830,7 @@ models: project: synthswap contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'synthswap' ] + tags: ["base", "dex", "trades", "synthswap"] description: "synthswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -855,7 +849,7 @@ models: project: solidly contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'solidly' ] + tags: ["base", "dex", "trades", "solidly"] description: "solidly base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -874,7 +868,7 @@ models: project: energon contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'energon' ] + tags: ["base", "dex", "trades", "energon"] description: "energon base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -893,7 +887,7 @@ models: project: voltswap contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'voltswap' ] + tags: ["base", "dex", "trades", "voltswap"] description: "voltswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -912,7 +906,7 @@ models: project: crescentswap contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'crescentswap' ] + tags: ["base", "dex", "trades", "crescentswap"] description: "crescentswap base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -931,7 +925,7 @@ models: project: baso_finance contributors: sofiat config: - tags: [ 'base', 'dex', 'trades', 'baso_finance' ] + tags: ["base", "dex", "trades", "baso_finance"] description: "baso finance base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -948,7 +942,7 @@ models: project: clipper contributors: amalashkevich config: - tags: [ 'base', 'dex', 'trades', 'clipper' ] + tags: ["base", "dex", "trades", "clipper"] description: "clipper base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -968,7 +962,7 @@ models: project: swaap contributors: borelien config: - tags: [ 'base', 'dex', 'trades', 'swaap', 'v2'] + tags: ["base", "dex", "trades", "swaap", "v2"] description: "swaap v2 base base trades" data_tests: - dbt_utils.unique_combination_of_columns: @@ -987,7 +981,7 @@ models: project: xchange contributors: mike-x7f config: - tags: [ 'base', 'dex', 'trades', 'xchange' ] + tags: ["base", "dex", "trades", "xchange"] description: "xchange base base trades" data_tests: - dbt_utils.unique_combination_of_columns: diff --git a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql index 9cbced710cb..27346a29e34 100644 --- a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql @@ -9,6 +9,7 @@ ref('uniswap_v3_base_base_trades') , ref('sushiswap_v1_base_base_trades') , ref('sushiswap_v2_base_base_trades') + , ref('stablebase_base_base_trades') , ref('aerodrome_base_base_trades') , ref('pancakeswap_v2_base_base_trades') , ref('pancakeswap_v3_base_base_trades') diff --git a/dbt_subprojects/dex/models/trades/base/platforms/stablebase_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/platforms/stablebase_base_base_trades.sql new file mode 100644 index 00000000000..f2c2df02aef --- /dev/null +++ b/dbt_subprojects/dex/models/trades/base/platforms/stablebase_base_base_trades.sql @@ -0,0 +1,50 @@ +{{ config( + schema = 'stablebase_base', + alias = 'base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index'] +) }} + +WITH token_swaps AS ( + SELECT + evt_block_number AS block_number, + CAST(evt_block_time AS timestamp(3) with time zone) AS block_time, + evt_tx_from AS maker, + evt_tx_to AS taker, + tokensSold AS token_sold_amount_raw, + tokensBought AS token_bought_amount_raw, + CAST(soldId AS varbinary) AS token_sold_address, + CAST(boughtId AS varbinary) AS token_bought_address, + contract_address AS project_contract_address, + evt_tx_hash AS tx_hash, + evt_index AS evt_index + FROM + {{ source('stablebase_base', 'SwapFlashLoan_evt_TokenSwap') }} + {% if is_incremental() %} + WHERE + {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +SELECT + 'base' AS blockchain, + 'stablebase' AS project, + '1' AS version, + CAST(date_trunc('month', token_swaps.block_time) AS date) AS block_month, + CAST(date_trunc('day', token_swaps.block_time) AS date) AS block_date, + token_swaps.block_time, + token_swaps.block_number, + token_swaps.token_sold_amount_raw, + token_swaps.token_bought_amount_raw, + token_swaps.token_sold_address, + token_swaps.token_bought_address, + token_swaps.maker, + token_swaps.taker, + token_swaps.project_contract_address, + token_swaps.tx_hash, + token_swaps.evt_index +FROM + token_swaps diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index 3c8a3436252..24f8e049c5e 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -1079,7 +1079,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: iziswap_scroll_base_trades_seed config: column_types: @@ -2098,7 +2098,7 @@ seeds: token_sold_address: varbinary token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 - block_date: timestamp + block_date: timestamp - name: velodrome_optimism_base_trades_seed config: @@ -2264,7 +2264,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: xchange_base_base_trades_seed config: column_types: @@ -2339,7 +2339,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: hashflow_optimism_base_trades_seed config: column_types: @@ -2369,7 +2369,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: baseswap_base_base_trades_seed config: column_types: @@ -2414,7 +2414,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: smardex_base_base_trades_seed config: column_types: @@ -2432,18 +2432,18 @@ seeds: - name: dackieswap_base_base_trades_seed config: - column_types: - blockchain: varchar - project: varchar - version: varchar - tx_hash: varbinary - evt_index: uint256 - block_number: uint256 - token_bought_address: varbinary - token_sold_address: varbinary - token_bought_amount_raw: uint256 - token_sold_amount_raw: uint256 - block_date: timestamp + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp - name: ramses_arbitrum_base_trades_seed config: @@ -2459,7 +2459,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: chainhop_optimism_base_trades_seed config: column_types: @@ -2474,7 +2474,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: fraxswap_arbitrum_base_trades_seed config: column_types: @@ -2534,7 +2534,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: apeswap_arbitrum_base_trades_seed config: column_types: @@ -2564,7 +2564,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: smardex_arbitrum_base_trades_seed config: column_types: @@ -2609,7 +2609,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: swaap_arbitrum_base_trades_seed config: column_types: @@ -2639,7 +2639,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: woofi_arbitrum_base_trades_seed config: column_types: @@ -2714,7 +2714,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: plantbaseswap_base_base_trades_seed config: column_types: @@ -2744,7 +2744,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: derpdex_base_base_trades_seed config: column_types: @@ -2759,7 +2759,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: torus_base_base_trades_seed config: column_types: @@ -2775,7 +2775,6 @@ seeds: token_sold_amount_raw: uint256 block_date: timestamp - - name: gridex_optimism_base_trades_seed config: column_types: @@ -2955,7 +2954,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: autotronic_base_base_trades_seed config: column_types: @@ -3015,7 +3014,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: sharkyswap_arbitrum_base_trades_seed config: column_types: @@ -3075,7 +3074,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: auragi_arbitrum_base_trades_seed config: column_types: @@ -3135,7 +3134,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: oasisswap_base_base_trades_seed config: column_types: @@ -3150,7 +3149,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: leetswap_v2_base_base_trades_seed config: column_types: @@ -3195,7 +3194,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: openocean_base_base_trades_seed config: column_types: @@ -3240,7 +3239,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: alienbase_base_base_trades_seed config: column_types: @@ -3255,7 +3254,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: swapbased_base_base_trades_seed config: column_types: @@ -3270,7 +3269,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: gridex_base_base_trades_seed config: column_types: @@ -3315,7 +3314,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: solidly_base_base_trades_seed config: column_types: @@ -3330,7 +3329,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: energon_base_base_trades_seed config: column_types: @@ -3345,7 +3344,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: voltswap_base_base_trades_seed config: column_types: @@ -3360,7 +3359,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: crescentswap_base_base_trades_seed config: column_types: @@ -3405,7 +3404,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: uniswap_zksync_base_trades_seed config: column_types: @@ -3420,7 +3419,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: uniswap_zora_base_trades_seed config: column_types: @@ -3435,7 +3434,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: syncswap_zksync_base_trades_seed config: column_types: @@ -3480,7 +3479,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: mute_zksync_base_trades_seed config: column_types: @@ -3540,7 +3539,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: zkswap_finance_zksync_base_trades_seed config: column_types: @@ -3555,7 +3554,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: gemswap_zksync_base_trades_seed config: column_types: @@ -3570,7 +3569,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: vesync_zksync_base_trades_seed config: column_types: @@ -3585,7 +3584,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: dracula_finance_zksync_base_trades_seed config: column_types: @@ -3735,7 +3734,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: smardex_polygon_base_trades_seed config: column_types: @@ -3765,7 +3764,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: horizondex_linea_base_trades_seed config: column_types: @@ -3780,7 +3779,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: dackieswap_v3_arbitrum_base_trades_seed config: column_types: @@ -3795,7 +3794,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: dackieswap_v2_arbitrum_base_trades_seed config: column_types: @@ -3810,7 +3809,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: thruster_blast_base_trades_seed config: column_types: @@ -4050,7 +4049,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: swaap_linea_base_trades_seed config: column_types: @@ -4065,7 +4064,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: swaap_mantle_base_trades_seed config: column_types: @@ -4080,7 +4079,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: swaap_scroll_base_trades_seed config: column_types: @@ -4109,8 +4108,8 @@ seeds: token_sold_address: varbinary token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 - block_date: timestamp - + block_date: timestamp + - name: dackieswap_v2_blast_base_trades_seed config: column_types: @@ -4139,8 +4138,8 @@ seeds: token_sold_address: varbinary token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 - block_date: timestamp - + block_date: timestamp + - name: spacefi_scroll_base_trades_seed config: column_types: @@ -4155,7 +4154,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: uniswap_mantle_base_trades_seed config: column_types: @@ -4200,7 +4199,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: tropicalswap_mantle_base_trades_seed config: column_types: @@ -4229,8 +4228,8 @@ seeds: token_sold_address: varbinary token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 - block_date: timestamp - + block_date: timestamp + - name: sushiswap_blast_base_trades_seed config: column_types: @@ -4245,7 +4244,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: dackieswap_v3_blast_base_trades_seed config: column_types: @@ -4275,7 +4274,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: swapblast_blast_base_trades_seed config: column_types: @@ -4305,7 +4304,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: yoshiexchange_fantom_base_trades_seed config: column_types: @@ -4350,7 +4349,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: icecreamswap_v2_blast_base_trades_seed config: column_types: @@ -4380,7 +4379,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: dragon_swap_kaia_base_trades_seed config: column_types: @@ -4395,7 +4394,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: klay_swap_kaia_base_trades_seed config: column_types: @@ -4410,7 +4409,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: neopin_kaia_base_trades_seed config: column_types: @@ -4425,7 +4424,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: defi_kingdoms_kaia_base_trades_seed config: column_types: @@ -4455,7 +4454,7 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp - + - name: flashliquidity_base_base_trades_seed config: column_types: @@ -4470,6 +4469,21 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp + + - name: stablebase_base_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp - name: akronswap_base_base_trades_seed config: @@ -4484,4 +4498,4 @@ seeds: token_sold_address: varbinary token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 - block_date: timestamp \ No newline at end of file + block_date: timestamp diff --git a/dbt_subprojects/dex/seeds/trades/stablebase_base_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/stablebase_base_base_trades_seed.csv new file mode 100644 index 00000000000..998c8e33f1b --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/stablebase_base_base_trades_seed.csv @@ -0,0 +1,2 @@ +blockchain,project,version,block_month,block_date,block_time,block_number,token_sold_amount_raw,token_bought_amount_raw,token_sold_address,token_bought_address,maker,taker,project_contract_address,tx_hash,evt_index +base,stablebase,1,2023-08-01,2023-08-28,2023-08-28 19:18:00.000,3230470,129976172599579374396,135180385,0x0000000000000000000000000000000000000000000000000000000000000001,0x0000000000000000000000000000000000000000000000000000000000000000,0x19fbc29d72476365a62151ffdbf4764e54774a81,0x8c59cc9b958635710957e751a9b4e77cd771baf2,0x8c59cc9b958635710957e751a9b4e77cd771baf2,0xc2dec669877f4edfcb7debd2eb23288a0fba8cd57d6f3fb3e45e8b15a6458d43,31 diff --git a/sources/_sector/dex/trades/base/_sources.yml b/sources/_sector/dex/trades/base/_sources.yml index 3411997a305..b7f7ad8a6ba 100644 --- a/sources/_sector/dex/trades/base/_sources.yml +++ b/sources/_sector/dex/trades/base/_sources.yml @@ -172,6 +172,9 @@ sources: tables: - name: PairFactory_evt_PairCreated - name: Pair_evt_Swap + - name: stablebase_base + tables: + - name: SwapFlashLoan_evt_TokenSwap - name: basex_base tables: - name: UniswapV3Pool_evt_Swap From 995cda7c22d01d0ad0e94093eb7ea14c3d6bcc72 Mon Sep 17 00:00:00 2001 From: hinus <64959125+cxheng315@users.noreply.github.com> Date: Fri, 6 Dec 2024 03:26:09 +0800 Subject: [PATCH 64/68] Add Ronin to evms tables (#7241) --- .../models/evms/evms_blocks.sql | 3 +- .../models/evms/evms_contracts.sql | 3 +- .../models/evms/evms_creation_traces.sql | 3 +- .../evms/evms_erc1155_approvalsforall.sql | 3 +- .../evms/evms_erc1155_transfersbatch.sql | 3 +- .../evms/evms_erc1155_transferssingle.sql | 3 +- .../models/evms/evms_erc20_approvals.sql | 3 +- .../models/evms/evms_erc20_transfers.sql | 3 +- .../models/evms/evms_erc721_approvals.sql | 3 +- .../evms/evms_erc721_approvalsforall.sql | 3 +- .../models/evms/evms_erc721_transfers.sql | 3 +- .../daily_spellbook/models/evms/evms_logs.sql | 3 +- .../models/evms/evms_logs_decoded.sql | 3 +- .../models/evms/evms_non_app_method_ids.sql | 3 +- .../models/evms/evms_schema.yml | 124 +++++++++--------- .../models/evms/evms_traces.sql | 3 +- .../models/evms/evms_traces_decoded.sql | 3 +- .../models/evms/evms_transactions.sql | 3 +- 18 files changed, 96 insertions(+), 79 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_blocks.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_blocks.sql index 3a92735e74c..21108d85279 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_blocks.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_blocks.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'blocks', unique_key=['blockchain', 'number'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -29,6 +29,7 @@ , ('mantle', source('mantle', 'blocks')) , ('mode', source('mode', 'blocks')) , ('sei', source('sei', 'blocks')) + , ('ronin', source('ronin', 'blocks')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_contracts.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_contracts.sql index 045c4ada3f8..c69543967f3 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_contracts.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_contracts.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'contracts', unique_key=['blockchain', 'address'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('blast', 'contracts')) , ('mantle', source('mantle', 'contracts')) , ('sei', source('sei', 'contracts')) + , ('ronin', source('ronin', 'contracts')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_creation_traces.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_creation_traces.sql index f3612f8dc96..8abe3191d0a 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_creation_traces.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_creation_traces.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'creation_traces', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('blast', 'creation_traces')) , ('mantle', source('mantle', 'creation_traces')) , ('sei', source('sei', 'creation_traces')) + , ('ronin', source('ronin', 'creation_traces')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_approvalsforall.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_approvalsforall.sql index 527ea9a7f15..fe6620fa1b0 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_approvalsforall.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_approvalsforall.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc1155_approvalsforall', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc1155_blast', 'evt_ApprovalForAll')) , ('mantle', source('erc1155_mantle', 'evt_ApprovalForAll')) , ('sei', source('erc1155_sei', 'evt_ApprovalForAll')) + , ('ronin', source('erc1155_ronin', 'evt_ApprovalForAll')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transfersbatch.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transfersbatch.sql index 1247a672e85..1466e326b17 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transfersbatch.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transfersbatch.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc1155_transfersbatch', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc1155_blast', 'evt_transferbatch')) , ('mantle', source('erc1155_mantle', 'evt_transferbatch')) , ('sei', source('erc1155_sei', 'evt_transferbatch')) + , ('ronin', source('erc1155_ronin', 'evt_transferbatch')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transferssingle.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transferssingle.sql index 39460816d35..da8b32c1d16 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transferssingle.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc1155_transferssingle.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc1155_transferssingle', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc1155_blast', 'evt_transfersingle')) , ('mantle', source('erc1155_mantle', 'evt_transfersingle')) , ('sei', source('erc1155_sei', 'evt_transfersingle')) + , ('ronin', source('erc1155_ronin', 'evt_transfersingle')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_approvals.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_approvals.sql index ba1a56bf569..abf407951c5 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_approvals.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_approvals.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc20_approvals', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc20_blast', 'evt_approval')) , ('mantle', source('erc20_mantle', 'evt_approval')) , ('sei', source('erc20_sei', 'evt_Approval')) + , ('ronin', source('erc20_ronin', 'evt_approval')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_transfers.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_transfers.sql index 9720d9346d4..b1da539a0a7 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_transfers.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc20_transfers.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc20_transfers', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc20_blast', 'evt_transfer')) , ('mantle', source('erc20_mantle', 'evt_transfer')) , ('sei', source('erc20_sei', 'evt_transfer')) + , ('ronin', source('erc20_ronin', 'evt_transfer')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvals.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvals.sql index 21ef83c3f3f..d683e392d34 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvals.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvals.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc721_approvals', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc721_blast', 'evt_Approval')) , ('mantle', source('erc721_mantle', 'evt_Approval')) , ('sei', source('erc721_sei', 'evt_Approval')) + , ('ronin', source('erc721_ronin', 'evt_Approval')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvalsforall.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvalsforall.sql index 55a260c134f..da8ca9ee6a3 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvalsforall.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_approvalsforall.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc721_approvalsforall', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc721_blast', 'evt_ApprovalForAll')) , ('mantle', source('erc721_mantle', 'evt_ApprovalForAll')) , ('sei', source('erc721_sei', 'evt_ApprovalForAll')) + , ('ronin', source('erc721_ronin', 'evt_ApprovalForAll')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_transfers.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_transfers.sql index 8fe4ff3fc30..68542f21fc3 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_transfers.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_erc721_transfers.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'erc721_transfers', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('erc721_blast', 'evt_transfer')) , ('mantle', source('erc721_mantle', 'evt_transfer')) , ('sei', source('erc721_sei', 'evt_transfer')) + , ('ronin', source('erc721_ronin', 'evt_transfer')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql index 8b8035feca9..11067157432 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'logs', unique_key=['blockchain', 'tx_hash'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby","rantum"]\') }}' @@ -29,6 +29,7 @@ , ('mantle', source('mantle', 'logs')) , ('mode', source('mode', 'logs')) , ('sei', source('sei', 'logs')) + , ('ronin', source('ronin', 'logs')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_logs_decoded.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_logs_decoded.sql index e3d4df61af2..a603911bf52 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_logs_decoded.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_logs_decoded.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'logs_decoded', unique_key=['blockchain', 'tx_hash'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('blast', 'logs_decoded')) , ('mantle', source('mantle', 'logs_decoded')) , ('sei', source('sei', 'logs_decoded')) + , ('ronin', source('ronin', 'logs_decoded')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_non_app_method_ids.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_non_app_method_ids.sql index cde347b82d7..bb96ab091ea 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_non_app_method_ids.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_non_app_method_ids.sql @@ -3,7 +3,7 @@ tags = [ 'static'], schema = 'non_app_method_ids', alias = 'non_app_method_ids', - post_hook='{{ expose_spells(\'["ethereum","optimism","arbitrum","polygon","gnosis","avalanche_c","fantom","goerli","bnb","base","celo", "zora"]\', + post_hook='{{ expose_spells(\'["ethereum","optimism","arbitrum","polygon","gnosis","avalanche_c","fantom","goerli","bnb","base","celo", "zora", "ronin"]\', "sector", "method_ids", \'["msilb7"]\') }}' @@ -23,6 +23,7 @@ ,'bnb' ,'base' ,'celo' + , 'ronin' ] %} WITH aggrregate_methods AS ( diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml b/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml index dbe4c032c1e..2ba49ad153e 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml @@ -3,11 +3,11 @@ version: 2 models: - name: evms_transactions meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'transactions'] + tags: ["evms", "transactions"] description: "An EVM transaction refers to an action initiated by an externally-owned account (i.e., an account managed by a human, not a contract)." columns: - &blockchain @@ -76,11 +76,11 @@ models: - name: evms_traces meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'traces'] + tags: ["evms", "traces"] description: "An EVM trace is a small atomic action that modify the internal state of the Ethereum Virtual Machine. The three main trace types are call, create, and suicide." columns: - *blockchain @@ -127,11 +127,11 @@ models: - name: evms_traces_decoded meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'traces', 'decoded'] + tags: ["evms", "traces", "decoded"] description: "An EVM trace is a small atomic action that modify the internal state of the Ethereum Virtual Machine. The three main trace types are call, create, and suicide. Decoded traces include additional information based on submitted smart contracts and their ABI" columns: - *blockchain @@ -153,11 +153,11 @@ models: - name: evms_logs meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei, ronin sector: evms contributors: [hildobby, synthquest, rantum] config: - tags: ['evms', 'logs'] + tags: ["evms", "logs"] description: "An EVM log can be used to describe an event within a smart contract, like a token transfer or a change of ownership." columns: - *blockchain @@ -183,11 +183,11 @@ models: - name: evms_logs_decoded meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'logs', 'decoded'] + tags: ["evms", "logs", "decoded"] description: "An EVM log can be used to describe an event within a smart contract, like a token transfer or a change of ownership. Those logs are decoded based on submitted smart contracts to make them human readable." columns: - *blockchain @@ -209,11 +209,11 @@ models: - name: evms_blocks meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'blocks'] + tags: ["evms", "blocks"] description: "Blocks are batches of transactions with a hash of the previous block in the chain. This links blocks together (in a chain) because hashes are cryptographically derived from the block data." columns: - *blockchain @@ -232,17 +232,17 @@ models: - name: evms_contracts meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'contracts'] + tags: ["evms", "contracts"] description: "A view keeping track of what contracts are decoded across EVM chains on Dune; contains information associated with the decoded contract such as namespace, name, address, ABI." data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - blockchain - - address + - blockchain + - address columns: - *blockchain - name: abi @@ -270,14 +270,14 @@ models: values: ["factory", "base", "dynamic"] - name: created_at description: "Timestamp for contract creation" - + - name: evms_creation_traces meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'traces', 'creation', 'contracts'] + tags: ["evms", "traces", "creation", "contracts"] description: "EVM chains creation traces" columns: - *blockchain @@ -293,11 +293,11 @@ models: - name: evms_erc20_transfers meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc20', 'transfers'] + tags: ["evms", "erc20", "transfers"] description: "Transfers events for ERC20 tokens on EVM chains." columns: - *blockchain @@ -322,11 +322,11 @@ models: - name: evms_erc20_approvals meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc20', 'approvals'] + tags: ["evms", "erc20", "approvals"] description: "Approval events for ERC20 tokens on EVM chains." columns: - *blockchain @@ -345,11 +345,11 @@ models: - name: evms_erc1155_transferssingle meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc1155', 'transfers', 'single'] + tags: ["evms", "erc1155", "transfers", "single"] description: "Single transfers events for ERC1155 tokens on EVM chains." columns: - *blockchain @@ -370,11 +370,11 @@ models: - name: evms_erc1155_transfersbatch meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc1155', 'transfers', 'batch'] + tags: ["evms", "erc1155", "transfers", "batch"] description: "Batch transfers events for ERC1155 tokens on EVM chains." columns: - *blockchain @@ -395,11 +395,11 @@ models: - name: evms_erc1155_approvalsforall meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc1155', 'approvals'] + tags: ["evms", "erc1155", "approvals"] description: "Approval for all events for ERC1155 tokens on EVM chains." columns: - *blockchain @@ -420,11 +420,11 @@ models: - name: evms_erc721_transfers meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc721', 'transfers'] + tags: ["evms", "erc721", "transfers"] description: "Transfers events for ERC721 tokens on EVM chains." columns: - *blockchain @@ -441,11 +441,11 @@ models: - name: evms_erc721_approvals meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc721', 'approvals'] + tags: ["evms", "erc721", "approvals"] description: "Approval events for ERC721 tokens on EVM chains." columns: - *blockchain @@ -464,11 +464,11 @@ models: - name: evms_erc721_approvalsforall meta: - blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei + blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, zksync, zora, scroll, linea, zkevm, blast, mantle, sei, ronin sector: evms contributors: [hildobby, synthquest] config: - tags: ['evms', 'erc721', 'approvals'] + tags: ["evms", "erc721", "approvals"] description: "Approval for all events for ERC721 tokens on EVM chains." columns: - *blockchain @@ -488,9 +488,9 @@ models: sector: evms contributors: hildobby config: - tags: ['evms', 'info'] + tags: ["evms", "info"] description: "Some information about the EVM chains" - columns: + columns: - name: chain_id description: "Chain ID" - name: blockchain @@ -513,54 +513,54 @@ models: - name: codebase description: "Codebase used" - name: data_availability - description: "Chain where proofs are submitted to" + description: "Chain where proofs are submitted to" - name: settlement - description: "Chain that is being settled on" + description: "Chain that is being settled on" - name: is_on_dune description: "Is the chain on Dune" - name: evms_non_app_method_ids meta: - blockchain: ethereum,optimism,arbitrum,polygon,gnosis,avalanche_c,fantom,goerli,bnb,base,celo + blockchain: ethereum, optimism, arbitrum, polygon, gnosis, avalanche_c, fantom, goerli, bnb, base, celo, ronin project: method_ids contributors: msilb7 config: - tags: ['method_ids','methods','function','signature'] + tags: ["method_ids", "methods", "function", "signature"] description: > - A table containing mappings for method ids (function signatures) that can be considered to be non-app transactions. There will be one row per blockchain x method_id combination. + A table containing mappings for method ids (function signatures) that can be considered to be non-app transactions. There will be one row per blockchain x method_id combination. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - blockchain - - method_id + - blockchain + - method_id columns: - *blockchain - - &method_id + - &method_id name: method_id description: "Method ID (first 4 bytes of calldata), in '0x....' format" - - &method_descriptor + - &method_descriptor name: method_descriptor - description: "Manual descriptor of the method ID." - + description: "Manual descriptor of the method ID." + - name: evm_smart_account_method_ids meta: blockchain: ethereum,optimism,arbitrum,polygon,gnosis,avalanche_c,fantom,goerli,bnb,base,celo,zora project: method_ids contributors: msilb7 config: - tags: ['method_ids','methods','function','signature'] + tags: ["method_ids", "methods", "function", "signature"] description: > - A table containing mappings for method ids (function signatures) that can be considered to be non-app transactions. There will be one row per blockchain x method_id combination. + A table containing mappings for method ids (function signatures) that can be considered to be non-app transactions. There will be one row per blockchain x method_id combination. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - blockchain - - method_id + - blockchain + - method_id columns: - *blockchain - - *method_id - - *method_descriptor - - &contract_project + - *method_id + - *method_descriptor + - &contract_project name: contract_project description: "Project associated with the method" @@ -570,16 +570,16 @@ models: project: method_ids contributors: msilb7 config: - tags: ['method_ids','methods','function','signature'] + tags: ["method_ids", "methods", "function", "signature"] description: > - A table containing mappings for method ids (function signatures) that can be considered to be non-app transactions. There will be one row per blockchain x method_id combination. + A table containing mappings for method ids (function signatures) that can be considered to be non-app transactions. There will be one row per blockchain x method_id combination. data_tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - blockchain - - method_id + - blockchain + - method_id columns: - *blockchain - - *method_id - - *method_descriptor - - *contract_project \ No newline at end of file + - *method_id + - *method_descriptor + - *contract_project diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_traces.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_traces.sql index ec2d7cb5e1f..a519cecc097 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_traces.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_traces.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'traces', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -29,6 +29,7 @@ , ('mantle', source('mantle', 'traces')) , ('mode', source('mode', 'traces')) , ('sei', source('sei', 'traces')) + , ('ronin', source('ronin', 'traces')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_traces_decoded.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_traces_decoded.sql index c043abbfa98..5bdd80ac062 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_traces_decoded.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_traces_decoded.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'traces_decoded', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby"]\') }}' @@ -28,6 +28,7 @@ , ('blast', source('blast', 'traces_decoded')) , ('mantle', source('mantle', 'traces_decoded')) , ('sei', source('sei', 'traces_decoded')) + , ('ronin', source('ronin', 'traces_decoded')) ] %} SELECT * diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_transactions.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_transactions.sql index 8e1e49ae65c..4ea26272bca 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_transactions.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_transactions.sql @@ -2,7 +2,7 @@ schema='evms', alias = 'transactions', unique_key=['blockchain', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', + post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle", "ronin"]\', "sector", "evms", \'["hildobby", "synthquest"]\') }}' @@ -29,6 +29,7 @@ , ('blast', source('blast', 'transactions')) , ('mantle', source('mantle', 'transactions')) , ('sei', source('sei', 'transactions')) + , ('ronin', source('ronin', 'transactions')) ] %} {% set unstructured_transactions_models = [ From 07eaf9e7dc6ae122d51c86ead1879d0703b3b55f Mon Sep 17 00:00:00 2001 From: Haris Angelidakis <64154020+harisang@users.noreply.github.com> Date: Thu, 5 Dec 2024 21:26:24 +0200 Subject: [PATCH 65/68] update solver names (#7236) --- .../cow_protocol_arbitrum_solvers.sql | 26 +++++++++---------- .../gnosis/cow_protocol_gnosis_solvers.sql | 12 ++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql index dc2eb9fdbbe..5b0751da6a5 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql @@ -37,30 +37,30 @@ registered_solvers as ( known_solver_metadata (address, environment, name) as ( SELECT * FROM (VALUES - (0xA70892d1Af41aBD2F648FEC74Ea2c17e56Ac3B9A, 'prod', 'Naive'), + (0xA70892d1Af41aBD2F648FEC74Ea2c17e56Ac3B9A, 'prod', 'Naive'), (0xba36CEfb45d1CdD2Ae30a899C432c5081E095Ff8, 'prod', 'Baseline'), (0xF017C6F66D68d11AF00FD243494E3fa0EBf44C66, 'prod', 'Quasimodo'), - (0x001088C88be46346ED99856dcfA3a00Da7AAf212, 'prod', '1Inch'), - (0xc46Ac109FDe084192BE59C24C3680D818763b0fd, 'prod', 'ParaSwap'), - (0xD31E0CE8154Da6b8086d961eB3068Ef74C4322b6, 'prod', '0x'), - (0xAa224676d096B6Fc257F8C386C67d9e96e53AD59, 'prod', 'BalancerSOR'), + (0x001088C88be46346ED99856dcfA3a00Da7AAf212, 'prod', 'Gnosis_1inch'), + (0xc46Ac109FDe084192BE59C24C3680D818763b0fd, 'prod', 'Gnosis_ParaSwap'), + (0xD31E0CE8154Da6b8086d961eB3068Ef74C4322b6, 'prod', 'Gnosis_0x'), + (0xAa224676d096B6Fc257F8C386C67d9e96e53AD59, 'prod', 'Gnosis_BalancerSOR'), (0x5932b2c05172aAfE097CE0Fbd27d18a7d5A45eE1, 'prod', 'Furucombo'), - (0x3A485742Bd85e660e72dE0f49cC27AD7a62911B5, 'prod', 'SeaSolver'), + (0x3A485742Bd85e660e72dE0f49cC27AD7a62911B5, 'prod', 'Seasolver'), (0x059aefdF9d9F47def37cF7066DA83fEB91fDd089, 'prod', 'Barter'), - (0x40798d2261f8b7F11BFa73623c99C876844dD05A, 'prod', 'OpenOcean'), + (0x40798d2261f8b7F11BFa73623c99C876844dD05A, 'prod', 'OpenOcean_Aggregator'), (0x0648548f891E1356f197070D009704e574182bfB, 'prod', 'Rizzolver'), (0x23e868881dfe0531358B8FE0cbec43FD860cbF33, 'prod', 'Rizzolver'), (0x20dC1014E946Cf511Ee535D908eC9a1d75Dd66ce, 'barn', 'Naive'), (0x2e6822f4Ab355E386d1A4fd34947ACE0F6f344a7, 'barn', 'Baseline'), (0x03a65D265E0613326ca23f5E6A1a99Ab2F12600B, 'barn', 'Quasimodo'), - (0xee10E8D38150BEe3b0B32c41b74821d6e7Da485A, 'barn', '1Inch'), - (0x9C803d345615aDe1e5ae07A789968403fAc9171a, 'barn', 'ParaSwap'), - (0x69433b336952e84Db44EF40b16B338F139B8baA1, 'barn', '0x'), - (0xCED55FC88186f672105712fe177374cce4861FDF, 'barn', 'BalancerSOR'), + (0xee10E8D38150BEe3b0B32c41b74821d6e7Da485A, 'barn', 'Gnosis_ParaSwap'), + (0x9C803d345615aDe1e5ae07A789968403fAc9171a, 'barn', 'Gnosis_ParaSwap'), + (0x69433b336952e84Db44EF40b16B338F139B8baA1, 'barn', 'Gnosis_0x'), + (0xCED55FC88186f672105712fe177374cce4861FDF, 'barn', 'Gnosis_BalancerSOR'), (0xE376a730037D8B495864FD5ed6373BE89643cD06, 'barn', 'Furucombo'), - (0x2633bd8e5FDf7C72Aca1d291CA11bdB717A6aa3d, 'barn', 'SeaSolver'), + (0x2633bd8e5FDf7C72Aca1d291CA11bdB717A6aa3d, 'barn', 'Seasolver'), (0x7B0211286d8Dfdb717f4A2E5Fa5131eD911097e1, 'barn', 'Barter'), - (0xc8371B2898FBaEeAe658f9FaeE8ddeDA24e37012, 'barn', 'OpenOcean'), + (0xc8371B2898FBaEeAe658f9FaeE8ddeDA24e37012, 'barn', 'OpenOcean_Aggregator'), (0x2aeC288B42C99D2e8e984c5C324FB069f7705186, 'barn', 'Rizzolver'), (0x26B5e3bF135D3Dd05A220508dD61f25BF1A47cBD, 'barn', 'Rizzolver') ) as _ diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql index 7a2b6742ae4..dd7b75e11b0 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql @@ -42,7 +42,7 @@ known_solver_metadata (address, environment, name) as ( (0x508bCC23C1a808A9c41D10E2FCB544Ffb76ae3E5, 'barn', 'MIP'), (0x7942a2b3540d1eC40B2740896f87aEcB2a588731, 'barn', 'Quasimodo'), (0x26029B63C7DBD0C4C04D7226C3e7de5EAb3DB3D8, 'barn', 'Gnosis_1inch'), - (0x52ac5B5e85De9aa72ef5925989Fc419AA04EB15b, 'barn', 'SeaSolver'), + (0x52ac5B5e85De9aa72ef5925989Fc419AA04EB15b, 'barn', 'Seasolver'), (0xf794f31976a9a1d866cadfecde8984e656395a70, 'barn', 'Quasilabs'), (0x449944c987d622cd8db9c150fd4ecdfe4435b836, 'barn', 'Naive'), (0x9aaceb30c5b0e676a6b20d0c6be68f58bc7d8659, 'barn', 'Baseline'), @@ -60,16 +60,16 @@ known_solver_metadata (address, environment, name) as ( (0xC088aea818dE69CeC696054682098ABa804b4FC9, 'barn', 'Gnosis_1inch'), (0x4930a9012e8677ae764e44f2b46af8087a1f9f8e, 'barn', 'Gnosis_BalancerSOR'), (0x8e600b399Da9c46255ccac98764987cF81837a66, 'barn', 'Enso'), - (0xC8D2f12a9505a82C4f6994204f4BbF095183E63A, 'barn', 'SeaSolver'), + (0xC8D2f12a9505a82C4f6994204f4BbF095183E63A, 'barn', 'Seasolver'), (0x67be9614C4E0FCdA95AFC66a95B5BDAFb55fa362, 'barn', 'Furucombo'), - (0x53F5378A6f8bb24333aD8D68FD28816504a467b2, 'barn', 'CopiumCapital'), + (0x53F5378A6f8bb24333aD8D68FD28816504a467b2, 'barn', 'Copium_Capital'), (0xC4dd6355Fbc6Eb108FD1C100389789C5B1A9A980, 'barn', 'Barter'), (0x4398129426Cb1377E9E10395b8dfBDa153c7Fe7D, 'barn', 'Fractal'), (0x727EB77c6f84ef148403f641aA32d75b7f6902A7, 'prod', 'Fractal'), (0x0a360134553feED49FE5eb273074d80B6e45941F, 'prod', 'Barter'), - (0xb4694FE6590acd1281Dc34a966bbAE224559BaD4, 'prod', 'CopiumCapital'), + (0xb4694FE6590acd1281Dc34a966bbAE224559BaD4, 'prod', 'Copium_Capital'), (0x227FDA1D5970dF605D785Bf5F2F8899d5fdF8624, 'prod', 'Furucombo'), - (0xE3068acB5b5672408eADaD4417e7d3BA41D4FEBe, 'prod', 'SeaSolver'), + (0xE3068acB5b5672408eADaD4417e7d3BA41D4FEBe, 'prod', 'Seasolver'), (0x12c53cdD1ef150E1cd291DD210b761acFADA6B9C, 'prod', 'Enso'), (0xf671d28fef15e5eafc21898c2814b1b4cd88bc9a, 'prod', 'Gnosis_BalancerSOR'), (0x056545021B39790eFb0a074827e7FddCb751A179, 'prod', 'Gnosis_1inch'), @@ -86,7 +86,7 @@ known_solver_metadata (address, environment, name) as ( (0x5D665472e2026C405aAc65cC652470a1B8FCff08, 'prod', 'Baseline'), (0xe71D3324E17E99B56c294067370D45111bc968D6, 'prod', 'Quasimodo'), (0xa7c4C18106e92Cea479627D02FAb583D987f17d9, 'prod', 'Gnosis_1inch'), - (0xfaBBDf8a77005C00edBe0000bDC000644c024322, 'prod', 'CopiumCapital'), + (0xfaBBDf8a77005C00edBe0000bDC000644c024322, 'prod', 'Copium_Capital'), (0x68dEE65bB88d919463495E5CeA9870a81f1e9413, 'service', 'Withdraw'), (0xa03be496e67ec29bc62f01a428683d7f9c204930, 'service', 'Withdraw'), (0x7524942F9283FBFa8F17b05CC0a9cBde397d25b3, 'test', 'Test 1') From e579cd1944bd134f24d126a5f436c70b1d3fb6ce Mon Sep 17 00:00:00 2001 From: bram-vdberg Date: Thu, 5 Dec 2024 20:27:21 +0100 Subject: [PATCH 66/68] Add new solvers to Arbitrum and Ethereum (#7245) Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql | 6 ++++++ .../cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql | 2 ++ 2 files changed, 8 insertions(+) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql index 5b0751da6a5..4b73365d687 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql @@ -50,6 +50,12 @@ known_solver_metadata (address, environment, name) as ( (0x40798d2261f8b7F11BFa73623c99C876844dD05A, 'prod', 'OpenOcean_Aggregator'), (0x0648548f891E1356f197070D009704e574182bfB, 'prod', 'Rizzolver'), (0x23e868881dfe0531358B8FE0cbec43FD860cbF33, 'prod', 'Rizzolver'), + (0x2692F7bFCB2e1a8575434b9511804266D9aeb628, 'prod', 'Velvet'), + (0x0148538e6cA813D41eA5988008Cdc9B72d4e65A7, 'prod', 'Laita'), + (0x1FA2FF499b327f53cD9a82BcAFE36093563E32e4, 'prod', 'Apollo'), + (0x5E06F88D28603f5bB106bD5C8AD93ce2E902d24b, 'barn', 'Apollo'), + (0x034F6Aca83F1900b0157b0123F514A29456eeA59, 'barn', 'Laita'), + (0x669Be18D403Be353C1B9EBC87225313Ec2560BF5, 'barn', 'Velvet'), (0x20dC1014E946Cf511Ee535D908eC9a1d75Dd66ce, 'barn', 'Naive'), (0x2e6822f4Ab355E386d1A4fd34947ACE0F6f344a7, 'barn', 'Baseline'), (0x03a65D265E0613326ca23f5E6A1a99Ab2F12600B, 'barn', 'Quasimodo'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql index 7847ccd2d23..489038303a2 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql @@ -118,6 +118,8 @@ known_solver_metadata (address, environment, name) as ( (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), (0x95480d3f27658e73b2785d30beb0c847d78294c7, 'prod', 'Fractal'), (0x00806DaA2Cfe49715eA05243FF259DeB195760fC, 'prod', 'Quasilabs'), + (0x28B1bd44996105b5c14c4dE41093226Ff78A4eB1, 'prod', '0x'), + (0xcC73072B53697911Ff394ae01D3de59c9900b0b0, 'barn', '0x'), (0xd0bA1b1782fbdE45edAb392428f60e14827D08EC, 'barn', 'Laita'), (0x7E2eF26AdccB02e57258784957922AEEFEe807e5, 'barn', 'Quasilabs'), (0x5131590ca2E9D3edC182581352b289dcaE83430c, 'barn', 'Portus'), From 9b16e752c03f508a994c0a40483bc59b48e1b1e7 Mon Sep 17 00:00:00 2001 From: Jason4276 <155130636+Jason4276@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:57:33 +0530 Subject: [PATCH 67/68] Added infusion dex on base chain (#7204) * Added infusion dex * Updated sql file * updated dex_info file * Update _schema.yml --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/base/_schema.yml | 17 ++++++++++++++++ .../trades/base/dex_base_base_trades.sql | 1 + .../platforms/infusion_base_base_trades.sql | 20 +++++++++++++++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 15 ++++++++++++++ .../trades/infusion_base_base_trades_seed.csv | 2 ++ sources/_sector/dex/trades/base/_sources.yml | 5 +++++ 7 files changed, 61 insertions(+) create mode 100644 dbt_subprojects/dex/models/trades/base/platforms/infusion_base_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/infusion_base_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index 214f25e6c75..ba4dd6586d7 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -185,6 +185,7 @@ FROM (VALUES , ('kaia_swap', 'KaiaSwap', 'Direct', 'KaiaSwap') , ('defi_kingdoms', 'DeFi Kingdoms', 'Direct', 'DeFiKingdoms') , ('hyperjump', 'HyperJump', 'Direct', 'Hyperjump_fi') + , ('infusion', 'Infusion', 'Direct', 'infusionfinance') , ('stablebase', 'StableBase', 'Direct', 'stablebasefi') , ('flashliquidity', 'Flashliquidity', 'Direct', 'flashliquidity') , ('akronswap', 'Akronswap', 'Direct', 'AkronFinance') diff --git a/dbt_subprojects/dex/models/trades/base/_schema.yml b/dbt_subprojects/dex/models/trades/base/_schema.yml index b7b9bea1fce..fde1b6d7532 100644 --- a/dbt_subprojects/dex/models/trades/base/_schema.yml +++ b/dbt_subprojects/dex/models/trades/base/_schema.yml @@ -991,6 +991,23 @@ models: - check_dex_base_trades_seed: seed_file: ref('xchange_base_base_trades_seed') + - name: infusion_base_base_trades + meta: + blockchain: base + sector: dex + project: infusion + contributors: jason + config: + tags: [ 'base', 'dex', 'trades', 'infusion' ] + description: "infusion base base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('infusion_base_base_trades_seed') + - name: flashliquidity_base_base_trades meta: blockchain: base diff --git a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql index 27346a29e34..fb04c901264 100644 --- a/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/base/dex_base_base_trades.sql @@ -51,6 +51,7 @@ , ref('solidly_v3_base_base_trades') , ref('swaap_v2_base_base_trades') , ref('xchange_base_base_trades') + , ref('infusion_base_base_trades') , ref('flashliquidity_base_base_trades') , ref('akronswap_base_base_trades') ] %} diff --git a/dbt_subprojects/dex/models/trades/base/platforms/infusion_base_base_trades.sql b/dbt_subprojects/dex/models/trades/base/platforms/infusion_base_base_trades.sql new file mode 100644 index 00000000000..e8d326a8c0b --- /dev/null +++ b/dbt_subprojects/dex/models/trades/base/platforms/infusion_base_base_trades.sql @@ -0,0 +1,20 @@ +{{ config( + schema = 'infusion_base' + , 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 = 'base' + , project = 'infusion' + , version = '1' + , Pair_evt_Swap = source('infusion_base', 'Pair_evt_Swap') + , Factory_evt_PairCreated = source('infusion_base', 'PairFactory_evt_PairCreated') + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index 24f8e049c5e..fb61bd5db94 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -4455,6 +4455,21 @@ seeds: token_sold_amount_raw: uint256 block_date: timestamp + - name: infusion_base_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp + - name: flashliquidity_base_base_trades_seed config: column_types: diff --git a/dbt_subprojects/dex/seeds/trades/infusion_base_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/infusion_base_base_trades_seed.csv new file mode 100644 index 00000000000..9026a315cd2 --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/infusion_base_base_trades_seed.csv @@ -0,0 +1,2 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw +base,infusion,1,2024-11-28,0x7d88692c8f071f5cc7c08451d7f2cc493f745949cbc05e6579e73d292df47eb1,77,0x4200000000000000000000000000000000000006,0x833589fcd6edb6e08f4c7c32d4f71b54bda02913,22989322,10575964385728786,38099604 \ No newline at end of file diff --git a/sources/_sector/dex/trades/base/_sources.yml b/sources/_sector/dex/trades/base/_sources.yml index b7f7ad8a6ba..0bb8805bdcc 100644 --- a/sources/_sector/dex/trades/base/_sources.yml +++ b/sources/_sector/dex/trades/base/_sources.yml @@ -189,6 +189,10 @@ sources: tables: - name: XchangePair_evt_Swap - name: XchangeFactory_evt_PairCreated + - name: infusion_base + tables: + - name: Pair_evt_Swap + - name: PairFactory_evt_PairCreated - name: flashliquidity_base tables: - name: FlashLiquidityPair_evt_Swap @@ -197,3 +201,4 @@ sources: tables: - name: UniswapV2Pair_evt_Swap - name: UniswapV2Factory_evt_PairCreated + From ea6d73ac4438b8798754030208e5aa73e03ec634 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 6 Dec 2024 03:27:44 +0800 Subject: [PATCH 68/68] Add transfers into boba sources (#7244) --- .../_base_sources/evm/boba_base_sources.yml | 109 ++++++++++++++++++ sources/_base_sources/evm/boba_docs_block.md | 58 ++++++++++ 2 files changed, 167 insertions(+) diff --git a/sources/_base_sources/evm/boba_base_sources.yml b/sources/_base_sources/evm/boba_base_sources.yml index 4d9ab561dd0..a277253d1c5 100644 --- a/sources/_base_sources/evm/boba_base_sources.yml +++ b/sources/_base_sources/evm/boba_base_sources.yml @@ -333,3 +333,112 @@ sources: description: "Excess blob gas in this block" - name: parent_beacon_block_root description: "Root hash of the parent beacon block" + + - name: erc20_boba + description: "Transfer events for ERC20 tokens on Boba blockchain" + tables: + - name: evt_transfer + meta: + docs_slug: /evm/boba/raw/erc20_transfers + short_description: The evt_transfer table contains all ERC20 token transfer events on the Boba blockchain. + description: '{{ doc("erc20_boba_evt_transfer_doc") }}' + columns: + - name: contract_address + description: "The address of the ERC20 token contract" + - name: from + description: "The address sending the tokens" + - name: to + description: "The address receiving the tokens" + - name: value + description: "The amount of tokens transferred" + - name: evt_tx_hash + description: "The transaction hash of the transfer event" + - name: evt_index + description: "The index of this event within the transaction" + - name: evt_block_time + description: "The timestamp of the block containing this transfer" + - name: evt_block_number + description: "The block number containing this transfer" + + - name: erc721_boba + description: "Transfer events for ERC721 tokens on Boba blockchain" + tables: + - name: evt_transfer + meta: + docs_slug: /evm/boba/raw/erc721_transfers + short_description: The evt_transfer table contains all ERC721 token transfer events on the Boba blockchain. + description: '{{ doc("erc721_boba_evt_transfer_doc") }}' + columns: + - name: contract_address + description: "The address of the ERC721 token contract" + - name: from + description: "The address sending the NFT" + - name: to + description: "The address receiving the NFT" + - name: tokenId + description: "The unique identifier of the NFT being transferred" + - name: evt_tx_hash + description: "The transaction hash of the transfer event" + - name: evt_index + description: "The index of this event within the transaction" + - name: evt_block_time + description: "The timestamp of the block containing this transfer" + - name: evt_block_number + description: "The block number containing this transfer" + + - name: erc1155_boba + description: "Transfer events for ERC1155 tokens on Boba blockchain" + tables: + - name: evt_transfersingle + meta: + docs_slug: /evm/boba/raw/erc1155_transfers_single + short_description: The evt_transfersingle table contains single token transfer events from ERC1155 contracts on the Boba blockchain. + description: '{{ doc("erc1155_boba_evt_transfer_doc") }}' + columns: + - name: contract_address + description: "The address of the ERC1155 token contract" + - name: operator + description: "The address authorized to make the transfer" + - name: from + description: "The address sending the tokens" + - name: to + description: "The address receiving the tokens" + - name: id + description: "The identifier for the token being transferred" + - name: value + description: "The amount of tokens being transferred" + - name: evt_tx_hash + description: "The transaction hash of the transfer event" + - name: evt_index + description: "The index of this event within the transaction" + - name: evt_block_time + description: "The timestamp of the block containing this transfer" + - name: evt_block_number + description: "The block number containing this transfer" + + - name: evt_transferbatch + meta: + docs_slug: /evm/boba/raw/erc1155_transfers_batch + short_description: The evt_transferbatch table contains batch token transfer events from ERC1155 contracts on the Boba blockchain. + description: '{{ doc("erc1155_boba_evt_transfer_doc") }}' + columns: + - name: contract_address + description: "The address of the ERC1155 token contract" + - name: operator + description: "The address authorized to make the transfer" + - name: from + description: "The address sending the tokens" + - name: to + description: "The address receiving the tokens" + - name: ids + description: "The array of token identifiers being transferred" + - name: values + description: "The array of amounts being transferred for each token id" + - name: evt_tx_hash + description: "The transaction hash of the transfer event" + - name: evt_index + description: "The index of this event within the transaction" + - name: evt_block_time + description: "The timestamp of the block containing this transfer" + - name: evt_block_number + description: "The block number containing this transfer" diff --git a/sources/_base_sources/evm/boba_docs_block.md b/sources/_base_sources/evm/boba_docs_block.md index 90a77a0192c..bf83ec57bb7 100644 --- a/sources/_base_sources/evm/boba_docs_block.md +++ b/sources/_base_sources/evm/boba_docs_block.md @@ -160,3 +160,61 @@ This table is used for: It's essentially a filtered version of the `boba.traces` table where `type = create`. {% enddocs %} + +{% docs erc20_boba_evt_transfer_doc %} + +The `erc20_boba.evt_transfer` table contains Transfer events from ERC20 token contracts on the Boba blockchain. Each record represents a token transfer and includes: + +- Token contract address +- Sender and recipient addresses +- Amount of tokens transferred +- Block and transaction information +- Event log details + +This table is essential for: +- Tracking token transfers and holder activity +- Analyzing token distribution patterns +- Monitoring token holder behavior +- Calculating token balances +- Understanding token velocity and liquidity + +{% enddocs %} + +{% docs erc721_boba_evt_transfer_doc %} + +The `erc721_boba.evt_transfer` table contains Transfer events from ERC721 (NFT) token contracts on the Boba blockchain. Each record represents an NFT transfer and includes: + +- NFT contract address +- Token ID +- Sender and recipient addresses +- Block and transaction information +- Event log details + +This table is used for: +- Tracking NFT ownership changes +- Analyzing NFT trading patterns +- Monitoring NFT collection activity +- Building NFT holder histories +- Understanding NFT market dynamics + +{% enddocs %} + +{% docs erc1155_boba_evt_transfer_doc %} + +The `erc1155_boba.evt_transfersingle` and `erc1155_boba.evt_transferbatch` tables contain Transfer events from ERC1155 token contracts on the Boba blockchain. These tables track both fungible and non-fungible token transfers within the same contract. They include: + +- Token contract address +- Token IDs +- Amounts transferred +- Sender, operator, and recipient addresses +- Block and transaction information +- Event log details + +These tables are essential for: +- Tracking multi-token transfers +- Analyzing gaming asset movements +- Monitoring hybrid token systems +- Understanding complex token ecosystems +- Building token holder analytics + +{% enddocs %}