diff --git a/macros/tests/missing_decoding.sql b/macros/tests/missing_decoding.sql index 81836ab..432c915 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('0x82aF49447D8a07e3bd95BD0d56f35241523fBab1') -- WETH AND l.topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' -- Transfer 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..1895c0d 100644 --- a/models/gold/core/core__ez_decoded_event_logs.sql +++ b/models/gold/core/core__ez_decoded_event_logs.sql @@ -8,19 +8,31 @@ 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( @@ -28,7 +40,8 @@ SELECT ) }} ) 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 + GREATEST(COALESCE(l.modified_timestamp, '2000-01-01'), COALESCE(C.modified_timestamp, '2000-01-01')) AS modified_timestamp, + tx_status --deprecate FROM {{ ref('silver__decoded_logs') }} l diff --git a/models/gold/core/core__ez_decoded_event_logs.yml b/models/gold/core/core__ez_decoded_event_logs.yml index f69ff55..372ecc0 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("arb_block_number") }}' @@ -36,13 +36,13 @@ models: - name: CONTRACT_ADDRESS description: '{{ doc("arb_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("arb_tx_origin_sig") }}' - name: ORIGIN_FROM_ADDRESS @@ -51,15 +51,25 @@ models: description: '{{ doc("arb_origin_to") }}' - name: TOPICS description: '{{ doc("arb_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("arb_logs_data") }}' - name: EVENT_REMOVED - description: '{{ doc("arb_event_removed") }}' + description: '{{ doc("arb_event_removed") }}' - name: TX_STATUS - description: '{{ doc("arb_tx_status") }}' + description: '{{ doc("evm_column_deprecation_notice") }}' + - name: TX_SUCCEEDED + description: '{{ doc("arb_tx_status") }}' - name: EZ_DECODED_EVENT_LOGS_ID - description: '{{ doc("pk") }}' + description: '{{ doc("evm_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 10fbdf0..5f8cc7f 100644 --- a/models/gold/core/core__ez_native_transfers.sql +++ b/models/gold/core/core__ez_native_transfers.sql @@ -5,34 +5,23 @@ ) }} SELECT - tx_hash, block_number, block_timestamp, + tx_hash, tx_position, trace_index, - identifier, - origin_from_address, - origin_to_address, - origin_function_signature, from_address, to_address, amount, 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 + origin_from_address, + origin_to_address, + origin_function_signature, + native_transfers_id AS ez_native_transfers_id, + inserted_timestamp, + modified_timestamp, + identifier -- deprecate FROM - {{ ref('silver__native_transfers') }} \ No newline at end of file + {{ 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 32da205..ee6b659 100644 --- a/models/gold/core/core__ez_native_transfers.yml +++ b/models/gold/core/core__ez_native_transfers.yml @@ -15,7 +15,7 @@ models: - name: TRACE_INDEX description: '{{ doc("arb_trace_index") }}' - name: IDENTIFIER - description: '{{ doc("arb_traces_identifier") }}' + description: '{{ doc("evm_column_deprecation_notice_identifier") }}' - name: ORIGIN_FROM_ADDRESS description: '{{ doc("arb_origin_from") }}' - name: ORIGIN_TO_ADDRESS @@ -33,10 +33,10 @@ models: - name: AMOUNT_PRECISE description: '{{ doc("precise_amount_adjusted") }}' - name: AMOUNT_USD - description: '{{ doc("arb_eth_amount_usd") }}' + description: '{{ doc("arb_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 5d975bf..c6ae146 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("arb_block_number") }}' + description: '{{ doc("arb_block_number") }}' - name: BLOCK_TIMESTAMP description: '{{ doc("arb_block_timestamp") }}' - name: TX_HASH @@ -41,18 +41,18 @@ models: - name: SYMBOL description: '{{ doc("arb_symbol") }}' - name: TOKEN_PRICE - description: '{{ doc("arb_transfer_token_price") }}' + description: '{{ doc("evm_column_deprecation_notice_token_price") }}' - name: HAS_DECIMAL - description: '{{ doc("arb_transfer_has_decimal") }}' + description: '{{ doc("evm_column_deprecation_notice_has_decimal") }}' - name: HAS_PRICE - description: '{{ doc("arb_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("evm_pk") }}' - name: INSERTED_TIMESTAMP - description: '{{ doc("inserted_timestamp") }}' + description: '{{ doc("evm_inserted_timestamp") }}' - name: MODIFIED_TIMESTAMP - description: '{{ doc("modified_timestamp") }}' \ No newline at end of file + description: '{{ doc("evm_modified_timestamp") }}' diff --git a/models/gold/core/core__fact_blocks.sql b/models/gold/core/core__fact_blocks.sql index dd171ca..610fdd0 100644 --- a/models/gold/core/core__fact_blocks.sql +++ b/models/gold/core/core__fact_blocks.sql @@ -6,21 +6,54 @@ SELECT block_number, + HASH AS block_hash, --new column block_timestamp, 'mainnet' AS network, - 'arbitrum' AS blockchain, tx_count, + SIZE, + miner, --new + extra_data, + parent_hash, + gas_used, + gas_limit, + base_fee_per_gas, --new column difficulty, total_difficulty, - extra_data, - gas_limit, - gas_used, - HASH, - parent_hash, - receipts_root, sha3_uncles, - SIZE, - uncles as uncle_blocks, + uncles AS uncle_blocks, + nonce,-- new column + receipts_root, + state_root, -- new column + transactions_root, -- new column + logs_bloom, -- new column + 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, + 'arbitrum' AS blockchain, -- deprecate + hash, --deprecate OBJECT_CONSTRUCT( 'baseFeePerGas', base_fee_per_gas, @@ -60,33 +93,9 @@ 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 + ) AS block_header_json -- deprecate + FROM - {{ ref('silver__blocks') }} a - LEFT JOIN {{ ref('silver__tx_count') }} d USING (block_number) + {{ ref('silver__blocks') }} A + LEFT JOIN {{ ref('silver__tx_count') }} + d USING (block_number) \ No newline at end of file diff --git a/models/gold/core/core__fact_blocks.yml b/models/gold/core/core__fact_blocks.yml index 7923806..b37343b 100644 --- a/models/gold/core/core__fact_blocks.yml +++ b/models/gold/core/core__fact_blocks.yml @@ -1,46 +1,62 @@ version: 2 models: - name: core__fact_blocks - description: '{{ doc("arb_blocks_table_doc") }}' + description: '{{ doc("evm_blocks_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("arb_block_number") }}' + description: '{{ doc("evm_block_number") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("arb_block_timestamp") }}' + description: '{{ doc("evm_block_timestamp") }}' - name: NETWORK - description: '{{ doc("arb_network") }}' + description: '{{ doc("evm_network") }}' - name: BLOCKCHAIN - description: '{{ doc("arb_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("arb_tx_count") }}' + description: '{{ doc("evm_tx_count") }}' - name: DIFFICULTY - description: '{{ doc("arb_difficulty") }}' + description: '{{ doc("evm_difficulty") }}' - name: TOTAL_DIFFICULTY - description: '{{ doc("arb_total_difficulty") }}' + description: '{{ doc("evm_total_difficulty") }}' - name: EXTRA_DATA - description: '{{ doc("arb_extra_data") }}' + description: '{{ doc("evm_extra_data") }}' - name: GAS_LIMIT - description: '{{ doc("arb_gas_limit") }}' + description: '{{ doc("evm_gas_limit") }}' - name: GAS_USED - description: '{{ doc("arb_gas_used") }}' + description: '{{ doc("evm_gas_used") }}' + - name: BASE_FEE_PER_GAS + description: '{{ doc("evm_base_fee_per_gas") }}' + - name: BLOCK_HASH + description: '{{ doc("evm_blocks_hash") }}' - name: HASH - description: '{{ doc("arb_blocks_hash") }}' + description: '{{ doc("evm_column_deprecation_notice_hash") }}' - name: PARENT_HASH - description: '{{ doc("arb_parent_hash") }}' + description: '{{ doc("evm_parent_hash") }}' - name: RECEIPTS_ROOT - description: '{{ doc("arb_receipts_root") }}' + description: '{{ doc("evm_receipts_root") }}' - name: SHA3_UNCLES - description: '{{ doc("arb_sha3_uncles") }}' + description: '{{ doc("evm_sha3_uncles") }}' - name: SIZE - description: '{{ doc("arb_size") }}' + description: '{{ doc("evm_size") }}' - name: UNCLE_BLOCKS - description: '{{ doc("arb_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("arb_block_header_json") }}' + description: '{{ doc("evm_column_deprecation_notice_block_header_json") }}' + - name: BASE_FEE_PER_GAS + description: '{{ doc("evm_base_fee_per_gas") }}' - name: FACT_BLOCKS_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") }}' \ No newline at end of file + description: '{{ doc("evm_modified_timestamp") }}' diff --git a/models/gold/core/core__fact_decoded_event_logs.yml b/models/gold/core/core__fact_decoded_event_logs.yml index 2cd16a3..66c31ae 100644 --- a/models/gold/core/core__fact_decoded_event_logs.yml +++ b/models/gold/core/core__fact_decoded_event_logs.yml @@ -1,30 +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: + description: '{{ doc("evm_table_deprecation_notice_fact_decoded_event_logs") }}' - ```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```' - columns: - name: BLOCK_NUMBER description: '{{ doc("arb_block_number") }}' @@ -37,14 +15,14 @@ models: - name: CONTRACT_ADDRESS description: '{{ doc("arb_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") }}' \ No newline at end of file + 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 76689c2..2f70983 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("arb_logs_table_doc") }}' + description: '{{ doc("evm_logs_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("arb_block_number") }}' + description: '{{ doc("evm_block_number") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("arb_block_timestamp") }}' + description: '{{ doc("evm_block_timestamp") }}' - name: TX_HASH - description: '{{ doc("arb_logs_tx_hash") }}' + description: '{{ doc("evm_logs_tx_hash") }}' - name: EVENT_INDEX - description: '{{ doc("arb_event_index") }}' + description: '{{ doc("evm_event_index") }}' - name: CONTRACT_ADDRESS - description: '{{ doc("arb_logs_contract_address") }}' + description: '{{ doc("evm_logs_contract_address") }}' - name: TOPICS - description: '{{ doc("arb_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("arb_logs_data") }}' + description: '{{ doc("evm_logs_data") }}' - name: EVENT_REMOVED - description: '{{ doc("arb_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("arb_tx_status") }}' + description: '{{ doc("evm_column_deprecation_notice_tx_status") }}' + - name: TX_SUCCEEDED + description: '{{ doc("evm_tx_succeeded") }}' - name: ORIGIN_FUNCTION_SIGNATURE - description: '{{ doc("arb_origin_sig") }}' + description: '{{ doc("evm_origin_sig") }}' - name: ORIGIN_FROM_ADDRESS - description: '{{ doc("arb_origin_from") }}' + description: '{{ doc("evm_origin_from") }}' - name: ORIGIN_TO_ADDRESS - description: '{{ doc("arb_origin_to") }}' + description: '{{ doc("evm_origin_to") }}' - name: FACT_EVENT_LOGS_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") }}' \ No newline at end of file + description: '{{ doc("evm_modified_timestamp") }}' diff --git a/models/gold/core/core__fact_token_transfers.yml b/models/gold/core/core__fact_token_transfers.yml index c760974..eab6c71 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("arb_block_number") }}' + description: '{{ doc("arb_block_number") }}' - name: BLOCK_TIMESTAMP description: '{{ doc("arb_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") }}' \ No newline at end of file + description: '{{ doc("modified_timestamp") }}' diff --git a/models/gold/core/core__fact_traces.sql b/models/gold/core/core__fact_traces.sql index 50fe421..f7ac5c0 100644 --- a/models/gold/core/core__fact_traces.sql +++ b/models/gold/core/core__fact_traces.sql @@ -611,9 +611,12 @@ SELECT revert_reason, tx_succeeded, identifier, + --deprecate DATA, + --deprecate tx_status, - trace_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 8d02cf2..0508448 100644 --- a/models/gold/core/core__fact_traces.yml +++ b/models/gold/core/core__fact_traces.yml @@ -1,74 +1,68 @@ version: 2 models: - name: core__fact_traces - description: '{{ doc("arb_traces_table_doc") }}' + description: '{{ doc("evm_traces_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("arb_traces_block_no") }}' + description: '{{ doc("evm_traces_block_no") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("arb_traces_blocktime") }}' + description: '{{ doc("evm_traces_blocktime") }}' - name: TX_HASH - description: '{{ doc("arb_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("arb_traces_from") }}' - - name: TO_ADDRESS - description: '{{ doc("arb_traces_to") }}' - - name: INPUT - description: '{{ doc("arb_traces_input") }}' - - name: OUTPUT - description: '{{ doc("arb_traces_output") }}' - - name: TYPE - description: '{{ doc("arb_traces_type") }}' - - name: TRACE_ADDRESS - description: This field represents the position of the trace within the transaction. - - name: SUB_TRACES - description: '{{ doc("arb_traces_sub") }}' - - name: IDENTIFIER - description: '{{ doc("arb_traces_identifier") }}' - - name: DATA - description: '{{ doc("arb_traces_call_data") }}' - - name: VALUE - description: '{{ doc("arb_traces_value") }}' - - name: VALUE_PRECISE_RAW - description: '{{ doc("precise_amount_unadjusted") }}' - - name: VALUE_PRECISE - description: '{{ doc("precise_amount_adjusted") }}' - - name: VALUE_HEX - description: The value transacted in ETH in hexadecimal format. - - name: GAS - description: '{{ doc("arb_traces_gas") }}' - - name: GAS_USED - description: '{{ doc("arb_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: BEFORE_EVM_TRANSFERS description: The state of all ETH transfers to be executed for a given transaction. - name: AFTER_EVM_TRANSFERS description: The state of all ETH transfers executed for a given transaction. - - 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("arb_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 755a86f..1e0837a 100644 --- a/models/gold/core/core__fact_transactions.sql +++ b/models/gold/core/core__fact_transactions.sql @@ -7,18 +7,25 @@ SELECT 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, + -- new column + tx_type, + nonce, + POSITION AS tx_position, + -- new + input_data, gas_price AS gas_price_bid, effective_gas_price AS gas_price_paid, gas AS gas_limit, @@ -26,14 +33,11 @@ SELECT cumulative_gas_used, max_fee_per_gas, max_priority_fee_per_gas, - input_data, - tx_status AS status, + l1_block_number, + gas_used_for_l1, r, s, v, - tx_type, - l1_block_number, - gas_used_for_l1, COALESCE ( transactions_id, {{ dbt_utils.generate_surrogate_key( @@ -47,6 +51,11 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + block_hash, + -- deprecate + tx_status AS status, + -- deprecate + POSITION -- deprecate FROM {{ ref('silver__transactions') }} diff --git a/models/gold/core/core__fact_transactions.yml b/models/gold/core/core__fact_transactions.yml index b0830ed..eca753b 100644 --- a/models/gold/core/core__fact_transactions.yml +++ b/models/gold/core/core__fact_transactions.yml @@ -1,55 +1,59 @@ version: 2 models: - name: core__fact_transactions - description: '{{ doc("arb_tx_table_doc") }}' + description: '{{ doc("evm_tx_table_doc") }}' columns: - name: BLOCK_NUMBER - description: '{{ doc("arb_block_number") }}' + description: '{{ doc("evm_block_number") }}' - name: BLOCK_TIMESTAMP - description: '{{ doc("arb_block_timestamp") }}' + description: '{{ doc("evm_block_timestamp") }}' - name: BLOCK_HASH - description: '{{ doc("arb_tx_block_hash") }}' + description: '{{ doc("evm_column_deprecation_notice_block_hash") }}' - name: TX_HASH - description: '{{ doc("arb_tx_hash") }}' + description: '{{ doc("evm_tx_hash") }}' - name: NONCE - description: '{{ doc("arb_tx_nonce") }}' + description: '{{ doc("evm_tx_nonce") }}' - name: POSITION - description: '{{ doc("arb_tx_position") }}' + description: '{{ doc("evm_column_deprecation_notice_position") }}' + - name: TX_POSITION + description: '{{ doc("evm_tx_position") }}' - name: FROM_ADDRESS - description: '{{ doc("arb_from_address") }}' + description: '{{ doc("evm_from_address") }}' - name: TO_ADDRESS - description: '{{ doc("arb_to_address") }}' + description: '{{ doc("evm_to_address") }}' - name: VALUE - description: '{{ doc("arb_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("arb_tx_fee") }}' + description: '{{ doc("evm_tx_fee") }}' - name: TX_FEE_PRECISE - description: '{{ doc("tx_fee_precise") }}' + description: '{{ doc("tx_fee_precise") }}' - name: GAS_PRICE_BID - description: '{{ doc("arb_tx_gas_bid") }}' + description: '{{ doc("arb_tx_gas_bid") }}' - name: GAS_PRICE_PAID - description: '{{ doc("arb_tx_gas_paid") }}' + description: '{{ doc("arb_tx_gas_paid") }}' - name: GAS_LIMIT - description: '{{ doc("arb_tx_gas_limit") }}' + description: '{{ doc("arb_tx_gas_limit") }}' - name: GAS_USED description: '{{ doc("arb_tx_gas_used") }}' - name: CUMULATIVE_GAS_USED - description: '{{ doc("arb_cumulative_gas_used") }}' + description: '{{ doc("arb_cumulative_gas_used") }}' - 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: STATUS - description: '{{ doc("arb_tx_status") }}' + description: '{{ doc("evm_column_deprecation_notice_tx_status") }}' + - name: TX_SUCCEEDED + description: '{{ doc("evm_tx_succeeded") }}' - name: INPUT_DATA - description: '{{ doc("arb_tx_input_data") }}' - - name: ORIGIN_FUNCTION_SIGNATURE - description: '{{ doc("arb_tx_origin_sig") }}' + 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 @@ -63,8 +67,8 @@ models: - name: GAS_USED_FOR_L1 description: The gas used by the transaction on Ethereum Mainnet. - 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") }}' \ 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 699a82f..189d682 100644 --- a/models/gold/defi/defi__ez_dex_swaps.sql +++ b/models/gold/defi/defi__ez_dex_swaps.sql @@ -58,7 +58,6 @@ SELECT token_out, symbol_in, symbol_out, - _log_id, COALESCE ( complete_dex_swaps_id, {{ dbt_utils.generate_surrogate_key( @@ -72,5 +71,6 @@ SELECT COALESCE( modified_timestamp, '2000-01-01' - ) AS modified_timestamp + ) AS modified_timestamp, + _log_id -- deprecate FROM {{ ref('silver_dex__complete_dex_swaps') }} \ No newline at end of file diff --git a/models/gold/defi/defi__ez_dex_swaps.yml b/models/gold/defi/defi__ez_dex_swaps.yml index e011d1c..7d47272 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("arb_event_index") }}' - name: _LOG_ID - description: '{{ doc("internal_column") }}' + description: '{{ doc("evm_column_deprecation_notice_log_id") }}' - name: ORIGIN_FUNCTION_SIGNATURE description: '{{ doc("arb_tx_origin_sig") }}' - name: ORIGIN_FROM_ADDRESS @@ -51,8 +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 54e8aaf..eb72239 100644 --- a/models/gold/nft/nft__ez_nft_sales.sql +++ b/models/gold/nft/nft__ez_nft_sales.sql @@ -23,10 +23,14 @@ 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, --new + CASE + WHEN erc1155_value IS NULL THEN 'erc721' + ELSE 'erc1155' + END AS token_standard, --new currency_symbol, currency_address, price, @@ -55,6 +59,10 @@ 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 866bc68..da86f0e 100644 --- a/models/gold/nft/nft__ez_nft_sales.yml +++ b/models/gold/nft/nft__ez_nft_sales.yml @@ -1,8 +1,8 @@ version: 2 models: - name: nft__ez_nft_sales - description: 'This table contains NFT sale events on the Arbitrum blockchain which includes Opensea, Treasure and Element' - + description: '{{ doc("evm_ez_nft_sales_table_doc") }}' + columns: - name: BLOCK_NUMBER description: '{{ doc("nft_block_no") }}' @@ -11,47 +11,59 @@ models: - name: 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 54be5a8..6b76848 100644 --- a/models/gold/nft/nft__ez_nft_transfers.sql +++ b/models/gold/nft/nft__ez_nft_transfers.sql @@ -12,15 +12,28 @@ 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, --new + 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, --new + 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( @@ -34,7 +47,14 @@ 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 7fd5c2a..8ecb775 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 acbd37d..f1818da 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 e4487c0..f66b14e 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 column #} logs, _inserted_timestamp FROM @@ -39,6 +40,7 @@ flat_logs AS ( origin_from_address, origin_to_address, tx_status, + {# position AS tx_position, --new column #} VALUE :address :: STRING AS contract_address, VALUE :blockHash :: STRING AS block_hash, VALUE :data :: STRING AS DATA, @@ -63,6 +65,7 @@ new_records AS ( l.origin_to_address, txs.origin_function_signature, l.tx_status, + {# l.tx_position, --new column #} l.contract_address, l.block_hash, l.data, @@ -107,6 +110,7 @@ missing_data AS ( t.origin_to_address, txs.origin_function_signature, t.tx_status, + {# t.tx_position, --new column #} 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 column #} contract_address, block_hash, DATA, @@ -162,6 +167,7 @@ SELECT origin_to_address, origin_function_signature, tx_status, + {# tx_position, --new column #} contract_address, block_hash, DATA, diff --git a/models/silver/core/silver__native_transfers.sql b/models/silver/core/silver__native_transfers.sql index bc8073d..843ea6d 100644 --- a/models/silver/core/silver__native_transfers.sql +++ b/models/silver/core/silver__native_transfers.sql @@ -31,13 +31,16 @@ 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' @@ -51,38 +54,12 @@ AND modified_timestamp >= ( {{ 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 - MAX(_inserted_timestamp) - INTERVAL '72 hours' - FROM - {{ this }} -) -{% 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 = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - 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..083e8bc 100644 --- a/models/silver/core/silver__relevant_contracts.sql +++ b/models/silver/core/silver__relevant_contracts.sql @@ -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 926198a..85e71ff 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 @@ -27,7 +27,9 @@ GROUP BY block_number ) SELECT - *, + block_number, + _inserted_timestamp, + tx_count, {{ dbt_utils.generate_surrogate_key( ['block_number'] ) }} AS tx_count_id, @@ -35,4 +37,4 @@ SELECT SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id FROM - base \ No newline at end of file + base 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 3def088..3600935 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 = '0xe35e9842fceaca96570b734083f4a58e8f7c5f2a' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -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 c7e1f40..8bdefff 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 = '0xe35e9842fceaca96570b734083f4a58e8f7c5f2a' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( 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 2ae12be..105de25 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,14 +26,11 @@ 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, + tx_hash :: STRING, '-', - event_index + event_index :: STRING ) AS _log_id, modified_timestamp AS _inserted_timestamp FROM @@ -69,14 +66,11 @@ 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, + tx_hash :: STRING, '-', - event_index + event_index :: STRING ) AS _log_id, modified_timestamp AS _inserted_timestamp FROM 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..94f63d0 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 >= ( @@ -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 >= ( @@ -109,10 +125,14 @@ transfers AS ( tx_hash, event_index, contract_address AS token_address, - _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 = '0xce16f69375520ab01377ce7b88f5ba8c48f8d666' AND to_address IN ( 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 0138e41..07b1bcd 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,35 +21,43 @@ 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 IN ( '0xdd90e5e87a2081dcf0391920868ebc2ffb81a1af', '0x1619de6b6b20ed217a58d00f37b9d47c7663feca' ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( 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 b58b996..cbdc476 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 >= ( @@ -112,7 +120,7 @@ SELECT WHEN token_address = '0x0000000000000000000000000000000000000000' THEN LOWER('0x82aF49447D8a07e3bd95BD0d56f35241523fBab1') ELSE token_address END AS token_address, - decoded_flat, + decoded_log AS decoded_flat, order_obj, _log_id, _inserted_timestamp diff --git a/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql b/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql index 269d6da..1a4b4d7 100644 --- a/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql +++ b/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql @@ -20,13 +20,21 @@ WITH base_evt AS ( event_index, topics [0] :: STRING AS topic_0, event_name, - 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 IN ( '0x5566d73d091d945ab32ea023cd1930c0d43aa43bef9aee4cb029775cfc94bdae', @@ -40,7 +48,7 @@ WITH base_evt AS ( --PortalV2 '0xbf0b5d561b986809924f88099c4ff0e6bcce60c9' --PortalV2 ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -65,11 +73,11 @@ requestsent AS ( event_index, topic_0, event_name, - decoded_flat :"chainIdTo" :: STRING AS chainIdTo, - decoded_flat :"data" :: STRING AS data_requestsent, - decoded_flat :"requestId" :: STRING AS requestId, - decoded_flat :"to" :: STRING AS to_address, - decoded_flat, + decoded_log :"chainIdTo" :: STRING AS chainIdTo, + decoded_log :"data" :: STRING AS data_requestsent, + decoded_log :"requestId" :: STRING AS requestId, + decoded_log :"to" :: STRING AS to_address, + decoded_log, event_removed, tx_status, _log_id, @@ -93,12 +101,12 @@ locked AS ( topic_0, event_name, TRY_TO_NUMBER( - decoded_flat :"amount" :: STRING + decoded_log :"amount" :: STRING ) AS amount, - decoded_flat :"from" :: STRING AS from_address, - decoded_flat :"to" :: STRING AS to_address, - decoded_flat :"token" :: STRING AS token, - decoded_flat, + decoded_log :"from" :: STRING AS from_address, + decoded_log :"to" :: STRING AS to_address, + decoded_log :"token" :: STRING AS token, + decoded_log, event_removed, tx_status, _log_id, @@ -136,4 +144,5 @@ FROM block_number, tx_hash ) -WHERE token_address IS NOT NULL +WHERE + token_address IS NOT NULL 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 ff4993b..2cc8bab 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..33b70c0 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 >= ( @@ -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 10d2cf0..a9b8c5b 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/multichain/silver_bridge__multichain_v7_loganyswapout.sql b/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.sql index 369affb..05c814d 100644 --- a/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.sql +++ b/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.sql @@ -21,26 +21,34 @@ 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 :"from" :: STRING AS from_address, - decoded_flat :"receiver" :: STRING AS receiver, - decoded_flat :"swapoutID" :: STRING AS swapoutID, + decoded_log :"from" :: STRING AS from_address, + decoded_log :"receiver" :: STRING AS receiver, + decoded_log :"swapoutID" :: STRING AS swapoutID, TRY_TO_NUMBER( - decoded_flat :"toChainID" :: STRING + decoded_log :"toChainID" :: STRING ) AS toChainID, - decoded_flat :"token" :: STRING AS token, - decoded_flat, + 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 = '0x0d969ae475ff6fcaf0dcfa760d4d8607244e8d95e9bf426f8d5d69f9a3e525af' AND contract_address = '0x1633d66ca91ce4d81f63ea047b7b19beb92df7f3' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _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 63e918c..aa235e8 100644 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql +++ b/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql @@ -29,8 +29,8 @@ WITH base_contracts AS ( WHERE from_address = '0x55bdb4164d28fbaf0898e0ef14a589ac09ac9970' AND TYPE ILIKE 'create%' - 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/bridge/stargate/silver_bridge__stargate_swap.sql b/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql index fa7676d..d54887a 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 >= ( 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 23a468c..ab5ddab 100644 --- a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql +++ b/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql @@ -21,30 +21,38 @@ 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 IN ( '0x0425841529882628880fbd228ac90606e0c2e09a', '0x01a3c8e513b758ebb011f7afaf6c37616c9c24d9' ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( 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 0e4e170..8e44509 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,20 +21,28 @@ 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 IN ( '0xdc5bad4651c5fbe9977a696aadc65996c468cde1448dd468ec0d83bf61c4b57c', @@ -43,7 +51,7 @@ WITH base_evt AS ( ) AND contract_address = '0x6f4e8eba4d337f874ab57478acc2cb5bacdc19c9' AND origin_to_address IS NOT NULL - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( 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 96475fb..4f41711 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 = '0x6f4e8eba4d337f874ab57478acc2cb5bacdc19c9' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( 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 7c4a655..b40ebcd 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/balancer/silver_dex__balancer_pools.sql b/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql index a75e8c4..c5cbd9d 100644 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql +++ b/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql @@ -20,18 +20,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 >= ( @@ -50,8 +54,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, @@ -60,11 +64,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' @@ -74,7 +82,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 a2e8257..09e0c3a 100644 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql +++ b/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql @@ -44,17 +44,21 @@ swaps_base 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, '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 >= ( diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql b/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql index bda36df..b5069c9 100644 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql +++ b/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql @@ -17,10 +17,14 @@ WITH pool_creation AS ( CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, 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 contract_address IN ( '0x6eccab422d763ac031210895c81787e87b43a652', @@ -33,7 +37,7 @@ WITH pool_creation AS ( --PairCreated v2 '0x91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db' ) --v3 - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.sql b/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.sql index 785b212..a281536 100644 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.sql +++ b/models/silver/defi/dex/camelot/silver_dex__camelot_v2_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/camelot/silver_dex__camelot_v3_swaps.sql b/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.sql index 6c6f4ad..63e3dd2 100644 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.sql +++ b/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.sql @@ -68,15 +68,20 @@ swaps_base AS ( WHEN amount0 > 0 THEN token0 ELSE token1 END AS token_out, - _log_id, - _inserted_timestamp + 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 INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - 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 270aec9..fcf43a2 100644 --- a/models/silver/defi/dex/curve/silver_dex__curve_pools.sql +++ b/models/silver/defi/dex/curve/silver_dex__curve_pools.sql @@ -42,8 +42,8 @@ WITH contract_deployments AS ( '0xb17b674d9c5cb2e441f8e196a2f048a81355d031' ) AND TYPE ILIKE 'create%' - 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 e5ac4fe..84de21c 100644 --- a/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql +++ b/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql @@ -13,20 +13,20 @@ WITH pool_meta AS ( pool_name, token_address, pool_symbol AS symbol, - token_id::INTEGER AS token_id, - token_type::STRING AS token_type + token_id :: INTEGER AS token_id, + token_type :: STRING AS token_type FROM {{ ref('silver_dex__curve_pools') }} ), - pools AS ( - SELECT + SELECT DISTINCT pool_address, pool_name - FROM pool_meta - QUALIFY (ROW_NUMBER() OVER (PARTITION BY pool_address ORDER BY pool_name ASC NULLS LAST)) = 1 + FROM + pool_meta qualify (ROW_NUMBER() over (PARTITION BY pool_address + ORDER BY + pool_name ASC nulls last)) = 1 ), - curve_base AS ( SELECT block_number, @@ -45,22 +45,35 @@ curve_base AS ( pool_name, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - TRY_TO_NUMBER(utils.udf_hex_to_int( - segmented_data [0] :: STRING - )) AS sold_id, - TRY_TO_NUMBER(utils.udf_hex_to_int( - segmented_data [1] :: STRING - )) AS tokens_sold, - TRY_TO_NUMBER(utils.udf_hex_to_int( - segmented_data [2] :: STRING - )) AS bought_id, - TRY_TO_NUMBER(utils.udf_hex_to_int( - segmented_data [3] :: STRING - )) AS tokens_bought, - _log_id, - _inserted_timestamp + TRY_TO_NUMBER( + utils.udf_hex_to_int( + segmented_data [0] :: STRING + ) + ) AS sold_id, + TRY_TO_NUMBER( + utils.udf_hex_to_int( + segmented_data [1] :: STRING + ) + ) AS tokens_sold, + TRY_TO_NUMBER( + utils.udf_hex_to_int( + segmented_data [2] :: STRING + ) + ) AS bought_id, + TRY_TO_NUMBER( + utils.udf_hex_to_int( + segmented_data [3] :: STRING + ) + ) AS tokens_bought, + 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 INNER JOIN pools p ON p.pool_address = l.contract_address WHERE @@ -69,7 +82,7 @@ curve_base AS ( '0xb2e76ae99761dc136e598d4a629bb347eccb9532a5f8bbd72e18467c3c34cc98', '0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b' ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -81,21 +94,42 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), - token_exchange AS ( - -SELECT - _log_id, - MAX(CASE WHEN sold_id = token_id THEN token_address END) AS token_in, - MAX(CASE WHEN bought_id = token_id THEN token_address END) AS token_out, - MAX(CASE WHEN sold_id = token_id THEN symbol END) AS symbol_in, - MAX(CASE WHEN bought_id = token_id THEN symbol END) AS symbol_out -FROM curve_base t -LEFT JOIN pool_meta p ON p.pool_address = t.pool_address AND (p.token_id = t.sold_id OR p.token_id = t.bought_id) -WHERE token_type = 'coins' -GROUP BY 1 + SELECT + _log_id, + MAX( + CASE + WHEN sold_id = token_id THEN token_address + END + ) AS token_in, + MAX( + CASE + WHEN bought_id = token_id THEN token_address + END + ) AS token_out, + MAX( + CASE + WHEN sold_id = token_id THEN symbol + END + ) AS symbol_in, + MAX( + CASE + WHEN bought_id = token_id THEN symbol + END + ) AS symbol_out + FROM + curve_base t + LEFT JOIN pool_meta p + ON p.pool_address = t.pool_address + AND ( + p.token_id = t.sold_id + OR p.token_id = t.bought_id + ) + WHERE + token_type = 'coins' + GROUP BY + 1 ), - token_transfers AS ( SELECT tx_hash, @@ -108,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 ( @@ -120,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 ( @@ -147,49 +181,52 @@ to_transfers AS ( FROM token_transfers ), - ready_pool_info AS ( - -SELECT - s.block_number, - s.block_timestamp, - s.tx_hash, - s.origin_function_signature, - s.origin_from_address, - s.origin_from_address AS tx_to, - s.origin_to_address, - event_index, - event_name, - pool_address, - pool_address AS contract_address, - pool_name, - sender, - sold_id, - tokens_sold, - COALESCE(sold.token_address,e.token_in) AS token_in, - e.symbol_in AS symbol_in, - bought_id, - tokens_bought, - COALESCE(bought.token_address,e.token_out) AS token_out, - e.symbol_out AS symbol_out, - s._log_id, - _inserted_timestamp -FROM - curve_base s - LEFT JOIN token_exchange e ON s._log_id = e._log_id - LEFT JOIN from_transfers sold - ON tokens_sold = sold.amount - AND s.tx_hash = sold.tx_hash - LEFT JOIN to_transfers bought - ON tokens_bought = bought.amount - AND s.tx_hash = bought.tx_hash -WHERE - tokens_sold <> 0 -qualify(ROW_NUMBER() over(PARTITION BY s._log_id + SELECT + s.block_number, + s.block_timestamp, + s.tx_hash, + s.origin_function_signature, + s.origin_from_address, + s.origin_from_address AS tx_to, + s.origin_to_address, + event_index, + event_name, + pool_address, + pool_address AS contract_address, + pool_name, + sender, + sold_id, + tokens_sold, + COALESCE( + sold.token_address, + e.token_in + ) AS token_in, + e.symbol_in AS symbol_in, + bought_id, + tokens_bought, + COALESCE( + bought.token_address, + e.token_out + ) AS token_out, + e.symbol_out AS symbol_out, + s._log_id, + _inserted_timestamp + FROM + curve_base s + LEFT JOIN token_exchange e + ON s._log_id = e._log_id + LEFT JOIN from_transfers sold + ON tokens_sold = sold.amount + AND s.tx_hash = sold.tx_hash + LEFT JOIN to_transfers bought + ON tokens_bought = bought.amount + AND s.tx_hash = bought.tx_hash + WHERE + tokens_sold <> 0 qualify(ROW_NUMBER() over(PARTITION BY s._log_id ORDER BY - _inserted_timestamp DESC)) = 1 + _inserted_timestamp DESC)) = 1 ) - SELECT block_number, block_timestamp, @@ -216,4 +253,4 @@ SELECT _inserted_timestamp, 'curve' AS platform FROM - ready_pool_info \ No newline at end of file + ready_pool_info diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql index 3c79a33..6b01c2a 100644 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql +++ b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql @@ -17,14 +17,18 @@ WITH pool_events AS ( CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS newBorn, CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS baseToken, CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS quoteToken, - _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 = '0xbcc3401e16c25eaf4d3fed632ce3288503883b1f' --DODOZoo AND topics [0] :: STRING = '0x5c428a2e12ecaa744a080b25b4cda8b86359c82d726575d7d747e07708071f93' --DODOBirth - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql index 9f3ee73..bd9d21f 100644 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql +++ b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql @@ -12,8 +12,9 @@ WITH pools AS ( pool_address, base_token, quote_token - FROM {{ ref('silver_dex__dodo_v1_pools') }} -), + FROM + {{ ref('silver_dex__dodo_v1_pools') }} +), proxies AS ( SELECT '0xd5a7e197bace1f3b26e2760321d6ce06ad07281a' AS proxy_address @@ -49,10 +50,14 @@ sell_base_token AS ( base_token AS tokenOut, receiveQuote AS amountIn, payBase AS amountOut, - 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 p ON p.pool_address = l.contract_address @@ -64,7 +69,7 @@ sell_base_token AS ( FROM proxies ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -104,10 +109,14 @@ buy_base_token AS ( base_token AS tokenOut, payQuote AS amountIn, receiveBase AS amountOut, - 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 p ON p.pool_address = l.contract_address @@ -119,7 +128,7 @@ buy_base_token AS ( FROM proxies ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql index 6e5ae50..aa61519 100644 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql +++ b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql @@ -18,10 +18,14 @@ WITH pools AS ( CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS quoteToken, CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS creator, CONCAT('0x', SUBSTR(segmented_data [3] :: 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 contract_address IN ( '0xa6cf3d163358af376ec5e8b7cc5e102a05fde63d', @@ -42,7 +46,7 @@ WITH pools AS ( --NewDSP '0xaf5c5f12a80fc937520df6fcaed66262a4cc775e0f3fceaf7a7cfe476d9a751d' --NewDVM ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql index 2f529ea..a7497ed 100644 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql +++ b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql @@ -73,14 +73,17 @@ swaps_base AS ( 40 ) ) AS receiver_address, - 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 p - ON - l.contract_address = p.pool_address + INNER JOIN pools p + ON l.contract_address = p.pool_address WHERE l.topics [0] :: STRING = '0xc2c0245e056d5fb095f04cd6373bc770802ebd1e6c918eb78fdef843cdb37b0f' --dodoswap AND trader_address NOT IN ( @@ -89,7 +92,7 @@ swaps_base AS ( FROM proxies ) - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql index 6007e3c..a67dc86 100644 --- a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql +++ b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql @@ -20,10 +20,14 @@ 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 IN ( '0x5ca135cb8527d76e932f34b5145575f9d8cbe08e', @@ -31,7 +35,7 @@ WITH pool_creation AS ( '0x8374a74a728f06bea6b7259c68aa7bbb732bfead' --v2 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/fraxswap/silver_dex__fraxswap_swaps.sql b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.sql index f758c59..6d75234 100644 --- a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.sql +++ b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.sql @@ -50,16 +50,20 @@ swaps_base AS ( ) AS amount1Out, token0, token1, - 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 = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' --Swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -116,4 +120,5 @@ SELECT _inserted_timestamp FROM swaps_base -WHERE token_in <> token_out \ No newline at end of file +WHERE + token_in <> token_out diff --git a/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.sql b/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.sql index 6d31665..f0f086f 100644 --- a/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.sql +++ b/models/silver/defi/dex/gmx/silver_dex__gmx_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 = '0x489ee077994b6658eafa855c308275ead8097c4a' AND topics [0] :: STRING = '0x0874b2d545cb271cdbda4e093020c452328b24af12382ed62c4d00f5c26709db' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql index d5f24dd..4f9c18a 100644 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql +++ b/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql @@ -33,8 +33,8 @@ WITH contract_deployments AS ( '0x75fb2ab4d5b0de8b1a1acdc9124887d35d459084' ) AND TYPE ILIKE 'create%' - 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/hashflow/silver_dex__hashflow_swaps.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.sql index 9a8e347..11aba9f 100644 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.sql +++ b/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.sql @@ -58,16 +58,20 @@ router_swaps_base AS ( l_segmented_data [6] :: STRING ) ) AS amountOut, - 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 p ON l.contract_address = p.pool_address WHERE l.topics [0] :: STRING = '0xb709ddcc6550418e9b89df1f4938071eeaa3f6376309904c77e15d46b16066f5' --swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -124,16 +128,20 @@ swaps_base AS ( l_segmented_data [5] :: STRING ) ) AS amountOut, - 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 p ON l.contract_address = p.pool_address WHERE l.topics [0] :: STRING = '0x8cf3dec1929508e5677d7db003124e74802bfba7250a572205a9986d86ca9f1e' --swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql index 159ae40..0e512ff 100644 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql +++ b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql @@ -14,14 +14,18 @@ WITH contract_deployments AS ( regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, origin_from_address AS deployer_address, 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 contract_address = LOWER('0xdE828fdc3F497F16416D1bB645261C7C6a62DAb5') AND topics [0] :: STRING = '0xdbd2a1ea6808362e6adbec4db4969cbc11e3b0b28fb6c74cb342defaaf1daada' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql index dad380c..2058b5e 100644 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql +++ b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql @@ -42,16 +42,20 @@ swaps AS ( segmented_data [6] :: STRING ) ) AS amountOut, - _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 l.contract_address = p.pool_address WHERE l.topics [0] :: STRING = '0x34f57786fb01682fb4eec88d340387ef01a168fe345ea5b76f709d4e560c10eb' --Trade - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql index 0fea2e3..12e23ad 100644 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql +++ b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql @@ -27,14 +27,18 @@ WITH pool_creation AS ( segmented_data [2] :: STRING ) ) AS totalPool, - _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('0xD9bfE9979e9CA4b2fe84bA5d4Cf963bBcB376974') --dynamic fee factory AND topics [0] :: STRING = '0xfc574402c445e75f2b79b67884ff9c662244dce454c5ae68935fcd0bebb7c8ff' --created pool - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql index fca6cf8..05178b9 100644 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql +++ b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql @@ -55,16 +55,20 @@ swaps_base AS ( ) AS feeInPrecision, token0, token1, - 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 p ON p.pool_address = l.contract_address WHERE l.topics [0] :: STRING = '0x606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c2499' --Dynamic Swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql index 8acdb26..0c34829 100644 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql +++ b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql @@ -32,14 +32,18 @@ WITH pool_creation AS ( segmented_data [3] :: STRING ) ) AS totalPool, - _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('0x1c758aF0688502e49140230F6b0EBd376d429be5') --static pool factory AND topics [0] :: STRING = '0xb6bce363b712c921bead4bcc977289440eb6172eb89e258e3a25bd49ca806de6' --create pool - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql index dcbda64..f5d327b 100644 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql +++ b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql @@ -55,16 +55,20 @@ swaps_base AS ( ) AS feeInPrecision, token0, token1, - 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 p ON p.pool_address = l.contract_address WHERE l.topics [0] :: STRING = '0x606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c2499' -- static swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql index 1406c20..c154c05 100644 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql +++ b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql @@ -23,17 +23,21 @@ WITH pool_creation AS ( ) ) AS tickDistance, 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 contract_address IN ( '0x5f1dddbf348ac2fbe22a163e30f99f9ece3dd50a', '0xc7a590291e07b9fe9e64b86c58fd8fc764308c4a' ) --KyberSwap: Elastic Factory AND topics [0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' --Create pool - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql index 24ab80e..c3a45ef 100644 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql +++ b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql @@ -68,16 +68,20 @@ swaps_base AS ( WHEN deltaQty0 > 0 THEN token0 ELSE token1 END AS token_out, - 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 p ON p.pool_address = l.contract_address WHERE topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' -- elastic swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql index 9b295a9..627bd0f 100644 --- a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql +++ b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql @@ -25,14 +25,19 @@ 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 = lower('0xAA2cd7477c451E703f3B9Ba5663334914763edF8') - AND tx_status = 'SUCCESS' + AND contract_address = LOWER('0xAA2cd7477c451E703f3B9Ba5663334914763edF8') + AND tx_succeeded + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -54,21 +59,21 @@ initial_info AS ( init_tick ) AS init_price_1_0_unadj 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 >= ( +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 AS ( SELECT created_block, @@ -94,7 +99,6 @@ FINAL AS ( LEFT JOIN initial_info i ON p.pool_address = i.contract_address ) - SELECT * FROM diff --git a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql index e94c51b..eda6a2e 100644 --- a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql +++ b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql @@ -34,19 +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 ( @@ -75,8 +76,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/sparta/silver_dex__sparta_pools.sql b/models/silver/defi/dex/sparta/silver_dex__sparta_pools.sql index 322bfca..2d788a9 100644 --- a/models/silver/defi/dex/sparta/silver_dex__sparta_pools.sql +++ b/models/silver/defi/dex/sparta/silver_dex__sparta_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('0xFe8EC10Fe07A6a6f4A2584f8cD9FE232930eAF55') 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/sparta/silver_dex__sparta_swaps.sql b/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.sql index 47e8a4e..cc092c2 100644 --- a/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.sql +++ b/models/silver/defi/dex/sparta/silver_dex__sparta_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/sushi/silver_dex__sushi_pools.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql index 3cfa358..f59ae12 100644 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql +++ b/models/silver/defi/dex/sushi/silver_dex__sushi_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('0xc35DADB65012eC5796536bD9864eD8773aBc74C4') 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/sushi/silver_dex__sushi_swaps.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql index 230d0ad..e985fbe 100644 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql +++ b/models/silver/defi/dex/sushi/silver_dex__sushi_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/trader_joe/silver_dex__trader_joe_v1_pools.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.sql index a5991ba..587d245 100644 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.sql +++ b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_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('0xae4ec9901c3076d0ddbe76a520f9e90a6227acb7') 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/trader_joe/silver_dex__trader_joe_v1_swaps.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.sql index cbc581a..60d6ca7 100644 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.sql +++ b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.sql @@ -50,16 +50,20 @@ swaps_base AS ( ) AS amount1Out, token0, token1, - 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 p ON p.pool_address = l.contract_address WHERE l.topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' --Swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -90,8 +94,8 @@ SELECT token1, CASE WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In + AND amount1In <> 0 + AND amount0Out <> 0 THEN amount1In WHEN amount0In <> 0 THEN amount0In WHEN amount1In <> 0 THEN amount1In END AS amount_in_unadj, @@ -101,8 +105,8 @@ SELECT END AS amount_out_unadj, CASE WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 + AND amount1In <> 0 + AND amount0Out <> 0 THEN token1 WHEN amount0In <> 0 THEN token0 WHEN amount1In <> 0 THEN token1 END AS token_in, @@ -116,4 +120,5 @@ SELECT _inserted_timestamp FROM swaps_base -WHERE token_in <> token_out +WHERE + token_in <> token_out diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql index 7a040f6..b2a6429 100644 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql +++ b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql @@ -72,16 +72,20 @@ swaps_base AS ( tokenX, tokenY, p.version, - 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 p ON lb_pair = l.contract_address WHERE topics [0] :: STRING = '0xad7d6f97abf51ce18e17a38f4d70e975be9c0708474987bb3e26ad21bd93ca70' --Swap - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql index 0d69c9e..85004b9 100644 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql +++ b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql @@ -28,10 +28,14 @@ WITH pool_creation AS ( WHEN contract_address = '0xb43120c4745967fa9b93e79c149e66b0f2d6fe0c' THEN 'v2.2' ELSE 'v2.1' END AS version, - _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 IN ( '0x1886d09c9ade0c5db822d85d21678db67b6c2982', @@ -45,7 +49,7 @@ WITH pool_creation AS ( '0xb43120c4745967fa9b93e79c149e66b0f2d6fe0c' --v2.2 ) AND topics [0] :: STRING = '0x2c8d104b27c6b7f4492017a6f5cf3803043688934ebcaa6a03540beeaf976aff' --LB PairCreated - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql index 1fb6c97..4aea802 100644 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql +++ b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql @@ -69,16 +69,20 @@ swaps_base AS ( WHEN swapForY THEN tokenX ELSE tokenY END AS token_in_address, - 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 p ON lb_pair = l.contract_address WHERE topics [0] :: STRING = '0xc528cda9e500228b16ce84fadae290d9a49aecb17483110004c5af0a07f6fd73' --Swap - 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 f727e47..82083a4 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('0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9') 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 c42dc85..0cda2a0 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,19 @@ 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 = '0x1f98431c8ad98523631ae4a59f267346ea31f984' - AND tx_status = 'SUCCESS' + AND tx_succeeded + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -54,21 +59,21 @@ initial_info AS ( init_tick ) AS init_price_1_0_unadj 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 >= ( +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 AS ( SELECT created_block, @@ -94,7 +99,6 @@ FINAL AS ( LEFT JOIN initial_info i ON p.pool_address = i.contract_address ) - SELECT * FROM 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 5b74550..347791c 100644 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql +++ b/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql @@ -34,20 +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 ( @@ -76,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/woofi/silver_dex__woofi_swaps.sql b/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql index a09336a..3955790 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 ( '0xb130a49065178465931d4f887056328cea5d723f' ) --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/dex/zyberswap/silver_dex__zyberswap_pools.sql b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.sql index a7211cd..2ce072b 100644 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.sql +++ b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.sql @@ -17,10 +17,14 @@ WITH pool_creation AS ( CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, 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 contract_address IN ( '0xac2ee06a14c52570ef3b9812ed240bce359772e7', @@ -32,7 +36,7 @@ WITH pool_creation AS ( --PairCreated v2 '0x91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db' ) --v3 - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.sql b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.sql index 40675e8..b51378e 100644 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.sql +++ b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_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/zyberswap/silver_dex__zyberswap_v3_swaps.sql b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.sql index e2ff719..be4397a 100644 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.sql +++ b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.sql @@ -68,15 +68,20 @@ swaps_base AS ( WHEN amount0 > 0 THEN token0 ELSE token1 END AS token_out, - _log_id, - _inserted_timestamp + 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 INNER JOIN pools p ON p.pool_address = contract_address WHERE topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - 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 8c93ae2..8d2a495 100644 --- a/models/silver/defi/lending/aave/silver__aave_borrows.sql +++ b/models/silver/defi/lending/aave/silver__aave_borrows.sql @@ -43,12 +43,17 @@ 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -59,7 +64,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') -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 38ec4d6..ede9795 100644 --- a/models/silver/defi/lending/aave/silver__aave_deposits.sql +++ b/models/silver/defi/lending/aave/silver__aave_deposits.sql @@ -36,12 +36,17 @@ 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -52,7 +57,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') -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 5c62aae..42a7e08 100644 --- a/models/silver/defi/lending/aave/silver__aave_flashloans.sql +++ b/models/silver/defi/lending/aave/silver__aave_flashloans.sql @@ -38,12 +38,17 @@ WITH flashloan AS ( WHEN contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -54,7 +59,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') -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 5938644..ed99434 100644 --- a/models/silver/defi/lending/aave/silver__aave_liquidations.sql +++ b/models/silver/defi/lending/aave/silver__aave_liquidations.sql @@ -36,12 +36,17 @@ 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -52,7 +57,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') -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 d4730a0..04eaa6c 100644 --- a/models/silver/defi/lending/aave/silver__aave_repayments.sql +++ b/models/silver/defi/lending/aave/silver__aave_repayments.sql @@ -33,12 +33,17 @@ 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -49,7 +54,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') -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 a6356a4..3fff749 100644 --- a/models/silver/defi/lending/aave/silver__aave_tokens.sql +++ b/models/silver/defi/lending/aave/silver__aave_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 ( @@ -122,10 +130,11 @@ SELECT C.token_name AS underlying_name, A._inserted_timestamp, A._log_id -FROM a_token_step_2 A +FROM + a_token_step_2 A INNER JOIN debt_tokens b ON A.a_token_address = b.atoken_address 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 d057eb9..cf633a4 100644 --- a/models/silver/defi/lending/aave/silver__aave_withdraws.sql +++ b/models/silver/defi/lending/aave/silver__aave_withdraws.sql @@ -32,12 +32,17 @@ 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -48,7 +53,7 @@ AND _inserted_timestamp >= ( AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} AND contract_address = LOWER('0x794a61358D6845594F94dc1DB02A252b5b4814aD') -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 8c518bd..a603e9b 100644 --- a/models/silver/defi/lending/compound/silver__comp_borrows.sql +++ b/models/silver/defi/lending/compound/silver__comp_borrows.sql @@ -32,10 +32,14 @@ WITH borrow AS ( C.underlying_asset_address, C.underlying_asset_symbol, 'arbitrum' 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__comp_asset_details') }} C ON asset = C.compound_market_address @@ -45,16 +49,16 @@ WITH borrow AS ( LOWER('0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA'), LOWER('0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf') ) - AND tx_status = 'SUCCESS' + 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 7e2f750..9cb83f8 100644 --- a/models/silver/defi/lending/compound/silver__comp_deposits.sql +++ b/models/silver/defi/lending/compound/silver__comp_deposits.sql @@ -30,25 +30,29 @@ WITH supply AS ( C.token_symbol, C.token_decimals, 'arbitrum' 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 tx_status = 'SUCCESS' + 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 039526a..ed96690 100644 --- a/models/silver/defi/lending/compound/silver__comp_liquidations.sql +++ b/models/silver/defi/lending/compound/silver__comp_liquidations.sql @@ -34,25 +34,29 @@ WITH liquidations AS ( C.token_symbol, C.token_decimals, 'arbitrum' 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 tx_status = 'SUCCESS' + 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 7d8824d..834c829 100644 --- a/models/silver/defi/lending/compound/silver__comp_repayments.sql +++ b/models/silver/defi/lending/compound/silver__comp_repayments.sql @@ -35,10 +35,14 @@ WITH repayments AS ( C.underlying_asset_address AS underlying_asset, C.underlying_asset_symbol, 'arbitrum' 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__comp_asset_details') }} C ON contract_address = C.compound_market_address @@ -48,16 +52,16 @@ WITH repayments AS ( LOWER('0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA'), LOWER('0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf') ) - AND tx_status = 'SUCCESS' + 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 995796f..a6c7ad9 100644 --- a/models/silver/defi/lending/compound/silver__comp_withdraws.sql +++ b/models/silver/defi/lending/compound/silver__comp_withdraws.sql @@ -29,25 +29,29 @@ WITH withdraw AS ( C.token_symbol, C.token_decimals, 'arbitrum' 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 tx_status = 'SUCCESS' + 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/dforce/silver__dforce_asset_details.sql b/models/silver/defi/lending/dforce/silver__dforce_asset_details.sql index 78f7f35..a5f4426 100644 --- a/models/silver/defi/lending/dforce/silver__dforce_asset_details.sql +++ b/models/silver/defi/lending/dforce/silver__dforce_asset_details.sql @@ -13,10 +13,14 @@ WITH log_pull AS ( block_number, block_timestamp, contract_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] :: STRING = '0x70aea8d848e8a90fb7661b227dc522eb6395c3dac71b63cb59edd5c9899b2364' AND origin_from_address IN ( diff --git a/models/silver/defi/lending/dforce/silver__dforce_borrows.sql b/models/silver/defi/lending/dforce/silver__dforce_borrows.sql index fe32a38..60e947f 100644 --- a/models/silver/defi/lending/dforce/silver__dforce_borrows.sql +++ b/models/silver/defi/lending/dforce/silver__dforce_borrows.sql @@ -43,10 +43,14 @@ dforce_borrows AS ( ) :: INTEGER AS totalBorrows, contract_address AS token, 'dForce' 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 @@ dforce_borrows AS ( asset_details ) AND topics [0] :: STRING = '0x2dd79f4fccfd18c360ce7f9132f3621bf05eee18f995224badb32d17f172df73' - 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/dforce/silver__dforce_deposits.sql b/models/silver/defi/lending/dforce/silver__dforce_deposits.sql index 3d32483..7cfba37 100644 --- a/models/silver/defi/lending/dforce/silver__dforce_deposits.sql +++ b/models/silver/defi/lending/dforce/silver__dforce_deposits.sql @@ -40,10 +40,14 @@ dforce_deposits AS ( ) :: INTEGER AS mintAmount_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier, 'dForce' 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 @@ dforce_deposits AS ( asset_details ) AND topics [0] :: STRING = '0x2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/dforce/silver__dforce_liquidations.sql b/models/silver/defi/lending/dforce/silver__dforce_liquidations.sql index c74a359..d6ff57d 100644 --- a/models/silver/defi/lending/dforce/silver__dforce_liquidations.sql +++ b/models/silver/defi/lending/dforce/silver__dforce_liquidations.sql @@ -43,10 +43,14 @@ dforce_liquidations AS ( ) :: INTEGER AS repayAmount_raw, CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS tokenCollateral, 'dForce' 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 @@ dforce_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/dforce/silver__dforce_repayments.sql b/models/silver/defi/lending/dforce/silver__dforce_repayments.sql index 7196379..1741015 100644 --- a/models/silver/defi/lending/dforce/silver__dforce_repayments.sql +++ b/models/silver/defi/lending/dforce/silver__dforce_repayments.sql @@ -38,10 +38,14 @@ dforce_repayments AS ( segmented_data [2] :: STRING ) :: INTEGER AS repayed_amount_raw, 'dForce' 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 @@ dforce_repayments AS ( asset_details ) AND topics [0] :: STRING = '0x6fadbf7329d21f278e724fa0d4511001a158f2a97ee35c5bc4cf8b64417399ef' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/dforce/silver__dforce_withdraws.sql b/models/silver/defi/lending/dforce/silver__dforce_withdraws.sql index 143c25a..00f1427 100644 --- a/models/silver/defi/lending/dforce/silver__dforce_withdraws.sql +++ b/models/silver/defi/lending/dforce/silver__dforce_withdraws.sql @@ -40,10 +40,14 @@ dforce_redemptions AS ( ) :: INTEGER AS redeemed_token_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer, 'dForce' 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,8 @@ dforce_redemptions AS ( asset_details ) AND topics [0] :: STRING = '0x3f693fff038bb8a046aa76d9516190ac7444f7d69cf952c4cbdc086fdef2d6fc' - AND tx_status = 'SUCCESS' + AND tx_succeeded + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -99,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/lodestar/silver__lodestar_asset_details.sql b/models/silver/defi/lending/lodestar/silver__lodestar_asset_details.sql index e3694e4..2a3114c 100644 --- a/models/silver/defi/lending/lodestar/silver__lodestar_asset_details.sql +++ b/models/silver/defi/lending/lodestar/silver__lodestar_asset_details.sql @@ -13,10 +13,14 @@ WITH log_pull AS ( block_number, block_timestamp, contract_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') }} l WHERE topics [0] = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d' @@ -45,7 +49,8 @@ traces_pull AS ( FROM log_pull ) - AND identifier = 'STATICCALL_0_2' + AND TYPE = 'STATICCALL' + AND trace_address = '0_2' {% if is_incremental() %} AND modified_timestamp >= ( diff --git a/models/silver/defi/lending/lodestar/silver__lodestar_borrows.sql b/models/silver/defi/lending/lodestar/silver__lodestar_borrows.sql index fa2f44f..9c518e4 100644 --- a/models/silver/defi/lending/lodestar/silver__lodestar_borrows.sql +++ b/models/silver/defi/lending/lodestar/silver__lodestar_borrows.sql @@ -43,10 +43,14 @@ lodestar_borrows AS ( ) :: INTEGER AS totalBorrows, contract_address AS itoken, 'Lodestar' 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 @@ lodestar_borrows AS ( asset_details ) AND topics [0] :: STRING = '0x2dd79f4fccfd18c360ce7f9132f3621bf05eee18f995224badb32d17f172df73' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( diff --git a/models/silver/defi/lending/lodestar/silver__lodestar_deposits.sql b/models/silver/defi/lending/lodestar/silver__lodestar_deposits.sql index f6142d8..51e39b9 100644 --- a/models/silver/defi/lending/lodestar/silver__lodestar_deposits.sql +++ b/models/silver/defi/lending/lodestar/silver__lodestar_deposits.sql @@ -40,10 +40,14 @@ lodestar_deposits AS ( ) :: INTEGER AS mintAmount_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier, 'Lodestar' 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 @@ lodestar_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/lodestar/silver__lodestar_liquidations.sql b/models/silver/defi/lending/lodestar/silver__lodestar_liquidations.sql index bd5091a..3325e43 100644 --- a/models/silver/defi/lending/lodestar/silver__lodestar_liquidations.sql +++ b/models/silver/defi/lending/lodestar/silver__lodestar_liquidations.sql @@ -43,10 +43,14 @@ lodestar_liquidations AS ( ) :: INTEGER AS repayAmount_raw, CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS itokenCollateral, 'Lodestar' 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 @@ lodestar_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/lodestar/silver__lodestar_repayments.sql b/models/silver/defi/lending/lodestar/silver__lodestar_repayments.sql index c9320b2..8073455 100644 --- a/models/silver/defi/lending/lodestar/silver__lodestar_repayments.sql +++ b/models/silver/defi/lending/lodestar/silver__lodestar_repayments.sql @@ -38,10 +38,14 @@ lodestar_repayments AS ( segmented_data [2] :: STRING ) :: INTEGER AS repayed_amount_raw, 'Lodestar' 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 @@ lodestar_repayments AS ( asset_details ) AND topics [0] :: STRING = '0x6fadbf7329d21f278e724fa0d4511001a158f2a97ee35c5bc4cf8b64417399ef' - AND tx_status = 'SUCCESS' + AND tx_succeeded {% if is_incremental() %} AND _inserted_timestamp >= ( @@ -86,7 +90,7 @@ lodestar_combine AS ( b._inserted_timestamp FROM lodestar_repayments b - LEFT JOIN asset_details c + LEFT JOIN asset_details C ON b.itoken = C.itoken_address ) SELECT diff --git a/models/silver/defi/lending/lodestar/silver__lodestar_withdraws.sql b/models/silver/defi/lending/lodestar/silver__lodestar_withdraws.sql index 336ad1d..dee32b9 100644 --- a/models/silver/defi/lending/lodestar/silver__lodestar_withdraws.sql +++ b/models/silver/defi/lending/lodestar/silver__lodestar_withdraws.sql @@ -40,10 +40,14 @@ lodestar_redemptions AS ( ) :: INTEGER AS redeemed_itoken_raw, CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer, 'Lodestar' 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,8 @@ lodestar_redemptions AS ( asset_details ) AND topics [0] :: STRING = '0xe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929' - AND tx_status = 'SUCCESS' + AND tx_succeeded + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -87,7 +92,7 @@ lodestar_combine AS ( b._inserted_timestamp FROM lodestar_redemptions b - LEFT JOIN asset_details c + LEFT JOIN asset_details C ON b.itoken = C.itoken_address ) SELECT diff --git a/models/silver/defi/lending/radiant/silver__radiant_borrows.sql b/models/silver/defi/lending/radiant/silver__radiant_borrows.sql index 82f0202..7728620 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_borrows.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_borrows.sql @@ -39,17 +39,22 @@ 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 = '0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b' AND contract_address IN ( LOWER('0x2032b9A8e9F7e76768CA9271003d3e43E1616B1F'), LOWER('0xF4B1486DD74D07706052A33d31d7c0AAFD0659E1') ) - AND tx_status = 'SUCCESS' --excludes failed txs + AND tx_succeeded + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT diff --git a/models/silver/defi/lending/radiant/silver__radiant_deposits.sql b/models/silver/defi/lending/radiant/silver__radiant_deposits.sql index bde2af9..4508eb0 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_deposits.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_deposits.sql @@ -32,12 +32,17 @@ WITH deposits AS( origin_to_address, contract_address ) AS lending_pool_contract, - _log_id, - _inserted_timestamp + 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -51,7 +56,7 @@ AND contract_address IN ( LOWER('0x2032b9A8e9F7e76768CA9271003d3e43E1616B1F'), LOWER('0xF4B1486DD74D07706052A33d31d7c0AAFD0659E1') ) -AND tx_status = 'SUCCESS' +AND tx_succeeded AND radiant_market <> LOWER('0xA130A97c841ffA12CFb5E3AEA503fD5825a39bA6') --weird one supply token deposit, just excluding as causing errors up in complete tables ), atoken_meta AS ( diff --git a/models/silver/defi/lending/radiant/silver__radiant_flashloans.sql b/models/silver/defi/lending/radiant/silver__radiant_flashloans.sql index cb9c08b..119712f 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_flashloans.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_flashloans.sql @@ -34,12 +34,17 @@ WITH flashloan AS ( origin_to_address, contract_address ) AS lending_pool_contract, - _log_id, - _inserted_timestamp + 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -53,7 +58,7 @@ AND contract_address IN ( LOWER('0x2032b9A8e9F7e76768CA9271003d3e43E1616B1F'), LOWER('0xF4B1486DD74D07706052A33d31d7c0AAFD0659E1') ) -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/radiant/silver__radiant_liquidations.sql b/models/silver/defi/lending/radiant/silver__radiant_liquidations.sql index 15b5680..5d61231 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_liquidations.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_liquidations.sql @@ -32,12 +32,17 @@ WITH liquidation AS( origin_to_address, contract_address ) AS lending_pool_contract, - _log_id, - _inserted_timestamp + 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 = '0xe76026d190f8c969db64638eaf9bc7087a3758e7fe58c017135a5051b4d7c4f8' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -51,7 +56,7 @@ AND contract_address IN ( LOWER('0x2032b9A8e9F7e76768CA9271003d3e43E1616B1F'), LOWER('0xF4B1486DD74D07706052A33d31d7c0AAFD0659E1') ) -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/radiant/silver__radiant_repayments.sql b/models/silver/defi/lending/radiant/silver__radiant_repayments.sql index 3fc37f3..ddb2214 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_repayments.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_repayments.sql @@ -29,12 +29,17 @@ WITH repay AS( contract_address ) AS lending_pool_contract, origin_from_address AS repayer_address, - _log_id, - _inserted_timestamp + 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 = '0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -48,7 +53,7 @@ AND contract_address IN ( LOWER('0x2032b9A8e9F7e76768CA9271003d3e43E1616B1F'), LOWER('0xF4B1486DD74D07706052A33d31d7c0AAFD0659E1') ) -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/radiant/silver__radiant_tokens.sql b/models/silver/defi/lending/radiant/silver__radiant_tokens.sql index 9203791..400cdfd 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_tokens.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_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 ( @@ -132,4 +140,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/radiant/silver__radiant_withdraws.sql b/models/silver/defi/lending/radiant/silver__radiant_withdraws.sql index 3b3ad7b..f244aac 100644 --- a/models/silver/defi/lending/radiant/silver__radiant_withdraws.sql +++ b/models/silver/defi/lending/radiant/silver__radiant_withdraws.sql @@ -28,12 +28,17 @@ 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' + {% if is_incremental() %} AND _inserted_timestamp >= ( SELECT @@ -47,7 +52,7 @@ AND contract_address IN ( LOWER('0x2032b9A8e9F7e76768CA9271003d3e43E1616B1F'), LOWER('0xF4B1486DD74D07706052A33d31d7c0AAFD0659E1') ) -AND tx_status = 'SUCCESS' --excludes failed txs +AND tx_succeeded ), atoken_meta AS ( SELECT diff --git a/models/silver/defi/lending/silo/silver__silo_borrows.sql b/models/silver/defi/lending/silo/silver__silo_borrows.sql index bd8fa26..019eb06 100644 --- a/models/silver/defi/lending/silo/silver__silo_borrows.sql +++ b/models/silver/defi/lending/silo/silver__silo_borrows.sql @@ -27,26 +27,30 @@ WITH borrows AS( segmented_data [1] :: STRING ) :: INTEGER AS collateral_only, p.token_address AS silo_market, - l._log_id, - l._inserted_timestamp + l.modified_timestamp AS _inserted_timestamp, + CONCAT( + l.tx_hash :: STRING, + '-', + l.event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN {{ ref('silver__silo_pools') }} p ON l.contract_address = p.silo_address WHERE topics [0] :: STRING = '0x312a5e5e1079f5dda4e95dbbd0b908b291fd5b992ef22073643ab691572c5b52' - AND tx_status = 'SUCCESS' --excludes failed txs + 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/silo/silver__silo_deposits.sql b/models/silver/defi/lending/silo/silver__silo_deposits.sql index 203c267..4ab27e4 100644 --- a/models/silver/defi/lending/silo/silver__silo_deposits.sql +++ b/models/silver/defi/lending/silo/silver__silo_deposits.sql @@ -24,26 +24,30 @@ WITH deposits AS( segmented_data [0] :: STRING ) :: INTEGER AS amount_unadj, p.token_address AS silo_market, - l._log_id, - l._inserted_timestamp + l.modified_timestamp AS _inserted_timestamp, + CONCAT( + l.tx_hash :: STRING, + '-', + l.event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN {{ ref('silver__silo_pools') }} p ON l.contract_address = p.silo_address WHERE topics [0] :: STRING = '0xdd160bb401ec5b5e5ca443d41e8e7182f3fe72d70a04b9c0ba844483d212bcb5' - AND tx_status = 'SUCCESS' --excludes failed txs + 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/silo/silver__silo_liquidations.sql b/models/silver/defi/lending/silo/silver__silo_liquidations.sql index f2d5ec2..f826280 100644 --- a/models/silver/defi/lending/silo/silver__silo_liquidations.sql +++ b/models/silver/defi/lending/silo/silver__silo_liquidations.sql @@ -33,26 +33,30 @@ WITH liquidations AS( WHEN shareamountrepaid > 0 THEN 'debt_token_event' ELSE 'collateral_token_event' END AS liquidation_event_type, - l._log_id, - l._inserted_timestamp + l.modified_timestamp AS _inserted_timestamp, + CONCAT( + l.tx_hash :: STRING, + '-', + l.event_index :: STRING + ) AS _log_id FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN {{ ref('silver__silo_pools') }} p ON l.contract_address = p.silo_address WHERE topics [0] :: STRING = '0xf3fa0eaee8f258c23b013654df25d1527f98a5c7ccd5e951dd77caca400ef972' - AND tx_status = 'SUCCESS' --excludes failed txs + 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 %} ), contracts AS ( diff --git a/models/silver/defi/lending/silo/silver__silo_pools.sql b/models/silver/defi/lending/silo/silver__silo_pools.sql index 228b4c0..d626657 100644 --- a/models/silver/defi/lending/silo/silver__silo_pools.sql +++ b/models/silver/defi/lending/silo/silver__silo_pools.sql @@ -13,20 +13,21 @@ WITH logs_pull AS ( ELSE NULL END AS tokens FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE contract_address IN ( LOWER('0x4166487056A922D784b073d4d928a516B074b719'), LOWER('0xe067b967a36a136084eb9df0149dde64f01ea7d1') ) + {% 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 %} ), contracts AS ( @@ -57,8 +58,12 @@ silo_pull AS ( 40 ) ) :: INTEGER AS version, - l._inserted_timestamp, - l._log_id + modified_timestamp AS _inserted_timestamp, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id FROM logs_pull l WHERE diff --git a/models/silver/defi/lending/silo/silver__silo_repayments.sql b/models/silver/defi/lending/silo/silver__silo_repayments.sql index 245f60f..58238e8 100644 --- a/models/silver/defi/lending/silo/silver__silo_repayments.sql +++ b/models/silver/defi/lending/silo/silver__silo_repayments.sql @@ -24,26 +24,30 @@ WITH deposits AS( segmented_data [0] :: STRING ) :: INTEGER AS amount, p.token_address AS silo_market, - l._log_id, - l._inserted_timestamp + CONCAT( + l.tx_hash :: STRING, + '-', + l.event_index :: STRING + ) AS _log_id, + l.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN {{ ref('silver__silo_pools') }} p ON l.contract_address = p.silo_address WHERE topics [0] :: STRING = '0x05f2eeda0e08e4b437f487c8d7d29b14537d15e3488170dc3de5dbdf8dac4684' - AND tx_status = 'SUCCESS' --excludes failed txs + 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/silo/silver__silo_withdraws.sql b/models/silver/defi/lending/silo/silver__silo_withdraws.sql index a5a75fa..c686e27 100644 --- a/models/silver/defi/lending/silo/silver__silo_withdraws.sql +++ b/models/silver/defi/lending/silo/silver__silo_withdraws.sql @@ -28,26 +28,30 @@ WITH deposits AS( segmented_data [1] :: STRING ) :: INTEGER AS collateral_only, p.token_address AS silo_market, - l._log_id, - l._inserted_timestamp + CONCAT( + l.tx_hash :: STRING, + '-', + l.event_index :: STRING + ) AS _log_id, + l.modified_timestamp AS _inserted_timestamp FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} l INNER JOIN {{ ref('silver__silo_pools') }} p ON l.contract_address = p.silo_address WHERE topics [0] :: STRING = '0x3b5f15635b488fe265654176726b3222080f3d6500a562f4664233b3ea2f0283' - AND tx_status = 'SUCCESS' --excludes failed txs + 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/nft/sales/silver__element_sales.sql b/models/silver/nft/sales/silver__element_sales.sql index 1c20010..d916d60 100644 --- a/models/silver/nft/sales/silver__element_sales.sql +++ b/models/silver/nft/sales/silver__element_sales.sql @@ -20,33 +20,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, @@ -57,8 +57,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 @@ -66,10 +66,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 @@ -144,7 +148,7 @@ new_base AS ( intra_grouping_seller_fill, event_index, event_name, - decoded_flat, + decoded_log, event_type, currency_address_raw, amount_raw, @@ -194,7 +198,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= ( SELECT @@ -210,13 +214,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 @@ -225,7 +229,7 @@ SELECT tx_hash, event_index, event_name, - decoded_flat, + decoded_log AS decoded_flat, event_type, ( SELECT diff --git a/models/silver/nft/sales/silver__seaport_1_1_sales.sql b/models/silver/nft/sales/silver__seaport_1_1_sales.sql index 88c4c5e..52c3c1a 100644 --- a/models/silver/nft/sales/silver__seaport_1_1_sales.sql +++ b/models/silver/nft/sales/silver__seaport_1_1_sales.sql @@ -23,14 +23,14 @@ seaport_tx_table AS ( block_timestamp, tx_hash FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp >= '2022-07-01' AND contract_address = '0x00000000006c3852cbef3e08e8df289169ede581' AND topics [0] = '0x9d9af8e38d66c62e2c12f0225249fd9d721c54b83f48d9352c97c6cacdcb6f31' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM @@ -41,25 +41,29 @@ AND _inserted_timestamp >= ( decoded AS ( SELECT tx_hash, - decoded_flat, + decoded_log, event_index, - decoded_data, - _log_id, - _inserted_timestamp, + full_decoded_log, + 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 - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_number >= 17137162 AND contract_address = '0x00000000006c3852cbef3e08e8df289169ede581' @@ -71,7 +75,7 @@ decoded AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM @@ -89,7 +93,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 ( @@ -111,7 +119,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 ( @@ -130,7 +142,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( @@ -140,7 +152,7 @@ flat_raw AS ( FROM decoded, LATERAL FLATTEN( - input => decoded_data :data + input => full_decoded_log :data ) f WHERE event_name = 'OrderFulfilled' @@ -1035,7 +1047,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= '2022-07-01' AND tx_hash IN ( @@ -1046,7 +1058,7 @@ tx_data AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM @@ -1072,7 +1084,7 @@ nft_transfer_operator AS ( ) ) AS erc1155_value FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE >= '2022-07-01' AND tx_hash IN ( @@ -1087,7 +1099,7 @@ nft_transfer_operator AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM diff --git a/models/silver/nft/sales/silver__seaport_1_4_sales.sql b/models/silver/nft/sales/silver__seaport_1_4_sales.sql index 955af92..d6e56ac 100644 --- a/models/silver/nft/sales/silver__seaport_1_4_sales.sql +++ b/models/silver/nft/sales/silver__seaport_1_4_sales.sql @@ -22,14 +22,14 @@ raw_decoded_logs AS ( SELECT * FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_number >= 65853745 AND contract_address = '0x00000000000001ad428e4906ae43d8f9852d0dd6' AND event_name = 'OrderFulfilled' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM @@ -42,11 +42,11 @@ mao_buy_tx AS ( tx_hash, event_index, 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 @@ -59,11 +59,11 @@ mao_offer_accepted_tx AS ( block_number, tx_hash, 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 @@ -81,13 +81,13 @@ raw_logs AS ( SELECT * FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_number >= 65853745 AND contract_address = '0x00000000000001ad428e4906ae43d8f9852d0dd6' {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM @@ -159,18 +159,18 @@ mao_orderhash AS ( mao_raw_decoded AS ( SELECT 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, - decoded_flat :orderHash :: STRING AS orderhash, + decoded_log :orderHash :: STRING AS orderhash, CONCAT( tx_hash, '-', - decoded_flat :orderHash :: STRING + decoded_log :orderHash :: STRING ) AS tx_hash_orderhash,* FROM raw_decoded_logs @@ -201,26 +201,26 @@ 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 @@ -242,42 +242,42 @@ mao_orderhash AS ( offer_length_match_advanced_order_oa AS ( SELECT tx_hash, - decoded_flat :orderHash :: STRING AS orderhash, + decoded_log :orderHash :: STRING AS orderhash, COUNT(1) AS offer_length_raw FROM mao_raw_decoded, - TABLE(FLATTEN(input => decoded_flat :consideration)) + TABLE(FLATTEN(input => decoded_log :consideration)) WHERE trade_type = 'offer_accepted' AND VALUE :itemType IN ( 2, 3 ) - AND decoded_flat :consideration [0] IS NOT NULL + AND decoded_log :consideration [0] IS NOT NULL GROUP BY tx_hash, - decoded_flat :orderHash :: STRING + decoded_log :orderHash :: STRING HAVING offer_length_raw IS NOT NULL ), offer_length_match_advanced_order_buy AS ( SELECT tx_hash, - decoded_flat :orderHash :: STRING AS orderhash, + decoded_log :orderHash :: STRING AS orderhash, COUNT(1) AS offer_length_raw FROM mao_raw_decoded, - TABLE(FLATTEN(input => decoded_flat :consideration)) + TABLE(FLATTEN(input => decoded_log :consideration)) WHERE trade_type = 'buy' AND VALUE :itemType IN ( 2, 3 ) - AND decoded_flat :consideration [0] IS NOT NULL + AND decoded_log :consideration [0] IS NOT NULL GROUP BY tx_hash, - decoded_flat :orderHash :: STRING + decoded_log :orderHash :: STRING ), offer_length_match_advanced_order_combined AS ( SELECT @@ -317,7 +317,7 @@ mao_orderhash 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 ( @@ -339,7 +339,7 @@ mao_orderhash 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 ( @@ -358,7 +358,7 @@ mao_orderhash 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( @@ -368,7 +368,7 @@ mao_orderhash AS ( FROM decoded, LATERAL FLATTEN( - input => decoded_data :data + input => full_decoded_log :data ) f WHERE event_name IN ( @@ -1194,31 +1194,31 @@ mao_orderhash AS ( contract_address, trade_type, offer_length_raw, - decoded_data, - decoded_flat, - decoded_flat :offerer :: STRING AS offerer, + full_decoded_log, + decoded_log, + decoded_log :offerer :: STRING AS offerer, -- or the one who proposed the sale so that they receive the nft - decoded_flat :zone :: STRING AS ZONE, - decoded_flat :recipient :: STRING AS recipient, - decoded_flat :orderHash :: STRING AS orderhash, + decoded_log :zone :: STRING AS ZONE, + decoded_log :recipient :: STRING AS recipient, + decoded_log :orderHash :: STRING AS orderhash, COALESCE( A.tx_hash_orderhash_full, b.tx_hash_orderhash_full ) AS tx_hash_orderhash_full, - decoded_flat :offer [0] :token :: STRING AS payment_token, + decoded_log :offer [0] :token :: STRING AS payment_token, ( - decoded_flat :offer [0] :amount :: INT + decoded_log :offer [0] :amount :: INT ) / offer_length_raw AS total_sale_price_raw, - _inserted_timestamp, - _log_id + r.modified_timestamp AS _inserted_timestamp, + concat(r.tx_hash::string, '-', r.event_index::string) AS _log_id FROM mao_raw_decoded r LEFT JOIN mao_orderhash_full A ON r.tx_hash = A.tx_hash - AND r.decoded_flat :orderHash :: STRING = A.orderhash_1 + AND r.decoded_log :orderHash :: STRING = A.orderhash_1 LEFT JOIN mao_orderhash_full b ON r.tx_hash = b.tx_hash - AND r.decoded_flat :orderHash :: STRING = b.orderhash_2 + AND r.decoded_log :orderHash :: STRING = b.orderhash_2 INNER JOIN offer_length_match_advanced_order o ON r.tx_hash = o.tx_hash AND COALESCE( @@ -1227,7 +1227,7 @@ mao_orderhash AS ( ) = o.tx_hash_orderhash_full WHERE trade_type = 'offer_accepted' - AND decoded_flat :offer [0] :itemType :: INT IN ( + AND decoded_log :offer [0] :itemType :: INT IN ( 0, 1 ) @@ -1236,9 +1236,9 @@ mao_orderhash AS ( SELECT tx_hash, event_index, - decoded_flat :orderHash :: STRING AS orderhash, - decoded_flat :offerer :: STRING AS transfers_nft_receiver, - decoded_flat :recipient :: STRING AS transfers_nft_seller, + decoded_log :orderHash :: STRING AS orderhash, + decoded_log :offerer :: STRING AS transfers_nft_receiver, + decoded_log :recipient :: STRING AS transfers_nft_seller, VALUE :token :: STRING AS nft_address, VALUE :identifier :: STRING AS tokenId, VALUE :amount :: INT AS nft_tokenid_quantity, @@ -1247,7 +1247,7 @@ mao_orderhash AS ( FROM mao_raw_decoded, LATERAL FLATTEN ( - input => decoded_flat :consideration + input => decoded_log :consideration ) WHERE trade_type = 'offer_accepted' @@ -1283,9 +1283,9 @@ mao_orderhash AS ( SELECT tx_hash, event_index, - decoded_flat :orderHash :: STRING AS orderhash, - decoded_flat :offerer :: STRING AS transfers_nft_seller, - decoded_flat :recipient :: STRING AS transfers_nft_receiver, + decoded_log :orderHash :: STRING AS orderhash, + decoded_log :offerer :: STRING AS transfers_nft_seller, + decoded_log :recipient :: STRING AS transfers_nft_receiver, VALUE :token :: STRING AS nft_address, VALUE :identifier :: STRING AS tokenId, VALUE :amount :: INT AS nft_tokenid_quantity, @@ -1294,7 +1294,7 @@ mao_orderhash AS ( FROM mao_raw_decoded, LATERAL FLATTEN ( - input => decoded_flat :consideration + input => decoded_log :consideration ) WHERE trade_type = 'buy' @@ -1340,7 +1340,7 @@ mao_orderhash AS ( match_advanced_orders_fees_oa_consideration AS ( SELECT tx_hash, - decoded_flat, + decoded_log, event_index, VALUE :token :: STRING AS payment_token, VALUE :amount :: INT AS raw_amount, @@ -1366,7 +1366,7 @@ mao_orderhash AS ( FROM mao_raw_decoded, LATERAL FLATTEN ( - input => decoded_flat :consideration + input => decoded_log :consideration ) f WHERE trade_type = 'offer_accepted' @@ -1390,8 +1390,8 @@ mao_orderhash AS ( match_advanced_orders_fees_buy_consideration AS ( SELECT tx_hash, - decoded_flat, - decoded_flat :orderHash :: STRING AS orderhash, + decoded_log, + decoded_log :orderHash :: STRING AS orderhash, VALUE :token :: STRING AS payment_token, VALUE :amount :: INT AS raw_amount, VALUE :recipient :: STRING AS royalty_recipient, @@ -1417,7 +1417,7 @@ mao_orderhash AS ( FROM mao_raw_decoded, LATERAL FLATTEN ( - input => decoded_flat :consideration + input => decoded_log :consideration ) WHERE trade_type = 'buy' @@ -1434,7 +1434,7 @@ mao_orderhash AS ( match_advanced_orders_fees_buy_consideration_filtered AS ( SELECT C.tx_hash, - decoded_flat, + decoded_log, C.orderhash, COALESCE( A.tx_hash_orderhash_full, @@ -1485,11 +1485,11 @@ mao_orderhash AS ( 'true', 'false' ) AS is_price_estimated, - decoded_flat, + decoded_log, -- using decoded flat here instead of decoded_output so that we're able to filter for match advanced orders - decoded_flat :consideration AS consideration, - decoded_flat :offer AS offer, - decoded_flat :consideration [0] :itemType AS tx_type, + decoded_log :consideration AS consideration, + decoded_log :offer AS offer, + decoded_log :consideration [0] :itemType AS tx_type, ZONE, transfers_nft_receiver AS recipient, --buyer_address in final @@ -1621,7 +1621,7 @@ mao_orderhash AS ( total_fees_raw, platform_fee_raw_total AS platform_fee_raw, creator_fee_raw_total AS creator_fee_raw, - decoded_flat, + decoded_log, consideration, offer, _log_id, @@ -1640,7 +1640,7 @@ mao_orderhash AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= '2023-03-01' AND tx_hash IN ( @@ -1651,7 +1651,7 @@ mao_orderhash AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM @@ -1677,7 +1677,7 @@ nft_transfer_operator AS ( ) ) AS erc1155_value FROM - {{ ref('silver__logs') }} + {{ ref('core__fact_event_logs') }} WHERE block_timestamp :: DATE >= '2022-06-01' AND tx_hash IN ( @@ -1692,7 +1692,7 @@ nft_transfer_operator AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX(_inserted_timestamp) - INTERVAL '24 hours' FROM 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 3fd57ca..f2ea6a7 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-05-01' AND block_number >= 86564958 @@ -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 modified_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-05-01' AND block_number >= 86564958 @@ -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-05-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-05-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..55d804d 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,18 +34,30 @@ 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 modified_timestamp >= SYSDATE() - INTERVAL '7 day' {% endif %} ), raw_logs AS ( SELECT - *, + block_number, + block_timestamp, + tx_hash, + event_index, + contract_address, + topics, + DATA, + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp, IFF( topics [0] :: STRING IN ( '0x4b9f2d36e1b4c93de62cc077b00b1a91d84b6c31b4a14e012718dcca230689e7' @@ -65,7 +77,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 +88,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 +146,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 +193,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 +219,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 +242,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 +252,7 @@ flat_raw AS ( FROM decoded, LATERAL FLATTEN( - input => decoded_data :data + input => full_decoded_log :data ) f WHERE event_name IN ( @@ -1098,22 +1122,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 +1174,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 +1210,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 +1444,7 @@ mao_deals_nft_transfers_sales AS ( 0 ) AS creator_fee_raw, currency_address, - decoded_flat, + decoded_log, offerer, recipient, _log_id, @@ -1471,7 +1499,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 +1630,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 +1652,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 +1689,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 +1700,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 +1736,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 +1844,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 +1859,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 +1880,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 +1891,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 +1918,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 +1933,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__treasure_sales.sql b/models/silver/nft/sales/silver__treasure_sales.sql index 86bcff5..e8e7532 100644 --- a/models/silver/nft/sales/silver__treasure_sales.sql +++ b/models/silver/nft/sales/silver__treasure_sales.sql @@ -11,7 +11,7 @@ WITH raw_logs AS ( SELECT * FROM - {{ ref('silver__decoded_logs') }} + {{ ref('core__ez_decoded_event_logs') }} WHERE block_timestamp :: DATE >= '2021-11-01' AND contract_address IN ( @@ -22,13 +22,13 @@ WITH raw_logs AS ( AND event_name IN ('ItemSold', 'BidAccepted') {% 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 %} ), base_sales AS ( @@ -37,22 +37,22 @@ base_sales AS ( event_index, event_name, contract_address, - decoded_flat, + decoded_log, COALESCE( - decoded_flat :bidType :: STRING, + decoded_log :bidType :: STRING, NULL ) AS auction_bid_type, COALESCE( - decoded_flat :buyer :: STRING, - decoded_flat :bidder :: STRING + decoded_log :buyer :: STRING, + decoded_log :bidder :: STRING ) AS buyer_address, - decoded_flat :seller :: STRING AS seller_address, - decoded_flat :nftAddress :: STRING AS nft_address, - decoded_flat :tokenId :: STRING AS tokenId, - decoded_flat :quantity :: STRING AS quantity, - decoded_flat :pricePerItem :: INT * quantity AS total_price_raw, + decoded_log :seller :: STRING AS seller_address, + decoded_log :nftAddress :: STRING AS nft_address, + decoded_log :tokenId :: STRING AS tokenId, + decoded_log :quantity :: STRING AS quantity, + decoded_log :pricePerItem :: INT * quantity AS total_price_raw, COALESCE ( - decoded_flat :paymentToken :: STRING, + decoded_log :paymentToken :: STRING, '0x539bde0d7dbd336b79148aa742883198bbf60342' ) AS currency_address, -- for v2 there's a 3 month period where certain txs does not have a payment token field in the logs but it's confirmed to be all MAGIC tokens as payment. For v1 , all are magic tokens @@ -68,8 +68,12 @@ base_sales AS ( origin_function_signature, origin_from_address, origin_to_address, - _log_id, - _inserted_timestamp + CONCAT( + tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + modified_timestamp AS _inserted_timestamp FROM raw_logs ), @@ -104,9 +108,9 @@ eth_payment AS ( block_timestamp :: DATE >= '2021-11-01' AND from_address = '0x09986b4e255b3c548041a30a2ee312fe176731c2' AND VALUE > 0 - AND identifier != 'CALL_ORIGIN' + AND trace_address != 'ORIGIN' AND TYPE != 'DELEGATECALL' - AND trace_status = 'SUCCESS' + AND trace_succeeded AND tx_hash IN ( SELECT tx_hash @@ -340,7 +344,7 @@ token_payment_raw AS ( ELSE NULL END AS intra_tx_grouping_raw FROM - {{ ref('silver__transfers') }} + {{ ref('core__ez_token_transfers') }} WHERE block_timestamp :: DATE >= '2021-11-01' AND contract_address IN ( @@ -361,13 +365,13 @@ token_payment_raw 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 %} ), token_payment_intra_fill AS ( @@ -590,7 +594,7 @@ nft_address_type AS ( contract_address AS nft_address, token_transfer_type FROM - {{ ref('silver__nft_transfers') }} + {{ ref('nft__ez_nft_transfers') }} WHERE block_timestamp :: DATE >= '2021-11-01' AND contract_address IN ( @@ -601,7 +605,7 @@ nft_address_type AS ( ) {% if is_incremental() %} -AND _inserted_timestamp >= ( +AND modified_timestamp >= ( SELECT MAX( _inserted_timestamp @@ -623,7 +627,7 @@ tx_data AS ( tx_fee, input_data FROM - {{ ref('silver__transactions') }} + {{ ref('core__fact_transactions') }} WHERE block_timestamp :: DATE >= '2021-11-01' AND tx_hash IN ( @@ -634,13 +638,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 diff --git a/models/silver/nft/silver__nft_transfers.sql b/models/silver/nft/silver__nft_transfers.sql index c53a4b0..34b7121 100644 --- a/models/silver/nft/silver__nft_transfers.sql +++ b/models/silver/nft/silver__nft_transfers.sql @@ -10,20 +10,29 @@ WITH base AS ( SELECT - _log_id, block_number, - tx_hash, block_timestamp, + tx_hash, + {#tx_position,#} event_index, contract_address, topics, DATA, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TO_TIMESTAMP_NTZ(_inserted_timestamp) AS _inserted_timestamp + {#origin_function_signature, + origin_from_address, + origin_to_address, + #} + 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 - tx_status = 'SUCCESS' + tx_succeeded AND ( ( topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' @@ -63,7 +72,10 @@ erc721s AS ( ) :: STRING AS token_id, NULL AS erc1155_value, TO_TIMESTAMP_NTZ(_inserted_timestamp) AS _inserted_timestamp, - event_index + event_index {#tx_position, + origin_function_signature, + origin_from_address, + origin_to_address #} FROM base WHERE @@ -88,7 +100,10 @@ transfer_singles AS ( segmented_data [1] :: STRING ) :: STRING AS erc1155_value, TO_TIMESTAMP_NTZ(_inserted_timestamp) AS _inserted_timestamp, - event_index + event_index {#tx_position, + origin_function_signature, + origin_from_address, + origin_to_address #} FROM base WHERE @@ -111,7 +126,10 @@ transfer_batch_raw AS ( ) AS tokenid_length, tokenid_length AS quantity_length, _log_id, - TO_TIMESTAMP_NTZ(_inserted_timestamp) AS _inserted_timestamp + TO_TIMESTAMP_NTZ(_inserted_timestamp) AS _inserted_timestamp {#tx_position, + origin_function_signature, + origin_from_address, + origin_to_address #} FROM base WHERE @@ -149,7 +167,10 @@ flattened AS ( quantity_indextag_end ) THEN 'quantity' ELSE NULL - END AS label + END AS label {#tx_position, + origin_function_signature, + origin_from_address, + origin_to_address #} FROM transfer_batch_raw, LATERAL FLATTEN ( @@ -176,7 +197,10 @@ tokenid_list AS ( event_index ORDER BY INDEX ASC - ) AS tokenid_order + ) AS tokenid_order {#tx_position, + origin_function_signature, + origin_from_address, + origin_to_address #} FROM flattened WHERE @@ -214,7 +238,10 @@ transfer_batch_final AS ( contract_address, t.tokenId AS token_id, q.quantity AS erc1155_value, - tokenid_order AS intra_event_index + tokenid_order AS intra_event_index {#tx_position, + origin_function_signature, + origin_from_address, + origin_to_address #} FROM tokenid_list t INNER JOIN quantity_list q @@ -226,6 +253,7 @@ all_transfers AS ( SELECT block_number, tx_hash, + {#tx_position,#} block_timestamp, contract_address, from_address, @@ -242,13 +270,16 @@ all_transfers AS ( contract_address, '-', token_id - ) AS _log_id + ) AS _log_id {#origin_function_signature, + origin_from_address, + origin_to_address #} FROM erc721s UNION ALL SELECT block_number, tx_hash, + {#tx_position,#} block_timestamp, contract_address, from_address, @@ -265,7 +296,9 @@ all_transfers AS ( contract_address, '-', token_id - ) AS _log_id + ) AS _log_id {#origin_function_signature, + origin_from_address, + origin_to_address #} FROM transfer_singles WHERE @@ -274,6 +307,7 @@ all_transfers AS ( SELECT block_number, tx_hash, + {#tx_position,#} block_timestamp, contract_address, from_address, @@ -292,7 +326,9 @@ all_transfers AS ( token_id, '-', intra_event_index - ) AS _log_id + ) AS _log_id {#origin_function_signature, + origin_from_address, + origin_to_address #} FROM transfer_batch_final WHERE @@ -303,6 +339,7 @@ transfer_base AS ( block_number, block_timestamp, tx_hash, + {#tx_position,#} event_index, intra_event_index, contract_address, @@ -316,6 +353,10 @@ transfer_base AS ( ELSE 'other' END AS event_type, token_transfer_type, + {#origin_function_signature, + origin_from_address, + origin_to_address, + #} A._log_id, A._inserted_timestamp FROM @@ -333,6 +374,7 @@ heal_model AS ( block_number, block_timestamp, tx_hash, + {#tx_position,#} event_index, intra_event_index, contract_address, @@ -343,6 +385,10 @@ heal_model AS ( erc1155_value, event_type, token_transfer_type, + {#origin_function_signature, + origin_from_address, + origin_to_address, + #} _log_id, t._inserted_timestamp FROM @@ -383,6 +429,7 @@ heal_model AS ( block_number, block_timestamp, tx_hash, + {#tx_position,#} event_index, intra_event_index, contract_address, @@ -393,6 +440,10 @@ heal_model AS ( erc1155_value, event_type, token_transfer_type, + {#origin_function_signature, + origin_from_address, + origin_to_address, + #} _log_id, A._inserted_timestamp, {{ dbt_utils.generate_surrogate_key( @@ -412,6 +463,7 @@ SELECT block_number, block_timestamp, tx_hash, + {#tx_position,#} event_index, intra_event_index, contract_address, @@ -422,6 +474,10 @@ SELECT erc1155_value, event_type, token_transfer_type, + {#origin_function_signature, + origin_from_address, + origin_to_address, + #} _log_id, _inserted_timestamp, {{ dbt_utils.generate_surrogate_key( @@ -435,7 +491,30 @@ FROM {% endif %} ) SELECT - * + block_number, + block_timestamp, + tx_hash, + {#tx_position,#} -- new , pending event logs + event_index, + intra_event_index, + contract_address, + project_name, + from_address, + to_address, + tokenId, + erc1155_value, + event_type, + token_transfer_type, + {#origin_function_signature, + origin_from_address, + origin_to_address, + #} -- new + _log_id, + _inserted_timestamp, + nft_transfers_id, + inserted_timestamp, + modified_timestamp, + _invocation_id FROM FINAL qualify ROW_NUMBER() over ( PARTITION BY _log_id 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 109948b..f4c1c95 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 = '0xe3607b00e75f6405248323a9417ff6b39b244b50' --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..af0df8d 100644 --- a/models/silver/protocols/olas/silver_olas__service_event_logs.sql +++ b/models/silver/protocols/olas/silver_olas__service_event_logs.sql @@ -31,8 +31,12 @@ SELECT d.topics [3] :: STRING AS 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 cf3acd1..a67e5bf 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 = '0xe3607b00e75f6405248323a9417ff6b39b244b50' --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/streamline/silver/decoder/realtime/streamline__decode_logs_realtime.sql b/models/streamline/silver/decoder/realtime/streamline__decode_logs_realtime.sql index 97e293a..3ad4210 100644 --- a/models/streamline/silver/decoder/realtime/streamline__decode_logs_realtime.sql +++ b/models/streamline/silver/decoder/realtime/streamline__decode_logs_realtime.sql @@ -4,13 +4,13 @@ tags = ['streamline_decoded_logs_realtime'] ) }} -WITH target_blocks AS ( +WITH target_blocks AS ( SELECT block_number - FROM + FROM {{ ref('core__fact_blocks') }} - WHERE + WHERE block_number >= ( SELECT block_number @@ -26,55 +26,54 @@ existing_logs_to_exclude AS ( l INNER JOIN target_blocks b USING (block_number) WHERE - l._inserted_timestamp :: DATE >= DATEADD('day', -5, 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', -5, SYSDATE()) -) -SELECT - l.block_number, - l._log_id, - A.abi AS 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 - ) -limit 7500000 \ No newline at end of file + l._inserted_timestamp :: DATE >= DATEADD('day', -5, 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', -5, SYSDATE())) + SELECT + l.block_number, + l._log_id, + A.abi AS 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 + ) + LIMIT + 7500000