Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 New Events (GMX V2) #7438

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2275,3 +2275,97 @@ models:
description: The funding fee amount associated with the update.
- name: is_long
description: A boolean indicating if the position is a long position (`True` for long, `False` for short).

- name: gmx_v2_arbitrum_swap_fees_collected
meta:
blockchain: arbitrum
sector: dex
project: gmx
contributors: ai_data_master, gmx-io
config:
tags: ['arbitrum', 'gmx', 'event', 'swap_fee']
description: |
Processes decoded event data for `SwapFeesCollected` events on the GMX platform across the Arbitrum blockchain.
This model extracts key details such as fee amounts, trade keys, and fee types for analyzing swap fee collection behavior.
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- index
columns:
- *blockchain
- *block_time
- *block_date
- *block_number
- *tx_hash
- *index
- *contract_address
- name: tx_from
description: The address initiating the transaction.
- name: tx_to
description: The recipient address of the transaction.
- name: event_name
description: The name of the event emitted, always `SwapFeesCollected`.
- *msg_sender
- name: ui_fee_receiver
description: The address receiving the UI fee.
- name: market
description: The specific GMX market where the swap occurred.
- name: token
description: The token involved in the swap transaction.
- name: token_price
description: The price of the token at the time of the swap.
- name: fee_receiver_amount
description: The amount received by the fee receiver.
- name: fee_amount_for_pool
description: The amount of fees sent to the pool.
- name: amount_after_fees
description: The amount remaining after fees were deducted.
- name: ui_fee_receiver_factor
description: The factor used to calculate the UI fee.
- name: ui_fee_amount
description: The total UI fee amount deducted from the transaction.
- name: trade_key
description: A unique identifier for the trade.
- name: swap_fee_type
description: The type of fee associated with the swap.
- name: action_type
description: The action performed in the swap event (e.g., deposit, withdrawal, or swap).

- name: gmx_v2_arbitrum_position_impact_pool_distributed
meta:
blockchain: arbitrum
sector: dex
project: gmx
contributors: ai_data_master, gmx-io
config:
tags: ['arbitrum', 'gmx', 'event', 'position_impact']
description: |
Processes decoded event data for `PositionImpactPoolDistributed` events on the GMX platform across the Arbitrum blockchain.
This model extracts key details such as distribution amounts and pool impact metrics to analyze the effect of position impact distribution.
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- index
columns:
- *blockchain
- *block_time
- *block_date
- *block_number
- *tx_hash
- *index
- *contract_address
- name: tx_from
description: The address initiating the transaction.
- name: tx_to
description: The recipient address of the transaction.
- name: event_name
description: The name of the event emitted, always `PositionImpactPoolDistributed`.
- *msg_sender
- name: market
description: The specific GMX market where the position impact occurred.
- name: distribution_amount
description: The amount distributed to the impact pool.
- name: next_position_impact_pool_amount
description: The updated position impact pool amount after the event.
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ 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,
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,
funding_fee_amount / POWER(10, collateral_token_decimals) AS funding_fee_amount,
claimable_long_token_amount / POWER(10, long_token_decimals) AS claimable_long_token_amount,
claimable_short_token_amount / POWER(10, short_token_decimals) AS claimable_short_token_amount,
latest_funding_fee_amount_per_size / POWER(10, collateral_token_decimals + 15) AS latest_funding_fee_amount_per_size,
latest_long_token_claimable_funding_amount_per_size / POWER(10, long_token_decimals + 15) AS latest_long_token_claimable_funding_amount_per_size,
latest_short_token_claimable_funding_amount_per_size / POWER(10, short_token_decimals + 15) AS latest_short_token_claimable_funding_amount_per_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ 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,
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,
funding_fee_amount / POWER(10, collateral_token_decimals) AS funding_fee_amount,
claimable_long_token_amount / POWER(10, long_token_decimals) AS claimable_long_token_amount,
claimable_short_token_amount / POWER(10, short_token_decimals) AS claimable_short_token_amount,
latest_funding_fee_amount_per_size / POWER(10, collateral_token_decimals + 15) AS latest_funding_fee_amount_per_size,
latest_long_token_claimable_funding_amount_per_size / POWER(10, long_token_decimals + 15) AS latest_long_token_claimable_funding_amount_per_size,
latest_short_token_claimable_funding_amount_per_size / POWER(10, short_token_decimals + 15) AS latest_short_token_claimable_funding_amount_per_size,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{{
config(
schema = 'gmx_v2_arbitrum',
alias = 'position_impact_pool_distributed',
materialized = 'incremental',
unique_key = ['tx_hash', 'index'],
incremental_strategy = 'merge'
)
}}

{%- set event_name = 'PositionImpactPoolDistributed' -%}
{%- set blockchain_name = 'arbitrum' -%}

WITH evt_data_1 AS (
SELECT
-- Main Variables
'{{ blockchain_name }}' AS blockchain,
evt_block_time AS block_time,
evt_block_number AS block_number,
evt_tx_hash AS tx_hash,
evt_index AS index,
contract_address,
eventName AS event_name,
eventData AS data,
msgSender AS msg_sender
FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}}
WHERE eventName = '{{ event_name }}'
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
)

, evt_data_2 AS (
SELECT
-- Main Variables
'{{ blockchain_name }}' AS blockchain,
evt_block_time AS block_time,
evt_block_number AS block_number,
evt_tx_hash AS tx_hash,
evt_index AS index,
contract_address,
eventName AS event_name,
eventData AS data,
msgSender AS msg_sender
FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}}
WHERE eventName = '{{ event_name }}'
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
)

-- unite 2 tables
, evt_data AS (
SELECT *
FROM evt_data_1
UNION ALL
SELECT *
FROM evt_data_2
)

, parsed_data AS (
SELECT
tx_hash,
index,
json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items,
json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items
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 = 'market' THEN value END) AS market,
MAX(CASE WHEN key_name = 'distributionAmount' THEN value END) AS distribution_amount,
MAX(CASE WHEN key_name = 'nextPositionImpactPoolAmount' THEN value END) AS next_position_impact_pool_amount

FROM
combined
GROUP BY tx_hash, index
)

, event_data AS (
SELECT
blockchain,
block_time,
block_number,
ED.tx_hash,
ED.index,
contract_address,
event_name,
msg_sender,

from_hex(market) AS market,
TRY_CAST(distribution_amount AS DOUBLE) AS distribution_amount,
TRY_CAST(next_position_impact_pool_amount AS DOUBLE) AS next_position_impact_pool_amount

FROM evt_data AS ED
LEFT JOIN evt_data_parsed AS EDP
ON ED.tx_hash = EDP.tx_hash
AND ED.index = EDP.index
)

, full_data AS (
SELECT
ED.blockchain,
block_time,
DATE(block_time) AS block_date,
block_number,
tx_hash,
index,
ED.contract_address,
event_name,
msg_sender,

ED.market,
CASE
WHEN distribution_amount = 0 THEN 0
ELSE distribution_amount / POWER(10, MD.index_token_decimals)
END AS distribution_amount,
CASE
WHEN next_position_impact_pool_amount = 0 THEN 0
ELSE next_position_impact_pool_amount / POWER(10, MD.index_token_decimals)
END AS next_position_impact_pool_amount

FROM event_data AS ED
LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD
ON ED.market = MD.market
)

--can be removed once decoded tables are fully denormalized
{{
add_tx_columns(
model_cte = 'full_data'
, blockchain = blockchain_name
, columns = ['from', 'to']
)
}}
Loading
Loading