From 90816fc2632963dd03ad8237bdb477c4b6116c6e Mon Sep 17 00:00:00 2001 From: Sam <110511194+sam-xyz@users.noreply.github.com> Date: Wed, 12 Feb 2025 21:29:45 +0800 Subject: [PATCH] An 5332/base standardization v2 (#250) * add core * bridges * add dex * add lending * add nft * core changes * add docs * misc * fix * docs * change to blocktimestamp * set to March 10 * make table * add mega --- .github/workflows/dbt_run_adhoc.yml | 17 +- macros/dbt/incremental_predicates.sql | 22 + macros/tests/missing_decoding.sql | 14 +- .../fsc_evm/L1_submission_fields.md | 89 +++ models/doc_descriptions/fsc_evm/blocks.md | 143 +++++ .../fsc_evm/complete_general.md | 65 ++ models/doc_descriptions/fsc_evm/event_logs.md | 83 +++ .../fsc_evm/evm_deprecations.md | 203 ++++++ models/doc_descriptions/fsc_evm/nft.md | 587 ++++++++++++++++++ models/doc_descriptions/fsc_evm/traces.md | 125 ++++ .../doc_descriptions/fsc_evm/transactions.md | 188 ++++++ models/doc_descriptions/fsc_evm/transfers.md | 144 +++++ .../transfers/evm_transfers_table_doc.md | 17 - .../gold/core/core__ez_decoded_event_logs.sql | 60 +- .../gold/core/core__ez_decoded_event_logs.yml | 32 +- .../gold/core/core__ez_native_transfers.sql | 19 +- .../gold/core/core__ez_native_transfers.yml | 12 +- models/gold/core/core__ez_token_transfers.sql | 16 +- models/gold/core/core__ez_token_transfers.yml | 20 +- models/gold/core/core__fact_blocks.sql | 93 +-- models/gold/core/core__fact_blocks.yml | 56 +- .../core/core__fact_decoded_event_logs.yml | 37 +- models/gold/core/core__fact_event_logs.sql | 27 +- models/gold/core/core__fact_event_logs.yml | 44 +- .../gold/core/core__fact_token_transfers.yml | 12 +- models/gold/core/core__fact_traces.sql | 4 + models/gold/core/core__fact_traces.yml | 105 ++-- models/gold/core/core__fact_transactions.sql | 60 +- models/gold/core/core__fact_transactions.yml | 94 +-- models/gold/defi/defi__ez_dex_swaps.sql | 4 +- models/gold/defi/defi__ez_dex_swaps.yml | 10 +- models/gold/nft/nft__ez_nft_sales.sql | 16 +- models/gold/nft/nft__ez_nft_sales.yml | 64 +- models/gold/nft/nft__ez_nft_transfers.sql | 34 +- models/gold/nft/nft__ez_nft_transfers.yml | 30 +- models/silver/abis/silver__proxies.sql | 4 +- .../abis/silver__user_verified_abis.sql | 2 +- .../silver/core/silver__created_contracts.sql | 4 +- models/silver/core/silver__logs.sql | 6 + .../silver/core/silver__native_transfers.sql | 49 +- .../core/silver__relevant_contracts.sql | 10 +- models/silver/core/silver__transfers.sql | 12 +- models/silver/core/silver__tx_count.sql | 6 +- .../silver_bridge__across_fundsdeposited.sql | 44 +- ...silver_bridge__across_v3fundsdeposited.sql | 50 +- .../silver_bridge__allbridge_tokens_sent.sql | 10 +- ...r_bridge__axelar_contractcallwithtoken.sql | 86 ++- .../silver_bridge__celer_cbridge_send.sql | 38 +- ...lver_bridge__dln_debridge_createdorder.sql | 64 +- .../hop/silver_bridge__hop_ammwrapper.sql | 6 +- .../hop/silver_bridge__hop_transfersent.sql | 48 +- .../meson/silver_bridge__meson_transfers.sql | 62 +- .../silver_bridge__stargate_createpool.sql | 2 +- .../stargate/silver_bridge__stargate_swap.sql | 38 +- ...er_bridge__symbiosis_synthesizerequest.sql | 36 +- .../silver_bridge__synapse_token_bridge.sql | 30 +- ...ver_bridge__synapse_tokenbridgeandswap.sql | 38 +- .../silver_bridge__wormhole_transfers.sql | 103 ++- .../aerodrome/silver_dex__aerodrome_pools.sql | 12 +- ...silver_dex__aerodrome_slipstream_pools.sql | 26 +- ...silver_dex__aerodrome_slipstream_swaps.sql | 18 +- .../aerodrome/silver_dex__aerodrome_swaps.sql | 12 +- .../alienbase/silver_dex__alienbase_pools.sql | 12 +- .../alienbase/silver_dex__alienbase_swaps.sql | 12 +- .../balancer/silver_dex__balancer_pools.sql | 32 +- .../balancer/silver_dex__balancer_swaps.sql | 16 +- .../baseswap/silver_dex__baseswap_pools.sql | 12 +- .../baseswap/silver_dex__baseswap_swaps.sql | 12 +- .../dex/curve/silver_dex__curve_pools.sql | 4 +- .../dex/curve/silver_dex__curve_swaps.sql | 18 +- .../dackieswap/silver_dex__dackie_pools.sql | 24 +- .../dackieswap/silver_dex__dackie_swaps.sql | 16 +- .../maverick/silver_dex__maverick_pools.sql | 12 +- .../maverick/silver_dex__maverick_swaps.sql | 12 +- .../dex/sushi/silver_dex__sushi_pools.sql | 24 +- .../dex/sushi/silver_dex__sushi_swaps.sql | 16 +- .../swapbased/silver_dex__swapbased_pools.sql | 12 +- .../swapbased/silver_dex__swapbased_swaps.sql | 12 +- .../dex/uniswap/silver_dex__univ2_pools.sql | 12 +- .../dex/uniswap/silver_dex__univ2_swaps.sql | 12 +- .../dex/uniswap/silver_dex__univ3_pools.sql | 24 +- .../dex/uniswap/silver_dex__univ3_swaps.sql | 16 +- .../dex/voodoo/silver_dex__voodoo_swaps.sql | 12 +- .../dex/woofi/silver_dex__woofi_swaps.sql | 24 +- .../lending/aave/silver__aave_borrows.sql | 12 +- .../lending/aave/silver__aave_deposits.sql | 12 +- .../lending/aave/silver__aave_flashloans.sql | 12 +- .../aave/silver__aave_liquidations.sql | 12 +- .../lending/aave/silver__aave_repayments.sql | 12 +- .../defi/lending/aave/silver__aave_tokens.sql | 25 +- .../lending/aave/silver__aave_withdraws.sql | 12 +- .../lending/compound/silver__comp_borrows.sql | 28 +- .../compound/silver__comp_deposits.sql | 30 +- .../compound/silver__comp_liquidations.sql | 30 +- .../compound/silver__comp_repayments.sql | 28 +- .../compound/silver__comp_withdraws.sql | 27 +- .../granary/silver__granary_borrows.sql | 21 +- .../granary/silver__granary_deposits.sql | 25 +- .../granary/silver__granary_flashloans.sql | 24 +- .../granary/silver__granary_liquidations.sql | 23 +- .../granary/silver__granary_repayments.sql | 24 +- .../granary/silver__granary_tokens.sql | 26 +- .../granary/silver__granary_withdraws.sql | 24 +- .../silver__moonwell_asset_details.sql | 17 +- .../moonwell/silver__moonwell_borrows.sql | 14 +- .../moonwell/silver__moonwell_deposits.sql | 12 +- .../silver__moonwell_liquidations.sql | 12 +- .../moonwell/silver__moonwell_repayments.sql | 14 +- .../moonwell/silver__moonwell_withdraws.sql | 14 +- .../lending/morpho/silver__morpho_borrows.sql | 47 +- .../morpho/silver__morpho_deposits.sql | 47 +- .../morpho/silver__morpho_flashloans.sql | 37 +- .../morpho/silver__morpho_liquidations.sql | 14 +- .../morpho/silver__morpho_repayments.sql | 47 +- .../morpho/silver__morpho_withdraws.sql | 48 +- .../seamless/silver__seamless_borrows.sql | 21 +- .../seamless/silver__seamless_deposits.sql | 25 +- .../seamless/silver__seamless_flashloans.sql | 24 +- .../silver__seamless_liquidations.sql | 23 +- .../seamless/silver__seamless_repayments.sql | 24 +- .../seamless/silver__seamless_tokens.sql | 22 +- .../seamless/silver__seamless_withdraws.sql | 24 +- .../sonne/silver__sonne_asset_details.sql | 14 +- .../lending/sonne/silver__sonne_borrows.sql | 14 +- .../lending/sonne/silver__sonne_deposits.sql | 12 +- .../sonne/silver__sonne_liquidations.sql | 12 +- .../sonne/silver__sonne_repayments.sql | 14 +- .../lending/sonne/silver__sonne_withdraws.sql | 14 +- .../silver/ethereum/silver__state_hashes.sql | 5 +- .../nft/sales/silver__element_sales.sql | 48 +- .../nft/sales/silver__seaport_1_5_sales.sql | 114 ++-- .../nft/sales/silver__seaport_1_6_sales.sql | 114 ++-- .../silver/nft/sales/silver__zeroex_sales.sql | 54 +- models/silver/nft/silver__nft_transfers.sql | 12 +- .../silver_olas__create_service_multisigs.sql | 20 +- .../olas/silver_olas__service_event_logs.sql | 22 +- .../silver_olas__service_registrations.sql | 23 +- .../silver_stats__core_metrics_hourly.sql | 12 +- .../streamline__decoded_logs_realtime.sql | 166 ++--- 139 files changed, 3789 insertions(+), 1482 deletions(-) create mode 100644 macros/dbt/incremental_predicates.sql create mode 100644 models/doc_descriptions/fsc_evm/L1_submission_fields.md create mode 100644 models/doc_descriptions/fsc_evm/blocks.md create mode 100644 models/doc_descriptions/fsc_evm/complete_general.md create mode 100644 models/doc_descriptions/fsc_evm/event_logs.md create mode 100644 models/doc_descriptions/fsc_evm/evm_deprecations.md create mode 100644 models/doc_descriptions/fsc_evm/nft.md create mode 100644 models/doc_descriptions/fsc_evm/traces.md create mode 100644 models/doc_descriptions/fsc_evm/transactions.md create mode 100644 models/doc_descriptions/fsc_evm/transfers.md delete mode 100644 models/doc_descriptions/transfers/evm_transfers_table_doc.md diff --git a/.github/workflows/dbt_run_adhoc.yml b/.github/workflows/dbt_run_adhoc.yml index 92873f2..8427432 100644 --- a/.github/workflows/dbt_run_adhoc.yml +++ b/.github/workflows/dbt_run_adhoc.yml @@ -7,7 +7,7 @@ on: - "main" inputs: environment: - type: choice + type: choice description: DBT Run Environment required: true options: @@ -15,19 +15,20 @@ on: - prod default: dev warehouse: - type: choice + type: choice description: Snowflake warehouse - required: true + required: true options: - DBT - DBT_CLOUD - DBT_EMERGENCY + - DBT_MEGA default: DBT dbt_command: type: string - description: 'DBT Run Command' + description: "DBT Run Command" required: true - + env: DBT_PROFILES_DIR: ./ @@ -43,12 +44,10 @@ env: concurrency: group: ${{ github.workflow }} - - jobs: run_dbt_jobs: runs-on: ubuntu-latest - environment: + environment: name: workflow_${{ inputs.environment }} steps: @@ -65,4 +64,4 @@ jobs: dbt deps - name: Run DBT Jobs run: | - ${{ inputs.dbt_command }} \ No newline at end of file + ${{ inputs.dbt_command }} diff --git a/macros/dbt/incremental_predicates.sql b/macros/dbt/incremental_predicates.sql new file mode 100644 index 0000000..ba1bb2e --- /dev/null +++ b/macros/dbt/incremental_predicates.sql @@ -0,0 +1,22 @@ +{% macro standard_predicate( + input_column = 'block_number' + ) -%} + {%- set database_name = target.database -%} + {%- set schema_name = generate_schema_name( + node = model + ) -%} + {%- set table_name = generate_alias_name( + node = model + ) -%} + {%- set tmp_table_name = table_name ~ '__dbt_tmp' -%} + {%- set full_table_name = database_name ~ '.' ~ schema_name ~ '.' ~ table_name -%} + {%- set full_tmp_table_name = database_name ~ '.' ~ schema_name ~ '.' ~ tmp_table_name -%} + {{ full_table_name }}.{{ input_column }} >= ( + SELECT + MIN( + {{ input_column }} + ) + FROM + {{ full_tmp_table_name }} + ) +{%- endmacro %} diff --git a/macros/tests/missing_decoding.sql b/macros/tests/missing_decoding.sql index b14190a..4a61add 100644 --- a/macros/tests/missing_decoding.sql +++ b/macros/tests/missing_decoding.sql @@ -1,14 +1,22 @@ {% test missing_decoded_logs(model) %} SELECT l.block_number, - l._log_id + CONCAT( + l.tx_hash, + '-', + l.event_index + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN {{ model }} d ON l.block_number = d.block_number - AND l._log_id = d._log_id + AND CONCAT( + l.tx_hash, + '-', + l.event_index + ) = d._log_id WHERE l.contract_address = LOWER('0x4200000000000000000000000000000000000006') -- WETH AND l.topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' -- Transfer diff --git a/models/doc_descriptions/fsc_evm/L1_submission_fields.md b/models/doc_descriptions/fsc_evm/L1_submission_fields.md new file mode 100644 index 0000000..8edb229 --- /dev/null +++ b/models/doc_descriptions/fsc_evm/L1_submission_fields.md @@ -0,0 +1,89 @@ +{% docs evm_batch_size %} + +Total transactions included within the batch on the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_max_block %} + +The max block on the OP stack L2 chain this batch relates to. + +{% enddocs %} + +{% docs evm_min_block %} + +The min block on the OP stack L2 chain this batch relates to. + +{% enddocs %} + +{% docs evm_batch_root %} + +Root of the batch, either for submission or state on the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_block_no %} + +The Ethereum block number that contained the batch from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_block_time %} + +The timestamp of the Ethereum block that contained this batch from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_fee %} + +The L1 portion of fees paid. + +{% enddocs %} + +{% docs evm_l1_fee_scalar %} + +This value covers the change in L1 gas price between the time the transaction is submitted and when it is published from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_gas_price %} + +The gas price for L1 transactions when the transaction was processed from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_gas_used %} + +The gas used on L1 to publish the transaction from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_state_batch %} + +The batch index of when this block was included in the Ethereum state root. This column will be deprecated 8/7 and will be consolidated into an array column consisting of all L1 submission details from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_state_tx_hash %} + +The L1 tx hash of when this block was included in the Ethereum state root. This column will be deprecated 8/7 and will be consolidated into an array column consisting of all L1 submission details from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_sub_batch %} + +The batch index of when this block was submitted to L1. This column will be deprecated 8/7 and will be consolidated into an array column consisting of all L1 submission details from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_l1_sub_tx_hash %} + +The L1 tx hash of when this block was submitted to L1. This column will be deprecated 8/7 and will be consolidated into an array column consisting of all L1 submission details from the OP stack L2 chain. + +{% enddocs %} + +{% docs evm_prev_total_elements %} + +Confirmed blocks prior to this batch on the OP stack L2 chain. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/blocks.md b/models/doc_descriptions/fsc_evm/blocks.md new file mode 100644 index 0000000..2f2f846 --- /dev/null +++ b/models/doc_descriptions/fsc_evm/blocks.md @@ -0,0 +1,143 @@ +{% docs evm_blocks_table_doc %} + +This table contains block level data for this EVM blockchain. This table can be used to analyze trends at a block level, for example gas fees vs. total transactions over time. For more information, please see [Etherscan Resources](https://etherscan.io/directory/Learning_Resources/Ethereum) or [The Ethereum Organization](https://ethereum.org/en/developers/docs/blocks/) + +{% enddocs %} + +{% docs evm_block_header_json %} + +This JSON column contains the block header details. + +{% enddocs %} + +{% docs evm_blockchain %} + +The blockchain on which transactions are being confirmed. + +{% enddocs %} + +{% docs evm_blocks_hash %} + +The hash of the block header for a given block. + +{% enddocs %} + +{% docs evm_blocks_nonce %} + +Block nonce is a value used during mining to demonstrate proof of work for a given block. + +{% enddocs %} + +{% docs evm_difficulty %} + +The effort required to mine the block. + +{% enddocs %} + +{% docs evm_extra_data %} + +Any data included by the miner for a given block. + +{% enddocs %} + +{% docs evm_gas_limit %} + +Total gas limit provided by all transactions in the block. + +{% enddocs %} + +{% docs evm_gas_used %} + +Total gas used in the block. + +{% enddocs %} + +{% docs evm_network %} + +The network on the blockchain used by a transaction. + +{% enddocs %} + +{% docs evm_parent_hash %} + +The hash of the block from which a given block is generated. Also known as the parent block. + +{% enddocs %} + +{% docs evm_receipts_root %} + +The root of the state trie. + +{% enddocs %} + +{% docs evm_sha3_uncles %} + +The mechanism which Ethereum Javascript RLP encodes an empty string. + +{% enddocs %} + +{% docs evm_size %} + +Block size, which is determined by a given block's gas limit. + +{% enddocs %} + +{% docs evm_total_difficulty %} + +Total difficulty of the chain at a given block. + +{% enddocs %} + +{% docs evm_tx_count %} + +Total number of transactions within a block. + +{% enddocs %} + +{% docs evm_uncle_blocks %} + +Uncle blocks occur when two blocks are mined and broadcasted at the same time, with the same block number. The block validated across the most nodes will be added to the primary chain, and the other one becomes an uncle block. Miners do receive rewards for uncle blocks. + +{% enddocs %} + +{% docs evm_miner %} + +The address of the beneficiary to whom the mining rewards were given + +{% enddocs %} + +{% docs evm_state_root %} + +The root of the final state trie of the block + +{% enddocs %} + +{% docs evm_transactions_root %} + +The root of the transaction trie of the block + +{% enddocs %} + +{% docs evm_logs_bloom %} + +The bloom filter for the logs of the block. + +{% enddocs %} + +{% docs evm_mix_hash %} + +A string of a 256-bit hash encoded as a hexadecimal + +{% enddocs %} + +{% docs evm_base_fee_per_gas %} + +A string of the base fee encoded in hexadecimal format. Please note that this response field will not be included in a block requested before the EIP-1559 upgrade + +{% enddocs %} + +{% docs evm_withdrawals_root %} + +The root of the withdrawals trie. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/complete_general.md b/models/doc_descriptions/fsc_evm/complete_general.md new file mode 100644 index 0000000..77e2b35 --- /dev/null +++ b/models/doc_descriptions/fsc_evm/complete_general.md @@ -0,0 +1,65 @@ +{% docs evm_block_number %} + +Also known as block height. The block number, which indicates the length of the blockchain, increases after the addition of each new block. + +{% enddocs %} + +{% docs evm_block_timestamp %} + +The date and time at which the block was produced. + +{% enddocs %} + +{% docs evm_from_address %} + +The sending address of this transaction. + +{% enddocs %} + +{% docs evm_ingested_at %} + +Internal column. + +{% enddocs %} + +{% docs evm_to_address %} + +The receiving address of this transaction. This can be a contract address. + +{% enddocs %} + +{% docs evm_pk %} + +The unique identifier for each row in the table. + +{% enddocs %} + +{% docs evm_inserted_timestamp %} + +The UTC timestamp at which the row was inserted into the table. + +{% enddocs %} + +{% docs evm_modified_timestamp %} + +The UTC timestamp at which the row was last modified. + +{% enddocs %} + +{% docs evm_precise_amount_unadjusted %} + +The precise, unadjusted amount of the transaction. This is returned as a string to avoid precision loss. + +{% enddocs %} + +{% docs evm_precise_amount_adjusted %} + +The precise, adjusted amount of the transaction. This is returned as a string to avoid precision loss. + +{% enddocs %} + +{% docs evm_value_hex %} + +The value of the transaction in hexadecimal format. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/event_logs.md b/models/doc_descriptions/fsc_evm/event_logs.md new file mode 100644 index 0000000..8880f5c --- /dev/null +++ b/models/doc_descriptions/fsc_evm/event_logs.md @@ -0,0 +1,83 @@ +{% docs evm_logs_table_doc %} + +This table contains flattened event logs from transactions on this EVM blockchain. Transactions may have multiple events, which are denoted by the event index for a transaction hash. Therefore, this table is unique on the combination of transaction hash and event index. Please see `fact_decoded_event_logs` or `ez_decoded_event_logs` for the decoded event logs. + +{% enddocs %} + +{% docs evm_event_index %} + +Event number within a transaction. + +{% enddocs %} + +{% docs evm_event_inputs %} + +The decoded event inputs for a given event. + +{% enddocs %} + +{% docs evm_event_removed %} + +Whether the event has been removed from the transaction. + +{% enddocs %} + +{% docs evm_log_id_events %} + +This is the primary key for this table. This is a concatenation of the transaction hash and the event index at which the event occurred. This field can be used within other event based tables such as `fact_transfers` & `ez_token_transfers`. + +{% enddocs %} + +{% docs evm_logs_contract_address %} + +The address interacted with for a given event. + +{% enddocs %} + +{% docs evm_logs_contract_name %} + +The name of the contract or token, where possible. + +{% enddocs %} + +{% docs evm_logs_data %} + +The un-decoded event data. + +{% enddocs %} + +{% docs evm_logs_tx_hash %} + +Transaction hash is a unique 66-character identifier that is generated when a transaction is executed. This field will not be unique in this table, as a given transaction can include multiple events. + +{% enddocs %} + +{% docs evm_topics %} + +The un-decoded event input topics. + +{% enddocs %} + +{% docs evm_topic_0 %} + +The first topic of the event, which is a unique identifier for the event. + +{% enddocs %} + +{% docs evm_topic_1 %} + +The second topic of the event, if applicable. + +{% enddocs %} + +{% docs evm_topic_2 %} + +The third topic of the event, if applicable. + +{% enddocs %} + +{% docs evm_topic_3 %} + +The fourth topic of the event, if applicable. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/evm_deprecations.md b/models/doc_descriptions/fsc_evm/evm_deprecations.md new file mode 100644 index 0000000..331f1c2 --- /dev/null +++ b/models/doc_descriptions/fsc_evm/evm_deprecations.md @@ -0,0 +1,203 @@ +{% docs evm_column_deprecation_notice %} + +This column is being deprecated for standardization purposes. Please update your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_hash %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `block_hash` column instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_block_hash %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_position %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `tx_position` column instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_tx_status %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `tx_succeeded` column instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_chain_id %} + +This column is being removed for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_identifier %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `trace_address` column instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_trace_status %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `trace_succeeded` column instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_log_id %} + +This column is being removed for standardization purposes. Please remove or update your queries with `CONCAT(tx_hash, '_', event_index)` to reconstruct `_log_id` by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_inserted_timestamp %} + +This column is being removed for standardization purposes. Please update your queries to use the `modified_timestamp` column instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_blockchain %} + +This column is being removed for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_block_header_json %} + +This column is being removed for standardization purposes and will be replaced with new columns associated with the keys extracted from this json. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_table_deprecation_notice %} + +This table is being deprecated for standardization purposes. Please update your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_table_deprecation_notice_fact_decoded_event_logs %} + +This table is being deprecated for standardization purposes. Please update your queries to use `ez_decoded_event_logs` instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_table_deprecation_notice_fact_decoded_traces %} + +This table is being deprecated for standardization purposes. Please update your queries to use `ez_decoded_traces` instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_table_deprecation_notice_fact_token_transfers %} + +This table is being deprecated for standardization purposes. Please update your queries to use `ez_token_transfers` instead by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_l1_state_root_tx_hash %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_l1_state_root_batch_index %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_l1_submission_tx_hash %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_l1_submission_batch_index %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_l1_submission_details %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_data %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_deposit_nonce %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_deposit_receipt_version %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_token_price %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_has_decimal %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{% docs evm_column_deprecation_notice_has_price %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_tokenid %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `token_id` column instead by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_erc1155_value %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_nft_address %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `contract_address` column instead by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_project_name %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `name` column instead by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_event_type %} + +This column is being deprecated for standardization purposes. Please remove from your queries by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_nft_from_address %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `from_address` column instead by March 10, 2025. + +{% enddocs %} + +{%docs evm_column_deprecation_notice_nft_to_address %} + +This column is being deprecated for standardization purposes. Please update your queries to use the `to_address` column instead by March 10, 2025. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/nft.md b/models/doc_descriptions/fsc_evm/nft.md new file mode 100644 index 0000000..dba8714 --- /dev/null +++ b/models/doc_descriptions/fsc_evm/nft.md @@ -0,0 +1,587 @@ +{% docs evm_nft_events_table_doc %} + +This table contains NFT sales on this EVM blockchain. More NFT marketplaces will be added over time. + +{% enddocs %} + +{% docs evm_ez_nft_sales_table_doc %} + +This table contains NFT sale events from various marketplaces. + +{% enddocs %} + +{% docs evm_ez_nft_mint_table_doc %} + +This table contains NFT mint events, defined as NFT transfers from a burn address to an address, on this EVM blockchain. + +{% enddocs %} + +{% docs evm_ez_nft_transfer_table_doc %} + +This table contains NFT transfer events on this EVM blockchain. + +{% enddocs %} + +{% docs evm_lending_repayments_table_doc %} + +This table contains repayment events for loans backed by collateralized NFTs on this EVM blockchain. Events in this table can be a full repayment either by the borrower to get their collateral back or by a new lender to repay the borrower's previous loan. The latter is labeled as refinance where the same borrower takes on a new loan from a new lender and repays the past loan. The NFT collateral is still locked in this scenario. + +{% enddocs %} + +{% docs evm_nft_aggregator_name %} + +The name of the aggregator platform where the sale took place. If the sale did not take place via an aggregator platform, then the value will be null. + +{% enddocs %} + +{% docs evm_nft_amount %} + +The total amount, specified by the mint token address, used as payment to mint the specified number of NFTs corresponding to this token id. + +{% enddocs %} + +{% docs evm_nft_amount_usd %} + +The USD value of amount. + +{% enddocs %} + +{% docs evm_nft_block_no %} + +The block number at which the NFT event occurred. + +{% enddocs %} + +{% docs evm_nft_blocktime %} + +The block timestamp at which the NFT event occurred. + +{% enddocs %} + +{% docs evm_nft_buyer_address %} + +The address of the buyer of the NFT in the transaction. + +{% enddocs %} + +{% docs evm_nft_creator_fee %} + +The decimal adjusted amount of fees paid to the NFT collection as royalty payments for this NFT event in the transaction's currency. + +{% enddocs %} + +{% docs evm_nft_creator_fee_usd %} + +The amount of fees paid to the NFT collection as royalty payments for this NFT event in US dollars. + +{% enddocs %} + +{% docs evm_nft_currency_address %} + +The token contract address for this NFT event. This will be the native asset for native transactions. + +{% enddocs %} + +{% docs evm_nft_currency_symbol %} + +The token symbol for this NFT event. + +{% enddocs %} + +{% docs evm_nft_erc1155_value %} + +If the NFT is an ERC-1155 contract, this field may be one or greater, representing the number of tokens. If it is not an ERC-1155 token, this value will be null. + +{% enddocs %} + +{% docs evm_nft_event_index %} + +The event number within a transaction. + +{% enddocs %} + +{% docs evm_nft_event_type %} + +The type of NFT event in this transaction, either sale, bid_won, redeem, or mint. + +{% enddocs %} + +{% docs evm_nft_from_address %} + +The sending address of the NFT in the transaction. + +{% enddocs %} + +{% docs evm_nft_intra_event_index %} + +The order of events within a single event index. This is primarily used for ERC1155 NFT batch transfer events. + +{% enddocs %} + +{% docs evm_nft_metadata %} + +The token metadata for this NFT. This may be blank for many NFTs. We are working to expand this field. + +{% enddocs %} + +{% docs evm_nft_mint_count %} + +The number of NFTs minted in this event. + +{% enddocs %} + +{% docs evm_nft_mint_price %} + +The price paid in the native asset to mint the NFT(s). + +{% enddocs %} + +{% docs evm_nft_mint_price_usd %} + +The price paid in US dollars to mint the NFT(s). + +{% enddocs %} + +{% docs evm_nft_mints_symbol %} + +The symbol of the token supplied to mint the NFT, if applicable. This field may not handle all edge cases. + +{% enddocs %} + +{% docs evm_nft_mints_token_address %} + +The contract address of the token supplied to mint the NFT, if applicable. This field may not handle all edge cases. + +{% enddocs %} + +{% docs evm_nft_mints_token_price %} + +The decimal adjusted amount of tokens supplied within the same transaction to mint the NFT. This field may not handle all edge cases. + +{% enddocs %} + +{% docs evm_nft_mints_token_price_usd %} + +The amount of tokens supplied in US dollars within the same transaction to mint the NFT. This field may not handle all edge cases. + +{% enddocs %} + +{% docs evm_nft_nft_address %} + +The contract address of the NFT. + +{% enddocs %} + +{% docs evm_nft_origin_from %} + +The from address of this transaction. In most cases, this is the NFT buyer. However, for some more complex transactions, it may not be the NFT buyer. + +{% enddocs %} + +{% docs evm_nft_origin_sig %} + +The function signature of this transaction. + +{% enddocs %} + +{% docs evm_nft_origin_to %} + +The to address of this transaction. In most cases, this is the exchange contract. However, for some more complex NFT events, such as aggregate buys with tools, this may not be the exchange address. + +{% enddocs %} + +{% docs evm_nft_platform_address %} + +The address of the exchange used for the transaction. + +{% enddocs %} + +{% docs evm_nft_platform_exchange_version %} + +The version of the exchange contract used for the transaction. + +{% enddocs %} + +{% docs evm_nft_platform_fee %} + +The decimal adjusted amount of fees paid to the platform for this NFT event in the transaction's currency. There are cases where there are fees paid to multiple marketplaces. In those cases, the fee in the platform_fee column will only reflect the platform fee related to the platform exchange contract. + +{% enddocs %} + +{% docs evm_nft_platform_fee_usd %} + +The amount of fees paid to the platform for this NFT event in US dollars. There are cases where there are fees paid to multiple marketplaces. In those cases, the fee in the platform_fee column will only reflect the platform fee related to the platform exchange contract. + +{% enddocs %} + +{% docs evm_nft_platform_name %} + +The name of the exchange used for the trade. + +{% enddocs %} + +{% docs evm_nft_price %} + +The total price of the NFT, in the currency in which the transaction occurred and decimal adjusted where possible. Please note that the price of the NFT, after subtracting total fees, may not represent the net amount paid to the seller in all cases. You may refer to the platform fee description for more info. + +{% enddocs %} + +{% docs evm_nft_price_usd %} + +The total price of the NFT in US dollars. This will be 0 for tokens without a decimal adjustment or hourly price. Please note that the price of the NFT, after subtracting total fees, may not represent the net amount paid to the seller in all cases. You may refer to the platform fee description for more info. + +{% enddocs %} + +{% docs evm_nft_project_name %} + +The name of the NFT project. This field, along with metadata, will be filled in over time. + +{% enddocs %} + +{% docs evm_nft_seller_address %} + +The address of the seller of the NFT in the transaction. + +{% enddocs %} + +{% docs evm_nft_to_address %} + +The receiving address of the NFT in the transaction. + +{% enddocs %} + +{% docs evm_nft_tokenid %} + +The token ID for this NFT contract. + +{% enddocs %} + +{% docs evm_nft_total_fees %} + +The total amount of fees paid relating to the NFT purchase in the transaction currency. This includes royalty payments to creators and platform fees. Please note, this does not include the gas fee. + +{% enddocs %} + +{% docs evm_nft_total_fees_usd %} + +The total amount of fees paid relating to the NFT purchase in US dollars. This includes royalty payments to creators and platform fees. Please note, this does not include the gas fee. + +{% enddocs %} + +{% docs evm_nft_tx_fee %} + +The gas fee for this transaction in the native asset. + +{% enddocs %} + +{% docs evm_nft_tx_fee_usd %} + +The gas fee for this transaction in US dollars. + +{% enddocs %} + +{% docs evm_nft_tx_hash %} + +The transaction hash for the NFT event. This is not necessarily unique in this table as a transaction may contain multiple NFT events. + +{% enddocs %} + +{% docs evm_nft_lending_liquidations_table_doc %} + +This table contains liquidation events for loans backed by collateralized NFTs on this EVM blockchain. This typically means the lender of the loan closes the loan and receives the NFT collateral. + +{% enddocs %} + +{% docs evm_platform_address %} + +The contract address of the platform's lending contract. + +{% enddocs %} + +{% docs evm_platform_name %} + +The name of the platform. + +{% enddocs %} + +{% docs evm_platform_exchange_version %} + +The version of the platform's lending contract. + +{% enddocs %} + +{% docs evm_loanid %} + +The ID associated with the loan, often times tied to the borrower's address and collateral. This ID can be used as a unique identifier when tracking active loans. However, note that refinances can happen while still maintaining the same loanId. For some platforms, loanids of previously paid loans are reused hence they can't be reliably used as a unique identifier without appropriate timestamp filters. Instead, use the unique_loan_id column. + +{% enddocs %} + +{% docs evm_unique_loan_id %} + +The unique ID that can be used to represent a loan within the same platform. For the same loan, the value of this ID will remain the same across the loans taken, liquidations and repayment tables. For some platforms where the lender is issued a promissory note, the lender can send this note to any address, making the receiver the new lender. However, the unique_loan_id still remains the same although the final lender is different. The unique_loan_id changes only if the loanId and lender changes which would also indicate the previous loan has been fully paid off. + +{% enddocs %} + +{% docs evm_lender_address %} + +The address that gives out a loan to the borrower. When a loan is issued, a promissory note (an ERC721) is issued to the lender. The lender can transfer this note to any address which makes any receiving address the new lender. + +{% enddocs %} + +{% docs evm_borrower_address %} + +The address that receives the loan and has an NFT locked as collateral. + +{% enddocs %} + +{% docs evm_nft_address %} + +The address of the NFT used as collateral. + +{% enddocs %} + +{% docs evm_tokenid %} + +The tokenId of the NFT used as collateral. + +{% enddocs %} + +{% docs evm_loan_token_address %} + +The contract address of what the loan is denominated in. This could be either the native asset or other tokens. + +{% enddocs %} + +{% docs evm_loan_token_symbol %} + +The symbol of the loan token address. + +{% enddocs %} + +{% docs evm_principal_unadj %} + +The principal amount of the loan taken with unadjusted decimal places. + +{% enddocs %} + +{% docs evm_principal %} + +The principal amount of the loan taken with adjusted decimal places. + +{% enddocs %} + +{% docs evm_principal_usd %} + +The principal amount of the loan taken in USD terms. + +{% enddocs %} + +{% docs evm_interest_rate %} + +The non-annualized rate charged by the lender on the principal amount of the loan denominated in percentage (%). For fixed term loans, it is calculated by taking the difference between total debt and principal amount divided by principal amount. For perpetual term loans, interest rate is usually on an annual basis and total debt is calculated prorated. + +{% enddocs %} + +{% docs evm_apr %} + +The annualized interest rate denominated in percentage (%). + +{% enddocs %} + +{% docs evm_loan_term_type %} + +The type of loan terms, could be either a fixed loan or a perpetual loan. A fixed term loan has a fixed repayment date while a perpetual loan does not. + +{% enddocs %} + +{% docs evm_loan_start_timestamp %} + +The timestamp of when the loan offer is accepted. + +{% enddocs %} + +{% docs evm_loan_due_timestamp %} + +The timestamp of when the loan is due. For perpetual term loan, the value will be null. + +{% enddocs %} + +{% docs evm_loan_tenure %} + +The tenure of the loan denominated in seconds. For perpetual term loan, the value will be null. + +{% enddocs %} + +{% docs evm_lending_loans %} + +This table contains NFT lending events for loans backed by collateralized NFTs on this EVM blockchain. This could be depositing an NFT and taking out a loan or using the Buy Now Pay Later (BNPL) feature to take a loan out of the newly bought NFT. This NFT will remain locked until the loan is cleared. + +{% enddocs %} + +{% docs evm_nft_lending_event_type %} + +There are 2 types of loan creation events. It can either be a new loan or a refinance of an existing loan. Note that renegotiation events are categorized as refinance events in this table. Old loans are repaid and new loan ids are reissued so these would be new loan entries in this table. + +{% enddocs %} + +{% docs evm_debt_unadj %} + +The total debt of the loan (principal amount plus interests) with unadjusted decimal places. + +{% enddocs %} + +{% docs evm_debt %} + +The total debt of the loan (principal amount plus interests) with adjusted decimal places. + +{% enddocs %} + +{% docs evm_debt_usd %} + +The total debt of the loan (principal amount plus interests) in USD terms. + +{% enddocs %} + +{% docs evm_platform_fee_unadj %} + +The fee charged by the lending platform with unadjusted decimal places. + +{% enddocs %} + +{% docs evm_platform_fee %} + +The fee charged by the lending platform with adjusted decimal places. + +{% enddocs %} + +{% docs evm_platform_fee_usd %} + +The fee charged by the lending platform in USD terms. + +{% enddocs %} + +{% docs evm_mev_arbitrage %} + +This table contains the financial metrics from NFT arbitrage transactions including cost, revenue and profits. + +{% enddocs %} + +{% docs evm_mev_searcher %} + +The address of the MEV finder, taken from the origin address that initiated the transaction. + +{% enddocs %} + +{% docs evm_mev_contract %} + +The contract address that the MEV searcher uses to execute mev transactions, taken from the origin to address of the transaction. + +{% enddocs %} + +{% docs evm_cost_usd %} + +The total cost in USD to purchase the NFT(s) in the transaction. + +{% enddocs %} + +{% docs evm_revenue_usd %} + +The total revenue in USD from selling the NFT(s) and other related tokens in the transaction. + +{% enddocs %} + +{% docs evm_miner_tip_usd %} + +The total amount in USD sent to the block miner/builder as a tip to include the transaction in the block. + +{% enddocs %} + +{% docs evm_profit_usd %} + +The remainder in USD after subtracting cost, miner tip and transaction fee from revenue. + +{% enddocs %} + +{% docs evm_funding_source %} + +The source of the funds used to perform the arbitrage. Currently there are three sources. Existing funds indicate that the user uses funds that are already in their balance while flash loan and flash swaps indicate that the user took a flash loan in the transaction. + +{% enddocs %} + +{% docs evm_arbitrage_direction %} + +The direction in which the arbitrage is performed. There are two possibilities of origin and destination: pool and marketplace. Pool represents marketplaces where users swap from a pool whereas marketplace represents regular marketplaces that are not pool-based. + +{% enddocs %} + +{% docs evm_fact_mev_arbitrage_events %} + +This table contains information about the NFTs involved in arbitrage transactions, documenting events from both the buy and sell sides. + +{% enddocs %} + +{% docs evm_trade_side %} + +The side of the trade that this event represents. This can be either buy or sell. Buy would represent the events where NFTs are bought while sell would present the events where the bought NFTs are sold. Note that the number of events for buy and sell may not be the same for a given transaction. + +{% enddocs %} + +{% docs evm_dim_nft_collection_metadata %} + +This table contains the metadata for popular NFT collections on this EVM blockchain. + +{% enddocs %} + +{% docs evm_nft_blockchain %} + +Blockchain where the NFT metadata is retrieved from. + +{% enddocs %} + +{% docs evm_collection_name %} + +The name for this NFT collection. + +{% enddocs %} + +{% docs evm_tokenid_name %} + +The name for this specific tokenId. This may be the same for all tokenIds within the same collection. + +{% enddocs %} + +{% docs evm_traits %} + +The traits for this tokenId in a key-value pair format. + +{% enddocs %} + +{% docs evm_tokenid_description %} + +The description for this specific tokenId. This may be the same for all tokenIds within the same collection. + +{% enddocs %} + +{% docs evm_tokenid_image_url %} + +The url of the image for this tokenId. + +{% enddocs %} + +{% docs evm_nft_address_tokenid %} + +The concatenation of NFT address and tokenId. + +{% enddocs %} + +{% docs evm_nft_quantity %} + +The number of NFTs transferred in this transaction. If it is an ERC1155, there can be multiple NFTs transferred in a single transaction. If it is an ERC721, this will be 1. + +{% enddocs %} + +{% docs evm_nft_token_standard %} + +The token standard of the NFT. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/traces.md b/models/doc_descriptions/fsc_evm/traces.md new file mode 100644 index 0000000..cebd31a --- /dev/null +++ b/models/doc_descriptions/fsc_evm/traces.md @@ -0,0 +1,125 @@ +{% docs evm_traces_table_doc %} + +This table contains flattened trace data for internal contract calls. User-defined functions (UDFs) are available to decode hex encoded fields, including `utils.udf_hex_to_int()`. + +{% enddocs %} + +{% docs evm_traces_block_no %} + +The block number of this transaction. + +{% enddocs %} + +{% docs evm_traces_blocktime %} + +The block timestamp of this transaction. + +{% enddocs %} + +{% docs evm_traces_call_data %} + +The raw JSON data for this trace. + +{% enddocs %} + +{% docs evm_traces_value %} + +The amount of the native asset transferred in this trace. + +{% enddocs %} + +{% docs evm_traces_from %} + +The sending address of this trace. This is not necessarily the from address of the transaction. + +{% enddocs %} + +{% docs evm_traces_gas %} + +The gas supplied for this trace. + +{% enddocs %} + +{% docs evm_traces_gas_used %} + +The gas used for this trace. + +{% enddocs %} + +{% docs evm_traces_identifier %} + +This field represents the position and type of the trace within the transaction. + +{% enddocs %} + +{% docs evm_trace_index %} + +The index of the trace within the transaction. + +{% enddocs %} + +{% docs evm_traces_input %} + +The input data for this trace. + +{% enddocs %} + +{% docs evm_traces_output %} + +The output data for this trace. + +{% enddocs %} + +{% docs evm_sub_traces %} + +The amount of nested sub traces for this trace. + +{% enddocs %} + +{% docs evm_traces_to %} + +The receiving address of this trace. This is not necessarily the to address of the transaction. + +{% enddocs %} + +{% docs evm_traces_tx_hash %} + +The transaction hash for the trace. Please note, this is not necessarily unique in this table as transactions frequently have multiple traces. + +{% enddocs %} + +{% docs evm_traces_type %} + +The type of internal transaction. Common trace types are `CALL`, `DELEGATECALL`, and `STATICCALL`. + +{% enddocs %} + +{% docs evm_trace_succeeded %} + +The boolean value representing if the trace succeeded. + +{% enddocs %} + +{% docs evm_trace_error_reason %} + +The reason for the trace failure, if any. + +{% enddocs %} + +{% docs evm_revert_reason %} + +The reason for the revert, if available. + +{% enddocs %} + +{% docs evm_trace_address %} + +The trace address for this trace. + +{% enddocs %} + +{% docs evm_trace_type %} + +The type of internal transaction. Common trace types are `CALL`, `DELEGATECALL`, and `STATICCALL`. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/transactions.md b/models/doc_descriptions/fsc_evm/transactions.md new file mode 100644 index 0000000..a5b74ea --- /dev/null +++ b/models/doc_descriptions/fsc_evm/transactions.md @@ -0,0 +1,188 @@ +{% docs evm_tx_table_doc %} + +This table contains transaction level data for this EVM blockchain. Each transaction will have a unique transaction hash, along with transaction fees and a value transferred in the native asset when applicable. Transactions may be native asset transfers or interactions with contract addresses. For more information, please see [The Ethereum Organization - Transactions](https://ethereum.org/en/developers/docs/transactions/) + +Below are the specific native tokens that correspond to each EVM chain: + +| Status | Description | +| --------- | ----------- | +| ETHEREUM | ETH | +| BINANCE | BNB | +| POLYGON | POL | +| AVALANCHE | AVAX | +| ARBITRUM | ETH | +| OPTIMISM | ETH | +| GNOSIS | xDAI | +| KAIA | KLAY | +| SEI | SEI | +| CORE | CORE | + +{% enddocs %} + +{% docs evm_cumulative_gas_used %} + +The total amount of gas used when this transaction was executed in the block. + +{% enddocs %} + +{% docs evm_tx_block_hash %} + +Block hash is a unique 66-character identifier that is generated when a block is produced. + +{% enddocs %} + +{% docs evm_tx_fee %} + +Amount paid to validate the transaction in the native asset. + +{% enddocs %} + +{% docs evm_tx_gas_limit %} + +Maximum amount of gas allocated for the transaction. + +{% enddocs %} + +{% docs evm_tx_gas_price %} + +Cost per unit of gas in Gwei. + +{% enddocs %} + +{% docs evm_tx_gas_used %} + +Gas used by the transaction. + +{% enddocs %} + +{% docs evm_tx_hash %} + +Transaction hash is a unique 66-character identifier that is generated when a transaction is executed. + +{% enddocs %} + +{% docs evm_tx_input_data %} + +This column contains additional data for this transaction, and is commonly used as part of a contract interaction or as a message to the recipient. + +{% enddocs %} + +{% docs evm_tx_json %} + +This JSON column contains the transaction details, including event logs. + +{% enddocs %} + +{% docs evm_tx_nonce %} + +The number of transactions sent from a given address. + +{% enddocs %} + +{% docs evm_tx_origin_sig %} + +The function signature of the call that triggered this transaction. + +{% enddocs %} + +{% docs evm_origin_sig %} + +The function signature of the contract call that triggered this transaction. + +{% enddocs %} + +{% docs evm_tx_position %} + +The position of the transaction within the block. + +{% enddocs %} + +{% docs evm_tx_status %} + +Status of the transaction. + +{% enddocs %} + +{% docs evm_value %} + +The value transacted in the native asset. + +{% enddocs %} + +{% docs evm_effective_gas_price %} + +The total base charge plus tip paid for each unit of gas, in Gwei. + +{% enddocs %} + +{% docs evm_max_fee_per_gas %} + +The maximum fee per gas of the transaction, in Gwei. + +{% enddocs %} + +{% docs evm_max_priority_fee_per_gas %} + +The maximum priority fee per gas of the transaction, in Gwei. + +{% enddocs %} + +{% docs evm_r %} + +The r value of the transaction signature. + +{% enddocs %} + +{% docs evm_s %} + +The s value of the transaction signature. + +{% enddocs %} + +{% docs evm_v %} + +The v value of the transaction signature. + +{% enddocs %} + +{% docs evm_tx_succeeded %} + +Whether the transaction was successful, returned as a boolean. + +{% enddocs %} + +{% docs evm_tx_fee_precise %} + +The precise amount of the transaction fee. This is returned as a string to avoid precision loss. + +{% enddocs %} + +{% docs evm_tx_type %} + +The type of transaction. + +{% enddocs %} + +{% docs evm_mint %} + +The minting event associated with the transaction + +{% enddocs %} + +{% docs evm_source_hash %} + +The hash of the source transaction that created this transaction + +{% enddocs %} + +{% docs evm_eth_value %} + +The eth value for the transaction + +{% enddocs %} + +{% docs evm_chain_id %} + +The unique identifier for the chain the transaction was executed on. + +{% enddocs %} diff --git a/models/doc_descriptions/fsc_evm/transfers.md b/models/doc_descriptions/fsc_evm/transfers.md new file mode 100644 index 0000000..eafaca3 --- /dev/null +++ b/models/doc_descriptions/fsc_evm/transfers.md @@ -0,0 +1,144 @@ +{% docs evm_transfers_table_doc %} + +This table contains all native asset transfers, including equivalent USD amounts. The origin addresses correspond to the to and from addresses from the `fact_transactions` table. The `identifier` and `tx_hash` columns relate this table back to `fact_traces`, which contains more details on the transfers. + +Below are the specific native tokens that correspond to each EVM chain: + +| Status | Description | +| --------- | ----------- | +| ETHEREUM | ETH | +| BINANCE | BNB | +| POLYGON | POL | +| AVALANCHE | AVAX | +| ARBITRUM | ETH | +| OPTIMISM | ETH | +| GNOSIS | xDAI | +| KAIA | KLAY | + +{% enddocs %} + +{% docs evm_transfer_table_doc %} + +This table contains all events in the `fact_token_transfers` table, along with joined columns such as token price, symbol, and decimals where possible that allow for easier analysis of token transfer events. Please note native asset transfers are not included here. + +{% enddocs %} + +{% docs evm_fact_token_transfers_table_doc %} + +This fact-based table contains emitted event logs for ERC-20 Token Transfers (e.g. `Transfer`: topic_0 = `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef`). The contract address is the token transferred, and the raw amount field is the amount of tokens transferred. The values in this table are not decimal adjusted, instead please use `core.dim_contracts` or `core.ez_token_transfers` to reference decimals or decimal adjusted values. This table does not contain ERC-721 and ERC-1155 token transfers, instead please use `nft.ez_nft_transfers`. Additionally, this table does not contain transfers of the chain's native asset, instead please use `core.ez_native_transfers`. + +{% enddocs %} + +{% docs evm_ez_token_transfers_table_doc %} + +This convenience table contains emitted event logs for ERC-20 Token Transfers (e.g. `Transfer`: topic_0 = `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef`), including decimal adjusted values, USD values, and other helpful token metadata where available for each transfer event. The contract address is the token transferred, and the raw amount field is the amount of tokens transferred. Note, this table does not contain ERC-721 and ERC-1155 token transfers, instead please use `nft.ez_nft_transfers`. Additionally, this table does not contain transfers of the chain's native asset, instead please use `core.ez_native_transfers`. + +{% enddocs %} + +{% docs evm_ez_native_transfers_table_doc %} + +This convenience table contains all transfers for the chain's native asset, sourced from internal traces (`core.fact_traces`), and includes decimal adjusted and USD values where available. The origin addresses correspond to the to and from addresses in the `core.fact_transactions` table. Note, this table does not contain ERC-721 and ERC-1155 token transfers, instead please use `nft.ez_nft_transfers`. + +{% enddocs %} + +{% docs evm_amount %} + +Native asset value transferred, this is imported from the fsc-evm package. + +{% enddocs %} + +{% docs evm_amount_usd %} + +Native asset value transferred, in USD. + +{% enddocs %} + +{% docs evm_log_id_transfers %} + +This is the primary key for this table. This is a concatenation of the transaction hash and the event index at which the transfer event occurred. This field can be used to find more details on the event within the `fact_event_logs` table. + +{% enddocs %} + +{% docs evm_origin_from %} + +The from address at the transaction level. + +{% enddocs %} + +{% docs evm_origin_to %} + +The to address at the transaction level. + +{% enddocs %} + +{% docs evm_transfer_amount %} + +The decimal transformed amount for this token. Tokens without a decimal adjustment will be nulled out here. + +{% enddocs %} + +{% docs evm_transfer_amount_precise %} + +The decimal transformed amount for this token returned as a string to preserve precision. Tokens without a decimal adjustment will be nulled out here. + +{% enddocs %} + +{% docs evm_transfer_amount_usd %} + +The amount in US dollars for this transfer at the time of the transfer. Tokens without a decimal adjustment or price will be nulled out here. + +{% enddocs %} + +{% docs evm_transfer_contract_address %} + +Contract address of the token being transferred. + +{% enddocs %} + +{% docs evm_transfer_from_address %} + +The sending address of this transfer. + +{% enddocs %} + +{% docs evm_transfer_has_decimal %} + +Whether or not our contracts model contains the necessary decimal adjustment for this token. + +{% enddocs %} + +{% docs evm_transfer_has_price %} + +Whether or not our prices model contains this hourly token price. + +{% enddocs %} + +{% docs evm_transfer_raw_amount %} + +The amount of tokens transferred. This value is not decimal adjusted. + +{% enddocs %} + +{% docs evm_transfer_raw_amount_precise %} + +The amount of tokens transferred returned as a string to preserve precision. This value is not decimal adjusted. + +{% enddocs %} + +{% docs evm_transfer_to_address %} + +The receiving address of this transfer. This can be a contract address. + +{% enddocs %} + +{% docs evm_transfer_token_price %} + +The price, if available, for this token at the transfer time. + +{% enddocs %} + +{% docs evm_transfer_tx_hash %} + +Transaction hash is a unique 66-character identifier that is generated when a transaction is executed. This will not be unique in this table as a transaction could include multiple transfer events. + +{% enddocs %} diff --git a/models/doc_descriptions/transfers/evm_transfers_table_doc.md b/models/doc_descriptions/transfers/evm_transfers_table_doc.md deleted file mode 100644 index 280f6f8..0000000 --- a/models/doc_descriptions/transfers/evm_transfers_table_doc.md +++ /dev/null @@ -1,17 +0,0 @@ -{% docs evm_fact_token_transfers_table_doc %} - -This fact-based table contains emitted event logs for ERC-20 Token Transfers (e.g. `Transfer`: topic_0 = `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef`). The contract address is the token transferred, and the raw amount field is the amount of tokens transferred. The values in this table are not decimal adjusted, instead please use `core.dim_contracts` or `core.ez_token_transfers` to reference decimals or decimal adjusted values. This table does not contain ERC-721 and ERC-1155 token transfers, instead please use `nft.ez_nft_transfers`. Additionally, this table does not contain transfers of the chain's native asset, instead please use `core.ez_native_transfers`. - -{% enddocs %} - -{% docs evm_ez_token_transfers_table_doc %} - -This convenience table contains emitted event logs for ERC-20 Token Transfers (e.g. `Transfer`: topic_0 = `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef`), including decimal adjusted values, usd values, and other helpful token metadata where available for each transfer event. The contract address is the token transferred, and the raw amount field is the amount of tokens transferred. Note, this table does not contain ERC-721 and ERC-1155 token transfers, instead please use `nft.ez_nft_transfers`. Additionally, this table does not contain transfers of the chain's native asset, instead please use `core.ez_native_transfers`. - -{% enddocs %} - -{% docs evm_ez_native_transfers_table_doc %} - -This convenience table contains all transfers for the chain's native asset, sourced from internal traces (`core.fact_traces`), and includes decimal adjusted and usd values where available. The origin addresses correspond to the to and from addresses in the `core.fact_transactions` table. Note, this table does not contain ERC-721 and ERC-1155 token transfers, instead please use `nft.ez_nft_transfers`. - -{% enddocs %} \ No newline at end of file diff --git a/models/gold/core/core__ez_decoded_event_logs.sql b/models/gold/core/core__ez_decoded_event_logs.sql index 1e1e3f6..07e7d30 100644 --- a/models/gold/core/core__ez_decoded_event_logs.sql +++ b/models/gold/core/core__ez_decoded_event_logs.sql @@ -1,35 +1,67 @@ -{{ config( - materialized = 'view', - persist_docs ={ "relation": true, - "columns": true } +{{ config ( + materialized = "incremental", + unique_key = "ez_decoded_event_logs_id", + incremental_strategy = 'delete+insert', + cluster_by = "block_timestamp::date", + incremental_predicates = [standard_predicate()], + post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(ez_decoded_event_logs_id, contract_name, contract_address)", + tags = ['decoded_logs'] ) }} SELECT block_number, block_timestamp, tx_hash, + {# tx_position, #} -- new column event_index, contract_address, - token_name AS contract_name, - event_name, - decoded_flat AS decoded_log, - decoded_data AS full_decoded_log, - origin_function_signature, - origin_from_address, - origin_to_address, topics, + topics [0] :: STRING AS topic_0, + --new column + topics [1] :: STRING AS topic_1, + --new column + topics [2] :: STRING AS topic_2, + --new column + topics [3] :: STRING AS topic_3, + --new column DATA, event_removed, - tx_status, + origin_from_address, + origin_to_address, + origin_function_signature, + CASE + WHEN tx_status = 'SUCCESS' THEN TRUE + ELSE FALSE + END AS tx_succeeded, + event_name, + decoded_data AS full_decoded_log, + decoded_flat AS decoded_log, + token_name AS contract_name, COALESCE ( decoded_logs_id, {{ dbt_utils.generate_surrogate_key( ['tx_hash', 'event_index'] ) }} ) AS ez_decoded_event_logs_id, - GREATEST(COALESCE(l.inserted_timestamp, '2000-01-01'), COALESCE(C.inserted_timestamp, '2000-01-01')) AS inserted_timestamp, - GREATEST(COALESCE(l.modified_timestamp, '2000-01-01'), COALESCE(C.modified_timestamp, '2000-01-01')) AS modified_timestamp + +{% if is_incremental() %} +SYSDATE() AS inserted_timestamp, +SYSDATE() AS modified_timestamp, +{% else %} + GREATEST(block_timestamp, DATEADD('day', -10, SYSDATE())) AS inserted_timestamp, + GREATEST(block_timestamp, DATEADD('day', -10, SYSDATE())) AS modified_timestamp, +{% endif %} + +tx_status -- deprecate FROM {{ ref('silver__decoded_logs') }} l LEFT JOIN {{ ref('silver__contracts') }} C USING (contract_address) + +{% if is_incremental() %} +AND l.modified_timestamp > ( + SELECT + COALESCE(MAX(modified_timestamp), '2000-01-01' :: TIMESTAMP) + FROM + {{ this }}) + {% endif %} diff --git a/models/gold/core/core__ez_decoded_event_logs.yml b/models/gold/core/core__ez_decoded_event_logs.yml index 7e85733..5fc9fda 100644 --- a/models/gold/core/core__ez_decoded_event_logs.yml +++ b/models/gold/core/core__ez_decoded_event_logs.yml @@ -9,7 +9,7 @@ models: The `full_decoded_logs` column contains the same information, as well as additional fields such as the datatype of the decoded data. You may need to laterally flatten this column to query the data. Sample query for USDC Transfer events: - + ```sql select tx_hash, @@ -23,7 +23,7 @@ models: and block_number between 16400000 and 16405000 and event_name = 'Transfer' limit 50```' - + columns: - name: BLOCK_NUMBER description: '{{ doc("base_block_number") }}' @@ -36,13 +36,13 @@ models: - name: CONTRACT_ADDRESS description: '{{ doc("base_logs_contract_address") }}' - name: CONTRACT_NAME - description: 'The name of the contract, if the contract has a name() function.' + description: "The name of the contract, if the contract has a name() function." - name: EVENT_NAME - description: 'The name of the event, as defined in the contract ABI.' + description: "The name of the event, as defined in the contract ABI." - name: DECODED_LOG - description: 'The flattened decoded log, where the keys are the names of the event parameters, and the values are the values of the event parameters.' + description: "The flattened decoded log, where the keys are the names of the event parameters, and the values are the values of the event parameters." - name: FULL_DECODED_LOG - description: 'The full decoded log, including the event name, the event parameters, and the data type of the event parameters.' + description: "The full decoded log, including the event name, the event parameters, and the data type of the event parameters." - name: ORIGIN_FUNCTION_SIGNATURE description: '{{ doc("base_tx_origin_sig") }}' - name: ORIGIN_FROM_ADDRESS @@ -51,15 +51,25 @@ models: description: '{{ doc("base_origin_to") }}' - name: TOPICS description: '{{ doc("base_topics") }}' + - name: TOPIC_0 + description: '{{ doc("evm_topic_0") }}' + - name: TOPIC_1 + description: '{{ doc("evm_topic_1") }}' + - name: TOPIC_2 + description: '{{ doc("evm_topic_2") }}' + - name: TOPIC_3 + description: '{{ doc("evm_topic_3") }}' - name: DATA description: '{{ doc("base_logs_data") }}' - name: EVENT_REMOVED - description: '{{ doc("base_event_removed") }}' + description: '{{ doc("base_event_removed") }}' - name: TX_STATUS - description: '{{ doc("base_tx_status") }}' + description: '{{ doc("evm_column_deprecation_notice") }}' + - name: TX_SUCCEEDED + description: '{{ doc("base_tx_status") }}' - name: EZ_DECODED_EVENT_LOGS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' \ No newline at end of file + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__ez_native_transfers.sql b/models/gold/core/core__ez_native_transfers.sql index 14d2cac..165eaab 100644 --- a/models/gold/core/core__ez_native_transfers.sql +++ b/models/gold/core/core__ez_native_transfers.sql @@ -10,7 +10,6 @@ SELECT block_timestamp, tx_position, trace_index, - identifier, origin_from_address, origin_to_address, origin_function_signature, @@ -20,19 +19,9 @@ SELECT amount_precise_raw, amount_precise, amount_usd, - COALESCE ( - native_transfers_id, - {{ dbt_utils.generate_surrogate_key( - ['tx_hash', 'trace_index'] - ) }} - ) AS ez_native_transfers_id, - COALESCE( - inserted_timestamp, - '2000-01-01' - ) AS inserted_timestamp, - COALESCE( - modified_timestamp, - '2000-01-01' - ) AS modified_timestamp + native_transfers_id AS ez_native_transfers_id, + inserted_timestamp, + modified_timestamp, + identifier -- deprecate FROM {{ ref('silver__native_transfers') }} diff --git a/models/gold/core/core__ez_native_transfers.yml b/models/gold/core/core__ez_native_transfers.yml index 941f0c2..7fbc593 100644 --- a/models/gold/core/core__ez_native_transfers.yml +++ b/models/gold/core/core__ez_native_transfers.yml @@ -2,7 +2,7 @@ version: 2 models: - name: core__ez_native_transfers description: '{{ doc("evm_ez_native_transfers_table_doc") }}' - + columns: - name: TX_HASH description: '{{ doc("base_transfer_tx_hash") }}' @@ -15,7 +15,7 @@ models: - name: TRACE_INDEX description: '{{ doc("base_trace_index") }}' - name: IDENTIFIER - description: '{{ doc("base_traces_identifier") }}' + description: '{{ doc("evm_column_deprecation_notice_identifier") }}' - name: ORIGIN_FROM_ADDRESS description: '{{ doc("base_origin_from") }}' - name: ORIGIN_TO_ADDRESS @@ -33,10 +33,10 @@ models: - name: AMOUNT_PRECISE description: '{{ doc("precise_amount_adjusted") }}' - name: AMOUNT_USD - description: '{{ doc("base_eth_amount_usd") }}' + description: '{{ doc("base_eth_amount_usd") }}' - name: EZ_NATIVE_TRANSFERS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' \ No newline at end of file + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__ez_token_transfers.sql b/models/gold/core/core__ez_token_transfers.sql index 11def73..5116bf5 100644 --- a/models/gold/core/core__ez_token_transfers.sql +++ b/models/gold/core/core__ez_token_transfers.sql @@ -22,11 +22,6 @@ SELECT amount_usd, decimals, symbol, - token_price, - has_decimal, - has_price, - _log_id, - _inserted_timestamp, COALESCE ( transfers_id, {{ dbt_utils.generate_surrogate_key( @@ -40,6 +35,15 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + token_price, + -- deprecate + has_decimal, + -- deprecate + has_price, + -- deprecate + _log_id, + -- deprecate + _inserted_timestamp -- deprecate FROM {{ ref('silver__transfers') }} diff --git a/models/gold/core/core__ez_token_transfers.yml b/models/gold/core/core__ez_token_transfers.yml index c1b1b90..642a8e9 100644 --- a/models/gold/core/core__ez_token_transfers.yml +++ b/models/gold/core/core__ez_token_transfers.yml @@ -2,10 +2,10 @@ version: 2 models: - name: core__ez_token_transfers description: '{{ doc("evm_ez_token_transfers_table_doc") }}' - + columns: - name: BLOCK_NUMBER - description: '{{ doc("base_block_number") }}' + description: '{{ doc("base_block_number") }}' - name: BLOCK_TIMESTAMP description: '{{ doc("base_block_timestamp") }}' - name: TX_HASH @@ -39,18 +39,18 @@ models: - name: SYMBOL description: '{{ doc("base_symbol") }}' - name: TOKEN_PRICE - description: '{{ doc("base_transfer_token_price") }}' + description: '{{ doc("evm_column_deprecation_notice_token_price") }}' - name: HAS_DECIMAL - description: '{{ doc("base_transfer_has_decimal") }}' + description: '{{ doc("evm_column_deprecation_notice_has_decimal") }}' - name: HAS_PRICE - description: '{{ doc("base_transfer_has_price") }}' + description: '{{ doc("evm_column_deprecation_notice_has_price") }}' - name: _LOG_ID - description: '{{ doc("internal_column") }}' + description: '{{ doc("evm_column_deprecation_notice_log_id") }}' - name: _INSERTED_TIMESTAMP - description: '{{ doc("internal_column") }}' + description: '{{ doc("evm_column_deprecation_notice_inserted_timestamp") }}' - name: EZ_TOKEN_TRANSFERS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__fact_blocks.sql b/models/gold/core/core__fact_blocks.sql index f195e82..18970ca 100644 --- a/models/gold/core/core__fact_blocks.sql +++ b/models/gold/core/core__fact_blocks.sql @@ -5,22 +5,65 @@ ) }} SELECT - A.block_number AS block_number, + A.block_number, + HASH AS block_hash, + --new column block_timestamp, 'mainnet' AS network, - 'base' AS blockchain, tx_count, + SIZE, + miner, + --new + extra_data, + parent_hash, + gas_used, + gas_limit, + base_fee_per_gas, + -- new difficulty, total_difficulty, - extra_data, - gas_limit, - gas_used, - HASH, - parent_hash, - receipts_root, sha3_uncles, - SIZE, uncles AS uncle_blocks, + nonce, + -- new column + receipts_root, + state_root, + -- new column + transactions_root, + -- new column + logs_bloom, + -- new column + withdrawals_root, + COALESCE ( + blocks_id, + {{ dbt_utils.generate_surrogate_key( + ['a.block_number'] + ) }} + ) AS fact_blocks_id, + GREATEST( + COALESCE( + A.inserted_timestamp, + '2000-01-01' + ), + COALESCE( + d.inserted_timestamp, + '2000-01-01' + ) + ) AS inserted_timestamp, + GREATEST( + COALESCE( + A.modified_timestamp, + '2000-01-01' + ), + COALESCE( + d.modified_timestamp, + '2000-01-01' + ) + ) AS modified_timestamp, + 'base' AS blockchain, + -- deprecate + HASH, + --deprecate OBJECT_CONSTRUCT( 'baseFeePerGas', base_fee_per_gas, @@ -60,36 +103,8 @@ SELECT transactions_root, 'uncles', uncles - ) AS block_header_json, - COALESCE ( - blocks_id, - {{ dbt_utils.generate_surrogate_key( - ['a.block_number'] - ) }} - ) AS fact_blocks_id, - GREATEST( - COALESCE( - A.inserted_timestamp, - '2000-01-01' - ), - COALESCE( - d.inserted_timestamp, - '2000-01-01' - ) - ) AS inserted_timestamp, - GREATEST( - COALESCE( - A.modified_timestamp, - '2000-01-01' - ), - COALESCE( - d.modified_timestamp, - '2000-01-01' - ) - ) AS modified_timestamp, - withdrawals_root + ) AS block_header_json -- deprecate FROM {{ ref('silver__blocks') }} A LEFT JOIN {{ ref('silver__tx_count') }} - d - ON A.block_number = d.block_number + d USING (block_number) diff --git a/models/gold/core/core__fact_blocks.yml b/models/gold/core/core__fact_blocks.yml index 1dfa792..4d004db 100644 --- a/models/gold/core/core__fact_blocks.yml +++ b/models/gold/core/core__fact_blocks.yml @@ -1,48 +1,62 @@ version: 2 models: - name: core__fact_blocks - description: '{{ doc("base_blocks_table_doc") }}' + description: '{{ doc("evm_blocks_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("base_block_number") }}' + description: '{{ doc("evm_block_number") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("base_block_timestamp") }}' + description: '{{ doc("evm_block_timestamp") }}' - name: NETWORK - description: '{{ doc("base_network") }}' + description: '{{ doc("evm_network") }}' - name: BLOCKCHAIN - description: '{{ doc("base_blockchain") }}' + description: '{{ doc("evm_column_deprecation_notice_blockchain") }}' + - name: MINER + description: '{{ doc("evm_miner") }}' + - name: NONCE + description: '{{ doc("evm_blocks_nonce") }}' - name: TX_COUNT - description: '{{ doc("base_tx_count") }}' + description: '{{ doc("evm_tx_count") }}' - name: DIFFICULTY - description: '{{ doc("base_difficulty") }}' + description: '{{ doc("evm_difficulty") }}' - name: TOTAL_DIFFICULTY - description: '{{ doc("base_total_difficulty") }}' + description: '{{ doc("evm_total_difficulty") }}' - name: EXTRA_DATA - description: '{{ doc("base_extra_data") }}' + description: '{{ doc("evm_extra_data") }}' - name: GAS_LIMIT - description: '{{ doc("base_gas_limit") }}' + description: '{{ doc("evm_gas_limit") }}' + - name: BASE_FEE_PER_GAS + description: '{{ doc("evm_base_fee_per_gas") }}' - name: GAS_USED - description: '{{ doc("base_gas_used") }}' + description: '{{ doc("evm_gas_used") }}' + - name: BLOCK_HASH + description: '{{ doc("evm_blocks_hash") }}' - name: HASH - description: '{{ doc("base_blocks_hash") }}' + description: '{{ doc("evm_column_deprecation_notice_hash") }}' - name: PARENT_HASH - description: '{{ doc("base_parent_hash") }}' + description: '{{ doc("evm_parent_hash") }}' - name: RECEIPTS_ROOT - description: '{{ doc("base_receipts_root") }}' + description: '{{ doc("evm_receipts_root") }}' - name: SHA3_UNCLES - description: '{{ doc("base_sha3_uncles") }}' + description: '{{ doc("evm_sha3_uncles") }}' - name: SIZE - description: '{{ doc("base_size") }}' + description: '{{ doc("evm_size") }}' - name: UNCLE_BLOCKS - description: '{{ doc("base_uncle_blocks") }}' + description: '{{ doc("evm_uncle_blocks") }}' + - name: STATE_ROOT + description: '{{ doc("evm_state_root") }}' + - name: TRANSACTIONS_ROOT + description: '{{ doc("evm_transactions_root") }}' + - name: LOGS_BLOOM + description: '{{ doc("evm_logs_bloom") }}' - name: BLOCK_HEADER_JSON - description: '{{ doc("base_block_header_json") }}' + description: '{{ doc("evm_column_deprecation_notice_block_header_json") }}' - name: FACT_BLOCKS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP description: '{{ doc("modified_timestamp") }}' - name: WITHDRAWALS_ROOT - description: A hash of the withdrawals that occurred in this block. \ No newline at end of file + description: A hash of the withdrawals that occurred in this block. diff --git a/models/gold/core/core__fact_decoded_event_logs.yml b/models/gold/core/core__fact_decoded_event_logs.yml index 8b61ee6..e25a5d9 100644 --- a/models/gold/core/core__fact_decoded_event_logs.yml +++ b/models/gold/core/core__fact_decoded_event_logs.yml @@ -1,29 +1,8 @@ version: 2 models: - name: core__fact_decoded_event_logs - description: > - 'For information on how to submit a contract for decoding, as well as how ABIs are sourced, please visit [here](https://science.flipsidecrypto.xyz/abi-requestor/). - This model contains decoded event logs for contracts that we have an ABI for. Please note, this table does not include all event logs, only those that we have an ABI for. - This table will perform better than the `core__ez_decoded_event_logs` table, but does not include as many columns. - The `decoded_log` column is the easiest place to query decoded data. It is a JSON object, where the keys are the names of the event parameters, and the values are the values of the event parameters. - You can select from this column using the following sample format, `decoded_log:from::string` or more generally, `decoded_log:::datatype`. See below for a full sample query. - The `full_decoded_logs` column contains the same information, as well as additional fields such as the datatype of the decoded data. You may need to laterally flatten this column to query the data. - - Sample query for USDC Transfer events: - ```sql - select - tx_hash, - block_number, - contract_address, - decoded_log:from::string as from_address, - decoded_log:to::string as to_address, - decoded_log:value::integer as value - from ethereum.core.fact_decoded_event_logs - where contract_address = lower('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48') - and block_number between 16400000 and 16405000 - and event_name = 'Transfer' - limit 50```' - + description: '{{ doc("evm_table_deprecation_notice_fact_decoded_event_logs") }}' + columns: - name: BLOCK_NUMBER description: '{{ doc("base_block_number") }}' @@ -36,14 +15,14 @@ models: - name: CONTRACT_ADDRESS description: '{{ doc("base_logs_contract_address") }}' - name: EVENT_NAME - description: 'The name of the event, as defined in the contract ABI.' + description: "The name of the event, as defined in the contract ABI." - name: DECODED_LOG - description: 'The flattened decoded log, where the keys are the names of the event parameters, and the values are the values of the event parameters.' + description: "The flattened decoded log, where the keys are the names of the event parameters, and the values are the values of the event parameters." - name: FULL_DECODED_LOG - description: 'The full decoded log, including the event name, the event parameters, and the data type of the event parameters.' + description: "The full decoded log, including the event name, the event parameters, and the data type of the event parameters." - name: FACT_DECODED_EVENT_LOGS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__fact_event_logs.sql b/models/gold/core/core__fact_event_logs.sql index e21eda0..d7d6e95 100644 --- a/models/gold/core/core__fact_event_logs.sql +++ b/models/gold/core/core__fact_event_logs.sql @@ -8,16 +8,28 @@ SELECT block_number, block_timestamp, tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, + {# tx_position, -- new column #} event_index, contract_address, topics, + topics [0] :: STRING AS topic_0, + --new column + topics [1] :: STRING AS topic_1, + --new column + topics [2] :: STRING AS topic_2, + --new column + topics [3] :: STRING AS topic_3, + --new column DATA, event_removed, - tx_status, - _log_id, + origin_from_address, + origin_to_address, + origin_function_signature, + CASE + WHEN tx_status = 'SUCCESS' THEN TRUE + ELSE FALSE + END AS tx_succeeded, + -- new column COALESCE ( logs_id, {{ dbt_utils.generate_surrogate_key( @@ -31,6 +43,9 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + tx_status, + -- deprecate + _log_id -- deprecate FROM {{ ref('silver__logs') }} diff --git a/models/gold/core/core__fact_event_logs.yml b/models/gold/core/core__fact_event_logs.yml index 858e88c..45fc35b 100644 --- a/models/gold/core/core__fact_event_logs.yml +++ b/models/gold/core/core__fact_event_logs.yml @@ -1,38 +1,48 @@ version: 2 models: - name: core__fact_event_logs - description: '{{ doc("base_logs_table_doc") }}' + description: '{{ doc("evm_logs_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("base_block_number") }}' + description: '{{ doc("evm_block_number") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("base_block_timestamp") }}' + description: '{{ doc("evm_block_timestamp") }}' - name: TX_HASH - description: '{{ doc("base_logs_tx_hash") }}' + description: '{{ doc("evm_logs_tx_hash") }}' - name: EVENT_INDEX - description: '{{ doc("base_event_index") }}' + description: '{{ doc("evm_event_index") }}' - name: CONTRACT_ADDRESS - description: '{{ doc("base_logs_contract_address") }}' + description: '{{ doc("evm_logs_contract_address") }}' - name: TOPICS - description: '{{ doc("base_topics") }}' + description: '{{ doc("evm_topics") }}' + - name: TOPIC_0 + description: '{{ doc("evm_topic_0") }}' + - name: TOPIC_1 + description: '{{ doc("evm_topic_1") }}' + - name: TOPIC_2 + description: '{{ doc("evm_topic_2") }}' + - name: TOPIC_3 + description: '{{ doc("evm_topic_3") }}' - name: DATA - description: '{{ doc("base_logs_data") }}' + description: '{{ doc("evm_logs_data") }}' - name: EVENT_REMOVED - description: '{{ doc("base_event_removed") }}' + description: '{{ doc("evm_event_removed") }}' - name: _LOG_ID - description: '{{ doc("internal_column") }}' + description: '{{ doc("evm_column_deprecation_notice_log_id") }}' - name: TX_STATUS - description: '{{ doc("base_tx_status") }}' + description: '{{ doc("evm_column_deprecation_notice_tx_status") }}' + - name: TX_SUCCEEDED + description: '{{ doc("evm_tx_succeeded") }}' - name: ORIGIN_FUNCTION_SIGNATURE - description: '{{ doc("base_origin_sig") }}' + description: '{{ doc("evm_origin_sig") }}' - name: ORIGIN_FROM_ADDRESS - description: '{{ doc("base_origin_from") }}' + description: '{{ doc("evm_origin_from") }}' - name: ORIGIN_TO_ADDRESS - description: '{{ doc("base_origin_to") }}' + description: '{{ doc("evm_origin_to") }}' - name: FACT_EVENT_LOGS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__fact_token_transfers.yml b/models/gold/core/core__fact_token_transfers.yml index 7dfa523..e48abda 100644 --- a/models/gold/core/core__fact_token_transfers.yml +++ b/models/gold/core/core__fact_token_transfers.yml @@ -1,11 +1,11 @@ version: 2 models: - name: core__fact_token_transfers - description: '{{ doc("evm_fact_token_transfers_table_doc") }}' - + description: '{{ doc("evm_table_deprecation_notice_fact_token_transfers") }}' + columns: - name: BLOCK_NUMBER - description: '{{ doc("base_block_number") }}' + description: '{{ doc("base_block_number") }}' - name: BLOCK_TIMESTAMP description: '{{ doc("base_block_timestamp") }}' - name: TX_HASH @@ -31,8 +31,8 @@ models: - name: _LOG_ID description: '{{ doc("internal_column") }}' - name: FACT_TOKEN_TRANSFERS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__fact_traces.sql b/models/gold/core/core__fact_traces.sql index 944e4ff..3453549 100644 --- a/models/gold/core/core__fact_traces.sql +++ b/models/gold/core/core__fact_traces.sql @@ -512,9 +512,13 @@ SELECT revert_reason, tx_succeeded, identifier, + -- deprecate DATA, + --deprecate tx_status, + -- deprecate trace_status, + -- deprecate {{ dbt_utils.generate_surrogate_key( ['tx_hash', 'trace_index'] ) }} AS fact_traces_id, diff --git a/models/gold/core/core__fact_traces.yml b/models/gold/core/core__fact_traces.yml index 53d2df9..0e05c85 100644 --- a/models/gold/core/core__fact_traces.yml +++ b/models/gold/core/core__fact_traces.yml @@ -1,69 +1,64 @@ version: 2 models: - name: core__fact_traces - description: '{{ doc("base_traces_table_doc") }}' + description: '{{ doc("evm_traces_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("base_traces_block_no") }}' + description: '{{ doc("evm_traces_block_no") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("base_traces_blocktime") }}' + description: '{{ doc("evm_traces_blocktime") }}' - name: TX_HASH - description: '{{ doc("base_traces_tx_hash") }}' + description: '{{ doc("evm_traces_tx_hash") }}' - name: TX_POSITION - description: The position of the transaction within the block. + description: '{{ doc("evm_tx_position") }}' + - name: FROM_ADDRESS + description: '{{ doc("evm_traces_from") }}' + - name: TO_ADDRESS + description: '{{ doc("evm_traces_to") }}' + - name: VALUE + description: '{{ doc("evm_traces_value") }}' + - name: VALUE_PRECISE_RAW + description: '{{ doc("evm_precise_amount_unadjusted") }}' + - name: VALUE_PRECISE + description: '{{ doc("evm_precise_amount_adjusted") }}' + - name: VALUE_HEX + description: '{{ doc("evm_value_hex") }}' + - name: GAS + description: '{{ doc("evm_traces_gas") }}' + - name: GAS_USED + description: '{{ doc("evm_traces_gas_used") }}' + - name: INPUT + description: '{{ doc("evm_traces_input") }}' + - name: OUTPUT + description: '{{ doc("evm_traces_output") }}' + - name: TYPE + description: '{{ doc("evm_traces_type") }}' + - name: IDENTIFIER + description: '{{ doc("evm_column_deprecation_notice_identifier") }}' + - name: TRACE_ADDRESS + description: '{{ doc("evm_trace_address") }}' + - name: DATA + description: '{{ doc("evm_column_deprecation_notice_data") }}' + - name: TX_STATUS + description: '{{ doc("evm_column_deprecation_notice_tx_status") }}' + - name: TX_SUCCEEDED + description: '{{ doc("evm_tx_succeeded") }}' + - name: TRACE_SUCCEEDED + description: '{{ doc("evm_trace_succeeded") }}' + - name: SUB_TRACES + description: '{{ doc("evm_sub_traces") }}' + - name: TRACE_STATUS + description: '{{ doc("evm_column_deprecation_notice_trace_status") }}' + - name: ERROR_REASON + description: '{{ doc("evm_trace_error_reason") }}' + - name: REVERT_REASON + description: '{{ doc("evm_revert_reason") }}' - name: TRACE_INDEX description: The index of the trace within the transaction. - - name: FROM_ADDRESS - description: '{{ doc("base_traces_from") }}' - - name: TO_ADDRESS - description: '{{ doc("base_traces_to") }}' - - name: INPUT - description: '{{ doc("base_traces_input") }}' - - name: OUTPUT - description: '{{ doc("base_traces_output") }}' - - name: TYPE - description: '{{ doc("base_traces_type") }}' - - name: TRACE_ADDRESS - description: This field represents the position of the trace within the transaction. - - name: SUB_TRACES - description: '{{ doc("base_traces_sub") }}' - - name: IDENTIFIER - description: '{{ doc("base_traces_identifier") }}' - - name: DATA - description: '{{ doc("base_traces_call_data") }}' - - - name: VALUE - description: '{{ doc("base_traces_value") }}' - - name: VALUE_PRECISE_RAW - description: '{{ doc("precise_amount_unadjusted") }}' - - name: VALUE_PRECISE - description: '{{ doc("precise_amount_adjusted") }}' - - name: GAS - description: '{{ doc("base_traces_gas") }}' - - name: GAS_USED - description: '{{ doc("base_traces_gas_used") }}' - - name: ORIGIN_FROM_ADDRESS - description: The from address at the transaction level. - - name: ORIGIN_TO_ADDRESS - description: The to address at the transaction level. - - name: ORIGIN_FUNCTION_SIGNATURE - description: The function signature at the transaction level. - - name: TRACE_STATUS - description: The status of the trace, either `SUCCESS` or `FAIL` - - name: TRACE_SUCCEEDED - description: Whether the trace succeeded or failed - - name: ERROR_REASON - description: The reason for the trace failure, if any. - - name: REVERT_REASON - description: The reason for the trace revert, if any. - - name: TX_STATUS - description: '{{ doc("base_tx_status") }}' - - name: TX_SUCCEEDED - description: Whether the transaction succeeded or failed - name: FACT_TRACES_ID - description: '{{ doc("pk") }}' + description: '{{ doc("evm_pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("evm_inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' + description: '{{ doc("evm_modified_timestamp") }}' diff --git a/models/gold/core/core__fact_transactions.sql b/models/gold/core/core__fact_transactions.sql index 9d371dd..f36799d 100644 --- a/models/gold/core/core__fact_transactions.sql +++ b/models/gold/core/core__fact_transactions.sql @@ -5,42 +5,39 @@ ) }} SELECT - A.block_number AS block_number, + block_number, block_timestamp, - block_hash, tx_hash, - nonce, - POSITION, - origin_function_signature, from_address, to_address, + origin_function_signature, VALUE, value_precise_raw, value_precise, tx_fee, tx_fee_precise, + CASE + WHEN tx_status = 'SUCCESS' THEN TRUE + ELSE FALSE + END AS tx_succeeded, + tx_type, + -- new + nonce, + POSITION AS tx_position, + -- new + input_data, gas_price, - effective_gas_price, - gas AS gas_limit, gas_used, + gas AS gas_limit, + cumulative_gas_used, + effective_gas_price, + max_fee_per_gas, + max_priority_fee_per_gas, l1_gas_price, l1_gas_used, l1_fee_scalar, - l1_fee, l1_fee_precise, - OBJECT_CONSTRUCT( - 'l1_state_batch_index', - state_batch_index, - 'l1_state_batch_root', - state_batch_root, - 'l1_state_root_tx_hash', - state_tx_hash - ) AS l1_submission_details, - cumulative_gas_used, - max_fee_per_gas, - max_priority_fee_per_gas, - input_data, - tx_status AS status, + l1_fee, r, s, v, @@ -52,10 +49,25 @@ SELECT ) AS fact_transactions_id, GREATEST(COALESCE(A.inserted_timestamp, '2000-01-01'), COALESCE(b.inserted_timestamp, '2000-01-01')) AS inserted_timestamp, GREATEST(COALESCE(A.modified_timestamp, '2000-01-01'), COALESCE(b.modified_timestamp, '2000-01-01')) AS modified_timestamp, + block_hash, + --deprecate + tx_status AS status, + --deprecate + POSITION, + --deprecate + OBJECT_CONSTRUCT( + 'l1_state_batch_index', + state_batch_index, + 'l1_state_batch_root', + state_batch_root, + 'l1_state_root_tx_hash', + state_tx_hash + ) AS l1_submission_details, + --deprecate deposit_nonce, - deposit_receipt_version + --deprecate + deposit_receipt_version --deprecate FROM {{ ref('silver__transactions') }} A LEFT JOIN {{ ref('silver__state_hashes') }} - b - ON A.block_number = b.block_number + b USING (block_number) diff --git a/models/gold/core/core__fact_transactions.yml b/models/gold/core/core__fact_transactions.yml index 9ea2059..f9f25b9 100644 --- a/models/gold/core/core__fact_transactions.yml +++ b/models/gold/core/core__fact_transactions.yml @@ -1,80 +1,86 @@ version: 2 models: - name: core__fact_transactions - description: '{{ doc("base_tx_table_doc") }}' + description: '{{ doc("evm_tx_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("base_block_number") }}' + description: '{{ doc("evm_block_number") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("base_block_timestamp") }}' + description: '{{ doc("evm_block_timestamp") }}' - name: BLOCK_HASH - description: '{{ doc("base_tx_block_hash") }}' + description: '{{ doc("evm_column_deprecation_notice_block_hash") }}' - name: TX_HASH - description: '{{ doc("base_tx_hash") }}' + description: '{{ doc("evm_tx_hash") }}' - name: NONCE - description: '{{ doc("base_tx_nonce") }}' + description: '{{ doc("evm_tx_nonce") }}' - name: POSITION - description: '{{ doc("base_tx_position") }}' + description: '{{ doc("evm_column_deprecation_notice_position") }}' + - name: TX_POSITION + description: '{{ doc("evm_tx_position") }}' - name: FROM_ADDRESS - description: '{{ doc("base_from_address") }}' + description: '{{ doc("evm_from_address") }}' - name: TO_ADDRESS - description: '{{ doc("base_to_address") }}' + description: '{{ doc("evm_to_address") }}' - name: VALUE - description: '{{ doc("base_value") }}' + description: '{{ doc("evm_value") }}' - name: VALUE_PRECISE_RAW description: '{{ doc("precise_amount_unadjusted") }}' - name: VALUE_PRECISE description: '{{ doc("precise_amount_adjusted") }}' - name: TX_FEE - description: '{{ doc("base_tx_fee") }}' + description: '{{ doc("evm_tx_fee") }}' - name: TX_FEE_PRECISE description: '{{ doc("tx_fee_precise") }}' - name: GAS_PRICE - description: '{{ doc("base_tx_gas_price") }}' - - name: EFFECTIVE_GAS_PRICE - description: The total base charge plus tip paid for each unit of gas, in Gwei. - - name: GAS_LIMIT - description: '{{ doc("base_tx_gas_limit") }}' + description: '{{ doc("evm_tx_gas_price") }}' - name: GAS_USED - description: '{{ doc("base_tx_gas_used") }}' - - name: L1_GAS_PRICE - description: '{{ doc("base_l1_gas_price") }}' - - name: L1_GAS_USED - description: '{{ doc("base_l1_gas_used") }}' - - name: L1_FEE_SCALAR - description: '{{ doc("base_l1_fee_scalar") }}' - - name: L1_FEE - description: The L1 portion of fees paid. - - name: L1_FEE_PRECISE - description: '{{ doc("tx_fee_precise") }}' - - name: L1_SUBMISSION_DETAILS - description: Variant column that includes details regarding state root, index and tx_hash information for when the block is submitted to Ethereum Mainnet. + description: '{{ doc("evm_tx_gas_used") }}' + - name: GAS_LIMIT + description: '{{ doc("evm_tx_gas_limit") }}' - name: CUMULATIVE_GAS_USED - description: '{{ doc("base_cumulative_gas_used") }}' + description: '{{ doc("evm_cumulative_gas_used") }}' + - name: EFFECTIVE_GAS_PRICE + description: '{{ doc("evm_effective_gas_price") }}' - name: MAX_FEE_PER_GAS description: The maximum fee per gas of the transaction, in Gwei. - name: MAX_PRIORITY_FEE_PER_GAS description: The maximum priority fee per gas of the transaction, in Gwei. + - name: L1_GAS_PRICE + description: '{{ doc("evm_l1_gas_price") }}' + - name: L1_GAS_USED + description: '{{ doc("evm_l1_gas_used") }}' + - name: L1_FEE_SCALAR + description: '{{ doc("evm_l1_fee_scalar") }}' + - name: L1_FEE_PRECISE + description: '{{ doc("evm_tx_fee_precise") }}' + - name: L1_FEE + description: The L1 portion of fees paid. + - name: L1_SUBMISSION_DETAILS + description: '{{ doc("evm_column_deprecation_notice_l1_submission_details") }}' + - name: DEPOSIT_NONCE + description: '{{ doc("evm_column_deprecation_notice_deposit_nonce") }}' + - name: DEPOSIT_RECEIPT_VERSION + description: '{{ doc("evm_column_deprecation_notice_deposit_receipt_version") }}' - name: STATUS - description: '{{ doc("base_tx_status") }}' + description: '{{ doc("evm_column_deprecation_notice_tx_status") }}' + - name: TX_SUCCEEDED + description: '{{ doc("evm_tx_succeeded") }}' - name: INPUT_DATA - description: '{{ doc("base_tx_input_data") }}' - - name: ORIGIN_FUNCTION_SIGNATURE - description: '{{ doc("base_tx_origin_sig") }}' - - name: R + description: '{{ doc("evm_tx_input_data") }}' + - name: ORIGIN_FUNCTION_SIGNATURE + description: '{{ doc("evm_tx_origin_sig") }}' + - name: TX_TYPE + description: The type of the transaction, 2 for EIP-1559 transactions and 0 for legacy transactions. + - name: r description: The r value of the transaction signature. - - name: S + - name: s description: The s value of the transaction signature. - - name: V + - name: v description: The v value of the transaction signature. - name: FACT_TRANSACTIONS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("evm_pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("evm_inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' - - name: DEPOSIT_NONCE - description: The nonce of the deposit transaction. - - name: DEPOSIT_RECEIPT_VERSION - description: The version of the deposit receipt. \ No newline at end of file + description: '{{ doc("evm_modified_timestamp") }}' diff --git a/models/gold/defi/defi__ez_dex_swaps.sql b/models/gold/defi/defi__ez_dex_swaps.sql index e029219..68ed523 100644 --- a/models/gold/defi/defi__ez_dex_swaps.sql +++ b/models/gold/defi/defi__ez_dex_swaps.sql @@ -53,7 +53,6 @@ SELECT token_out, symbol_in, symbol_out, - _log_id, COALESCE ( complete_dex_swaps_id, {{ dbt_utils.generate_surrogate_key( @@ -67,6 +66,7 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + _log_id --deprecate FROM {{ ref('silver_dex__complete_dex_swaps') }} diff --git a/models/gold/defi/defi__ez_dex_swaps.yml b/models/gold/defi/defi__ez_dex_swaps.yml index df077cc..a2ae518 100644 --- a/models/gold/defi/defi__ez_dex_swaps.yml +++ b/models/gold/defi/defi__ez_dex_swaps.yml @@ -39,7 +39,7 @@ models: - name: EVENT_INDEX description: '{{ doc("base_event_index") }}' - name: _LOG_ID - description: '{{ doc("internal_column") }}' + description: '{{ doc("evm_column_deprecation_notice_log_id") }}' - name: ORIGIN_FUNCTION_SIGNATURE description: '{{ doc("base_tx_origin_sig") }}' - name: ORIGIN_FROM_ADDRESS @@ -51,10 +51,8 @@ models: - name: AMOUNT_OUT_UNADJ description: '{{ doc("eth_dex_swaps_amount_out_unadj") }}' - name: EZ_DEX_SWAPS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' - - + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/nft/nft__ez_nft_sales.sql b/models/gold/nft/nft__ez_nft_sales.sql index aa25263..fb5b7e4 100644 --- a/models/gold/nft/nft__ez_nft_sales.sql +++ b/models/gold/nft/nft__ez_nft_sales.sql @@ -17,10 +17,11 @@ SELECT aggregator_name, seller_address, buyer_address, - nft_address, - project_name, - tokenId, - erc1155_value, + nft_address as contract_address, -- new + project_name as name, -- new + tokenId as token_id, -- new + coalesce(erc1155_value, '1')::STRING AS quantity, + case when erc1155_value is null then 'erc721' else 'erc1155' end as token_standard, currency_symbol, currency_address, price, @@ -49,6 +50,11 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + tokenId, --deprecate + erc1155_value, --deprecate + project_name, --deprecate + nft_address --deprecate + FROM {{ ref('silver__complete_nft_sales') }} diff --git a/models/gold/nft/nft__ez_nft_sales.yml b/models/gold/nft/nft__ez_nft_sales.yml index 5a60523..da86f0e 100644 --- a/models/gold/nft/nft__ez_nft_sales.yml +++ b/models/gold/nft/nft__ez_nft_sales.yml @@ -1,57 +1,69 @@ version: 2 models: - name: nft__ez_nft_sales - description: 'This table contains NFT sale events on the Base blockchain which includes Element, Opensea and 0x' - + description: '{{ doc("evm_ez_nft_sales_table_doc") }}' + columns: - name: BLOCK_NUMBER description: '{{ doc("nft_block_no") }}' - name: BLOCK_TIMESTAMP description: '{{ doc("nft_blocktime") }}' - name: TX_HASH - description: '{{ doc("nft_tx_hash") }}' + description: '{{ doc("nft_tx_hash") }}' - name: EVENT_INDEX - description: '{{ doc("nft_event_index") }}' + description: '{{ doc("nft_event_index") }}' - name: EVENT_TYPE - description: '{{ doc("nft_event_type") }}' + description: '{{ doc("nft_event_type") }}' - name: PLATFORM_ADDRESS - description: '{{ doc("nft_platform_address") }}' + description: '{{ doc("nft_platform_address") }}' - name: PLATFORM_NAME - description: '{{ doc("nft_platform_name") }}' + description: '{{ doc("nft_platform_name") }}' - name: PLATFORM_EXCHANGE_VERSION - description: '{{ doc("nft_platform_exchange_version") }}' + description: '{{ doc("nft_platform_exchange_version") }}' - name: AGGREGATOR_NAME description: '{{ doc("nft_aggregator_name") }}' - name: SELLER_ADDRESS - description: '{{ doc("nft_seller_address") }}' + description: '{{ doc("nft_seller_address") }}' - name: BUYER_ADDRESS - description: '{{ doc("nft_buyer_address") }}' + description: '{{ doc("nft_buyer_address") }}' - name: NFT_ADDRESS - description: '{{ doc("nft_nft_address") }}' + description: '{{ doc("evm_column_deprecation_notice_nft_address") }}' + - name: CONTRACT_ADDRESS + description: '{{ doc("nft_nft_address") }}' + - name: PROJECT_NAME + description: '{{ doc("evm_column_deprecation_notice_project_name") }}' + - name: NAME + description: '{{ doc("evm_nft_project_name") }}' - name: TOKENID - description: '{{ doc("nft_tokenid") }}' + description: '{{ doc("evm_column_deprecation_notice_tokenid") }}' + - name: TOKEN_ID + description: '{{ doc("nft_tokenid") }}' - name: ERC1155_VALUE - description: '{{ doc("nft_erc1155_value") }}' + description: '{{ doc("evm_column_deprecation_notice_erc1155_value") }}' + - name: QUANTITY + description: '{{ doc("evm_nft_quantity") }}' + - name: TOKEN_STANDARD + description: '{{ doc("evm_nft_token_standard") }}' - name: CURRENCY_SYMBOL - description: '{{ doc("nft_currency_symbol") }}' + description: '{{ doc("nft_currency_symbol") }}' - name: CURRENCY_ADDRESS - description: '{{ doc("nft_currency_address") }}' + description: '{{ doc("nft_currency_address") }}' - name: PRICE - description: '{{ doc("nft_price") }}' + description: '{{ doc("nft_price") }}' - name: PRICE_USD - description: '{{ doc("nft_price_usd") }}' + description: '{{ doc("nft_price_usd") }}' - name: TOTAL_FEES - description: '{{ doc("nft_total_fees") }}' + description: '{{ doc("nft_total_fees") }}' - name: PLATFORM_FEE - description: '{{ doc("nft_platform_fee") }}' + description: '{{ doc("nft_platform_fee") }}' - name: CREATOR_FEE - description: '{{ doc("nft_creator_fee") }}' + description: '{{ doc("nft_creator_fee") }}' - name: TOTAL_FEES_USD - description: '{{ doc("nft_total_fees_usd") }}' + description: '{{ doc("nft_total_fees_usd") }}' - name: PLATFORM_FEE_USD - description: '{{ doc("nft_platform_fee_usd") }}' + description: '{{ doc("nft_platform_fee_usd") }}' - name: CREATOR_FEE_USD - description: '{{ doc("nft_creator_fee_usd") }}' + description: '{{ doc("nft_creator_fee_usd") }}' - name: ORIGIN_FROM_ADDRESS description: '{{ doc("nft_origin_from") }}' - name: ORIGIN_TO_ADDRESS @@ -59,8 +71,8 @@ models: - name: ORIGIN_FUNCTION_SIGNATURE description: '{{ doc("nft_origin_sig") }}' - name: EZ_NFT_SALES_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/nft/nft__ez_nft_transfers.sql b/models/gold/nft/nft__ez_nft_transfers.sql index 486b18a..0ebea7f 100644 --- a/models/gold/nft/nft__ez_nft_transfers.sql +++ b/models/gold/nft/nft__ez_nft_transfers.sql @@ -9,15 +9,26 @@ SELECT block_timestamp, block_number, tx_hash, + {#tx_position, -- new #} event_index, intra_event_index, - event_type, - contract_address AS nft_address, - project_name, - from_address AS nft_from_address, - to_address AS nft_to_address, - tokenId, - erc1155_value, + token_transfer_type, + iff(from_address = '0x0000000000000000000000000000000000000000', TRUE, FALSE) as is_mint, -- new + from_address, -- new + to_address, -- new + contract_address, -- new + tokenId as token_id, -- new + coalesce(erc1155_value, '1')::STRING AS quantity, + case + when token_transfer_type = 'erc721_Transfer' then 'erc721' + when token_transfer_type = 'erc1155_TransferSingle' then 'erc1155' + when token_transfer_type = 'erc1155_TransferBatch' then 'erc1155' + end as token_standard, + project_name as name, -- new + {#origin_function_signature, -- new + origin_from_address, -- new + origin_to_address -- new + #} COALESCE ( nft_transfers_id, {{ dbt_utils.generate_surrogate_key( @@ -31,6 +42,13 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + event_type, --deprecate + from_address as nft_from_address, --deprecate + to_address as nft_to_address, --deprecate + contract_address as nft_address, --deprecate + tokenId, --deprecate + erc1155_value, --deprecate + project_name --deprecate FROM {{ ref('silver__nft_transfers') }} diff --git a/models/gold/nft/nft__ez_nft_transfers.yml b/models/gold/nft/nft__ez_nft_transfers.yml index dfc0c45..6cb7849 100644 --- a/models/gold/nft/nft__ez_nft_transfers.yml +++ b/models/gold/nft/nft__ez_nft_transfers.yml @@ -1,8 +1,8 @@ version: 2 models: - name: nft__ez_nft_transfers - description: '{{ doc("nft_transfer_doc") }}' - + description: '{{ doc("evm_ez_nft_transfer_table_doc") }}' + columns: - name: BLOCK_NUMBER description: '{{ doc("nft_block_no") }}' @@ -15,22 +15,36 @@ models: - name: INTRA_EVENT_INDEX description: '{{ doc("nft_intra_event_index") }}' - name: EVENT_TYPE - description: '{{ doc("nft_event_type") }}' + description: '{{ doc("evm_column_deprecation_notice_event_type") }}' - name: NFT_ADDRESS + description: '{{ doc("evm_column_deprecation_notice_nft_address") }}' + - name: CONTRACT_ADDRESS description: '{{ doc("nft_nft_address") }}' + - name: NAME + description: '{{ doc("evm_nft_project_name") }}' - name: PROJECT_NAME - description: '{{ doc("nft_project_name") }}' + description: '{{ doc("evm_column_deprecation_notice_project_name") }}' - name: NFT_FROM_ADDRESS + description: '{{ doc("evm_column_deprecation_notice_nft_from_address") }}' + - name: FROM_ADDRESS description: '{{ doc("nft_nft_from_address") }}' - name: NFT_TO_ADDRESS + description: '{{ doc("evm_column_deprecation_notice_nft_to_address") }}' + - name: TO_ADDRESS description: '{{ doc("nft_nft_to_address") }}' - name: TOKENID + description: '{{ doc("evm_column_deprecation_notice_tokenid") }}' + - name: TOKEN_ID description: '{{ doc("nft_tokenid") }}' - name: ERC1155_VALUE - description: '{{ doc("nft_erc1155_value") }}' + description: '{{ doc("evm_column_deprecation_notice_erc1155_value") }}' + - name: QUANTITY + description: '{{ doc("evm_nft_quantity") }}' + - name: TOKEN_STANDARD + description: '{{ doc("evm_nft_token_standard") }}' - name: EZ_NFT_TRANSFERS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' \ No newline at end of file + description: '{{ doc("modified_timestamp") }}' diff --git a/models/silver/abis/silver__proxies.sql b/models/silver/abis/silver__proxies.sql index 3cceeaf..a328b24 100644 --- a/models/silver/abis/silver__proxies.sql +++ b/models/silver/abis/silver__proxies.sql @@ -16,8 +16,8 @@ WITH base AS ( {{ ref('core__fact_traces') }} WHERE TYPE = 'DELEGATECALL' - AND trace_status = 'SUCCESS' - AND tx_status = 'SUCCESS' + AND trace_succeeded + AND tx_succeeded AND from_address != to_address -- exclude self-calls {% if is_incremental() %} diff --git a/models/silver/abis/silver__user_verified_abis.sql b/models/silver/abis/silver__user_verified_abis.sql index fcab5b0..4de20b9 100644 --- a/models/silver/abis/silver__user_verified_abis.sql +++ b/models/silver/abis/silver__user_verified_abis.sql @@ -506,7 +506,7 @@ valid_traces AS ( SELECT base_address FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l JOIN event_mapping ia ON ia.contract_address = l.contract_address diff --git a/models/silver/core/silver__created_contracts.sql b/models/silver/core/silver__created_contracts.sql index bbc1f30..23b956e 100644 --- a/models/silver/core/silver__created_contracts.sql +++ b/models/silver/core/silver__created_contracts.sql @@ -27,8 +27,8 @@ WHERE AND to_address IS NOT NULL AND input IS NOT NULL AND input != '0x' - AND tx_status = 'SUCCESS' - AND trace_status = 'SUCCESS' + AND tx_succeeded + AND trace_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/core/silver__logs.sql b/models/silver/core/silver__logs.sql index 8de38ef..781a667 100644 --- a/models/silver/core/silver__logs.sql +++ b/models/silver/core/silver__logs.sql @@ -16,6 +16,7 @@ WITH base AS ( from_address AS origin_from_address, to_address AS origin_to_address, tx_status, + {#position as tx_position,#} -- new logs, _inserted_timestamp FROM @@ -39,6 +40,7 @@ flat_logs AS ( origin_from_address, origin_to_address, tx_status, + {#position as tx_position,#} -- new VALUE :address :: STRING AS contract_address, VALUE :blockHash :: STRING AS block_hash, VALUE :data :: STRING AS DATA, @@ -64,6 +66,7 @@ new_records AS ( txs.origin_function_signature, l.tx_status, l.contract_address, + {#l.tx_position,#} -- new l.block_hash, l.data, l.event_index, @@ -107,6 +110,7 @@ missing_data AS ( t.origin_to_address, txs.origin_function_signature, t.tx_status, + {#t.tx_position,#} -- new t.contract_address, t.block_hash, t.data, @@ -140,6 +144,7 @@ FINAL AS ( origin_to_address, origin_function_signature, tx_status, + {#tx_position,#} -- new contract_address, block_hash, DATA, @@ -162,6 +167,7 @@ SELECT origin_to_address, origin_function_signature, tx_status, + {#tx_position,#} -- new contract_address, block_hash, DATA, diff --git a/models/silver/core/silver__native_transfers.sql b/models/silver/core/silver__native_transfers.sql index 63c9c79..17672d4 100644 --- a/models/silver/core/silver__native_transfers.sql +++ b/models/silver/core/silver__native_transfers.sql @@ -31,44 +31,21 @@ WITH eth_base AS ( value_precise_raw AS eth_value_precise_raw, value_precise AS eth_value_precise, tx_position, - trace_index + trace_index, + origin_from_address, + origin_to_address, + origin_function_signature FROM {{ ref('core__fact_traces') }} WHERE VALUE > 0 - AND tx_status = 'SUCCESS' - AND trace_status = 'SUCCESS' + AND tx_succeeded + AND trace_succeeded AND TYPE NOT IN ( 'DELEGATECALL', 'STATICCALL' ) -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '72 hours' - FROM - {{ this }} -) -{% endif %} -), -tx_table AS ( - SELECT - block_number, - tx_hash, - from_address AS origin_from_address, - to_address AS origin_to_address, - origin_function_signature - FROM - {{ ref('silver__transactions') }} - WHERE - tx_hash IN ( - SELECT - DISTINCT tx_hash - FROM - eth_base - ) - {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -79,10 +56,10 @@ AND _inserted_timestamp >= ( {% endif %} ) SELECT - tx_hash AS tx_hash, - block_number AS block_number, - block_timestamp AS block_timestamp, - identifier AS identifier, + tx_hash, + block_number, + block_timestamp, + identifier, origin_from_address, origin_to_address, origin_function_signature, @@ -96,7 +73,7 @@ SELECT 2 ) AS amount_usd, _call_id, - _inserted_timestamp, + A._inserted_timestamp, tx_position, trace_index, {{ dbt_utils.generate_surrogate_key( @@ -114,7 +91,3 @@ FROM A.block_timestamp ) = HOUR AND p.token_address = '0x4200000000000000000000000000000000000006' - JOIN tx_table USING ( - tx_hash, - block_number - ) diff --git a/models/silver/core/silver__relevant_contracts.sql b/models/silver/core/silver__relevant_contracts.sql index 23aefb7..14ba6cf 100644 --- a/models/silver/core/silver__relevant_contracts.sql +++ b/models/silver/core/silver__relevant_contracts.sql @@ -10,14 +10,14 @@ WITH emitted_events AS ( SELECT contract_address, COUNT(*) AS event_count, - MAX(_inserted_timestamp) AS max_inserted_timestamp_logs, + MAX(modified_timestamp) AS max_inserted_timestamp_logs, MAX(block_number) AS latest_event_block FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} {% if is_incremental() %} WHERE - _inserted_timestamp > ( + modified_timestamp > ( SELECT MAX(max_inserted_timestamp_logs) FROM @@ -36,8 +36,8 @@ function_calls AS ( FROM {{ ref('core__fact_traces') }} WHERE - tx_status = 'SUCCESS' - AND trace_status = 'SUCCESS' + tx_succeeded + AND trace_succeeded AND to_address IS NOT NULL AND input IS NOT NULL AND input <> '0x' diff --git a/models/silver/core/silver__transfers.sql b/models/silver/core/silver__transfers.sql index dc688df..d98f573 100644 --- a/models/silver/core/silver__transfers.sql +++ b/models/silver/core/silver__transfers.sql @@ -11,7 +11,11 @@ WITH logs AS ( SELECT - _log_id, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, block_number, tx_hash, block_timestamp, @@ -24,12 +28,12 @@ WITH logs AS ( utils.udf_hex_to_int(SUBSTR(DATA, 3, 64)) AS raw_amount_precise, raw_amount_precise :: FLOAT AS raw_amount, event_index, - _inserted_timestamp + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/core/silver__tx_count.sql b/models/silver/core/silver__tx_count.sql index 0635342..02fa05d 100644 --- a/models/silver/core/silver__tx_count.sql +++ b/models/silver/core/silver__tx_count.sql @@ -9,14 +9,14 @@ WITH base AS ( SELECT block_number, - MIN(_inserted_timestamp) AS _inserted_timestamp, + MIN(modified_timestamp) AS _inserted_timestamp, COUNT(*) AS tx_count FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} {% if is_incremental() %} WHERE - _inserted_timestamp >= ( + modified_timestamp >= ( SELECT MAX(_inserted_timestamp) _inserted_timestamp FROM diff --git a/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql b/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql index dbd1c8a..d98e014 100644 --- a/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql +++ b/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql @@ -21,38 +21,46 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, TRY_TO_NUMBER( - decoded_flat :"depositId" :: STRING + decoded_log :"depositId" :: STRING ) AS depositId, - decoded_flat :"depositor" :: STRING AS depositor, + decoded_log :"depositor" :: STRING AS depositor, TRY_TO_NUMBER( - decoded_flat :"destinationChainId" :: STRING + decoded_log :"destinationChainId" :: STRING ) AS destinationChainId, - decoded_flat :"message" :: STRING AS message, + decoded_log :"message" :: STRING AS message, TRY_TO_NUMBER( - decoded_flat :"originChainId" :: STRING + decoded_log :"originChainId" :: STRING ) AS originChainId, - decoded_flat :"originToken" :: STRING AS originToken, + decoded_log :"originToken" :: STRING AS originToken, TRY_TO_TIMESTAMP( - decoded_flat :"quoteTimestamp" :: STRING + decoded_log :"quoteTimestamp" :: STRING ) AS quoteTimestamp, - decoded_flat :"recipient" :: STRING AS recipient, + decoded_log :"recipient" :: STRING AS recipient, TRY_TO_NUMBER( - decoded_flat :"relayerFeePct" :: STRING + decoded_log :"relayerFeePct" :: STRING ) AS relayerFeePct, - decoded_flat, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0xafc4df6845a4ab948b492800d3d8a25d538a102a2bc07cd01f1cfa097fddcff6' AND contract_address = '0x09aea4b2242abc8bb4bb78d537a67a245a7bec64' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -61,7 +69,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT @@ -77,7 +85,7 @@ SELECT event_removed, tx_status, contract_address AS bridge_address, - name AS platform, + NAME AS platform, depositor AS sender, recipient AS receiver, recipient AS destination_chain_receiver, diff --git a/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql b/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql index c0e65d8..d90c20c 100644 --- a/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql +++ b/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql @@ -21,46 +21,54 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"depositId" :: STRING + decoded_log :"depositId" :: STRING ) AS depositId, - decoded_flat :"depositor" :: STRING AS depositor, + decoded_log :"depositor" :: STRING AS depositor, TRY_TO_NUMBER( - decoded_flat :"destinationChainId" :: STRING + decoded_log :"destinationChainId" :: STRING ) AS destinationChainId, - decoded_flat :"message" :: STRING AS message, + decoded_log :"message" :: STRING AS message, TRY_TO_TIMESTAMP( - decoded_flat :"quoteTimestamp" :: STRING + decoded_log :"quoteTimestamp" :: STRING ) AS quoteTimestamp, - decoded_flat :"recipient" :: STRING AS recipient, + decoded_log :"recipient" :: STRING AS recipient, TRY_TO_NUMBER( - decoded_flat :"relayerFeePct" :: STRING + decoded_log :"relayerFeePct" :: STRING ) AS relayerFeePct, - decoded_flat :"exclusiveRelayer" :: STRING AS exclusiveRelayer, + decoded_log :"exclusiveRelayer" :: STRING AS exclusiveRelayer, TRY_TO_NUMBER( - decoded_flat :"exclusivityDeadline" :: STRING + decoded_log :"exclusivityDeadline" :: STRING ) AS exclusivityDeadline, TRY_TO_NUMBER( - decoded_flat :"fillDeadline" :: STRING + decoded_log :"fillDeadline" :: STRING ) AS fillDeadline, TRY_TO_NUMBER( - decoded_flat :"inputAmount" :: STRING + decoded_log :"inputAmount" :: STRING ) AS inputAmount, - decoded_flat :"inputToken" :: STRING AS inputToken, + decoded_log :"inputToken" :: STRING AS inputToken, TRY_TO_NUMBER( - decoded_flat :"outputAmount" :: STRING + decoded_log :"outputAmount" :: STRING ) AS outputAmount, - decoded_flat :"outputToken" :: STRING AS outputToken, - decoded_flat, + decoded_log :"outputToken" :: STRING AS outputToken, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0xa123dc29aebf7d0c3322c8eeb5b999e859f39937950ed31056532713d0de396f' AND contract_address = '0x09aea4b2242abc8bb4bb78d537a67a245a7bec64' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -69,7 +77,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql b/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql index 8ba1fc0..a56b4d7 100644 --- a/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql +++ b/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql @@ -26,10 +26,7 @@ WITH base_evt AS ( origin_from_address AS recipient, TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS nonce, TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) AS messenger, - CASE - WHEN tx_status = 'SUCCESS' THEN TRUE - ELSE FALSE - END AS tx_succeeded, + tx_succeeded, CONCAT( tx_hash, '-', @@ -69,10 +66,7 @@ lp_evt AS ( TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS amount, TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [3] :: STRING)) AS vUsdAmount, TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS fee, - CASE - WHEN tx_status = 'SUCCESS' THEN TRUE - ELSE FALSE - END AS tx_succeeded, + tx_succeeded, CONCAT( tx_hash, '-', diff --git a/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql b/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql index f20e37d..7cfa54c 100644 --- a/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql +++ b/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql @@ -21,28 +21,36 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, - decoded_flat :"destinationChain" :: STRING AS destinationChain, + decoded_log :"destinationChain" :: STRING AS destinationChain, LOWER( - decoded_flat :"destinationContractAddress" :: STRING + decoded_log :"destinationContractAddress" :: STRING ) AS destinationContractAddress, - decoded_flat :"payload" :: STRING AS payload, + decoded_log :"payload" :: STRING AS payload, origin_from_address AS recipient, - decoded_flat :"payloadHash" :: STRING AS payloadHash, - decoded_flat :"sender" :: STRING AS sender, - decoded_flat :"symbol" :: STRING AS symbol, - decoded_flat, + decoded_log :"payloadHash" :: STRING AS payloadHash, + decoded_log :"sender" :: STRING AS sender, + decoded_log :"symbol" :: STRING AS symbol, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0x7e50569d26be643bda7757722291ec66b1be66d8283474ae3fab5a98f878a7a2' AND contract_address = '0xe432150cce91c13a887f7d836923d5597add8e31' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -51,7 +59,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), native_gas_paid AS ( @@ -68,30 +76,38 @@ native_gas_paid AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, - decoded_flat :"destinationChain" :: STRING AS destinationChain, + decoded_log :"destinationChain" :: STRING AS destinationChain, LOWER( - decoded_flat :"destinationAddress" :: STRING + decoded_log :"destinationAddress" :: STRING ) AS destinationAddress, TRY_TO_NUMBER( - decoded_flat :"gasFeeAmount" :: STRING + decoded_log :"gasFeeAmount" :: STRING ) AS gasFeeAmount, - decoded_flat :"payloadHash" :: STRING AS payloadHash, - decoded_flat :"refundAddress" :: STRING AS refundAddress, - decoded_flat :"sourceAddress" :: STRING AS sourceAddress, - decoded_flat :"symbol" :: STRING AS symbol, - decoded_flat, + decoded_log :"payloadHash" :: STRING AS payloadHash, + decoded_log :"refundAddress" :: STRING AS refundAddress, + decoded_log :"sourceAddress" :: STRING AS sourceAddress, + decoded_log :"symbol" :: STRING AS symbol, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0x999d431b58761213cf53af96262b67a069cbd963499fd8effd1e21556217b841' AND contract_address = '0x2d5d7d31f671f86c782533cc367f14109a082712' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -100,7 +116,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), transfers AS ( @@ -109,10 +125,14 @@ transfers AS ( tx_hash, event_index, contract_address AS token_address, - _log_id, - _inserted_timestamp + CONCAT( + event_index :: STRING, + '-', + tx_hash :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__transfers') }} + {{ ref('core__ez_token_transfers') }} WHERE from_address = '0xce16f69375520ab01377ce7b88f5ba8c48f8d666' AND to_address IN ( @@ -127,7 +147,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), FINAL AS ( diff --git a/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql b/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql index 6952006..239ee71 100644 --- a/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql +++ b/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql @@ -21,32 +21,40 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, TRY_TO_NUMBER( - decoded_flat :"dstChainId" :: STRING + decoded_log :"dstChainId" :: STRING ) AS dstChainId, TRY_TO_NUMBER( - decoded_flat :"maxSlippage" :: STRING + decoded_log :"maxSlippage" :: STRING ) AS maxSlippage, TRY_TO_NUMBER( - decoded_flat :"nonce" :: STRING + decoded_log :"nonce" :: STRING ) AS nonce, - decoded_flat :"receiver" :: STRING AS receiver, - decoded_flat :"sender" :: STRING AS sender, - decoded_flat :"token" :: STRING AS token, - decoded_flat :"transferId" :: STRING AS transferId, - decoded_flat, + decoded_log :"receiver" :: STRING AS receiver, + decoded_log :"sender" :: STRING AS sender, + decoded_log :"token" :: STRING AS token, + decoded_log :"transferId" :: STRING AS transferId, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0x89d8051e597ab4178a863a5190407b98abfeff406aa8db90c59af76612e58f01' AND contract_address = '0x7d43aabc515c356145049227cee54b608342c0ad' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -55,7 +63,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql b/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql index caed385..1b8b695 100644 --- a/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql +++ b/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql @@ -23,54 +23,62 @@ WITH base_evt AS ( DATA, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, CONCAT('0x', SUBSTR(segmented_data [24] :: STRING, 1, 40)) AS token_address, - decoded_flat :"affiliateFee" :: STRING AS affiliateFee, - decoded_flat :"metadata" :: STRING AS metadata, + decoded_log :"affiliateFee" :: STRING AS affiliateFee, + decoded_log :"metadata" :: STRING AS metadata, TRY_TO_NUMBER( - decoded_flat :"nativeFixFee" :: STRING + decoded_log :"nativeFixFee" :: STRING ) AS nativeFixFee, - decoded_flat :"order" AS order_obj, - decoded_flat :"order" :"allowedCancelBeneficiarySrc" :: STRING AS allowedCancelBeneficiarySrc, - decoded_flat :"order" :"allowedTakerDst" :: STRING AS allowedTakerDst, - decoded_flat :"order" :"externalCall" :: STRING AS externalCall, + decoded_log :"order" AS order_obj, + decoded_log :"order" :"allowedCancelBeneficiarySrc" :: STRING AS allowedCancelBeneficiarySrc, + decoded_log :"order" :"allowedTakerDst" :: STRING AS allowedTakerDst, + decoded_log :"order" :"externalCall" :: STRING AS externalCall, TRY_TO_NUMBER( - decoded_flat :"order" :"giveAmount" :: STRING + decoded_log :"order" :"giveAmount" :: STRING ) AS giveAmount, TRY_TO_NUMBER( - decoded_flat :"order" :"giveChainId" :: STRING + decoded_log :"order" :"giveChainId" :: STRING ) AS giveChainId, - decoded_flat :"order" :"givePatchAuthoritySrc" :: STRING AS givePatchAuthoritySrc, - decoded_flat :"order" :"giveTokenAddress" :: STRING AS giveTokenAddress, + decoded_log :"order" :"givePatchAuthoritySrc" :: STRING AS givePatchAuthoritySrc, + decoded_log :"order" :"giveTokenAddress" :: STRING AS giveTokenAddress, TRY_TO_NUMBER( - decoded_flat :"order" :"makerOrderNonce" :: STRING + decoded_log :"order" :"makerOrderNonce" :: STRING ) AS makerOrderNonce, - decoded_flat :"order" :"makerSrc" :: STRING AS makerSrc, - decoded_flat :"order" :"orderAuthorityAddressDst" :: STRING AS orderAuthorityAddressDst, + decoded_log :"order" :"makerSrc" :: STRING AS makerSrc, + decoded_log :"order" :"orderAuthorityAddressDst" :: STRING AS orderAuthorityAddressDst, CONCAT('0x', LEFT(segmented_data [28] :: STRING, 40)) AS receiverDst, TRY_TO_NUMBER( - decoded_flat :"order" :"takeAmount" :: STRING + decoded_log :"order" :"takeAmount" :: STRING ) AS takeAmount, TRY_TO_NUMBER( - decoded_flat :"order" :"takeChainId" :: STRING + decoded_log :"order" :"takeChainId" :: STRING ) AS takeChainId, - decoded_flat :"order" :"takeTokenAddress" :: STRING AS takeTokenAddress, - decoded_flat :"orderId" :: STRING AS orderId, + decoded_log :"order" :"takeTokenAddress" :: STRING AS takeTokenAddress, + decoded_log :"orderId" :: STRING AS orderId, TRY_TO_NUMBER( - decoded_flat :"percentFee" :: STRING + decoded_log :"percentFee" :: STRING ) AS percentFee, TRY_TO_NUMBER( - decoded_flat :"referralCode" :: STRING + decoded_log :"referralCode" :: STRING ) AS referralCode, - decoded_flat, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0xfc8703fd57380f9dd234a89dce51333782d49c5902f307b02f03e014d18fe471' --CreatedOrder AND contract_address = '0xef4fb24ad0916217251f553c0596f8edc630eb66' --Dln: Source - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -79,7 +87,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT @@ -112,7 +120,7 @@ SELECT WHEN token_address = '0x0000000000000000000000000000000000000000' THEN '0x4200000000000000000000000000000000000006' ELSE token_address END AS token_address, - decoded_flat, + decoded_log, order_obj, _log_id, _inserted_timestamp diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql b/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql index 5296e42..ba2016c 100644 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql +++ b/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql @@ -11,13 +11,13 @@ WITH base_contracts AS ( contract_address, MAX(block_number) AS block_number FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xe35dddd4ea75d7e9b3fe93af4f4e40e778c3da4074c9d93e7c6536f1e803c1eb' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql b/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql index 30dff17..806ba40 100644 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql +++ b/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql @@ -21,37 +21,45 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, TRY_TO_NUMBER( - decoded_flat :"amountOutMin" :: STRING + decoded_log :"amountOutMin" :: STRING ) AS amountOutMin, TRY_TO_NUMBER( - decoded_flat :"bonderFee" :: STRING + decoded_log :"bonderFee" :: STRING ) AS bonderFee, TRY_TO_NUMBER( - decoded_flat :"chainId" :: STRING + decoded_log :"chainId" :: STRING ) AS chainId, TRY_TO_TIMESTAMP( - decoded_flat :"deadline" :: STRING + decoded_log :"deadline" :: STRING ) AS deadline, TRY_TO_TIMESTAMP( - decoded_flat :"index" :: STRING - ) AS index, - decoded_flat :"recipient" :: STRING AS recipient, - decoded_flat :"transferId" :: STRING AS transferId, - decoded_flat :"transferNonce" :: STRING AS transferNonce, - decoded_flat, + decoded_log :"index" :: STRING + ) AS INDEX, + decoded_log :"recipient" :: STRING AS recipient, + decoded_log :"transferId" :: STRING AS transferId, + decoded_log :"transferNonce" :: STRING AS transferNonce, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0xe35dddd4ea75d7e9b3fe93af4f4e40e778c3da4074c9d93e7c6536f1e803c1eb' AND origin_to_address IS NOT NULL - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -60,7 +68,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), hop_tokens AS ( @@ -86,7 +94,7 @@ SELECT event_removed, tx_status, contract_address AS bridge_address, - amm_wrapper_address, + amm_wrapper_address, NAME AS platform, origin_from_address AS sender, recipient AS receiver, @@ -97,9 +105,9 @@ SELECT amountOutMin AS amount_out_min, bonderFee AS bonder_fee, deadline, - index, + INDEX, transferId AS transfer_id, - transferNonce AS transfer_nonce, + transferNonce AS transfer_nonce, _log_id, _inserted_timestamp FROM diff --git a/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql b/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql index bf99c7e..dd9cc79 100644 --- a/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql +++ b/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql @@ -20,10 +20,14 @@ WITH token_transfers AS ( from_address, to_address, raw_amount, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__transfers') }} + {{ ref('core__ez_token_transfers') }} WHERE from_address <> '0x0000000000000000000000000000000000000000' AND to_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' @@ -40,30 +44,28 @@ AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' ), native_transfers AS ( SELECT - et.block_number, - et.block_timestamp, - et.tx_hash, - tx.from_address AS origin_from_address, - tx.to_address AS origin_to_address, - tx.origin_function_signature, - et.from_address, - et.to_address, + block_number, + block_timestamp, + tx_hash, + origin_from_address, + origin_to_address, + origin_function_signature, + from_address, + to_address, amount_precise_raw, - identifier, - _call_id, - et._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + trace_index :: STRING + ) AS _call_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__native_transfers') }} - et - INNER JOIN {{ ref('silver__transactions') }} - tx - ON et.block_number = tx.block_number - AND et.tx_hash = tx.tx_hash + {{ ref('core__ez_native_transfers') }} WHERE - et.to_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' + to_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' {% if is_incremental() %} -AND et._inserted_timestamp >= ( +AND _inserted_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM @@ -120,14 +122,18 @@ dst_info AS ( tx_hash, topics [1] :: STRING AS encoded_data, SUBSTR(RIGHT(encoded_data, 12), 1, 4) AS destination_chain_id, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' AND topics [0] :: STRING = '0x5ce4019f772fda6cb703b26bce3ec3006eb36b73f1d3a0eb441213317d9f5e9d' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -151,13 +157,13 @@ SELECT bridge_address, sender, receiver, - CASE + CASE WHEN origin_from_address = '0x0000000000000000000000000000000000000000' THEN sender ELSE origin_from_address END AS destination_chain_receiver, amount_unadj, destination_chain_id, - COALESCE(LOWER(chain),'other') AS destination_chain, + COALESCE(LOWER(chain), 'other') AS destination_chain, token_address, _id, t._inserted_timestamp diff --git a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql b/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql index 6db3a7c..1c0cc82 100644 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql +++ b/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql @@ -29,7 +29,7 @@ WITH base_contracts AS ( WHERE from_address = '0xaf5191b0de278c7286d6c7cc6ab6bb8a73ba2cd6' --Factory AND TYPE ILIKE 'create%' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql b/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql index c7fe6e0..b83c5e1 100644 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql +++ b/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql @@ -28,45 +28,53 @@ base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amountSD" :: STRING + decoded_log :"amountSD" :: STRING ) AS amountSD, TRY_TO_NUMBER( - decoded_flat :"chainId" :: STRING + decoded_log :"chainId" :: STRING ) AS chainId, CASE WHEN chainId < 100 THEN chainId + 100 ELSE chainId END AS destination_chain_id, TRY_TO_NUMBER( - decoded_flat :"dstPoolId" :: STRING + decoded_log :"dstPoolId" :: STRING ) AS dstPoolId, TRY_TO_NUMBER( - decoded_flat :"eqFee" :: STRING + decoded_log :"eqFee" :: STRING ) AS eqFee, TRY_TO_NUMBER( - decoded_flat :"eqReward" :: STRING + decoded_log :"eqReward" :: STRING ) AS eqReward, TRY_TO_NUMBER( - decoded_flat :"amountSD" :: STRING + decoded_log :"amountSD" :: STRING ) AS lpFee, TRY_TO_NUMBER( - decoded_flat :"amountSD" :: STRING + decoded_log :"amountSD" :: STRING ) AS protocolFee, - decoded_flat :"from" :: STRING AS from_address, - decoded_flat, + decoded_log :"from" :: STRING AS from_address, + decoded_log, token_address, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} d INNER JOIN pools p ON d.contract_address = p.pool_address WHERE topics [0] :: STRING = '0x34660fc8af304464529f48a778e03d03e4d34bcd5f9b6f0cfbf3cd238c642f7f' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -75,7 +83,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql b/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql index 25f2a8d..db17524 100644 --- a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql +++ b/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql @@ -21,27 +21,35 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, TRY_TO_NUMBER( - decoded_flat :"chainID" :: STRING + decoded_log :"chainID" :: STRING ) AS chainID, - decoded_flat :"from" :: STRING AS from_address, - decoded_flat :"id" :: STRING AS id, - decoded_flat :"revertableAddress" :: STRING AS revertableAddress, - decoded_flat :"to" :: STRING AS to_address, - decoded_flat :"token" :: STRING AS token, - decoded_flat, + decoded_log :"from" :: STRING AS from_address, + decoded_log :"id" :: STRING AS id, + decoded_log :"revertableAddress" :: STRING AS revertableAddress, + decoded_log :"to" :: STRING AS to_address, + decoded_log :"token" :: STRING AS token, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0x31325fe0a1a2e6a5b1e41572156ba5b4e94f0fae7e7f63ec21e9b5ce1e4b3eab' AND contract_address = '0xee981b2459331ad268cc63ce6167b446af4161f8' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -50,7 +58,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql b/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql index 049af3a..2c8118d 100644 --- a/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql +++ b/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql @@ -21,25 +21,33 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, TRY_TO_NUMBER( - decoded_flat :"chainId" :: STRING + decoded_log :"chainId" :: STRING ) AS chainId, - decoded_flat :"to" :: STRING AS to_address, - decoded_flat :"token" :: STRING AS token, - decoded_flat, + decoded_log :"to" :: STRING AS to_address, + decoded_log :"token" :: STRING AS token, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0xdc5bad4651c5fbe9977a696aadc65996c468cde1448dd468ec0d83bf61c4b57c' AND contract_address = '0xf07d1c752fab503e47fef309bf14fbdd3e867089' AND origin_to_address IS NOT NULL - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -48,7 +56,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql b/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql index 8c2a075..cd4b2a7 100644 --- a/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql +++ b/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql @@ -21,36 +21,44 @@ WITH base_evt AS ( topics [0] :: STRING AS topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, TRY_TO_NUMBER( - decoded_flat :"chainId" :: STRING + decoded_log :"chainId" :: STRING ) AS chainId, TRY_TO_TIMESTAMP( - decoded_flat :"deadline" :: STRING + decoded_log :"deadline" :: STRING ) AS deadline, TRY_TO_NUMBER( - decoded_flat :"minDy" :: STRING + decoded_log :"minDy" :: STRING ) AS minDy, - decoded_flat :"to" :: STRING AS to_address, - decoded_flat :"token" :: STRING AS token, + decoded_log :"to" :: STRING AS to_address, + decoded_log :"token" :: STRING AS token, TRY_TO_NUMBER( - decoded_flat :"tokenIndexFrom" :: STRING + decoded_log :"tokenIndexFrom" :: STRING ) AS tokenIndexFrom, TRY_TO_NUMBER( - decoded_flat :"tokenIndexTo" :: STRING + decoded_log :"tokenIndexTo" :: STRING ) AS tokenIndexTo, - decoded_flat, + decoded_log, event_removed, - tx_status, - _log_id, - _inserted_timestamp + IFF( + tx_succeeded, + 'SUCCESS', + 'FAIL' + ) AS tx_status, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0x91f25e9be0134ec851830e0e76dc71e06f9dade75a9b84e9524071dbbc319425' AND contract_address = '0xf07d1c752fab503e47fef309bf14fbdd3e867089' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -59,7 +67,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql b/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql index a3d8a89..1bedc52 100644 --- a/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql +++ b/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql @@ -49,12 +49,16 @@ WITH token_transfers AS ( utils.udf_hex_to_int( segmented_data [5] :: STRING ) AS nonce, - _log_id, - tr._inserted_timestamp + CONCAT( + tr.tx_hash :: STRING, + '-', + tr.event_index :: STRING + ) AS _log_id, + tr.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__transfers') }} + {{ ref('core__ez_token_transfers') }} tr - INNER JOIN {{ ref('silver__transactions') }} + INNER JOIN {{ ref('core__fact_transactions') }} tx ON tr.block_number = tx.block_number AND tr.tx_hash = tx.tx_hash @@ -65,13 +69,13 @@ WITH token_transfers AS ( AND destination_chain_id <> 0 {% if is_incremental() %} -AND tr._inserted_timestamp >= ( +AND tr.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND tr._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND tr.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), native_transfers AS ( @@ -85,7 +89,6 @@ native_transfers AS ( et.from_address, et.to_address, amount_precise_raw, - identifier, regexp_substr_all(SUBSTR(input_data, 11, len(input_data)), '.{64}') AS segmented_data, TRY_TO_NUMBER( utils.udf_hex_to_int( @@ -113,12 +116,16 @@ native_transfers AS ( utils.udf_hex_to_int( segmented_data [3] :: STRING ) AS nonce, - _call_id, - et._inserted_timestamp + CONCAT( + et.tx_hash :: STRING, + '-', + et.trace_index :: STRING + ) AS _call_id, + et.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__native_transfers') }} + {{ ref('core__ez_native_transfers') }} et - INNER JOIN {{ ref('silver__transactions') }} + INNER JOIN {{ ref('core__fact_transactions') }} tx ON et.block_number = tx.block_number AND et.tx_hash = tx.tx_hash @@ -128,13 +135,13 @@ native_transfers AS ( AND destination_chain_id <> 0 {% if is_incremental() %} -AND et._inserted_timestamp >= ( +AND et.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND et._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND et.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), all_transfers AS ( @@ -213,23 +220,61 @@ SELECT token_address, destination_recipient_address, --hex address on the destination chain, requires decoding for non-EVM - more info: https://docs.wormhole.com/wormhole/blockchain-environments/environments - CASE + CASE WHEN destination_chain = 'solana' THEN utils.udf_hex_to_base58(destination_recipient_address) - WHEN destination_chain IN ('injective','sei') - THEN utils.udf_hex_to_bech32(destination_recipient_address,SUBSTR(destination_chain,1,3)) - WHEN destination_chain IN ('osmosis','xpla') - THEN utils.udf_hex_to_bech32(destination_recipient_address,SUBSTR(destination_chain,1,4)) - WHEN destination_chain IN ('terra','terra2','evmos') - THEN utils.udf_hex_to_bech32(destination_recipient_address,SUBSTR(destination_chain,1,5)) - WHEN destination_chain IN ('cosmoshub','kujira') - THEN utils.udf_hex_to_bech32(destination_recipient_address,SUBSTR(destination_chain,1,6)) - WHEN destination_chain IN ('near') - THEN near_address - WHEN destination_chain IN ('algorand') - THEN utils.udf_hex_to_algorand(destination_recipient_address) - WHEN destination_chain IN ('polygon') - THEN SUBSTR(destination_recipient_address,1,42) - ELSE destination_recipient_address + WHEN destination_chain IN ( + 'injective', + 'sei' + ) THEN utils.udf_hex_to_bech32( + destination_recipient_address, + SUBSTR( + destination_chain, + 1, + 3 + ) + ) + WHEN destination_chain IN ( + 'osmosis', + 'xpla' + ) THEN utils.udf_hex_to_bech32( + destination_recipient_address, + SUBSTR( + destination_chain, + 1, + 4 + ) + ) + WHEN destination_chain IN ( + 'terra', + 'terra2', + 'evmos' + ) THEN utils.udf_hex_to_bech32( + destination_recipient_address, + SUBSTR( + destination_chain, + 1, + 5 + ) + ) + WHEN destination_chain IN ( + 'cosmoshub', + 'kujira' + ) THEN utils.udf_hex_to_bech32( + destination_recipient_address, + SUBSTR( + destination_chain, + 1, + 6 + ) + ) + WHEN destination_chain IN ('near') THEN near_address + WHEN destination_chain IN ('algorand') THEN utils.udf_hex_to_algorand(destination_recipient_address) + WHEN destination_chain IN ('polygon') THEN SUBSTR( + destination_recipient_address, + 1, + 42 + ) + ELSE destination_recipient_address END AS destination_chain_receiver, _id, _inserted_timestamp diff --git a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_pools.sql b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_pools.sql index 7125142..1fb5ade 100644 --- a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_pools.sql +++ b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_pools.sql @@ -21,14 +21,18 @@ WITH created_pools AS( segmented_data [1] :: STRING ) :: INTEGER AS pool_number, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x2128d88d14c80cb081c1252a5acff7a264671bf199ce226b53788fb26065005e' AND contract_address = '0x420dd381b31aef6683db6b902084cb0ffece40da' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_pools.sql b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_pools.sql index fa54623..b2710b7 100644 --- a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_pools.sql +++ b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_pools.sql @@ -21,14 +21,18 @@ WITH created_pools AS ( topics [3] :: STRING ) :: INTEGER AS tick_spacing, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0xab0d57f0df537bb25e80245ef7748fa62353808c54d6e528a9dd20887aed9ac2' - AND contract_address = lower('0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A') - AND tx_status = 'SUCCESS' + AND contract_address = LOWER('0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A') + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -50,13 +54,17 @@ initial_info AS ( 1.0001, init_tick ) AS init_price_1_0_unadj, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_swaps.sql b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_swaps.sql index f3ae21c..02e10de 100644 --- a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_swaps.sql +++ b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_slipstream_swaps.sql @@ -34,17 +34,17 @@ WITH base_swaps AS ( segmented_data [4] :: STRING ) :: FLOAT AS tick FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_status = 'SUCCESS' + AND tx_succeeded AND event_removed = 'false' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX( - _inserted_timestamp + _inserted_timestamp ) - INTERVAL '12 hours' FROM {{ this }} @@ -75,8 +75,12 @@ FINAL AS ( event_index, token0_address, token1_address, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, origin_function_signature, origin_from_address, origin_to_address, @@ -92,4 +96,4 @@ SELECT FROM FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id ORDER BY - _inserted_timestamp DESC)) = 1 \ No newline at end of file + _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_swaps.sql b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_swaps.sql index 7122b92..e204226 100644 --- a/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_swaps.sql +++ b/models/silver/defi/dex/aerodrome/silver_dex__aerodrome_swaps.sql @@ -50,15 +50,19 @@ swaps_base AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, token0, token1, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xb3e2773606abfd36b5bd91394b3a54d1398336c65005baf7bf7a05efeffaf75b' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/alienbase/silver_dex__alienbase_pools.sql b/models/silver/defi/dex/alienbase/silver_dex__alienbase_pools.sql index 3879a18..776004c 100644 --- a/models/silver/defi/dex/alienbase/silver_dex__alienbase_pools.sql +++ b/models/silver/defi/dex/alienbase/silver_dex__alienbase_pools.sql @@ -20,14 +20,18 @@ WITH pool_creation AS ( utils.udf_hex_to_int( segmented_data [1] :: STRING ) :: INT AS pool_id, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref ('silver__logs') }} + {{ ref ('core__fact_event_logs') }} WHERE contract_address = LOWER('0x3E84D913803b02A4a7f027165E8cA42C14C0FdE7') AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.sql b/models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.sql index d9da4b5..e7a4ed8 100644 --- a/models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.sql +++ b/models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.sql @@ -50,15 +50,19 @@ swaps_base AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, token0, token1, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql b/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql index 8ae5573..708da5c 100644 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql +++ b/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql @@ -19,18 +19,22 @@ WITH pools_registered AS ( 1, 42 ) AS pool_address, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, ROW_NUMBER() over ( ORDER BY pool_address ) AS row_num FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x3c13bc30b8e878c53fd2a36b679409c073afd75950be43d8858768e956fbc20e' --PoolRegistered AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -39,7 +43,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), tokens_registered AS ( @@ -49,8 +53,8 @@ tokens_registered AS ( event_index, tx_hash, contract_address, - decoded_flat :poolId :: STRING AS pool_id, - decoded_flat :tokens AS tokens, + decoded_log :poolId :: STRING AS pool_id, + decoded_log :tokens AS tokens, tokens [0] :: STRING AS token0, tokens [1] :: STRING AS token1, tokens [2] :: STRING AS token2, @@ -59,11 +63,15 @@ tokens_registered AS ( tokens [5] :: STRING AS token5, tokens [6] :: STRING AS token6, tokens [7] :: STRING AS token7, - decoded_flat :assetManagers AS asset_managers, - _log_id, - _inserted_timestamp + decoded_log :assetManagers AS asset_managers, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE topics [0] :: STRING = '0xf5847d3f2197b16cdcd2098ec95d0905cd1abdaf415f07bb7cef2bba8ac5dec4' --TokensRegistered AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8' @@ -73,7 +81,7 @@ tokens_registered AS ( FROM pools_registered ) - AND tx_status = 'SUCCESS' + AND tx_succeeded ), function_sigs AS ( SELECT diff --git a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql b/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql index 5023350..c894091 100644 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql +++ b/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql @@ -23,7 +23,7 @@ swaps_base AS ( origin_from_address, origin_to_address, contract_address, - _inserted_timestamp, + modified_timestamp AS _inserted_timestamp, 'Swap' AS event_name, event_index, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, @@ -51,25 +51,29 @@ swaps_base AS ( 1, 42 ) AS pool_address, - _log_id, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, 'balancer' AS platform, origin_from_address AS sender, origin_from_address AS tx_to FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b' AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/dex/baseswap/silver_dex__baseswap_pools.sql b/models/silver/defi/dex/baseswap/silver_dex__baseswap_pools.sql index 53422ec..ad0a0d6 100644 --- a/models/silver/defi/dex/baseswap/silver_dex__baseswap_pools.sql +++ b/models/silver/defi/dex/baseswap/silver_dex__baseswap_pools.sql @@ -20,14 +20,18 @@ WITH pool_creation AS ( utils.udf_hex_to_int( segmented_data [1] :: STRING ) :: INT AS pool_id, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref ('silver__logs') }} + {{ ref ('core__fact_event_logs') }} WHERE contract_address = '0xfda619b6d20975be80a10332cd39b9a4b0faa8bb' --factory AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/baseswap/silver_dex__baseswap_swaps.sql b/models/silver/defi/dex/baseswap/silver_dex__baseswap_swaps.sql index a7cc45b..fb4fb26 100644 --- a/models/silver/defi/dex/baseswap/silver_dex__baseswap_swaps.sql +++ b/models/silver/defi/dex/baseswap/silver_dex__baseswap_swaps.sql @@ -50,15 +50,19 @@ swaps_base AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, token0, token1, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/curve/silver_dex__curve_pools.sql b/models/silver/defi/dex/curve/silver_dex__curve_pools.sql index 7df4387..71c9024 100644 --- a/models/silver/defi/dex/curve/silver_dex__curve_pools.sql +++ b/models/silver/defi/dex/curve/silver_dex__curve_pools.sql @@ -40,8 +40,8 @@ WITH contract_deployments AS ( '0x3093f9b57a428f3eb6285a589cb35bea6e78c336', '0x5ef72230578b3e399e6c6f4f6360edf95e83bbfd' ) - AND tx_status = 'SUCCESS' - AND trace_status = 'SUCCESS' + AND tx_succeeded + AND trace_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql b/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql index ba6101a..2d1d956 100644 --- a/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql +++ b/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql @@ -65,10 +65,14 @@ curve_base AS ( segmented_data [3] :: STRING ) ) AS tokens_bought, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN pools p ON p.pool_address = l.contract_address @@ -78,7 +82,7 @@ curve_base AS ( '0xb2e76ae99761dc136e598d4a629bb347eccb9532a5f8bbd72e18467c3c34cc98', '0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b' ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -138,7 +142,7 @@ token_transfers AS ( CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS from_address, CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS to_address FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' AND tx_hash IN ( @@ -150,13 +154,13 @@ token_transfers AS ( AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) <> '0x0000000000000000000000000000000000000000' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), from_transfers AS ( diff --git a/models/silver/defi/dex/dackieswap/silver_dex__dackie_pools.sql b/models/silver/defi/dex/dackieswap/silver_dex__dackie_pools.sql index a930421..5c04cc5 100644 --- a/models/silver/defi/dex/dackieswap/silver_dex__dackie_pools.sql +++ b/models/silver/defi/dex/dackieswap/silver_dex__dackie_pools.sql @@ -25,14 +25,18 @@ WITH created_pools AS ( segmented_data [0] :: STRING ) :: INTEGER AS tick_spacing, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' AND contract_address = '0x3d237ac6d2f425d2e890cc99198818cc1fa48870' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -54,13 +58,17 @@ initial_info AS ( 1.0001, init_tick ) AS init_price_1_0_unadj, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/dackieswap/silver_dex__dackie_swaps.sql b/models/silver/defi/dex/dackieswap/silver_dex__dackie_swaps.sql index e89d986..beef6b6 100644 --- a/models/silver/defi/dex/dackieswap/silver_dex__dackie_swaps.sql +++ b/models/silver/defi/dex/dackieswap/silver_dex__dackie_swaps.sql @@ -34,20 +34,20 @@ WITH base_swaps AS ( segmented_data [4] :: STRING ) :: FLOAT AS tick FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83' - AND tx_status = 'SUCCESS' + AND tx_succeeded AND event_removed = 'false' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), pool_data AS ( @@ -77,8 +77,12 @@ FINAL AS ( event_index, token0_address, token1_address, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, origin_function_signature, origin_from_address, origin_to_address, diff --git a/models/silver/defi/dex/maverick/silver_dex__maverick_pools.sql b/models/silver/defi/dex/maverick/silver_dex__maverick_pools.sql index ed7cc13..b57b210 100644 --- a/models/silver/defi/dex/maverick/silver_dex__maverick_pools.sql +++ b/models/silver/defi/dex/maverick/silver_dex__maverick_pools.sql @@ -43,14 +43,18 @@ WITH pools AS ( ) AS protocolFeeRatio, CONCAT('0x', SUBSTR(segmented_data [6] :: STRING, 25, 40)) AS tokenA, CONCAT('0x', SUBSTR(segmented_data [7] :: STRING, 25, 40)) AS tokenB, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref ('silver__logs') }} + {{ ref ('core__fact_event_logs') }} WHERE contract_address = '0xb2855783a346735e4aae0c1eb894def861fa9b45' AND topics [0] :: STRING = '0x9b3fb3a17b4e94eb4d1217257372dcc712218fcd4bc1c28482bd8a6804a7c775' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/maverick/silver_dex__maverick_swaps.sql b/models/silver/defi/dex/maverick/silver_dex__maverick_swaps.sql index 771fa86..ae4aa8e 100644 --- a/models/silver/defi/dex/maverick/silver_dex__maverick_swaps.sql +++ b/models/silver/defi/dex/maverick/silver_dex__maverick_swaps.sql @@ -76,16 +76,20 @@ swaps_base AS ( ) AS activeTick, tokenA, tokenB, - l._log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN pools ON l.contract_address = pool_address WHERE l.topics [0] :: STRING = '0x3b841dc9ab51e3104bda4f61b41e4271192d22cd19da5ee6e292dc8e2744f713' --Swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql index c51ab16..5269295 100644 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql +++ b/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql @@ -25,14 +25,18 @@ WITH created_pools AS ( segmented_data [0] :: STRING ) :: INTEGER AS tick_spacing, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' AND contract_address = '0xc35dadb65012ec5796536bd9864ed8773abc74c4' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -55,13 +59,17 @@ initial_info AS ( 1.0001, init_tick ) AS init_price_1_0_unadj, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql index 9ed5e60..1b66a3e 100644 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql +++ b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql @@ -34,20 +34,20 @@ WITH base_swaps AS ( segmented_data [4] :: STRING ) :: FLOAT AS tick FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_status = 'SUCCESS' + AND tx_succeeded AND event_removed = 'false' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), pool_data AS ( @@ -77,8 +77,12 @@ FINAL AS ( event_index, token0_address, token1_address, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, origin_function_signature, origin_from_address, origin_to_address, diff --git a/models/silver/defi/dex/swapbased/silver_dex__swapbased_pools.sql b/models/silver/defi/dex/swapbased/silver_dex__swapbased_pools.sql index aa1fa52..3eba048 100644 --- a/models/silver/defi/dex/swapbased/silver_dex__swapbased_pools.sql +++ b/models/silver/defi/dex/swapbased/silver_dex__swapbased_pools.sql @@ -20,14 +20,18 @@ WITH pool_creation AS ( utils.udf_hex_to_int( segmented_data [1] :: STRING ) :: INT AS pool_id, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref ('silver__logs') }} + {{ ref ('core__fact_event_logs') }} WHERE contract_address = '0x04c9f118d21e8b767d2e50c946f0cc9f6c367300' --factory AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/swapbased/silver_dex__swapbased_swaps.sql b/models/silver/defi/dex/swapbased/silver_dex__swapbased_swaps.sql index f08efdf..3f612fb 100644 --- a/models/silver/defi/dex/swapbased/silver_dex__swapbased_swaps.sql +++ b/models/silver/defi/dex/swapbased/silver_dex__swapbased_swaps.sql @@ -50,15 +50,19 @@ swaps_base AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, token0, token1, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql b/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql index e242bd2..66fd915 100644 --- a/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql +++ b/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql @@ -20,14 +20,18 @@ WITH pool_creation AS ( utils.udf_hex_to_int( segmented_data [1] :: STRING ) :: INT AS pool_id, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref ('silver__logs') }} + {{ ref ('core__fact_event_logs') }} WHERE contract_address = LOWER('0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6') AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql b/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql index c2cc44c..4846c43 100644 --- a/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql +++ b/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql @@ -50,15 +50,19 @@ swaps_base AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, token0, token1, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql b/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql index f9fca55..34dc477 100644 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql +++ b/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql @@ -25,14 +25,18 @@ WITH created_pools AS ( segmented_data [0] :: STRING ) :: INTEGER AS tick_spacing, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' AND contract_address = '0x33128a8fc17869897dce68ed026d694621f6fdfd' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -54,13 +58,17 @@ initial_info AS ( 1.0001, init_tick ) AS init_price_1_0_unadj, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql b/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql index 58b729b..cf03f9f 100644 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql +++ b/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql @@ -34,21 +34,21 @@ WITH base_swaps AS ( segmented_data [4] :: STRING ) :: FLOAT AS tick FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE > '2021-04-01' AND topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_status = 'SUCCESS' + AND tx_succeeded AND event_removed = 'false' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), pool_data AS ( @@ -78,8 +78,12 @@ FINAL AS ( event_index, token0_address, token1_address, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, origin_function_signature, origin_from_address, origin_to_address, diff --git a/models/silver/defi/dex/voodoo/silver_dex__voodoo_swaps.sql b/models/silver/defi/dex/voodoo/silver_dex__voodoo_swaps.sql index 545b050..79a6798 100644 --- a/models/silver/defi/dex/voodoo/silver_dex__voodoo_swaps.sql +++ b/models/silver/defi/dex/voodoo/silver_dex__voodoo_swaps.sql @@ -62,14 +62,18 @@ WITH swaps_base AS ( segmented_data [6] :: STRING ) ) AS feeBasisPoints, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address = '0x4f188afdc40e6d2ddddf5fd1b2df7aef7da52f50' --Vault AND topics [0] :: STRING = '0x0874b2d545cb271cdbda4e093020c452328b24af12382ed62c4d00f5c26709db' --Swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql b/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql index a231d21..ead7f5f 100644 --- a/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql +++ b/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql @@ -52,10 +52,14 @@ WITH router_swaps_base AS ( 40 ) ) AS rebateTo, - l._log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l WHERE contract_address IN ( @@ -67,7 +71,7 @@ WITH router_swaps_base AS ( '0x27425e9fb6a9a625e8484cfd9620851d1fa322e5' ) --v3 AND topics [0] :: STRING = '0x27c98e911efdd224f4002f6cd831c3ad0d2759ee176f9ee8466d95826af22a1c' --WooRouterSwap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -119,10 +123,14 @@ swaps_base AS ( 40 ) ) AS rebateTo, - l._log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l WHERE contract_address IN ( @@ -145,7 +153,7 @@ swaps_base AS ( FROM router_swaps_base ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/aave/silver__aave_borrows.sql b/models/silver/defi/lending/aave/silver__aave_borrows.sql index ea5b635..efb7c3c 100644 --- a/models/silver/defi/lending/aave/silver__aave_borrows.sql +++ b/models/silver/defi/lending/aave/silver__aave_borrows.sql @@ -43,10 +43,14 @@ borrow AS ( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' @@ -60,7 +64,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/aave/silver__aave_deposits.sql b/models/silver/defi/lending/aave/silver__aave_deposits.sql index 3884dcd..8943d0a 100644 --- a/models/silver/defi/lending/aave/silver__aave_deposits.sql +++ b/models/silver/defi/lending/aave/silver__aave_deposits.sql @@ -36,10 +36,14 @@ WITH deposits AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61' @@ -53,7 +57,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/aave/silver__aave_flashloans.sql b/models/silver/defi/lending/aave/silver__aave_flashloans.sql index af8de2d..bf67e34 100644 --- a/models/silver/defi/lending/aave/silver__aave_flashloans.sql +++ b/models/silver/defi/lending/aave/silver__aave_flashloans.sql @@ -38,10 +38,14 @@ WITH flashloan AS ( WHEN contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') THEN 'Aave V3' ELSE 'ERROR' END AS aave_version, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' @@ -55,7 +59,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/aave/silver__aave_liquidations.sql b/models/silver/defi/lending/aave/silver__aave_liquidations.sql index 939f49c..929427f 100644 --- a/models/silver/defi/lending/aave/silver__aave_liquidations.sql +++ b/models/silver/defi/lending/aave/silver__aave_liquidations.sql @@ -36,10 +36,14 @@ WITH liquidation AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286' @@ -53,7 +57,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/aave/silver__aave_repayments.sql b/models/silver/defi/lending/aave/silver__aave_repayments.sql index 28cada0..b2bbd7b 100644 --- a/models/silver/defi/lending/aave/silver__aave_repayments.sql +++ b/models/silver/defi/lending/aave/silver__aave_repayments.sql @@ -33,10 +33,14 @@ WITH repay AS( contract_address ) AS lending_pool_contract, origin_from_address AS repayer_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xa534c8dbe71f871f9f3530e97a74601fea17b426cae02e1c5aee42c96c784051' @@ -50,7 +54,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/aave/silver__aave_tokens.sql b/models/silver/defi/lending/aave/silver__aave_tokens.sql index 691b8cb..e95f782 100644 --- a/models/silver/defi/lending/aave/silver__aave_tokens.sql +++ b/models/silver/defi/lending/aave/silver__aave_tokens.sql @@ -24,11 +24,14 @@ WITH DECODE AS ( utils.udf_hex_to_string ( segmented_data [9] :: STRING ) :: STRING AS atoken_symbol, - l._inserted_timestamp, - l._log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} - l + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0xb19e051f8af41150ccccb3fc2c2d8d15f4a4cf434f32a559ba75fe73d6eea20b' @@ -76,10 +79,14 @@ debt_tokens AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS atoken_address, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40)) :: STRING AS atoken_stable_debt_address, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 27, 40)) :: STRING AS atoken_variable_debt_address, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f' AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) IN ( @@ -107,7 +114,7 @@ a_token_step_2 AS ( ) SELECT A.atoken_created_block, - a.aave_version_pool, + A.aave_version_pool, A.atoken_symbol AS atoken_symbol, A.a_token_address AS atoken_address, b.atoken_stable_debt_address, @@ -128,4 +135,4 @@ FROM INNER JOIN {{ ref('silver__contracts') }} C ON contract_address = A.underlying_asset qualify(ROW_NUMBER() over(PARTITION BY atoken_address ORDER BY - a.atoken_created_block DESC)) = 1 + A.atoken_created_block DESC)) = 1 diff --git a/models/silver/defi/lending/aave/silver__aave_withdraws.sql b/models/silver/defi/lending/aave/silver__aave_withdraws.sql index 61e6a9d..dff28e3 100644 --- a/models/silver/defi/lending/aave/silver__aave_withdraws.sql +++ b/models/silver/defi/lending/aave/silver__aave_withdraws.sql @@ -32,10 +32,14 @@ WITH withdraw AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7' @@ -49,7 +53,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0xa238dd80c259a72e81d7e4664a9801593f98d1c5') -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/compound/silver__comp_borrows.sql b/models/silver/defi/lending/compound/silver__comp_borrows.sql index 9bd9100..f6277cb 100644 --- a/models/silver/defi/lending/compound/silver__comp_borrows.sql +++ b/models/silver/defi/lending/compound/silver__comp_borrows.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -comp_assets as ( +WITH comp_assets AS ( + SELECT compound_market_address, compound_market_name, @@ -21,7 +21,6 @@ comp_assets as ( {{ ref('silver__comp_asset_details') }} ), borrow AS ( - SELECT tx_hash, block_number, @@ -46,26 +45,35 @@ borrow AS ( C.underlying_asset_address, C.underlying_asset_symbol, 'base' AS blockchain, - _log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN comp_assets C ON asset = C.compound_market_address WHERE topics [0] = '0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb' --withdrawl - AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets) - AND tx_status = 'SUCCESS' + AND l.contract_address IN ( + SELECT + DISTINCT(compound_market_address) + FROM + comp_assets + ) + AND tx_succeeded {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/lending/compound/silver__comp_deposits.sql b/models/silver/defi/lending/compound/silver__comp_deposits.sql index 9de8618..25f0a72 100644 --- a/models/silver/defi/lending/compound/silver__comp_deposits.sql +++ b/models/silver/defi/lending/compound/silver__comp_deposits.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -comp_assets as ( +WITH comp_assets AS ( + SELECT compound_market_address, compound_market_name, @@ -20,9 +20,7 @@ comp_assets as ( FROM {{ ref('silver__comp_asset_details') }} ), - supply AS ( - SELECT tx_hash, block_number, @@ -45,25 +43,35 @@ supply AS ( C.token_symbol, C.token_decimals, 'base' AS blockchain, - _log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + l.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN {{ ref('silver__contracts') }} C ON asset = C.contract_address WHERE topics [0] = '0xfa56f7b24f17183d81894d3ac2ee654e3c26388d17a28dbd9549b8114304e1f4' --SupplyCollateral - AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets) - AND tx_status = 'SUCCESS' + AND l.contract_address IN ( + SELECT + DISTINCT(compound_market_address) + FROM + comp_assets + ) + AND tx_succeeded + {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/lending/compound/silver__comp_liquidations.sql b/models/silver/defi/lending/compound/silver__comp_liquidations.sql index 0f5926d..2bbbc1b 100644 --- a/models/silver/defi/lending/compound/silver__comp_liquidations.sql +++ b/models/silver/defi/lending/compound/silver__comp_liquidations.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -comp_assets as ( +WITH comp_assets AS ( + SELECT compound_market_address, compound_market_name, @@ -20,9 +20,7 @@ comp_assets as ( FROM {{ ref('silver__comp_asset_details') }} ), - liquidations AS ( - SELECT tx_hash, block_number, @@ -49,25 +47,35 @@ liquidations AS ( C.token_symbol, C.token_decimals, 'base' AS blockchain, - _log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + l.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN {{ ref('silver__contracts') }} C ON asset = C.contract_address WHERE topics [0] = '0x9850ab1af75177e4a9201c65a2cf7976d5d28e40ef63494b44366f86b2f9412e' --AbsorbCollateral - AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets) - AND tx_status = 'SUCCESS' + AND l.contract_address IN ( + SELECT + DISTINCT(compound_market_address) + FROM + comp_assets + ) + AND tx_succeeded + {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/lending/compound/silver__comp_repayments.sql b/models/silver/defi/lending/compound/silver__comp_repayments.sql index 8fa693c..6d1269d 100644 --- a/models/silver/defi/lending/compound/silver__comp_repayments.sql +++ b/models/silver/defi/lending/compound/silver__comp_repayments.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -comp_assets as ( +WITH comp_assets AS ( + SELECT compound_market_address, compound_market_name, @@ -21,7 +21,6 @@ comp_assets as ( {{ ref('silver__comp_asset_details') }} ), repayments AS ( - SELECT tx_hash, block_number, @@ -49,26 +48,35 @@ repayments AS ( C.underlying_asset_address AS underlying_asset, C.underlying_asset_symbol, 'base' AS blockchain, - _log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + l.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN comp_assets C ON contract_address = C.compound_market_address WHERE topics [0] = '0xd1cf3d156d5f8f0d50f6c122ed609cec09d35c9b9fb3fff6ea0959134dae424e' --Supply - AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets) - AND tx_status = 'SUCCESS' + AND l.contract_address IN ( + SELECT + DISTINCT(compound_market_address) + FROM + comp_assets + ) + AND tx_succeeded {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/lending/compound/silver__comp_withdraws.sql b/models/silver/defi/lending/compound/silver__comp_withdraws.sql index d64bb83..89f5392 100644 --- a/models/silver/defi/lending/compound/silver__comp_withdraws.sql +++ b/models/silver/defi/lending/compound/silver__comp_withdraws.sql @@ -6,9 +6,8 @@ tags = ['reorg','curated'] ) }} +WITH comp_assets AS ( -WITH -comp_assets as ( SELECT compound_market_address, compound_market_name, @@ -22,7 +21,6 @@ comp_assets as ( {{ ref('silver__comp_asset_details') }} ), withdraw AS ( - SELECT tx_hash, block_number, @@ -44,26 +42,35 @@ withdraw AS ( C.token_symbol, C.token_decimals, 'base' AS blockchain, - _log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + l.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN {{ ref('silver__contracts') }} C ON token_address = C.contract_address WHERE topics [0] = '0xd6d480d5b3068db003533b170d67561494d72e3bf9fa40a266471351ebba9e16' --WithdrawCollateral - AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets) - AND tx_status = 'SUCCESS' + AND l.contract_address IN ( + SELECT + DISTINCT(compound_market_address) + FROM + comp_assets + ) + AND tx_succeeded {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT diff --git a/models/silver/defi/lending/granary/silver__granary_borrows.sql b/models/silver/defi/lending/granary/silver__granary_borrows.sql index 35afb55..5bcb96f 100644 --- a/models/silver/defi/lending/granary/silver__granary_borrows.sql +++ b/models/silver/defi/lending/granary/silver__granary_borrows.sql @@ -8,6 +8,7 @@ WITH --borrows from granary LendingPool contracts atoken_meta AS ( + SELECT atoken_address, granary_version_pool, @@ -26,7 +27,6 @@ atoken_meta AS ( {{ ref('silver__granary_tokens') }} ), borrow AS ( - SELECT tx_hash, block_number, @@ -58,10 +58,14 @@ borrow AS ( contract_address ) AS lending_pool_contract, 'Granary' AS granary_version, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' @@ -74,8 +78,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT granary_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + granary_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/granary/silver__granary_deposits.sql b/models/silver/defi/lending/granary/silver__granary_deposits.sql index cb9b115..0e21baf 100644 --- a/models/silver/defi/lending/granary/silver__granary_deposits.sql +++ b/models/silver/defi/lending/granary/silver__granary_deposits.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, granary_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__granary_tokens') }} ), deposits AS( - SELECT tx_hash, block_number, @@ -52,10 +51,14 @@ deposits AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951' @@ -68,10 +71,14 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT granary_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + granary_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) - SELECT tx_hash, block_number, diff --git a/models/silver/defi/lending/granary/silver__granary_flashloans.sql b/models/silver/defi/lending/granary/silver__granary_flashloans.sql index d66b29f..ea53e68 100644 --- a/models/silver/defi/lending/granary/silver__granary_flashloans.sql +++ b/models/silver/defi/lending/granary/silver__granary_flashloans.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, granary_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__granary_tokens') }} ), flashloan AS ( - SELECT tx_hash, block_number, @@ -54,10 +53,14 @@ flashloan AS ( contract_address ) AS lending_pool_contract, 'Granary' AS granary_version, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac' @@ -70,8 +73,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT granary_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + granary_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/granary/silver__granary_liquidations.sql b/models/silver/defi/lending/granary/silver__granary_liquidations.sql index 49da8fc..c71c59b 100644 --- a/models/silver/defi/lending/granary/silver__granary_liquidations.sql +++ b/models/silver/defi/lending/granary/silver__granary_liquidations.sql @@ -6,9 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH +WITH atoken_meta AS ( -atoken_meta AS ( SELECT atoken_address, granary_version_pool, @@ -27,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__granary_tokens') }} ), liquidation AS( - SELECT tx_hash, block_number, @@ -53,10 +51,14 @@ liquidation AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286' @@ -69,8 +71,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT granary_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + granary_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/granary/silver__granary_repayments.sql b/models/silver/defi/lending/granary/silver__granary_repayments.sql index 76261f1..0156022 100644 --- a/models/silver/defi/lending/granary/silver__granary_repayments.sql +++ b/models/silver/defi/lending/granary/silver__granary_repayments.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, granary_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__granary_tokens') }} ), repay AS( - SELECT tx_hash, block_number, @@ -49,10 +48,14 @@ repay AS( contract_address ) AS lending_pool_contract, origin_from_address AS repayer_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa' @@ -65,8 +68,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT granary_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + granary_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/granary/silver__granary_tokens.sql b/models/silver/defi/lending/granary/silver__granary_tokens.sql index 4771429..e0c3de1 100644 --- a/models/silver/defi/lending/granary/silver__granary_tokens.sql +++ b/models/silver/defi/lending/granary/silver__granary_tokens.sql @@ -24,10 +24,14 @@ WITH DECODE AS ( utils.udf_hex_to_string ( segmented_data [9] :: STRING ) :: STRING AS atoken_symbol, - l._inserted_timestamp, - l._log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l WHERE topics [0] = '0xb19e051f8af41150ccccb3fc2c2d8d15f4a4cf434f32a559ba75fe73d6eea20b' @@ -48,7 +52,6 @@ AND contract_address NOT IN ( {{ this }} ) AND block_timestamp >= SYSDATE() - INTERVAL '7 days' - {% endif %} ), a_token_step_1 AS ( @@ -66,7 +69,8 @@ a_token_step_1 AS ( FROM DECODE WHERE - atoken_name LIKE '%Granary%' OR atoken_name LIKE '%Grain%' + atoken_name LIKE '%Granary%' + OR atoken_name LIKE '%Grain%' ), debt_tokens AS ( SELECT @@ -77,10 +81,14 @@ debt_tokens AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS atoken_address, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40)) :: STRING AS atoken_stable_debt_address, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 27, 40)) :: STRING AS atoken_variable_debt_address, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f' AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) IN ( @@ -129,4 +137,4 @@ FROM INNER JOIN {{ ref('silver__contracts') }} C ON contract_address = A.underlying_asset qualify(ROW_NUMBER() over(PARTITION BY atoken_address ORDER BY - a.atoken_created_block DESC)) = 1 + A.atoken_created_block DESC)) = 1 diff --git a/models/silver/defi/lending/granary/silver__granary_withdraws.sql b/models/silver/defi/lending/granary/silver__granary_withdraws.sql index ace7814..08e83bc 100644 --- a/models/silver/defi/lending/granary/silver__granary_withdraws.sql +++ b/models/silver/defi/lending/granary/silver__granary_withdraws.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, granary_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__granary_tokens') }} ), withdraw AS( - SELECT block_number, block_timestamp, @@ -48,10 +47,14 @@ withdraw AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7' @@ -64,8 +67,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT granary_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + granary_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/moonwell/silver__moonwell_asset_details.sql b/models/silver/defi/lending/moonwell/silver__moonwell_asset_details.sql index c9322d8..4084fd8 100644 --- a/models/silver/defi/lending/moonwell/silver__moonwell_asset_details.sql +++ b/models/silver/defi/lending/moonwell/silver__moonwell_asset_details.sql @@ -22,10 +22,14 @@ log_pull AS ( C.token_name, C.token_symbol, C.token_decimals, - l._inserted_timestamp, - l._log_id + l.modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN contracts C ON C.contract_address = l.contract_address @@ -34,7 +38,7 @@ log_pull AS ( AND C.token_name LIKE '%Moonwell%' {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX( _inserted_timestamp @@ -48,7 +52,7 @@ AND l.contract_address NOT IN ( FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), traces_pull AS ( @@ -56,7 +60,8 @@ traces_pull AS ( t.from_address AS token_address, t.to_address AS underlying_asset, CASE - WHEN identifier = 'STATICCALL_0_2' THEN 1 + WHEN TYPE = 'STATICCALL' + AND trace_address = '0_2' THEN 1 ELSE NULL END AS asset_identifier FROM diff --git a/models/silver/defi/lending/moonwell/silver__moonwell_borrows.sql b/models/silver/defi/lending/moonwell/silver__moonwell_borrows.sql index c676a9b..0380960 100644 --- a/models/silver/defi/lending/moonwell/silver__moonwell_borrows.sql +++ b/models/silver/defi/lending/moonwell/silver__moonwell_borrows.sql @@ -43,10 +43,14 @@ moonwell_borrows AS ( ) :: INTEGER AS totalBorrows, contract_address AS token, 'Moonwell' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -55,7 +59,7 @@ moonwell_borrows AS ( asset_details ) AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -105,7 +109,7 @@ SELECT borrower, borrows_contract_address, borrows_contract_symbol, - token as token_address, + token AS token_address, token_symbol, loan_amount_raw AS amount_unadj, loan_amount_raw / pow( diff --git a/models/silver/defi/lending/moonwell/silver__moonwell_deposits.sql b/models/silver/defi/lending/moonwell/silver__moonwell_deposits.sql index 0dd88dc..1e8aee8 100644 --- a/models/silver/defi/lending/moonwell/silver__moonwell_deposits.sql +++ b/models/silver/defi/lending/moonwell/silver__moonwell_deposits.sql @@ -40,10 +40,14 @@ moonwell_deposits AS ( ) :: INTEGER AS mintAmount_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier, 'Moonwell' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -52,7 +56,7 @@ moonwell_deposits AS ( asset_details ) AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/moonwell/silver__moonwell_liquidations.sql b/models/silver/defi/lending/moonwell/silver__moonwell_liquidations.sql index 4cfe0cd..6a6d1ca 100644 --- a/models/silver/defi/lending/moonwell/silver__moonwell_liquidations.sql +++ b/models/silver/defi/lending/moonwell/silver__moonwell_liquidations.sql @@ -43,10 +43,14 @@ moonwell_liquidations AS ( ) :: INTEGER AS repayAmount_raw, CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS tokenCollateral, 'Moonwell' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -55,7 +59,7 @@ moonwell_liquidations AS ( asset_details ) AND topics [0] :: STRING = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/moonwell/silver__moonwell_repayments.sql b/models/silver/defi/lending/moonwell/silver__moonwell_repayments.sql index ae1e27f..c907fc7 100644 --- a/models/silver/defi/lending/moonwell/silver__moonwell_repayments.sql +++ b/models/silver/defi/lending/moonwell/silver__moonwell_repayments.sql @@ -38,10 +38,14 @@ moonwell_repayments AS ( segmented_data [2] :: STRING ) :: INTEGER AS repayed_amount_raw, 'Moonwell' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -50,7 +54,7 @@ moonwell_repayments AS ( asset_details ) AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -99,7 +103,7 @@ SELECT origin_function_signature, contract_address, borrower, - token as token_address, + token AS token_address, token_symbol, payer, repay_contract_address, diff --git a/models/silver/defi/lending/moonwell/silver__moonwell_withdraws.sql b/models/silver/defi/lending/moonwell/silver__moonwell_withdraws.sql index 3812e08..c29ccf4 100644 --- a/models/silver/defi/lending/moonwell/silver__moonwell_withdraws.sql +++ b/models/silver/defi/lending/moonwell/silver__moonwell_withdraws.sql @@ -40,10 +40,14 @@ moonwell_redemptions AS ( ) :: INTEGER AS redeemed_token_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer, 'Moonwell' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -52,7 +56,7 @@ moonwell_redemptions AS ( asset_details ) AND topics [0] :: STRING = '0xe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -100,7 +104,7 @@ SELECT origin_to_address, origin_function_signature, contract_address, - token as token_address, + token AS token_address, token_symbol, received_amount_raw AS amount_unadj, received_amount_raw / pow( diff --git a/models/silver/defi/lending/morpho/silver__morpho_borrows.sql b/models/silver/defi/lending/morpho/silver__morpho_borrows.sql index 9ec2c25..ff2df96 100644 --- a/models/silver/defi/lending/morpho/silver__morpho_borrows.sql +++ b/models/silver/defi/lending/morpho/silver__morpho_borrows.sql @@ -50,15 +50,18 @@ WITH traces AS ( trace_address ) ) AS _call_id, - modified_timestamp AS _inserted_timestamp + modified_timestamp AS _inserted_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature FROM {{ ref('core__fact_traces') }} t WHERE to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue AND function_sig = '0x50d8cd4b' - AND trace_status = 'SUCCESS' - AND tx_status = 'SUCCESS' + AND trace_succeeded + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -72,28 +75,24 @@ AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' ), tx_join AS ( SELECT - tx.block_number, - tx.tx_hash, - tx.block_timestamp, - tx.from_address AS origin_from_address, - tx.to_address AS origin_to_address, - tx.origin_function_signature, - t.from_address, - t.to_address AS contract_address, - tx.from_address AS borrower_address, - t.loan_token, - t.collateral_token, - t.amount, - t.on_behalf_address, - t.receiver_address, - t._call_id, - t._inserted_timestamp + block_number, + tx_hash, + block_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature, + from_address, + to_address AS contract_address, + origin_from_address AS borrower_address, + loan_token, + collateral_token, + amount, + on_behalf_address, + receiver_address, + _call_id, + _inserted_timestamp FROM - traces t - INNER JOIN {{ ref('silver__transactions') }} - tx - ON tx.block_number = t.block_number - AND tx.tx_hash = t.tx_hash + traces ) SELECT tx_hash, diff --git a/models/silver/defi/lending/morpho/silver__morpho_deposits.sql b/models/silver/defi/lending/morpho/silver__morpho_deposits.sql index 332f6eb..7e2ccef 100644 --- a/models/silver/defi/lending/morpho/silver__morpho_deposits.sql +++ b/models/silver/defi/lending/morpho/silver__morpho_deposits.sql @@ -50,15 +50,18 @@ WITH traces AS ( trace_address ) ) AS _call_id, - modified_timestamp AS _inserted_timestamp + modified_timestamp AS _inserted_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature FROM {{ ref('core__fact_traces') }} t WHERE to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue AND function_sig = '0xa99aad89' - AND trace_status = 'SUCCESS' - AND tx_status = 'SUCCESS' + AND trace_succeeded + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -72,28 +75,24 @@ AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' ), tx_join AS ( SELECT - tx.block_number, - tx.tx_hash, - tx.block_timestamp, - tx.from_address AS origin_from_address, - tx.to_address AS origin_to_address, - tx.origin_function_signature, - t.from_address, - t.to_address AS contract_address, - tx.from_address AS depositor_address, - t.loan_token, - t.collateral_token, - t.amount, - t.on_behalf_address, - t.receiver_address, - t._call_id, - t._inserted_timestamp + block_number, + tx_hash, + block_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature, + from_address, + to_address AS contract_address, + origin_from_address AS depositor_address, + loan_token, + collateral_token, + amount, + on_behalf_address, + receiver_address, + _call_id, + _inserted_timestamp FROM - traces t - INNER JOIN {{ ref('silver__transactions') }} - tx - ON tx.block_number = t.block_number - AND tx.tx_hash = t.tx_hash + traces ) SELECT tx_hash, diff --git a/models/silver/defi/lending/morpho/silver__morpho_flashloans.sql b/models/silver/defi/lending/morpho/silver__morpho_flashloans.sql index df7ed40..30e6f52 100644 --- a/models/silver/defi/lending/morpho/silver__morpho_flashloans.sql +++ b/models/silver/defi/lending/morpho/silver__morpho_flashloans.sql @@ -6,7 +6,7 @@ tags = ['reorg','curated'] ) }} -with flashloan AS( +WITH flashloan AS( SELECT l.tx_hash, @@ -20,27 +20,32 @@ with flashloan AS( regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS caller, CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token, - try_to_number( - utils.udf_hex_to_int( + TRY_TO_NUMBER( + utils.udf_hex_to_int( segmented_data [0] :: STRING - )) - AS flashloan_quantity, - l._log_id, - l._inserted_timestamp + ) + ) AS flashloan_quantity, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} - l + {{ ref('core__fact_event_logs') }} + l WHERE - topics[0]::STRING = '0xc76f1b4fe4396ac07a9fa55a415d4ca430e72651d37d3401f3bed7cb13fc4f12' + topics [0] :: STRING = '0xc76f1b4fe4396ac07a9fa55a415d4ca430e72651d37d3401f3bed7cb13fc4f12' AND contract_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' + {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT @@ -52,8 +57,8 @@ SELECT origin_to_address, origin_function_signature, f.contract_address, - caller as initiator_address, - token as market, + caller AS initiator_address, + token AS market, C.token_symbol, flashloan_quantity AS flashloan_amount_unadj, flashloan_quantity / pow( @@ -66,5 +71,5 @@ SELECT f._inserted_timestamp FROM flashloan f - LEFT JOIN {{ ref('silver__contracts') }} c - ON f.token = c.contract_address \ No newline at end of file + LEFT JOIN {{ ref('silver__contracts') }} C + ON f.token = C.contract_address diff --git a/models/silver/defi/lending/morpho/silver__morpho_liquidations.sql b/models/silver/defi/lending/morpho/silver__morpho_liquidations.sql index dd654e8..6198842 100644 --- a/models/silver/defi/lending/morpho/silver__morpho_liquidations.sql +++ b/models/silver/defi/lending/morpho/silver__morpho_liquidations.sql @@ -46,8 +46,8 @@ WITH traces AS ( WHERE to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue AND function_sig = '0xd8eabcb8' - AND trace_status = 'SUCCESS' - AND tx_status = 'SUCCESS' + AND trace_succeeded + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -87,10 +87,14 @@ logs AS( l.origin_to_address, l.contract_address ) AS lending_pool_contract, - l._log_id, - l._inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l WHERE topics [0] :: STRING = '0xa4946ede45d0c6f06a0f5ce92c9ad3b4751452d2fe0e25010783bcab57a67e41' diff --git a/models/silver/defi/lending/morpho/silver__morpho_repayments.sql b/models/silver/defi/lending/morpho/silver__morpho_repayments.sql index 70f7eb5..077271b 100644 --- a/models/silver/defi/lending/morpho/silver__morpho_repayments.sql +++ b/models/silver/defi/lending/morpho/silver__morpho_repayments.sql @@ -50,14 +50,17 @@ WITH traces AS ( trace_address ) ) AS _call_id, - modified_timestamp AS _inserted_timestamp + modified_timestamp AS _inserted_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature FROM {{ ref('core__fact_traces') }} WHERE to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue AND function_sig = '0x20b76e81' - AND trace_status = 'SUCCESS' - AND tx_status = 'SUCCESS' + AND trace_succeeded + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -71,28 +74,24 @@ AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' ), tx_join AS ( SELECT - tx.block_number, - tx.tx_hash, - tx.block_timestamp, - tx.from_address AS origin_from_address, - tx.to_address AS origin_to_address, - tx.origin_function_signature, - t.from_address, - t.to_address AS contract_address, - tx.from_address AS borrower_address, - t.loan_token, - t.collateral_token, - t.amount, - t.on_behalf_address, - t.receiver_address, - t._call_id, - t._inserted_timestamp + block_number, + tx_hash, + block_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature, + from_address, + to_address AS contract_address, + origin_from_address AS borrower_address, + loan_token, + collateral_token, + amount, + on_behalf_address, + receiver_address, + _call_id, + _inserted_timestamp FROM - traces t - INNER JOIN {{ ref('silver__transactions') }} - tx - ON tx.block_number = t.block_number - AND tx.tx_hash = t.tx_hash + traces ) SELECT tx_hash, diff --git a/models/silver/defi/lending/morpho/silver__morpho_withdraws.sql b/models/silver/defi/lending/morpho/silver__morpho_withdraws.sql index da1b5ea..409319e 100644 --- a/models/silver/defi/lending/morpho/silver__morpho_withdraws.sql +++ b/models/silver/defi/lending/morpho/silver__morpho_withdraws.sql @@ -50,15 +50,17 @@ WITH traces AS ( trace_address ) ) AS _call_id, - modified_timestamp AS _inserted_timestamp + modified_timestamp AS _inserted_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature FROM {{ ref('core__fact_traces') }} - t WHERE to_address = '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb' --Morpho Blue AND function_sig = '0x5c2bea49' - AND trace_status = 'SUCCESS' - AND tx_status = 'SUCCESS' + AND trace_succeeded + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -72,28 +74,24 @@ AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' ), tx_join AS ( SELECT - tx.block_number, - tx.tx_hash, - tx.block_timestamp, - tx.from_address AS origin_from_address, - tx.to_address AS origin_to_address, - tx.origin_function_signature, - t.from_address, - t.to_address AS contract_address, - tx.from_address AS depositor_address, - t.loan_token, - t.collateral_token, - t.amount, - t.on_behalf_address, - t.receiver_address, - t._call_id, - t._inserted_timestamp + block_number, + tx_hash, + block_timestamp, + origin_from_address, + origin_to_address, + origin_function_signature, + from_address, + to_address AS contract_address, + origin_from_address AS depositor_address, + loan_token, + collateral_token, + amount, + on_behalf_address, + receiver_address, + _call_id, + _inserted_timestamp FROM - traces t - INNER JOIN {{ ref('silver__transactions') }} - tx - ON tx.block_number = t.block_number - AND tx.tx_hash = t.tx_hash + traces ) SELECT tx_hash, diff --git a/models/silver/defi/lending/seamless/silver__seamless_borrows.sql b/models/silver/defi/lending/seamless/silver__seamless_borrows.sql index 5f8f38e..1679ddb 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_borrows.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_borrows.sql @@ -8,6 +8,7 @@ WITH --borrows from seamless LendingPool contracts atoken_meta AS ( + SELECT atoken_address, seamless_version_pool, @@ -26,7 +27,6 @@ atoken_meta AS ( {{ ref('silver__seamless_tokens') }} ), borrow AS ( - SELECT tx_hash, block_number, @@ -58,10 +58,14 @@ borrow AS ( contract_address ) AS lending_pool_contract, 'Seamless' AS seamless_version, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0' @@ -74,8 +78,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT seamless_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + seamless_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/seamless/silver__seamless_deposits.sql b/models/silver/defi/lending/seamless/silver__seamless_deposits.sql index 847c77d..699adca 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_deposits.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_deposits.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, seamless_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__seamless_tokens') }} ), deposits AS( - SELECT tx_hash, block_number, @@ -52,10 +51,14 @@ deposits AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61' @@ -68,10 +71,14 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT seamless_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + seamless_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) - SELECT tx_hash, block_number, diff --git a/models/silver/defi/lending/seamless/silver__seamless_flashloans.sql b/models/silver/defi/lending/seamless/silver__seamless_flashloans.sql index d0ab732..889bea8 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_flashloans.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_flashloans.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, seamless_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__seamless_tokens') }} ), flashloan AS ( - SELECT tx_hash, block_number, @@ -54,10 +53,14 @@ flashloan AS ( contract_address ) AS lending_pool_contract, 'Seamless' AS seamless_version, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0' @@ -70,8 +73,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT seamless_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + seamless_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/seamless/silver__seamless_liquidations.sql b/models/silver/defi/lending/seamless/silver__seamless_liquidations.sql index d2054a5..5d61344 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_liquidations.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_liquidations.sql @@ -6,9 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH +WITH atoken_meta AS ( -atoken_meta AS ( SELECT atoken_address, seamless_version_pool, @@ -27,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__seamless_tokens') }} ), liquidation AS( - SELECT tx_hash, block_number, @@ -53,10 +51,14 @@ liquidation AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286' @@ -69,8 +71,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT seamless_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + seamless_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/seamless/silver__seamless_repayments.sql b/models/silver/defi/lending/seamless/silver__seamless_repayments.sql index 0048f16..a722713 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_repayments.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_repayments.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, seamless_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__seamless_tokens') }} ), repay AS( - SELECT tx_hash, block_number, @@ -49,10 +48,14 @@ repay AS( contract_address ) AS lending_pool_contract, origin_from_address AS repayer_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0xa534c8dbe71f871f9f3530e97a74601fea17b426cae02e1c5aee42c96c784051' @@ -65,8 +68,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT seamless_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + seamless_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/seamless/silver__seamless_tokens.sql b/models/silver/defi/lending/seamless/silver__seamless_tokens.sql index 106b5ba..671305e 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_tokens.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_tokens.sql @@ -24,10 +24,14 @@ WITH DECODE AS ( utils.udf_hex_to_string ( segmented_data [9] :: STRING ) :: STRING AS atoken_symbol, - l._inserted_timestamp, - l._log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l WHERE topics [0] = '0xb19e051f8af41150ccccb3fc2c2d8d15f4a4cf434f32a559ba75fe73d6eea20b' @@ -76,10 +80,14 @@ debt_tokens AS ( CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS atoken_address, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40)) :: STRING AS atoken_stable_debt_address, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 27, 40)) :: STRING AS atoken_variable_debt_address, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] = '0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f' AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) IN ( @@ -128,4 +136,4 @@ FROM INNER JOIN {{ ref('silver__contracts') }} C ON contract_address = A.underlying_asset qualify(ROW_NUMBER() over(PARTITION BY atoken_address ORDER BY - a.atoken_created_block DESC)) = 1 + A.atoken_created_block DESC)) = 1 diff --git a/models/silver/defi/lending/seamless/silver__seamless_withdraws.sql b/models/silver/defi/lending/seamless/silver__seamless_withdraws.sql index ca65db2..0206886 100644 --- a/models/silver/defi/lending/seamless/silver__seamless_withdraws.sql +++ b/models/silver/defi/lending/seamless/silver__seamless_withdraws.sql @@ -6,8 +6,8 @@ tags = ['reorg','curated'] ) }} -WITH -atoken_meta AS ( +WITH atoken_meta AS ( + SELECT atoken_address, seamless_version_pool, @@ -26,7 +26,6 @@ atoken_meta AS ( {{ ref('silver__seamless_tokens') }} ), withdraw AS( - SELECT block_number, block_timestamp, @@ -48,10 +47,14 @@ withdraw AS( origin_to_address, contract_address ) AS lending_pool_contract, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE topics [0] :: STRING = '0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7' @@ -64,8 +67,13 @@ AND _inserted_timestamp >= ( ) AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} -AND contract_address in (SELECT seamless_version_pool from atoken_meta) -AND tx_status = 'SUCCESS' --excludes failed txs +AND contract_address IN ( + SELECT + seamless_version_pool + FROM + atoken_meta +) +AND tx_succeeded ) SELECT tx_hash, diff --git a/models/silver/defi/lending/sonne/silver__sonne_asset_details.sql b/models/silver/defi/lending/sonne/silver__sonne_asset_details.sql index bdbf94b..4f69fa0 100644 --- a/models/silver/defi/lending/sonne/silver__sonne_asset_details.sql +++ b/models/silver/defi/lending/sonne/silver__sonne_asset_details.sql @@ -22,10 +22,14 @@ log_pull AS ( C.token_name, C.token_symbol, C.token_decimals, - l._inserted_timestamp, - l._log_id + l.modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l LEFT JOIN contracts C ON C.contract_address = l.contract_address @@ -34,7 +38,7 @@ log_pull AS ( AND C.token_name LIKE '%SonneBase%' {% if is_incremental() %} -AND l._inserted_timestamp >= ( +AND l.modified_timestamp >= ( SELECT MAX( _inserted_timestamp @@ -48,7 +52,7 @@ AND l.contract_address NOT IN ( FROM {{ this }} ) -AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), traces_pull AS ( diff --git a/models/silver/defi/lending/sonne/silver__sonne_borrows.sql b/models/silver/defi/lending/sonne/silver__sonne_borrows.sql index e999799..b2d8f3d 100644 --- a/models/silver/defi/lending/sonne/silver__sonne_borrows.sql +++ b/models/silver/defi/lending/sonne/silver__sonne_borrows.sql @@ -43,10 +43,14 @@ sonne_borrows AS ( ) :: INTEGER AS totalBorrows, contract_address AS token, 'Sonne' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -55,7 +59,7 @@ sonne_borrows AS ( asset_details ) AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -105,7 +109,7 @@ SELECT borrower, borrows_contract_address, borrows_contract_symbol, - token as token_address, + token AS token_address, token_symbol, loan_amount_raw AS amount_unadj, loan_amount_raw / pow( diff --git a/models/silver/defi/lending/sonne/silver__sonne_deposits.sql b/models/silver/defi/lending/sonne/silver__sonne_deposits.sql index a36d140..a2d383c 100644 --- a/models/silver/defi/lending/sonne/silver__sonne_deposits.sql +++ b/models/silver/defi/lending/sonne/silver__sonne_deposits.sql @@ -40,10 +40,14 @@ sonne_deposits AS ( ) :: INTEGER AS mintAmount_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier, 'Sonne' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -52,7 +56,7 @@ sonne_deposits AS ( asset_details ) AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/sonne/silver__sonne_liquidations.sql b/models/silver/defi/lending/sonne/silver__sonne_liquidations.sql index 2794246..c58de4d 100644 --- a/models/silver/defi/lending/sonne/silver__sonne_liquidations.sql +++ b/models/silver/defi/lending/sonne/silver__sonne_liquidations.sql @@ -43,10 +43,14 @@ sonne_liquidations AS ( ) :: INTEGER AS repayAmount_raw, CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS tokenCollateral, 'Sonne' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -55,7 +59,7 @@ sonne_liquidations AS ( asset_details ) AND topics [0] :: STRING = '0x298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/sonne/silver__sonne_repayments.sql b/models/silver/defi/lending/sonne/silver__sonne_repayments.sql index a9dc789..607bb74 100644 --- a/models/silver/defi/lending/sonne/silver__sonne_repayments.sql +++ b/models/silver/defi/lending/sonne/silver__sonne_repayments.sql @@ -38,10 +38,14 @@ sonne_repayments AS ( segmented_data [2] :: STRING ) :: INTEGER AS repayed_amount_raw, 'Sonne' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -50,7 +54,7 @@ sonne_repayments AS ( asset_details ) AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -99,7 +103,7 @@ SELECT origin_function_signature, contract_address, borrower, - token as token_address, + token AS token_address, token_symbol, payer, repay_contract_address, diff --git a/models/silver/defi/lending/sonne/silver__sonne_withdraws.sql b/models/silver/defi/lending/sonne/silver__sonne_withdraws.sql index 37c2ef4..969222e 100644 --- a/models/silver/defi/lending/sonne/silver__sonne_withdraws.sql +++ b/models/silver/defi/lending/sonne/silver__sonne_withdraws.sql @@ -40,10 +40,14 @@ sonne_redemptions AS ( ) :: INTEGER AS redeemed_token_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer, 'Sonne' AS platform, - _inserted_timestamp, - _log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( SELECT @@ -52,7 +56,7 @@ sonne_redemptions AS ( asset_details ) AND topics [0] :: STRING = '0xe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -100,7 +104,7 @@ SELECT origin_to_address, origin_function_signature, contract_address, - token as token_address, + token AS token_address, token_symbol, received_amount_raw AS amount_unadj, received_amount_raw / pow( diff --git a/models/silver/ethereum/silver__state_hashes.sql b/models/silver/ethereum/silver__state_hashes.sql index 9b5f235..771885c 100644 --- a/models/silver/ethereum/silver__state_hashes.sql +++ b/models/silver/ethereum/silver__state_hashes.sql @@ -71,7 +71,6 @@ FROM blocks INNER JOIN base ON block_number BETWEEN state_min_block - AND state_max_block QUALIFY(ROW_NUMBER() over(PARTITION BY block_number - ORDER BY + AND state_max_block qualify(ROW_NUMBER() over(PARTITION BY block_number +ORDER BY state_block_timestamp DESC)) = 1 - diff --git a/models/silver/nft/sales/silver__element_sales.sql b/models/silver/nft/sales/silver__element_sales.sql index e44ddf9..4ea3db3 100644 --- a/models/silver/nft/sales/silver__element_sales.sql +++ b/models/silver/nft/sales/silver__element_sales.sql @@ -19,33 +19,33 @@ raw AS ( tx_hash, event_index, event_name, - decoded_flat, + decoded_log, IFF( event_name LIKE '%Buy%', 'bid_won', 'sale' ) AS event_type, - decoded_flat :erc20Token :: STRING AS currency_address_raw, + decoded_log :erc20Token :: STRING AS currency_address_raw, COALESCE( - decoded_flat :erc20TokenAmount, - decoded_flat :erc20FillAmount + decoded_log :erc20TokenAmount, + decoded_log :erc20FillAmount ) :: INT AS amount_raw, COALESCE( - decoded_flat :erc721Token, - decoded_flat :erc1155Token + decoded_log :erc721Token, + decoded_log :erc1155Token ) :: STRING AS nft_address, COALESCE( - decoded_flat :erc721TokenId, - decoded_flat :erc1155TokenId + decoded_log :erc721TokenId, + decoded_log :erc1155TokenId ) :: STRING AS tokenid, - decoded_flat :erc1155FillAmount :: STRING AS erc1155_value, + decoded_log :erc1155FillAmount :: STRING AS erc1155_value, IFF( erc1155_value IS NULL, 'erc721', 'erc1155' ) AS nft_type, - decoded_flat :maker :: STRING AS maker, - decoded_flat :taker :: STRING AS taker, + decoded_log :maker :: STRING AS maker, + decoded_log :taker :: STRING AS taker, IFF( event_name LIKE '%Buy%', taker, @@ -56,8 +56,8 @@ raw AS ( maker, taker ) AS buyer_address, - decoded_flat :fees AS fees_array, - decoded_flat :orderHash :: STRING AS orderhash, + decoded_log :fees AS fees_array, + decoded_log :orderHash :: STRING AS orderhash, ROW_NUMBER() over ( PARTITION BY tx_hash ORDER BY @@ -65,10 +65,14 @@ raw AS ( ) AS intra_grouping_seller_fill, block_timestamp, block_number, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_timestamp :: DATE >= ( SELECT @@ -96,7 +100,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), raw_fees AS ( @@ -147,7 +151,7 @@ new_base AS ( intra_grouping_seller_fill, event_index, event_name, - decoded_flat, + decoded_log, event_type, currency_address_raw, amount_raw, @@ -197,7 +201,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= ( SELECT @@ -213,13 +217,13 @@ tx_data AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ) SELECT @@ -228,7 +232,7 @@ SELECT tx_hash, event_index, event_name, - decoded_flat, + decoded_log, event_type, ( SELECT diff --git a/models/silver/nft/sales/silver__seaport_1_5_sales.sql b/models/silver/nft/sales/silver__seaport_1_5_sales.sql index 8ae9743..7fd4a83 100644 --- a/models/silver/nft/sales/silver__seaport_1_5_sales.sql +++ b/models/silver/nft/sales/silver__seaport_1_5_sales.sql @@ -21,10 +21,10 @@ WITH seaport_fees_wallet AS ( raw_decoded_logs AS ( SELECT *, - decoded_flat :orderHash :: STRING AS orderhash, - tx_hash || '-' || decoded_flat :orderHash AS tx_hash_orderhash + decoded_log :orderHash :: STRING AS orderhash, + tx_hash || '-' || decoded_log :orderHash AS tx_hash_orderhash FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_timestamp :: DATE >= '2023-07-01' AND block_number >= 1491574 @@ -35,13 +35,13 @@ raw_decoded_logs AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), raw_logs AS ( @@ -66,7 +66,7 @@ raw_logs AS ( NULL ) AS order_hash FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE >= '2023-07-01' AND block_number >= 1491574 @@ -78,13 +78,13 @@ raw_logs AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), raw_logs_event_index_fill AS ( @@ -136,26 +136,30 @@ mao_orderhash AS ( decoded AS ( SELECT tx_hash, - decoded_flat, + decoded_log, event_index, - decoded_data, + full_decoded_log, CONCAT( tx_hash, '-', - decoded_flat :orderHash :: STRING + decoded_log :orderHash :: STRING ) AS tx_hash_orderhash, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, LOWER( - decoded_data :address :: STRING + full_decoded_log :address :: STRING ) AS contract_address, - decoded_data :name :: STRING AS event_name, + full_decoded_log :name :: STRING AS event_name, CASE - WHEN decoded_data :data [4] :value [0] [0] IN ( + WHEN full_decoded_log :data [4] :value [0] [0] IN ( 2, 3 ) THEN 'buy' - WHEN decoded_data :data [4] :value [0] [0] IN (1) THEN 'offer_accepted' + WHEN full_decoded_log :data [4] :value [0] [0] IN (1) THEN 'offer_accepted' ELSE NULL END AS trade_type FROM @@ -179,7 +183,11 @@ offer_length_count_buy AS ( ) AS offer_length_raw --> this is the number of nfts in a batch buy. If n = 1, then price is known. If n > 1 then price is estimated FROM decoded, - TABLE(FLATTEN(input => decoded_data :data [4] :value)) + TABLE( + FLATTEN( + input => full_decoded_log :data [4] :value + ) + ) WHERE trade_type = 'buy' AND VALUE [0] IN ( @@ -201,7 +209,11 @@ offer_length_count_offer AS ( ) AS offer_length_raw --> this is the number of nfts in a batch buy. If n = 1, then price is known. If n > 1 then price is estimated FROM decoded, - TABLE(FLATTEN(input => decoded_data :data [5] :value)) + TABLE( + FLATTEN( + input => full_decoded_log :data [5] :value + ) + ) WHERE trade_type = 'offer_accepted' AND VALUE [0] IN ( @@ -220,7 +232,7 @@ flat_raw AS ( contract_address, event_name, trade_type, - decoded_data :data AS full_data, + full_decoded_log :data AS full_data, _log_id, _inserted_timestamp, OBJECT_AGG( @@ -230,7 +242,7 @@ flat_raw AS ( FROM decoded, LATERAL FLATTEN( - input => decoded_data :data + input => full_decoded_log :data ) f WHERE event_name IN ( @@ -1100,22 +1112,22 @@ mao_consideration_all AS ( SELECT tx_hash, event_index, - decoded_flat, + decoded_log, INDEX, orderhash, tx_hash_orderhash, - decoded_flat :offerer :: STRING AS offerer, - decoded_flat :recipient :: STRING AS recipient, + decoded_log :offerer :: STRING AS offerer, + decoded_log :recipient :: STRING AS recipient, VALUE, VALUE :amount :: INT AS amount, VALUE :identifier :: STRING AS identifier, VALUE :itemType :: INT AS item_type, VALUE :recipient :: STRING AS item_recipient, VALUE :token :: STRING AS item_token_address, - decoded_flat :offer [0] :amount :: INT AS offer_amount, - decoded_flat :offer [0] :identifier :: STRING AS offer_identifier, - decoded_flat :offer [0] :itemType :: INT AS offer_item_type, - decoded_flat :offer [0] :token :: STRING AS offer_item_token_address, + decoded_log :offer [0] :amount :: INT AS offer_amount, + decoded_log :offer [0] :identifier :: STRING AS offer_identifier, + decoded_log :offer [0] :itemType :: INT AS offer_item_type, + decoded_log :offer [0] :token :: STRING AS offer_item_token_address, IFF(item_type NOT IN (0, 1), CONCAT(item_token_address, '-', identifier, '-', amount), CONCAT(offer_item_token_address, '-', offer_identifier, '-', offer_amount)) AS nft_address_identifier, IFF(item_type NOT IN (0, 1), nft_address_identifier, NULL) AS nft_address_identifier_null, CASE @@ -1152,12 +1164,16 @@ mao_consideration_all AS ( ORDER BY INDEX ASC ) AS orderhash_within_event_index_rn, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM raw_decoded_logs, LATERAL FLATTEN ( - input => decoded_flat :consideration + input => decoded_log :consideration ) WHERE event_name = 'OrderFulfilled' @@ -1184,7 +1200,7 @@ mao_consideration_all_joined AS ( END AS nft_address_identifier_fill, IFF(item_type NOT IN (0, 1) AND offer_item_type NOT IN (0, 1) - AND decoded_flat :consideration [0] :itemType :: INT NOT IN (0, 1), CONCAT(tx_hash_orderhash, '-', event_index), NULL) AS deals_tag, + AND decoded_log :consideration [0] :itemType :: INT NOT IN (0, 1), CONCAT(tx_hash_orderhash, '-', event_index), NULL) AS deals_tag, CONCAT( tx_hash_orderhash, '-', @@ -1418,7 +1434,7 @@ mao_deals_nft_transfers_sales AS ( 0 ) AS creator_fee_raw, currency_address, - decoded_flat, + decoded_log, offerer, recipient, _log_id, @@ -1473,7 +1489,7 @@ mao_nondeals_nft_transfers_sales AS ( ) AS seller_address, offerer, recipient, - decoded_flat, + decoded_log, currency_address, sale_amount_raw, platform_fee_raw, @@ -1604,7 +1620,7 @@ mao_nondeals_nft_transfers_sales_fill_offer_length AS ( seller_address, offerer, recipient, - decoded_flat, + decoded_log, currency_address_fill AS currency_address, offer_length, sale_amount_raw_fill / offer_length AS sale_amount_raw, @@ -1626,7 +1642,7 @@ mao_combined_base AS ( tx_hash, om_event_index_fill, IFF( - decoded_flat :consideration [0] :itemType :: INT IN ( + decoded_log :consideration [0] :itemType :: INT IN ( 0, 1 ), @@ -1663,7 +1679,7 @@ mao_combined_base AS ( sale_amount_raw + total_fees_raw AS total_price_raw, offerer, recipient, - decoded_flat, + decoded_log, _log_id, _inserted_timestamp FROM @@ -1674,7 +1690,7 @@ mao_combined_base AS ( om_event_index_fill, -- the event index for the ordermatched IFF( - decoded_flat :consideration [0] :itemType :: INT IN ( + decoded_log :consideration [0] :itemType :: INT IN ( 0, 1 ), @@ -1710,7 +1726,7 @@ mao_combined_base AS ( sale_amount_raw + total_fees_raw AS total_price_raw, offerer, recipient, - decoded_flat, + decoded_log, _log_id, _inserted_timestamp FROM @@ -1818,7 +1834,7 @@ base_sales_buy_and_offer AS ( 'true', 'false' ) AS is_price_estimated, - decoded_flat :zone :: STRING AS ZONE, + decoded_log :zone :: STRING AS ZONE, item_type AS tx_type, item_type AS token_type, nft_address AS nft_address_temp, @@ -1833,9 +1849,9 @@ base_sales_buy_and_offer AS ( total_fees_raw, platform_fee_raw, creator_fee_raw, - decoded_flat, - decoded_flat :consideration AS consideration, - decoded_flat :offer AS offer, + decoded_log, + decoded_log :consideration AS consideration, + decoded_log :offer AS offer, seller_address AS seller_address_temp, buyer_address AS buyer_address_temp, _log_id, @@ -1854,7 +1870,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= '2023-07-01' AND tx_hash IN ( @@ -1865,13 +1881,13 @@ tx_data AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), nft_transfer_operator AS ( @@ -1892,7 +1908,7 @@ nft_transfer_operator AS ( ) ) AS erc1155_value FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE >= '2023-07-01' AND tx_hash IN ( @@ -1907,13 +1923,13 @@ nft_transfer_operator AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), final_seaport AS ( diff --git a/models/silver/nft/sales/silver__seaport_1_6_sales.sql b/models/silver/nft/sales/silver__seaport_1_6_sales.sql index b3838f3..4efbcdb 100644 --- a/models/silver/nft/sales/silver__seaport_1_6_sales.sql +++ b/models/silver/nft/sales/silver__seaport_1_6_sales.sql @@ -21,10 +21,10 @@ WITH seaport_fees_wallet AS ( raw_decoded_logs AS ( SELECT *, - decoded_flat :orderHash :: STRING AS orderhash, - tx_hash || '-' || decoded_flat :orderHash AS tx_hash_orderhash + decoded_log :orderHash :: STRING AS orderhash, + tx_hash || '-' || decoded_log :orderHash AS tx_hash_orderhash FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_timestamp :: DATE >= '2024-03-15' AND contract_address = '0x0000000000000068f116a894984e2db1123eb395' @@ -34,13 +34,13 @@ raw_decoded_logs AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND block_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), raw_logs AS ( @@ -65,7 +65,7 @@ raw_logs AS ( NULL ) AS order_hash FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE >= '2024-03-15' AND contract_address = '0x0000000000000068f116a894984e2db1123eb395' @@ -76,13 +76,13 @@ raw_logs AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), raw_logs_event_index_fill AS ( @@ -134,26 +134,30 @@ mao_orderhash AS ( decoded AS ( SELECT tx_hash, - decoded_flat, + decoded_log, event_index, - decoded_data, + full_decoded_log, CONCAT( tx_hash, '-', - decoded_flat :orderHash :: STRING + decoded_log :orderHash :: STRING ) AS tx_hash_orderhash, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, LOWER( - decoded_data :address :: STRING + full_decoded_log :address :: STRING ) AS contract_address, - decoded_data :name :: STRING AS event_name, + full_decoded_log :name :: STRING AS event_name, CASE - WHEN decoded_data :data [4] :value [0] [0] IN ( + WHEN full_decoded_log :data [4] :value [0] [0] IN ( 2, 3 ) THEN 'buy' - WHEN decoded_data :data [4] :value [0] [0] IN (1) THEN 'offer_accepted' + WHEN full_decoded_log :data [4] :value [0] [0] IN (1) THEN 'offer_accepted' ELSE NULL END AS trade_type FROM @@ -177,7 +181,11 @@ offer_length_count_buy AS ( ) AS offer_length_raw --> this is the number of nfts in a batch buy. If n = 1, then price is known. If n > 1 then price is estimated FROM decoded, - TABLE(FLATTEN(input => decoded_data :data [4] :value)) + TABLE( + FLATTEN( + input => full_decoded_log :data [4] :value + ) + ) WHERE trade_type = 'buy' AND VALUE [0] IN ( @@ -199,7 +207,11 @@ offer_length_count_offer AS ( ) AS offer_length_raw --> this is the number of nfts in a batch buy. If n = 1, then price is known. If n > 1 then price is estimated FROM decoded, - TABLE(FLATTEN(input => decoded_data :data [5] :value)) + TABLE( + FLATTEN( + input => full_decoded_log :data [5] :value + ) + ) WHERE trade_type = 'offer_accepted' AND VALUE [0] IN ( @@ -218,7 +230,7 @@ flat_raw AS ( contract_address, event_name, trade_type, - decoded_data :data AS full_data, + full_decoded_log :data AS full_data, _log_id, _inserted_timestamp, OBJECT_AGG( @@ -228,7 +240,7 @@ flat_raw AS ( FROM decoded, LATERAL FLATTEN( - input => decoded_data :data + input => full_decoded_log :data ) f WHERE event_name IN ( @@ -1098,22 +1110,22 @@ mao_consideration_all AS ( SELECT tx_hash, event_index, - decoded_flat, + decoded_log, INDEX, orderhash, tx_hash_orderhash, - decoded_flat :offerer :: STRING AS offerer, - decoded_flat :recipient :: STRING AS recipient, + decoded_log :offerer :: STRING AS offerer, + decoded_log :recipient :: STRING AS recipient, VALUE, VALUE :amount :: INT AS amount, VALUE :identifier :: STRING AS identifier, VALUE :itemType :: INT AS item_type, VALUE :recipient :: STRING AS item_recipient, VALUE :token :: STRING AS item_token_address, - decoded_flat :offer [0] :amount :: INT AS offer_amount, - decoded_flat :offer [0] :identifier :: STRING AS offer_identifier, - decoded_flat :offer [0] :itemType :: INT AS offer_item_type, - decoded_flat :offer [0] :token :: STRING AS offer_item_token_address, + decoded_log :offer [0] :amount :: INT AS offer_amount, + decoded_log :offer [0] :identifier :: STRING AS offer_identifier, + decoded_log :offer [0] :itemType :: INT AS offer_item_type, + decoded_log :offer [0] :token :: STRING AS offer_item_token_address, IFF(item_type NOT IN (0, 1), CONCAT(item_token_address, '-', identifier, '-', amount), CONCAT(offer_item_token_address, '-', offer_identifier, '-', offer_amount)) AS nft_address_identifier, IFF(item_type NOT IN (0, 1), nft_address_identifier, NULL) AS nft_address_identifier_null, CASE @@ -1150,12 +1162,16 @@ mao_consideration_all AS ( ORDER BY INDEX ASC ) AS orderhash_within_event_index_rn, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM raw_decoded_logs, LATERAL FLATTEN ( - input => decoded_flat :consideration + input => decoded_log :consideration ) WHERE event_name = 'OrderFulfilled' @@ -1182,7 +1198,7 @@ mao_consideration_all_joined AS ( END AS nft_address_identifier_fill, IFF(item_type NOT IN (0, 1) AND offer_item_type NOT IN (0, 1) - AND decoded_flat :consideration [0] :itemType :: INT NOT IN (0, 1), CONCAT(tx_hash_orderhash, '-', event_index), NULL) AS deals_tag, + AND decoded_log :consideration [0] :itemType :: INT NOT IN (0, 1), CONCAT(tx_hash_orderhash, '-', event_index), NULL) AS deals_tag, CONCAT( tx_hash_orderhash, '-', @@ -1416,7 +1432,7 @@ mao_deals_nft_transfers_sales AS ( 0 ) AS creator_fee_raw, currency_address, - decoded_flat, + decoded_log, offerer, recipient, _log_id, @@ -1471,7 +1487,7 @@ mao_nondeals_nft_transfers_sales AS ( ) AS seller_address, offerer, recipient, - decoded_flat, + decoded_log, currency_address, sale_amount_raw, platform_fee_raw, @@ -1602,7 +1618,7 @@ mao_nondeals_nft_transfers_sales_fill_offer_length AS ( seller_address, offerer, recipient, - decoded_flat, + decoded_log, currency_address_fill AS currency_address, offer_length, sale_amount_raw_fill / offer_length AS sale_amount_raw, @@ -1624,7 +1640,7 @@ mao_combined_base AS ( tx_hash, om_event_index_fill, IFF( - decoded_flat :consideration [0] :itemType :: INT IN ( + decoded_log :consideration [0] :itemType :: INT IN ( 0, 1 ), @@ -1661,7 +1677,7 @@ mao_combined_base AS ( sale_amount_raw + total_fees_raw AS total_price_raw, offerer, recipient, - decoded_flat, + decoded_log, _log_id, _inserted_timestamp FROM @@ -1672,7 +1688,7 @@ mao_combined_base AS ( om_event_index_fill, -- the event index for the ordermatched IFF( - decoded_flat :consideration [0] :itemType :: INT IN ( + decoded_log :consideration [0] :itemType :: INT IN ( 0, 1 ), @@ -1708,7 +1724,7 @@ mao_combined_base AS ( sale_amount_raw + total_fees_raw AS total_price_raw, offerer, recipient, - decoded_flat, + decoded_log, _log_id, _inserted_timestamp FROM @@ -1816,7 +1832,7 @@ base_sales_buy_and_offer AS ( 'true', 'false' ) AS is_price_estimated, - decoded_flat :zone :: STRING AS ZONE, + decoded_log :zone :: STRING AS ZONE, item_type AS tx_type, item_type AS token_type, nft_address AS nft_address_temp, @@ -1831,9 +1847,9 @@ base_sales_buy_and_offer AS ( total_fees_raw, platform_fee_raw, creator_fee_raw, - decoded_flat, - decoded_flat :consideration AS consideration, - decoded_flat :offer AS offer, + decoded_log, + decoded_log :consideration AS consideration, + decoded_log :offer AS offer, seller_address AS seller_address_temp, buyer_address AS buyer_address_temp, _log_id, @@ -1852,7 +1868,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= '2024-03-15' AND tx_hash IN ( @@ -1863,13 +1879,13 @@ tx_data AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), nft_transfer_operator AS ( @@ -1890,7 +1906,7 @@ nft_transfer_operator AS ( ) ) AS erc1155_value FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE >= '2024-03-15' AND tx_hash IN ( @@ -1905,13 +1921,13 @@ nft_transfer_operator AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM {{ this }} ) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), final_seaport AS ( diff --git a/models/silver/nft/sales/silver__zeroex_sales.sql b/models/silver/nft/sales/silver__zeroex_sales.sql index f08a71d..947bf1b 100644 --- a/models/silver/nft/sales/silver__zeroex_sales.sql +++ b/models/silver/nft/sales/silver__zeroex_sales.sql @@ -17,31 +17,35 @@ WITH raw_logs AS ( origin_from_address, origin_to_address, origin_function_signature, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, event_index, - decoded_flat, - decoded_flat :direction AS direction, - decoded_flat :erc20Token :: STRING AS currency_address, + decoded_log, + decoded_log :direction AS direction, + decoded_log :erc20Token :: STRING AS currency_address, COALESCE( - decoded_flat :erc20TokenAmount, - decoded_flat :erc20FillAmount + decoded_log :erc20TokenAmount, + decoded_log :erc20FillAmount ) :: INT AS total_price_raw, COALESCE( - decoded_flat :erc721Token, - decoded_flat :erc1155Token + decoded_log :erc721Token, + decoded_log :erc1155Token ) :: STRING AS nft_address, COALESCE( - decoded_flat :erc721TokenId, - decoded_flat :erc1155TokenId + decoded_log :erc721TokenId, + decoded_log :erc1155TokenId ) :: STRING AS tokenId, COALESCE( - decoded_flat :erc1155FillAmount, + decoded_log :erc1155FillAmount, NULL ) :: STRING AS erc1155_value, - decoded_flat :maker :: STRING AS maker, - decoded_flat :matcher :: STRING AS matcher, - decoded_flat :taker :: STRING AS taker, + decoded_log :maker :: STRING AS maker, + decoded_log :matcher :: STRING AS matcher, + decoded_log :taker :: STRING AS taker, IFF( direction = 0, maker, @@ -66,7 +70,7 @@ WITH raw_logs AS ( event_index ASC ) AS intra_tx_grouping FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_timestamp :: DATE >= '2023-08-01' AND contract_address = '0xdef1c0ded9bec7f1a1670819833240f027b25eff' @@ -84,7 +88,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= DATEADD('day', -14, CURRENT_DATE()) +AND block_timestamp >= DATEADD('day', -14, CURRENT_DATE()) {% endif %}), token_transfers_raw AS ( SELECT @@ -103,7 +107,7 @@ token_transfers_raw AS ( event_index ASC ) AS intra_tx_index FROM - {{ ref('silver__transfers') }} + {{ ref('core__ez_token_transfers') }} WHERE block_timestamp :: DATE >= '2023-08-01' AND tx_hash IN ( @@ -116,7 +120,7 @@ token_transfers_raw AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX( _inserted_timestamp @@ -124,7 +128,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= DATEADD('day', -14, CURRENT_DATE()) +AND modified_timestamp >= DATEADD('day', -14, CURRENT_DATE()) {% endif %}), logs_token_raw AS ( SELECT @@ -173,9 +177,9 @@ eth_transfers_raw AS ( WHERE currency_address = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ) - AND identifier != 'CALL_ORIGIN' + AND trace_address != 'ORIGIN' AND from_address = '0xdef1c0ded9bec7f1a1670819833240f027b25eff' - AND trace_status = 'SUCCESS' + AND trace_succeeded AND VALUE > 0 {% if is_incremental() %} @@ -311,7 +315,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= '2023-08-01' AND tx_hash IN ( @@ -322,7 +326,7 @@ tx_data AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX( _inserted_timestamp @@ -330,7 +334,7 @@ AND _inserted_timestamp >= ( FROM {{ this }} ) -AND _inserted_timestamp >= DATEADD('day', -14, CURRENT_DATE()) +AND modified_timestamp >= DATEADD('day', -14, CURRENT_DATE()) {% endif %}) SELECT block_number, diff --git a/models/silver/nft/silver__nft_transfers.sql b/models/silver/nft/silver__nft_transfers.sql index ab8d4bc..fb5ffe9 100644 --- a/models/silver/nft/silver__nft_transfers.sql +++ b/models/silver/nft/silver__nft_transfers.sql @@ -10,7 +10,11 @@ WITH base AS ( SELECT - _log_id, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, block_number, tx_hash, block_timestamp, @@ -19,11 +23,11 @@ WITH base AS ( topics, DATA, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TO_TIMESTAMP_NTZ(_inserted_timestamp) AS _inserted_timestamp + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE - tx_status = 'SUCCESS' + tx_succeeded AND ( ( topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' diff --git a/models/silver/protocols/olas/silver_olas__create_service_multisigs.sql b/models/silver/protocols/olas/silver_olas__create_service_multisigs.sql index dc66076..146fb2e 100644 --- a/models/silver/protocols/olas/silver_olas__create_service_multisigs.sql +++ b/models/silver/protocols/olas/silver_olas__create_service_multisigs.sql @@ -15,10 +15,10 @@ SELECT origin_to_address, contract_address, event_index, - topics [0] :: STRING AS topic_0, - topics [1] :: STRING AS topic_1, - topics [2] :: STRING AS topic_2, - topics [3] :: STRING AS topic_3, + topic_0, + topic_1, + topic_2, + topic_3, 'CreateMultisigWithAgents' AS event_name, DATA, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, @@ -28,8 +28,12 @@ SELECT ) ) AS id, CONCAT('0x', SUBSTR(topic_2, 27, 40)) AS multisig_address, - _log_id, - _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, {{ dbt_utils.generate_surrogate_key( ['tx_hash','event_index'] ) }} AS create_service_multisigs_id, @@ -37,11 +41,11 @@ SELECT SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address = '0x3c1ff68f5aa342d296d4dee4bb1cacca912d95fe' --Service Registry (AUTONOLAS-SERVICE-V1) AND topic_0 = '0x2d53f895cd5faf3cddba94a25c2ced2105885b5b37450ff430ffa3cbdf332c74' --CreateMultisigWithAgents - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/protocols/olas/silver_olas__service_event_logs.sql b/models/silver/protocols/olas/silver_olas__service_event_logs.sql index 23102e7..24c2751 100644 --- a/models/silver/protocols/olas/silver_olas__service_event_logs.sql +++ b/models/silver/protocols/olas/silver_olas__service_event_logs.sql @@ -25,14 +25,18 @@ SELECT d.event_index, s.multisig_address, s.id AS service_id, - d.topics [0] :: STRING AS topic_0, - d.topics [1] :: STRING AS topic_1, - d.topics [2] :: STRING AS topic_2, - d.topics [3] :: STRING AS topic_3, + d.topic_0, + d.topic_1, + d.topic_2, + d.topic_3, d.data, regexp_substr_all(SUBSTR(d.data, 3, len(d.data)), '.{64}') AS segmented_data, - d._log_id, - d._inserted_timestamp, + CONCAT( + d.tx_hash :: STRING, + '-', + d.event_index :: STRING + ) AS _log_id, + d.modified_timestamp AS _inserted_timestamp, {{ dbt_utils.generate_surrogate_key( ['d.tx_hash','d.event_index'] ) }} AS service_event_logs_id, @@ -40,15 +44,15 @@ SELECT SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} d INNER JOIN service_multisigs s ON d.origin_to_address = s.multisig_address WHERE - d.tx_status = 'SUCCESS' + d.tx_succeeded {% if is_incremental() %} -AND d._inserted_timestamp >= ( +AND d.modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '12 hours' FROM diff --git a/models/silver/protocols/olas/silver_olas__service_registrations.sql b/models/silver/protocols/olas/silver_olas__service_registrations.sql index bd01f75..74f285e 100644 --- a/models/silver/protocols/olas/silver_olas__service_registrations.sql +++ b/models/silver/protocols/olas/silver_olas__service_registrations.sql @@ -17,20 +17,24 @@ WITH registry_evt AS ( origin_to_address, contract_address, event_index, - topics [0] :: STRING AS topic_0, - topics [1] :: STRING AS topic_1, - topics [2] :: STRING AS topic_2, - topics [3] :: STRING AS topic_3, + topic_0, + topic_1, + topic_2, + topic_3, CASE WHEN topic_0 = '0xb34c1e02384201736eb4693b9b173306cb41bff12f15894dea5773088e9a3b1c' THEN 'CreateService' WHEN topic_0 = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' THEN 'Transfer' END AS event_name, DATA, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address = '0x3c1ff68f5aa342d296d4dee4bb1cacca912d95fe' --Service Registry (AUTONOLAS-SERVICE-V1) AND topic_0 IN ( @@ -38,7 +42,7 @@ WITH registry_evt AS ( --CreateService (for services) '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' --Transfer ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -142,7 +146,8 @@ heal_model AS ( t0.service_id, t0.config_hash, t0.owner_address, - m.multisig_address, --fill late-arriving or replace with current multisig + m.multisig_address, + --fill late-arriving or replace with current multisig t0._log_id, t0._inserted_timestamp FROM diff --git a/models/silver/stats/silver_stats__core_metrics_hourly.sql b/models/silver/stats/silver_stats__core_metrics_hourly.sql index d16c1bb..b08810d 100644 --- a/models/silver/stats/silver_stats__core_metrics_hourly.sql +++ b/models/silver/stats/silver_stats__core_metrics_hourly.sql @@ -14,9 +14,9 @@ SELECT MIN(DATE_TRUNC('hour', block_timestamp)) block_timestamp_hour FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE - _inserted_timestamp >= ( + modified_timestamp >= ( SELECT MAX(_inserted_timestamp) FROM @@ -40,12 +40,12 @@ SELECT ) AS transaction_count, COUNT( DISTINCT CASE - WHEN tx_success THEN tx_hash + WHEN tx_succeeded THEN tx_hash END ) AS transaction_count_success, COUNT( DISTINCT CASE - WHEN NOT tx_success THEN tx_hash + WHEN NOT tx_succeeded THEN tx_hash END ) AS transaction_count_failed, COUNT( @@ -55,7 +55,7 @@ SELECT DISTINCT to_address ) AS unique_to_count, SUM(tx_fee_precise) AS total_fees, - MAX(_inserted_timestamp) AS _inserted_timestamp, + MAX(modified_timestamp) AS _inserted_timestamp, {{ dbt_utils.generate_surrogate_key( ['block_timestamp_hour'] ) }} AS core_metrics_hourly_id, @@ -63,7 +63,7 @@ SELECT SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp_hour < DATE_TRUNC( 'hour', diff --git a/models/streamline/silver/decoded_logs/realtime/streamline__decoded_logs_realtime.sql b/models/streamline/silver/decoded_logs/realtime/streamline__decoded_logs_realtime.sql index 3c624d2..30f92ac 100644 --- a/models/streamline/silver/decoded_logs/realtime/streamline__decoded_logs_realtime.sql +++ b/models/streamline/silver/decoded_logs/realtime/streamline__decoded_logs_realtime.sql @@ -1,37 +1,43 @@ -{%- set testing_limit = var('DECODED_LOGS_REALTIME_TESTING_LIMIT', none) -%} - -{%- set streamline_params = { - "external_table": var("DECODED_LOGS_REALTIME_EXTERNAL_TABLE", "decoded_logs"), - "sql_limit": var("DECODED_LOGS_REALTIME_SQL_LIMIT", 10000000), - "producer_batch_size": var("DECODED_LOGS_REALTIME_PRODUCER_BATCH_SIZE", 400000), - "worker_batch_size": var("DECODED_LOGS_REALTIME_WORKER_BATCH_SIZE", 200000), - "sql_source": "decoded_logs_realtime" -} -%} - +{%- set testing_limit = var( + 'DECODED_LOGS_REALTIME_TESTING_LIMIT', + none +) -%} +{%- set streamline_params ={ "external_table": var( + "DECODED_LOGS_REALTIME_EXTERNAL_TABLE", + "decoded_logs" +), +"sql_limit": var( + "DECODED_LOGS_REALTIME_SQL_LIMIT", + 10000000 +), +"producer_batch_size": var( + "DECODED_LOGS_REALTIME_PRODUCER_BATCH_SIZE", + 400000 +), +"worker_batch_size": var( + "DECODED_LOGS_REALTIME_WORKER_BATCH_SIZE", + 200000 +), +"sql_source": "decoded_logs_realtime" } -%} {# Log configuration details #} -{{ log_model_details( - params = streamline_params +{{ log_model_details( + params = streamline_params ) }} - {# Set up dbt configuration #} {{ config ( materialized = "view", - post_hook = [fsc_utils.if_data_call_function_v2( - func = 'streamline.udf_bulk_decode_logs_v2', - target = "{{this.schema}}.{{this.identifier}}", - params = { - "external_table": streamline_params['external_table'], - "sql_limit": streamline_params['sql_limit'], - "producer_batch_size": streamline_params['producer_batch_size'], - "worker_batch_size": streamline_params['worker_batch_size'], - "sql_source": streamline_params['sql_source'] - } - ), - fsc_utils.if_data_call_wait()], - tags = ['streamline_decoded_logs_realtime'] + post_hook = [fsc_utils.if_data_call_function_v2( func = 'streamline.udf_bulk_decode_logs_v2', target = "{{this.schema}}.{{this.identifier}}", params = { "external_table": streamline_params['external_table'], + "sql_limit": streamline_params ['sql_limit'], + "producer_batch_size": streamline_params ['producer_batch_size'], + "worker_batch_size": streamline_params ['worker_batch_size'], + "sql_source": streamline_params ['sql_source'] } +), +fsc_utils.if_data_call_wait() ], +tags = ['streamline_decoded_logs_realtime'] ) }} WITH target_blocks AS ( + SELECT block_number FROM @@ -52,59 +58,55 @@ existing_logs_to_exclude AS ( l INNER JOIN target_blocks b USING (block_number) WHERE - l.inserted_timestamp :: DATE >= DATEADD('day', -2, SYSDATE()) -), -candidate_logs AS ( - SELECT - l.block_number, - l.tx_hash, - l.event_index, - l.contract_address, - l.topics, - l.data, - CONCAT( - l.tx_hash :: STRING, - '-', - l.event_index :: STRING - ) AS _log_id - FROM - target_blocks b - INNER JOIN {{ ref('core__fact_event_logs') }} - l USING (block_number) - WHERE - l.tx_status = 'SUCCESS' - AND l.inserted_timestamp :: DATE >= DATEADD('day', -2, SYSDATE()) -) -SELECT - l.block_number, - l._log_id, - A.abi, - OBJECT_CONSTRUCT( - 'topics', - l.topics, - 'data', - l.data, - 'address', - l.contract_address - ) AS DATA -FROM - candidate_logs l - INNER JOIN {{ ref('silver__complete_event_abis') }} A - ON A.parent_contract_address = l.contract_address - AND A.event_signature = l.topics [0] :: STRING - AND l.block_number BETWEEN A.start_block - AND A.end_block -WHERE - NOT EXISTS ( - SELECT - 1 - FROM - existing_logs_to_exclude e - WHERE - e._log_id = l._log_id - ) - -{% if testing_limit is not none %} - LIMIT - {{ testing_limit }} -{% endif %} \ No newline at end of file + l.inserted_timestamp :: DATE >= DATEADD('day', -2, SYSDATE())), + candidate_logs AS ( + SELECT + l.block_number, + l.tx_hash, + l.event_index, + l.contract_address, + l.topics, + l.data, + CONCAT( + l.tx_hash :: STRING, + '-', + l.event_index :: STRING + ) AS _log_id + FROM + target_blocks b + INNER JOIN {{ ref('core__fact_event_logs') }} + l USING (block_number) + WHERE + l.tx_succeeded + AND l.inserted_timestamp :: DATE >= DATEADD('day', -2, SYSDATE())) + SELECT + l.block_number, + l._log_id, + A.abi, + OBJECT_CONSTRUCT( + 'topics', + l.topics, + 'data', + l.data, + 'address', + l.contract_address + ) AS DATA + FROM + candidate_logs l + INNER JOIN {{ ref('silver__complete_event_abis') }} A + ON A.parent_contract_address = l.contract_address + AND A.event_signature = l.topics [0] :: STRING + AND l.block_number BETWEEN A.start_block + AND A.end_block + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + existing_logs_to_exclude e + WHERE + e._log_id = l._log_id + ) {% if testing_limit is not none %} + LIMIT + {{ testing_limit }} + {% endif %}