From e91d9b26836084849ac1273aa835d0dfedc02691 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Mon, 25 Nov 2024 20:22:28 +0200 Subject: [PATCH 01/14] Add New Event Models --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 270 ++++++++++++++++- ...bitrum_open_interest_in_tokens_updated.sql | 183 ++++++++++++ .../gmx_v2_arbitrum_open_interest_updated.sql | 181 ++++++++++++ .../gmx_v2_arbitrum_oracle_price_update.sql | 149 ++++++++++ .../gmx_v2_arbitrum_pool_amount_updated.sql | 159 ++++++++++ .../arbitrum/gmx_v2_arbitrum_set_uint.sql | 159 ++++++++++ .../gmx_v2_avalanche_c_event_schema.yml | 270 ++++++++++++++++- ...nche_c_open_interest_in_tokens_updated.sql | 183 ++++++++++++ ...x_v2_avalanche_c_open_interest_updated.sql | 181 ++++++++++++ ...gmx_v2_avalanche_c_oracle_price_update.sql | 149 ++++++++++ ...gmx_v2_avalanche_c_pool_amount_updated.sql | 159 ++++++++++ .../gmx_v2_avalanche_c_set_uint.sql | 159 ++++++++++ .../gmx/event/gmx_v2_event_schema.yml | 271 +++++++++++++++++- ...gmx_v2_open_interest_in_tokens_updated.sql | 40 +++ .../event/gmx_v2_open_interest_updated.sql | 41 +++ .../gmx/event/gmx_v2_oracle_price_update.sql | 40 +++ .../gmx/event/gmx_v2_pool_amount_updated.sql | 39 +++ .../_projects/gmx/event/gmx_v2_set_uint.sql | 38 +++ 18 files changed, 2668 insertions(+), 3 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_in_tokens_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_oracle_price_update.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_pool_amount_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index d61b2d58e13..4a2bd1a9e80 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -909,4 +909,272 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + + + - name: gmx_v2_arbitrum_open_interest_in_tokens_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'open_interest_in_tokens_updated'] + description: | + Combines and processes decoded event data to produce a normalized dataset of updated orders + on the GMX platform for the Arbitrum blockchain. + This model integrates data from the `open_interest_in_tokens_updated` table, enriching it with market-specific details. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OpenInterestInTokensUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market in which the order was updated, decoded from a hexadecimal value. + data_tests: + - not_null + - name: collateral_token + description: The token used as collateral for the order, decoded from a hexadecimal value. + data_tests: + - not_null + - name: is_long + description: A boolean flag indicating whether the order is a long position (true) or short position (false). + - name: next_value + description: | + Represents the updated open interest vlaue after the transaction. It is derived by normalizing + the raw value using index token decimals. + This ensures consistent scaling of the value across tokens with varying decimals. + - name: delta + description: | + Indicates the change in open interest. It is calculated by normalizing the raw delta value + using index token decimals. + This normalization accounts for token decimal differences and provides a standardized measure of change. + - name: tx_from + description: The address that initiated the transaction + - name: tx_to + description: The destination address of the transaction + - name: tx_index + description: Index value related to the transaction + + + - name: gmx_v2_arbitrum_open_interest_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'open_interest_updated'] + description: | + Extracts and processes decoded event data for open interest updates on the GMX platform, + specifically on the Arbitrum blockchain. This model normalizes data, including key metrics like + delta and next_value, ensuring consistent scaling based on token decimals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OpenInterestUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market associated with the open interest update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: collateral_token + description: The token used as collateral for the open interest, decoded from a hexadecimal value. + data_tests: + - not_null + - name: is_long + description: | + A boolean flag indicating whether the open interest update is for a long position (true) or short position (false). + data_type: boolean + - name: delta + description: | + Represents the change in open interest value, normalized by dividing the raw delta by `POWER(10, 30)`. + This ensures consistent scaling for values across tokens with varying decimals. + data_type: float + data_tests: + - not_null + - name: next_value + description: | + Indicates the updated open interest value after the transaction, normalized by dividing + the raw value by `POWER(10, 30)` to ensure consistent scaling across tokens. + data_type: float + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction. + + + - name: gmx_v2_arbitrum_oracle_price_update + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'oracle_price_update'] + description: | + Processes decoded event data for Oracle Price Updates on the GMX platform in the Arbitrum blockchain. + The model normalizes price data (min_price and max_price) using token-specific decimals and extracts + additional details such as the provider and token involved in the update. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OraclePriceUpdate' for this model + data_tests: + - not_null + - *msg_sender + - name: token + description: The token associated with the oracle price update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: provider + description: The address of the price provider, decoded from a hexadecimal value. + - name: min_price + description: The minimum price reported by the oracle. + data_tests: + - not_null + - name: max_price + description: The maximum price reported by the oracle. + data_tests: + - not_null + - name: timestamp + description: The timestamp of the oracle price update. + data_type: timestamp + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_arbitrum_pool_amount_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'pool_amount_updated'] + description: | + Processes decoded event data for Pool Amount Updates on the GMX platform in the Arbitrum blockchain. + This model normalizes token values (next_value and delta) based on token-specific decimals and extracts + additional details such as the market and token involved in the pool update. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'PoolAmountUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market associated with the pool update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: token + description: The token involved in the pool update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: next_value + description: | + The amount in the pool for the specified token, normalized by dividing the raw value + by `POWER(10, token_decimals)`, where `token_decimals` is derived from ERC-20 token metadata. + data_tests: + - not_null + - name: delta + description: | + The change in the pool amount for the specified token, normalized by dividing the raw value + by `POWER(10, token_decimals)`, where `token_decimals` is derived from ERC-20 token metadata. + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_arbitrum_set_uint + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'set_uint'] + description: | + Processes decoded event data for `SetUint` events on the GMX platform in the Arbitrum blockchain. + This model normalizes the value field and extracts additional details such as the base key and associated data, + ensuring compatibility with downstream analyses. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'SetUint' for this model + data_tests: + - not_null + - *msg_sender + - name: base_key + description: The base key associated with the event, decoded from a hexadecimal value. + data_tests: + - not_null + - name: data + description: The associated data field, decoded from a hexadecimal value. + data_tests: + - not_null + - name: value + description: | + The value associated with the event, normalized by dividing the raw value by `POWER(10, 30)`. + This ensures the value is represented in a standard floating-point format for analysis. + data_type: float + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql new file mode 100644 index 00000000000..30565e97753 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql @@ -0,0 +1,183 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'open_interest_in_tokens_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OpenInterestInTokensUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender, + varbinary_substring(topic1, 13, 20) as account + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender, + varbinary_substring(topic2, 13, 20) as account + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.market) AS market, + from_hex(EDP.collateral_token) AS collateral_token, + CAST(EDP.is_long AS BOOLEAN) AS is_long, + CAST(EDP.next_value AS DOUBLE) / POWER(10, MD.index_token_decimals) AS next_value, + CAST(EDP.delta AS DOUBLE) / POWER(10, MD.index_token_decimals) AS delta + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON from_hex(EDP.market) = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql new file mode 100644 index 00000000000..c981bad6e6f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql @@ -0,0 +1,181 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'open_interest_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OpenInterestUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(is_long AS BOOLEAN) AS is_long, + TRY_CAST(delta AS DOUBLE) / POWER(10, 30) AS delta, + TRY_CAST(next_value AS DOUBLE) / POWER(10, 30) AS next_value + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql new file mode 100644 index 00000000000..913c15b2598 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -0,0 +1,149 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'oracle_price_update', + materialized = 'table' + ) +}} + +{%- set event_name = 'OraclePriceUpdate' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + AND evt_block_time > DATE '2023-08-01' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + AND evt_block_time > DATE '2023-08-01' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'token' THEN value END) AS token, + MAX(CASE WHEN key_name = 'provider' THEN value END) AS provider, + MAX(CASE WHEN key_name = 'minPrice' THEN value END) AS min_price, + MAX(CASE WHEN key_name = 'maxPrice' THEN value END) AS max_price, + MAX(CASE WHEN key_name = 'timestamp' THEN value END) AS "timestamp" + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(token) AS token, + from_hex(provider) AS provider, + TRY_CAST(min_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS min_price, + TRY_CAST(max_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS max_price, + CASE + WHEN "timestamp" = 0 THEN NULL + ELSE "timestamp" + END AS "timestamp" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20 + ON from_hex(EDP.token) = ERC20.contract_address +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql new file mode 100644 index 00000000000..661a8a161e6 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql @@ -0,0 +1,159 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'pool_amount_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'PoolAmountUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items + FROM + evt_data +) +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed +) +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'token' THEN value END) AS token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(token) AS token, + TRY_CAST(next_value AS DOUBLE) / POWER(10, ERC20.decimals) AS next_value, + TRY_CAST(delta AS DOUBLE) / POWER(10, ERC20.decimals) AS delta + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20 + ON from_hex(EDP.token) = ERC20.contract_address +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql new file mode 100644 index 00000000000..bbf186f2248 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql @@ -0,0 +1,159 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'set_uint', + materialized = 'table' + ) +}} + +{%- set event_name = 'SetUint' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'baseKey' THEN value END) AS base_key, + MAX(CASE WHEN key_name = 'data' THEN value END) AS "data", + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value" + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(base_key) AS base_key, + from_hex("data") AS "data", + TRY_CAST("value" AS DOUBLE) / POWER(10, 30) AS "value" + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index d43cb91644a..d2fb067a0d9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -909,4 +909,272 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + + + - name: gmx_v2_avalanche_c_open_interest_in_tokens_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'open_interest_in_tokens_updated'] + description: | + Combines and processes decoded event data to produce a normalized dataset of updated orders + on the GMX platform for the Avalanche blockchain. + This model integrates data from the `open_interest_in_tokens_updated` table, enriching it with market-specific details. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OpenInterestInTokensUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market in which the order was updated, decoded from a hexadecimal value. + data_tests: + - not_null + - name: collateral_token + description: The token used as collateral for the order, decoded from a hexadecimal value. + data_tests: + - not_null + - name: is_long + description: A boolean flag indicating whether the order is a long position (true) or short position (false). + - name: next_value + description: | + Represents the updated open interest vlaue after the transaction. It is derived by normalizing + the raw value using index token decimals. + This ensures consistent scaling of the value across tokens with varying decimals. + - name: delta + description: | + Indicates the change in open interest. It is calculated by normalizing the raw delta value + using index token decimals. + This normalization accounts for token decimal differences and provides a standardized measure of change. + - name: tx_from + description: The address that initiated the transaction + - name: tx_to + description: The destination address of the transaction + - name: tx_index + description: Index value related to the transaction + + + - name: gmx_v2_avalanche_c_open_interest_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'open_interest_updated'] + description: | + Extracts and processes decoded event data for open interest updates on the GMX platform, + specifically on the Avalanche blockchain. This model normalizes data, including key metrics like + delta and next_value, ensuring consistent scaling based on token decimals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OpenInterestUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market associated with the open interest update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: collateral_token + description: The token used as collateral for the open interest, decoded from a hexadecimal value. + data_tests: + - not_null + - name: is_long + description: | + A boolean flag indicating whether the open interest update is for a long position (true) or short position (false). + data_type: boolean + - name: delta + description: | + Represents the change in open interest value, normalized by dividing the raw delta by `POWER(10, 30)`. + This ensures consistent scaling for values across tokens with varying decimals. + data_type: float + data_tests: + - not_null + - name: next_value + description: | + Indicates the updated open interest value after the transaction, normalized by dividing + the raw value by `POWER(10, 30)` to ensure consistent scaling across tokens. + data_type: float + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction. + + + - name: gmx_v2_avalanche_c_oracle_price_update + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'oracle_price_update'] + description: | + Processes decoded event data for Oracle Price Updates on the GMX platform in the Avalanche blockchain. + The model normalizes price data (min_price and max_price) using token-specific decimals and extracts + additional details such as the provider and token involved in the update. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OraclePriceUpdate' for this model + data_tests: + - not_null + - *msg_sender + - name: token + description: The token associated with the oracle price update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: provider + description: The address of the price provider, decoded from a hexadecimal value. + - name: min_price + description: The minimum price reported by the oracle. + data_tests: + - not_null + - name: max_price + description: The maximum price reported by the oracle. + data_tests: + - not_null + - name: timestamp + description: The timestamp of the oracle price update. + data_type: timestamp + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_avalanche_c_pool_amount_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'pool_amount_updated'] + description: | + Processes decoded event data for Pool Amount Updates on the GMX platform in the Avalanche blockchain. + This model normalizes token values (next_value and delta) based on token-specific decimals and extracts + additional details such as the market and token involved in the pool update. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'PoolAmountUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market associated with the pool update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: token + description: The token involved in the pool update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: next_value + description: | + The amount in the pool for the specified token, normalized by dividing the raw value + by `POWER(10, token_decimals)`, where `token_decimals` is derived from ERC-20 token metadata. + data_tests: + - not_null + - name: delta + description: | + The change in the pool amount for the specified token, normalized by dividing the raw value + by `POWER(10, token_decimals)`, where `token_decimals` is derived from ERC-20 token metadata. + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_avalanche_c_set_uint + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'set_uint'] + description: | + Processes decoded event data for `SetUint` events on the GMX platform in the Avalanche blockchain. + This model normalizes the value field and extracts additional details such as the base key and associated data, + ensuring compatibility with downstream analyses. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'SetUint' for this model + data_tests: + - not_null + - *msg_sender + - name: base_key + description: The base key associated with the event, decoded from a hexadecimal value. + data_tests: + - not_null + - name: data + description: The associated data field, decoded from a hexadecimal value. + data_tests: + - not_null + - name: value + description: | + The value associated with the event, normalized by dividing the raw value by `POWER(10, 30)`. + This ensures the value is represented in a standard floating-point format for analysis. + data_type: float + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql new file mode 100644 index 00000000000..d7d14e9c6cc --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql @@ -0,0 +1,183 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'open_interest_in_tokens_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OpenInterestInTokensUpdated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender, + varbinary_substring(topic1, 13, 20) as account + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender, + varbinary_substring(topic2, 13, 20) as account + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.market) AS market, + from_hex(EDP.collateral_token) AS collateral_token, + CAST(EDP.is_long AS BOOLEAN) AS is_long, + CAST(EDP.next_value AS DOUBLE) / POWER(10, MD.index_token_decimals) AS next_value, + CAST(EDP.delta AS DOUBLE) / POWER(10, MD.index_token_decimals) AS delta + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON from_hex(EDP.market) = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql new file mode 100644 index 00000000000..5574f500b53 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql @@ -0,0 +1,181 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'open_interest_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OpenInterestUpdated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(is_long AS BOOLEAN) AS is_long, + TRY_CAST(delta AS DOUBLE) / POWER(10, 30) AS delta, + TRY_CAST(next_value AS DOUBLE) / POWER(10, 30) AS next_value + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql new file mode 100644 index 00000000000..8ea6899f269 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql @@ -0,0 +1,149 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'oracle_price_update', + materialized = 'table' + ) +}} + +{%- set event_name = 'OraclePriceUpdate' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + AND evt_block_time > DATE '2023-08-01' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + AND evt_block_time > DATE '2023-08-01' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'token' THEN value END) AS token, + MAX(CASE WHEN key_name = 'provider' THEN value END) AS provider, + MAX(CASE WHEN key_name = 'minPrice' THEN value END) AS min_price, + MAX(CASE WHEN key_name = 'maxPrice' THEN value END) AS max_price, + MAX(CASE WHEN key_name = 'timestamp' THEN value END) AS "timestamp" + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(token) AS token, + from_hex(provider) AS provider, + TRY_CAST(min_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS min_price, + TRY_CAST(max_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS max_price, + CASE + WHEN "timestamp" = 0 THEN NULL + ELSE "timestamp" + END AS "timestamp" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_avalanche_c_erc20') }} AS ERC20 + ON from_hex(EDP.token) = ERC20.contract_address +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql new file mode 100644 index 00000000000..6f7621ea976 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql @@ -0,0 +1,159 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'pool_amount_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'PoolAmountUpdated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items + FROM + evt_data +) +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed +) +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'token' THEN value END) AS token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(token) AS token, + TRY_CAST(next_value AS DOUBLE) / POWER(10, ERC20.decimals) AS next_value, + TRY_CAST(delta AS DOUBLE) / POWER(10, ERC20.decimals) AS delta + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_avalanche_c_erc20') }} AS ERC20 + ON from_hex(EDP.token) = ERC20.contract_address +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql new file mode 100644 index 00000000000..bd1a5f2f06a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql @@ -0,0 +1,159 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'set_uint', + materialized = 'table' + ) +}} + +{%- set event_name = 'SetUint' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'baseKey' THEN value END) AS base_key, + MAX(CASE WHEN key_name = 'data' THEN value END) AS "data", + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value" + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(base_key) AS base_key, + from_hex("data") AS "data", + TRY_CAST("value" AS DOUBLE) / POWER(10, 30) AS "value" + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index bbe86ebd151..34efc3f9c6e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -909,4 +909,273 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + + + - name: gmx_v2_open_interest_in_tokens_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'open_interest_in_tokens_updated'] + description: | + Combines and processes decoded event data to produce a normalized dataset of updated orders + on the GMX platform for the Arbitrum and Avalanche blockchains. + This model integrates data from the `open_interest_in_tokens_updated` table, enriching it with market-specific details. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OpenInterestInTokensUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market in which the order was updated, decoded from a hexadecimal value. + data_tests: + - not_null + - name: collateral_token + description: The token used as collateral for the order, decoded from a hexadecimal value. + data_tests: + - not_null + - name: is_long + description: A boolean flag indicating whether the order is a long position (true) or short position (false). + - name: next_value + description: | + Represents the updated open interest vlaue after the transaction. It is derived by normalizing + the raw value using index token decimals. + This ensures consistent scaling of the value across tokens with varying decimals. + - name: delta + description: | + Indicates the change in open interest. It is calculated by normalizing the raw delta value + using index token decimals. + This normalization accounts for token decimal differences and provides a standardized measure of change. + - name: tx_from + description: The address that initiated the transaction + - name: tx_to + description: The destination address of the transaction + - name: tx_index + description: Index value related to the transaction + + + - name: gmx_v2_open_interest_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'open_interest_updated'] + description: | + Extracts and processes decoded event data for open interest updates on the GMX platform, + specifically on the Arbitrum and Avalanche blockchains. This model normalizes data, including key metrics like + delta and next_value, ensuring consistent scaling based on token decimals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OpentInterestUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market associated with the open interest update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: collateral_token + description: The token used as collateral for the open interest, decoded from a hexadecimal value. + data_tests: + - not_null + - name: is_long + description: | + A boolean flag indicating whether the open interest update is for a long position (true) or short position (false). + data_type: boolean + - name: delta + description: | + Represents the change in open interest value, normalized by dividing the raw delta by `POWER(10, 30)`. + This ensures consistent scaling for values across tokens with varying decimals. + data_type: float + data_tests: + - not_null + - name: next_value + description: | + Indicates the updated open interest value after the transaction, normalized by dividing + the raw value by `POWER(10, 30)` to ensure consistent scaling across tokens. + data_type: float + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction. + + + - name: gmx_v2_oracle_price_update + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'oracle_price_update'] + description: | + Processes decoded event data for Oracle Price Updates on the GMX platform in the Arbitrum and Avalanche blockchains. + The model normalizes price data (min_price and max_price) using token-specific decimals and extracts + additional details such as the provider and token involved in the update. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'OraclePriceUpdate' for this model + data_tests: + - not_null + - *msg_sender + - name: token + description: The token associated with the oracle price update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: provider + description: The address of the price provider, decoded from a hexadecimal value. + - name: min_price + description: The minimum price reported by the oracle. + data_tests: + - not_null + - name: max_price + description: The maximum price reported by the oracle. + data_tests: + - not_null + - name: timestamp + description: The timestamp of the oracle price update. + data_type: timestamp + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_pool_amount_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'pool_amount_updated'] + description: | + Processes decoded event data for Pool Amount Updates on the GMX platform in the Arbitrum and Avalanche blockchains. + This model normalizes token values (next_value and delta) based on token-specific decimals and extracts + additional details such as the market and token involved in the pool update. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'PoolAmountUpdated' for this model + data_tests: + - not_null + - *msg_sender + - name: market + description: The market associated with the pool update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: token + description: The token involved in the pool update, decoded from a hexadecimal value. + data_tests: + - not_null + - name: next_value + description: | + The amount in the pool for the specified token, normalized by dividing the raw value + by `POWER(10, token_decimals)`, where `token_decimals` is derived from ERC-20 token metadata. + data_tests: + - not_null + - name: delta + description: | + The change in the pool amount for the specified token, normalized by dividing the raw value + by `POWER(10, token_decimals)`, where `token_decimals` is derived from ERC-20 token metadata. + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_set_uint + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'set_uint'] + description: | + Processes decoded event data for `SetUint` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model normalizes the value field and extracts additional details such as the base key and associated data, + ensuring compatibility with downstream analyses. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: event_name + description: The type of event recorded, always 'SetUint' for this model + data_tests: + - not_null + - *msg_sender + - name: base_key + description: The base key associated with the event, decoded from a hexadecimal value. + data_tests: + - not_null + - name: data + description: The associated data field, decoded from a hexadecimal value. + data_tests: + - not_null + - name: value + description: | + The value associated with the event, normalized by dividing the raw value by `POWER(10, 30)`. + This ensures the value is represented in a standard floating-point format for analysis. + data_type: float + data_tests: + - not_null + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: tx_index + description: The index value related to the transaction, used for unique identification. + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_in_tokens_updated.sql new file mode 100644 index 00000000000..1bdd950e9a0 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_in_tokens_updated.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'open_interest_in_tokens_updated', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_index, + tx_from, + tx_to, + event_name, + msg_sender, + market, + collateral_token, + is_long, + next_value, + delta +FROM {{ ref('gmx_v2_' ~ chain ~ '_open_interest_in_tokens_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_updated.sql new file mode 100644 index 00000000000..60d0182af5c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_open_interest_updated.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'open_interest_updated', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_index, + tx_from, + tx_to, + event_name, + msg_sender, + market, + collateral_token, + is_long, + next_value, + delta +FROM {{ ref('gmx_v2_' ~ chain ~ '_open_interest_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_oracle_price_update.sql new file mode 100644 index 00000000000..5296ab83672 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_oracle_price_update.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'oracle_price_update', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_index, + tx_from, + tx_to, + event_name, + msg_sender, + token, + "provider", + min_price, + max_price, + "timestamp" +FROM {{ ref('gmx_v2_' ~ chain ~ '_oracle_price_update') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_pool_amount_updated.sql new file mode 100644 index 00000000000..f55114c2cc6 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_pool_amount_updated.sql @@ -0,0 +1,39 @@ +{{ config( + schema='gmx_v2', + alias = 'pool_amount_updated', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_index, + tx_from, + tx_to, + event_name, + msg_sender, + market, + token, + next_value, + delta +FROM {{ ref('gmx_v2_' ~ chain ~ '_pool_amount_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql new file mode 100644 index 00000000000..d534c170216 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql @@ -0,0 +1,38 @@ +{{ config( + schema='gmx_v2', + alias = 'set_uint', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_index, + tx_from, + tx_to, + event_name, + msg_sender, + base_key, + "data", + "value" +FROM {{ ref('gmx_v2_' ~ chain ~ '_set_uint') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + From 056d13f221b0b8bd93bdb06f769d059fb9c98e86 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Mon, 25 Nov 2024 20:33:21 +0200 Subject: [PATCH 02/14] Fixed error in OraclePriceUpdate event model --- .../arbitrum/gmx_v2_arbitrum_oracle_price_update.sql | 8 ++++---- .../gmx_v2_avalanche_c_oracle_price_update.sql | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql index 913c15b2598..267e0d58720 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -111,13 +111,13 @@ WITH evt_data_1 AS ( -- full data , full_data AS ( SELECT - blockchain, + ED.blockchain, block_time, DATE(block_time) AS block_date, block_number, ED.tx_hash, ED.index, - contract_address, + ED.contract_address, event_name, msg_sender, @@ -126,8 +126,8 @@ WITH evt_data_1 AS ( TRY_CAST(min_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS min_price, TRY_CAST(max_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS max_price, CASE - WHEN "timestamp" = 0 THEN NULL - ELSE "timestamp" + WHEN TRY_CAST("timestamp" AS DOUBLE) = 0 THEN NULL + ELSE TRY_CAST("timestamp" AS DOUBLE) END AS "timestamp" FROM evt_data AS ED diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql index 8ea6899f269..b00c14e51d6 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql @@ -111,13 +111,13 @@ WITH evt_data_1 AS ( -- full data , full_data AS ( SELECT - blockchain, + ED.blockchain, block_time, DATE(block_time) AS block_date, block_number, ED.tx_hash, ED.index, - contract_address, + ED.contract_address, event_name, msg_sender, @@ -126,10 +126,10 @@ WITH evt_data_1 AS ( TRY_CAST(min_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS min_price, TRY_CAST(max_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS max_price, CASE - WHEN "timestamp" = 0 THEN NULL - ELSE "timestamp" + WHEN TRY_CAST("timestamp" AS DOUBLE) = 0 THEN NULL + ELSE TRY_CAST("timestamp" AS DOUBLE) END AS "timestamp" - + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash From bcfc214c5a46519433e6a103a6e0ad3e7fb71413 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Mon, 25 Nov 2024 20:39:50 +0200 Subject: [PATCH 03/14] Fixed error in PoolAmountUpdated --- .../event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql | 4 ++-- .../avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql index 661a8a161e6..f29421ee619 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql @@ -125,13 +125,13 @@ WITH evt_data_1 AS ( -- full data , full_data AS ( SELECT - blockchain, + ED.blockchain, block_time, DATE(block_time) AS block_date, block_number, ED.tx_hash, ED.index, - contract_address, + ED.contract_address, event_name, msg_sender, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql index 6f7621ea976..05139b447e7 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql @@ -125,13 +125,13 @@ WITH evt_data_1 AS ( -- full data , full_data AS ( SELECT - blockchain, + ED.blockchain, block_time, DATE(block_time) AS block_date, block_number, ED.tx_hash, ED.index, - contract_address, + ED.contract_address, event_name, msg_sender, From 538a084829d2a7640c7965b8ef785fec550d1008 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Mon, 25 Nov 2024 20:44:36 +0200 Subject: [PATCH 04/14] Fix Error in SetUint Event model --- .../gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql | 6 +++--- .../gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql index bbf186f2248..bd92b2de14c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql @@ -139,9 +139,9 @@ WITH evt_data_1 AS ( event_name, msg_sender, - from_hex(base_key) AS base_key, - from_hex("data") AS "data", - TRY_CAST("value" AS DOUBLE) / POWER(10, 30) AS "value" + from_hex(EDP.base_key) AS base_key, + from_hex(EDP."data") AS "data", + TRY_CAST(EDP."value" AS DOUBLE) / POWER(10, 30) AS "value" FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql index bd1a5f2f06a..ce273774ff1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql @@ -139,9 +139,9 @@ WITH evt_data_1 AS ( event_name, msg_sender, - from_hex(base_key) AS base_key, - from_hex("data") AS "data", - TRY_CAST("value" AS DOUBLE) / POWER(10, 30) AS "value" + from_hex(EDP.base_key) AS base_key, + from_hex(EDP."data") AS "data", + TRY_CAST(EDP."value" AS DOUBLE) / POWER(10, 30) AS "value" FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash From 803449d222e2a5f26631711a5a15bf1c58e61449 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 16:25:44 +0200 Subject: [PATCH 05/14] Make small updates --- .../gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml | 5 ++--- .../gmx_v2_arbitrum_open_interest_in_tokens_updated.sql | 6 ++---- .../gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql | 2 +- .../event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml | 5 ++--- .../gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql | 6 ++---- .../gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql | 2 +- .../models/_projects/gmx/event/gmx_v2_event_schema.yml | 5 ++--- .../models/_projects/gmx/event/gmx_v2_set_uint.sql | 2 +- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index 4a2bd1a9e80..698a3593c18 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -1165,10 +1165,9 @@ models: description: The associated data field, decoded from a hexadecimal value. data_tests: - not_null - - name: value + - name: value_raw description: | - The value associated with the event, normalized by dividing the raw value by `POWER(10, 30)`. - This ensures the value is represented in a standard floating-point format for analysis. + The value associated with the event. data_type: float data_tests: - not_null diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql index 30565e97753..ec47d6d313c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql @@ -21,8 +21,7 @@ WITH evt_data_1 AS ( contract_address, eventName AS event_name, eventData AS data, - msgSender AS msg_sender, - varbinary_substring(topic1, 13, 20) as account + msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' ORDER BY evt_block_time ASC @@ -39,8 +38,7 @@ WITH evt_data_1 AS ( contract_address, eventName AS event_name, eventData AS data, - msgSender AS msg_sender, - varbinary_substring(topic2, 13, 20) as account + msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' ORDER BY evt_block_time ASC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql index bd92b2de14c..e457a3447e2 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql @@ -141,7 +141,7 @@ WITH evt_data_1 AS ( from_hex(EDP.base_key) AS base_key, from_hex(EDP."data") AS "data", - TRY_CAST(EDP."value" AS DOUBLE) / POWER(10, 30) AS "value" + TRY_CAST(EDP."value" AS DOUBLE) AS "value_raw" FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index d2fb067a0d9..374da3344d2 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -1165,10 +1165,9 @@ models: description: The associated data field, decoded from a hexadecimal value. data_tests: - not_null - - name: value + - name: value_raw description: | - The value associated with the event, normalized by dividing the raw value by `POWER(10, 30)`. - This ensures the value is represented in a standard floating-point format for analysis. + The value associated with the event. data_type: float data_tests: - not_null diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql index d7d14e9c6cc..c9245e10dda 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql @@ -21,8 +21,7 @@ WITH evt_data_1 AS ( contract_address, eventName AS event_name, eventData AS data, - msgSender AS msg_sender, - varbinary_substring(topic1, 13, 20) as account + msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' ORDER BY evt_block_time ASC @@ -39,8 +38,7 @@ WITH evt_data_1 AS ( contract_address, eventName AS event_name, eventData AS data, - msgSender AS msg_sender, - varbinary_substring(topic2, 13, 20) as account + msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' ORDER BY evt_block_time ASC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql index ce273774ff1..6454497af61 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql @@ -141,7 +141,7 @@ WITH evt_data_1 AS ( from_hex(EDP.base_key) AS base_key, from_hex(EDP."data") AS "data", - TRY_CAST(EDP."value" AS DOUBLE) / POWER(10, 30) AS "value" + TRY_CAST(EDP."value" AS DOUBLE) AS "value_raw" FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index 34efc3f9c6e..c14d4a5fea4 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -1165,10 +1165,9 @@ models: description: The associated data field, decoded from a hexadecimal value. data_tests: - not_null - - name: value + - name: value_raw description: | - The value associated with the event, normalized by dividing the raw value by `POWER(10, 30)`. - This ensures the value is represented in a standard floating-point format for analysis. + The value associated with the event. data_type: float data_tests: - not_null diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql index d534c170216..4dbe5e181f8 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_set_uint.sql @@ -29,7 +29,7 @@ SELECT msg_sender, base_key, "data", - "value" + "value_raw" FROM {{ ref('gmx_v2_' ~ chain ~ '_set_uint') }} {% if not loop.last %} UNION ALL From 4a38a041c4c2d40c5578cc809b76c660d3cdb768 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 16:53:31 +0200 Subject: [PATCH 06/14] empty commit to run action again --- .../gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql index 267e0d58720..289ee37fd10 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -138,7 +138,7 @@ WITH evt_data_1 AS ( ON from_hex(EDP.token) = ERC20.contract_address ) ---can be removed once decoded tables are fully denormalized +-- can be removed once decoded tables are fully denormalized {{ add_tx_columns( model_cte = 'full_data' From fbef76b241c9230666ca8f633897e394a9078c9d Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Sun, 1 Dec 2024 19:15:41 +0800 Subject: [PATCH 07/14] Modify gmx_v2_arbitrum_open_interest_updated to incremental view --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 6 +++++- .../gmx_v2_arbitrum_open_interest_updated.sql | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index 698a3593c18..b2ded0096b9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -978,7 +978,11 @@ models: Extracts and processes decoded event data for open interest updates on the GMX platform, specifically on the Arbitrum blockchain. This model normalizes data, including key metrics like delta and next_value, ensuring consistent scaling based on token decimals. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql index c981bad6e6f..ddc123a21e3 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql @@ -2,7 +2,10 @@ config( schema = 'gmx_v2_arbitrum', alias = 'open_interest_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'delete+insert', + tags = ['increment_daily'] ) }} @@ -24,7 +27,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +46,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables @@ -178,4 +185,3 @@ WITH evt_data_1 AS ( , columns = ['from', 'to', 'index'] ) }} - From 070b3ed5c436987159ddd6083ac2560f74bd0ad5 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Sun, 1 Dec 2024 19:23:42 +0800 Subject: [PATCH 08/14] Fix incremental strategy --- .../event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql index ddc123a21e3..acbf9774525 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql @@ -4,9 +4,8 @@ alias = 'open_interest_updated', materialized = 'incremental', unique_key = ['tx_hash', 'index'], - incremental_strategy = 'delete+insert', - tags = ['increment_daily'] - ) + incremental_strategy = 'merge' + ) }} {%- set event_name = 'OpenInterestUpdated' -%} From 857a50cb2223f669b43c2d4980e774b0400d8ca3 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Tue, 3 Dec 2024 22:52:14 +0200 Subject: [PATCH 09/14] Add 2 new Event Models --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 72 +++++++++ .../gmx_v2_arbitrum_execution_fee_refund.sql | 141 ++++++++++++++++++ .../gmx_v2_arbitrum_keeper_execution_fee.sql | 141 ++++++++++++++++++ .../gmx_v2_avalanche_c_event_schema.yml | 72 +++++++++ ...mx_v2_avalanche_c_execution_fee_refund.sql | 141 ++++++++++++++++++ ...mx_v2_avalanche_c_keeper_execution_fee.sql | 141 ++++++++++++++++++ .../gmx/event/gmx_v2_event_schema.yml | 73 +++++++++ .../gmx/event/gmx_v2_execution_fee_refund.sql | 36 +++++ .../gmx/event/gmx_v2_keeper_execution_fee.sql | 36 +++++ 9 files changed, 853 insertions(+) create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_execution_fee_refund.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_keeper_execution_fee.sql diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index b2ded0096b9..19c2f14baea 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -1181,3 +1181,75 @@ models: description: The destination address of the transaction. - name: tx_index description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_arbitrum_execution_fee_refund + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'execution_fee_refund'] + description: | + Processes decoded event data for `ExecutionFeeRefund` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the refund amount, receiver, and transaction details to + enable analysis of refunded execution fees. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ExecutionFeeRefund` for this model. + data_tests: + - not_null + - *msg_sender + - name: receiver + description: The address that received the refunded execution fee. + - name: refund_fee_amount + description: The amount of the refunded execution fee, denominated in the native token of the blockchain (e.g., ETH). + + + - name: gmx_v2_arbitrum_keeper_execution_fee + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'keeper_execution_fee'] + description: | + Processes decoded event data for `KeeperExecutionFee` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the keeper's address, execution fee amount, and transaction details, enabling + analysis of fees associated with keeper-based executions. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `KeeperExecutionFee` for this model. + data_tests: + - not_null + - *msg_sender + - name: keeper + description: The address of the keeper responsible for executing the transaction. + - name: execution_fee_amount + description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql new file mode 100644 index 00000000000..c9a1087fa46 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql @@ -0,0 +1,141 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'execution_fee_refund', + materialized = 'table' + ) +}} + +{%- set event_name = 'ExecutionFeeRefund' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'refundFeeAmount' THEN value END) AS refund_fee_amount + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.receiver) AS receiver, + CAST(EDP.refund_fee_amount AS DOUBLE) / POWER(10, 18) AS refund_fee_amount + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql new file mode 100644 index 00000000000..fb88cf0c277 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql @@ -0,0 +1,141 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'keeper_execution_fee', + materialized = 'table' + ) +}} + +{%- set event_name = 'KeeperExecutionFee' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'keeper' THEN value END) AS keeper, + MAX(CASE WHEN key_name = 'executionFeeAmount' THEN value END) AS execution_fee_amount + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.keeper) AS keeper, + CAST(EDP.execution_fee_amount AS DOUBLE) / POWER(10, 18) AS execution_fee_amount + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index 374da3344d2..fe0276bd17c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -1177,3 +1177,75 @@ models: description: The destination address of the transaction. - name: tx_index description: The index value related to the transaction, used for unique identification. + + + - name: gmx_v2_avalanche_c_execution_fee_refund + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'execution_fee_refund'] + description: | + Processes decoded event data for `ExecutionFeeRefund` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the refund amount, receiver, and transaction details to + enable analysis of refunded execution fees. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ExecutionFeeRefund` for this model. + data_tests: + - not_null + - *msg_sender + - name: receiver + description: The address that received the refunded execution fee. + - name: refund_fee_amount + description: The amount of the refunded execution fee, denominated in the native token of the blockchain (e.g., ETH). + + + - name: gmx_v2_avalanche_c_keeper_execution_fee + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'keeper_execution_fee'] + description: | + Processes decoded event data for `KeeperExecutionFee` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the keeper's address, execution fee amount, and transaction details, enabling + analysis of fees associated with keeper-based executions. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `KeeperExecutionFee` for this model. + data_tests: + - not_null + - *msg_sender + - name: keeper + description: The address of the keeper responsible for executing the transaction. + - name: execution_fee_amount + description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql new file mode 100644 index 00000000000..57b15e1e655 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql @@ -0,0 +1,141 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'execution_fee_refund', + materialized = 'table' + ) +}} + +{%- set event_name = 'ExecutionFeeRefund' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'refundFeeAmount' THEN value END) AS refund_fee_amount + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.receiver) AS receiver, + CAST(EDP.refund_fee_amount AS DOUBLE) / POWER(10, 18) AS refund_fee_amount + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql new file mode 100644 index 00000000000..d4caf1ae74a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql @@ -0,0 +1,141 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'keeper_execution_fee', + materialized = 'table' + ) +}} + +{%- set event_name = 'KeeperExecutionFee' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'keeper' THEN value END) AS keeper, + MAX(CASE WHEN key_name = 'executionFeeAmount' THEN value END) AS execution_fee_amount + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.keeper) AS keeper, + CAST(EDP.execution_fee_amount AS DOUBLE) / POWER(10, 18) AS execution_fee_amount + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index c14d4a5fea4..f7bdaad6408 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -1178,3 +1178,76 @@ models: - name: tx_index description: The index value related to the transaction, used for unique identification. + + - name: gmx_v2_execution_fee_refund + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'execution_fee_refund'] + description: | + Processes decoded event data for `ExecutionFeeRefund` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the refund amount, receiver, and transaction details to + enable analysis of refunded execution fees. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ExecutionFeeRefund` for this model. + data_tests: + - not_null + - *msg_sender + - name: receiver + description: The address that received the refunded execution fee. + - name: refund_fee_amount + description: The amount of the refunded execution fee, denominated in the native token of the blockchain (e.g., ETH). + + + - name: gmx_v2_keeper_execution_fee + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'keeper_execution_fee'] + description: | + Processes decoded event data for `KeeperExecutionFee` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the keeper's address, execution fee amount, and transaction details, enabling + analysis of fees associated with keeper-based executions. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `KeeperExecutionFee` for this model. + data_tests: + - not_null + - *msg_sender + - name: keeper + description: The address of the keeper responsible for executing the transaction. + - name: execution_fee_amount + description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_execution_fee_refund.sql new file mode 100644 index 00000000000..a4f2675416f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_execution_fee_refund.sql @@ -0,0 +1,36 @@ +{{ config( + schema='gmx_v2', + alias = 'execution_fee_refund', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + receiver, + refund_fee_amount +FROM {{ ref('gmx_v2_' ~ chain ~ '_execution_fee_refund') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_keeper_execution_fee.sql new file mode 100644 index 00000000000..a24684122d9 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_keeper_execution_fee.sql @@ -0,0 +1,36 @@ +{{ config( + schema='gmx_v2', + alias = 'keeper_execution_fee', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + keeper, + execution_fee_amount +FROM {{ ref('gmx_v2_' ~ chain ~ '_keeper_execution_fee') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + From 500438fc75e668cc943964fb94d0aa24a63856cb Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Wed, 4 Dec 2024 10:16:55 +0200 Subject: [PATCH 10/14] Added Incremental Materialization to Main Event Models --- .../gmx_v2_arbitrum_execution_fee_refund.sql | 12 +++++++++--- .../gmx_v2_arbitrum_keeper_execution_fee.sql | 12 +++++++++--- ...x_v2_arbitrum_open_interest_in_tokens_updated.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_oracle_price_update.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_order_cancelled.sql | 12 +++++++++--- .../event/arbitrum/gmx_v2_arbitrum_order_created.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_order_executed.sql | 12 +++++++++--- .../event/arbitrum/gmx_v2_arbitrum_order_frozen.sql | 12 +++++++++--- .../event/arbitrum/gmx_v2_arbitrum_order_updated.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_position_decrease.sql | 12 +++++++++--- .../gmx_v2_arbitrum_position_fees_collected.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_position_fees_info.sql | 12 +++++++++--- .../arbitrum/gmx_v2_arbitrum_position_increase.sql | 12 +++++++++--- .../gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_execution_fee_refund.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_keeper_execution_fee.sql | 12 +++++++++--- ...2_avalanche_c_open_interest_in_tokens_updated.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_open_interest_updated.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_oracle_price_update.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_order_cancelled.sql | 12 +++++++++--- .../avalanche_c/gmx_v2_avalanche_c_order_created.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_order_executed.sql | 12 +++++++++--- .../avalanche_c/gmx_v2_avalanche_c_order_frozen.sql | 12 +++++++++--- .../avalanche_c/gmx_v2_avalanche_c_order_updated.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_pool_amount_updated.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_position_decrease.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_position_fees_collected.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_position_fees_info.sql | 12 +++++++++--- .../gmx_v2_avalanche_c_position_increase.sql | 12 +++++++++--- .../avalanche_c/gmx_v2_avalanche_c_set_uint.sql | 12 +++++++++--- 31 files changed, 279 insertions(+), 93 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql index c9a1087fa46..c20cd8fe4f9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'execution_fee_refund', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql index fb88cf0c277..e7f2e0ee0f8 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'keeper_execution_fee', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql index ec47d6d313c..3d73a35efa3 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'open_interest_in_tokens_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql index 289ee37fd10..72ee41bbc0a 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'oracle_price_update', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -25,7 +27,9 @@ WITH evt_data_1 AS ( FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' AND evt_block_time > DATE '2023-08-01' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -43,7 +47,9 @@ WITH evt_data_1 AS ( FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' AND evt_block_time > DATE '2023-08-01' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql index 84fe7f7b326..b24ca5fafe2 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'order_cancelled', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 4339e211083..34d70690f8b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'order_created', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql index b373d356708..a7a9c6c1c62 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'order_executed', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql index b0cc9d09f62..289f146dcb3 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'order_frozen', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql index 4fe2a489b05..7b16ee4d6d9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'order_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql index f29421ee619..d1cba68b7fa 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'pool_amount_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql index d5cfa5c134e..b05f68e1501 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'position_decrease', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql index fa7d065f5fa..664aa2bbb8a 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'position_fees_collected', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql index 4a7432cea9b..44936217c17 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'position_fees_info', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql index bddd6f5c9f6..1129f3b860f 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'position_increase', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql index e457a3447e2..c3a1085676b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_arbitrum', alias = 'set_uint', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql index 57b15e1e655..2fa2e95fe43 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'execution_fee_refund', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql index d4caf1ae74a..3a6c16d6009 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'keeper_execution_fee', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql index c9245e10dda..d601703949e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'open_interest_in_tokens_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql index 5574f500b53..cd88f284349 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'open_interest_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql index b00c14e51d6..53c392e3d3a 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'oracle_price_update', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -25,7 +27,9 @@ WITH evt_data_1 AS ( FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' AND evt_block_time > DATE '2023-08-01' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -43,7 +47,9 @@ WITH evt_data_1 AS ( FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' AND evt_block_time > DATE '2023-08-01' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql index ce8206ba85c..e974c4d20e5 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'order_cancelled', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql index cec7a4baf06..29be393151d 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'order_created', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql index 677afcce2bd..d0f775d745e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'order_executed', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql index 0de9538f4a7..6e9b7ce230c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'order_frozen', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql index 5f0b28869f7..4498fb02930 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'order_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql index 05139b447e7..17c7d2934da 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'pool_amount_updated', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql index e82cce31001..a5edbae87fc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'position_decrease', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql index 2241dfb0e56..bba278bcb37 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'position_fees_collected', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql index 0e71e6ccfdf..ce0d96d1e3e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'position_fees_info', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql index a4b6b107a40..52d9bd0cddb 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'position_increase', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -23,7 +25,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -40,7 +44,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql index 6454497af61..41e06b529d5 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql @@ -2,7 +2,9 @@ config( schema = 'gmx_v2_avalanche_c', alias = 'set_uint', - materialized = 'table' + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' ) }} @@ -24,7 +26,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) , evt_data_2 AS ( @@ -41,7 +45,9 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} ) -- unite 2 tables From 1bc82ffe426f3eadc53fd4fc7c1c93c880bb09af Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Wed, 4 Dec 2024 10:19:15 +0200 Subject: [PATCH 11/14] Updated OraclePriceUpdate Event Model --- .../gmx_v2_arbitrum_oracle_price_update.sql | 14 ++++++++------ .../gmx_v2_avalanche_c_oracle_price_update.sql | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql index 72ee41bbc0a..1e9216afe01 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -26,10 +26,11 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - AND evt_block_time > DATE '2023-08-01' - {% if is_incremental() %} + {% if is_incremental() %} AND {{ incremental_predicate('evt_block_time') }} - {% endif %} + {% else %} + AND evt_block_time > DATE '2023-08-01' + {% endif %} ) , evt_data_2 AS ( @@ -46,10 +47,11 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - AND evt_block_time > DATE '2023-08-01' - {% if is_incremental() %} + {% if is_incremental() %} AND {{ incremental_predicate('evt_block_time') }} - {% endif %} + {% else %} + AND evt_block_time > DATE '2023-08-01' + {% endif %} ) -- unite 2 tables diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql index 53c392e3d3a..14f2540c8f6 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql @@ -26,10 +26,11 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} WHERE eventName = '{{ event_name }}' - AND evt_block_time > DATE '2023-08-01' - {% if is_incremental() %} + {% if is_incremental() %} AND {{ incremental_predicate('evt_block_time') }} - {% endif %} + {% else %} + AND evt_block_time > DATE '2023-08-01' + {% endif %} ) , evt_data_2 AS ( @@ -46,10 +47,11 @@ WITH evt_data_1 AS ( msgSender AS msg_sender FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} WHERE eventName = '{{ event_name }}' - AND evt_block_time > DATE '2023-08-01' - {% if is_incremental() %} + {% if is_incremental() %} AND {{ incremental_predicate('evt_block_time') }} - {% endif %} + {% else %} + AND evt_block_time > DATE '2023-08-01' + {% endif %} ) -- unite 2 tables From b47cf520f003ff79b7ac8b195c51e8d6f4d13794 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 5 Dec 2024 11:31:38 +0200 Subject: [PATCH 12/14] Empty commit --- .../models/_projects/gmx/event/gmx_v2_position_decrease.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_decrease.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_decrease.sql index 1970473375e..30f8ebfff2b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_decrease.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_decrease.sql @@ -57,4 +57,4 @@ FROM {{ ref('gmx_v2_' ~ chain ~ '_position_decrease') }} {% if not loop.last %} UNION ALL {% endif %} -{%- endfor -%} \ No newline at end of file +{%- endfor -%} From 4eb6639aae796dbe894d19e90cb4a5c6bef1ba56 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 5 Dec 2024 13:50:41 +0200 Subject: [PATCH 13/14] Removed tests for the market column This error arises because the other model has not been updated yet. I believe that is the reason. The corresponding table will be updated on schedule, and then the market column will no longer be NULL. --- .../gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml | 2 -- .../gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml | 2 -- .../models/_projects/gmx/event/gmx_v2_event_schema.yml | 2 -- 3 files changed, 6 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index 41ff069f9c6..bfe7feb2e7c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -925,8 +925,6 @@ models: - not_null - name: market description: The market in which the order was updated - data_tests: - - not_null - name: account description: The address associated with the order. - *size_delta_usd diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index 98cec5662cc..ca73ec61840 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -925,8 +925,6 @@ models: - not_null - name: market description: The market in which the order was updated. - data_tests: - - not_null - name: account description: The address associated with the order. - *size_delta_usd diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index 47c16c65921..bdc21de5862 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -925,8 +925,6 @@ models: - not_null - name: market description: The market in which the order was updated. - data_tests: - - not_null - name: account description: The address associated with the order. - *size_delta_usd From 3c2f452c9857a92136578bee802aadb87fa7854e Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 5 Dec 2024 14:02:09 +0200 Subject: [PATCH 14/14] added data_tests --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 87 ++++++++++++++---- .../gmx_v2_avalanche_c_event_schema.yml | 92 +++++++++++++++---- .../gmx/event/gmx_v2_event_schema.yml | 5 + 3 files changed, 152 insertions(+), 32 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index bfe7feb2e7c..dfc436cc271 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -13,7 +13,11 @@ models: Extracts and decodes the `OrderCreated` event log data from the Arbitrum blockchain. This model processes log entries related to created orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - &blockchain name: blockchain @@ -187,7 +191,11 @@ models: Extracts and decodes the `OrderExecuted` event log data from the Arbitrum blockchain. This model processes log entries related to executed orders, extracting key variables such as account addresses, event keys, and integer values. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -230,7 +238,11 @@ models: Extracts and decodes the `OrderCancelled` event log data from the Arbitrum blockchain. This model processes log entries related to cancelled orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -344,7 +356,11 @@ models: This model extracts and parses `PositionIncrease` events from the Arbitrum blockchain. It includes transaction details, addresses, and various metrics related to the event, such as market data, collateral amounts, price impacts, and more. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -477,7 +493,11 @@ models: This model extracts and parses `PositionDecrease` events from the Arbitrum blockchain. It includes transaction details, addresses, and various metrics related to the event, such as market data, collateral amounts, price impacts, and more. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -558,7 +578,11 @@ models: This model extracts and parses `PositionFeesCollected` events from the Arbitrum blockchain. It includes details about the transaction, addresses involved, and various metrics related to fees collected from positions, including fee amounts and related market data. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -775,7 +799,11 @@ models: This model extracts and parses `PositionFeesInfo` events from the Arbitrum blockchain. It includes details about the transaction, addresses involved, and various metrics related to position fees, including fee amounts and related market data. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -858,8 +886,7 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - tx_hash - - key - + - index columns: - *blockchain - *block_time @@ -903,7 +930,11 @@ models: Extracts and decodes the `OrderUpdated` event log data from the Arbitrum blockchain. This model processes log entries related to updated orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -952,7 +983,11 @@ models: Combines and processes decoded event data to produce a normalized dataset of updated orders on the GMX platform for the Arbitrum blockchain. This model integrates data from the `open_interest_in_tokens_updated` table, enriching it with market-specific details. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1070,7 +1105,11 @@ models: Processes decoded event data for Oracle Price Updates on the GMX platform in the Arbitrum blockchain. The model normalizes price data (min_price and max_price) using token-specific decimals and extracts additional details such as the provider and token involved in the update. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1121,7 +1160,11 @@ models: Processes decoded event data for Pool Amount Updates on the GMX platform in the Arbitrum blockchain. This model normalizes token values (next_value and delta) based on token-specific decimals and extracts additional details such as the market and token involved in the pool update. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1175,7 +1218,11 @@ models: Processes decoded event data for `SetUint` events on the GMX platform in the Arbitrum blockchain. This model normalizes the value field and extracts additional details such as the base key and associated data, ensuring compatibility with downstream analyses. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1223,7 +1270,11 @@ models: Processes decoded event data for `ExecutionFeeRefund` events on the GMX platform in the Arbitrum blockchain. This model extracts key details such as the refund amount, receiver, and transaction details to enable analysis of refunded execution fees. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1259,7 +1310,11 @@ models: Processes decoded event data for `KeeperExecutionFee` events on the GMX platform in the Arbitrum blockchain. This model extracts key details such as the keeper's address, execution fee amount, and transaction details, enabling analysis of fees associated with keeper-based executions. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index ca73ec61840..bd0636b0db1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -13,7 +13,11 @@ models: Extracts and decodes the `OrderCreated` event log data from the Avalanche blockchain. This model processes log entries related to created orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - &blockchain name: blockchain @@ -187,7 +191,11 @@ models: Extracts and decodes the `OrderExecuted` event log data from the Avalanche blockchain. This model processes log entries related to executed orders, extracting key variables such as account addresses, event keys, and integer values. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -230,7 +238,11 @@ models: Extracts and decodes the `OrderCancelled` event log data from the Avalanche blockchain. This model processes log entries related to cancelled orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -344,7 +356,11 @@ models: This model extracts and parses `PositionIncrease` events from the Avalanche blockchain. It includes transaction details, addresses, and various metrics related to the event, such as market data, collateral amounts, price impacts, and more. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -477,7 +493,11 @@ models: This model extracts and parses `PositionDecrease` events from the Avalanche blockchain. It includes transaction details, addresses, and various metrics related to the event, such as market data, collateral amounts, price impacts, and more. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -558,7 +578,11 @@ models: This model extracts and parses `PositionFeesCollected` events from the Avalanche blockchain. It includes details about the transaction, addresses involved, and various metrics related to fees collected from positions, including fee amounts and related market data. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -775,7 +799,11 @@ models: This model extracts and parses `PositionFeesInfo` events from the Avalanche blockchain. It includes details about the transaction, addresses involved, and various metrics related to position fees, including fee amounts and related market data. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -858,7 +886,7 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - tx_hash - - key + - index columns: - *blockchain @@ -903,7 +931,11 @@ models: Extracts and decodes the `OrderUpdated` event log data from the Avalanche blockchain. This model processes log entries related to updated orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -952,7 +984,11 @@ models: Combines and processes decoded event data to produce a normalized dataset of updated orders on the GMX platform for the Avalanche blockchain. This model integrates data from the `open_interest_in_tokens_updated` table, enriching it with market-specific details. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1006,7 +1042,11 @@ models: Extracts and processes decoded event data for open interest updates on the GMX platform, specifically on the Avalanche blockchain. This model normalizes data, including key metrics like delta and next_value, ensuring consistent scaling based on token decimals. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1066,7 +1106,11 @@ models: Processes decoded event data for Oracle Price Updates on the GMX platform in the Avalanche blockchain. The model normalizes price data (min_price and max_price) using token-specific decimals and extracts additional details such as the provider and token involved in the update. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1117,7 +1161,11 @@ models: Processes decoded event data for Pool Amount Updates on the GMX platform in the Avalanche blockchain. This model normalizes token values (next_value and delta) based on token-specific decimals and extracts additional details such as the market and token involved in the pool update. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1171,7 +1219,11 @@ models: Processes decoded event data for `SetUint` events on the GMX platform in the Avalanche blockchain. This model normalizes the value field and extracts additional details such as the base key and associated data, ensuring compatibility with downstream analyses. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1219,7 +1271,11 @@ models: Processes decoded event data for `ExecutionFeeRefund` events on the GMX platform in the Avalanche blockchain. This model extracts key details such as the refund amount, receiver, and transaction details to enable analysis of refunded execution fees. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time @@ -1255,7 +1311,11 @@ models: Processes decoded event data for `KeeperExecutionFee` events on the GMX platform in the Avalanche blockchain. This model extracts key details such as the keeper's address, execution fee amount, and transaction details, enabling analysis of fees associated with keeper-based executions. - + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - *blockchain - *block_time diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index bdc21de5862..39ea55ccbab 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -13,6 +13,11 @@ models: Extracts and decodes the `OrderCreated` event log data from the Arbitrum and Avalanche blockchains. This model processes log entries related to created orders, extracting key variables such as account addresses, event keys, and strings representing the reason for cancellation. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index columns: - &blockchain