From dd8fbf749d19b077bf101c584eeedeeb18a58b06 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Fri, 20 Dec 2024 12:41:37 +0200 Subject: [PATCH] New Event Models for GMX v2 (next iteration) (#7314) * Add 36 models and update schemas * Fix errors in 2 schemas * Added token contracts in 2 events * Added 2 new models * Replace UNION with UNION ALL * Added uniqueness tests --------- Co-authored-by: Huang Geyang Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- ...imable_funding_amount_per_size_updated.sql | 195 ++++ .../gmx_v2_arbitrum_deposit_cancelled.sql | 187 ++++ .../gmx_v2_arbitrum_deposit_created.sql | 258 +++++ .../gmx_v2_arbitrum_deposit_executed.sql | 199 ++++ .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 989 +++++++++++++++++- .../gmx_v2_arbitrum_execution_fee_refund.sql | 2 +- ...um_funding_fee_amount_per_size_updated.sql | 195 ++++ .../arbitrum/gmx_v2_arbitrum_glv_created.sql | 157 +++ .../gmx_v2_arbitrum_glv_deposit_cancelled.sql | 187 ++++ .../gmx_v2_arbitrum_glv_deposit_created.sql | 269 +++++ .../gmx_v2_arbitrum_glv_deposit_executed.sql | 186 ++++ .../gmx_v2_arbitrum_glv_shift_cancelled.sql | 167 +++ .../gmx_v2_arbitrum_glv_shift_created.sql | 200 ++++ .../gmx_v2_arbitrum_glv_shift_executed.sql | 165 +++ ...x_v2_arbitrum_glv_withdrawal_cancelled.sql | 187 ++++ ...gmx_v2_arbitrum_glv_withdrawal_created.sql | 255 +++++ ...mx_v2_arbitrum_glv_withdrawal_executed.sql | 149 +++ .../gmx_v2_arbitrum_keeper_execution_fee.sql | 2 +- .../gmx_v2_arbitrum_market_created.sql | 2 +- ...bitrum_open_interest_in_tokens_updated.sql | 2 +- .../gmx_v2_arbitrum_open_interest_updated.sql | 2 +- .../gmx_v2_arbitrum_oracle_price_update.sql | 2 +- .../gmx_v2_arbitrum_order_cancelled.sql | 2 +- .../gmx_v2_arbitrum_order_executed.sql | 2 +- .../arbitrum/gmx_v2_arbitrum_order_frozen.sql | 2 +- .../gmx_v2_arbitrum_pool_amount_updated.sql | 2 +- .../gmx_v2_arbitrum_position_decrease.sql | 2 +- ...mx_v2_arbitrum_position_fees_collected.sql | 2 +- .../gmx_v2_arbitrum_position_fees_info.sql | 2 +- .../gmx_v2_arbitrum_position_increase.sql | 2 +- .../arbitrum/gmx_v2_arbitrum_set_uint.sql | 2 +- .../gmx_v2_arbitrum_shift_created.sql | 218 ++++ .../gmx_v2_arbitrum_shift_executed.sql | 168 +++ .../gmx_v2_arbitrum_withdrawal_cancelled.sql | 187 ++++ .../gmx_v2_arbitrum_withdrawal_created.sql | 243 +++++ .../gmx_v2_arbitrum_withdrawal_executed.sql | 169 +++ ...imable_funding_amount_per_size_updated.sql | 195 ++++ .../gmx_v2_avalanche_c_deposit_cancelled.sql | 187 ++++ .../gmx_v2_avalanche_c_deposit_created.sql | 258 +++++ .../gmx_v2_avalanche_c_deposit_executed.sql | 199 ++++ .../gmx_v2_avalanche_c_event_schema.yml | 986 ++++++++++++++++- ...mx_v2_avalanche_c_execution_fee_refund.sql | 2 +- ..._c_funding_fee_amount_per_size_updated.sql | 195 ++++ .../gmx_v2_avalanche_c_glv_created.sql | 157 +++ ...x_v2_avalanche_c_glv_deposit_cancelled.sql | 187 ++++ ...gmx_v2_avalanche_c_glv_deposit_created.sql | 269 +++++ ...mx_v2_avalanche_c_glv_deposit_executed.sql | 186 ++++ ...gmx_v2_avalanche_c_glv_shift_cancelled.sql | 167 +++ .../gmx_v2_avalanche_c_glv_shift_created.sql | 200 ++++ .../gmx_v2_avalanche_c_glv_shift_executed.sql | 165 +++ ...2_avalanche_c_glv_withdrawal_cancelled.sql | 187 ++++ ..._v2_avalanche_c_glv_withdrawal_created.sql | 255 +++++ ...v2_avalanche_c_glv_withdrawal_executed.sql | 149 +++ ...mx_v2_avalanche_c_keeper_execution_fee.sql | 2 +- .../gmx_v2_avalanche_c_market_created.sql | 2 +- ...nche_c_open_interest_in_tokens_updated.sql | 2 +- ...x_v2_avalanche_c_open_interest_updated.sql | 2 +- ...gmx_v2_avalanche_c_oracle_price_update.sql | 2 +- .../gmx_v2_avalanche_c_order_cancelled.sql | 2 +- .../gmx_v2_avalanche_c_order_executed.sql | 2 +- .../gmx_v2_avalanche_c_order_frozen.sql | 2 +- ...gmx_v2_avalanche_c_pool_amount_updated.sql | 2 +- .../gmx_v2_avalanche_c_position_decrease.sql | 2 +- ...v2_avalanche_c_position_fees_collected.sql | 2 +- .../gmx_v2_avalanche_c_position_fees_info.sql | 2 +- .../gmx_v2_avalanche_c_position_increase.sql | 2 +- .../gmx_v2_avalanche_c_set_uint.sql | 2 +- .../gmx_v2_avalanche_c_shift_created.sql | 218 ++++ .../gmx_v2_avalanche_c_shift_executed.sql | 168 +++ ...mx_v2_avalanche_c_withdrawal_cancelled.sql | 187 ++++ .../gmx_v2_avalanche_c_withdrawal_created.sql | 243 +++++ ...gmx_v2_avalanche_c_withdrawal_executed.sql | 169 +++ ...imable_funding_amount_per_size_updated.sql | 41 + .../gmx/event/gmx_v2_deposit_cancelled.sql | 39 + .../gmx/event/gmx_v2_deposit_created.sql | 51 + .../gmx/event/gmx_v2_deposit_executed.sql | 43 + .../gmx/event/gmx_v2_event_schema.yml | 905 +++++++++++++++- ...v2_funding_fee_amount_per_size_updated.sql | 40 + .../gmx/event/gmx_v2_glv_created.sql | 44 + .../event/gmx_v2_glv_deposit_cancelled.sql | 42 + .../gmx/event/gmx_v2_glv_deposit_created.sql | 56 + .../gmx/event/gmx_v2_glv_deposit_executed.sql | 42 + .../gmx/event/gmx_v2_glv_shift_cancelled.sql | 41 + .../gmx/event/gmx_v2_glv_shift_created.sql | 44 + .../gmx/event/gmx_v2_glv_shift_executed.sql | 39 + .../event/gmx_v2_glv_withdrawal_cancelled.sql | 42 + .../event/gmx_v2_glv_withdrawal_created.sql | 52 + .../event/gmx_v2_glv_withdrawal_executed.sql | 40 + .../gmx/event/gmx_v2_shift_created.sql | 49 + .../gmx/event/gmx_v2_shift_executed.sql | 41 + .../gmx/event/gmx_v2_withdrawal_cancelled.sql | 41 + .../gmx/event/gmx_v2_withdrawal_created.sql | 49 + .../gmx/event/gmx_v2_withdrawal_executed.sql | 40 + .../gmx_v2_arbitrum_glv_markets_data.sql | 24 + .../arbitrum/gmx_v2_arbitrum_markets_data.sql | 3 + .../gmx_v2_arbitrum_tokens_schema.yml | 44 +- .../gmx_v2_avalanche_c_glv_markets_data.sql | 24 + .../gmx_v2_avalanche_c_markets_data.sql | 3 + .../gmx_v2_avalanche_c_tokens_schema.yml | 42 + .../gmx/tokens/gmx_v2_glv_markets_data.sql | 34 + .../gmx/tokens/gmx_v2_markets_data.sql | 3 + .../gmx/tokens/gmx_v2_tokens_schema.yml | 45 +- 102 files changed, 11815 insertions(+), 105 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql new file mode 100644 index 00000000000..65468f09cf8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'claimable_funding_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ClaimableFundingAmountPerSizeUpdated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.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) +) + +, 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 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 = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_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(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_arbitrum.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--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_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql new file mode 100644 index 00000000000..17988609734 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql new file mode 100644 index 00000000000..44357cb1fbb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql @@ -0,0 +1,258 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'depositType' THEN value END) AS deposit_type, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + TRY_CAST(deposit_type AS INTEGER) AS deposit_type, + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + initial_long_token, + initial_short_token, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + deposit_type, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql new file mode 100644 index 00000000000..332c95169b7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql @@ -0,0 +1,199 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'longTokenAmount' THEN value END) AS long_token_amount, + MAX(CASE WHEN key_name = 'shortTokenAmount' THEN value END) AS short_token_amount, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(long_token_amount AS DOUBLE) AS long_token_amount, + TRY_CAST(short_token_amount AS DOUBLE) AS short_token_amount, + TRY_CAST(received_market_tokens AS DOUBLE) AS received_market_tokens, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + ED.blockchain, + ED.block_time, + DATE(ED.block_time) AS block_date, + ED.block_number, + ED.tx_hash, + ED.index, + ED.contract_address, + ED.event_name, + ED.msg_sender, + + ED.account, + ED.long_token_amount / POWER(10, MD.long_token_decimals) AS long_token_amount, + ED.short_token_amount / POWER(10, MD.short_token_decimals) AS short_token_amount, + ED.received_market_tokens / POWER(10, 18) AS received_market_tokens, + ED.swap_pricing_type, + ED."key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_deposit_created') }} AS DC + ON ED."key" = DC."key" + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON DC.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'] + ) +}} + + 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 dfc436cc271..36a4e868118 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 @@ -22,57 +22,35 @@ models: - &blockchain name: blockchain description: The blockchain network where the event occurred (Arbitrum) - data_tests: - - not_null - &block_time name: block_time description: The timestamp of the block when the event was recorded - data_tests: - - not_null - &block_date name: block_date - description: The date extracted from the block timestamp, representing the day the block was created - data_tests: - - not_null + description: The date extracted from the block timestamp, representing the day the block was created - &block_number name: block_number description: The block number where the event is included - data_tests: - - not_null - &tx_hash name: tx_hash description: The hash of the transaction where the event was logged - data_tests: - - not_null - &index name: index description: The position of the event within the transaction - data_tests: - - not_null - &contract_address name: contract_address - description: The contract address associated with the event - data_tests: - - not_null + description: The contract address associated with the event - &tx_from name: tx_from description: The originating address of the transaction, usually representing the sender - data_tests: - - not_null - &tx_to name: tx_to - description: The destination address of the transaction, representing the receiver - data_tests: - - not_null + description: The destination address of the transaction, representing the receiver - name: event_name description: The type of event recorded, always 'OrderCreated' for this model. - data_tests: - - not_null - &msg_sender name: msg_sender description: The address of the sender of the message or transaction. - data_tests: - - not_null - name: account description: The address associated with the order. - name: receiver @@ -1336,3 +1314,964 @@ models: 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). + + + - name: gmx_v2_arbitrum_deposit_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'deposit_cancelled'] + description: | + Processes decoded event data for `DepositCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction details, enabling + analysis of deposit cancellations on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `DepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_arbitrum_deposit_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'deposit_created'] + description: | + Processes decoded event data for `DepositCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of deposits created on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `DepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market for which the deposit was created. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_market_tokens + description: The minimum amount of market tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: deposit_type + description: The type of deposit created. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_arbitrum_deposit_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'deposit_executed'] + description: | + Processes decoded event data for `DepositExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, execution details, and transaction specifics, enabling + analysis of deposits executed on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `DepositExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: long_token_amount + description: The amount of the long token in the executed deposit. + - name: short_token_amount + description: The amount of the short token in the executed deposit. + - name: received_market_tokens + description: The number of market tokens received from the executed deposit. + - name: swap_pricing_type + description: The type of swap pricing applied during the execution. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_arbitrum_glv_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_created'] + description: | + Processes decoded event data for `GLVCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the GLV token, associated tokens, and transaction specifics, enabling + analysis of GLV creation events on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVCreated` for this model. + - *msg_sender + - name: glv_token + description: The identifier of the GLV token created in the transaction. + - name: long_token + description: The long token associated with the GLV creation. + - name: short_token + description: The short token associated with the GLV creation. + - name: salt + description: A unique salt value used in the GLV creation. + - name: glv_type + description: The type of GLV created. + - name: market_token_symbol + description: The symbol of the market token involved in the GLV creation. + - name: market_token_decimals + description: The decimal precision of the market token involved in the GLV creation. + + + - name: gmx_v2_arbitrum_glv_deposit_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_deposit_cancelled'] + description: | + Processes decoded event data for `GLVDepositCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVDepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_arbitrum_glv_deposit_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_deposit_created'] + description: | + Processes decoded event data for `GLVDepositCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of created GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVDepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market associated with the deposit. + - name: glv + description: The identifier of the GLV associated with the deposit. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: ui_fee_receiver + description: The address receiving the UI fee for the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_glv_tokens + description: The minimum amount of GLV tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: market_token_amount + description: The amount of market tokens associated with the deposit. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: is_market_token_deposit + description: Indicates whether the deposit was made using market tokens. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_arbitrum_glv_deposit_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_deposit_executed'] + description: | + Processes decoded event data for `GLVDepositExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, received GLV tokens, and transaction specifics, enabling + analysis of executed GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVDepositExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: received_glv_tokens + description: The number of GLV tokens received from the executed deposit. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_arbitrum_glv_shift_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_shift_cancelled'] + description: | + Processes decoded event data for `GLVShiftCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the cancellation reason and transaction specifics, enabling + analysis of cancelled GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVShiftCancelled` for this model. + - *msg_sender + - name: key + description: A unique identifier for the cancelled shift. + - name: reason_bytes + description: Encoded reason data for the shift cancellation. + - name: reason + description: The decoded textual reason for the shift cancellation. + + + - name: gmx_v2_arbitrum_glv_shift_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_shift_created'] + description: | + Processes decoded event data for `GLVShiftCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the source and destination markets, GLV details, and transaction specifics, enabling + analysis of created GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVShiftCreated` for this model. + - *msg_sender + - name: from_market + description: The source market for the GLV shift. + - name: to_market + description: The destination market for the GLV shift. + - name: glv + description: The identifier of the GLV being shifted. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_arbitrum_glv_shift_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_shift_executed'] + description: | + Processes decoded event data for `GLVShiftExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the received market tokens and transaction specifics, enabling + analysis of executed GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVShiftExecuted` for this model. + - *msg_sender + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_arbitrum_glv_withdrawal_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_withdrawal_cancelled'] + description: | + Processes decoded event data for `GLVWithdrawalCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVWithdrawalCancelled` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_arbitrum_glv_withdrawal_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_withdrawal_created'] + description: | + Processes decoded event data for `GLVWithdrawalCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVWithdrawalCreated` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: glv + description: The identifier of the GLV associated with the withdrawal. + - name: ui_fee_receiver + description: The address receiving the UI fee for the withdrawal. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: glv_token_amount + description: The amount of GLV tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_arbitrum_glv_withdrawal_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_withdrawal_executed'] + description: | + Processes decoded event data for `GLVWithdrawalExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address and transaction specifics, enabling + analysis of executed GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVWithdrawalExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_arbitrum_shift_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'shift_created'] + description: | + Processes decoded event data for `ShiftCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, market details, and transaction specifics, enabling + analysis of created shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `ShiftCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the shift. + - name: receiver + description: The receiver address specified for the shift. + - name: callback_contract + description: The address of the callback contract associated with the shift. + - name: from_market + description: The source market for the shift. + - name: to_market + description: The destination market for the shift. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: execution_fee + description: The execution fee for processing the shift. + - name: callback_gas_limit + description: The gas limit for the callback associated with the shift. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_arbitrum_shift_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'shift_executed'] + description: | + Processes decoded event data for `ShiftExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, received market tokens, and transaction specifics, enabling + analysis of executed shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `ShiftExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed shift. + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_arbitrum_withdrawal_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'withdrawal_cancelled'] + description: | + Processes decoded event data for `WithdrawalCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `WithdrawalCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_arbitrum_withdrawal_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'withdrawal_created'] + description: | + Processes decoded event data for `WithdrawalCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `WithdrawalCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: market_token_amount + description: The amount of market tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_arbitrum_withdrawal_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'withdrawal_executed'] + description: | + Processes decoded event data for `WithdrawalExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, pricing type, and transaction specifics, enabling + analysis of executed withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `WithdrawalExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: swap_pricing_type + description: The pricing type applied during the withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_arbitrum_claimable_funding_amount_per_size_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'claimable_funding'] + description: | + Processes decoded event data for `ClaimableFundingAmountPerSizeUpdated` events on the GMX platform across the Arbitrum blockchain. + This model extracts key details such as funding updates, collateral information, and market direction to support funding analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `ClaimableFundingAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding amount was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding amount. + - name: value + description: The funding amount value associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`true` for long, `false` for short). + + - name: gmx_v2_arbitrum_funding_fee_amount_per_size_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'funding_fee'] + description: | + Processes decoded event data for `FundingFeeAmountPerSizeUpdated` events on the GMX platform across the Arbitrum blockchain. + This model extracts key details such as funding fees, collateral details, and market direction to enable funding fee analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `FundingFeeAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding fee was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding fee amount. + - name: value + description: The funding fee amount associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`True` for long, `False` for short). 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 c20cd8fe4f9..62b61274227 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql new file mode 100644 index 00000000000..48aef2055c4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'funding_fee_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'FundingFeeAmountPerSizeUpdated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.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) +) + +, 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 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 = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_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(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_arbitrum.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--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_glv_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql new file mode 100644 index 00000000000..efa07928cd6 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql @@ -0,0 +1,157 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'glvToken' THEN value END) AS glv_token, + MAX(CASE WHEN key_name = 'longToken' THEN value END) AS long_token, + MAX(CASE WHEN key_name = 'shortToken' THEN value END) AS short_token, + MAX(CASE WHEN key_name = 'salt' THEN value END) AS salt, + MAX(CASE WHEN key_name = 'glvType' THEN value END) AS glv_type + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(glv_token) AS glv_token, + from_hex(long_token) AS long_token, + from_hex(short_token) AS short_token, + from_hex(salt) AS salt, + from_hex(glv_type) AS glv_type, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals + + 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_glv_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql new file mode 100644 index 00000000000..347667e0461 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_glv_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql new file mode 100644 index 00000000000..ea34140f4fc --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql @@ -0,0 +1,269 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minGlvTokens' THEN value END) AS min_glv_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + MAX(CASE WHEN key_name = 'isMarketTokenDeposit' THEN value END) AS is_market_token_deposit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, -- long_token_decimals + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, -- short_token_decimals + TRY_CAST(min_glv_tokens AS DOUBLE) min_glv_tokens, -- index_token_decimals (glv or market?) + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (glv or market?) + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + TRY_CAST(is_market_token_deposit AS BOOLEAN) AS is_market_token_deposit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + initial_long_token, + initial_short_token, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_glv_tokens / POWER(10, 18) AS min_glv_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + market_token_amount / POWER(10, 18) AS market_token_amount, + + should_unwrap_native_token, + is_market_token_deposit, + + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql new file mode 100644 index 00000000000..3302d0cbe00 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql @@ -0,0 +1,186 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedGlvTokens' THEN value END) AS received_glv_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(received_glv_tokens AS DOUBLE) received_glv_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + received_glv_tokens / POWER(10,18) AS received_glv_tokens, + "key" + + FROM event_data AS ED +) + +--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_glv_shift_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql new file mode 100644 index 00000000000..eb06ffd6817 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql @@ -0,0 +1,167 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_shift_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.stringItems' OMIT QUOTES) AS string_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) +) + +, string_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(string_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 string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + 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("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_glv_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql new file mode 100644 index 00000000000..3352d8cbe46 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql @@ -0,0 +1,200 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + from_hex(glv) AS glv, + TRY_CAST(market_token_amount AS DOUBLE) AS market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) AS min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) updated_at_time, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + from_market, + to_market, + glv, + market_token_amount / POWER(10, 18) AS market_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + "key" + FROM event_data AS ED +) + +--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_glv_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql new file mode 100644 index 00000000000..106f89913c2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql @@ -0,0 +1,165 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + TRY_CAST(received_market_tokens AS DOUBLE) received_market_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + received_market_tokens / POWER(10, 18) AS received_market_tokens, + "key" + FROM event_data AS ED +) + +--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_glv_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql new file mode 100644 index 00000000000..e07944f51c7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_glv_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql new file mode 100644 index 00000000000..3aa3f886a57 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql @@ -0,0 +1,255 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'glvTokenAmount' THEN value END) AS glv_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(glv_token_amount AS DOUBLE) glv_token_amount, -- index_token_decimals (glv or market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + glv_token_amount / POWER(10, 18) AS glv_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql new file mode 100644 index 00000000000..80574bfc7c7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql @@ -0,0 +1,149 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key" + + 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 index e7f2e0ee0f8..c10578e4da4 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql index 58a6f6bcb5e..77ebbce58c1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql @@ -49,7 +49,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 3d73a35efa3..e783d229c36 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 acbf9774525..2bfd18b0817 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 1e9216afe01..3f21c89db83 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 @@ -58,7 +58,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 b24ca5fafe2..c7444cacce2 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 a7a9c6c1c62..366dc5709e9 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 289f146dcb3..132477a7d8e 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 d1cba68b7fa..947eef0660f 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 b05f68e1501..b41395df4a1 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 5b142f5b386..7ef09cf95a9 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 8502f185856..355dc8b647d 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 1129f3b860f..a0e6f4eaddf 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 c3a1085676b..24939abe129 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql new file mode 100644 index 00000000000..18602bee501 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql @@ -0,0 +1,218 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + from_market, + to_market, + + market_token_amount / POWER(10,18) AS market_token_amount, + min_market_tokens / POWER(10,18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + "key" + + FROM event_data AS ED +) + +--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_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql new file mode 100644 index 00000000000..bfe660d6dbf --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql @@ -0,0 +1,168 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + TRY_CAST(received_market_tokens AS DOUBLE) / POWER(10,18) AS received_market_tokens, + from_hex("key") AS "key" + + 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_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql new file mode 100644 index 00000000000..e7e5a292a44 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql new file mode 100644 index 00000000000..c97a0b78ad3 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql @@ -0,0 +1,243 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + + market_token_amount / POWER(10, 18) AS market_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql new file mode 100644 index 00000000000..5456bbde74b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql @@ -0,0 +1,169 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + 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_claimable_funding_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql new file mode 100644 index 00000000000..e2456aeb0de --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'claimable_funding_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ClaimableFundingAmountPerSizeUpdated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.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) +) + +, 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 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 = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_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(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_avalanche_c.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--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_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql new file mode 100644 index 00000000000..41cce75f491 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql new file mode 100644 index 00000000000..ce9567fda4b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql @@ -0,0 +1,258 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'depositType' THEN value END) AS deposit_type, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + TRY_CAST(deposit_type AS INTEGER) AS deposit_type, + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + initial_long_token, + initial_short_token, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + deposit_type, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql new file mode 100644 index 00000000000..8271444fcf5 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql @@ -0,0 +1,199 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'longTokenAmount' THEN value END) AS long_token_amount, + MAX(CASE WHEN key_name = 'shortTokenAmount' THEN value END) AS short_token_amount, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(long_token_amount AS DOUBLE) AS long_token_amount, + TRY_CAST(short_token_amount AS DOUBLE) AS short_token_amount, + TRY_CAST(received_market_tokens AS DOUBLE) AS received_market_tokens, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + ED.blockchain, + ED.block_time, + DATE(ED.block_time) AS block_date, + ED.block_number, + ED.tx_hash, + ED.index, + ED.contract_address, + ED.event_name, + ED.msg_sender, + + ED.account, + ED.long_token_amount / POWER(10, MD.long_token_decimals) AS long_token_amount, + ED.short_token_amount / POWER(10, MD.short_token_decimals) AS short_token_amount, + ED.received_market_tokens / POWER(10, 18) AS received_market_tokens, + ED.swap_pricing_type, + ED."key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_deposit_created') }} AS DC + ON ED."key" = DC."key" + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON DC.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'] + ) +}} + + 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 bd0636b0db1..f8c25f3763c 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 @@ -22,57 +22,35 @@ models: - &blockchain name: blockchain description: The blockchain network where the event occurred (Avalanche) - data_tests: - - not_null - &block_time name: block_time description: The timestamp of the block when the event was recorded - data_tests: - - not_null - &block_date name: block_date - description: The date extracted from the block timestamp, representing the day the block was created - data_tests: - - not_null + description: The date extracted from the block timestamp, representing the day the block was created - &block_number name: block_number description: The block number where the event is included - data_tests: - - not_null - &tx_hash name: tx_hash description: The hash of the transaction where the event was logged - data_tests: - - not_null - &index name: index description: The position of the event within the transaction - data_tests: - - not_null - &contract_address name: contract_address description: The contract address associated with the event - data_tests: - - not_null - &tx_from name: tx_from description: The originating address of the transaction, usually representing the sender - data_tests: - - not_null - &tx_to name: tx_to - description: The destination address of the transaction, representing the receiver - data_tests: - - not_null + description: The destination address of the transaction, representing the receiver - name: event_name description: The type of event recorded, always 'OrderCreated' for this model. - data_tests: - - not_null - &msg_sender name: msg_sender description: The address of the sender of the message or transaction. - data_tests: - - not_null - name: account description: The address associated with the order. - name: receiver @@ -1337,3 +1315,963 @@ models: 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). + + + - name: gmx_v2_avalanche_c_deposit_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'deposit_cancelled'] + description: | + Processes decoded event data for `DepositCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction details, enabling + analysis of deposit cancellations on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `DepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_avalanche_c_deposit_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'deposit_created'] + description: | + Processes decoded event data for `DepositCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of deposits created on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `DepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market for which the deposit was created. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_market_tokens + description: The minimum amount of market tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: deposit_type + description: The type of deposit created. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_avalanche_c_deposit_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'deposit_executed'] + description: | + Processes decoded event data for `DepositExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, execution details, and transaction specifics, enabling + analysis of deposits executed on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `DepositExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: long_token_amount + description: The amount of the long token in the executed deposit. + - name: short_token_amount + description: The amount of the short token in the executed deposit. + - name: received_market_tokens + description: The number of market tokens received from the executed deposit. + - name: swap_pricing_type + description: The type of swap pricing applied during the execution. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_avalanche_c_glv_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_created'] + description: | + Processes decoded event data for `GLVCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the GLV token, associated tokens, and transaction specifics, enabling + analysis of GLV creation events on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVCreated` for this model. + - *msg_sender + - name: glv_token + description: The identifier of the GLV token created in the transaction. + - name: long_token + description: The long token associated with the GLV creation. + - name: short_token + description: The short token associated with the GLV creation. + - name: salt + description: A unique salt value used in the GLV creation. + - name: glv_type + description: The type of GLV created. + - name: market_token_symbol + description: The symbol of the market token involved in the GLV creation. + - name: market_token_decimals + description: The decimal precision of the market token involved in the GLV creation. + + + - name: gmx_v2_avalanche_c_glv_deposit_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_deposit_cancelled'] + description: | + Processes decoded event data for `GLVDepositCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVDepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_avalanche_c_glv_deposit_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_deposit_created'] + description: | + Processes decoded event data for `GLVDepositCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of created GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVDepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market associated with the deposit. + - name: glv + description: The identifier of the GLV associated with the deposit. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: ui_fee_receiver + description: The address receiving the UI fee for the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_glv_tokens + description: The minimum amount of GLV tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: market_token_amount + description: The amount of market tokens associated with the deposit. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: is_market_token_deposit + description: Indicates whether the deposit was made using market tokens. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_avalanche_c_glv_deposit_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_deposit_executed'] + description: | + Processes decoded event data for `GLVDepositExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, received GLV tokens, and transaction specifics, enabling + analysis of executed GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVDepositExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: received_glv_tokens + description: The number of GLV tokens received from the executed deposit. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_avalanche_c_glv_shift_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_shift_cancelled'] + description: | + Processes decoded event data for `GLVShiftCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the cancellation reason and transaction specifics, enabling + analysis of cancelled GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVShiftCancelled` for this model. + - *msg_sender + - name: key + description: A unique identifier for the cancelled shift. + - name: reason_bytes + description: Encoded reason data for the shift cancellation. + - name: reason + description: The decoded textual reason for the shift cancellation. + + + - name: gmx_v2_avalanche_c_glv_shift_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_shift_created'] + description: | + Processes decoded event data for `GLVShiftCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the source and destination markets, GLV details, and transaction specifics, enabling + analysis of created GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVShiftCreated` for this model. + - *msg_sender + - name: from_market + description: The source market for the GLV shift. + - name: to_market + description: The destination market for the GLV shift. + - name: glv + description: The identifier of the GLV being shifted. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_avalanche_c_glv_shift_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_shift_executed'] + description: | + Processes decoded event data for `GLVShiftExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the received market tokens and transaction specifics, enabling + analysis of executed GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVShiftExecuted` for this model. + - *msg_sender + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_avalanche_c_glv_withdrawal_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_withdrawal_cancelled'] + description: | + Processes decoded event data for `GLVWithdrawalCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVWithdrawalCancelled` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_avalanche_c_glv_withdrawal_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_withdrawal_created'] + description: | + Processes decoded event data for `GLVWithdrawalCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVWithdrawalCreated` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: glv + description: The identifier of the GLV associated with the withdrawal. + - name: ui_fee_receiver + description: The address receiving the UI fee for the withdrawal. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: glv_token_amount + description: The amount of GLV tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_avalanche_c_glv_withdrawal_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_withdrawal_executed'] + description: | + Processes decoded event data for `GLVWithdrawalExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address and transaction specifics, enabling + analysis of executed GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `GLVWithdrawalExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_avalanche_c_shift_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'shift_created'] + description: | + Processes decoded event data for `ShiftCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, market details, and transaction specifics, enabling + analysis of created shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `ShiftCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the shift. + - name: receiver + description: The receiver address specified for the shift. + - name: callback_contract + description: The address of the callback contract associated with the shift. + - name: from_market + description: The source market for the shift. + - name: to_market + description: The destination market for the shift. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: execution_fee + description: The execution fee for processing the shift. + - name: callback_gas_limit + description: The gas limit for the callback associated with the shift. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_avalanche_c_shift_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'shift_executed'] + description: | + Processes decoded event data for `ShiftExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, received market tokens, and transaction specifics, enabling + analysis of executed shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `ShiftExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed shift. + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_avalanche_c_withdrawal_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'withdrawal_cancelled'] + description: | + Processes decoded event data for `WithdrawalCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `WithdrawalCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_avalanche_c_withdrawal_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'withdrawal_created'] + description: | + Processes decoded event data for `WithdrawalCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `WithdrawalCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: market_token_amount + description: The amount of market tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_avalanche_c_withdrawal_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'withdrawal_executed'] + description: | + Processes decoded event data for `WithdrawalExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, pricing type, and transaction specifics, enabling + analysis of executed withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + 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 `WithdrawalExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: swap_pricing_type + description: The pricing type applied during the withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + - name: gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'claimable_funding'] + description: | + Processes decoded event data for `ClaimableFundingAmountPerSizeUpdated` events on the GMX platform across the Avalanche blockchain. + This model extracts key details such as funding updates, collateral information, and market direction to support funding analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `ClaimableFundingAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding amount was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding amount. + - name: value + description: The funding amount value associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`true` for long, `false` for short). + + - name: gmx_v2_avalanche_c_funding_fee_amount_per_size_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'funding_fee'] + description: | + Processes decoded event data for `FundingFeeAmountPerSizeUpdated` events on the GMX platform across the Avalanche blockchain. + This model extracts key details such as funding fees, collateral details, and market direction to enable funding fee analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `FundingFeeAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding fee was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding fee amount. + - name: value + description: The funding fee amount associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`True` for long, `False` for short). 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 2fa2e95fe43..f685312857d 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql new file mode 100644 index 00000000000..a2f93f4f0f8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'funding_fee_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'FundingFeeAmountPerSizeUpdated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.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) +) + +, 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 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 = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_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(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_avalanche_c.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--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_glv_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql new file mode 100644 index 00000000000..1dc64b7568b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql @@ -0,0 +1,157 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'glvToken' THEN value END) AS glv_token, + MAX(CASE WHEN key_name = 'longToken' THEN value END) AS long_token, + MAX(CASE WHEN key_name = 'shortToken' THEN value END) AS short_token, + MAX(CASE WHEN key_name = 'salt' THEN value END) AS salt, + MAX(CASE WHEN key_name = 'glvType' THEN value END) AS glv_type + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(glv_token) AS glv_token, + from_hex(long_token) AS long_token, + from_hex(short_token) AS short_token, + from_hex(salt) AS salt, + from_hex(glv_type) AS glv_type, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals + + 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_glv_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql new file mode 100644 index 00000000000..863c2643169 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_glv_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql new file mode 100644 index 00000000000..c5c9f968d07 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql @@ -0,0 +1,269 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minGlvTokens' THEN value END) AS min_glv_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + MAX(CASE WHEN key_name = 'isMarketTokenDeposit' THEN value END) AS is_market_token_deposit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, -- long_token_decimals + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, -- short_token_decimals + TRY_CAST(min_glv_tokens AS DOUBLE) min_glv_tokens, -- index_token_decimals (glv or market?) + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (glv or market?) + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + TRY_CAST(is_market_token_deposit AS BOOLEAN) AS is_market_token_deposit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + initial_long_token, + initial_short_token, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_glv_tokens / POWER(10, 18) AS min_glv_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + market_token_amount / POWER(10, 18) AS market_token_amount, + + should_unwrap_native_token, + is_market_token_deposit, + + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql new file mode 100644 index 00000000000..f24cd674f4c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql @@ -0,0 +1,186 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedGlvTokens' THEN value END) AS received_glv_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(received_glv_tokens AS DOUBLE) received_glv_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + received_glv_tokens / POWER(10,18) AS received_glv_tokens, + "key" + + FROM event_data AS ED +) + +--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_glv_shift_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql new file mode 100644 index 00000000000..4a3c61e65e4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql @@ -0,0 +1,167 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_shift_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.stringItems' OMIT QUOTES) AS string_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) +) + +, string_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(string_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 string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + 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("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_glv_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql new file mode 100644 index 00000000000..397886221ad --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql @@ -0,0 +1,200 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + from_hex(glv) AS glv, + TRY_CAST(market_token_amount AS DOUBLE) AS market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) AS min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) updated_at_time, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + from_market, + to_market, + glv, + market_token_amount / POWER(10, 18) AS market_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + "key" + FROM event_data AS ED +) + +--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_glv_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql new file mode 100644 index 00000000000..f07679676cb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql @@ -0,0 +1,165 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + TRY_CAST(received_market_tokens AS DOUBLE) received_market_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + received_market_tokens / POWER(10, 18) AS received_market_tokens, + "key" + FROM event_data AS ED +) + +--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_glv_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql new file mode 100644 index 00000000000..9c9a58a940f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_glv_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql new file mode 100644 index 00000000000..ab1baf9bcd1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql @@ -0,0 +1,255 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'glvTokenAmount' THEN value END) AS glv_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(glv_token_amount AS DOUBLE) glv_token_amount, -- index_token_decimals (glv or market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + glv_token_amount / POWER(10, 18) AS glv_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql new file mode 100644 index 00000000000..b1d43e8e510 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql @@ -0,0 +1,149 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key" + + 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 index 3a6c16d6009..69ea1e6771f 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql index 9979092e3ef..93ac2def471 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql @@ -49,7 +49,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 d601703949e..9f82c578bca 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 cd88f284349..fbb392ff855 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 14f2540c8f6..0c5d6121b68 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 @@ -58,7 +58,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 e974c4d20e5..b38eb38e5cc 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 d0f775d745e..5a28248d8c1 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 6e9b7ce230c..9651369a61e 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 17c7d2934da..8f2ee6167cd 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 a5edbae87fc..9870ebd74fc 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 ad4015404f2..d138becbf80 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 a4aae5dd017..092bf293fdf 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 52d9bd0cddb..da0e3bde9b2 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 @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) 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 41e06b529d5..7d7b60cc0a9 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 @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql new file mode 100644 index 00000000000..c0e8906b3c4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql @@ -0,0 +1,218 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + from_market, + to_market, + + market_token_amount / POWER(10,18) AS market_token_amount, + min_market_tokens / POWER(10,18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + "key" + + FROM event_data AS ED +) + +--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_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql new file mode 100644 index 00000000000..7e5d1068301 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql @@ -0,0 +1,168 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + TRY_CAST(received_market_tokens AS DOUBLE) / POWER(10,18) AS received_market_tokens, + from_hex("key") AS "key" + + 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_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql new file mode 100644 index 00000000000..5ec6ef12537 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCancelled' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_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) +) + +, 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) +) + +, string_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(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + 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_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql new file mode 100644 index 00000000000..f42e389f09c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql @@ -0,0 +1,243 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCreated' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + + market_token_amount / POWER(10, 18) AS market_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.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'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql new file mode 100644 index 00000000000..b7a17202a3d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql @@ -0,0 +1,169 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalExecuted' -%} +{%- 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, 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 }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + 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 $.bytes32Items' OMIT QUOTES) AS bytes32_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) +) + +, 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) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, 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(account) AS account, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + 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_claimable_funding_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql new file mode 100644 index 00000000000..234a369761b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'claimable_funding_amount_per_size_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_from, + tx_to, + event_name, + msg_sender, + market, + collateral_token, + delta, + "value", + is_long +FROM {{ ref('gmx_v2_' ~ chain ~ '_claimable_funding_amount_per_size_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql new file mode 100644 index 00000000000..f82c94e76db --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql @@ -0,0 +1,39 @@ +{{ config( + schema='gmx_v2', + alias = 'deposit_cancelled', + 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, + account, + "key", + reason_bytes, + reason +FROM {{ ref('gmx_v2_' ~ chain ~ '_deposit_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql new file mode 100644 index 00000000000..4ee27fc9ff4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql @@ -0,0 +1,51 @@ +{{ config( + schema='gmx_v2', + alias = 'deposit_created', + 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, + account, + receiver, + callback_contract, + market, + initial_long_token, + initial_short_token, + long_token_swap_path, + short_token_swap_path, + initial_long_token_amount, + initial_short_token_amount, + min_market_tokens, + updated_at_time, + execution_fee, + callback_gas_limit, + deposit_type, + should_unwrap_native_token, + "key" +FROM {{ ref('gmx_v2_' ~ chain ~ '_deposit_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql new file mode 100644 index 00000000000..57d159c87df --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql @@ -0,0 +1,43 @@ +{{ config( + schema='gmx_v2', + alias = 'deposit_executed', + 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, + + account, + long_token_amount, + short_token_amount, + received_market_tokens, + swap_pricing_type, + "key" +FROM {{ ref('gmx_v2_' ~ chain ~ '_deposit_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + 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 39ea55ccbab..f6783776688 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 @@ -23,57 +23,35 @@ models: - &blockchain name: blockchain description: The blockchain network where the event occurred - data_tests: - - not_null - &block_time name: block_time description: The timestamp of the block when the event was recorded - data_tests: - - not_null - &block_date name: block_date - description: The date extracted from the block timestamp, representing the day the block was created - data_tests: - - not_null + description: The date extracted from the block timestamp, representing the day the block was created - &block_number name: block_number description: The block number where the event is included - data_tests: - - not_null - &tx_hash name: tx_hash description: The hash of the transaction where the event was logged - data_tests: - - not_null - &index name: index description: The position of the event within the transaction - data_tests: - - not_null - &contract_address name: contract_address description: The contract address associated with the event - data_tests: - - not_null - &tx_from name: tx_from description: The originating address of the transaction, usually representing the sender - data_tests: - - not_null - &tx_to name: tx_to - description: The destination address of the transaction, representing the receiver - data_tests: - - not_null + description: The destination address of the transaction, representing the receiver - name: event_name description: The type of event recorded, always 'OrderCreated' for this model. - data_tests: - - not_null - &msg_sender name: msg_sender description: The address of the sender of the message or transaction. - data_tests: - - not_null - name: account description: The address associated with the order. - name: receiver @@ -1284,3 +1262,882 @@ models: description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). + - name: gmx_v2_deposit_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'deposit_cancelled'] + description: | + Processes decoded event data for `DepositCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction details, enabling + analysis of deposit cancellations on the platform. + + 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 `DepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_deposit_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'deposit_created'] + description: | + Processes decoded event data for `DepositCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of deposits created on the platform. + + 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 `DepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market for which the deposit was created. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_market_tokens + description: The minimum amount of market tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: deposit_type + description: The type of deposit created. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_deposit_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'deposit_executed'] + description: | + Processes decoded event data for `DepositExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, execution details, and transaction specifics, enabling + analysis of deposits executed on the platform. + + 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 `DepositExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: long_token_amount + description: The amount of the long token in the executed deposit. + - name: short_token_amount + description: The amount of the short token in the executed deposit. + - name: received_market_tokens + description: The number of market tokens received from the executed deposit. + - name: swap_pricing_type + description: The type of swap pricing applied during the execution. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_glv_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_created'] + description: | + Processes decoded event data for `GLVCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the GLV token, associated tokens, and transaction specifics, enabling + analysis of GLV creation events on the platform. + + 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 `GLVCreated` for this model. + - *msg_sender + - name: glv_token + description: The identifier of the GLV token created in the transaction. + - name: long_token + description: The long token associated with the GLV creation. + - name: short_token + description: The short token associated with the GLV creation. + - name: salt + description: A unique salt value used in the GLV creation. + - name: glv_type + description: The type of GLV created. + - name: market_token_symbol + description: The symbol of the market token involved in the GLV creation. + - name: market_token_decimals + description: The decimal precision of the market token involved in the GLV creation. + + + - name: gmx_v2_glv_deposit_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_deposit_cancelled'] + description: | + Processes decoded event data for `GLVDepositCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV deposits. + + 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 `GLVDepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_glv_deposit_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_deposit_created'] + description: | + Processes decoded event data for `GLVDepositCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of created GLV deposits. + + 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 `GLVDepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market associated with the deposit. + - name: glv + description: The identifier of the GLV associated with the deposit. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: ui_fee_receiver + description: The address receiving the UI fee for the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_glv_tokens + description: The minimum amount of GLV tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: market_token_amount + description: The amount of market tokens associated with the deposit. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: is_market_token_deposit + description: Indicates whether the deposit was made using market tokens. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_glv_deposit_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_deposit_executed'] + description: | + Processes decoded event data for `GLVDepositExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, received GLV tokens, and transaction specifics, enabling + analysis of executed GLV deposits. + + 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 `GLVDepositExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: received_glv_tokens + description: The number of GLV tokens received from the executed deposit. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_glv_shift_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_shift_cancelled'] + description: | + Processes decoded event data for `GLVShiftCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the cancellation reason and transaction specifics, enabling + analysis of cancelled GLV shifts. + + 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 `GLVShiftCancelled` for this model. + - *msg_sender + - name: key + description: A unique identifier for the cancelled shift. + - name: reason_bytes + description: Encoded reason data for the shift cancellation. + - name: reason + description: The decoded textual reason for the shift cancellation. + + + - name: gmx_v2_glv_shift_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_shift_created'] + description: | + Processes decoded event data for `GLVShiftCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the source and destination markets, GLV details, and transaction specifics, enabling + analysis of created GLV shifts. + + 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 `GLVShiftCreated` for this model. + - *msg_sender + - name: from_market + description: The source market for the GLV shift. + - name: to_market + description: The destination market for the GLV shift. + - name: glv + description: The identifier of the GLV being shifted. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_glv_shift_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_shift_executed'] + description: | + Processes decoded event data for `GLVShiftExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the received market tokens and transaction specifics, enabling + analysis of executed GLV shifts. + + 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 `GLVShiftExecuted` for this model. + - *msg_sender + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_glv_withdrawal_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_withdrawal_cancelled'] + description: | + Processes decoded event data for `GLVWithdrawalCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV withdrawals. + + 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 `GLVWithdrawalCancelled` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_glv_withdrawal_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_withdrawal_created'] + description: | + Processes decoded event data for `GLVWithdrawalCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created GLV withdrawals. + + 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 `GLVWithdrawalCreated` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: glv + description: The identifier of the GLV associated with the withdrawal. + - name: ui_fee_receiver + description: The address receiving the UI fee for the withdrawal. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: glv_token_amount + description: The amount of GLV tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_glv_withdrawal_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_withdrawal_executed'] + description: | + Processes decoded event data for `GLVWithdrawalExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address and transaction specifics, enabling + analysis of executed GLV withdrawals. + + 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 `GLVWithdrawalExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_shift_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'shift_created'] + description: | + Processes decoded event data for `ShiftCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, market details, and transaction specifics, enabling + analysis of created shifts. + + 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 `ShiftCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the shift. + - name: receiver + description: The receiver address specified for the shift. + - name: callback_contract + description: The address of the callback contract associated with the shift. + - name: from_market + description: The source market for the shift. + - name: to_market + description: The destination market for the shift. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: execution_fee + description: The execution fee for processing the shift. + - name: callback_gas_limit + description: The gas limit for the callback associated with the shift. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_shift_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'shift_executed'] + description: | + Processes decoded event data for `ShiftExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, received market tokens, and transaction specifics, enabling + analysis of executed shifts. + + 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 `ShiftExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed shift. + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_withdrawal_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'withdrawal_cancelled'] + description: | + Processes decoded event data for `WithdrawalCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled withdrawals. + + 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 `WithdrawalCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_withdrawal_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'withdrawal_created'] + description: | + Processes decoded event data for `WithdrawalCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created withdrawals. + + 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 `WithdrawalCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: market_token_amount + description: The amount of market tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_withdrawal_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'withdrawal_executed'] + description: | + Processes decoded event data for `WithdrawalExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, pricing type, and transaction specifics, enabling + analysis of executed withdrawals. + + 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 `WithdrawalExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: swap_pricing_type + description: The pricing type applied during the withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_claimable_funding_amount_per_size_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'claimable_funding'] + description: | + Processes decoded event data for `ClaimableFundingAmountPerSizeUpdated` events on the GMX platform across the Arbitrum and Avalanche blockchains. + This model extracts key details such as funding updates, collateral information, and market direction to support funding analysis. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `ClaimableFundingAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding amount was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding amount. + - name: value + description: The funding amount value associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`true` for long, `false` for short). + + - name: gmx_v2_funding_fee_amount_per_size_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'funding_fee'] + description: | + Processes decoded event data for `FundingFeeAmountPerSizeUpdated` events on the GMX platform across the Arbitrum and Avalanche blockchains. + This model extracts key details such as funding fees, collateral details, and market direction to enable funding fee analysis. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `FundingFeeAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding fee was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding fee amount. + - name: value + description: The funding fee amount associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`True` for long, `False` for short). diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql new file mode 100644 index 00000000000..77db6dab786 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'funding_fee_amount_per_size_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_from, + tx_to, + event_name, + msg_sender, + market, + collateral_token, + delta, + "value", + is_long +FROM {{ ref('gmx_v2_' ~ chain ~ '_funding_fee_amount_per_size_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql new file mode 100644 index 00000000000..3ff0d276649 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql @@ -0,0 +1,44 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_created', + 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, + + glv_token, + long_token, + short_token, + salt, + glv_type, + market_token_symbol, + market_token_decimals + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql new file mode 100644 index 00000000000..a94e78ae3f1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql @@ -0,0 +1,42 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_deposit_cancelled', + 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, + + account, + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_deposit_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql new file mode 100644 index 00000000000..550dbdac8ff --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql @@ -0,0 +1,56 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_deposit_created', + 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, + + account, + receiver, + callback_contract, + market, + glv, + initial_long_token, + initial_short_token, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + initial_long_token_amount, + initial_short_token_amount, + min_glv_tokens, + updated_at_time, + execution_fee, + callback_gas_limit, + market_token_amount, + should_unwrap_native_token, + is_market_token_deposit, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_deposit_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql new file mode 100644 index 00000000000..2a8ffc7a0a7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql @@ -0,0 +1,42 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_deposit_executed', + 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, + + account, + received_glv_tokens, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_deposit_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql new file mode 100644 index 00000000000..93b1164153e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_shift_cancelled', + 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, + + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_shift_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql new file mode 100644 index 00000000000..eb1a077a283 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql @@ -0,0 +1,44 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_shift_created', + 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, + + from_market, + to_market, + glv, + market_token_amount, + min_market_tokens, + updated_at_time, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_shift_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql new file mode 100644 index 00000000000..8b5098727a0 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql @@ -0,0 +1,39 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_shift_executed', + 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, + + received_market_tokens, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_shift_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql new file mode 100644 index 00000000000..e13c2bfe157 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql @@ -0,0 +1,42 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_withdrawal_cancelled', + 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, + + account, + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_withdrawal_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql new file mode 100644 index 00000000000..85faee03b17 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql @@ -0,0 +1,52 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_withdrawal_created', + 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, + + account, + receiver, + callback_contract, + market, + glv, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + glv_token_amount, + min_long_token_amount, + min_short_token_amount, + updated_at_time, + execution_fee, + callback_gas_limit, + should_unwrap_native_token, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_withdrawal_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql new file mode 100644 index 00000000000..5fd5d1de1e2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_withdrawal_executed', + 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, + + account, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_withdrawal_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql new file mode 100644 index 00000000000..e79bb2d2a80 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql @@ -0,0 +1,49 @@ +{{ config( + schema='gmx_v2', + alias = 'shift_created', + 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, + + account, + receiver, + callback_contract, + from_market, + to_market, + market_token_amount, + min_market_tokens, + updated_at_time, + execution_fee, + callback_gas_limit, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_shift_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql new file mode 100644 index 00000000000..4407f016586 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'shift_executed', + 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, + + account, + received_market_tokens, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_shift_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql new file mode 100644 index 00000000000..a1199d59838 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'withdrawal_cancelled', + 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, + + account, + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_withdrawal_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql new file mode 100644 index 00000000000..527870ac98b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql @@ -0,0 +1,49 @@ +{{ config( + schema='gmx_v2', + alias = 'withdrawal_created', + 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, + + account, + receiver, + callback_contract, + market, + market_token_amount, + min_long_token_amount, + min_short_token_amount, + updated_at_time, + execution_fee, + callback_gas_limit, + should_unwrap_native_token, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_withdrawal_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql new file mode 100644 index 00000000000..be12acddb55 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'withdrawal_executed', + 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, + + account, + swap_pricing_type, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_withdrawal_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql new file mode 100644 index 00000000000..16d2d77e07e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql @@ -0,0 +1,24 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_markets_data', + materialized = 'view' + ) +}} + +SELECT + GCE.glv_token AS glv, + CONCAT(ERC20_LT.symbol, '-', ERC20_ST.symbol) AS glv_market_name, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals, + GCE.long_token, + ERC20_LT.symbol AS long_token_symbol, + ERC20_LT.decimals AS long_token_decimals, + GCE.short_token, + ERC20_ST.symbol AS short_token_symbol, + ERC20_ST.decimals AS short_token_decimals +FROM {{ ref('gmx_v2_arbitrum_glv_created') }} AS GCE +LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20_LT + ON ERC20_LT.contract_address = GCE.long_token +LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20_ST + ON ERC20_ST.contract_address = GCE.short_token \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql index 5c4682b2fe8..9ef54976e01 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql @@ -15,10 +15,13 @@ SELECT END AS market_name, 'GM' AS market_token_symbol, 18 AS market_token_decimals, + MCE.index_token, ERC20_IT.symbol AS index_token_symbol, ERC20_IT.decimals AS index_token_decimals, + MCE.long_token, ERC20_LT.symbol AS long_token_symbol, ERC20_LT.decimals AS long_token_decimals, + MCE.short_token, ERC20_ST.symbol AS short_token_symbol, ERC20_ST.decimals AS short_token_decimals FROM {{ ref('gmx_v2_arbitrum_market_created') }} AS MCE diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml index 5bea8c3ee7f..317ba7b82c7 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml @@ -110,10 +110,14 @@ models: description: The number of decimal places for the market token. data_tests: - not_null + - name: index_token + description: The contract address of the index token. - name: index_token_symbol description: The symbol representing the index token in the market. - name: index_token_decimals description: The number of decimal places for the index token used in the market. + - name: long_token + description: The contract address of the long token. - name: long_token_symbol description: The symbol representing the long token in the market. data_tests: @@ -122,6 +126,8 @@ models: description: The number of decimal places for the long token used in the market. data_tests: - not_null + - name: short_token + description: The contract address of the short token. - name: short_token_symbol description: The symbol representing the short token in the market. data_tests: @@ -129,4 +135,40 @@ models: - name: short_token_decimals description: The number of decimal places for the short token used in the market. data_tests: - - not_null \ No newline at end of file + - not_null + + + - name: gmx_v2_arbitrum_glv_markets_data + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'markets', 'glv_markets_data'] + description: | + Processes decoded market data for GLV markets on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as market names, token symbols, and decimals, enabling + comprehensive analysis of GLV markets. + + columns: + - name: glv + description: The identifier of the GLV market. + - name: glv_market_name + description: The name of the GLV market. + - name: market_token_symbol + description: The symbol of the market token. + - name: market_token_decimals + description: The decimal precision of the market token. + - name: long_token + description: The contract address of the long token. + - name: long_token_symbol + description: The symbol of the long token in the market. + - name: long_token_decimals + description: The decimal precision of the long token. + - name: short_token + description: The contract address of the short token. + - name: short_token_symbol + description: The symbol of the short token in the market. + - name: short_token_decimals + description: The decimal precision of the short token. diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql new file mode 100644 index 00000000000..126a8adc6fb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql @@ -0,0 +1,24 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_markets_data', + materialized = 'view' + ) +}} + +SELECT + GCE.glv_token AS glv, + CONCAT(ERC20_LT.symbol, '-', ERC20_ST.symbol) AS glv_market_name, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals, + GCE.long_token, + ERC20_LT.symbol AS long_token_symbol, + ERC20_LT.decimals AS long_token_decimals, + GCE.short_token, + ERC20_ST.symbol AS short_token_symbol, + ERC20_ST.decimals AS short_token_decimals +FROM {{ ref('gmx_v2_avalanche_c_glv_created') }} AS GCE +LEFT JOIN {{ ref('gmx_v2_avalanche_c_erc20') }} AS ERC20_LT + ON ERC20_LT.contract_address = GCE.long_token +LEFT JOIN {{ ref('gmx_v2_avalanche_c_erc20') }} AS ERC20_ST + ON ERC20_ST.contract_address = GCE.short_token \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql index c8fda944fb9..61d4a394158 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql @@ -15,10 +15,13 @@ SELECT END AS market_name, 'GM' AS market_token_symbol, 18 AS market_token_decimals, + MCE.index_token, ERC20_IT.symbol AS index_token_symbol, ERC20_IT.decimals AS index_token_decimals, + MCE.long_token, ERC20_LT.symbol AS long_token_symbol, ERC20_LT.decimals AS long_token_decimals, + MCE.short_token, ERC20_ST.symbol AS short_token_symbol, ERC20_ST.decimals AS short_token_decimals FROM {{ ref('gmx_v2_avalanche_c_market_created') }} AS MCE diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml index 572164b7ae2..279bb25881c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml @@ -109,10 +109,14 @@ models: description: The number of decimal places for the market token. data_tests: - not_null + - name: index_token + description: The contract address of the index token. - name: index_token_symbol description: The symbol representing the index token in the market. - name: index_token_decimals description: The number of decimal places for the index token used in the market. + - name: long_token + description: The contract address of the long token. - name: long_token_symbol description: The symbol representing the long token in the market. data_tests: @@ -121,6 +125,8 @@ models: description: The number of decimal places for the long token used in the market. data_tests: - not_null + - name: short_token + description: The contract address of the short token. - name: short_token_symbol description: The symbol representing the short token in the market. data_tests: @@ -129,3 +135,39 @@ models: description: The number of decimal places for the short token used in the market. data_tests: - not_null + + + - name: gmx_v2_avalanche_c_glv_markets_data + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'markets', 'glv_markets_data'] + description: | + Processes decoded market data for GLV markets on the GMX platform in the Avalanche blockchain. + This model extracts key details such as market names, token symbols, and decimals, enabling + comprehensive analysis of GLV markets. + + columns: + - name: glv + description: The identifier of the GLV market. + - name: glv_market_name + description: The name of the GLV market. + - name: market_token_symbol + description: The symbol of the market token. + - name: market_token_decimals + description: The decimal precision of the market token. + - name: long_token + description: The contract address of the long token. + - name: long_token_symbol + description: The symbol of the long token in the market. + - name: long_token_decimals + description: The decimal precision of the long token. + - name: short_token + description: The contract address of the short token. + - name: short_token_symbol + description: The symbol of the short token in the market. + - name: short_token_decimals + description: The decimal precision of the short token. diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql new file mode 100644 index 00000000000..b0e0b15ba91 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql @@ -0,0 +1,34 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_markets_data', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + '{{ chain }}' AS "blockchain", + glv, + glv_market_name, + market_token_symbol, + market_token_decimals, + long_token, + long_token_symbol, + long_token_decimals, + short_token, + short_token_symbol, + short_token_decimals +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_markets_data') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql index 0c0951fee6f..60a22b01370 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql @@ -20,10 +20,13 @@ SELECT market_name, market_token_symbol, market_token_decimals, + index_token, index_token_symbol, index_token_decimals, + long_token, long_token_symbol, long_token_decimals, + short_token, short_token_symbol, short_token_decimals FROM {{ ref('gmx_v2_' ~ chain ~ '_markets_data') }} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml index e1c9b389c18..601a5f113d1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml @@ -110,10 +110,14 @@ models: description: The number of decimal places for the market token. data_tests: - not_null + - name: index_token + description: The contract address of the index token. - name: index_token_symbol description: The symbol representing the index token in the market. - name: index_token_decimals description: The number of decimal places for the index token used in the market. + - name: long_token + description: The contract address of the long token. - name: long_token_symbol description: The symbol representing the long token in the market. data_tests: @@ -122,6 +126,8 @@ models: description: The number of decimal places for the long token used in the market. data_tests: - not_null + - name: short_token + description: The contract address of the short token. - name: short_token_symbol description: The symbol representing the short token in the market. data_tests: @@ -129,4 +135,41 @@ models: - name: short_token_decimals description: The number of decimal places for the short token used in the market. data_tests: - - not_null \ No newline at end of file + - not_null + + + - name: gmx_v2_glv_markets_data + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'markets', 'glv_markets_data'] + description: | + Processes decoded market data for GLV markets on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as market names, token symbols, and decimals, enabling + comprehensive analysis of GLV markets. + + columns: + - *blockchain + - name: glv + description: The identifier of the GLV market. + - name: glv_market_name + description: The name of the GLV market. + - name: market_token_symbol + description: The symbol of the market token. + - name: market_token_decimals + description: The decimal precision of the market token. + - name: long_token + description: The contract address of the long token. + - name: long_token_symbol + description: The symbol of the long token in the market. + - name: long_token_decimals + description: The decimal precision of the long token. + - name: short_token + description: The contract address of the short token. + - name: short_token_symbol + description: The symbol of the short token in the market. + - name: short_token_decimals + description: The decimal precision of the short token.