From 174b3474615bc9a3bd3b67d548d2dac3d800e5be Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Mon, 11 Nov 2024 19:56:07 +0200 Subject: [PATCH 1/9] Add 5 new Event Models. Update 4 Event Models Based on Changes in Contracts --- ...bitrum_open_interest_in_tokens_updated.sql | 184 ++++++++++++++++++ .../gmx_v2_arbitrum_open_interest_updated.sql | 181 +++++++++++++++++ .../gmx_v2_arbitrum_oracle_price_update.sql | 150 ++++++++++++++ .../gmx_v2_arbitrum_order_created.sql | 12 +- .../gmx_v2_arbitrum_order_updated.sql | 31 ++- .../gmx_v2_arbitrum_pool_amount_updated.sql | 160 +++++++++++++++ ...mx_v2_arbitrum_position_fees_collected.sql | 86 +++++--- .../gmx_v2_arbitrum_position_fees_info.sql | 84 +++++--- .../arbitrum/gmx_v2_arbitrum_set_uint.sql | 159 +++++++++++++++ 9 files changed, 978 insertions(+), 69 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql new file mode 100644 index 00000000000..fd92530a51c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql @@ -0,0 +1,184 @@ + +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'open_interest_in_tokens_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OpenInterestInTokensUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender, + varbinary_substring(topic1, 13, 20) as account + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender, + varbinary_substring(topic2, 13, 20) as account + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(EDP.market) AS market, + from_hex(EDP.collateral_token) AS collateral_token, + CAST(EDP.is_long AS BOOLEAN) AS is_long, + CAST(EDP.next_value AS DOUBLE) / POWER(10, MD.index_token_decimals) AS next_value, + CAST(EDP.delta AS DOUBLE) / POWER(10, MD.index_token_decimals) AS delta, + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON from_hex(EDP.market) = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql new file mode 100644 index 00000000000..2451c10596e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql @@ -0,0 +1,181 @@ + +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'open_interest_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OpenInterestUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(is_long AS BOOLEAN) AS is_long, + TRY_CAST(delta AS DOUBLE) / POWER(10, 30) AS delta, + TRY_CAST(next_value AS DOUBLE) / POWER(10, 30) AS next_value + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql new file mode 100644 index 00000000000..55b34d0ba1e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -0,0 +1,150 @@ + +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'open_price_update', + materialized = 'table' + ) +}} + +{%- set event_name = 'OraclePriceUpdate' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + AND evt_block_time > DATE '2023-08-01' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + AND evt_block_time > DATE '2023-08-01' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'token' THEN value END) AS token, + MAX(CASE WHEN key_name = 'provider' THEN value END) AS provider, + MAX(CASE WHEN key_name = 'minPrice' THEN value END) AS min_price, + MAX(CASE WHEN key_name = 'maxPrice' THEN value END) AS max_price, + MAX(CASE WHEN key_name = 'timestamp' THEN value END) AS "timestamp" + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(token) AS token, + from_hex(provider) AS provider, + TRY_CAST(min_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS min_price, + TRY_CAST(max_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS max_price, + CASE + WHEN "timestamp" = 0 THEN NULL + ELSE "timestamp" + END AS "timestamp" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20 + ON from_hex(EDP.token) = ERC20.contract_address +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 4339e211083..6f23476ac3e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -169,12 +169,12 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, - MAX(CASE WHEN key_name = 'updatedAtBlock' THEN value END) AS updated_at_block, MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, - MAX(CASE WHEN key_name = 'isFrozen' THEN value END) AS is_frozen, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel, MAX(CASE WHEN key_name = 'key' THEN value END) AS key FROM @@ -211,11 +211,11 @@ WITH evt_data_1 AS ( TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, - TRY_CAST(updated_at_block AS BIGINT) AS updated_at_block, TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, TRY_CAST(is_long AS BOOLEAN) AS is_long, TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, - TRY_CAST(is_frozen AS BOOLEAN) AS is_frozen, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel, from_hex(key) AS key FROM evt_data AS ED @@ -279,14 +279,14 @@ WITH evt_data_1 AS ( callback_gas_limit, min_output_amount AS min_output_amount_raw, - updated_at_block, CASE WHEN updated_at_time = 0 THEN NULL ELSE updated_at_time END AS updated_at_time, + valid_from_time, is_long, should_unwrap_native_token, - is_frozen, + auto_cancel, key FROM event_data AS ED diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql index 4fe2a489b05..3f0c1196068 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -58,7 +58,8 @@ WITH evt_data_1 AS ( index, json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items FROM evt_data ) @@ -102,6 +103,19 @@ WITH evt_data_1 AS ( ) AS t(item) ) +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + , combined AS ( SELECT * FROM bytes32_items_parsed @@ -111,6 +125,9 @@ WITH evt_data_1 AS ( UNION ALL SELECT * FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed ) , evt_data_parsed AS ( @@ -123,7 +140,9 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'acceptablePrice' THEN value END) AS acceptable_price, MAX(CASE WHEN key_name = 'triggerPrice' THEN value END) AS trigger_price, MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, - MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel FROM combined GROUP BY tx_hash, index @@ -147,7 +166,9 @@ WITH evt_data_1 AS ( TRY_CAST(acceptable_price AS DOUBLE) AS acceptable_price, TRY_CAST(trigger_price AS DOUBLE) AS trigger_price, TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, - TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP @@ -186,7 +207,9 @@ WITH evt_data_1 AS ( CASE WHEN ED.updated_at_time = 0 THEN NULL ELSE ED.updated_at_time - END AS updated_at_time + END AS updated_at_time, + valid_from_time, + auto_cancel FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql new file mode 100644 index 00000000000..8f36d76fbcc --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql @@ -0,0 +1,160 @@ + +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'pool_amount_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'PoolAmountUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items + FROM + evt_data +) +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, int_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM int_items_parsed +) +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'token' THEN value END) AS token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(token) AS token, + TRY_CAST(next_value AS DOUBLE) / POWER(10, ERC20.decimals) AS next_value, + TRY_CAST(delta AS DOUBLE) / POWER(10, ERC20.decimals) AS delta + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index + LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20 + ON from_hex(EDP.token) = ERC20.contract_address +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql index fa7d065f5fa..f8b8ddc0cc9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql @@ -135,19 +135,19 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +168,19 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'adjustedAffiliateRewardFactor' THEN value END) AS adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +199,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +232,20 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(adjusted_affiliate_reward_factor AS DOUBLE) AS adjusted_affiliate_reward_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +265,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +277,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,11 +298,20 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code - + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + adjusted_affiliate_reward_factor / POWER(10, 30) AS adjusted_affiliate_reward_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD ON ED.market = MD.market diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql index 4a7432cea9b..ffd31aa9bac 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql @@ -135,19 +135,19 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +168,19 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'adjustedAffiliateRewardFactor' THEN value END) AS adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +199,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +232,20 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(adjusted_affiliate_reward_factor AS DOUBLE) AS adjusted_affiliate_reward_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +265,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +277,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,10 +298,19 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + adjusted_affiliate_reward_factor / POWER(10, 30) AS adjusted_affiliate_reward_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql new file mode 100644 index 00000000000..102747fcad1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql @@ -0,0 +1,159 @@ + +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'set_uint', + materialized = 'table' + ) +}} + +{%- set event_name = 'SetUint' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'baseKey' THEN value END) AS base_key, + MAX(CASE WHEN key_name = 'data' THEN value END) AS data_key, + MAX(CASE WHEN key_name = 'value' THEN value END) AS value + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(base_key) AS base_key, + from_hex(data_key) AS data_key, + TRY_CAST(value AS DOUBLE) / POWER(10, 30) AS value + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to', 'index'] + ) +}} From f6806e13c0ed694352aac8a6f2cfc880d0fb72d4 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Tue, 26 Nov 2024 16:59:20 +0200 Subject: [PATCH 2/9] Update 4 Event Models --- ...bitrum_open_interest_in_tokens_updated.sql | 184 ------------------ .../gmx_v2_arbitrum_open_interest_updated.sql | 181 ----------------- .../gmx_v2_arbitrum_oracle_price_update.sql | 150 -------------- .../gmx_v2_arbitrum_order_created.sql | 11 +- .../gmx_v2_arbitrum_order_updated.sql | 10 +- .../gmx_v2_arbitrum_pool_amount_updated.sql | 160 --------------- ...mx_v2_arbitrum_position_fees_collected.sql | 22 ++- .../gmx_v2_arbitrum_position_fees_info.sql | 46 ++++- .../arbitrum/gmx_v2_arbitrum_set_uint.sql | 159 --------------- .../gmx_v2_avalanche_c_position_fees_info.sql | 5 + 10 files changed, 79 insertions(+), 849 deletions(-) delete mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql 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 deleted file mode 100644 index fd92530a51c..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql +++ /dev/null @@ -1,184 +0,0 @@ - -{{ - config( - schema = 'gmx_v2_arbitrum', - alias = 'open_interest_in_tokens_updated', - materialized = 'table' - ) -}} - -{%- set event_name = 'OpenInterestInTokensUpdated' -%} -{%- set blockchain_name = 'arbitrum' -%} - - -WITH evt_data_1 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender, - varbinary_substring(topic1, 13, 20) as account - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - -, evt_data_2 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender, - varbinary_substring(topic2, 13, 20) as account - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - --- unite 2 tables -, evt_data AS ( - SELECT * - FROM evt_data_1 - UNION - SELECT * - FROM evt_data_2 -) -, parsed_data AS ( - SELECT - tx_hash, - index, - json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, - json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, - json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items - FROM - evt_data -) - -, address_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, uint_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, int_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, bool_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, combined AS ( - SELECT * - FROM address_items_parsed - UNION ALL - SELECT * - FROM uint_items_parsed - UNION ALL - SELECT * - FROM int_items_parsed - UNION ALL - SELECT * - FROM bool_items_parsed -) - -, evt_data_parsed AS ( - SELECT - tx_hash, - index, - MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, - MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value, - MAX(CASE WHEN key_name = 'market' THEN value END) AS market, - MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, - MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta - FROM - combined - GROUP BY tx_hash, index -) - --- full data -, full_data AS ( - SELECT - blockchain, - block_time, - DATE(block_time) AS block_date, - block_number, - ED.tx_hash, - ED.index, - contract_address, - event_name, - msg_sender, - - from_hex(EDP.market) AS market, - from_hex(EDP.collateral_token) AS collateral_token, - CAST(EDP.is_long AS BOOLEAN) AS is_long, - CAST(EDP.next_value AS DOUBLE) / POWER(10, MD.index_token_decimals) AS next_value, - CAST(EDP.delta AS DOUBLE) / POWER(10, MD.index_token_decimals) AS delta, - - FROM evt_data AS ED - LEFT JOIN evt_data_parsed AS EDP - ON ED.tx_hash = EDP.tx_hash - AND ED.index = EDP.index - LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD - ON from_hex(EDP.market) = MD.market -) - ---can be removed once decoded tables are fully denormalized -{{ - add_tx_columns( - model_cte = 'full_data' - , blockchain = blockchain_name - , columns = ['from', 'to', 'index'] - ) -}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql deleted file mode 100644 index 2451c10596e..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql +++ /dev/null @@ -1,181 +0,0 @@ - -{{ - config( - schema = 'gmx_v2_arbitrum', - alias = 'open_interest_updated', - materialized = 'table' - ) -}} - -{%- set event_name = 'OpenInterestUpdated' -%} -{%- set blockchain_name = 'arbitrum' -%} - - -WITH evt_data_1 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - -, evt_data_2 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - --- unite 2 tables -, evt_data AS ( - SELECT * - FROM evt_data_1 - UNION - SELECT * - FROM evt_data_2 -) - -, parsed_data AS ( - SELECT - tx_hash, - index, - json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, - json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items, - json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items - FROM - evt_data -) - -, address_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, uint_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, int_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, bool_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, combined AS ( - SELECT * - FROM address_items_parsed - UNION ALL - SELECT * - FROM uint_items_parsed - UNION ALL - SELECT * - FROM int_items_parsed - UNION ALL - SELECT * - FROM bool_items_parsed -) - -, evt_data_parsed AS ( - SELECT - tx_hash, - index, - MAX(CASE WHEN key_name = 'market' THEN value END) AS market, - MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, - MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, - MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, - MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value - FROM - combined - GROUP BY tx_hash, index -) - --- full data -, full_data AS ( - SELECT - blockchain, - block_time, - DATE(block_time) AS block_date, - block_number, - ED.tx_hash, - ED.index, - contract_address, - event_name, - msg_sender, - - from_hex(market) AS market, - from_hex(collateral_token) AS collateral_token, - TRY_CAST(is_long AS BOOLEAN) AS is_long, - TRY_CAST(delta AS DOUBLE) / POWER(10, 30) AS delta, - TRY_CAST(next_value AS DOUBLE) / POWER(10, 30) AS next_value - - FROM evt_data AS ED - LEFT JOIN evt_data_parsed AS EDP - ON ED.tx_hash = EDP.tx_hash - AND ED.index = EDP.index -) - ---can be removed once decoded tables are fully denormalized -{{ - add_tx_columns( - model_cte = 'full_data' - , blockchain = blockchain_name - , columns = ['from', 'to', 'index'] - ) -}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql deleted file mode 100644 index 55b34d0ba1e..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql +++ /dev/null @@ -1,150 +0,0 @@ - -{{ - config( - schema = 'gmx_v2_arbitrum', - alias = 'open_price_update', - materialized = 'table' - ) -}} - -{%- set event_name = 'OraclePriceUpdate' -%} -{%- set blockchain_name = 'arbitrum' -%} - - -WITH evt_data_1 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} - WHERE eventName = '{{ event_name }}' - AND evt_block_time > DATE '2023-08-01' - ORDER BY evt_block_time ASC -) - -, evt_data_2 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} - WHERE eventName = '{{ event_name }}' - AND evt_block_time > DATE '2023-08-01' - ORDER BY evt_block_time ASC -) - --- unite 2 tables -, evt_data AS ( - SELECT * - FROM evt_data_1 - UNION - SELECT * - FROM evt_data_2 -) -, parsed_data AS ( - SELECT - tx_hash, - index, - json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items - FROM - evt_data -) -, address_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) -, uint_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) -, combined AS ( - SELECT * - FROM address_items_parsed - UNION ALL - SELECT * - FROM uint_items_parsed -) -, evt_data_parsed AS ( - SELECT - tx_hash, - index, - MAX(CASE WHEN key_name = 'token' THEN value END) AS token, - MAX(CASE WHEN key_name = 'provider' THEN value END) AS provider, - MAX(CASE WHEN key_name = 'minPrice' THEN value END) AS min_price, - MAX(CASE WHEN key_name = 'maxPrice' THEN value END) AS max_price, - MAX(CASE WHEN key_name = 'timestamp' THEN value END) AS "timestamp" - FROM - combined - GROUP BY tx_hash, index -) - --- full data -, full_data AS ( - SELECT - blockchain, - block_time, - DATE(block_time) AS block_date, - block_number, - ED.tx_hash, - ED.index, - contract_address, - event_name, - msg_sender, - - from_hex(token) AS token, - from_hex(provider) AS provider, - TRY_CAST(min_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS min_price, - TRY_CAST(max_price AS DOUBLE) / POWER(10, 30 - ERC20.decimals) AS max_price, - CASE - WHEN "timestamp" = 0 THEN NULL - ELSE "timestamp" - END AS "timestamp" - - FROM evt_data AS ED - LEFT JOIN evt_data_parsed AS EDP - ON ED.tx_hash = EDP.tx_hash - AND ED.index = EDP.index - LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20 - ON from_hex(EDP.token) = ERC20.contract_address -) - ---can be removed once decoded tables are fully denormalized -{{ - add_tx_columns( - model_cte = 'full_data' - , blockchain = blockchain_name - , columns = ['from', 'to', 'index'] - ) -}} - diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 6f23476ac3e..11b398ebb49 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -283,10 +283,17 @@ WITH evt_data_1 AS ( WHEN updated_at_time = 0 THEN NULL ELSE updated_at_time END AS updated_at_time, - valid_from_time, + CASE + WHEN valid_from_time = 0 THEN NULL + ELSE valid_from_time + END AS valid_from_time, is_long, should_unwrap_native_token, - auto_cancel, + + CASE + WHEN auto_cancel IS NULL THEN false + ELSE auto_cancel + END AS auto_cancel, key FROM event_data AS ED diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql index 3f0c1196068..1479f50a097 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -208,8 +208,14 @@ WITH evt_data_1 AS ( WHEN ED.updated_at_time = 0 THEN NULL ELSE ED.updated_at_time END AS updated_at_time, - valid_from_time, - auto_cancel + CASE + WHEN ED.valid_from_time = 0 THEN NULL + ELSE ED.valid_from_time + END AS valid_from_time, + CASE + WHEN ED.auto_cancel IS NULL THEN false + ELSE ED.auto_cancel + END AS auto_cancel FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql deleted file mode 100644 index 8f36d76fbcc..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql +++ /dev/null @@ -1,160 +0,0 @@ - -{{ - config( - schema = 'gmx_v2_arbitrum', - alias = 'pool_amount_updated', - materialized = 'table' - ) -}} - -{%- set event_name = 'PoolAmountUpdated' -%} -{%- set blockchain_name = 'arbitrum' -%} - - -WITH evt_data_1 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - -, evt_data_2 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - --- unite 2 tables -, evt_data AS ( - SELECT * - FROM evt_data_1 - UNION - SELECT * - FROM evt_data_2 -) - -, parsed_data AS ( - SELECT - tx_hash, - index, - json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, - json_query(data, 'lax $.intItems' OMIT QUOTES) AS int_items - FROM - evt_data -) -, address_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) -, uint_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) -, int_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(int_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) -, combined AS ( - SELECT * - FROM address_items_parsed - UNION ALL - SELECT * - FROM uint_items_parsed - UNION ALL - SELECT * - FROM int_items_parsed -) -, evt_data_parsed AS ( - SELECT - tx_hash, - index, - MAX(CASE WHEN key_name = 'market' THEN value END) AS market, - MAX(CASE WHEN key_name = 'token' THEN value END) AS token, - MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, - MAX(CASE WHEN key_name = 'nextValue' THEN value END) AS next_value - FROM - combined - GROUP BY tx_hash, index -) - --- full data -, full_data AS ( - SELECT - blockchain, - block_time, - DATE(block_time) AS block_date, - block_number, - ED.tx_hash, - ED.index, - contract_address, - event_name, - msg_sender, - - from_hex(market) AS market, - from_hex(token) AS token, - TRY_CAST(next_value AS DOUBLE) / POWER(10, ERC20.decimals) AS next_value, - TRY_CAST(delta AS DOUBLE) / POWER(10, ERC20.decimals) AS delta - - FROM evt_data AS ED - LEFT JOIN evt_data_parsed AS EDP - ON ED.tx_hash = EDP.tx_hash - AND ED.index = EDP.index - LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20 - ON from_hex(EDP.token) = ERC20.contract_address -) - ---can be removed once decoded tables are fully denormalized -{{ - add_tx_columns( - model_cte = 'full_data' - , blockchain = blockchain_name - , columns = ['from', 'to', 'index'] - ) -}} - diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql index f8b8ddc0cc9..4c69a3348f5 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 @@ -170,11 +170,20 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'adjustedAffiliateRewardFactor' THEN value END) AS adjusted_affiliate_reward_factor, MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, @@ -234,12 +243,21 @@ WITH evt_data_1 AS ( TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(adjusted_affiliate_reward_factor AS DOUBLE) AS adjusted_affiliate_reward_factor, TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, 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 ffd31aa9bac..71fce15006b 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 @@ -148,6 +148,7 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, + MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -170,11 +171,20 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'adjustedAffiliateRewardFactor' THEN value END) AS adjusted_affiliate_reward_factor, MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, @@ -234,15 +244,24 @@ WITH evt_data_1 AS ( TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(adjusted_affiliate_reward_factor AS DOUBLE) AS adjusted_affiliate_reward_factor, TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, - TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, - TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, - TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, TRY_CAST(is_increase AS BOOLEAN) AS is_increase @@ -300,15 +319,24 @@ WITH evt_data_1 AS ( ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - adjusted_affiliate_reward_factor / POWER(10, 30) AS adjusted_affiliate_reward_factor, trader_discount_factor / POWER(10, 30) AS trader_discount_factor, total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, - liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, - liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, - liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, is_increase 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 deleted file mode 100644 index 102747fcad1..00000000000 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql +++ /dev/null @@ -1,159 +0,0 @@ - -{{ - config( - schema = 'gmx_v2_arbitrum', - alias = 'set_uint', - materialized = 'table' - ) -}} - -{%- set event_name = 'SetUint' -%} -{%- set blockchain_name = 'arbitrum' -%} - - -WITH evt_data_1 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - -, evt_data_2 AS ( - SELECT - -- Main Variables - '{{ blockchain_name }}' AS blockchain, - evt_block_time AS block_time, - evt_block_number AS block_number, - evt_tx_hash AS tx_hash, - evt_index AS index, - contract_address, - eventName AS event_name, - eventData AS data, - msgSender AS msg_sender - FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} - WHERE eventName = '{{ event_name }}' - ORDER BY evt_block_time ASC -) - --- unite 2 tables -, evt_data AS ( - SELECT * - FROM evt_data_1 - UNION - SELECT * - FROM evt_data_2 -) - -, parsed_data AS ( - SELECT - tx_hash, - index, - json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, - json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items - FROM - evt_data -) - -, bytes32_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, bytes_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, uint_items_parsed AS ( - SELECT - tx_hash, - index, - json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, - json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value - FROM - parsed_data, - UNNEST( - CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) - ) AS t(item) -) - -, combined AS ( - SELECT * - FROM bytes32_items_parsed - UNION ALL - SELECT * - FROM bytes_items_parsed - UNION ALL - SELECT * - FROM uint_items_parsed -) - -, evt_data_parsed AS ( - SELECT - tx_hash, - index, - MAX(CASE WHEN key_name = 'baseKey' THEN value END) AS base_key, - MAX(CASE WHEN key_name = 'data' THEN value END) AS data_key, - MAX(CASE WHEN key_name = 'value' THEN value END) AS value - FROM - combined - GROUP BY tx_hash, index -) - --- full data -, full_data AS ( - SELECT - blockchain, - block_time, - DATE(block_time) AS block_date, - block_number, - ED.tx_hash, - ED.index, - contract_address, - event_name, - msg_sender, - - from_hex(base_key) AS base_key, - from_hex(data_key) AS data_key, - TRY_CAST(value AS DOUBLE) / POWER(10, 30) AS value - FROM evt_data AS ED - LEFT JOIN evt_data_parsed AS EDP - ON ED.tx_hash = EDP.tx_hash - AND ED.index = EDP.index -) - ---can be removed once decoded tables are fully denormalized -{{ - add_tx_columns( - model_cte = 'full_data' - , blockchain = blockchain_name - , columns = ['from', 'to', 'index'] - ) -}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql index 0e71e6ccfdf..3c5bd6bdc78 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 @@ -140,14 +140,17 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,7 +171,9 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code From 81a8bdb96f322d5e5d5e68d61173c05f0aaa654d Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Tue, 26 Nov 2024 17:48:57 +0200 Subject: [PATCH 3/9] fix Error --- .../gmx_v2_arbitrum_position_fees_collected.sql | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 4c69a3348f5..e849c8e69ce 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 @@ -318,12 +318,21 @@ WITH evt_data_1 AS ( ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - adjusted_affiliate_reward_factor / POWER(10, 30) AS adjusted_affiliate_reward_factor, trader_discount_factor / POWER(10, 30) AS trader_discount_factor, total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, From 34cde13ef9d984b973b306626faa55473d28f6fe Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 21:33:46 +0200 Subject: [PATCH 4/9] Final changes on 4 event models --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 108 +++++++--- .../gmx_v2_arbitrum_order_created.sql | 8 +- .../gmx_v2_arbitrum_order_updated.sql | 10 +- ...mx_v2_arbitrum_position_fees_collected.sql | 89 ++++++++ .../gmx_v2_arbitrum_position_fees_info.sql | 89 ++++++++ .../gmx_v2_avalanche_c_event_schema.yml | 110 +++++++--- .../gmx_v2_avalanche_c_order_created.sql | 15 +- .../gmx_v2_avalanche_c_order_updated.sql | 31 ++- ...v2_avalanche_c_position_fees_collected.sql | 202 +++++++++++++++--- .../gmx_v2_avalanche_c_position_fees_info.sql | 200 ++++++++++++++--- .../gmx/event/gmx_v2_event_schema.yml | 108 +++++++--- .../gmx/event/gmx_v2_order_created.sql | 3 +- .../gmx/event/gmx_v2_order_updated.sql | 5 +- .../event/gmx_v2_position_fees_collected.sql | 16 +- .../gmx/event/gmx_v2_position_fees_info.sql | 16 +- 15 files changed, 816 insertions(+), 194 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index d61b2d58e13..c78dee73773 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 @@ -158,6 +158,8 @@ models: - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. + - name: valid_from_time + description: The time from which the order becomes valid for execution. - &is_long name: is_long description: A boolean indicating whether the position is long @@ -165,8 +167,8 @@ models: - not_null - name: should_unwrap_native_token description: Boolean indicating if the native token should be unwrapped. - - name: is_frozen - description: Boolean indicating if the order is frozen. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. - &key name: key description: The unique identifier for the order, stored as a bytes32 value. @@ -604,31 +606,6 @@ models: description: The size of the trade in USD data_tests: - not_null - - &total_rebate_factor - name: total_rebate_factor - description: The total rebate factor for the position - data_tests: - - not_null - - &trader_discount_factor - name: trader_discount_factor - description: The discount factor applied to the trader - data_tests: - - not_null - - &total_rebate_amount - name: total_rebate_amount - description: The total amount of rebate given - data_tests: - - not_null - - &trader_discount_amount - name: trader_discount_amount - description: The amount of discount given to the trader - data_tests: - - not_null - - &affiliate_reward_amount - name: affiliate_reward_amount - description: The reward amount given to the affiliate - data_tests: - - not_null - &funding_fee_amount name: funding_fee_amount description: The amount of funding fee charged @@ -729,6 +706,61 @@ models: description: The total amount of UI fee collected data_tests: - not_null + - &referral_total_rebate_factor + name: referral_total_rebate_factor + description: The total rebate factor associated with referrals. + data_tests: + - not_null + - &referral_total_rebate_amount + name: referral_total_rebate_amount + description: The total rebate amount given for referrals. + data_tests: + - not_null + - &referral_trader_discount_factor + name: referral_trader_discount_factor + description: The discount factor applied to the trader through referrals. + data_tests: + - not_null + - &referral_adjusted_affiliate_reward_factor + name: referral_adjusted_affiliate_reward_factor + description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null + - &referral_affiliate_reward_amount + name: referral_affiliate_reward_amount + description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null + - &referral_trader_discount_amount + name: referral_trader_discount_amount + description: The discount amount given to the trader through referrals. + data_tests: + - not_null + - &pro_trader_discount_factor + name: pro_trader_discount_factor + description: The discount factor applied for pro traders. + data_tests: + - not_null + - &pro_trader_discount_amount + name: pro_trader_discount_amount + description: The discount amount given to pro traders. + data_tests: + - not_null + - &liquidation_fee_amount + name: liquidation_fee_amount + description: The amount of fees charged during liquidation. + data_tests: + - not_null + - &liquidation_fee_receiver_factor + name: liquidation_fee_receiver_factor + description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null + - &liquidation_fee_amount_for_fee_receiver + name: liquidation_fee_amount_for_fee_receiver + description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) @@ -785,11 +817,6 @@ models: - *collateral_token_price_min - *collateral_token_price_max - *trade_size_usd - - *total_rebate_factor - - *trader_discount_factor - - *total_rebate_amount - - *trader_discount_amount - - *affiliate_reward_amount - *funding_fee_amount - *claimable_long_token_amount - *claimable_short_token_amount @@ -810,6 +837,17 @@ models: - *total_cost_amount - *ui_fee_receiver_factor - *ui_fee_amount + - *referral_total_rebate_factor + - *referral_total_rebate_amount + - *referral_trader_discount_factor + - *referral_adjusted_affiliate_reward_factor + - *referral_affiliate_reward_amount + - *referral_trader_discount_amount + - *pro_trader_discount_factor + - *pro_trader_discount_amount + - *liquidation_fee_amount + - *liquidation_fee_receiver_factor + - *liquidation_fee_amount_for_fee_receiver - *is_increase - *order_key - *position_key @@ -909,4 +947,8 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + - name: valid_from_time + description: The time from which the order becomes valid for execution. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 11b398ebb49..37823907ffc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -169,6 +169,7 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, + MAX(CASE WHEN key_name = 'updatedAtBlock' THEN value END) AS updated_at_block, MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, @@ -211,6 +212,7 @@ WITH evt_data_1 AS ( TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, + TRY_CAST(updated_at_block AS BIGINT) AS updated_at_block, TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, TRY_CAST(is_long AS BOOLEAN) AS is_long, @@ -279,14 +281,12 @@ WITH evt_data_1 AS ( callback_gas_limit, min_output_amount AS min_output_amount_raw, + updated_at_block, CASE WHEN updated_at_time = 0 THEN NULL ELSE updated_at_time END AS updated_at_time, - CASE - WHEN valid_from_time = 0 THEN NULL - ELSE valid_from_time - END AS valid_from_time, + valid_from_time, is_long, should_unwrap_native_token, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql index 1479f50a097..edb33308631 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -208,14 +208,8 @@ WITH evt_data_1 AS ( WHEN ED.updated_at_time = 0 THEN NULL ELSE ED.updated_at_time END AS updated_at_time, - CASE - WHEN ED.valid_from_time = 0 THEN NULL - ELSE ED.valid_from_time - END AS valid_from_time, - CASE - WHEN ED.auto_cancel IS NULL THEN false - ELSE ED.auto_cancel - END AS auto_cancel + ED.valid_from_time, + ED.auto_cancel FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql index e849c8e69ce..f58b8608d5d 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 @@ -346,6 +346,95 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( 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 71fce15006b..212f79eeb83 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 @@ -347,6 +347,95 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index d43cb91644a..bfd9d48a489 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 @@ -155,9 +155,11 @@ models: description: The block number at which the order was last updated. data_tests: - not_null - - &updated_at_time + - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. + - name: valid_from_time + description: The time from which the order becomes valid for execution. - &is_long name: is_long description: A boolean indicating whether the position is long @@ -165,8 +167,8 @@ models: - not_null - name: should_unwrap_native_token description: Boolean indicating if the native token should be unwrapped. - - name: is_frozen - description: Boolean indicating if the order is frozen. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. - &key name: key description: The unique identifier for the order, stored as a bytes32 value. @@ -604,31 +606,6 @@ models: description: The size of the trade in USD data_tests: - not_null - - &total_rebate_factor - name: total_rebate_factor - description: The total rebate factor for the position - data_tests: - - not_null - - &trader_discount_factor - name: trader_discount_factor - description: The discount factor applied to the trader - data_tests: - - not_null - - &total_rebate_amount - name: total_rebate_amount - description: The total amount of rebate given - data_tests: - - not_null - - &trader_discount_amount - name: trader_discount_amount - description: The amount of discount given to the trader - data_tests: - - not_null - - &affiliate_reward_amount - name: affiliate_reward_amount - description: The reward amount given to the affiliate - data_tests: - - not_null - &funding_fee_amount name: funding_fee_amount description: The amount of funding fee charged @@ -729,6 +706,61 @@ models: description: The total amount of UI fee collected data_tests: - not_null + - &referral_total_rebate_factor + name: referral_total_rebate_factor + description: The total rebate factor associated with referrals. + data_tests: + - not_null + - &referral_total_rebate_amount + name: referral_total_rebate_amount + description: The total rebate amount given for referrals. + data_tests: + - not_null + - &referral_trader_discount_factor + name: referral_trader_discount_factor + description: The discount factor applied to the trader through referrals. + data_tests: + - not_null + - &referral_adjusted_affiliate_reward_factor + name: referral_adjusted_affiliate_reward_factor + description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null + - &referral_affiliate_reward_amount + name: referral_affiliate_reward_amount + description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null + - &referral_trader_discount_amount + name: referral_trader_discount_amount + description: The discount amount given to the trader through referrals. + data_tests: + - not_null + - &pro_trader_discount_factor + name: pro_trader_discount_factor + description: The discount factor applied for pro traders. + data_tests: + - not_null + - &pro_trader_discount_amount + name: pro_trader_discount_amount + description: The discount amount given to pro traders. + data_tests: + - not_null + - &liquidation_fee_amount + name: liquidation_fee_amount + description: The amount of fees charged during liquidation. + data_tests: + - not_null + - &liquidation_fee_receiver_factor + name: liquidation_fee_receiver_factor + description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null + - &liquidation_fee_amount_for_fee_receiver + name: liquidation_fee_amount_for_fee_receiver + description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) @@ -785,11 +817,6 @@ models: - *collateral_token_price_min - *collateral_token_price_max - *trade_size_usd - - *total_rebate_factor - - *trader_discount_factor - - *total_rebate_amount - - *trader_discount_amount - - *affiliate_reward_amount - *funding_fee_amount - *claimable_long_token_amount - *claimable_short_token_amount @@ -810,6 +837,17 @@ models: - *total_cost_amount - *ui_fee_receiver_factor - *ui_fee_amount + - *referral_total_rebate_factor + - *referral_total_rebate_amount + - *referral_trader_discount_factor + - *referral_adjusted_affiliate_reward_factor + - *referral_affiliate_reward_amount + - *referral_trader_discount_amount + - *pro_trader_discount_factor + - *pro_trader_discount_amount + - *liquidation_fee_amount + - *liquidation_fee_receiver_factor + - *liquidation_fee_amount_for_fee_receiver - *is_increase - *order_key - *position_key @@ -909,4 +947,8 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + - name: valid_from_time + description: The time from which the order becomes valid for execution. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql index cec7a4baf06..ba428954368 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql @@ -171,10 +171,11 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'updatedAtBlock' THEN value END) AS updated_at_block, MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long, MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, - MAX(CASE WHEN key_name = 'isFrozen' THEN value END) AS is_frozen, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel, MAX(CASE WHEN key_name = 'key' THEN value END) AS key FROM @@ -213,9 +214,10 @@ WITH evt_data_1 AS ( TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, TRY_CAST(updated_at_block AS BIGINT) AS updated_at_block, TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, TRY_CAST(is_long AS BOOLEAN) AS is_long, TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, - TRY_CAST(is_frozen AS BOOLEAN) AS is_frozen, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel, from_hex(key) AS key FROM evt_data AS ED @@ -272,7 +274,7 @@ WITH evt_data_1 AS ( END AS trigger_price, acceptable_price AS acceptable_price_raw, CASE - WHEN index_token_decimals IS NULL THEN NULL + WHEN index_token_decimals IS NULL THEN NULL ELSE acceptable_price / POWER(10, 30 - index_token_decimals) END AS acceptable_price, execution_fee / POWER(10, 18) AS execution_fee, @@ -284,9 +286,14 @@ WITH evt_data_1 AS ( WHEN updated_at_time = 0 THEN NULL ELSE updated_at_time END AS updated_at_time, + valid_from_time, is_long, should_unwrap_native_token, - is_frozen, + + CASE + WHEN auto_cancel IS NULL THEN false + ELSE auto_cancel + END AS auto_cancel, key FROM event_data AS ED diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql index 5f0b28869f7..0f56ec17a91 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql @@ -58,7 +58,8 @@ WITH evt_data_1 AS ( index, json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, - json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items FROM evt_data ) @@ -102,6 +103,19 @@ WITH evt_data_1 AS ( ) AS t(item) ) +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + , combined AS ( SELECT * FROM bytes32_items_parsed @@ -111,6 +125,9 @@ WITH evt_data_1 AS ( UNION ALL SELECT * FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed ) , evt_data_parsed AS ( @@ -123,7 +140,9 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'acceptablePrice' THEN value END) AS acceptable_price, MAX(CASE WHEN key_name = 'triggerPrice' THEN value END) AS trigger_price, MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, - MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'validFromTime' THEN value END) AS valid_from_time, + MAX(CASE WHEN key_name = 'autoCancel' THEN value END) AS auto_cancel FROM combined GROUP BY tx_hash, index @@ -147,7 +166,9 @@ WITH evt_data_1 AS ( TRY_CAST(acceptable_price AS DOUBLE) AS acceptable_price, TRY_CAST(trigger_price AS DOUBLE) AS trigger_price, TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, - TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(valid_from_time AS DOUBLE) AS valid_from_time, + TRY_CAST(auto_cancel AS BOOLEAN) AS auto_cancel FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP @@ -186,7 +207,9 @@ WITH evt_data_1 AS ( CASE WHEN ED.updated_at_time = 0 THEN NULL ELSE ED.updated_at_time - END AS updated_at_time + END AS updated_at_time, + ED.valid_from_time, + ED.auto_cancel FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_avalanche_c_order_created') }} AS OC diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql index 2241dfb0e56..d390c9d4fdc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql @@ -135,19 +135,19 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, MAX(CASE WHEN key_name = 'trader' THEN value END) AS trader, MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'collateralTokenPrice.min' THEN value END) AS collateral_token_price_min, MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -168,10 +168,28 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, + + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -190,19 +208,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -223,11 +241,29 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -247,6 +283,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -255,12 +295,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -281,11 +316,29 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD ON ED.market = MD.market @@ -293,6 +346,95 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( @@ -300,4 +442,4 @@ WITH evt_data_1 AS ( , blockchain = blockchain_name , columns = ['from', 'to'] ) -}} +}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql index 3c5bd6bdc78..313c55263a6 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql @@ -135,6 +135,10 @@ WITH evt_data_1 AS ( tx_hash, index, + MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, + MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, + MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, MAX(CASE WHEN key_name = 'affiliate' THEN value END) AS affiliate, @@ -145,12 +149,6 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'collateralTokenPrice.max' THEN value END) AS collateral_token_price_max, MAX(CASE WHEN key_name = 'tradeSizeUsd' THEN value END) AS trade_size_usd, - MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, - MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, - MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, - MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, - MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, - MAX(CASE WHEN key_name = 'fundingFeeAmount' THEN value END) AS funding_fee_amount, MAX(CASE WHEN key_name = 'claimableLongTokenAmount' THEN value END) AS claimable_long_token_amount, MAX(CASE WHEN key_name = 'claimableShortTokenAmount' THEN value END) AS claimable_short_token_amount, @@ -171,12 +169,28 @@ WITH evt_data_1 AS ( MAX(CASE WHEN key_name = 'totalCostAmount' THEN value END) AS total_cost_amount, MAX(CASE WHEN key_name = 'uiFeeReceiverFactor' THEN value END) AS ui_fee_receiver_factor, MAX(CASE WHEN key_name = 'uiFeeAmount' THEN value END) AS ui_fee_amount, + + MAX(CASE WHEN key_name = 'totalRebateFactor' THEN value END) AS total_rebate_factor, + MAX(CASE WHEN key_name = 'traderDiscountFactor' THEN value END) AS trader_discount_factor, + MAX(CASE WHEN key_name = 'totalRebateAmount' THEN value END) AS total_rebate_amount, + MAX(CASE WHEN key_name = 'traderDiscountAmount' THEN value END) AS trader_discount_amount, + MAX(CASE WHEN key_name = 'affiliateRewardAmount' THEN value END) AS affiliate_reward_amount, - MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase, + MAX(CASE WHEN key_name = 'referral.totalRebateFactor' THEN value END) AS referral_total_rebate_factor, + MAX(CASE WHEN key_name = 'referral.adjustedAffiliateRewardFactor' THEN value END) AS referral_adjusted_affiliate_reward_factor, + MAX(CASE WHEN key_name = 'referral.traderDiscountFactor' THEN value END) AS referral_trader_discount_factor, + MAX(CASE WHEN key_name = 'referral.totalRebateAmount' THEN value END) AS referral_total_rebate_amount, + MAX(CASE WHEN key_name = 'referral.traderDiscountAmount' THEN value END) AS referral_trader_discount_amount, + MAX(CASE WHEN key_name = 'referral.affiliateRewardAmount' THEN value END) AS referral_affiliate_reward_amount, + + MAX(CASE WHEN key_name = 'pro.traderDiscountFactor' THEN value END) AS pro_trader_discount_factor, + MAX(CASE WHEN key_name = 'pro.traderDiscountAmount' THEN value END) AS pro_trader_discount_amount, + + MAX(CASE WHEN key_name = 'liquidationFeeAmount' THEN value END) AS liquidation_fee_amount, + MAX(CASE WHEN key_name = 'liquidationFeeReceiverFactor' THEN value END) AS liquidation_fee_receiver_factor, + MAX(CASE WHEN key_name = 'liquidationFeeAmountForFeeReceiver' THEN value END) AS liquidation_fee_amount_for_fee_receiver, - MAX(CASE WHEN key_name = 'orderKey' THEN value END) AS order_key, - MAX(CASE WHEN key_name = 'positionKey' THEN value END) AS position_key, - MAX(CASE WHEN key_name = 'referralCode' THEN value END) AS referral_code + MAX(CASE WHEN key_name = 'isIncrease' THEN value END) AS is_increase FROM combined @@ -195,19 +209,19 @@ WITH evt_data_1 AS ( event_name, msg_sender, + from_hex(order_key) AS order_key, + from_hex(position_key) AS position_key, + from_hex(referral_code) AS referral_code, + from_hex(market) AS market, from_hex(collateral_token) AS collateral_token, from_hex(affiliate) AS affiliate, from_hex(trader) AS trader, from_hex(ui_fee_receiver) AS ui_fee_receiver, + TRY_CAST(collateral_token_price_min AS DOUBLE) AS collateral_token_price_min, TRY_CAST(collateral_token_price_max AS DOUBLE) AS collateral_token_price_max, TRY_CAST(trade_size_usd AS DOUBLE) AS trade_size_usd, - TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, - TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, - TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, - TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, - TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, TRY_CAST(funding_fee_amount AS DOUBLE) AS funding_fee_amount, TRY_CAST(claimable_long_token_amount AS DOUBLE) AS claimable_long_token_amount, TRY_CAST(claimable_short_token_amount AS DOUBLE) AS claimable_short_token_amount, @@ -228,11 +242,29 @@ WITH evt_data_1 AS ( TRY_CAST(total_cost_amount AS DOUBLE) AS total_cost_amount, TRY_CAST(ui_fee_receiver_factor AS DOUBLE) AS ui_fee_receiver_factor, TRY_CAST(ui_fee_amount AS DOUBLE) AS ui_fee_amount, - TRY_CAST(is_increase AS BOOLEAN) AS is_increase, - from_hex(order_key) AS order_key, - from_hex(position_key) AS position_key, - from_hex(referral_code) AS referral_code - + + TRY_CAST(total_rebate_factor AS DOUBLE) AS total_rebate_factor, + TRY_CAST(trader_discount_factor AS DOUBLE) AS trader_discount_factor, + TRY_CAST(total_rebate_amount AS DOUBLE) AS total_rebate_amount, + TRY_CAST(trader_discount_amount AS DOUBLE) AS trader_discount_amount, + TRY_CAST(affiliate_reward_amount AS DOUBLE) AS affiliate_reward_amount, + + TRY_CAST(referral_total_rebate_factor AS DOUBLE) AS referral_total_rebate_factor, + TRY_CAST(referral_adjusted_affiliate_reward_factor AS DOUBLE) AS referral_adjusted_affiliate_reward_factor, + TRY_CAST(referral_trader_discount_factor AS DOUBLE) AS referral_trader_discount_factor, + TRY_CAST(referral_total_rebate_amount AS DOUBLE) AS referral_total_rebate_amount, + TRY_CAST(referral_trader_discount_amount AS DOUBLE) AS referral_trader_discount_amount, + TRY_CAST(referral_affiliate_reward_amount AS DOUBLE) AS referral_affiliate_reward_amount, + + TRY_CAST(pro_trader_discount_factor AS DOUBLE) AS pro_trader_discount_factor, + TRY_CAST(pro_trader_discount_amount AS DOUBLE) AS pro_trader_discount_amount, + + TRY_CAST(liquidation_fee_amount AS DOUBLE) AS liquidation_fee_amount, + TRY_CAST(liquidation_fee_receiver_factor AS DOUBLE) AS liquidation_fee_receiver_factor, + TRY_CAST(liquidation_fee_amount_for_fee_receiver AS DOUBLE) AS liquidation_fee_amount_for_fee_receiver, + + TRY_CAST(is_increase AS BOOLEAN) AS is_increase + FROM evt_data AS ED LEFT JOIN evt_data_parsed AS EDP ON ED.tx_hash = EDP.tx_hash @@ -252,6 +284,10 @@ WITH evt_data_1 AS ( event_name, msg_sender, + order_key, + position_key, + referral_code, + ED.market AS market, ED.collateral_token, affiliate, @@ -260,12 +296,7 @@ WITH evt_data_1 AS ( collateral_token_price_min / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_min, collateral_token_price_max / POWER(10, 30 - collateral_token_decimals) AS collateral_token_price_max, - trade_size_usd / POWER(10, 30) AS trade_size_usd, - total_rebate_factor / POWER(10, 30) AS total_rebate_factor, - trader_discount_factor / POWER(10, 30) AS trader_discount_factor, - total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, - trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, - affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + trade_size_usd / POWER(10, 30) AS trade_size_usd, funding_fee_amount / POWER(10, collateral_token_decimals + 15) AS funding_fee_amount, claimable_long_token_amount / POWER(10, long_token_decimals + 15) AS claimable_long_token_amount, claimable_short_token_amount / POWER(10, short_token_decimals + 15) AS claimable_short_token_amount, @@ -286,10 +317,28 @@ WITH evt_data_1 AS ( total_cost_amount / POWER(10, collateral_token_decimals) AS total_cost_amount, ui_fee_receiver_factor / POWER(10, 30) AS ui_fee_receiver_factor, ui_fee_amount / POWER(10, collateral_token_decimals) AS ui_fee_amount, - is_increase, - order_key, - position_key, - referral_code + + total_rebate_factor / POWER(10, 30) AS total_rebate_factor, + trader_discount_factor / POWER(10, 30) AS trader_discount_factor, + total_rebate_amount / POWER(10, collateral_token_decimals) AS total_rebate_amount, + trader_discount_amount / POWER(10, collateral_token_decimals) AS trader_discount_amount, + affiliate_reward_amount / POWER(10, collateral_token_decimals) AS affiliate_reward_amount, + + referral_total_rebate_factor / POWER(10, 30) AS referral_total_rebate_factor, + referral_adjusted_affiliate_reward_factor / POWER(10, 30) AS referral_adjusted_affiliate_reward_factor, + referral_trader_discount_factor / POWER(10, 30) AS referral_trader_discount_factor, + referral_total_rebate_amount / POWER(10, collateral_token_decimals) AS referral_total_rebate_amount, + referral_trader_discount_amount / POWER(10, collateral_token_decimals) AS referral_trader_discount_amount, + referral_affiliate_reward_amount / POWER(10, collateral_token_decimals) AS referral_affiliate_reward_amount, + + pro_trader_discount_factor / POWER(10, 30) AS pro_trader_discount_factor, + pro_trader_discount_amount / POWER(10, collateral_token_decimals) AS pro_trader_discount_amount, + + liquidation_fee_amount / POWER(10, collateral_token_decimals) AS liquidation_fee_amount, + liquidation_fee_receiver_factor / POWER(10, 30) AS liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver / POWER(10, collateral_token_decimals) AS liquidation_fee_amount_for_fee_receiver, + + is_increase FROM event_data AS ED LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD @@ -298,6 +347,95 @@ WITH evt_data_1 AS ( ON ED.collateral_token = CTD.collateral_token ) +, full_data_2 AS ( + SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + order_key, + position_key, + referral_code, + + market, + collateral_token, + affiliate, + trader, + ui_fee_receiver, + + collateral_token_price_min, + collateral_token_price_max, + trade_size_usd, + funding_fee_amount, + claimable_long_token_amount, + claimable_short_token_amount, + latest_funding_fee_amount_per_size, + latest_long_token_claimable_funding_amount_per_size, + latest_short_token_claimable_funding_amount_per_size, + borrowing_fee_usd, + borrowing_fee_amount, + borrowing_fee_receiver_factor, + borrowing_fee_amount_for_fee_receiver, + position_fee_factor, + protocol_fee_amount, + position_fee_receiver_factor, + fee_receiver_amount, + fee_amount_for_pool, + position_fee_amount_for_pool, + position_fee_amount, + total_cost_amount, + ui_fee_receiver_factor, + ui_fee_amount, + + CASE + WHEN total_rebate_factor IS NOT NULL THEN total_rebate_factor + WHEN referral_total_rebate_factor IS NOT NULL THEN referral_total_rebate_factor + ELSE 0 + END AS referral_total_rebate_factor, + CASE + WHEN total_rebate_amount IS NOT NULL THEN total_rebate_amount + WHEN referral_total_rebate_amount IS NOT NULL THEN referral_total_rebate_amount + ELSE 0 + END AS referral_total_rebate_amount, + CASE + WHEN referral_trader_discount_factor IS NOT NULL THEN referral_trader_discount_factor + WHEN trader_discount_factor IS NOT NULL THEN trader_discount_factor * total_rebate_factor + ELSE 0 + END AS referral_trader_discount_factor, + CASE + WHEN referral_adjusted_affiliate_reward_factor IS NOT NULL THEN referral_adjusted_affiliate_reward_factor + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_adjusted_affiliate_reward_factor, + CASE + WHEN referral_affiliate_reward_amount IS NOT NULL THEN referral_affiliate_reward_amount + WHEN affiliate_reward_amount IS NOT NULL THEN affiliate_reward_amount + ELSE 0 + END AS referral_affiliate_reward_amount, + CASE + WHEN referral_trader_discount_amount IS NOT NULL THEN referral_trader_discount_amount + WHEN trader_discount_amount IS NOT NULL THEN trader_discount_amount + ELSE 0 + END AS referral_trader_discount_amount, + + COALESCE(pro_trader_discount_factor, 0) AS pro_trader_discount_factor, + COALESCE(pro_trader_discount_amount, 0) AS pro_trader_discount_amount, + + COALESCE(liquidation_fee_amount, 0) AS liquidation_fee_amount, + COALESCE(liquidation_fee_receiver_factor, 0) AS liquidation_fee_receiver_factor, + COALESCE(liquidation_fee_amount_for_fee_receiver, 0) AS liquidation_fee_amount_for_fee_receiver, + + is_increase + + FROM full_data +) + --can be removed once decoded tables are fully denormalized {{ add_tx_columns( @@ -305,4 +443,4 @@ WITH evt_data_1 AS ( , blockchain = blockchain_name , columns = ['from', 'to'] ) -}} +}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index bbe86ebd151..e04cf4b6bf1 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 @@ -158,6 +158,8 @@ models: - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. + - name: valid_from_time + description: The time from which the order becomes valid for execution. - &is_long name: is_long description: A boolean indicating whether the position is long @@ -165,8 +167,8 @@ models: - not_null - name: should_unwrap_native_token description: Boolean indicating if the native token should be unwrapped. - - name: is_frozen - description: Boolean indicating if the order is frozen. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. - &key name: key description: The unique identifier for the order, stored as a bytes32 value. @@ -604,31 +606,6 @@ models: description: The size of the trade in USD data_tests: - not_null - - &total_rebate_factor - name: total_rebate_factor - description: The total rebate factor for the position - data_tests: - - not_null - - &trader_discount_factor - name: trader_discount_factor - description: The discount factor applied to the trader - data_tests: - - not_null - - &total_rebate_amount - name: total_rebate_amount - description: The total amount of rebate given - data_tests: - - not_null - - &trader_discount_amount - name: trader_discount_amount - description: The amount of discount given to the trader - data_tests: - - not_null - - &affiliate_reward_amount - name: affiliate_reward_amount - description: The reward amount given to the affiliate - data_tests: - - not_null - &funding_fee_amount name: funding_fee_amount description: The amount of funding fee charged @@ -729,6 +706,61 @@ models: description: The total amount of UI fee collected data_tests: - not_null + - &referral_total_rebate_factor + name: referral_total_rebate_factor + description: The total rebate factor associated with referrals. + data_tests: + - not_null + - &referral_total_rebate_amount + name: referral_total_rebate_amount + description: The total rebate amount given for referrals. + data_tests: + - not_null + - &referral_trader_discount_factor + name: referral_trader_discount_factor + description: The discount factor applied to the trader through referrals. + data_tests: + - not_null + - &referral_adjusted_affiliate_reward_factor + name: referral_adjusted_affiliate_reward_factor + description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null + - &referral_affiliate_reward_amount + name: referral_affiliate_reward_amount + description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null + - &referral_trader_discount_amount + name: referral_trader_discount_amount + description: The discount amount given to the trader through referrals. + data_tests: + - not_null + - &pro_trader_discount_factor + name: pro_trader_discount_factor + description: The discount factor applied for pro traders. + data_tests: + - not_null + - &pro_trader_discount_amount + name: pro_trader_discount_amount + description: The discount amount given to pro traders. + data_tests: + - not_null + - &liquidation_fee_amount + name: liquidation_fee_amount + description: The amount of fees charged during liquidation. + data_tests: + - not_null + - &liquidation_fee_receiver_factor + name: liquidation_fee_receiver_factor + description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null + - &liquidation_fee_amount_for_fee_receiver + name: liquidation_fee_amount_for_fee_receiver + description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) @@ -785,11 +817,6 @@ models: - *collateral_token_price_min - *collateral_token_price_max - *trade_size_usd - - *total_rebate_factor - - *trader_discount_factor - - *total_rebate_amount - - *trader_discount_amount - - *affiliate_reward_amount - *funding_fee_amount - *claimable_long_token_amount - *claimable_short_token_amount @@ -810,6 +837,17 @@ models: - *total_cost_amount - *ui_fee_receiver_factor - *ui_fee_amount + - *referral_total_rebate_factor + - *referral_total_rebate_amount + - *referral_trader_discount_factor + - *referral_adjusted_affiliate_reward_factor + - *referral_affiliate_reward_amount + - *referral_trader_discount_amount + - *pro_trader_discount_factor + - *pro_trader_discount_amount + - *liquidation_fee_amount + - *liquidation_fee_receiver_factor + - *liquidation_fee_amount_for_fee_receiver - *is_increase - *order_key - *position_key @@ -909,4 +947,8 @@ models: - *acceptable_price_raw - *acceptable_price - *min_output_amount_raw - - *updated_at_time \ No newline at end of file + - *updated_at_time + - name: valid_from_time + description: The time from which the order becomes valid for execution. + - name: auto_cancel + description: Boolean indicating whether the order will be automatically canceled under certain conditions. \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql index 9f95d34ebbd..11d0a609f05 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql @@ -46,9 +46,10 @@ SELECT min_output_amount_raw, updated_at_block, updated_at_time, + valid_from_time, is_long, should_unwrap_native_token, - is_frozen, + auto_cancel, key FROM {{ ref('gmx_v2_' ~ chain ~ '_order_created') }} {% if not loop.last %} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql index 9481e7bc1b6..c456c7dcc75 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql @@ -34,8 +34,9 @@ SELECT trigger_price, trigger_price_raw, min_output_amount_raw, - updated_at_time - + updated_at_time, + valid_from_time, + auto_cancel FROM {{ ref('gmx_v2_' ~ chain ~ '_order_updated') }} {% if not loop.last %} UNION ALL diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql index 78e89d3a511..c54fcae240e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_collected.sql @@ -34,11 +34,6 @@ SELECT collateral_token_price_min, collateral_token_price_max, trade_size_usd, - total_rebate_factor, - trader_discount_factor, - total_rebate_amount, - trader_discount_amount, - affiliate_reward_amount, funding_fee_amount, claimable_long_token_amount, claimable_short_token_amount, @@ -59,6 +54,17 @@ SELECT total_cost_amount, ui_fee_receiver_factor, ui_fee_amount, + referral_total_rebate_factor, + referral_total_rebate_amount, + referral_trader_discount_factor, + referral_adjusted_affiliate_reward_factor, + referral_affiliate_reward_amount, + referral_trader_discount_amount, + pro_trader_discount_factor, + pro_trader_discount_amount, + liquidation_fee_amount, + liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver, is_increase, order_key, position_key, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql index 917113693ac..feda3cbcbe2 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql @@ -34,11 +34,6 @@ SELECT collateral_token_price_min, collateral_token_price_max, trade_size_usd, - total_rebate_factor, - trader_discount_factor, - total_rebate_amount, - trader_discount_amount, - affiliate_reward_amount, funding_fee_amount, claimable_long_token_amount, claimable_short_token_amount, @@ -59,6 +54,17 @@ SELECT total_cost_amount, ui_fee_receiver_factor, ui_fee_amount, + referral_total_rebate_factor, + referral_total_rebate_amount, + referral_trader_discount_factor, + referral_adjusted_affiliate_reward_factor, + referral_affiliate_reward_amount, + referral_trader_discount_amount, + pro_trader_discount_factor, + pro_trader_discount_amount, + liquidation_fee_amount, + liquidation_fee_receiver_factor, + liquidation_fee_amount_for_fee_receiver, is_increase, order_key, position_key, From 60eeb0a0e3c2457fe0b889448612b75516a19c14 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 21:45:42 +0200 Subject: [PATCH 5/9] Empty commit --- .../models/_projects/gmx/event/gmx_v2_position_fees_info.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql index feda3cbcbe2..9ae7458454b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_position_fees_info.sql @@ -73,4 +73,4 @@ FROM {{ ref('gmx_v2_' ~ chain ~ '_position_fees_info') }} {% if not loop.last %} UNION ALL {% endif %} -{%- endfor -%} \ No newline at end of file +{%- endfor -%} From 68c75577793dcba70f0acdb294ef0152956af24d Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 22:04:25 +0200 Subject: [PATCH 6/9] fix tests --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 36 +------------------ .../gmx_v2_avalanche_c_event_schema.yml | 34 ------------------ .../gmx/event/gmx_v2_event_schema.yml | 28 --------------- 3 files changed, 1 insertion(+), 97 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index c78dee73773..230c2a58920 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -152,9 +152,7 @@ models: data_tests: - not_null - name: updated_at_block - description: The block number at which the order was last updated. - data_tests: - - not_null + description: The block number at which the order was last updated. - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. @@ -614,28 +612,18 @@ models: - &claimable_long_token_amount name: claimable_long_token_amount description: The amount of long tokens claimable - data_tests: - - not_null - &claimable_short_token_amount name: claimable_short_token_amount description: The amount of short tokens claimable - data_tests: - - not_null - &latest_funding_fee_amount_per_size name: latest_funding_fee_amount_per_size description: The latest funding fee amount per size - data_tests: - - not_null - &latest_long_token_claimable_funding_amount_per_size name: latest_long_token_claimable_funding_amount_per_size description: The latest claimable long token funding amount per size - data_tests: - - not_null - &latest_short_token_claimable_funding_amount_per_size name: latest_short_token_claimable_funding_amount_per_size description: The latest claimable short token funding amount per size - data_tests: - - not_null - &borrowing_fee_usd name: borrowing_fee_usd description: The borrowing fee amount in USD @@ -709,58 +697,36 @@ models: - &referral_total_rebate_factor name: referral_total_rebate_factor description: The total rebate factor associated with referrals. - data_tests: - - not_null - &referral_total_rebate_amount name: referral_total_rebate_amount description: The total rebate amount given for referrals. - data_tests: - - not_null - &referral_trader_discount_factor name: referral_trader_discount_factor description: The discount factor applied to the trader through referrals. - data_tests: - - not_null - &referral_adjusted_affiliate_reward_factor name: referral_adjusted_affiliate_reward_factor description: The adjusted affiliate reward factor based on referral criteria. - data_tests: - - not_null - &referral_affiliate_reward_amount name: referral_affiliate_reward_amount description: The reward amount given to the affiliate for referrals. - data_tests: - - not_null - &referral_trader_discount_amount name: referral_trader_discount_amount description: The discount amount given to the trader through referrals. - data_tests: - - not_null - &pro_trader_discount_factor name: pro_trader_discount_factor description: The discount factor applied for pro traders. - data_tests: - - not_null - &pro_trader_discount_amount name: pro_trader_discount_amount description: The discount amount given to pro traders. - data_tests: - - not_null - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. - data_tests: - - not_null - &liquidation_fee_receiver_factor name: liquidation_fee_receiver_factor description: The factor used to calculate the liquidation fee allocated to the receiver. - data_tests: - - not_null - &liquidation_fee_amount_for_fee_receiver name: liquidation_fee_amount_for_fee_receiver description: The amount of liquidation fee allocated to the fee receiver. - data_tests: - - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) 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 bfd9d48a489..3f94499dbbe 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -153,8 +153,6 @@ models: - not_null - name: updated_at_block description: The block number at which the order was last updated. - data_tests: - - not_null - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. @@ -614,28 +612,18 @@ models: - &claimable_long_token_amount name: claimable_long_token_amount description: The amount of long tokens claimable - data_tests: - - not_null - &claimable_short_token_amount name: claimable_short_token_amount description: The amount of short tokens claimable - data_tests: - - not_null - &latest_funding_fee_amount_per_size name: latest_funding_fee_amount_per_size description: The latest funding fee amount per size - data_tests: - - not_null - &latest_long_token_claimable_funding_amount_per_size name: latest_long_token_claimable_funding_amount_per_size description: The latest claimable long token funding amount per size - data_tests: - - not_null - &latest_short_token_claimable_funding_amount_per_size name: latest_short_token_claimable_funding_amount_per_size description: The latest claimable short token funding amount per size - data_tests: - - not_null - &borrowing_fee_usd name: borrowing_fee_usd description: The borrowing fee amount in USD @@ -709,58 +697,36 @@ models: - &referral_total_rebate_factor name: referral_total_rebate_factor description: The total rebate factor associated with referrals. - data_tests: - - not_null - &referral_total_rebate_amount name: referral_total_rebate_amount description: The total rebate amount given for referrals. - data_tests: - - not_null - &referral_trader_discount_factor name: referral_trader_discount_factor description: The discount factor applied to the trader through referrals. - data_tests: - - not_null - &referral_adjusted_affiliate_reward_factor name: referral_adjusted_affiliate_reward_factor description: The adjusted affiliate reward factor based on referral criteria. - data_tests: - - not_null - &referral_affiliate_reward_amount name: referral_affiliate_reward_amount description: The reward amount given to the affiliate for referrals. - data_tests: - - not_null - &referral_trader_discount_amount name: referral_trader_discount_amount description: The discount amount given to the trader through referrals. - data_tests: - - not_null - &pro_trader_discount_factor name: pro_trader_discount_factor description: The discount factor applied for pro traders. - data_tests: - - not_null - &pro_trader_discount_amount name: pro_trader_discount_amount description: The discount amount given to pro traders. - data_tests: - - not_null - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. - data_tests: - - not_null - &liquidation_fee_receiver_factor name: liquidation_fee_receiver_factor description: The factor used to calculate the liquidation fee allocated to the receiver. - data_tests: - - not_null - &liquidation_fee_amount_for_fee_receiver name: liquidation_fee_amount_for_fee_receiver description: The amount of liquidation fee allocated to the fee receiver. - data_tests: - - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) 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 e04cf4b6bf1..73848fc96b9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -153,8 +153,6 @@ models: - not_null - name: updated_at_block description: The block number at which the order was last updated. - data_tests: - - not_null - &updated_at_time name: updated_at_time description: The timestamp when the order was last updated. @@ -614,28 +612,18 @@ models: - &claimable_long_token_amount name: claimable_long_token_amount description: The amount of long tokens claimable - data_tests: - - not_null - &claimable_short_token_amount name: claimable_short_token_amount description: The amount of short tokens claimable - data_tests: - - not_null - &latest_funding_fee_amount_per_size name: latest_funding_fee_amount_per_size description: The latest funding fee amount per size - data_tests: - - not_null - &latest_long_token_claimable_funding_amount_per_size name: latest_long_token_claimable_funding_amount_per_size description: The latest claimable long token funding amount per size - data_tests: - - not_null - &latest_short_token_claimable_funding_amount_per_size name: latest_short_token_claimable_funding_amount_per_size description: The latest claimable short token funding amount per size - data_tests: - - not_null - &borrowing_fee_usd name: borrowing_fee_usd description: The borrowing fee amount in USD @@ -709,43 +697,27 @@ models: - &referral_total_rebate_factor name: referral_total_rebate_factor description: The total rebate factor associated with referrals. - data_tests: - - not_null - &referral_total_rebate_amount name: referral_total_rebate_amount description: The total rebate amount given for referrals. - data_tests: - - not_null - &referral_trader_discount_factor name: referral_trader_discount_factor description: The discount factor applied to the trader through referrals. - data_tests: - - not_null - &referral_adjusted_affiliate_reward_factor name: referral_adjusted_affiliate_reward_factor description: The adjusted affiliate reward factor based on referral criteria. - data_tests: - - not_null - &referral_affiliate_reward_amount name: referral_affiliate_reward_amount description: The reward amount given to the affiliate for referrals. - data_tests: - - not_null - &referral_trader_discount_amount name: referral_trader_discount_amount description: The discount amount given to the trader through referrals. - data_tests: - - not_null - &pro_trader_discount_factor name: pro_trader_discount_factor description: The discount factor applied for pro traders. - data_tests: - - not_null - &pro_trader_discount_amount name: pro_trader_discount_amount description: The discount amount given to pro traders. - data_tests: - - not_null - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. From f7956e06aa146912a4469bf3f67a2eb3b3a410af Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 22:15:07 +0200 Subject: [PATCH 7/9] fix tests --- .../models/_projects/gmx/event/gmx_v2_event_schema.yml | 6 ------ 1 file changed, 6 deletions(-) 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 73848fc96b9..984a50017de 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 @@ -721,18 +721,12 @@ models: - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. - data_tests: - - not_null - &liquidation_fee_receiver_factor name: liquidation_fee_receiver_factor description: The factor used to calculate the liquidation fee allocated to the receiver. - data_tests: - - not_null - &liquidation_fee_amount_for_fee_receiver name: liquidation_fee_amount_for_fee_receiver description: The amount of liquidation fee allocated to the fee receiver. - data_tests: - - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) From bd2d0513e4deb7bd4fd846a8d321cc8471b68194 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Thu, 28 Nov 2024 22:36:38 +0200 Subject: [PATCH 8/9] fix errors again --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 22 +++++++++++++++++++ ...mx_v2_arbitrum_position_fees_collected.sql | 2 +- .../gmx_v2_arbitrum_position_fees_info.sql | 2 +- .../gmx_v2_avalanche_c_event_schema.yml | 22 +++++++++++++++++++ ...v2_avalanche_c_position_fees_collected.sql | 2 +- .../gmx_v2_avalanche_c_position_fees_info.sql | 2 +- .../gmx/event/gmx_v2_event_schema.yml | 22 +++++++++++++++++++ 7 files changed, 70 insertions(+), 4 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index 230c2a58920..d12bb30e20c 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 @@ -697,36 +697,58 @@ models: - &referral_total_rebate_factor name: referral_total_rebate_factor description: The total rebate factor associated with referrals. + data_tests: + - not_null - &referral_total_rebate_amount name: referral_total_rebate_amount description: The total rebate amount given for referrals. + data_tests: + - not_null - &referral_trader_discount_factor name: referral_trader_discount_factor description: The discount factor applied to the trader through referrals. + data_tests: + - not_null - &referral_adjusted_affiliate_reward_factor name: referral_adjusted_affiliate_reward_factor description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null - &referral_affiliate_reward_amount name: referral_affiliate_reward_amount description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null - &referral_trader_discount_amount name: referral_trader_discount_amount description: The discount amount given to the trader through referrals. + data_tests: + - not_null - &pro_trader_discount_factor name: pro_trader_discount_factor description: The discount factor applied for pro traders. + data_tests: + - not_null - &pro_trader_discount_amount name: pro_trader_discount_amount description: The discount amount given to pro traders. + data_tests: + - not_null - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. + data_tests: + - not_null - &liquidation_fee_receiver_factor name: liquidation_fee_receiver_factor description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null - &liquidation_fee_amount_for_fee_receiver name: liquidation_fee_amount_for_fee_receiver description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) 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 f58b8608d5d..7019c6c497d 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql @@ -438,7 +438,7 @@ WITH evt_data_1 AS ( --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql index 212f79eeb83..6665accfbd1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql @@ -439,7 +439,7 @@ WITH evt_data_1 AS ( --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index 3f94499dbbe..ba40d0e98e5 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -697,36 +697,58 @@ models: - &referral_total_rebate_factor name: referral_total_rebate_factor description: The total rebate factor associated with referrals. + data_tests: + - not_null - &referral_total_rebate_amount name: referral_total_rebate_amount description: The total rebate amount given for referrals. + data_tests: + - not_null - &referral_trader_discount_factor name: referral_trader_discount_factor description: The discount factor applied to the trader through referrals. + data_tests: + - not_null - &referral_adjusted_affiliate_reward_factor name: referral_adjusted_affiliate_reward_factor description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null - &referral_affiliate_reward_amount name: referral_affiliate_reward_amount description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null - &referral_trader_discount_amount name: referral_trader_discount_amount description: The discount amount given to the trader through referrals. + data_tests: + - not_null - &pro_trader_discount_factor name: pro_trader_discount_factor description: The discount factor applied for pro traders. + data_tests: + - not_null - &pro_trader_discount_amount name: pro_trader_discount_amount description: The discount amount given to pro traders. + data_tests: + - not_null - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. + data_tests: + - not_null - &liquidation_fee_receiver_factor name: liquidation_fee_receiver_factor description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null - &liquidation_fee_amount_for_fee_receiver name: liquidation_fee_amount_for_fee_receiver description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) 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 d390c9d4fdc..5e19b65ebfd 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql @@ -438,7 +438,7 @@ WITH evt_data_1 AS ( --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql index 313c55263a6..6dff079f071 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql @@ -439,7 +439,7 @@ WITH evt_data_1 AS ( --can be removed once decoded tables are fully denormalized {{ add_tx_columns( - model_cte = 'full_data' + model_cte = 'full_data_2' , blockchain = blockchain_name , columns = ['from', 'to'] ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index 984a50017de..c772b056d86 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -697,36 +697,58 @@ models: - &referral_total_rebate_factor name: referral_total_rebate_factor description: The total rebate factor associated with referrals. + data_tests: + - not_null - &referral_total_rebate_amount name: referral_total_rebate_amount description: The total rebate amount given for referrals. + data_tests: + - not_null - &referral_trader_discount_factor name: referral_trader_discount_factor description: The discount factor applied to the trader through referrals. + data_tests: + - not_null - &referral_adjusted_affiliate_reward_factor name: referral_adjusted_affiliate_reward_factor description: The adjusted affiliate reward factor based on referral criteria. + data_tests: + - not_null - &referral_affiliate_reward_amount name: referral_affiliate_reward_amount description: The reward amount given to the affiliate for referrals. + data_tests: + - not_null - &referral_trader_discount_amount name: referral_trader_discount_amount description: The discount amount given to the trader through referrals. + data_tests: + - not_null - &pro_trader_discount_factor name: pro_trader_discount_factor description: The discount factor applied for pro traders. + data_tests: + - not_null - &pro_trader_discount_amount name: pro_trader_discount_amount description: The discount amount given to pro traders. + data_tests: + - not_null - &liquidation_fee_amount name: liquidation_fee_amount description: The amount of fees charged during liquidation. + data_tests: + - not_null - &liquidation_fee_receiver_factor name: liquidation_fee_receiver_factor description: The factor used to calculate the liquidation fee allocated to the receiver. + data_tests: + - not_null - &liquidation_fee_amount_for_fee_receiver name: liquidation_fee_amount_for_fee_receiver description: The amount of liquidation fee allocated to the fee receiver. + data_tests: + - not_null - &is_increase name: is_increase description: Indicates whether the position is increased (true) or decreased (false) From bcd0ed6a4ccd843a5d2848640de4a1f2f478ef64 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Tue, 3 Dec 2024 21:45:29 +0200 Subject: [PATCH 9/9] Run Check Again. --- .../gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d12bb30e20c..a234b79c6fb 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -924,7 +924,7 @@ models: data_tests: - not_null - name: market - description: The market in which the order was updated. + description: The market in which the order was updated data_tests: - not_null - name: account