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

Upgrade Event Models for GMX v2 Project #7195

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -152,21 +152,21 @@ 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.
- 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
data_tests:
- 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.
Expand Down Expand Up @@ -604,31 +604,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
Expand All @@ -637,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
Expand Down Expand Up @@ -729,6 +694,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)
Expand Down Expand Up @@ -785,11 +805,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
Expand All @@ -810,6 +825,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
Expand Down Expand Up @@ -898,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
Expand All @@ -909,4 +935,8 @@ models:
- *acceptable_price_raw
- *acceptable_price
- *min_output_amount_raw
- *updated_at_time
- *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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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_arbitrum_order_created') }} AS OC
Expand Down
Loading
Loading